📄 snmptargetparamsentry.c
字号:
snmpTargetParams_addSecModel(struct targetParamTable_struct *entry, char *cptr){ if (cptr == 0) { DEBUGMSGTL(("snmpTargetParamsEntry", "ERROR snmpTargetParamsEntry: no sec model in config string\n")); return (0); } else if (!(isdigit(*cptr))) { DEBUGMSGTL(("snmpTargetParamsEntry", "ERROR snmpTargeParamsEntry: security model is not digit in config string\n")); return (0); } /* * spec check Sec. Model > 0 */ else if ((entry->secModel = (int) strtol(cptr, (char **) NULL, 0)) <= 0) { DEBUGMSGTL(("snmpTargetParamsEntry", "ERROR snmpTargetParamsEntry: security model out of range in config string\n")); return (0); } return (1);} /* snmpTargetParams_addSecModel */intsnmpTargetParams_addSecName(struct targetParamTable_struct *entry, char *cptr){ size_t len; if (cptr == 0) { DEBUGMSGTL(("snmpTargetParamsEntry", "ERROR snmpTargetParamsEntry: no security name in config string\n")); return (0); } else { len = strlen(cptr); entry->secName = (char *) malloc(len + 1); strncpy(entry->secName, cptr, len); entry->secName[len] = '\0'; } return (1);} /* snmpTargetParams_addSecName */intsnmpTargetParams_addSecLevel(struct targetParamTable_struct *entry, char *cptr){ if (cptr == 0) { DEBUGMSGTL(("snmpTargetParamsEntry", "ERROR snmpTargetParamsEntry: no security level in config string\n")); return (0); } else if (!(isdigit(*cptr))) { DEBUGMSGTL(("snmpTargetParamsEntry", "ERROR snmpTargeParamsEntry: security level is not digit in config string\n")); return (0); } /* * no spec range check, but noAuthNoPriv is 1 so... */ else if ((entry->secLevel = (int) strtol(cptr, (char **) NULL, 0)) <= 0) { DEBUGMSGTL(("snmpTargetParamsEntry", "ERROR snmpTargeParamsEntry: security level is not greater than 0 in config string\n")); return (0); } return (1);} /* snmpTargetParams_addSecLevel */intsnmpTargetParams_addStorageType(struct targetParamTable_struct *entry, char *cptr){ if (cptr == 0) { DEBUGMSGTL(("snmpTargetParamsEntry", "ERROR snmpTargetParamsEntry: no storage type in config string\n")); return (0); } else if (!(isdigit(*cptr))) { DEBUGMSGTL(("snmpTargetParamsEntry", "ERROR snmpTargeParamsEntry: storage type is not digit in config string\n")); return (0); } /* * check that storage type is a possible value */ else if (((entry->storageType = (int) strtol(cptr, (char **) NULL, 0)) != SNMP_STORAGE_OTHER) && (entry->storageType != SNMP_STORAGE_VOLATILE) && (entry->storageType != SNMP_STORAGE_NONVOLATILE) && (entry->storageType != SNMP_STORAGE_PERMANENT) && (entry->storageType != SNMP_STORAGE_READONLY)) { DEBUGMSGTL(("snmpTargetParamsEntry", "ERROR snmpTargeParamsEntry: storage type is not a valid value of")); DEBUGMSG(("snmpTargetParamsEntry", " other(%d), volatile(%d), nonvolatile(%d), permanent(%d), or ", SNMP_STORAGE_OTHER, SNMP_STORAGE_VOLATILE, SNMP_STORAGE_NONVOLATILE, SNMP_STORAGE_PERMANENT)); DEBUGMSGTL(("snmpTargetParamsEntry", "readonly(%d) in config string.\n", SNMP_STORAGE_READONLY)); return (0); } return (1);} /* snmpTargetParams_addStorageType */intsnmpTargetParams_addRowStatus(struct targetParamTable_struct *entry, char *cptr){ if (cptr == 0) { DEBUGMSGTL(("snmpTargetParamsEntry", "ERROR snmpTargetParamsEntry: no row status in config string\n")); return (0); } else if (!(isdigit(*cptr))) { DEBUGMSGTL(("snmpTargetParamsEntry", "ERROR snmpTargeParamsEntry: row status is not digit in config string\n")); return (0); } /* * check that row status is a valid value */ else if (((entry->rowStatus = (int) strtol(cptr, (char **) NULL, 0)) != SNMP_ROW_ACTIVE) && (entry->rowStatus != SNMP_ROW_NOTINSERVICE) && (entry->rowStatus != SNMP_ROW_NOTREADY)) { DEBUGMSGTL(("snmpTargetParamsEntry", "ERROR snmpTargetParamsEntry: Row Status is not a valid value of ")); DEBUGMSG(("snmpTargetParamsEntry", "active(%d), notinservice(%d), or notready(%d) in config string.\n", SNMP_ROW_ACTIVE, SNMP_ROW_NOTINSERVICE, SNMP_ROW_NOTREADY)); return (0); } return (1);} /* snmpTargetParams_addRowStatus *//* * timestamp the current entry's modification time */voidupdate_timestamp(struct targetParamTable_struct *temp_struct){ temp_struct->updateTime = time(NULL);}voidsnmpd_parse_config_targetParams(const char *token, char *char_ptr){ char *cptr = char_ptr, buff[1024]; struct targetParamTable_struct *newEntry; newEntry = snmpTargetParamTable_create(); cptr = copy_nword(cptr, buff, sizeof(buff)); if (snmpTargetParams_addParamName(newEntry, buff) == 0) { snmpTargetParamTable_dispose(newEntry); return; } cptr = copy_nword(cptr, buff, sizeof(buff)); if (snmpTargetParams_addMPModel(newEntry, buff) == 0) { snmpTargetParamTable_dispose(newEntry); return; } cptr = copy_nword(cptr, buff, sizeof(buff)); if (snmpTargetParams_addSecModel(newEntry, buff) == 0) { snmpTargetParamTable_dispose(newEntry); return; } cptr = copy_nword(cptr, buff, sizeof(buff)); if (snmpTargetParams_addSecName(newEntry, buff) == 0) { snmpTargetParamTable_dispose(newEntry); return; } cptr = copy_nword(cptr, buff, sizeof(buff)); if (snmpTargetParams_addSecLevel(newEntry, buff) == 0) { snmpTargetParamTable_dispose(newEntry); return; } cptr = copy_nword(cptr, buff, sizeof(buff)); if (snmpTargetParams_addStorageType(newEntry, buff) == 0) { snmpTargetParamTable_dispose(newEntry); return; } cptr = copy_nword(cptr, buff, sizeof(buff)); if (snmpTargetParams_addRowStatus(newEntry, buff) == 0) { snmpTargetParamTable_dispose(newEntry); return; } snprintf(buff, sizeof(buff), "snmp_parse_config_targetParams, read: %s %d %d %s %d %d %d\n", newEntry->paramName, newEntry->mpModel, newEntry->secModel, newEntry->secName, newEntry->secLevel, newEntry->storageType, newEntry->rowStatus); buff[ sizeof(buff)-1 ] = 0; DEBUGMSGTL(("snmpTargetParamsEntry", buff)); update_timestamp(newEntry); snmpTargetParamTable_addToList(newEntry, &aPTable);} /* snmpd_parse_config_target *//* * shutdown routines *//* * store_snmpTargetParamsEntry handles the presistent storage proccess * for this MIB table. It writes out all the non-volatile rows * to permanent storage on a shutdown */intstore_snmpTargetParamsEntry(int majorID, int minorID, void *serverarg, void *clientarg){ struct targetParamTable_struct *curr_struct; char line[1024]; strcpy(line, ""); if ((curr_struct = aPTable) != 0) { while (curr_struct != 0) { if ((curr_struct->storageType == SNMP_STORAGE_NONVOLATILE || curr_struct->storageType == SNMP_STORAGE_PERMANENT) && (curr_struct->rowStatus == SNMP_ROW_ACTIVE || curr_struct->rowStatus == SNMP_ROW_NOTINSERVICE)) { snprintf(line, sizeof(line), "targetParams %s %i %i %s %i %i %i\n", curr_struct->paramName, curr_struct->mpModel, curr_struct->secModel, curr_struct->secName, curr_struct->secLevel, curr_struct->storageType, curr_struct->rowStatus); line[ sizeof(line)-1 ] = 0; /* * store to file */ snmpd_store_config(line); } curr_struct = curr_struct->next; } } return SNMPERR_SUCCESS;} /* store_snmpTargetParmsEntry *//* * MIB table access routines */u_char *var_snmpTargetParamsEntry(struct variable * vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method){ /* * variables we may use later */ static long long_ret; static unsigned char string[1500]; struct targetParamTable_struct *temp_struct; switch (vp->magic) { case SNMPTARGETPARAMSMPMODEL: *write_method = write_snmpTargetParamsMPModel; break; case SNMPTARGETPARAMSSECURITYMODEL: *write_method = write_snmpTargetParamsSecModel; break; case SNMPTARGETPARAMSSECURITYNAME: *write_method = write_snmpTargetParamsSecName; break; case SNMPTARGETPARAMSSECURITYLEVEL: *write_method = write_snmpTargetParamsSecLevel; break; case SNMPTARGETPARAMSSTORAGETYPE: *write_method = write_snmpTargetParamsStorageType; break; case SNMPTARGETPARAMSROWSTATUS: *write_method = write_snmpTargetParamsRowStatus; break; default: *write_method = NULL; } *var_len = sizeof(long_ret); /* assume an integer and change later if not */ /* * look for OID in current table */ if ((temp_struct = search_snmpTargetParamsTable(vp->name, vp->namelen, name, length, exact)) == 0) { return (0); } /* * We found what we were looking for, either the next OID or the exact OID */ /* * this is where we do the value assignments for the mib results. */ switch (vp->magic) { case SNMPTARGETPARAMSMPMODEL: /* * if unset value, (i.e. new row) */ if (temp_struct->mpModel == -1) return (0); long_ret = temp_struct->mpModel; return (unsigned char *) &long_ret; case SNMPTARGETPARAMSSECURITYMODEL: /* * if unset value, (i.e. new row) */ if (temp_struct->secModel == -1) return (0); long_ret = temp_struct->secModel; return (unsigned char *) &long_ret; case SNMPTARGETPARAMSSECURITYNAME: /* * if unset value, (i.e. new row) */ if (temp_struct->secName == 0) return (0); /* * including null character. */ memcpy(string, temp_struct->secName, strlen(temp_struct->secName)); string[strlen(temp_struct->secName)] = '\0'; *var_len = strlen(temp_struct->secName); return (unsigned char *) string; case SNMPTARGETPARAMSSECURITYLEVEL: /* * if unset value, (i.e. new row) */ if (temp_struct->secLevel == -1) return (0); long_ret = temp_struct->secLevel; return (unsigned char *) &long_ret;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -