]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/net/snmp/lib/v2_0/include/snmpusm.h
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / net / snmp / lib / v2_0 / include / snmpusm.h
1 //==========================================================================
2 //
3 //      ./lib/current/include/snmpusm.h
4 //
5 //
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.
11 //
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.
15 //
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
19 // for more details.
20 //
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.
24 //
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.
31 //
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.
34 //
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####
40 //
41 // -------------------------------------------
42 //
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.
48 //
49 // The release used was version 4.1.2 of May 2000.  "ucd-snmp-4.1.2"
50 // -------------------------------------------
51 //
52 //####UCDSNMPCOPYRIGHTEND####
53 //==========================================================================
54 //#####DESCRIPTIONBEGIN####
55 //
56 // Author(s):    hmt
57 // Contributors: hmt
58 // Date:         2000-05-30
59 // Purpose:      Port of UCD-SNMP distribution to eCos.
60 // Description:  
61 //              
62 //
63 //####DESCRIPTIONEND####
64 //
65 //==========================================================================
66 /********************************************************************
67        Copyright 1989, 1991, 1992 by Carnegie Mellon University
68
69                           Derivative Work -
70 Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
71
72                          All Rights Reserved
73
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
81 permission.
82
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 *********************************************************************/
92 /* 
93  * snmpusm.h
94  *
95  * Header file for USM support.
96  */
97
98 #ifndef SNMPUSM_H
99 #define SNMPUSM_H
100
101 #ifdef __cplusplus
102 extern "C" {
103 #endif
104
105 #define WILDCARDSTRING "*"
106
107 /*
108  * General.
109  */
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. */
113
114 #define USM_TIME_WINDOW                 150
115 #define USM_MD5_AND_SHA_AUTH_LEN        12      /* bytes */
116
117
118 /*
119  * Structures.
120  */
121 struct usmStateReference {
122         char            *usr_name;
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;
134         u_int            usr_sec_level;
135 };
136
137
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: */
141
142 struct usmUser;
143 struct usmUser {
144    u_char         *engineID;
145    size_t          engineIDLen;
146    char           *name;
147    char           *secName;
148    oid            *cloneFrom;
149    size_t          cloneFromLen;
150    oid            *authProtocol;
151    size_t          authProtocolLen;
152    u_char         *authKey;
153    size_t          authKeyLen;
154    oid            *privProtocol;
155    size_t          privProtocolLen;
156    u_char         *privKey;
157    size_t          privKeyLen;
158    u_char         *userPublicString;
159    int             userStatus;
160    int             userStorageType;
161    struct usmUser *next;
162    struct usmUser *prev;
163 };
164
165
166
167 /*
168  * Prototypes.
169  */
170 void    usm_set_reportErrorOnUnknownID (int value);
171
172 struct usmStateReference *
173         usm_malloc_usmStateReference (void);
174
175 void    usm_free_usmStateReference (void *old);
176
177 int     usm_set_usmStateReference_name (
178                 struct usmStateReference        *ref,
179                 char                            *name,
180                 size_t                           name_len);
181
182 int     usm_set_usmStateReference_engine_id (
183                 struct usmStateReference        *ref,
184                 u_char                          *engine_id,
185                 size_t                           engine_id_len);
186
187 int     usm_set_usmStateReference_auth_protocol (
188                 struct usmStateReference *ref,
189                 oid *auth_protocol,
190                 size_t auth_protocol_len);
191
192 int     usm_set_usmStateReference_auth_key (
193                 struct usmStateReference *ref,
194                 u_char *auth_key,
195                 size_t auth_key_len);
196
197 int     usm_set_usmStateReference_priv_protocol (
198                 struct usmStateReference *ref,
199                 oid *priv_protocol,
200                 size_t priv_protocol_len);
201
202 int     usm_set_usmStateReference_priv_key (
203                 struct usmStateReference *ref,
204                 u_char *priv_key,
205                 size_t priv_key_len);
206
207 int     usm_set_usmStateReference_sec_level (
208                 struct usmStateReference *ref,
209                 int sec_level);
210
211 #ifdef SNMP_TESTING_CODE
212 void    emergency_print (u_char *field, u_int length);
213 #endif
214
215 int     asn_predict_int_length (int type, long number, size_t len);
216
217 int     asn_predict_length (int type, u_char *ptr, size_t u_char_len);
218
219 int     usm_set_salt (
220                 u_char          *iv,
221                 size_t          *iv_length,
222                 u_char          *priv_salt,
223                 size_t           priv_salt_length,
224                 u_char          *msgSalt );
225
226 int     usm_parse_security_parameters (
227                 u_char  *secParams,
228                 size_t   remaining,
229                 u_char  *secEngineID,
230                 size_t  *secEngineIDLen,
231                 u_int   *boots_uint,
232                 u_int   *time_uint,
233                 char    *secName,
234                 size_t  *secNameLen,
235                 u_char  *signature,
236                 size_t  *signature_length,
237                 u_char  *salt,
238                 size_t  *salt_length,
239                 u_char **data_ptr);
240
241 int     usm_check_and_update_timeliness (
242                 u_char *secEngineID,
243                 size_t  secEngineIDLen,
244                 u_int   boots_uint,
245                 u_int   time_uint,
246                 int    *error);
247
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 *);
251
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 *,
254                             size_t *, void **);
255
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,
262                                        int use_default);
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,
278                                         const char *type);
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);
283
284 void            usm_set_password(const char *token, char *line);
285 void            usm_set_user_password(struct usmUser *user, const char *token,
286                                       char *line);
287 void            init_usm(void);
288 int             init_usm_post_config(int majorid, int minorid, void *serverarg,
289                                      void *clientarg);
290
291 #ifdef __cplusplus
292 }
293 #endif
294
295 #endif /* SNMPUSM_H */