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

📄 snmptargetparamsentry.c

📁 Snmp(简单网管协议)软件包。
💻 C
📖 第 1 页 / 共 3 页
字号:
    return(0);  }  return(1);}  /*  snmpTargetParams_addSecLevel  */  int snmpTargetParams_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  */int snmpTargetParams_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  */    void snmpd_parse_config_targetParams(     const char *token, char *char_ptr){  char *cptr = char_ptr, buff[1024];  struct targetParamTable_struct *newEntry;  newEntry = snmpTargetParamTable_create();    cptr = copy_word(cptr, buff);  if (snmpTargetParams_addParamName(newEntry, buff) == 0) {    snmpTargetParamTable_dispose(newEntry);    return;  }  cptr = copy_word(cptr, buff);  if (snmpTargetParams_addMPModel(newEntry, buff) == 0) {    snmpTargetParamTable_dispose(newEntry);    return;  }  cptr = copy_word(cptr, buff);  if (snmpTargetParams_addSecModel(newEntry, buff) == 0) {    snmpTargetParamTable_dispose(newEntry);    return;  }  cptr = copy_word(cptr, buff);  if (snmpTargetParams_addSecName(newEntry, buff) == 0) {    snmpTargetParamTable_dispose(newEntry);    return;  }  cptr = copy_word(cptr, buff);  if (snmpTargetParams_addSecLevel(newEntry, buff) == 0) {    snmpTargetParamTable_dispose(newEntry);    return;  }  cptr = copy_word(cptr, buff);  if (snmpTargetParams_addStorageType(newEntry, buff) == 0) {    snmpTargetParamTable_dispose(newEntry);    return;  }  cptr = copy_word(cptr, buff);  if (snmpTargetParams_addRowStatus(newEntry, buff) == 0) {    snmpTargetParamTable_dispose(newEntry);    return;  }  sprintf(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);  DEBUGMSGTL(("snmpTargetParamsEntry", buff));  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  */int store_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) ) {	sprintf(&line[strlen(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  );	/* 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;    *write_method = 0;           /* assume it isnt writable for the time being */  *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 ) {    if (vp->magic == SNMPTARGETPARAMSROWSTATUS)  {      *write_method = write_snmpTargetParamsRowStatus;    }    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:      *write_method = write_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:      *write_method = write_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:      *write_method = write_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:      *write_method = write_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;    case SNMPTARGETPARAMSSTORAGETYPE:      *write_method = write_snmpTargetParamsStorageType;      long_ret = temp_struct->storageType;      return (unsigned char *) &long_ret;    case SNMPTARGETPARAMSROWSTATUS:      *write_method = write_snmpTargetParamsRowStatus;      long_ret = temp_struct->rowStatus;      return (unsigned char *) &long_ret;    default:      DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_snmpTargetParamsEntry\n", vp->magic));  }  return 0;}  /* var_snmpTargetParamsEntry *//* timestamp the current entry's modification time */voidupdate_timestamp(struct targetParamTable_struct *temp_struct) {    temp_struct->updateTime = time(NULL);}/* Assign a value to the mpModel variable */intwrite_snmpTargetParamsMPModel(   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){  static long                    long_ret;  size_t                         size;  struct targetParamTable_struct *temp_struct;  /* check incoming variable */  if (var_val_type != ASN_INTEGER) {      DEBUGMSGTL(("snmpTargetParamsEntry","write to snmpTargetParamsMPModel : not ASN_INTEGER\n"));      return SNMP_ERR_WRONGTYPE;  }  if (var_val_len > (size = sizeof(long_ret))) {      DEBUGMSGTL(("snmpTargetParamsEntry","write to snmpTargetParamsMPModel : bad length\n"));      return SNMP_ERR_WRONGLENGTH;  }  long_ret = *((long *) var_val);  /* spec check range */  if (long_ret < 0) {    DEBUGMSGTL(("snmpTargetParamsEntry","write to snmpTargetParamsMPModel : MP Model out of range\n"));    return SNMP_ERR_INCONSISTENTVALUE;  }  /* Find row in linked list and check pertinent status... */  snmpTargetParamsOID[snmpTargetParamsOIDLen-1] = SNMPTARGETPARAMSMPMODELCOLUMN;  if ((temp_struct = search_snmpTargetParamsTable(snmpTargetParamsOID, snmpTargetParamsOIDLen, 				     name, &name_len, 1)) == 0 ) {    DEBUGMSGTL(("snmpTargetParamsEntry","write to snmpTargetParamsMPModel : BAD OID\n"));    return SNMP_ERR_NOSUCHNAME;  }  /* row exists, check if it is changeable */  if (temp_struct->storageType == SNMP_STORAGE_READONLY) {    DEBUGMSGTL(("snmpTargetParamsEntry","write to snmpTargetParamMPModel : row is read only\n"));    return SNMP_ERR_NOTWRITABLE;  }  /* check if row is active */  if (temp_struct->rowStatus == SNMP_ROW_ACTIVE) {    DEBUGMSGTL(("snmpTargetParamsEntry","write to snmpTargetParamsMPModel : This change not allowed in active row.\n"));    return SNMP_ERR_INCONSISTENTVALUE;  }  /* Finally, we're golden, should we save value? */  if (action == COMMIT)  {    temp_struct->mpModel = long_ret;    /* If row is new, check if its status can be updated */    if ( (temp_struct->rowStatus == SNMP_ROW_NOTREADY) &&	 (snmpTargetParams_rowStatusCheck(temp_struct) != 0) )      temp_struct->rowStatus = SNMP_ROW_NOTINSERVICE;    update_timestamp(temp_struct);  }  return SNMP_ERR_NOERROR;}  /* write_snmpTargetParamsMPModel *//* Assign a value to the Security Model variable */intwrite_snmpTargetParamsSecurityModel(   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){  static long                    long_ret;  size_t                         size;  struct targetParamTable_struct *temp_struct;  /* check incoming variable */  if (var_val_type != ASN_INTEGER) {      DEBUGMSGTL(("snmpTargetParamsEntry","write to snmpTargetParamsSecurityModel : not ASN_INTEGER\n"));      return SNMP_ERR_WRONGTYPE;  }  if (var_val_len > (size = sizeof(long_ret))) {      DEBUGMSGTL(("snmpTargetParamsEntry","write to snmpTargetParamsSecurityModel : bad length\n"));      return SNMP_ERR_WRONGLENGTH;  }  long_ret = *((long *) var_val);  /* spec check range */  if (long_ret <= 0)  {    DEBUGMSGTL(("snmpTargetParamsEntry","write to snmpTargetParamsSecModel : Security Model out of range\n"));    return SNMP_ERR_INCONSISTENTVALUE;  }  /* Find struct in linked list and check row status */  snmpTargetParamsOID[snmpTargetParamsOIDLen-1] = SNMPTARGETPARAMSSECURITYMODELCOLUMN;  if ((temp_struct = search_snmpTargetParamsTable(snmpTargetParamsOID, snmpTargetParamsOIDLen, 				     name, &name_len, 1)) == 0 ) {    DEBUGMSGTL(("snmpTargetParamsEntry","write to snmpTargetParamSecurityModel : BAD OID!\n"));      return SNMP_ERR_NOSUCHNAME;  }  /* row exists, check if it is changeable */  if (temp_struct->storageType == SNMP_STORAGE_READONLY) {    DEBUGMSGTL(("snmpTargetParamsEntry","write to snmpTargetParamSecurityModel : row is read only\n"));    return SNMP_ERR_NOTWRITABLE;  }  /* check if row active */  if (temp_struct->rowStatus == SNMP_ROW_ACTIVE) {    DEBUGMSGTL(("snmpTargetParamsEntry","write to snmpTargetParamSecurityModel : This change not allowed in active row.\n"));    return SNMP_ERR_INCONSISTENTVALUE;  }

⌨️ 快捷键说明

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