1 //==========================================================================
3 // ./lib/current/include/snmpusm.h
6 //==========================================================================
7 //####ECOSGPLCOPYRIGHTBEGIN####
8 // -------------------------------------------
9 // This file is part of eCos, the Embedded Configurable Operating System.
10 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 // eCos is free software; you can redistribute it and/or modify it under
13 // the terms of the GNU General Public License as published by the Free
14 // Software Foundation; either version 2 or (at your option) any later version.
16 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 // You should have received a copy of the GNU General Public License along
22 // with eCos; if not, write to the Free Software Foundation, Inc.,
23 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 // As a special exception, if other files instantiate templates or use macros
26 // or inline functions from this file, or you compile this file and link it
27 // with other works to produce a work based on this file, this file does not
28 // by itself cause the resulting work to be covered by the GNU General Public
29 // License. However the source code for this file must still be made available
30 // in accordance with section (3) of the GNU General Public License.
32 // This exception does not invalidate any other reasons why a work based on
33 // this file might be covered by the GNU General Public License.
35 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
36 // at http://sources.redhat.com/ecos/ecos-license/
37 // -------------------------------------------
38 //####ECOSGPLCOPYRIGHTEND####
39 //####UCDSNMPCOPYRIGHTBEGIN####
41 // -------------------------------------------
43 // Portions of this software may have been derived from the UCD-SNMP
44 // project, <http://ucd-snmp.ucdavis.edu/> from the University of
45 // California at Davis, which was originally based on the Carnegie Mellon
46 // University SNMP implementation. Portions of this software are therefore
47 // covered by the appropriate copyright disclaimers included herein.
49 // The release used was version 4.1.2 of May 2000. "ucd-snmp-4.1.2"
50 // -------------------------------------------
52 //####UCDSNMPCOPYRIGHTEND####
53 //==========================================================================
54 //#####DESCRIPTIONBEGIN####
59 // Purpose: Port of UCD-SNMP distribution to eCos.
63 //####DESCRIPTIONEND####
65 //==========================================================================
66 /********************************************************************
67 Copyright 1989, 1991, 1992 by Carnegie Mellon University
70 Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
74 Permission to use, copy, modify and distribute this software and its
75 documentation for any purpose and without fee is hereby granted,
76 provided that the above copyright notice appears in all copies and
77 that both that copyright notice and this permission notice appear in
78 supporting documentation, and that the name of CMU and The Regents of
79 the University of California not be used in advertising or publicity
80 pertaining to distribution of the software without specific written
83 CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
84 WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
85 WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL CMU OR
86 THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
87 INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
88 FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
89 CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
90 CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
91 *********************************************************************/
95 * Header file for USM support.
105 #define WILDCARDSTRING "*"
110 #define USM_MAX_ID_LENGTH 1024 /* In bytes. */
111 #define USM_MAX_SALT_LENGTH 64 /* In BITS. */
112 #define USM_MAX_KEYEDHASH_LENGTH 128 /* In BITS. */
114 #define USM_TIME_WINDOW 150
115 #define USM_MD5_AND_SHA_AUTH_LEN 12 /* bytes */
121 struct usmStateReference {
123 size_t usr_name_length;
124 u_char *usr_engine_id;
125 size_t usr_engine_id_length;
126 oid *usr_auth_protocol;
127 size_t usr_auth_protocol_length;
128 u_char *usr_auth_key;
129 size_t usr_auth_key_length;
130 oid *usr_priv_protocol;
131 size_t usr_priv_protocol_length;
132 u_char *usr_priv_key;
133 size_t usr_priv_key_length;
138 /* struct usmUser: a structure to represent a given user in a list */
139 /* Note: Any changes made to this structure need to be reflected in
140 the following functions: */
151 size_t authProtocolLen;
155 size_t privProtocolLen;
158 u_char *userPublicString;
161 struct usmUser *next;
162 struct usmUser *prev;
170 void usm_set_reportErrorOnUnknownID (int value);
172 struct usmStateReference *
173 usm_malloc_usmStateReference (void);
175 void usm_free_usmStateReference (void *old);
177 int usm_set_usmStateReference_name (
178 struct usmStateReference *ref,
182 int usm_set_usmStateReference_engine_id (
183 struct usmStateReference *ref,
185 size_t engine_id_len);
187 int usm_set_usmStateReference_auth_protocol (
188 struct usmStateReference *ref,
190 size_t auth_protocol_len);
192 int usm_set_usmStateReference_auth_key (
193 struct usmStateReference *ref,
195 size_t auth_key_len);
197 int usm_set_usmStateReference_priv_protocol (
198 struct usmStateReference *ref,
200 size_t priv_protocol_len);
202 int usm_set_usmStateReference_priv_key (
203 struct usmStateReference *ref,
205 size_t priv_key_len);
207 int usm_set_usmStateReference_sec_level (
208 struct usmStateReference *ref,
211 #ifdef SNMP_TESTING_CODE
212 void emergency_print (u_char *field, u_int length);
215 int asn_predict_int_length (int type, long number, size_t len);
217 int asn_predict_length (int type, u_char *ptr, size_t u_char_len);
223 size_t priv_salt_length,
226 int usm_parse_security_parameters (
230 size_t *secEngineIDLen,
236 size_t *signature_length,
241 int usm_check_and_update_timeliness (
243 size_t secEngineIDLen,
248 int usm_generate_out_msg (int, u_char *, size_t, int, int, u_char *, size_t,
249 char *, size_t, int, u_char *, size_t, void *,
250 u_char *, size_t *, u_char **, size_t *);
252 int usm_process_in_msg (int, size_t, u_char *, int, int, u_char *, size_t,
253 u_char *, size_t *, char *, size_t *, u_char **, size_t *,
256 int usm_check_secLevel(int level, struct usmUser *user);
257 void usm_update_engine_time(void);
258 struct usmUser *usm_get_userList(void);
259 struct usmUser *usm_get_user(u_char *engineID, size_t engineIDLen, char *name);
260 struct usmUser *usm_get_user_from_list(u_char *engineID, size_t engineIDLen,
261 char *name, struct usmUser *userList,
263 struct usmUser *usm_add_user(struct usmUser *user);
264 struct usmUser *usm_add_user_to_list(struct usmUser *user,
265 struct usmUser *userList);
266 struct usmUser *usm_free_user(struct usmUser *user);
267 struct usmUser *usm_create_user(void);
268 struct usmUser *usm_create_initial_user(const char *name,
269 oid *authProtocol, size_t authProtocolLen,
270 oid *privProtocol, size_t privProtocolLen);
271 struct usmUser *usm_cloneFrom_user(struct usmUser *from, struct usmUser *to);
272 struct usmUser *usm_remove_user(struct usmUser *user);
273 struct usmUser *usm_remove_user_from_list(struct usmUser *user,
274 struct usmUser **userList);
275 char *get_objid(char *line, oid **optr, size_t *len);
276 void usm_save_users(const char *token, const char *type);
277 void usm_save_users_from_list(struct usmUser *user, const char *token,
279 void usm_save_user(struct usmUser *user, const char *token, const char *type);
280 SNMPCallback usm_store_users;
281 struct usmUser *usm_read_user(char *line);
282 void usm_parse_config_usmUser(const char *token, char *line);
284 void usm_set_password(const char *token, char *line);
285 void usm_set_user_password(struct usmUser *user, const char *token,
288 int init_usm_post_config(int majorid, int minorid, void *serverarg,
295 #endif /* SNMPUSM_H */