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

📄 vacm_vars.c

📁 ucd-snmp源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	groupName[0] = 0;	contextPrefix[0] = 0;	op = name+11;	if (op >= name + *length) {	} else {	    len = *op;	    if (len > VACM_MAX_STRING)	        return 0;	    cp = groupName;	    for (i = 0; i <= len; i++) {                if (*op > 255) {		    return 0; /* illegal value */		}		*cp++ = (char)*op++;	    }	    *cp = 0;	}	if (op >= name + *length) {	} else {	    len = *op;	    if (len > VACM_MAX_STRING)	        return 0;	    cp = contextPrefix;	    for (i = 0; i <= len; i++) {                if (*op > 255) {		    return 0; /* illegal value */		}		*cp++ = (char)*op++;	    }	    *cp = 0;	}	if (op >= name + *length) {	} else {	    secmodel = *op++;	}	if (op >= name + *length) {	} else {	    seclevel = *op++;	}	vacm_scanAccessInit();	while ((gp = vacm_scanAccessNext()) != NULL) {	    cmp = strcmp(gp->groupName, groupName);	    if (cmp > 0) break;	    if (cmp < 0) continue;	    cmp = strcmp(gp->contextPrefix, contextPrefix);	    if (cmp > 0) break;	    if (cmp < 0) continue;	    if (gp->securityModel > (int)secmodel) break;	    if (gp->securityModel < (int)secmodel) continue;	    if (gp->securityLevel > (int)seclevel) break;	}	if (gp) {	    *length = 11;	    cp = gp->groupName;	    do {		name[(*length)++] = *cp++;	    } while (*cp);	    cp = gp->contextPrefix;	    do {		name[(*length)++] = *cp++;	    } while (*cp);	    name[(*length)++] = gp->securityModel;	    name[(*length)++] = gp->securityLevel;	}    }    if (!gp) {	return NULL;    }    *var_len = sizeof(long_return);    switch (vp->magic) {    case ACCESSMATCH:	long_return = gp->contextMatch;	return (u_char *)&long_return;    case ACCESSLEVEL:	long_return = gp->securityLevel;	return (u_char *)&long_return;    case ACCESSMODEL:	long_return = gp->securityModel;	return (u_char *)&long_return;    case ACCESSPREFIX:	*var_len = *gp->contextPrefix;	return (u_char *)&gp->contextPrefix[1];    case ACCESSREAD:	*var_len = strlen(gp->readView);	return (u_char *)gp->readView;    case ACCESSWRITE:	*var_len = strlen(gp->writeView);	return (u_char *)gp->writeView;    case ACCESSNOTIFY:	*var_len = strlen(gp->notifyView);	return (u_char *)gp->notifyView;    case ACCESSSTORAGE:	long_return = gp->storageType;	return (u_char *)&long_return;    case ACCESSSTATUS:	long_return = gp->status;	return (u_char *)&long_return;    }    return NULL;}u_char *var_vacm_view(struct variable *vp,		      oid *name,		      size_t *length,		      int exact,		      size_t *var_len,		      WriteMethod **write_method){    struct vacm_viewEntry *gp=NULL;    char viewName[VACMSTRINGLEN] = { 0 };    oid subtree[MAX_OID_LEN]= { 0 };    size_t subtreeLen = 0;    oid *op, *op1;    unsigned long len = 0, i = 0;    char *cp;    int cmp,cmp2;    /*  Set up write_method first, in case we return NULL before getting to	the switch (vp->magic) below.  In some of these cases, we still want	to call the appropriate write_method, if only to have it return the	appropriate error.  */    switch (vp->magic) {    case VIEWMASK:	*write_method = write_vacmViewMask;	break;    case VIEWTYPE:	*write_method = write_vacmViewType;	break;    case VIEWSTORAGE:	*write_method = write_vacmViewStorageType;	break;    case VIEWSTATUS:	*write_method = write_vacmViewStatus;	break;    default:	*write_method = NULL;    }        *var_len = sizeof(long_return);    if (vp->magic != VACMVIEWSPINLOCK) {	if (memcmp(name, vp->name, sizeof(oid)*vp->namelen) != 0) {	    memcpy(name, vp->name, sizeof(oid)*vp->namelen);	    *length = vp->namelen;	}	if (exact) {	    if (*length < 15) return NULL;	    op = name+12;	    len = *op++;	    if (len > VACM_MAX_STRING)		return 0;	    cp = viewName;	    while (len-- > 0) {		if (*op > 255)		    return 0; 		*cp++ = (char) *op++;	    }	    *cp = 0;	    subtree[0] = len = *op++;	    subtreeLen = 1;	    if (len > MAX_OID_LEN)		return 0;	    op1 = &(subtree[1]);	    while (len-- > 0) {		*op1++ = (op != name + *length) ? *op++ : 0;		subtreeLen++;	    }	    if (op != name + *length) {		return NULL;	    }	    gp = vacm_getViewEntry(viewName, subtree, subtreeLen, 1);	    if (gp != NULL) {		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;		for (i = 0; i <= len && op < name + *length; i++) {		    if (*op > 255) {			return 0;		    }		    *cp++ = (char)*op++;		}		*cp = 0;	    }	    if (op >= name + *length) {	    } else {		len = *op++;		op1 = subtree;		*op1++ = len;		subtreeLen++;		for (i = 0; i <= len && op < name + *length; i++) {		    *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 == NULL) {	    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 (u_char *)&long_return;    case VIEWNAME:	*var_len = gp->viewName[0];	return (u_char *)&gp->viewName[1];    case VIEWSUBTREE:	*var_len = gp->viewSubtreeLen*sizeof(oid);	return (u_char *)gp->viewSubtree;    case VIEWMASK:	*var_len = (gp->viewSubtreeLen + 7) / 8;	return (u_char *)gp->viewMask;    case VIEWTYPE:	long_return = gp->viewType;	return (u_char *)&long_return;    case VIEWSTORAGE:	long_return = gp->viewStorageType;	return (u_char *)&long_return;    case VIEWSTATUS:	long_return = gp->viewStatus;	return (u_char *)&long_return;    }    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){    static unsigned char string[VACMSTRINGLEN];    struct vacm_groupEntry *geptr;    static int resetOnFail;    if (action == RESERVE1) {	resetOnFail = 0;	if (var_val_type != ASN_OCTET_STR) {	    return SNMP_ERR_WRONGTYPE;	}	if (var_val_len < 1 || var_val_len > 32) {	    return SNMP_ERR_WRONGLENGTH;	}    } else if (action == RESERVE2) {	if ((geptr = sec2group_parse_groupEntry(name, name_len)) == NULL) {	    return SNMP_ERR_INCONSISTENTNAME;	} else {	    resetOnFail = 1;	    memcpy(string, geptr->groupName, VACMSTRINGLEN);	    memcpy(geptr->groupName, var_val, var_val_len);	    geptr->groupName[var_val_len] = 0;	    if (geptr->status == RS_NOTREADY) {		geptr->status = RS_NOTINSERVICE;	    }	}    } else if (action == FREE) {	/*  Try to undo the SET here (abnormal usage of FREE clause)  */	if ((geptr = sec2group_parse_groupEntry(name, name_len)) != NULL &&	    resetOnFail) {	    memcpy(geptr->groupName, string, VACMSTRINGLEN);	}    }    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){      return SNMP_ERR_WRONGTYPE;  }  if (var_val_len > sizeof(long_ret)){      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 if (long_ret == geptr->storageType) {	  return SNMP_ERR_NOERROR;      } 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){    static long long_ret;    int model;    char *newName;    size_t nameLen;    struct vacm_groupEntry *geptr;    if (action == RESERVE1) {	if (var_val_type != ASN_INTEGER){	    return SNMP_ERR_WRONGTYPE;	}	if (var_val_len != sizeof(long_ret)){	    return SNMP_ERR_WRONGLENGTH;

⌨️ 快捷键说明

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