📄 vacm_vars.c
字号:
} if (op != name + *length) { return NULL; } gp = vacm_getViewEntry(viewName, subtree, subtreeLen); if(gp) if(gp->viewSubtreeLen!=subtreeLen) gp=NULL; } else { viewName[0] = 0; op = name+12; if (op >= name + *length) { } else { len = *op; if (len > VACM_MAX_STRING) return 0; cp = viewName; while (len-- >= 0 && op < name + *length) { if (*op > 255) return 0; *cp++ = (char) *op++; } *cp = 0; } if (op >= name + *length) { } else { len = *op++; op1 = subtree; *op1++ = len; subtreeLen++; while (len-- >= 0 && op < name + *length) { *op1++ = *op++; subtreeLen++; } } vacm_scanViewInit(); while ((gp = vacm_scanViewNext()) != NULL) { cmp = strcmp(gp->viewName, viewName); cmp2 = snmp_oid_compare(gp->viewSubtree, gp->viewSubtreeLen, subtree, subtreeLen); if (cmp == 0 && cmp2 > 0) break; if (cmp > 0) break; } if (gp) { *length = 12; cp = gp->viewName; do { name[(*length)++] = *cp++; } while (*cp); op1 = gp->viewSubtree; len = gp->viewSubtreeLen; while (len-- > 0){ name[(*length)++] = *op1++; } } } if (!gp && !exact) return NULL; } else { if(header_generic(vp,name,length,exact,var_len,write_method)) return NULL; } /*endif -- vp->magic != VACMVIEWSPINLOCK */ switch (vp->magic) { case VACMVIEWSPINLOCK: *write_method = write_vacmViewSpinLock; long_return = vacmViewSpinLock; return (unsigned char *) &long_return; case VIEWNAME: if(gp) { *var_len = gp->viewName[0]; return (u_char *)&gp->viewName[1]; } return NULL; case VIEWSUBTREE: if(gp) { *var_len = gp->viewSubtreeLen*sizeof(oid); return (u_char *)gp->viewSubtree; } return NULL; case VIEWMASK: *write_method=write_vacmViewMask; if(gp) { *var_len = (gp->viewSubtreeLen + 7) / 8; return (u_char *)gp->viewMask; } return NULL; case VIEWTYPE: *write_method=write_vacmViewType; if(gp) { long_return = gp->viewType; return (u_char *)&long_return; } return NULL; case VIEWSTORAGE: *write_method=write_vacmViewStorageType; if(gp) { long_return = gp->viewStorageType; return (u_char *)&long_return; } return NULL; case VIEWSTATUS: *write_method=write_vacmViewStatus; if(gp) { long_return = gp->viewStatus; return (u_char *)&long_return; } return NULL; } return NULL;}oid *sec2group_generate_OID(oid *prefix, size_t prefixLen, struct vacm_groupEntry *geptr, size_t *length){ oid *indexOid; int i,securityNameLen; securityNameLen=strlen(geptr->securityName); *length = 2 + securityNameLen + prefixLen; indexOid = (oid *) malloc(*length * sizeof(oid)); if (indexOid) { memmove(indexOid, prefix, prefixLen * sizeof (oid)); indexOid[prefixLen] = geptr->securityModel; indexOid[prefixLen+1]= securityNameLen; for(i = 0; i < securityNameLen; i++) indexOid[prefixLen+2+i] = (oid) geptr->securityName[i]; } return indexOid;}int sec2group_parse_oid(oid *oidIndex, size_t oidLen, int *model, unsigned char **name, size_t *nameLen){ int nameL; int i; /* first check the validity of the oid */ if ((oidLen <= 0) || (!oidIndex)) { return 1; } nameL = oidIndex[1]; /* the initial name length */ if ((int)oidLen != nameL + 2) { return 1; } /* its valid, malloc the space and store the results */ if (name == NULL) { return 1; } *name = (unsigned char *) malloc(nameL+1); if (*name == NULL) { return 1; } *model = oidIndex[0]; *nameLen = nameL; for(i = 0; i < nameL; i++) { if (oidIndex[i+2] > 255) { free(*name); return 1; } name[0][i] = (unsigned char) oidIndex[i+2]; } name[0][nameL] = 0; return 0;} struct vacm_groupEntry *sec2group_parse_groupEntry(oid *name, size_t name_len){ struct vacm_groupEntry *geptr; char *newName; int model; size_t nameLen; /* get the name and engineID out of the incoming oid */ if (sec2group_parse_oid(&name[SEC2GROUP_MIB_LENGTH], name_len-SEC2GROUP_MIB_LENGTH, &model, (u_char **)&newName, &nameLen)) return NULL; /* Now see if a user exists with these index values */ geptr = vacm_getGroupEntry(model, newName); free(newName); return geptr;} /* end vacm_parse_groupEntry() */intwrite_vacmGroupName(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len){ /* variables we may use later */ static unsigned char string[SNMP_MAXBUF]; struct vacm_groupEntry *geptr; if (var_val_type != ASN_OCTET_STR){ DEBUGMSGTL(("mibII/vacm_vars","write to vacmGroupName not ASN_OCTET_STR\n")); return SNMP_ERR_WRONGTYPE; } if (var_val_len > sizeof(string)){ DEBUGMSGTL(("mibII/vacm_vars","write to vacmGroupName: bad length\n")); return SNMP_ERR_WRONGLENGTH; } if (action == COMMIT) { /* don't allow creations here */ if ((geptr = sec2group_parse_groupEntry(name, name_len)) == NULL) { return SNMP_ERR_NOSUCHNAME; } memcpy(geptr->groupName, var_val, var_val_len); geptr->groupName[var_val_len] = 0; } return SNMP_ERR_NOERROR;}intwrite_vacmSecurityToGroupStorageType(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len){ /* variables we may use later */ static long long_ret; struct vacm_groupEntry *geptr; if (var_val_type != ASN_INTEGER){ DEBUGMSGTL(("mibII/vacm_vars","write to vacmSecurityToGroupStorageType not ASN_INTEGER\n")); return SNMP_ERR_WRONGTYPE; } if (var_val_len > sizeof(long_ret)){ DEBUGMSGTL(("mibII/vacm_vars","write to vacmSecurityToGroupStorageType: bad length\n")); return SNMP_ERR_WRONGLENGTH; } if (action == COMMIT){ /* don't allow creations here */ if ((geptr = sec2group_parse_groupEntry(name, name_len)) == NULL) { return SNMP_ERR_NOSUCHNAME; } long_ret = *((long *) var_val); if ((long_ret == ST_VOLATILE || long_ret == ST_NONVOLATILE) && (geptr->storageType == ST_VOLATILE || geptr->storageType == ST_NONVOLATILE)) geptr->storageType = long_ret; else return SNMP_ERR_INCONSISTENTVALUE; } return SNMP_ERR_NOERROR;}intwrite_vacmSecurityToGroupStatus(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len){ /* variables we may use later */ static long long_ret; int model; char *newName; size_t nameLen; struct vacm_groupEntry *geptr; if (var_val_type != ASN_INTEGER){ DEBUGMSGTL(("mibII/vacm_vars","write to vacmSecurityToGroupStatus not ASN_INTEGER\n")); return SNMP_ERR_WRONGTYPE; } if (var_val_len > sizeof(long_ret)){ DEBUGMSGTL(("mibII/vacm_vars","write to vacmSecurityToGroupStatus: bad length\n")); return SNMP_ERR_WRONGLENGTH; } if (action == COMMIT){ long_ret = *((long *) var_val); /* ditch illegal values now */ /* notReady can not be used, but the return error code is not mentioned */ if (long_ret == RS_NOTREADY || long_ret < 1 || long_ret > 6) return SNMP_ERR_INCONSISTENTVALUE; /* see if we can parse the oid for model/name first */ if (sec2group_parse_oid(&name[SEC2GROUP_MIB_LENGTH], name_len-SEC2GROUP_MIB_LENGTH, &model, (u_char **)&newName, &nameLen)) return SNMP_ERR_INCONSISTENTNAME; /* Now see if a group already exists with these index values */ geptr = vacm_getGroupEntry(model, newName); if (geptr) { /* If so, we set the appropriate value... */ if (long_ret == RS_CREATEANDGO || long_ret == RS_CREATEANDWAIT) { return SNMP_ERR_INCONSISTENTVALUE; } if (long_ret == RS_DESTROY) { vacm_destroyGroupEntry(model,newName); } else { geptr->status = long_ret; } free(newName); } else { /* ...else we create a new group entry */ /* check for a valid status column set */ if (long_ret == RS_ACTIVE || long_ret == RS_NOTINSERVICE) { free(newName); return SNMP_ERR_INCONSISTENTVALUE; } if (long_ret == RS_DESTROY) { /* destroying a non-existent row is actually legal */ free(newName); return SNMP_ERR_NOERROR; } /* generate a new group entry */ if ((geptr = vacm_createGroupEntry(model,newName)) == NULL) { free(newName); return SNMP_ERR_GENERR; } /*set default storage type*/ geptr->storageType = ST_NONVOLATILE; /* set the status of the row based on the request */ if (long_ret == RS_CREATEANDGO) geptr->status = RS_ACTIVE; else if (long_ret == RS_CREATEANDWAIT) geptr->status = RS_NOTINSERVICE; } /* endif -- uptr */ } /* endif -- action==COMMIT */ return SNMP_ERR_NOERROR;}oid *access_generate_OID(oid *prefix, size_t prefixLen, struct vacm_accessEntry *aptr, size_t *length){ oid *indexOid; int i,groupNameLen,contextPrefixLen; groupNameLen=strlen(aptr->groupName); contextPrefixLen=strlen(aptr->contextPrefix); *length = 4 + groupNameLen + contextPrefixLen + prefixLen; indexOid = (oid *) malloc(*length * sizeof(oid)); if (indexOid) { memmove(indexOid, prefix, prefixLen * sizeof (oid)); indexOid[prefixLen]=groupNameLen; for(i = 0; i < groupNameLen; i++) indexOid[groupNameLen+1+i] = (oid) aptr->groupName[i]; indexOid[prefixLen+groupNameLen+1]=contextPrefixLen; for(i = 0; i < contextPrefixLen; i++) indexOid[prefixLen+groupNameLen+2+i] = (oid) aptr->contextPrefix[i]; indexOid[prefixLen+groupNameLen+contextPrefixLen+3] = aptr->securityModel; indexOid[prefixLen+groupNameLen+contextPrefixLen+4] = aptr->securityLevel; } return indexOid;}int access_parse_oid(oid *oidIndex, size_t oidLen, unsigned char **groupName, size_t *groupNameLen, unsigned char **contextPrefix, size_t *contextPrefixLen, int *model, int *level){ int groupNameL,contextPrefixL; int i; /* first check the validity of the oid */ if ((oidLen <= 0) || (!oidIndex)) { return 1; } groupNameL=oidIndex[0]; contextPrefixL = oidIndex[groupNameL+1]; /* the initial name length */ if ((int)oidLen != groupNameL+contextPrefixL + 4) { return 1; } /* its valid, malloc the space and store the results */ if (contextPrefix == NULL || groupName == NULL) { return 1; } *groupName = (unsigned char *) malloc(groupNameL+1); if (*groupName == NULL) { return 1; } *contextPrefix = (unsigned char *) malloc(contextPrefixL+1); if (*contextPrefix == NULL) { free(*groupName); return 1; } *contextPrefixLen = contextPrefixL; *groupNameLen = groupNameL; for(i = 0; i < groupNameL; i++) { if (oidIndex[i+1] > 255) { free(*groupName); free(*contextPrefix); return 1; } groupName[0][i] = (unsigned char) oidIndex[i+1]; } groupName[0][groupNameL] = 0; for(i = 0; i < contextPrefixL; i++) { if (oidIndex[i+groupNameL+2] > 255) { free(*groupName); free(*contextPrefix); return 1; } contextPrefix[0][i] = (unsigned char) oidIndex[i+groupNameL+2]; } contextPrefix[0][contextPrefixL] = 0; *model = oidIndex[groupNameL+contextPrefixL+2]; *level = oidIndex[groupNameL+contextPrefixL+3]; return 0;} struct vacm_accessEntry *access_parse_accessEntry(oid *name, size_t name_len){ struct vacm_accessEntry *aptr; char *newGroupName; char *newContextPrefix; int model,level; size_t groupNameLen,contextPrefixLen; /* get the name and engineID out of the incoming oid */ if (access_parse_oid(&name[ACCESS_MIB_LENGTH], name_len-ACCESS_MIB_LENGTH, (u_char **)&newGroupName, &groupNameLen, (u_char **)&newContextPrefix, &contextPrefixLen, &model, &level)) return NULL; /* Now see if a user exists with these index values */ aptr = vacm_getAccessEntry(newGroupName, newContextPrefix, model, level); free(newContextPrefix); free(newGroupName); return aptr;} /* end vacm_parse_accessEntry() */intwrite_vacmAccessStatus(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len){ /* variables we may use later */ static long long_ret; int model,level; char *newGroupName,*newContextPrefix; size_t groupNameLen,contextPrefixLen; struct vacm_accessEntry *aptr; if (var_val_type != ASN_INTEGER){ DEBUGMSGTL(("mibII/vacm_vars","write to vacmSecurityToGroupStatus not ASN_INTEGER\n")); return SNMP_ERR_WRONGTYPE; } if (var_val_len > sizeof(long_ret)){ DEBUGMSGTL(("mibII/vacm_vars","write to vacmSecurityToGroupStatus: bad length\n")); return SNMP_ERR_WRONGLENGTH; } if (action == COMMIT){ long_ret = *((long *) var_val); /* ditch illegal values now */ /* notReady can not be used, but the return error code is not mentioned */ if (long_ret == RS_NOTREADY || long_ret < 1 || long_ret > 6) return SNMP_ERR_INCONSISTENTVALUE; /* see if we can parse the oid for model/name first */ if (access_parse_oid(&name[ACCESS_MIB_LENGTH], name_len-ACCESS_MIB_LENGTH, (u_char **)&newGroupName, &groupNameLen, (u_char **)&newContextPrefix, &contextPrefixLen, &model,&level)) return SNMP_ERR_INCONSISTENTNAME; /* Now see if a group already exists with these index values */ aptr = vacm_getAccessEntry(newGroupName,newContextPrefix,model,level); if (aptr) { /* If so, we set the appropriate value... */ if (long_ret == RS_CREATEANDGO || long_ret == RS_CREATEANDWAIT) { return SNMP_ERR_INCONSISTENTVALUE; } if (long_ret == RS_DESTROY) { vacm_destroyAccessEntry(newGroupName,newContextPrefix,model,level); } else { aptr->status = long_ret; } free(newGroupName); free(newContextPrefix); } else { /* ...else we create a new group entry */ /* check for a valid status column set */ if (long_ret == RS_ACTIVE || long_ret == RS_NOTINSERVICE) { free(newGroupName); free(newContextPrefix); return SNMP_ERR_INCONSISTENTVALUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -