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

📄 vacm_vars.c

📁 ucd-snmp源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	}	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 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;	}    	if (model < 1 || nameLen < 1 || nameLen > 32 ) {	    free(newName);	    return SNMP_ERR_NOCREATION;	}	/*  Now see if a group already exists with these index values.  */	geptr = vacm_getGroupEntry(model, newName);	if (geptr != NULL) {	    if (long_ret == RS_CREATEANDGO || long_ret == RS_CREATEANDWAIT) {		free(newName);		long_ret = RS_NOTREADY;		return SNMP_ERR_INCONSISTENTVALUE;	    }	} else {	    if (long_ret == RS_ACTIVE || long_ret == RS_NOTINSERVICE) {		free(newName);		return SNMP_ERR_INCONSISTENTVALUE;	    }	    if (long_ret == RS_CREATEANDGO || long_ret == RS_CREATEANDWAIT) {		/*  Generate a new group entry.  */		if ((geptr = vacm_createGroupEntry(model, newName)) == NULL) {		    free(newName);		    return SNMP_ERR_GENERR;		}		/*  Set defaults.  */		geptr->storageType = ST_NONVOLATILE;		geptr->status = RS_NOTREADY;	    }	}	free(newName);    } else if (action == ACTION) {	sec2group_parse_oid(&name[SEC2GROUP_MIB_LENGTH],			    name_len-SEC2GROUP_MIB_LENGTH,			    &model, (u_char **)&newName, &nameLen);	geptr = vacm_getGroupEntry(model, newName);	if (geptr != NULL) {	    if (long_ret == RS_CREATEANDGO || long_ret == RS_ACTIVE) {		/* Check that all the mandatory objects have been set by now,		   otherwise return inconsistentValue.  */		if (geptr->groupName[0] == 0) {		    free(newName);		    return SNMP_ERR_INCONSISTENTVALUE;		}		geptr->status = RS_ACTIVE;	    } else if (long_ret == RS_CREATEANDWAIT) {		if (geptr->groupName[0] != 0) {		    geptr->status = RS_NOTINSERVICE;		}	    } else if (long_ret == RS_NOTINSERVICE) {		if (geptr->status == RS_ACTIVE) {		    geptr->status = RS_NOTINSERVICE;		} else if (geptr->status == RS_NOTREADY) {		    free(newName);		    return SNMP_ERR_INCONSISTENTVALUE;		}	    }	}	free(newName);    } else if (action == COMMIT) {	sec2group_parse_oid(&name[SEC2GROUP_MIB_LENGTH],			    name_len-SEC2GROUP_MIB_LENGTH,			    &model, (u_char **)&newName, &nameLen);	geptr = vacm_getGroupEntry(model, newName);	if (geptr != NULL) {	    if (long_ret == RS_DESTROY) {		vacm_destroyGroupEntry(model, newName);        	    }	}	free(newName);    } else if (action == UNDO) {	if (long_ret == RS_CREATEANDGO || long_ret == RS_CREATEANDWAIT) {	    sec2group_parse_oid(&name[SEC2GROUP_MIB_LENGTH],				name_len-SEC2GROUP_MIB_LENGTH,				&model, (u_char **)&newName, &nameLen);	    geptr = vacm_getGroupEntry(model, newName);	    if (geptr != NULL) {		vacm_destroyGroupEntry(model, newName);        	    }	    free(newName);	}    }    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){  static long long_ret;  int model, level;  char *newGroupName, *newContextPrefix;  size_t groupNameLen, contextPrefixLen;  struct vacm_accessEntry *aptr = NULL;  if (action == RESERVE1) {      if (var_val_type != ASN_INTEGER) {	  return SNMP_ERR_WRONGTYPE;      }      if (var_val_len != sizeof(long_ret)) {	  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 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;      }            if (model < 0 || groupNameLen < 1 || groupNameLen > 32 || 	  contextPrefixLen > 32) {	  free(newGroupName);	  free(newContextPrefix);	  return SNMP_ERR_NOCREATION;      }            /*  Now see if a group already exists with these index values.  */      aptr = vacm_getAccessEntry(newGroupName, newContextPrefix, model, level);      if (aptr != NULL) {	  if (long_ret == RS_CREATEANDGO || long_ret == RS_CREATEANDWAIT) {	      free(newGroupName);	      free(newContextPrefix);	      return SNMP_ERR_INCONSISTENTVALUE;	  }      } else {	  if (long_ret == RS_ACTIVE || long_ret == RS_NOTINSERVICE) {	      free(newGroupName);	      free(newContextPrefix);	      return SNMP_ERR_INCONSISTENTVALUE;	  }	  if (long_ret == RS_CREATEANDGO || long_ret == RS_CREATEANDWAIT) {	      if ((aptr = vacm_createAccessEntry(newGroupName,						 newContextPrefix,						 model, level)) == NULL) {		  free(newGroupName);		  free(newContextPrefix);		  return SNMP_ERR_GENERR;	      }	      /*  Set defaults.  */	      aptr->contextMatch = 1;  /*  exact(1) is the DEFVAL  */	      aptr->storageType = ST_NONVOLATILE;	      aptr->status = RS_NOTREADY;	  }      }      free(newGroupName);      free(newContextPrefix);  } else if (action == ACTION) {      access_parse_oid(&name[ACCESS_MIB_LENGTH], name_len-ACCESS_MIB_LENGTH,		       (u_char **)&newGroupName, &groupNameLen,		       (u_char **)&newContextPrefix, &contextPrefixLen,		       &model, &level);      aptr = vacm_getAccessEntry(newGroupName, newContextPrefix, model, level);      if (aptr != NULL) {	  if (long_ret == RS_CREATEANDGO || long_ret == RS_ACTIVE) {	      aptr->status = RS_ACTIVE;	    } else if (long_ret == RS_CREATEANDWAIT) {		aptr->status = RS_NOTINSERVICE;	    } else if (long_ret == RS_NOTINSERVICE) {		if (aptr->status == RS_ACTIVE) {		    aptr->status = RS_NOTINSERVICE;		} else if (aptr->status == RS_NOTREADY) {		    free(newGroupName);		    free(newContextPrefix);		    return SNMP_ERR_INCONSISTENTVALUE;		}	    }      }      free(newGroupName);      free(newContextPrefix);  } else if (action == COMMIT) {      access_parse_oid(&name[ACCESS_MIB_LENGTH], name_len-ACCESS_MIB_LENGTH,		       (u_char **)&newGroupName, &groupNameLen,		       (u_char **)&newContextPrefix, &contextPrefixLen,		       &model, &level);      aptr = vacm_getAccessEntry(newGroupName, newContextPrefix, model, level);      if (aptr) {	  if (long_ret == RS_DESTROY) {	      vacm_destroyAccessEntry(newGroupName, newContextPrefix,				      model, level);	  }      }      free(newGroupName);      free(newContextPrefix);  } else if (action == UNDO) {      if (long_ret == RS_CREATEANDGO || long_ret == RS_CREATEANDWAIT) {	  access_parse_oid(&name[ACCESS_MIB_LENGTH], 			   name_len-ACCESS_MIB_LENGTH,			   (u_char **)&newGroupName, &groupNameLen,			   (u_char **)&newContextPrefix, &contextPrefixLen,			   &model, &level);	  aptr = vacm_getAccessEntry(newGroupName, newContextPrefix, 				     model, level);	  if (aptr != NULL) {	      vacm_destroyAccessEntry(newGroupName, newContextPrefix,				      model, level);	  }      }      free(newGroupName);      free(newContextPrefix);  }  return SNMP_ERR_NOERROR;}intwrite_vacmAccessStorageType(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_accessEntry *aptr;    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 ((aptr = access_parse_accessEntry(name, name_len)) == NULL) {        return SNMP_ERR_NOSUCHNAME;      }      long_ret = *((long *) var_val);/*      if ((long_ret == ST_VOLATILE || long_ret == ST_NONVOLATILE) &&          (aptr->storageType == ST_VOLATILE ||           aptr->storageType == ST_NONVOLATILE)) */	  /*This version only supports volatile storage*/       if (long_ret == aptr->storageType) {	  return SNMP_ERR_NOERROR;      } else {	  return SNMP_ERR_INCONSISTENTVALUE;      }  }  return SNMP_ERR_NOERROR;}intwrite_vacmAccessContextMatch(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_accessEntry *aptr;    if (var_val_type != ASN_INTEGER){      DEBUGMSGTL(("mibII/vacm_vars","write to vacmAccessContextMatch not ASN_INTEGER\n"));      return SNMP_ERR_WRONGTYPE;  }  if (var_val_len > sizeof(long_ret)){      DEBUGMSGTL(("mibII/vacm_vars","write to vacmAccessContextMatch: bad length\n"));      return SNMP_ERR_WRONGLENGTH;  }  if (action == COMMIT){      /* don't allow creations here */      if ((aptr = access_parse_accessEntry(name, name_len)) == NULL) {        return SNMP_ERR_NOSUCHNAME;      }      long_ret = *((long *) var_val);      if (long_ret == CM_EXACT || long_ret == CM_PREFIX) {	  aptr->contextMatch = long_ret;      } else {	  return SNMP_ERR_WRONGVALUE;      }  }  return SNMP_ERR_NOERROR;}intwrite_vacmAccessReadViewName(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 unsigned char string[VACMSTRINGLEN];  struct vacm_accessEntry *aptr = NULL;  static int resetOnFail;    if (action == RESERVE1) {      resetOnFail = 0;      if (var_val_type != ASN_OCTET_STR) {	  DEBUGMSGTL(("mibII/vacm_vars",		      "write to vacmAccessReadViewName not ASN_OCTET_STR\n"));	  return SNMP_ERR_WRONGTYPE;      }      if (var_val_len > 32) {	  DEBUGMSGTL(("mibII/vacm_vars",		      "write to vacmAccessReadViewName: bad length\n"));	  return SNMP_ERR_WRONGLENGTH;      }  } else if (action == RESERVE2) {      if ((aptr = access_parse_accessEntry(name, name_len)) == NULL) {	  return SNMP_ERR_INCONSISTENTNAME;      } else {	  resetOnFail = 1;	  memcpy(string, aptr->readView, VACMSTRINGLEN);	  memcpy(aptr->readView, var_val, var_val_len);

⌨️ 快捷键说明

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