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

📄 nvutils.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 5 页
字号:
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, *infoview, *nameview;MODS_T     *skip_entry = 0; int        oidclen;OIDC_T    *oidc;ALENGTH_T  nlen, nlen2;bits8_t    name[ETC_VIEW_NAME_MAX + 1], name2[ETC_VIEW_NAME_MAX + 1];/* 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;	nameview = (VIEWLEAF_T *)(skip_entry->data    ? skip_entry->data :				                        skip_entry->newdata);	infoview = (VIEWLEAF_T *)(skip_entry->newdata ? skip_entry->newdata :				                        skip_entry->data);	nlen = ETC_VIEW_NAME_MAX;	SNMP_View_2275_Name(nameview, name, &nlen);        view_write(infoview, name, nlen, SNMP_View_Get_Subtree(nameview),		   SNMP_View_Get_Subtree_Len(nameview), outstream);        }/* Step through the view database and write out all the views   except for those specified in the argument list, */view = 0;while((view = SNMP_View_Next(view)) != 0) {    nlen = ETC_VIEW_NAME_MAX;    SNMP_View_2275_Name(view, name, &nlen);    oidc = SNMP_View_Get_Subtree(view);    oidclen = SNMP_View_Get_Subtree_Len(view);    for(skip_entry = skip_list; skip_entry; skip_entry = skip_entry->next) {	nameview = (VIEWLEAF_T *)(skip_entry->data    ? skip_entry->data :				                        skip_entry->newdata);	nlen2 = ETC_VIEW_NAME_MAX;	SNMP_View_2275_Name(nameview, name2, &nlen2);	if ((nlen == nlen2) && (MEMCMP(name, name2, nlen) == 0) &&	    (oidcmp2(oidclen, oidc,		     SNMP_View_Get_Subtree_Len(nameview),		     SNMP_View_Get_Subtree(nameview)) == 0))	    break;        }    if (skip_entry == 0) {        view_write(view, name, nlen, oidc, oidclen, outstream);        }    }/* put out an empty line as a spacer */fputc('\n', outstream);return(0);}#endif /* #if (INSTALL_ENVOY_SNMP_RFC2275_VIEWS) */#if (INSTALL_ENVOY_SNMP_VERSION_3)/****************************************************************************NAME: read_v3myidPURPOSE: Read my engines 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))	 If eng_id is not zero than it is used as the engine id	 and we don't need an engine id token otherwise we need	 an id token and we use whatever we find here.PARAMETERS:        FILE *  input file (file to read from)	char *  possible engine id from elsewhereRETURNS: int    0 = success                other = failure****************************************************************************/int  read_v3myid(FILE *instream,	      char *eng_id){TB_T *tbp;char buf[100], *cp, *cp2;ALENGTH_T id_len;int value;bits8_t buf_id[50];bits32_t boots;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(1);    if ((*buf == ';') || (*buf == '\n'))        continue;    if ((tbp = tokenizer(buf, engine_tokens)) == 0)        return(1);    if (eng_id) {        /* use the supplied engine id */        cp = eng_id;	        }    else {        if (tbp->token_tag != TENGID) {	    printf("v3myengine block: first token must be id\n");	    return(1);            }	cp = buf + STRLEN(tbp->token_string) + 1;	/* remove white space before the arguments */	while((*cp == ' ') || (*cp == '\t'))	    cp++;        }    /* then try and pull out the engine id */    for (id_len = 0; id_len < 50; id_len++, cp+=2) {        if ((*cp == '\n') || (*cp == ' ') || (*cp == '\t') || (*cp == '\0'))	    break;	if ((*(cp+1) == '\n') || (*(cp+1) == ' ') || (*(cp+1) == '\t')) {	    printf("v3myengine block: odd number of characters in string\n");	    return(1);	    }        sscanf(cp, "%02x", &value);	buf_id[id_len] = (bits8_t)(value & 0xff);        }    /* If there are any more characters left the id was too long */    if ((*cp != '\n') && (*cp != ' ') && (*cp != '\t') && (*cp != '\0')) {        printf("v3myengine block: engineid is too long\n");        return(1);        }    break;    }while(1) {    /* we need to find one agentboots tag, anything else will be ignored       (and removed when we rewrite this section */    if ((fgets(buf, sizeof(buf), instream) == 0) || (*buf == '[')) {        printf("v3myengine block: no agent boots specified\n");        return(1);        }    /* 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, engine_tokens)) == 0) ||        (tbp->token_tag != TENGBOOTS)) {        printf("v3myengine block: unexpected token %s\n", tbp->token_string);        return(1);        }    cp = buf + STRLEN(tbp->token_string) + 1;    /* remove white space before the arguments */    while((*cp == ' ') || (*cp == '\t'))        cp++;    /* then terminate he agrument with a 0 */    for (cp2 = cp; (*cp2 != '\n') && (*cp2 != ' ') && (*cp2 != '\t'); cp2++)        ;    *cp2 = 0;    sscanf(cp, "%lu", &boots);    if (SNMP_Engine_Set_My_Info(buf_id, id_len, boots, 0)) {        printf("v3myengine block: unable to install engine info\n");	return(1);        }    return(0);    }}/****************************************************************************NAME: write_v3myidPURPOSE: Write the information about my engine to the configuration file.PARAMETERS:        FILE     *      output file (file to write to)RETURNS: int    0 = success                other = failure****************************************************************************/int  write_v3myid(FILE     *outstream){bits8_t *bufp;ALENGTH_T buf_len; fprintf(outstream, "engineid = ");buf_len = SNMP_Engine_Get_My_ID_Length();bufp    = SNMP_Engine_Get_My_ID();for(; buf_len; buf_len--, bufp++)    fprintf(outstream, "%02x", *bufp & 0xff);fprintf(outstream, "\nengineboots = %lu\n\n", SNMP_Engine_Get_My_Boots() + 1);return(0);}/****************************************************************************NAME: read_v3enginesPURPOSE: Read the engine 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_v3engines(FILE *instream){TB_T *tbp;char buf[100], *cp;ALENGTH_T id_len = 0;int value;bits8_t buf_id[50];#if (INSTALL_ENVOY_SNMP_V3_TARGET)char *cp2;int i;OIDC_T udpoid[] = { 1, 3, 6, 1, 6, 1, 1 };bits8_t taddress[6];bits16_t port;#endifwhile(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, engine_tokens)) == 0)        return(1);    if ((tbp->token_tag == TENGID) || (tbp->token_tag == TENGTADDR)) {        cp = buf + STRLEN(tbp->token_string) + 1;	/* remove white space before the arguments */	while((*cp == ' ') || (*cp == '\t'))	    cp++;        }    else        continue;        if (tbp->token_tag == TENGID) {	/* then try and pull out the engine id */	for (id_len = 0; id_len < 50; id_len++, cp+=2) {	    if ((*cp == '\n') || (*cp == ' ') || (*cp == '\t'))	        break;	    if ((*(cp+1) == '\n') || (*(cp+1) == ' ') || (*(cp+1) == '\t')) {	        printf("v3engines block: odd number of characters in string\n");		return(1);	        }	    sscanf(cp, "%02x", &value);	    buf_id[id_len] = (bits8_t)(value & 0xff);            }	/* If there are any more characters left the id was too long */	if ((*cp != '\n') && (*cp != ' ') && (*cp != '\t')) {	    printf("v3engines block: engineid is too long\n");	    return(1);            }	/* we don't install the engine id if it matches my engine id.	   this allows the config file to be more general */	if ((id_len != SNMP_Engine_Get_My_ID_Length()) ||	    MEMCMP(buf_id, SNMP_Engine_Get_My_ID(), id_len)) {	    if (SNMP_Engine_Install(buf_id, id_len, 0, 0)){	        printf("v3engines block: unable to install engine info\n");		return(1);	        }            }        }#if (INSTALL_ENVOY_SNMP_V3_TARGET)    else if ((tbp->token_tag == TENGTADDR) && (id_len)) {	for (cp2 = cp; (*cp2) != ':'; cp2++)	    ;	*(cp2++) = '\0';	for (i = 0; i < 4; i++) {	    sscanf(cp, "%d", &value);	    if (value > 255) {	        printf("v3engines: invalid IP address");		return(1);	        }	    taddress[i] = value;	    if (i < 3)	        while (*(cp++) != '.')		    ;	    }	sscanf(cp2, "%d", &value);	port = htons((bits16_t) value);	MEMCPY(&(taddress[4]), &port, 2);	if (SNMP_Engine_Set_Address(buf_id, id_len, 				    udpoid,				    (sizeof(udpoid)/sizeof(OIDC_T)),				    taddress, 6)) {	    printf("v3engines block: unable to set address\n");	    return(1);	    }        }#endif    }}/****************************************************************************NAME: read_v3usersPURPOSE: Read the user 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_v3users(FILE *instream){TB_T *tbp;char buf[100], *cp, *cp2;ALENGTH_T id_len, userlen = 0, authlen = 0, privlen = 0;bits8_t buf_id[50], username[100], authkey[50], privkey[50];int value, i, storage = 0, stat = 1;SNMP_AUTH_T *auth = 0, *auth_md5, *auth_sha;SNMP_PRIV_T *priv = 0, *priv_des;SNMP_USER_T *user;OIDC_T md5_obj[] = {1, 3, 6, 1, 6, 3, 10, 1, 1, 2};OIDC_T sha_obj[] = {1, 3, 6, 1, 6, 3, 10, 1, 1, 3};OIDC_T des_obj[] = {1, 3, 6, 1, 6, 3, 10, 1, 2, 2};/* set up some initial items */auth_md5 = SNMP_Auth_Find(sizeof(md5_obj)/sizeof(OIDC_T), md5_obj);auth_sha = SNMP_Auth_Find(sizeof(sha_obj)/sizeof(OIDC_T), sha_obj);priv_des = SNMP_Priv_Find(sizeof(des_obj)/sizeof(OIDC_T), des_obj);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'))        break;    }if (((tbp = tokenizer(buf, v3user_tokens)) == 0) ||    (tbp->token_tag != TV3UID)) {    printf("V3User block: first token must be engineid\n");    return(1);    }cp = buf + STRLEN(tbp->token_string) + 1;/* remove white space before the arguments */while((*cp == ' ') || (*cp == '\t'))    cp++;/* then try and pull out the engine id */for (id_len = 0; id_len < 50; id_len++, cp+=2) {    if ((*cp == '\n') || (*cp == ' ') || (*cp == '\t'))        break;    if ((*(cp+1) == '\n') || (*(cp+1) == ' ') || (*(cp+1) == '\t')) {        printf("v3user block: odd number of characters in engineid\n");	return(1);        }    sscanf(cp, "%02x", &value);    buf_id[id_len] = (bits8_t)(value & 0xff);    }/* If there are any more characters left the id was too long */if ((*cp != '\n') && (*cp != ' ') && (*cp != '\t')) {    printf("v3user block: engineid is too long\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 user and then return */    if ((fgets(buf, sizeof(buf), instream) == 0) || (*buf == '[')) {        /* If we picked up all the needed info create and install the user */        if ((userlen == 0) ||	    (auth && (SNMP_Auth_Get_KeySize(auth) != authlen)) ||	    (priv && (SNMP_Priv_Get_KeySize(priv) != privlen)) ||	    (priv && (auth == 0))) {

⌨️ 快捷键说明

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