xref: /titanic_41/usr/src/uts/common/gssapi/mechs/krb5/include/gssapiP_generic.h (revision 6a634c9dca3093f3922e4b7ab826d7bdf17bf78e)
1 /*
2  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
3  */
4 /*
5  * Copyright 1993 by OpenVision Technologies, Inc.
6  *
7  * Permission to use, copy, modify, distribute, and sell this software
8  * and its documentation for any purpose is hereby granted without fee,
9  * provided that the above copyright notice appears in all copies and
10  * that both that copyright notice and this permission notice appear in
11  * supporting documentation, and that the name of OpenVision not be used
12  * in advertising or publicity pertaining to distribution of the software
13  * without specific, written prior permission. OpenVision makes no
14  * representations about the suitability of this software for any
15  * purpose.  It is provided "as is" without express or implied warranty.
16  *
17  * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
19  * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
20  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
21  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
22  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23  * PERFORMANCE OF THIS SOFTWARE.
24  */
25 
26 #ifndef _GSSAPIP_GENERIC_H_
27 #define _GSSAPIP_GENERIC_H_
28 
29 /*
30  * $Id: gssapiP_generic.h 18396 2006-07-25 20:29:43Z lxs $
31  */
32 
33 #if defined(_WIN32)
34 #include "k5-int.h"
35 #else
36 #include "autoconf.h"
37 #ifndef _KERNEL
38 #ifdef HAVE_STDLIB_H
39 #include <stdlib.h>
40 #endif /* !_KERNEL */
41 #endif
42 #endif
43 
44 #include "k5-thread.h"
45 
46 #include "gssapi_generic.h"
47 
48 #include "gssapi_err_generic.h"
49 #ifndef _KERNEL
50 #include <errno.h>
51 #else
52 #include <sys/errno.h>
53 #endif /* !_KERNEL */
54 
55 #include "k5-platform.h"
56 typedef UINT64_TYPE gssint_uint64;
57 
58 #include "gssapi/gssapi_ext.h"
59 
60 /** helper macros **/
61 
62 #if 0 /* SUNW15resync - on Solaris g_OID_equal is in gssapi_ext.h */
63 #define g_OID_equal(o1, o2) \
64    (((o1)->length == (o2)->length) && \
65     (memcmp((o1)->elements,(o2)->elements,(unsigned int) (o1)->length) == 0))
66 #endif
67 
68 /* this code knows that an int on the wire is 32 bits.  The type of
69    num should be at least this big, or the extra shifts may do weird
70    things */
71 
72 #define TWRITE_INT(ptr, num, bigend) \
73    (ptr)[0] = (char) ((bigend)?((num)>>24):((num)&0xff)); \
74    (ptr)[1] = (char) ((bigend)?(((num)>>16)&0xff):(((num)>>8)&0xff)); \
75    (ptr)[2] = (char) ((bigend)?(((num)>>8)&0xff):(((num)>>16)&0xff)); \
76    (ptr)[3] = (char) ((bigend)?((num)&0xff):((num)>>24)); \
77    (ptr) += 4;
78 
79 #define TWRITE_INT16(ptr, num, bigend) \
80    (ptr)[0] = (char) ((bigend)?((num)>>24):((num)&0xff)); \
81    (ptr)[1] = (char) ((bigend)?(((num)>>16)&0xff):(((num)>>8)&0xff)); \
82    (ptr) += 2;
83 
84 #define TREAD_INT(ptr, num, bigend) \
85    (num) = (((ptr)[0]<<((bigend)?24: 0)) | \
86             ((ptr)[1]<<((bigend)?16: 8)) | \
87             ((ptr)[2]<<((bigend)? 8:16)) | \
88             ((ptr)[3]<<((bigend)? 0:24))); \
89    (ptr) += 4;
90 
91 #define TREAD_INT16(ptr, num, bigend) \
92    (num) = (((ptr)[0]<<((bigend)?24: 0)) | \
93             ((ptr)[1]<<((bigend)?16: 8))); \
94    (ptr) += 2;
95 
96 #define TWRITE_STR(ptr, str, len) \
97   (void) memcpy((ptr), (char *) (str), (len)); \
98    (ptr) += (len);
99 
100 #define TREAD_STR(ptr, str, len) \
101    (str) = (ptr); \
102    (ptr) += (len);
103 
104 #define TWRITE_BUF(ptr, buf, bigend) \
105    TWRITE_INT((ptr), (buf).length, (bigend)); \
106    TWRITE_STR((ptr), (buf).value, (buf).length);
107 
108 /** malloc wrappers; these may actually do something later */
109 
110 #ifdef _KERNEL
111 #define xmalloc(n) MALLOC(n)
112 #else
113 #define xmalloc(n) malloc(n)
114 #endif
115 
116 #define xrealloc(p,n) realloc(p,n)
117 #ifdef xfree
118 #undef xfree
119 #endif
120 
121 #ifdef _KERNEL
122 #define xfree_wrap(p,sze) kmem_free(p,sze)
123 #else
124 #define xfree_wrap(p,sze) free(p)
125 #define xfree(p) free(p)
126 #endif
127 
128 /** helper functions **/
129 
130 /* hide names from applications, especially glib applications */
131 #define	g_set_init		gssint_g_set_init
132 #define	g_set_destroy		gssint_g_set_destroy
133 #define	g_set_entry_add		gssint_g_set_entry_add
134 #define	g_set_entry_delete	gssint_g_set_entry_delete
135 #define	g_set_entry_get		gssint_g_set_entry_get
136 #define	g_save_name		gssint_g_save_name
137 #define	g_save_cred_id		gssint_g_save_cred_id
138 #define	g_save_ctx_id		gssint_g_save_ctx_id
139 #define	g_save_lucidctx_id	gssint_g_save_lucidctx_id
140 #define	g_validate_name		gssint_g_validate_name
141 #define	g_validate_cred_id	gssint_g_validate_cred_id
142 #define	g_validate_ctx_id	gssint_g_validate_ctx_id
143 #define	g_validate_lucidctx_id	gssint_g_validate_lucidctx_id
144 #define	g_delete_name		gssint_g_delete_name
145 #define	g_delete_cred_id	gssint_g_delete_cred_id
146 #define	g_delete_ctx_id		gssint_g_delete_ctx_id
147 #define	g_delete_lucidctx_id	gssint_g_delete_lucidctx_id
148 #define	g_make_string_buffer	gssint_g_make_string_buffer
149 #define	g_token_size		gssint_g_token_size
150 #define	g_make_token_header	gssint_g_make_token_header
151 #define	g_verify_token_header	gssint_g_verify_token_header
152 #define	g_display_major_status	gssint_g_display_major_status
153 #define	g_display_com_err_status gssint_g_display_com_err_status
154 #define	g_order_init		gssint_g_order_init
155 #define	g_order_check		gssint_g_order_check
156 #define	g_order_free		gssint_g_order_free
157 #define	g_queue_size		gssint_g_queue_size
158 #define	g_queue_externalize	gssint_g_queue_externalize
159 #define	g_queue_internalize	gssint_g_queue_internalize
160 #define	g_canonicalize_host	gssint_g_canonicalize_host
161 #define	g_local_host_name	gssint_g_local_host_name
162 #define	g_strdup		gssint_g_strdup
163 
164 typedef struct _g_set_elt *g_set_elt;
165 typedef struct {
166     k5_mutex_t mutex;
167     void *data;
168 } g_set;
169 #define G_SET_INIT { K5_MUTEX_PARTIAL_INITIALIZER, 0 }
170 
171 int g_set_init (g_set_elt *s);
172 int g_set_destroy (g_set_elt *s);
173 int g_set_entry_add (g_set_elt *s, void *key, void *value);
174 int g_set_entry_delete (g_set_elt *s, void *key);
175 int g_set_entry_get (g_set_elt *s, void *key, void **value);
176 
177 int g_save_name (g_set *vdb, gss_name_t name);
178 int g_save_cred_id (g_set *vdb, gss_cred_id_t cred);
179 int g_save_ctx_id (g_set *vdb, gss_ctx_id_t ctx);
180 int g_save_lucidctx_id (g_set *vdb, void *lctx);
181 
182 int g_validate_name (g_set *vdb, gss_name_t name);
183 int g_validate_cred_id (g_set *vdb, gss_cred_id_t cred);
184 int g_validate_ctx_id (g_set *vdb, gss_ctx_id_t ctx);
185 int g_validate_lucidctx_id (g_set *vdb, void *lctx);
186 
187 int g_delete_name (g_set *vdb, gss_name_t name);
188 int g_delete_cred_id (g_set *vdb, gss_cred_id_t cred);
189 int g_delete_ctx_id (g_set *vdb, gss_ctx_id_t ctx);
190 int g_delete_lucidctx_id (g_set *vdb, void *lctx);
191 
192 int g_make_string_buffer (const char *str, gss_buffer_t buffer);
193 
194 unsigned int g_token_size (const gss_OID_desc * mech, unsigned int body_size);
195 
196 void g_make_token_header (const gss_OID_desc * mech, unsigned int body_size,
197 			  unsigned char **buf, int tok_type);
198 
199 gss_int32 g_verify_token_header (const gss_OID_desc * mech,
200 				 unsigned int *body_size,
201 				 unsigned char **buf, int tok_type,
202 				 unsigned int toksize_in,
203 				 int wrapper_required);
204 
205 OM_uint32 g_display_major_status (OM_uint32 *minor_status,
206 				 OM_uint32 status_value,
207 				 OM_uint32 *message_context,
208 				 gss_buffer_t status_string);
209 
210 OM_uint32 g_display_com_err_status (OM_uint32 *minor_status,
211 				   OM_uint32 status_value,
212 				   gss_buffer_t status_string);
213 
214 gss_int32 g_order_init (void **queue, gssint_uint64 seqnum,
215 				  int do_replay, int do_sequence, int wide);
216 
217 gss_int32 g_order_check (void **queue, gssint_uint64 seqnum);
218 
219 void g_order_free (void **queue);
220 
221 gss_uint32 g_queue_size(void *vqueue, size_t *sizep);
222 gss_uint32 g_queue_externalize(void *vqueue, unsigned char **buf,
223 			       size_t *lenremain);
224 gss_uint32 g_queue_internalize(void **vqueue, unsigned char **buf,
225 			       size_t *lenremain);
226 
227 char *g_strdup (char *str);
228 
229 /** declarations of internal name mechanism functions **/
230 
231 #if 0 /* SUNW15resync - mved to mglueP.h for sake of non-krb5 mechs */
232 OM_uint32 generic_gss_release_buffer
233 (OM_uint32*,       /* minor_status */
234             gss_buffer_t      /* buffer */
235            );
236 
237 OM_uint32 generic_gss_release_oid_set
238 (OM_uint32*,       /* minor_status */
239             gss_OID_set*      /* set */
240            );
241 
242 OM_uint32 generic_gss_release_oid
243 (OM_uint32*,       /* minor_status */
244             gss_OID*         /* set */
245            );
246 
247 OM_uint32 generic_gss_copy_oid
248 (OM_uint32 *,	/* minor_status */
249             gss_OID_desc * const,   /* oid */ /* SUNW15resync */
250 	    gss_OID *		/* new_oid */
251 	    );
252 
253 OM_uint32 generic_gss_create_empty_oid_set
254 (OM_uint32 *,	/* minor_status */
255 	    gss_OID_set *	/* oid_set */
256 	   );
257 
258 OM_uint32 generic_gss_add_oid_set_member
259 (OM_uint32 *,	/* minor_status */
260 	    const gss_OID_desc * const,		/* member_oid */
261 	    gss_OID_set *	/* oid_set */
262 	   );
263 
264 OM_uint32 generic_gss_test_oid_set_member
265 (OM_uint32 *,	/* minor_status */
266 	    const gss_OID_desc * const,		/* member */
267 	    gss_OID_set,	/* set */
268 	    int *		/* present */
269 	   );
270 
271 OM_uint32 generic_gss_oid_to_str
272 (OM_uint32 *,	/* minor_status */
273 	    const gss_OID_desc * const,		/* oid */
274 	    gss_buffer_t	/* oid_str */
275 	   );
276 
277 OM_uint32 generic_gss_str_to_oid
278 (OM_uint32 *,	/* minor_status */
279 	    gss_buffer_t,	/* oid_str */
280 	    gss_OID *		/* oid */
281 	   );
282 
283 OM_uint32
284 generic_gss_oid_compose(
285     OM_uint32 *,        /* minor_status */
286     const char *,       /* prefix */
287     size_t,             /* prefix_len */
288     int,                /* suffix */
289     gss_OID_desc *);    /* oid */
290 
291 OM_uint32
292 generic_gss_oid_decompose(
293     OM_uint32 *,        /* minor_status */
294     const char *,       /*prefix */
295     size_t,             /* prefix_len */
296     gss_OID_desc *,     /* oid */
297     int *);             /* suffix */
298 
299 #endif /* 0 */
300 
301 #ifndef _KERNEL
302 int gssint_mecherrmap_init(void);
303 void gssint_mecherrmap_destroy(void);
304 OM_uint32 gssint_mecherrmap_map(OM_uint32 minor, const gss_OID_desc *oid);
305 int gssint_mecherrmap_get(OM_uint32 minor, gss_OID mech_oid,
306 			OM_uint32 *mech_minor);
307 OM_uint32 gssint_mecherrmap_map_errcode(OM_uint32 errcode);
308 #endif
309 
310 #endif /* _GSSAPIP_GENERIC_H_ */
311