⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snmpsys.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/snmp/vxagent/base/snmpsys.c,v 1.4 2001/11/09 17:30:26 tneale Exp $ *//* snmpSystem.c - method routines for system group *//* *  Copyright 1984-2005 Wind River Systems, Inc. *  All rights reserved.  Provided under license only. *  Distribution or other use of this software is only *  permitted pursuant to the terms of a license agreement *  from Wind River Systems (and is otherwise prohibited). *  Refer to that license agreement for terms of use. */#include "copyright_wrs.h"/*modification history-------------------01c,19apr05,job  update copyright notices01b,01dec03,job  update copyright information01a,10mar96,rjc  written*//* * $Log: snmpsys.c,v $ * Revision 1.4  2001/11/09 17:30:26  tneale * Another adjustment for generated header files * * Revision 1.3  2001/11/09 14:54:09  tneale * Fixed paths for generated files mibhand.h and mibleaf.h * * Revision 1.2  2001/11/08 22:18:35  meister * rework pathnames * * Revision 1.1.1.1  2001/11/05 17:47:50  tneale * Tornado shuffle * * Revision 1.7  2001/04/16 19:38:43  josh * merging the kingfisher branch onto the trunk * * Revision 1.6  2001/01/19 22:25:07  paul * Update copyright. * * Revision 1.5.2.2  2001/03/12 22:11:35  tneale * Updated copyright * * Revision 1.5.2.1  2001/02/21 21:28:58  josh * updating system group set functions to do NVT and length checking * * Revision 1.5  2000/03/09 17:42:27  josh * setting up prototypes and includes where appropriate to eliminate * build warnings * * Revision 1.4  2000/03/08 21:33:58  sar * Changed the test for strings in the system group to leave space for * the end of string character * * Revision 1.3  2000/03/07 21:17:30  josh * fixing log comments * * Revision 1.2  2000/03/07 20:58:37  josh * putting CVS headers and logs into files that were lacking * *//* includes */#include <wrn/wm/snmp/vxagent/snmpdLib.h>#include "m2Lib.h"#include <wrn/wm/snmp/vxagent/mibleaf.h>#include <wrn/wm/snmp/vxagent/mibhand.h>/* forward declarations */void  systemUndo ( OIDC_T, int, OIDC_T *, SNMP_PKT_T *, VB_T * );static int check_nvt (OCTET_T *, size_t);/*******************************************************************************  systemGet**  Get method routine for system group**  Parameters to this routine are *  *  <lastmatch> - the last oid component that was matched to get to this leaf.*  <compc>     - count of components remaining in the unmatched portion i.e.*                the length of the instance portion.*  <compl>     - ptr to the oid sequence remaining, i.e. the instance portion.*  <pktp>      - ptr to internal representation of the snmp pkt.*  <vbp>       - ptr to var bind being processed.**  *  RETURNS: N/A*/void systemGet    (    OIDC_T              lastmatch,    int	                compc,    OIDC_T *            compl,    SNMP_PKT_T *	pktp,    VB_T *              vbp    )    {    static  M2_SYSTEM       sysVars;        /* Group together all varbinds which have the same getproc and instance */    snmpdGroupByGetprocAndInstance (pktp, vbp, compc, compl);    if ( (compc != 1) || (*compl != 0) )         {        for ( ; vbp != NULL; vbp = vbp->vb_link)            {            getproc_nosuchins (pktp, vbp);            }        return;        }    if ( m2SysGroupInfoGet (&sysVars)  != OK )         {        for ( ; vbp != NULL; vbp = vbp->vb_link)             {             getproc_error (pktp, vbp, GEN_ERR);             }        return;        }    else        {         for (  ; vbp; vbp = vbp->vb_link)            {                switch (vbp->vb_ml.ml_last_match)                {                case LEAF_sysDescr:                    getproc_got_string (pktp, vbp,                                         strlen ((char*)sysVars.sysDescr),                                        sysVars.sysDescr, 0, VT_STRING);                    break;                case LEAF_sysObjectID:                    getproc_got_object_id (pktp, vbp,                                            sysVars.sysObjectID.idLength,                                           (OIDC_T*) sysVars.sysObjectID.                                                             idArray, 0);                    break;                 case LEAF_sysUpTime:                    getproc_got_uint32 (pktp, vbp, sysVars.sysUpTime,                                         VT_TIMETICKS);                    break;                 case LEAF_sysContact:                    getproc_got_string (pktp, vbp,                                         strlen ((char*) sysVars.sysContact),                                        sysVars.sysContact, 0, VT_STRING);                    break;                case LEAF_sysName:                    getproc_got_string (pktp, vbp,                                         strlen ((char*)sysVars.sysName),                                        sysVars.sysName, 0, VT_STRING);                    break;                 case LEAF_sysLocation:                    getproc_got_string (pktp, vbp,                                         strlen ((char*) sysVars.sysLocation),                                        sysVars.sysLocation, 0, VT_STRING);                    break;                 case LEAF_sysServices:                    getproc_got_int32 (pktp, vbp, 0x4F);                    break;                default:                    getproc_error (pktp, vbp, GEN_ERR);                     break;                }            }        }    }                /*******************************************************************************  systemSet**  Set method routine for system group*  Parameters to this routine are *  *  <lastmatch> - the last oid component that was matched to get to this leaf.*  <compc>     - count of components remaining in the unmatched portion i.e.*                the length of the instance portion.*  <compl>     - ptr to the oid sequence remaining, i.e. the instance portion.*  <pktp>      - ptr to internal representation of the snmp pkt.*  <vbp>       - ptr to var bind being processed.***  RETURNS: N/A*/void systemSet    (    OIDC_T              lastmatch,    int	                compc,    OIDC_T *            compl,    SNMP_PKT_T *	pktp,    VB_T *              vbp    )    {    int             length;    M2_SYSTEM       sysVars;    unsigned int    varToSet = 0;    VB_T *          pVbpSaved = vbp;    for (    ; vbp; vbp = vbp->vb_link)        {         length = EBufferUsed (&vbp->value_u.v_string);        switch (vbp->vb_ml.ml_last_match)            {            case LEAF_sysName:                memcpy (sysVars.sysName,                         EBufferStart (&vbp->value_u.v_string), length);                sysVars.sysName [length] = 0;                varToSet |= M2SYSNAME;                break;             case LEAF_sysContact:                memcpy (sysVars.sysContact,                         EBufferStart (&vbp->value_u.v_string), length);                sysVars.sysContact [length] = 0;                varToSet |= M2SYSCONTACT;                break;             case LEAF_sysLocation:                memcpy (sysVars.sysLocation,                         EBufferStart (&vbp->value_u.v_string), length);                sysVars.sysLocation [length] = 0;                varToSet |= M2SYSLOCATION;                break;            }        }     if (m2SysGroupInfoSet (varToSet, &sysVars) != OK )        {        /* Since this set failed the undo is pointless as nothing has changed.         * However since the undo proc for this vb will be called we remove the         * attached undo buffer to distinguish between a required undo and this         * case.         */         snmpVbPrivFree (vbp);        setproc_error (pktp, pVbpSaved, COMMIT_FAILED);        return;        }    for (vbp = pVbpSaved; vbp != NULL; vbp = vbp->vb_link)        {        setproc_good (pktp, vbp);        }    pVbpSaved->undoproc = (UNDOPROC_T *) systemUndo;    }        /*******************************************************************************  systemTest**  Test method routine for system group**  Parameters to this routine are *  *  <lastmatch> - the last oid component that was matched to get to this leaf.*  <compc>     - count of components remaining in the unmatched portion i.e.*                the length of the instance portion.*  <compl>     - ptr to the oid sequence remaining, i.e. the instance portion.*  <pktp>      - ptr to internal representation of the snmp pkt.*  <vbp>       - ptr to var bind being processed.***/    void systemTest    (    OIDC_T              lastmatch,    int	                compc,    OIDC_T *            compl,    SNMP_PKT_T *	pktp,    VB_T *              vbp    )    {    /* Group together all varbinds which have the same getproc and instance */    snmpdGroupByGetprocAndInstance (pktp, vbp, compc, compl);    if ((compc != 1) || (*compl != 0))         {        testproc_error (pktp, vbp, NO_SUCH_NAME);        return;        }    vbp->vb_priv = snmpdMemoryAlloc (sizeof (M2_SYSTEM));    vbp->vb_free_priv = (VBPRIVPROC_T *) snmpVbPrivFree;    if ((vbp->vb_priv == NULL) ||        m2SysGroupInfoGet ((M2_SYSTEM *) vbp->vb_priv) != OK)        {        testproc_error (pktp, vbp, GEN_ERR);        return;        }    for (  ; vbp; vbp = vbp->vb_link)        {        switch (vbp->vb_ml.ml_last_match)            {            case LEAF_sysContact:            case LEAF_sysName:            case LEAF_sysLocation:                if (EBufferUsed(&vbp->value_u.v_string) >                    (ALENGTH_T)(M2DISPLAYSTRSIZE - 1))                    {                    testproc_error (pktp, vbp, WRONG_LENGTH);                    return;                    }                else if (check_nvt(vbp->value_u.v_string.start_bp,                                   EBufferUsed(&vbp->value_u.v_string)))                    {                    testproc_error (pktp, vbp, WRONG_VALUE);                    return;                    }            default:                testproc_good (pktp, vbp);            }        }    }    /******************************************************************************** systemUndo*** Undo proc for the sytem group.* Restores the values saved earlier in the testproc.**  Parameters to this routine are *  *  <lastmatch> - the last oid component that was matched to get to this leaf.*  <compc>     - count of components remaining in the unmatched portion i.e.*                the length of the instance portion.*  <compl>     - ptr to the oid sequence remaining, i.e. the instance portion.*  <pktp>      - ptr to internal representation of the snmp pkt.*  <vbp>       - ptr to var bind being processed.** RETURNS: N/A**/void systemUndo    (    OIDC_T              lastmatch,    int	                compc,    OIDC_T *            compl,    SNMP_PKT_T *	pktp,    VB_T *              vbp    )    {    if (vbp->vb_priv == NULL)        {        goto goodReturn;        }    if (m2SysGroupInfoSet (M2SYSNAME | M2SYSCONTACT | M2SYSLOCATION,                            (M2_SYSTEM *) vbp->vb_priv) != OK)        {        undoproc_error (pktp, vbp, UNDO_FAILED);         return;        }goodReturn:    undoproc_good (pktp, vbp);    return;    }/* check NVT compliance.  Return 0 if good. */static intcheck_nvt(OCTET_T *cp, size_t len){  while (len--) {    if ((*cp & 0200) != 0)      return -1;    if (*cp++ == '\r') {      if (len-- == 0)        return -1;      if ((*cp == '\n') || (*cp == 0))        cp++;      else        return -1;    }  }  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -