1 /* -*- mode: c; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright 1993 by OpenVision Technologies, Inc. 4 * 5 * Permission to use, copy, modify, distribute, and sell this software 6 * and its documentation for any purpose is hereby granted without fee, 7 * provided that the above copyright notice appears in all copies and 8 * that both that copyright notice and this permission notice appear in 9 * supporting documentation, and that the name of OpenVision not be used 10 * in advertising or publicity pertaining to distribution of the software 11 * without specific, written prior permission. OpenVision makes no 12 * representations about the suitability of this software for any 13 * purpose. It is provided "as is" without express or implied warranty. 14 * 15 * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 17 * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR 18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF 19 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 20 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 21 * PERFORMANCE OF THIS SOFTWARE. 22 */ 23 24 #ifndef _GSSAPIP_GENERIC_H_ 25 #define _GSSAPIP_GENERIC_H_ 26 27 /* 28 * $Id$ 29 */ 30 31 #if defined(_WIN32) 32 #include "k5-int.h" 33 #else 34 #include "autoconf.h" 35 #ifdef HAVE_STDLIB_H 36 #include <stdlib.h> 37 #endif 38 #endif 39 40 #include "k5-thread.h" 41 42 #include "gssapi_generic.h" 43 #include "gssapi_ext.h" 44 #include <gssapi/gssapi_alloc.h> 45 #include "gssapi_err_generic.h" 46 #include <errno.h> 47 48 #include "k5-platform.h" 49 #include "k5-buf.h" 50 51 /** helper macros **/ 52 53 #define g_OID_equal(o1, o2) \ 54 (((o1)->length == (o2)->length) && \ 55 (memcmp((o1)->elements, (o2)->elements, (o1)->length) == 0)) 56 57 /** malloc wrappers; these may actually do something later */ 58 59 #define xmalloc(n) malloc(n) 60 #define xrealloc(p,n) realloc(p,n) 61 #ifdef xfree 62 #undef xfree 63 #endif 64 #define xfree(p) free(p) 65 66 /** helper functions **/ 67 68 /* hide names from applications, especially glib applications */ 69 #define g_set_init gssint_g_set_init 70 #define g_set_destroy gssint_g_set_destroy 71 #define g_set_entry_add gssint_g_set_entry_add 72 #define g_set_entry_delete gssint_g_set_entry_delete 73 #define g_set_entry_get gssint_g_set_entry_get 74 #define g_make_string_buffer gssint_g_make_string_buffer 75 #define g_token_size gssint_g_token_size 76 #define g_make_token_header gssint_g_make_token_header 77 #define g_verify_token_header gssint_g_verify_token_header 78 #define g_display_major_status gssint_g_display_major_status 79 #define g_display_com_err_status gssint_g_display_com_err_status 80 #define g_seqstate_init gssint_g_seqstate_init 81 #define g_seqstate_check gssint_g_seqstate_check 82 #define g_seqstate_free gssint_g_seqstate_free 83 #define g_seqstate_size gssint_g_seqstate_size 84 #define g_seqstate_externalize gssint_g_seqstate_externalize 85 #define g_seqstate_internalize gssint_g_seqstate_internalize 86 #define g_canonicalize_host gssint_g_canonicalize_host 87 #define g_local_host_name gssint_g_local_host_name 88 #define g_strdup gssint_g_strdup 89 90 typedef struct _g_set_elt *g_set_elt; 91 typedef struct { 92 k5_mutex_t mutex; 93 void *data; 94 } g_set; 95 #define G_SET_INIT { K5_MUTEX_PARTIAL_INITIALIZER, 0 } 96 97 typedef struct g_seqnum_state_st *g_seqnum_state; 98 99 int g_set_init (g_set_elt *s); 100 int g_set_destroy (g_set_elt *s); 101 int g_set_entry_add (g_set_elt *s, void *key, void *value); 102 int g_set_entry_delete (g_set_elt *s, void *key); 103 int g_set_entry_get (g_set_elt *s, void *key, void **value); 104 105 int g_save_name (g_set *vdb, gss_name_t name); 106 int g_save_cred_id (g_set *vdb, gss_cred_id_t cred); 107 int g_save_ctx_id (g_set *vdb, gss_ctx_id_t ctx); 108 int g_save_lucidctx_id (g_set *vdb, void *lctx); 109 110 int g_validate_name (g_set *vdb, gss_name_t name); 111 int g_validate_cred_id (g_set *vdb, gss_cred_id_t cred); 112 int g_validate_ctx_id (g_set *vdb, gss_ctx_id_t ctx); 113 int g_validate_lucidctx_id (g_set *vdb, void *lctx); 114 115 int g_delete_name (g_set *vdb, gss_name_t name); 116 int g_delete_cred_id (g_set *vdb, gss_cred_id_t cred); 117 int g_delete_ctx_id (g_set *vdb, gss_ctx_id_t ctx); 118 int g_delete_lucidctx_id (g_set *vdb, void *lctx); 119 120 int g_make_string_buffer (const char *str, gss_buffer_t buffer); 121 122 unsigned int g_token_size (const gss_OID_desc * mech, unsigned int body_size); 123 124 void g_make_token_header (struct k5buf *buf, const gss_OID_desc *mech, 125 size_t body_size, int tok_type); 126 127 /* flags for g_verify_token_header() */ 128 #define G_VFY_TOKEN_HDR_WRAPPER_REQUIRED 0x01 129 130 gss_int32 g_verify_token_header (const gss_OID_desc * mech, 131 unsigned int *body_size, 132 unsigned char **buf, int tok_type, 133 unsigned int toksize_in, 134 int flags); 135 136 OM_uint32 g_display_major_status (OM_uint32 *minor_status, 137 OM_uint32 status_value, 138 OM_uint32 *message_context, 139 gss_buffer_t status_string); 140 141 OM_uint32 g_display_com_err_status (OM_uint32 *minor_status, 142 OM_uint32 status_value, 143 gss_buffer_t status_string); 144 145 long g_seqstate_init(g_seqnum_state *state_out, uint64_t seqnum, 146 int do_replay, int do_sequence, int wide); 147 OM_uint32 g_seqstate_check(g_seqnum_state state, uint64_t seqnum); 148 void g_seqstate_free(g_seqnum_state state); 149 void g_seqstate_size(g_seqnum_state state, size_t *sizep); 150 long g_seqstate_externalize(g_seqnum_state state, unsigned char **buf, 151 size_t *lenremain); 152 long g_seqstate_internalize(g_seqnum_state *state_out, unsigned char **buf, 153 size_t *lenremain); 154 155 char *g_strdup (char *str); 156 157 /** declarations of internal name mechanism functions **/ 158 159 OM_uint32 160 generic_gss_release_buffer( 161 OM_uint32 *, /* minor_status */ 162 gss_buffer_t); /* buffer */ 163 164 OM_uint32 165 generic_gss_release_oid_set( 166 OM_uint32 *, /* minor_status */ 167 gss_OID_set *); /* set */ 168 169 OM_uint32 170 generic_gss_release_oid( 171 OM_uint32 *, /* minor_status */ 172 gss_OID *); /* set */ 173 174 OM_uint32 175 generic_gss_copy_oid( 176 OM_uint32 *, /* minor_status */ 177 const gss_OID_desc * const, /* oid */ 178 gss_OID *); /* new_oid */ 179 180 OM_uint32 181 generic_gss_create_empty_oid_set( 182 OM_uint32 *, /* minor_status */ 183 gss_OID_set *); /* oid_set */ 184 185 OM_uint32 186 generic_gss_add_oid_set_member( 187 OM_uint32 *, /* minor_status */ 188 const gss_OID_desc * const, /* member_oid */ 189 gss_OID_set *); /* oid_set */ 190 191 OM_uint32 192 generic_gss_test_oid_set_member( 193 OM_uint32 *, /* minor_status */ 194 const gss_OID_desc * const, /* member */ 195 gss_OID_set, /* set */ 196 int *); /* present */ 197 198 OM_uint32 199 generic_gss_oid_to_str( 200 OM_uint32 *, /* minor_status */ 201 const gss_OID_desc * const, /* oid */ 202 gss_buffer_t); /* oid_str */ 203 204 OM_uint32 205 generic_gss_str_to_oid( 206 OM_uint32 *, /* minor_status */ 207 gss_buffer_t, /* oid_str */ 208 gss_OID *); /* oid */ 209 210 OM_uint32 211 generic_gss_oid_compose( 212 OM_uint32 *, /* minor_status */ 213 const char *, /* prefix */ 214 size_t, /* prefix_len */ 215 int, /* suffix */ 216 gss_OID_desc *); /* oid */ 217 218 OM_uint32 219 generic_gss_oid_decompose( 220 OM_uint32 *, /* minor_status */ 221 const char *, /*prefix */ 222 size_t, /* prefix_len */ 223 gss_OID_desc *, /* oid */ 224 int *); /* suffix */ 225 226 int gssint_mecherrmap_init(void); 227 void gssint_mecherrmap_destroy(void); 228 OM_uint32 gssint_mecherrmap_map(OM_uint32 minor, const gss_OID_desc *oid); 229 int gssint_mecherrmap_get(OM_uint32 minor, gss_OID mech_oid, 230 OM_uint32 *mech_minor); 231 OM_uint32 gssint_mecherrmap_map_errcode(OM_uint32 errcode); 232 233 /* 234 * Transfer contents of a k5buf to a gss_buffer and invalidate the source 235 * On unix, this is a simple pointer copy 236 * On windows, memory is reallocated and copied. 237 */ 238 static inline OM_uint32 239 k5buf_to_gss(OM_uint32 *minor, 240 struct k5buf *input_k5buf, 241 gss_buffer_t output_buffer) 242 { 243 OM_uint32 status = GSS_S_COMPLETE; 244 245 if (k5_buf_status(input_k5buf) != 0) { 246 *minor = ENOMEM; 247 return GSS_S_FAILURE; 248 } 249 output_buffer->length = input_k5buf->len; 250 #if defined(_WIN32) || defined(DEBUG_GSSALLOC) 251 if (output_buffer->length > 0) { 252 output_buffer->value = gssalloc_malloc(output_buffer->length); 253 if (output_buffer->value) { 254 memcpy(output_buffer->value, input_k5buf->data, 255 output_buffer->length); 256 } else { 257 status = GSS_S_FAILURE; 258 *minor = ENOMEM; 259 } 260 } else { 261 output_buffer->value = NULL; 262 } 263 k5_buf_free(input_k5buf); 264 #else 265 output_buffer->value = input_k5buf->data; 266 memset(input_k5buf, 0, sizeof(*input_k5buf)); 267 #endif 268 return status; 269 } 270 271 OM_uint32 generic_gss_create_empty_buffer_set 272 (OM_uint32 * /*minor_status*/, 273 gss_buffer_set_t * /*buffer_set*/); 274 275 OM_uint32 generic_gss_add_buffer_set_member 276 (OM_uint32 * /*minor_status*/, 277 const gss_buffer_t /*member_buffer*/, 278 gss_buffer_set_t * /*buffer_set*/); 279 280 OM_uint32 generic_gss_release_buffer_set 281 (OM_uint32 * /*minor_status*/, 282 gss_buffer_set_t * /*buffer_set*/); 283 284 OM_uint32 generic_gss_copy_oid_set 285 (OM_uint32 *, /* minor_status */ 286 const gss_OID_set_desc * const /*oidset*/, 287 gss_OID_set * /*new_oidset*/); 288 289 extern gss_OID_set gss_ma_known_attrs; 290 291 OM_uint32 generic_gss_display_mech_attr( 292 OM_uint32 *minor_status, 293 gss_const_OID mech_attr, 294 gss_buffer_t name, 295 gss_buffer_t short_desc, 296 gss_buffer_t long_desc); 297 298 #endif /* _GSSAPIP_GENERIC_H_ */ 299