📄 usmuser.c
字号:
} /* end write_usmUserPublic() */intwrite_usmUserStorageType(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){ long long_ret = *((long *) var_val); static long oldValue; struct usmUser *uptr; static int resetOnFail; if (action == RESERVE1) { resetOnFail = 0; if (var_val_type != ASN_INTEGER) { DEBUGMSGTL(("usmUser", "write to usmUserStorageType not ASN_INTEGER\n")); return SNMP_ERR_WRONGTYPE; } if (var_val_len != sizeof(long)) { DEBUGMSGTL(("usmUser", "write to usmUserStorageType: bad length\n")); return SNMP_ERR_WRONGLENGTH; } if (long_ret < 1 || long_ret > 5) { return SNMP_ERR_WRONGVALUE; } } else if (action == RESERVE2) { if ((uptr = usm_parse_user(name, name_len)) == NULL) { return SNMP_ERR_INCONSISTENTNAME; } if ((long_ret == ST_VOLATILE || long_ret == ST_NONVOLATILE) && (uptr->userStorageType == ST_VOLATILE || uptr->userStorageType == ST_NONVOLATILE)) { oldValue = uptr->userStorageType; uptr->userStorageType = long_ret; resetOnFail = 1; } else { /* * From RFC2574: * * "Note that any user who employs authentication or privacy must * allow its secret(s) to be updated and thus cannot be 'readOnly'. * * If an initial set operation tries to set the value to 'readOnly' * for a user who employs authentication or privacy, then an * 'inconsistentValue' error must be returned. Note that if the * value has been previously set (implicit or explicit) to any * value, then the rules as defined in the StorageType Textual * Convention apply. */ DEBUGMSGTL(("usmUser", "long_ret %d uptr->st %d uptr->status %d\n", long_ret, uptr->userStorageType, uptr->userStatus)); if (long_ret == ST_READONLY && uptr->userStorageType != ST_READONLY && (uptr->userStatus == RS_ACTIVE || uptr->userStatus == RS_NOTINSERVICE)) { return SNMP_ERR_WRONGVALUE; } else if (long_ret == ST_READONLY && (snmp_oid_compare (uptr->privProtocol, uptr->privProtocolLen, usmNoPrivProtocol, sizeof(usmNoPrivProtocol) / sizeof(oid)) != 0 || snmp_oid_compare(uptr->authProtocol, uptr->authProtocolLen, usmNoAuthProtocol, sizeof(usmNoAuthProtocol) / sizeof(oid)) != 0)) { return SNMP_ERR_INCONSISTENTVALUE; } else { return SNMP_ERR_WRONGVALUE; } } } else if (action == UNDO || action == FREE) { if ((uptr = usm_parse_user(name, name_len)) != NULL && resetOnFail) { uptr->userStorageType = oldValue; } } return SNMP_ERR_NOERROR;} /* end write_usmUserStorageType() *//* * Return 1 if enough objects have been set up to transition rowStatus to * notInService(2) or active(1). */intusmStatusCheck(struct usmUser *uptr){ if (uptr == NULL) { return 0; } else { if (uptr->cloneFrom == NULL) { return 0; } } return 1;}/*******************************************************************-o-****** * write_usmUserStatus * * Parameters: * action * *var_val * var_val_type * var_val_len * *statP * *name * name_len * * Returns: * SNMP_ERR_NOERROR On success. * SNMP_ERR_GENERR * SNMP_ERR_INCONSISTENTNAME * SNMP_ERR_INCONSISTENTVALUE * SNMP_ERR_WRONGLENGTH * SNMP_ERR_WRONGTYPE */intwrite_usmUserStatus(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; unsigned char *engineID; size_t engineIDLen; char *newName; size_t nameLen; struct usmUser *uptr = NULL; if (action == RESERVE1) { if (var_val_type != ASN_INTEGER) { DEBUGMSGTL(("usmUser", "write to usmUserStatus not ASN_INTEGER\n")); return SNMP_ERR_WRONGTYPE; } if (var_val_len != sizeof(long_ret)) { DEBUGMSGTL(("usmUser", "write to usmUserStatus: bad length\n")); return SNMP_ERR_WRONGLENGTH; } long_ret = *((long *) var_val); if (long_ret == RS_NOTREADY || long_ret < 1 || long_ret > 6) { return SNMP_ERR_WRONGVALUE; } /* * See if we can parse the oid for engineID/name first. */ if (usm_parse_oid(&name[USM_MIB_LENGTH], name_len - USM_MIB_LENGTH, &engineID, &engineIDLen, (u_char **) & newName, &nameLen)) { return SNMP_ERR_INCONSISTENTNAME; } if (engineIDLen < 5 || engineIDLen > 32 || nameLen < 1 || nameLen > 32) { SNMP_FREE(engineID); SNMP_FREE(newName); return SNMP_ERR_NOCREATION; } /* * Now see if a user already exists with these index values. */ uptr = usm_get_user(engineID, engineIDLen, newName); if (uptr != NULL) { if (long_ret == RS_CREATEANDGO || long_ret == RS_CREATEANDWAIT) { SNMP_FREE(engineID); SNMP_FREE(newName); long_ret = RS_NOTREADY; return SNMP_ERR_INCONSISTENTVALUE; } SNMP_FREE(engineID); SNMP_FREE(newName); } else { if (long_ret == RS_ACTIVE || long_ret == RS_NOTINSERVICE) { SNMP_FREE(engineID); SNMP_FREE(newName); return SNMP_ERR_INCONSISTENTVALUE; } if (long_ret == RS_CREATEANDGO || long_ret == RS_CREATEANDWAIT) { if ((uptr = usm_create_user()) == NULL) { SNMP_FREE(engineID); SNMP_FREE(newName); return SNMP_ERR_RESOURCEUNAVAILABLE; } uptr->engineID = engineID; uptr->name = newName; uptr->secName = strdup(uptr->name); if (uptr->secName == NULL) { usm_free_user(uptr); return SNMP_ERR_RESOURCEUNAVAILABLE; } uptr->engineIDLen = engineIDLen; /* * Set status to createAndGo or createAndWait so we can tell * that this row is under creation. */ uptr->userStatus = long_ret; /* * Add to the list of users (we will take it off again * later if something goes wrong). */ usm_add_user(uptr); } else { SNMP_FREE(engineID); SNMP_FREE(newName); } } } else if (action == ACTION) { usm_parse_oid(&name[USM_MIB_LENGTH], name_len - USM_MIB_LENGTH, &engineID, &engineIDLen, (u_char **) & newName, &nameLen); uptr = usm_get_user(engineID, engineIDLen, newName); SNMP_FREE(engineID); SNMP_FREE(newName); if (uptr != NULL) { if (long_ret == RS_CREATEANDGO || long_ret == RS_ACTIVE) { if (usmStatusCheck(uptr)) { uptr->userStatus = RS_ACTIVE; } else { SNMP_FREE(engineID); SNMP_FREE(newName); return SNMP_ERR_INCONSISTENTVALUE; } } else if (long_ret == RS_CREATEANDWAIT) { if (usmStatusCheck(uptr)) { uptr->userStatus = RS_NOTINSERVICE; } else { uptr->userStatus = RS_NOTREADY; } } else if (long_ret == RS_NOTINSERVICE) { if (uptr->userStatus == RS_ACTIVE || uptr->userStatus == RS_NOTINSERVICE) { uptr->userStatus = RS_NOTINSERVICE; } else { return SNMP_ERR_INCONSISTENTVALUE; } } } } else if (action == COMMIT) { usm_parse_oid(&name[USM_MIB_LENGTH], name_len - USM_MIB_LENGTH, &engineID, &engineIDLen, (u_char **) & newName, &nameLen); uptr = usm_get_user(engineID, engineIDLen, newName); SNMP_FREE(engineID); SNMP_FREE(newName); if (uptr != NULL) { if (long_ret == RS_DESTROY) { usm_remove_user(uptr); usm_free_user(uptr); } } } else if (action == UNDO || action == FREE) { usm_parse_oid(&name[USM_MIB_LENGTH], name_len - USM_MIB_LENGTH, &engineID, &engineIDLen, (u_char **) & newName, &nameLen); uptr = usm_get_user(engineID, engineIDLen, newName); SNMP_FREE(engineID); SNMP_FREE(newName); if (long_ret == RS_CREATEANDGO || long_ret == RS_CREATEANDWAIT) { usm_remove_user(uptr); usm_free_user(uptr); } } return SNMP_ERR_NOERROR;}#if 0 /* * see if we can parse the oid for engineID/name first */if (usm_parse_oid(&name[USM_MIB_LENGTH], name_len - USM_MIB_LENGTH, &engineID, &engineIDLen, (u_char **) & newName, &nameLen)) return SNMP_ERR_INCONSISTENTNAME; /* * Now see if a user already exists with these index values */uptr = usm_get_user(engineID, engineIDLen, newName);if (uptr) { /* If so, we set the appropriate value... */ free(engineID); free(newName); if (long_ret == RS_CREATEANDGO || long_ret == RS_CREATEANDWAIT) { return SNMP_ERR_INCONSISTENTVALUE; } if (long_ret == RS_DESTROY) { usm_remove_user(uptr); usm_free_user(uptr); } else { uptr->userStatus = long_ret; }} else { /* ...else we create a new user */ /* * check for a valid status column set */ if (long_ret == RS_ACTIVE || long_ret == RS_NOTINSERVICE) { free(engineID); free(newName); return SNMP_ERR_INCONSISTENTVALUE; } if (long_ret == RS_DESTROY) { /* * destroying a non-existent row is actually legal */ free(engineID); free(newName); return SNMP_ERR_NOERROR; } /* * generate a new user */ if ((uptr = usm_create_user()) == NULL) { free(engineID); free(newName); return SNMP_ERR_GENERR; } /* * copy in the engineID */ uptr->engineID = (unsigned char *) malloc(engineIDLen); if (uptr->engineID == NULL) { free(engineID); free(newName); usm_free_user(uptr); return SNMP_ERR_GENERR; } uptr->engineIDLen = engineIDLen; memcpy(uptr->engineID, engineID, engineIDLen); free(engineID); /* * copy in the name and secname */ if ((uptr->name = strdup(newName)) == NULL) { free(newName); usm_free_user(uptr); return SNMP_ERR_GENERR; } free(newName); if ((uptr->secName = strdup(uptr->name)) == NULL) { usm_free_user(uptr); return SNMP_ERR_GENERR; } /* * set the status of the row based on the request */ if (long_ret == RS_CREATEANDGO) uptr->userStatus = RS_ACTIVE; else if (long_ret == RS_CREATEANDWAIT) uptr->userStatus = RS_NOTINSERVICE; /* * finally, add it to our list of users */ usm_add_user(uptr);} /* endif -- uptr */} /* endif -- action==COMMIT */return SNMP_ERR_NOERROR;} /* end write_usmUserStatus() */#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -