vacm_vars.c

来自「eCos操作系统源码」· C语言 代码 · 共 1,195 行 · 第 1/3 页

C
1,195
字号
    gp = vacm_getGroupEntry(pdu->securityModel, sn);    if (gp == NULL) { DEBUGMSG(("mibII/vacm_vars", "\n")); return 2; }    DEBUGMSG (("mibII/vacm_vars", ", gn=%s", gp->groupName));    ap = vacm_getAccessEntry(gp->groupName, "", pdu->securityModel,                             pdu->securityLevel);    if (ap == NULL) { DEBUGMSG(("mibII/vacm_vars", "\n")); return 3; }    if (name == 0) { /* only check the setup of the vacm for the request */        DEBUGMSG(("mibII/vacm_vars", ", Done checking setup\n"));        return 0;    }    switch (pdu->command) {      case SNMP_MSG_GET:      case SNMP_MSG_GETNEXT:      case SNMP_MSG_GETBULK:	vn = ap->readView;	break;      case SNMP_MSG_SET:	vn = ap->writeView;	break;      case SNMP_MSG_TRAP:      case SNMP_MSG_TRAP2:      case SNMP_MSG_INFORM:	vn = ap->notifyView;	break;      default:        snmp_log(LOG_ERR, "bad msg type in vacm_in_view: %d\n", pdu->command);	vn = ap->readView;    }    DEBUGMSG (("mibII/vacm_vars", ", vn=%s", vn));    vp = vacm_getViewEntry (vn, name, namelen);    if (vp == NULL) { DEBUGMSG(("mibII/vacm_vars", "\n")); return 4; }    DEBUGMSG(("mibII/vacm_vars", ", vt=%d\n", vp->viewType));    if (vp->viewType == SNMP_VIEW_EXCLUDED) return 5;    return 0;}  /* end vacm_in_view() */u_char *var_vacm_sec2group(struct variable *vp,			   oid *name,			   size_t *length,			   int exact,			   size_t *var_len,			   WriteMethod **write_method){    struct vacm_groupEntry *gp;    oid *groupSubtree;    int groupSubtreeLen;    int secmodel;    char secname[32], *cp;    write_method = NULL;    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 < 13) return NULL;	secmodel = name[11];	groupSubtree = name+13;	groupSubtreeLen = *length - 13;	cp = secname;	while (groupSubtreeLen-- > 0) {            if (*groupSubtree > 255)              return 0; /* illegal value */	    *cp++ = (char) *groupSubtree++;	}	*cp = 0;	gp = vacm_getGroupEntry(secmodel, secname);    }    else {	secmodel = *length > 11 ? name[11] : 0;	groupSubtree = name+12;	groupSubtreeLen = *length - 12;	cp = secname;	while (groupSubtreeLen-- > 0) {            if (*groupSubtree > 255)              return 0; /* illegal value */	    *cp++ = (char) *groupSubtree++;	}	*cp = 0;	vacm_scanGroupInit();	while ((gp = vacm_scanGroupNext()) != NULL) {	    if (gp->securityModel > secmodel ||		(gp->securityModel == secmodel && strcmp(gp->securityName, secname) > 0))		break;	}	if (gp) {	    name[11] = gp->securityModel;	    *length = 12;	    cp = gp->securityName;	    while (*cp) {		name[(*length)++] = *cp++;	    }	}    }    if (!gp) return NULL;    *var_len =sizeof(long_return);    switch (vp->magic) {    case SECURITYMODEL:	long_return = gp->securityModel;	return (u_char *)&long_return;    case SECURITYNAME:	*var_len = gp->securityName[0];	return (u_char *)&gp->securityName[1];    case SECURITYGROUP:	*var_len = strlen(gp->groupName);	return (u_char *)gp->groupName;    case SECURITYSTORAGE:	long_return = gp->storageType;	return (u_char *)&long_return;    case SECURITYSTATUS:	long_return = gp->status;	return (u_char *)&long_return;    }    return NULL;}u_char *var_vacm_access(struct variable *vp,			oid *name,			size_t *length,			int exact,			size_t *var_len,			WriteMethod **write_method){    struct vacm_accessEntry *gp;    int secmodel;    int seclevel;    char groupName[32];    char contextPrefix[32];    oid *op;    int len;    char *cp;    int cmp;    write_method = NULL;    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+11;	len = *op++;	cp = groupName;	while (len-- > 0) {            if (*op > 255)              return 0; /* illegal value */	    *cp++ = (char) *op++;	}	*cp = 0;	len = *op++;	cp = contextPrefix;	while (len-- > 0) {            if (*op > 255)              return 0; /* illegal value */	    *cp++ = (char) *op++;	}	*cp = 0;	secmodel = *op++;	seclevel = *op++;	if (op != name + *length) {	    return NULL;	}	gp = vacm_getAccessEntry(groupName, contextPrefix, secmodel, seclevel);    }    else {	secmodel = seclevel = 0;	groupName[0] = 0;	contextPrefix[0] = 0;	op = name+11;	if (op >= name + *length) {	}	else {	    len = *op;	    cp = groupName;	    while (len-- >= 0) {                if (*op > 255)                  return 0; /* illegal value */		*cp++ = (char) *op++;	    }	    *cp = 0;	}	if (op >= name + *length) {	}	else {	    len = *op;	    cp = contextPrefix;	    while (len-- >= 0) {                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 > secmodel) break;	    if (gp->securityModel < secmodel) continue;	    if (gp->securityLevel > 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;    char viewName[32];    oid subtree[MAX_OID_LEN];    size_t subtreeLen = 0;    oid *op, *op1;    int len;    char *cp;    int cmp;    write_method = NULL;    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++;	cp = viewName;	while (len-- > 0) {            if (*op > 255)              return 0; /* illegal value */	    *cp++ = (char) *op++;	}	*cp = 0;	len = *length - (op - name);	op1 = subtree;	while (len-- > 0) {	    *op1++ = *op++;	    subtreeLen++;	}	if (op != name + *length) {	    return NULL;	}	gp = vacm_getViewEntry(viewName, subtree, subtreeLen);    }    else {	viewName[0] = 0;	op = name+12;	if (op >= name + *length) {	}	else {	    len = *op;	    cp = viewName;	    while (len-- >= 0) {                if (*op > 255)                  return 0; /* illegal value */		*cp++ = (char) *op++;	    }	    *cp = 0;	}	if (op >= name + *length) {	}	else {	    len = *length - (op - name);	    op1 = subtree;	    while (len-- >= 0) {		*op1++ = *op++;		subtreeLen++;	    }	}	vacm_scanViewInit();	while ((gp = vacm_scanViewNext()) != NULL) {	    cmp = strcmp(gp->viewName, viewName);	    if (cmp > 0) break;	    if (cmp < 0) continue;	}	if (gp) {	    *length = 12;	    cp = gp->viewName;	    do {		name[(*length)++] = *cp++;	    } while (*cp);	    op1 = gp->viewSubtree;	    len = gp->viewSubtreeLen;	    do {		name[(*length)++] = *op1++;	    } while (len-- > 0);	}    }    if (!gp) return NULL;    *var_len =sizeof(long_return);    switch (vp->magic) {    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;}#endif /* CYGPKG_SNMPLIB_FILESYSTEM_SUPPORT */#endif /* CYGPKG_SNMPAGENT_V3_SUPPORT */

⌨️ 快捷键说明

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