📄 v3_acc.c
字号:
if (*group && ((*group)->model == sec_model) && ((*group)->uname_len == uname_len) && (MEMCMP((*group)->uname, uname, uname_len) == 0)) return(-1);/* allocate space for the name */in_group->uname = (bits8_t *)SNMP_memory_alloc_lt(uname_len);if (in_group->uname == 0) return(-1);in_group->model = sec_model;in_group->uname_len = uname_len;MEMCPY(in_group->uname, uname, uname_len);/* insert the group into the list */in_group->next = *group;*group = in_group;return(0);}/********************************************************************************* SNMP_Group_Deinstall - remove the specified group from the group table* SYNOPSIS** \cs* void SNMP_Group_Deinstall* (* SNMP_GROUP_T * group * )* \ce** DESCRIPTION** This routine removes the specified group from the group table and cleans up * any resources that might have been used for indexing purposes.** PARAMETERS* \is* \i <*group>* Specify the group to remove from the group table.* \ie** RETURNS: None.** ERRNO: N/A** SEE ALSO: SNMP_Group_Create(), SNMP_Group_Destroy(), SNMP_Group_Install(), * SNMP_Group_Lookup(), SNMP_Group_Name(), SNMP_Group_Next_Group(), SNMP Group * Table Field Routines*/void SNMP_Group_Deinstall(SNMP_GROUP_T *in_group){SNMP_GROUP_T **group;for(group = &root_group; *group; group = &(*group)->next) if (*group == in_group) { *group = in_group->next; SNMP_memory_free_lt(in_group->uname); in_group->uname = 0; in_group->uname_len = 0; in_group->next = 0; return; }return;}/********************************************************************************* SNMP_Group_Name - extract the indexing information for the specified <group>* SYNOPSIS** \cs* void SNMP_Group_Name * ( * SNMP_GROUP_T * group, * sbits32_t * sec_model, * bits8_t * name, * ALENGTH_T * length * )* \ce** DESCRIPTION** This routine extracts the indexing information for the specified <group>. * After this routine completes, check the values in the <name> and <length> * fields.** PARAMETERS* \is* \i <*group>* Specify the <group> entry from which to extract indexing information.* \i <*sec_model>* Specify the security model under which the security name is defined.* \i <*name>* Specify the security name.* \i <*length>* On input, specifies the amount of space available in <name>. On output, it is * the amount of space required to hold the security name. If <name> is long * enough to hold the security name then the security name is copied to name.* \ie** RETURNS: None.** ERRNO: N/A** SEE ALSO: SNMP_Group_Create(), SNMP_Group_Deinstall(), SNMP_Group_Destroy(), * SNMP_Group_Install(), SNMP_Group_Lookup(), SNMP_Group_Next_Group(), SNMP * Group Table Field Routines*/void SNMP_Group_Name(SNMP_GROUP_T *group, sbits32_t *sec_model, bits8_t *uname, ALENGTH_T *uname_len){*sec_model = group->model;if (group->uname_len && (*uname_len >= group->uname_len)){ MEMCPY(uname, group->uname, group->uname_len); }*uname_len = group->uname_len;return;}/****************************************************************************\NOMANUALName: access listPurpose: This is the list of access structures that we know about. It is arranged in a two level linked list. The first linked list is sorted by the group size and name. Each element in that list points to another linked list that is sorted by context size, context name, security model and security level.****************************************************************************//********************************************************************************* SNMP_V3_Access_Destroy - destroy an <access> and frees associated resources* SYNOPSIS** \cs* void SNMP_V3_Access_Destroy* (* SNMP_ACCESS_T * access * )* \ce** DESCRIPTION** This routine destroys the specified <access> and frees the space for the * entry in addition to any resources the entry might contain.** \&NOTE: If the specified <access> has been installed, call * SNMP_V3_Access_Deinstall() before calling this routine.** PARAMETERS* \is* \i <*access>* Specify the <access> to remove from the access table.* \ie** RETURNS: None.** ERRNO: N/A** SEE ALSO: SNMP_V3_Access_Create(), SNMP_V3_Access_Deinstall(), * SNMP_V3_Access_Install(), SNMP_V3_Access_Lookup(), SNMP_V3_Access_Name(), * SNMP_V3_Access_Next_Access(), SNMPv3 Access Table Field Routines, SNMPv3 * Access Table View Routines*/void SNMP_V3_Access_Destroy(SNMP_ACCESS_T *access){EBufferClean(&access->readview);EBufferClean(&access->writeview);EBufferClean(&access->notifyview);SNMP_memory_free_lt(access);}/********************************************************************************* SNMP_V3_Access_Create - create an access structure* SYNOPSIS** \cs* SNMP_ACCESS_T * SNMP_V3_Access_Create* (* void * )* \ce** DESCRIPTION** This routine creates an access structure, as in 'vacmAccessTable'. It * attempts to allocate space for the entry. To make an entry visible to the * engine, use SNMP_V3_Access_Install().** PARAMETERS* None.** RETURNS: If this routine is successful, it sets the entry to a default state * and returns a pointer to the entry. Otherwise, it returns 0.** ERRNO: N/A** SEE ALSO: SNMP_V3_Access_Deinstall(), SNMP_V3_Access_Destroy(), * SNMP_V3_Access_Install(), SNMP_V3_Access_Lookup(), SNMP_V3_Access_Name(), * SNMP_V3_Access_Next_Access(), SNMPv3 Access Table Field Routines, SNMPv3 * Access Table View Routines*/SNMP_ACCESS_T * SNMP_V3_Access_Create(void){SNMP_ACCESS_T *access;access = (SNMP_ACCESS_T *)SNMP_memory_alloc_lt(sizeof(SNMP_ACCESS_T));if (access == 0) return(0);MEMSET(access, 0, sizeof(SNMP_ACCESS_T));SNMP_V3_Access_Set_Defaults(access);return(access);}/********************************************************************************* SNMP_V3_Access_Install - install the specified <access> in the access table* SYNOPSIS** \cs* int SNMP_V3_Access_Install * ( * SNMP_ACCESS_T * access, * bits8_t * group_name, * ALENGTH_T group_name_length, * bits8_t * prefix_name, * ALENGTH_T prefix_name_length, * sbits32_t sec_model, * sbits32_t sec_level* )* \ce** DESCRIPTION** This routine installs the specified <access> in the access table using * <group_name>, <prefix_name>, <sec_model> and <name> as indices.** \&NOTE: Once an <access> has been installed, you must call * SNMP_V3_Access_Deinstall() before calling SNMP_V3_Access_Destroy() to remove * it.** PARAMETERS* \is* \i <*access>* Specify the <access> to install in the access table* \i <*group_name>* Specify the group name.* \i <group_name_length>* Specify the length in bytes of the group name.* \i <*prefix_name>* Specify the name to match against the context.* \i <prefix_name_length>* Specify the length in bytes of the prefix name.* \i <sec_model>* Specify the security model under which the security name is defined.* \i <sec_level>* Specify the security level as one of the following values: * 'ETC_SEC_LEVEL_NONE' (none), 'ETC_SEC_LEVEL_AUTH' (authentication) or * 'ETC_SEC_LEVEL_PRIV' (authentication and privacy). Definitions for these tags * are contained in the file 'snmpdefs.h'.* \ie** RETURNS: If successful, this routine returns a value of 0. If an entry * already exists with the same indices or another error occurs, it returns 1.** ERRNO: N/A** SEE ALSO: SNMP_V3_Access_Create(), SNMP_V3_Access_Deinstall(), * SNMP_V3_Access_Destroy(), SNMP_V3_Access_Lookup(), SNMP_V3_Access_Name(), * SNMP_V3_Access_Next_Access(), SNMPv3 Access Table Field Routines, SNMPv3 * Access Table View Routines*/int SNMP_V3_Access_Install(SNMP_ACCESS_T *in_access, bits8_t *grp_name, ALENGTH_T grp_len, bits8_t *prefix, ALENGTH_T prefix_len, sbits32_t sec_model, sbits32_t sec_level){bits8_t *buffp = 0;SNMP_ACC_GRP_T **group, *temp_grp;SNMP_ACCESS_T **access;/* sanity check the group and context names */if ((grp_len == 0) || (grp_len > ETC_ACCESS_GROUP_MAX) || (prefix_len > ETC_ACCESS_ACCESS_MAX) || (sec_level > 0xFFFF)) return(1);/* allocate space for the context prefix and copy the prefix over, if we succeed we will need to attach it to the access struct */if (prefix_len) { buffp = SNMP_memory_alloc_lt(prefix_len); if (buffp == 0) return(1); MEMCPY(buffp, prefix, prefix_len); }/* walk through the group list trying to find our group name */for(group = &root_access; *group; group= &(*group)->next) { if ((*group)->grp_len >= grp_len) break; }for(; *group; group = &(*group)->next) { if (((*group)->grp_len != grp_len) || (MEMCMP((*group)->grp_name, grp_name, grp_len) >= 0)) break; }if ((*group == 0) || ((*group)->grp_len != grp_len) || MEMCMP((*group)->grp_name, grp_name, grp_len)) { /* if we didn't find our group name create it and attach the access struct to it. */ temp_grp = (SNMP_ACC_GRP_T *)SNMP_memory_alloc_lt(sizeof(SNMP_ACC_GRP_T) + grp_len); if (temp_grp == 0) { SNMP_memory_free_lt(buffp); return(1); } temp_grp->grp_name = ((bits8_t *)temp_grp) + sizeof(SNMP_ACC_GRP_T); MEMCPY(temp_grp->grp_name, grp_name, grp_len); temp_grp->grp_len = grp_len; temp_grp->access = in_access; temp_grp->next = *group; *group = temp_grp; }else { /* if we found the group name search the access struct list for the prefix, sec model and sec level information. If we find a matching entry generate an error. If we don't find one thread the new one onto the list */ for(access = &(*group)->access; *access; access = &(*access)->next) { if ((*access)->prefix_len >= prefix_len) break; } for(; *access; access = &(*access)->next) { if (((*access)->prefix_len != prefix_len) || (MEMCMP_NULLOK((*access)->prefix, prefix, prefix_len) >= 0)) break; } for(; *access; access = &(*access)->next) { if (((*access)->prefix_len != prefix_len) || (MEMCMP_NULLOK((*access)->prefix, prefix, prefix_len) != 0) || ((*access)->model > sec_model)) break; if ((*access)->model == sec_model) { if ((*access)->level > sec_level) break; if ((*access)->level == sec_level) { /* an access struct is already installed in the requested slot, cleanup and error out */ SNMP_memory_free_lt(buffp); return(1); } } } in_access->next = *access; *access = in_access; }/* fill in the access struct information */in_access->prefix = buffp;in_access->prefix_len = prefix_len;in_access->model = sec_model;in_access->level = (sbits16_t)sec_level;in_access->group = *group;return(0);}/********************************************************************************* SNMP_V3_Access_Deinstall - remove the specified access from the access table* SYNOPSIS** \cs* void SNMP_V3_Access_Deinstall* (* SNMP_ACCESS_T * access * )* \ce** DESCRIPTION** This routine removes the specified access from the access table and cleans up * any resources that might have been used for indexing purposes.** PARAMETERS* \is* \i <*access>* Specify the <access> to remove from the access table.* \ie** RETURNS: None.** ERRNO: N/A** SEE ALSO: SNMP_V3_Access_Create(), SNMP_V3_Access_Destroy(), * SNMP_V3_Access_Install(), SNMP_V3_Access_Lookup(), SNMP_V3_Access_Name(), * SNMP_V3_Access_Next_Access(), SNMPv3 Access Table Field Routines, SNMPv3 * Access Table View Routines*/void SNMP_V3_Access_Deinstall(SNMP_ACCESS_T *in_access){SNMP_ACC_GRP_T **group, *our_group;SNMP_ACCESS_T **access;our_group = in_access->group;if (our_group == 0) return;/* if our structure is in the list clean it up */for(access = &(our_group->access); *access; access = &(*access)->next) { if (*access == in_access) { *access = in_access->next; if (in_access->prefix) SNMP_memory_free_lt(in_access->prefix); in_access->group = 0; in_access->next = 0; in_access->prefix = 0; in_access->prefix_len = 0; in_access->model = 0; in_access->level = 0; break; } }/* see if we need to remove the group as well */if (our_group->access == 0) { for(group = &root_access; *group; group = &(*group)->next) { if (*group == our_group){ *group = our_group->next; SNMP_memory_free_lt(our_group); break; } } }return;}/********************************************************************************* SNMP_V3_Access_Lookup - find an access entry matching the specified indices* SYNOPSIS** \cs* SNMP_ACCESS_T * SNMP_V3_Access_Lookup * ( * bits8_t * group_name, * ALENGTH_T group_name_length, * bits8_t * prefix_name, * ALENGTH_T prefix_name_length, * sbits32_t sec_model, * sbits32_t sec_level * )* \ce** DESCRIPTION** This routine finds an access entry matching the specified prefix name, group * name, security model, and the security name.** PARAMETERS* \is* \i <*group_name>* Specify the group name.* \i <group_name_length>* Specify the length in bytes of the group name.* \i <*prefix_name>* Specify the name to match against the context.* \i <prefix_name_length>* Specify the length in bytes of the prefix name.* \i <sec_model>* Specify the security model under which the security name is defined.* \i <sec_level>* Specify the security level as one of the following values: * 'ETC_SEC_LEVEL_NONE' (none), 'ETC_SEC_LEVEL_AUTH' (authentication) or * 'ETC_SEC_LEVEL_PRIV' (authentication and privacy). Definitions for these tags
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -