📄 v3_user.c
字号:
/* v3_user.c - v3_user.c routines *//* * Copyright 2000-2005 Wind River Systems, Inc. * All rights reserved. Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//* * Copyright 1998 Integrated Systems, Inc. * All rights reserved. *//* * $Log: v3_user.c,v $ * Revision 1.2 2001/11/06 21:20:32 josh * revised new path hacking * * Revision 1.1.1.1 2001/11/05 17:47:44 tneale * Tornado shuffle * * Revision 9.4 2001/01/19 22:22:30 paul * Update copyright. * * Revision 9.3 2000/03/17 00:19:33 meister * Update copyright message * * Revision 9.2 1999/11/02 20:55:18 josh * bringing usmUserTable into line with new spec: RFC 2574 * allows changing of auth and priv protocols after clone, * allows row creation without initial clone, and allows enabling of rows * without keychange for unused protocols (no authkeychange required if * not using auth, etc.) * * Revision 9.1 1999/09/30 22:09:47 josh * change public field to public_data so as not to conflict with * C++ compilers * * Revision 9.0 1998/10/16 22:12:41 sar * Update version stamp to match release * * Revision 1.14 1998/09/04 14:33:13 sar * Added some casts to try and keep compilers happy * * Revision 1.13 1998/08/12 04:44:03 sar * Move the initialization routines around some in order to minimize * the amount of code that gets pulled in for init purposes. * * Revision 1.12 1998/08/04 02:00:14 sar * Modified some of the routines that allocate longer term * storage (table structures and indexing information) to * user SNMP_memory_{alloc free}_lt in preparation for * possibly allocating them from a different pool then the * short term structures. * * Revision 1.11 1998/08/01 17:35:03 sar * Removed the check_id flag from the user lookup call * * Revision 1.10 1998/07/03 16:51:34 sar * Removed the many engine option and moved this engine's boots and time * informtaion into an engine entry * * Revision 1.9 1998/06/24 23:45:26 sar * Check that we have a user before looking at it's fields * * Revision 1.8 1998/06/19 20:13:59 sar * make sure all files include asn1conf.h and snmp.h to pick up all of * the common code * * Revision 1.7 1998/06/18 04:38:31 sar * Make sure we have an engine struct when deinstalling a user * * Revision 1.6 1998/06/16 05:28:14 sar * clean up some type info * rearrange the handling of the instance info for nexts * split the engine id into its own struct * * Revision 1.5 1998/06/09 21:46:31 sar * Cleaned up some code that might have called alloc or memcmp with * 0 lenght strings * * Revision 1.4 1998/05/30 03:20:02 sar * Modified the names for the max string length macros for clarity * Update user_lookup * * Revision 1.3 1998/05/29 17:06:21 josh * syntax fixes in a few spots * * Revision 1.2 1998/05/27 20:52:27 sar * Added comments and header information, added size checks where appropriate * * Revision 1.1 1998/05/24 04:14:49 sar * Support for processing SNMPv3 packets. * acc = access and group structure control functions * auth & prive = authentication and privacy code (not including the * actual digest or encryption routines) * ber = routines for encoding and decoding v3 packets * eng = engine sructure control functions * user = user structure control functions * *//* [clearcase]modification history-------------------01g,17may05,job fix up the DH code01f,12may05,job fix apigen comments01e,29apr05,job nomanual for new functions01d,18apr05,job update copyright notices01c,13apr05,AJS Diffie-Hellman work01b,23feb05,job apigen for documented APIs01a,24nov03,job update copyright information*//*DESCRIPTIONThis library contains v3_user.c routines.INCLUDE FILES: snmp.h, v3_user.h, v3_auth.h, v3_priv.h*/#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/buffer.h>#include <wrn/wm/snmp/engine/snmpdefs.h>#include <wrn/wm/snmp/engine/v3_user.h>#include <wrn/wm/snmp/engine/v3_auth.h>#include <wrn/wm/snmp/engine/v3_priv.h>sbits32_t v3_usmUserSpinLock = 0;/****************************************************************************\NOMANUALNAME: user listPURPOSE: This is the list of users known to this engine. This is a two level list the first level is ordered by engineid (size and then lexi) the second hangs off the first and is ordered by user name (size and then lexi)****************************************************************************//******************************************************************************** SNMP_User_Lookup - find a user entry matching the specified indices** SYNOPSIS** \cs* SNMP_USER_T * SNMP_User_Lookup * ( * bits8_t * id, * ALENGTH_T id_length, * bits8_t * name, * ALENGTH_T name_length * )* \ce** DESCRIPTION** This routine finds a user entry matching the specified <id> and <name>.** Parameters:* \is* \i <*id>* Point to the user <id>.* \i <id_length>* Specify the length in bytes of the <id>.* \i <*name>* Specify the user <name>.* \i <name_length>* Specify the length in bytes of the user <name>.* \ie** RETURNS: If successful, this routine returns a pointer to the entry. * Otherwise, it returns 0.** ERRNO: N/A** SEE ALSO: SNMP_User_Create(), SNMP_User_Deinstall(), SNMP_User_Destroy(), * SNMP_User_Install(), SNMP_User_Name(), SNMP_User_Next_User(), SNMPv3 User * Table Field Routines, SNMPv3 User Table Key Routines*/SNMP_USER_T * SNMP_User_Lookup(bits8_t *id, ALENGTH_T id_len, bits8_t *uname, ALENGTH_T uname_len){SNMP_USER_ENG_T *engine;SNMP_USER_T *user;/* walk through the engine list trying to find our engine id */for(engine = root_user; engine; engine = engine->next) { if (engine->id_len >= id_len) break; }for(; engine; engine = engine->next) { if (engine->id_len != id_len) return(0); if (MEMCMP(engine->id, id, id_len) >= 0) break; }/* if we didn't find the engine struct return an empty indicator */if ((engine == 0) || MEMCMP(engine->id, id, id_len)) return(0);/* we have an engine structure, search the user list */for(user = engine->user; user; user = user->next) { if (user->uname_len >= uname_len) break; }for(; user; user = user->next) { if (user->uname_len != uname_len) return(0); if (MEMCMP(user->uname, uname, uname_len) >= 0) break; }/* if we didn't find the user return an empty indicator */if ((user == 0) || MEMCMP(user->uname, uname, uname_len)) return(0);return(user);}/****************************************************************************\NOMANUALNAME: SNMP_User_NextPURPOSE: Find the entry after the named one the indexing information is of the form: <len> <engineid> <len> <name> but as this is a next we might not have all of it or it might not be consistent or some of the subids that represent bytes may be too large (greater than 0xff).PARAMETERS: int tcount count of subids OIDC_T *tlist list of subidsRETURNS: SNMP_USER_T * pointer to entry or 0 if none found****************************************************************************/SNMP_USER_T * SNMP_User_Next(int tcount, OIDC_T *tlist){SNMP_USER_ENG_T *engine;SNMP_USER_T *user;OIDC_T req_len, check_len, *temp_oid, len;bits8_t *name;if (tcount == 0) { if (root_user) return(root_user->user); else return(0); }if (*tlist > ETC_USER_ENGINE_MAX) return(0);req_len = *tlist++;tcount--;check_len = min(req_len, (OIDC_T)tcount);for (engine = root_user; engine && (engine->id_len < req_len); engine = engine->next) ; /* no body for for loop */for (; ; engine = engine->next) { if (engine == 0) return(0); if (engine->id_len != req_len) return(engine->user); name = engine->id; temp_oid = tlist; for(len = check_len; len && (*name == *temp_oid); len--, name++, temp_oid++) ; /* no body for for loop */ if (len) { if (*name > *temp_oid) return(engine->user); else continue; } if (req_len != check_len) return(engine->user); else break; }/* if we get to here we have found a struct with the correct engine id now we need to examine the user name, we start by extracting the next block of naming info */tlist += (int)req_len;tcount -= (int)req_len;if (tcount <= 0) return(engine->user);if (*tlist > ETC_USER_USER_MAX) { if (engine->next) return(engine->next->user); else return(0); }req_len = *tlist++;tcount--;check_len = min(req_len, (OIDC_T)tcount);for(user = engine->user; user && (user->uname_len < req_len); user = user->next) ; /* no body for for loop */for (; user; user = user->next) { if (user->uname_len != req_len) return(user); name = user->uname; temp_oid = tlist; for(len = check_len; len && (*name == *temp_oid); len--, name++, temp_oid++) ; /* no body for for loop */ if (len) { if (*name > *temp_oid) return(user); else continue; } if (req_len != check_len) return(user); }/* need to step to next engine */if (engine->next) return(engine->next->user);return(0);}/********************************************************************************* SNMP_User_Next_User - find the next user entry in the user table* SYNOPSIS** \cs* SNMP_USER_T * SNMP_User_Next_User* (* SNMP_USER_T * user * )* \ce** DESCRIPTION** This routine finds the user entry in the user table after the specified user * entry. Use this routine to step through the user table to find all installed * users.** Parameters:* \is* \i <*user>* Specify the <user> entry to install in the user table.* \ie** RETURNS: If successful, this routine returns a pointer to the user entry. If * there is no successor or the specified <user> is not installed, it returns 0. * If the <user> is specified as 0, then it returns a pointer to the first user * entry in the table.** ERRNO: N/A** SEE ALSO: SNMP_User_Create(), SNMP_User_Deinstall(), SNMP_User_Destroy(), * SNMP_User_Install(), SNMP_User_Lookup(), SNMP_User_Name(), SNMPv3 User Table * Field Routines, SNMPv3 User Table Key Routines*/SNMP_USER_T * SNMP_User_Next_User(SNMP_USER_T *user){if (user) { if (user->next) return(user->next); if (user->parent->next) return(user->parent->next->user); return(0); }if (root_user) return(root_user->user);return(0);}/****************************************************************************** SNMP_User_Destroy - destroy the specified <user> and frees any associated resources* SYNOPSIS** \cs* void SNMP_User_Destroy* (* SNMP_USER_T * user * )* \ce** DESCRIPTION** This routine destroys the specified user entry, frees the space for the * entry, and frees the space for any resources the entry might contain.** \&NOTE: If the specified user entry has been installed, call * SNMP_User_Deinstall() before calling this routine.** Parameters:* \is* \i <*user>* Specify the user entry to remove from the user table.* \ie** RETURNS: None.** ERRNO: N/A** SEE ALSO: SNMP_User_Create(), SNMP_User_Deinstall(), SNMP_User_Install(), * SNMP_User_Lookup(), SNMP_User_Name(), SNMP_User_Next_User(), SNMPv3 User * Table Field Routines, SNMPv3 User Table Key Routines*/void SNMP_User_Destroy(SNMP_USER_T *user){#if INSTALL_SNMP_V3_DIFFIE_HELLMANDH_free(user -> DH_keys.DHauthValues);DH_free(user -> DH_keys.DHprivValues);#endif /* INSTALL_SNMP_V3_DIFFIE_HELLMAN */EBufferClean(&user->public_data);SNMP_memory_free_lt(user);}/********************************************************************************* SNMP_User_Create - create a user entry structure** SYNOPSIS** \cs* SNMP_USER_T * SNMP_User_Create * ( * SNMP_AUTH_T * auth, * SNMP_PRIV_T * priv * )* \ce** DESCRIPTION** This routine creates a 'usmUserTable' user entry structure. It attempts to * allocate space for the entry. To make an entry visible to the engine, use * SNMP_User_Install().** Parameters:* \is* \i <*auth>* Point to the structure containing the authentication algorithm. This value * must be set when the user entry is created. If you do not want to use * authentication or privacy, set this value to zero.* \i <*priv>* Point to the structure containing the privacy algorithm. This value must be * set when the user entry is created. If you do not want to use authentication * or privacy, set this value to zero.* \ie** \&NOTE: If you have not configured <auth,> then you cannot use <priv>.** 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*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -