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
120 struct usmStateReference {
122 size_t usr_name_length;
123 u_char *usr_engine_id;
124 size_t usr_engine_id_length;
125 oid *usr_auth_protocol;
126 size_t usr_auth_protocol_length;
127 u_char *usr_auth_key;
128 size_t usr_auth_key_length;
129 oid *usr_priv_protocol;
130 size_t usr_priv_protocol_length;
131 u_char *usr_priv_key;
132 size_t usr_priv_key_length;
137 /* struct usmUser: a structure to represent a given user in a list */
138 /* Note: Any changes made to this structure need to be reflected in
139 the following functions: */
150 size_t authProtocolLen;
154 size_t privProtocolLen;
157 u_char *userPublicString;
160 struct usmUser *next;
161 struct usmUser *prev;
169 void usm_set_reportErrorOnUnknownID (int value);
171 struct usmStateReference *
172 usm_malloc_usmStateReference (void);
174 void usm_free_usmStateReference (void *old);
176 int usm_set_usmStateReference_name (
177 struct usmStateReference *ref,
181 int usm_set_usmStateReference_engine_id (
182 struct usmStateReference *ref,
184 size_t engine_id_len);
186 int usm_set_usmStateReference_auth_protocol (
187 struct usmStateReference *ref,
189 size_t auth_protocol_len);
191 int usm_set_usmStateReference_auth_key (
192 struct usmStateReference *ref,
194 size_t auth_key_len);
196 int usm_set_usmStateReference_priv_protocol (
197 struct usmStateReference *ref,
199 size_t priv_protocol_len);
201 int usm_set_usmStateReference_priv_key (
202 struct usmStateReference *ref,
204 size_t priv_key_len);
206 int usm_set_usmStateReference_sec_level (
207 struct usmStateReference *ref,
210 #ifdef SNMP_TESTING_CODE
211 void emergency_print (u_char *field, u_int length);
214 int asn_predict_int_length (int type, long number, size_t len);
216 int asn_predict_length (int type, u_char *ptr, size_t u_char_len);
222 size_t priv_salt_length,
225 int usm_parse_security_parameters (
229 size_t *secEngineIDLen,
235 size_t *signature_length,
240 int usm_check_and_update_timeliness (
242 size_t secEngineIDLen,
247 int usm_generate_out_msg (int, u_char *, size_t, int, int, u_char *, size_t,
248 char *, size_t, int, u_char *, size_t, void *,
249 u_char *, size_t *, u_char **, size_t *);
251 int usm_process_in_msg (int, size_t, u_char *, int, int, u_char *, size_t,
252 u_char *, size_t *, char *, size_t *, u_char **, size_t *,
255 int usm_check_secLevel(int level, struct usmUser *user);
256 void usm_update_engine_time(void);
257 struct usmUser *usm_get_userList(void);
258 struct usmUser *usm_get_user(u_char *engineID, size_t engineIDLen, char *name);
259 struct usmUser *usm_get_user_from_list(u_char *engineID, size_t engineIDLen,
260 char *name, struct usmUser *userList,
262 struct usmUser *usm_add_user(struct usmUser *user);
263 struct usmUser *usm_add_user_to_list(struct usmUser *user,
264 struct usmUser *userList);
265 struct usmUser *usm_free_user(struct usmUser *user);
266 struct usmUser *usm_create_user(void);
267 struct usmUser *usm_create_initial_user(const char *name,
268 oid *authProtocol, size_t authProtocolLen,
269 oid *privProtocol, size_t privProtocolLen);
270 struct usmUser *usm_cloneFrom_user(struct usmUser *from, struct usmUser *to);
271 struct usmUser *usm_remove_user(struct usmUser *user);
272 struct usmUser *usm_remove_user_from_list(struct usmUser *user,
273 struct usmUser **userList);
274 char *get_objid(char *line, oid **optr, size_t *len);
275 void usm_save_users(const char *token, const char *type);
276 void usm_save_users_from_list(struct usmUser *user, const char *token,
278 void usm_save_user(struct usmUser *user, const char *token, const char *type);
279 SNMPCallback usm_store_users;
280 struct usmUser *usm_read_user(char *line);
281 void usm_parse_config_usmUser(const char *token, char *line);
283 void usm_set_password(const char *token, char *line);
284 void usm_set_user_password(struct usmUser *user, const char *token,
287 int init_usm_post_config(int majorid, int minorid, void *serverarg,
294 #endif /* SNMPUSM_H */