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

📄 nvutils.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 5 页
字号:
	    printf("v3user block: improperly formatted user entry\n");	    return(1);	    }	user = SNMP_User_Create(auth, priv);	if (user == 0) {	    printf("v3user block: unable to create user\n");	    return(1);	    }	if (auth)	   (void) SNMP_User_Set_AuthKey(user, authkey, authlen);	if (priv)	   (void) SNMP_User_Set_PrivKey(user, privkey, privlen);	SNMP_User_Set_Status(user, stat);	if (storage)	    SNMP_User_Set_Storage(user, storage);	if (SNMP_User_Install(user, buf_id, id_len, username, userlen)) {	    printf("v3user block: unable to install user\n");	    SNMP_User_Destroy(user);	    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, v3user_tokens)) == 0) {        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 TV3UID:            /* Before we get the new id we deal with the current user.               If it is ok we install the view into the dbase */	    if ((userlen == 0) ||		(auth && (SNMP_Auth_Get_KeySize(auth) != authlen)) ||		(priv && (SNMP_Priv_Get_KeySize(priv) != privlen)) ||		(priv && (auth == 0))) {	        printf("v3user block: improperly formatted user entry\n");		return(1);	        }	    user = SNMP_User_Create(auth, priv);	    if (user == 0) {	        printf("v3user block: unable to create user\n");		return(1);	        }	    SNMP_User_Set_Status(user, stat);	    if (storage)	        SNMP_User_Set_Storage(user, storage);	    if (auth)	        (void) SNMP_User_Set_AuthKey(user, authkey, authlen);	    if (priv)	        (void) SNMP_User_Set_PrivKey(user, privkey, privlen);	    if (SNMP_User_Install(user, buf_id, id_len, username, userlen)) {	        printf("v3user block: unable to install user\n");		SNMP_User_Destroy(user);		return(1);	        }            /* now that we are done with the old user start work on               the new user */	    userlen = 0;	    auth = 0;	    authlen = 0;	    priv = 0;	    privlen = 0;	    stat = 1;	    storage = 0;	    if (i % 2) {	        printf("v3user block: odd number of characters in engineid\n");		return(1);	        }	    if (i > 100) {	        printf("v3user block: engineid is too long\n");		return(1);	        }	    for (id_len = 0; i; i-=2,id_len++, cp+=2) {		sscanf(cp, "%02x", &value);		buf_id[id_len] = (bits8_t)(value & 0xff);	        }            break;              case TV3UUNAME:            userlen = i;            MEMCPY(username, cp, i);            break;        case TV3UAUTHPROT:	    sscanf(cp, "%d", &value);	    switch(value) {	        case 1:		    if (auth_md5 == 0)		        printf("v3user block: unknown auth, continuing\n");		    auth = auth_md5;		    break;	        case 2: 		    if (auth_sha == 0)		        printf("v3user block: unknown auth, continuing\n");		    auth = auth_sha;		    break;	        }            break;                 case TV3UAUTHKEY:	    if (i%2) {	        printf("v3user block: authkey is odd length\n");		return(1);	        }	    if (i > 100) {	        printf("v3user block: authkey is too long\n");		return(1);	        }	                    for (authlen = 0; i; i-=2, authlen++, cp+=2) {                sscanf(cp, "%02x", &value);                authkey[authlen] = (bits8_t)(value & 0xff);                }            break;        case TV3UPRIVPROT:	    sscanf(cp, "%d", &value);	    switch(value) {	        case 1:		    if (priv_des == 0)		        printf("v3user block: unknown priv, continuing\n");		    priv = priv_des;		    break;	        }            break;                 case TV3UPRIVKEY:	    if (i%2) {	        printf("v3user block: privkey is odd length\n");		return(1);	        }	    if (i > 100) {	        printf("v3user block: privkey is too long\n");		return(1);	        }	                    for (privlen = 0; i; i-=2, privlen++, cp+=2) {                sscanf(cp, "%02x", &value);                privkey[privlen] = (bits8_t)(value & 0xff);                }            break;        case TV3USTATUS:            sscanf(cp, "%d", &value);            if ((value >= ETC_RS_ACTIVE) && (value <= ETC_RS_DESTROY) &&                (value != ETC_RS_NREADY))	        stat = value;            else {	        printf("v3user block: status has wrong value\n");		return(1);	        }            break;        case TV3USTORAGE:            sscanf(cp, "%d", &value);            if ((value >= ETC_STO_OTHER) && (value <= ETC_STO_RONLY))	        storage = value;            else {	        printf("v3user block: storage has wrong value\n");		return(1);	        }            break;        }    }}/****************************************************************************NAME: read_v3groupsPURPOSE: Read the user to group 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_v3groups(FILE *instream){TB_T *tbp;char buf[100], *cp, *cp2, *error_cp = 0;ALENGTH_T user_len = 0, group_len = 0;bits8_t username[100], groupname[100];int value, i, storage = 0, stat = 1;SNMP_GROUP_T *group;sbits32_t model = 3; 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, v3group_tokens)) == 0) ||    (tbp->token_tag != TV3GUSER)) {    printf("V3Group: first token must be user name\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 security name */for (user_len = 0, cp2 = cp;     (*cp2 != '\n') && (*cp2 != ' ') && (*cp2 != '\t');     user_len++, cp2++)    ;MEMCPY(username, cp, user_len);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 had any bad values bail out */        if (error_cp != 0) {	    printf("v3group: illegal value for %s, group dropped\n",		   error_cp);	    return(0);	    }	if (group_len == 0) {	    printf("v3group: group name required\n");	    return(0);	    }	group = SNMP_Group_Create();	if (group == 0) {	    printf("v3group: unable to create group\n");	    return(1);	    }	SNMP_Group_Set_Status(group, stat);	if (storage)	    SNMP_Group_Set_Storage(group, storage);	if (SNMP_Group_Set_Group(group, groupname, group_len, BFL_IS_ALLOC) ||	    SNMP_Group_Install(group, model, username, user_len)) {	    printf("v3group: unable to build or install group\n");	    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, v3group_tokens)) == 0) {        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 TV3GUSER:	    /* if we had any bad info drop the group */	    if (error_cp != 0) {	        printf("v3group: illegal value for %s, group dropped\n",		       error_cp);	        }	    else if (group_len == 0) {	        printf("v3group: group name required\n");	        }	    else {	        group = SNMP_Group_Create();		if (group == 0) {		    printf("v3group: unable to create group\n");		    return(1);	            }		SNMP_Group_Set_Status(group, stat);		if (storage)		    SNMP_Group_Set_Storage(group, storage);		if (SNMP_Group_Set_Group(group, groupname,					 group_len, BFL_IS_ALLOC) ||		    SNMP_Group_Install(group, model, username, user_len)) {		    printf("v3group: unable to build or install group\n");		    return(1);	            }	        }	    /* now clean up any info we have */	    group = 0;	    group_len = 0;	    model = 3;	    stat = 1;	    storage = 0;	    user_len = i;	    MEMCPY(username, cp, user_len);            break;              case TV3GGROUP:            group_len = i;            MEMCPY(groupname, cp, group_len);            break;        case TV3GMODEL:	    sscanf(cp, "%d", &value);	    if (model != 3)	        error_cp = "model";	    model = value;            break;        case TV3GSTATUS:            sscanf(cp, "%d", &value);            if ((value >= ETC_RS_ACTIVE) && (value <= ETC_RS_DESTROY) &&                (value != ETC_RS_NREADY))	        stat = value;            else                error_cp = "status";            break;        case TV3GSTORAGE:            sscanf(cp, "%d", &value);            if ((value >= ETC_STO_OTHER) && (value <= ETC_STO_RONLY))	        storage = value;            else                error_cp = "storage";            break;        }    }}/****************************************************************************NAME: v3group_writePURPOSE: If required write the information from the group out to the         given file.	 The information we write is:	 user	 model	 group	 status	 storagePARAMETERS:	 SNMP_GROUP_T * oldgroup 	 SNMP_GROUP_T * newgroup			if oldgroup exists it contains the naming info			if newgroup exists it contains the rest of the info         FILE        *  the file to store the group inRETURNS: int    0 = success                other = failure****************************************************************************/int  v3group_write(SNMP_GROUP_T *oldgrp,		SNMP_GROUP_T *newgrp,		FILE         *outstream){int slen, status, storage;SNMP_

⌨️ 快捷键说明

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