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

📄 nvutils.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 5 页
字号:
while(1) {    /* If we find the end of the file or the start of another section       we are done, deal with the current view and then return */    if ((fgets(buf, sizeof(buf), instream) == 0) || (*buf == '[')) {        /* If values were illegal or the view isn't consistent drop it */        if (error_cp != 0) {            printf("Illegal value for %s, the view was dropped\n", error_cp);            SNMP_View_Delete(view);            return(0);            }        /* if it's ok install it */        if (SNMP_View_Install((UINT_16_T)(idoidc[0] & 0xFFFF), view) != 0) {            /* if we couldn't install it, cleanup and fail */            printf("Unable to install view\n");            SNMP_View_Delete(view);            return(1);            }        return(0);        }    /* skip comments and blank lines */    if ((*buf == ';') || (*buf == '\n'))        continue;    /* try to translate the first string into a token, if we can't do       the translation the file is broken so we clean up and bail out */    if ((tbp = tokenizer(buf, view_tokens)) == 0) {        SNMP_View_Delete(view);        return(1);        }    cp = buf + STRLEN(tbp->token_string) + 1;    /* remove white space before the arguments */    while((*cp == ' ') || (*cp == '\t'))        cp++;    /* then determine the length of the agrument and terminate it with a 0 */    for (cp2 = cp, i = 0;         (*cp2 != '\n') && (*cp2 != ' ') && (*cp2 != '\t');         cp2++, i++)        ;    *cp2 = 0;    switch (tbp->token_tag) {        case TVID:            /* Before we get the new id we deal with the current view.  We               check and see if any values were illegal and if the view is               consistent.  If it is ok we install the view into the dbase */            if (error_cp == 0) {                /* if it's ok install it */                if (SNMP_View_Install((UINT_16_T)(idoidc[0] & 0xFFFF),                                      view) != 0) {                    /* if we couldn't install it, cleanup and fail */                    printf("Unable to install view\n");                          SNMP_View_Delete(view);                    return(1);                    }                }            /* If it wasn't ok drop the view but continue reading the file */            else {                if (error_cp != 0) {                    printf("Illegal value for %s, the view was dropped\n",                           error_cp);                    error_cp = 0;                    }                SNMP_View_Delete(view);                }            /* now that we are done with the old view start work on               the new view */            idoidclen = s2oid(cp, idoidc, sizeof(idoidc));            if ((view = SNMP_View_Create(idoidc + 1, idoidclen - 1)) == 0) {                printf("Error creating view\n");                return(1);                }            break;              case TVSTATUS:            sscanf(cp, "%d", &value);            if ((value >= ETC_RS_ACTIVE) && (value <= ETC_RS_DESTROY) &&                (value != ETC_RS_NREADY))                SNMP_View_Set_Status(view, value);            else                error_cp = "status";            break;        case TVSTORAGE:            sscanf(cp, "%d", &value);            if ((value >= ETC_STO_OTHER) && (value <= ETC_STO_PERM))                SNMP_View_Set_StorageType(view, value);            else                error_cp = "storage";            break;                 case TVMASK:            if (i != 0) {                j = i/2;                if (j <= VIEW_MAXMASKLEN) {                    for (i = 0; i < j; i++, cp += 2) {                        sscanf(cp, "%02x", &value);                        buf2[i] = (char)(value & 0xFF);                        }                    SNMP_View_Set_Mask(view, (OCTET_T *)buf2, j);                    }                else                    error_cp = "mask";                }            break;        case TVTYPE:            sscanf(cp, "%d", &value);            if ((value == VIEW_INCLUDED) || (value == VIEW_EXCLUDED))                SNMP_View_Set_Type(view, value);            else                error_cp = "type";            break;        }    }}/****************************************************************************NAME: write_viewsPURPOSE: Write the information in the view database to the configuration file.PARAMETERS:        FILE     *      output file (file to write to)        MODS_T   *      The list of views to skip        int             Flag, 1 if we should write out the skip listRETURNS: int    0 = success                other = failure****************************************************************************/int  write_views(FILE       *outstream,              MODS_T     *skip_list,              int         wflag){VIEWLEAF_T *view;OIDC_T      oidc1[MAX_OID_COUNT], oidc2[MAX_OID_COUNT];int         oidc1len, oidc2len;MODS_T     *skip_entry;UINT_16_T   indx1, indx2;/* if requested write out the entries in the skip list */if (wflag)    for (skip_entry = skip_list; skip_entry; skip_entry = skip_entry->next) {        /* if we are destroying the entry we don't need to write it out */        if (skip_entry->flags & NV_MOD_DESTROY)            continue;        view = (VIEWLEAF_T *)(skip_entry->data);        oidc2len = SNMP_View_Name(view, &indx2, oidc2 + 1, sizeof(oidc2) - 1)                  + 1;        oidc2[0] = (OIDC_T)indx2;        view_write(view, 0, 0, oidc2, oidc2len, outstream);        }/* Step through the view database and write out all the views   except for those specified in the argument list,   Note: When we get the subtree oid for the candidate view (oidc1)   we leave space for the index to be inserted into the oid.  We will   put the index in just before writing the view.  Until then we must   skip the reserved space in the oid.  We don't have to do this for   oid2 because we won't need to insert it's index in this section. */view = 0;while((view = SNMP_View_Next(view)) != 0) {    oidc1len = SNMP_View_Name(view, &indx1, oidc1 + 1, sizeof(oidc1) - 1);    for(skip_entry = skip_list; skip_entry; skip_entry = skip_entry->next) {        oidc2len = SNMP_View_Name((VIEWLEAF_T *)(skip_entry->data),                                   &indx2, oidc2, sizeof(oidc2));        if ((indx1 == indx2) &&            (oidcmp2(oidc1len, oidc1 + 1, oidc2len, oidc2) == 0))            break;        }    if (skip_entry == 0) {        /* we insert the index into the oid now */        oidc1[0] = (OIDC_T)indx1;        oidc1len++;        view_write(view, 0, 0, oidc1, oidc1len, outstream);        }    }/* put out an empty line as a spacer */fputc('\n', outstream);return(0);}#endif /* #if (INSTALL_ENVOY_SNMP_RFC1445_VIEWS) */#if (INSTALL_ENVOY_SNMP_RFC2275_VIEWS)/****************************************************************************NAME: SNMP_NV_View_2275_Add_ModPURPOSE: Add the given group to the group modification listPARAMETERS:	VIEWLEAF_T * oldview	VIEWLEAF_T * newview	sbits32_t    flags                      Destroy is the only one currently defined RETURNS: sbits32_t    0 = success, other = failure****************************************************************************/sbits32_t  SNMP_NV_View_2275_Add_Mod(VIEWLEAF_T *oldview,			    VIEWLEAF_T *newview,			    sbits32_t   flags){return(SNMP_NV_Add_Mod((ptr_t)oldview, (ptr_t)newview, flags,		       &view_mod_list));}/****************************************************************************NAME: read_viewsPURPOSE: Read the view information from the configuration.  We read         information until we hit a statement starting with a '[' or         an end of file (both probably successful or we          hit an unknown token (a failure)PARAMETERS:        FILE *  input file (file to read from)RETURNS: int    0 = success                other = failure****************************************************************************/int  read_views(FILE *instream){TB_T *tbp;char buf[100], buf2[100], *cp, *cp2, *error_cp = 0;bits8_t name[100];VIEWLEAF_T *view;OIDC_T idoidc[MAX_OID_COUNT];int idoidclen = 0, i, j;ALENGTH_T nlen;int value;while(1) {    /* We are done if we have found the end of the file or       a new section is starting */    if ((fgets(buf, sizeof(buf), instream) == 0) || (*buf == '['))        return(0);    if ((*buf == ';') || (*buf == '\n'))        continue;    if ((tbp = tokenizer(buf, view_tokens)) == 0)        return(1);    if (tbp->token_tag != TVID) {        printf("View block: first token must be identity (name and subtree\n");        return(1);        }    cp = buf + STRLEN(tbp->token_string) + 1;    /* remove white space before the arguments */    while((*cp == ' ') || (*cp == '\t'))        cp++;    /* then determine the length of the name and copy it to name */    for (cp2 = cp, nlen = 0; (*cp2 != '\n') && (*cp2 != ':'); cp2++, nlen++)        ;    if ((nlen == 0) || (*cp2 != ':')) {        printf("View block: badly formed identity string\n");	return(1);        }    MEMCPY(name, cp, nlen);    /* then determine the length of the agrument and terminate it with a 0 */    cp = cp2+1;    for (cp2 = cp; (*cp2 != '\n') && (*cp2 != ' ') && (*cp2 != '\t'); cp2++)        ;    *cp2 = 0;    idoidclen = s2oid(cp, idoidc, sizeof(idoidc));    break;    }if ((view = SNMP_View_Create(idoidc, idoidclen)) == 0) {    printf("Error creating view\n");    return(1);    }while(1) {    /* If we find the end of the file or the start of another section       we are done, deal with the current view and then return */    if ((fgets(buf, sizeof(buf), instream) == 0) || (*buf == '[')) {        /* If values were illegal or the view isn't consistent drop it */        if (error_cp != 0) {            printf("Illegal value for %s, the view was dropped\n", error_cp);            SNMP_View_Delete(view);            return(0);            }        /* if it's ok install it */        if (SNMP_View_2275_Install(view, name, nlen) != 0) {            /* if we couldn't install it, cleanup and fail */            printf("Unable to install view\n");            SNMP_View_Delete(view);            return(1);            }        return(0);        }    /* skip comments and blank lines */    if ((*buf == ';') || (*buf == '\n'))        continue;    /* try to translate the first string into a token, if we can't do       the translation the file is broken so we clean up and bail out */    if ((tbp = tokenizer(buf, view_tokens)) == 0) {        SNMP_View_Delete(view);        return(1);        }    cp = buf + STRLEN(tbp->token_string) + 1;    /* remove white space before the arguments */    while((*cp == ' ') || (*cp == '\t'))        cp++;    /* then determine the length of the agrument and terminate it with a 0 */    for (cp2 = cp, i = 0;         (*cp2 != '\n') && (*cp2 != ' ') && (*cp2 != '\t');         cp2++, i++)        ;    *cp2 = 0;    switch (tbp->token_tag) {        case TVID:            /* Before we get the new id we deal with the current view.  We               check and see if any values were illegal and if the view is               consistent.  If it is ok we install the view into the dbase */            if (error_cp == 0) {                /* if it's ok install it */                if (SNMP_View_2275_Install(view, name, nlen) != 0) {                    /* if we couldn't install it, cleanup and fail */                    printf("Unable to install view\n");                          SNMP_View_Delete(view);                    return(1);                    }                }            /* If it wasn't ok drop the view but continue reading the file */            else {                if (error_cp != 0) {                    printf("Illegal value for %s, the view was dropped\n",                           error_cp);                    error_cp = 0;                    }                SNMP_View_Delete(view);                }            /* now that we are done with the old view start work on               the new view */	    /* determine the length of the name and copy it to name */	    for (cp2 = cp, nlen = 0;		 (*cp2 != '\n') && (*cp2 != ':');		 cp2++, nlen++)	        ;	    if ((nlen == 0) || (*cp2 != ':')) {	        printf("View block: badly formed identity string\n");		return(1);	        }	    MEMCPY(name, cp, nlen);	    cp = cp2+1;            idoidclen = s2oid(cp, idoidc, sizeof(idoidc));            if ((view = SNMP_View_Create(idoidc, idoidclen)) == 0) {                printf("Error creating view\n");                return(1);                }            break;              case TVSTATUS:            sscanf(cp, "%d", &value);            if ((value >= ETC_RS_ACTIVE) && (value <= ETC_RS_DESTROY) &&                (value != ETC_RS_NREADY))                SNMP_View_Set_Status(view, value);            else                error_cp = "status";            break;        case TVSTORAGE:            sscanf(cp, "%d", &value);            if ((value >= ETC_STO_OTHER) && (value <= ETC_STO_RONLY))                SNMP_View_Set_StorageType(view, value);            else                error_cp = "storage";            break;                 case TVMASK:            if (i != 0) {                j = i/2;                if (j <= VIEW_MAXMASKLEN) {                    for (i = 0; i < j; i++, cp += 2) {                        sscanf(cp, "%02x", &value);                        buf2[i] = (char)(value & 0xFF);                        }                    SNMP_View_Set_Mask(view, (OCTET_T *)buf2, j);                    }                else                    error_cp = "mask";                }            break;        case TVTYPE:            sscanf(cp, "%d", &value);            if ((value == VIEW_INCLUDED) || (value == VIEW_EXCLUDED))                SNMP_View_Set_Type(view, value);            else                error_cp = "type";            break;        }    }}/****************************************************************************

⌨️ 快捷键说明

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