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 #include "k5-input.h" 51 52 /** helper macros **/ 53 54 #define g_OID_equal(o1, o2) \ 55 (((o1)->length == (o2)->length) && \ 56 (memcmp((o1)->elements, (o2)->elements, (o1)->length) == 0)) 57 58 /** malloc wrappers; these may actually do something later */ 59 60 #define xmalloc(n) malloc(n) 61 #define xrealloc(p,n) realloc(p,n) 62 #ifdef xfree 63 #undef xfree 64 #endif 65 #define xfree(p) free(p) 66 67 /** helper functions **/ 68 69 /* hide names from applications, especially glib applications */ 70 #define g_make_string_buffer gssint_g_make_string_buffer 71 #define g_token_size gssint_g_token_size 72 #define g_make_token_header gssint_g_make_token_header 73 #define g_get_token_header gssint_g_get_token_header 74 #define g_verify_token_header gssint_g_verify_token_header 75 #define g_display_major_status gssint_g_display_major_status 76 #define g_display_com_err_status gssint_g_display_com_err_status 77 #define g_seqstate_init gssint_g_seqstate_init 78 #define g_seqstate_check gssint_g_seqstate_check 79 #define g_seqstate_free gssint_g_seqstate_free 80 #define g_seqstate_size gssint_g_seqstate_size 81 #define g_seqstate_externalize gssint_g_seqstate_externalize 82 #define g_seqstate_internalize gssint_g_seqstate_internalize 83 #define g_canonicalize_host gssint_g_canonicalize_host 84 85 typedef struct g_seqnum_state_st *g_seqnum_state; 86 87 int g_make_string_buffer (const char *str, gss_buffer_t buffer); 88 89 unsigned int g_token_size (const gss_OID_desc * mech, unsigned int body_size); 90 91 void g_make_token_header (struct k5buf *buf, const gss_OID_desc *mech, 92 size_t body_size, int tok_type); 93 94 int g_get_token_header (struct k5input *in, gss_OID oid_out, 95 size_t *token_len_out); 96 97 int g_verify_token_header(struct k5input *in, gss_const_OID expected_mech); 98 99 OM_uint32 g_display_major_status (OM_uint32 *minor_status, 100 OM_uint32 status_value, 101 OM_uint32 *message_context, 102 gss_buffer_t status_string); 103 104 OM_uint32 g_display_com_err_status (OM_uint32 *minor_status, 105 OM_uint32 status_value, 106 gss_buffer_t status_string); 107 108 long g_seqstate_init(g_seqnum_state *state_out, uint64_t seqnum, 109 int do_replay, int do_sequence, int wide); 110 OM_uint32 g_seqstate_check(g_seqnum_state state, uint64_t seqnum); 111 void g_seqstate_free(g_seqnum_state state); 112 void g_seqstate_size(g_seqnum_state state, size_t *sizep); 113 long g_seqstate_externalize(g_seqnum_state state, unsigned char **buf, 114 size_t *lenremain); 115 long g_seqstate_internalize(g_seqnum_state *state_out, unsigned char **buf, 116 size_t *lenremain); 117 118 /** declarations of internal name mechanism functions **/ 119 120 OM_uint32 121 generic_gss_release_buffer( 122 OM_uint32 *, /* minor_status */ 123 gss_buffer_t); /* buffer */ 124 125 OM_uint32 126 generic_gss_release_oid_set( 127 OM_uint32 *, /* minor_status */ 128 gss_OID_set *); /* set */ 129 130 OM_uint32 131 generic_gss_release_oid( 132 OM_uint32 *, /* minor_status */ 133 gss_OID *); /* set */ 134 135 OM_uint32 136 generic_gss_copy_oid( 137 OM_uint32 *, /* minor_status */ 138 const gss_OID_desc * const, /* oid */ 139 gss_OID *); /* new_oid */ 140 141 OM_uint32 142 generic_gss_create_empty_oid_set( 143 OM_uint32 *, /* minor_status */ 144 gss_OID_set *); /* oid_set */ 145 146 OM_uint32 147 generic_gss_add_oid_set_member( 148 OM_uint32 *, /* minor_status */ 149 const gss_OID_desc * const, /* member_oid */ 150 gss_OID_set *); /* oid_set */ 151 152 OM_uint32 153 generic_gss_test_oid_set_member( 154 OM_uint32 *, /* minor_status */ 155 const gss_OID_desc * const, /* member */ 156 gss_OID_set, /* set */ 157 int *); /* present */ 158 159 OM_uint32 160 generic_gss_oid_to_str( 161 OM_uint32 *, /* minor_status */ 162 const gss_OID_desc * const, /* oid */ 163 gss_buffer_t); /* oid_str */ 164 165 OM_uint32 166 generic_gss_str_to_oid( 167 OM_uint32 *, /* minor_status */ 168 gss_buffer_t, /* oid_str */ 169 gss_OID *); /* oid */ 170 171 OM_uint32 172 generic_gss_oid_compose( 173 OM_uint32 *, /* minor_status */ 174 const char *, /* prefix */ 175 size_t, /* prefix_len */ 176 int, /* suffix */ 177 gss_OID_desc *); /* oid */ 178 179 OM_uint32 180 generic_gss_oid_decompose( 181 OM_uint32 *, /* minor_status */ 182 const char *, /*prefix */ 183 size_t, /* prefix_len */ 184 gss_OID_desc *, /* oid */ 185 int *); /* suffix */ 186 187 int gssint_mecherrmap_init(void); 188 void gssint_mecherrmap_destroy(void); 189 OM_uint32 gssint_mecherrmap_map(OM_uint32 minor, const gss_OID_desc *oid); 190 int gssint_mecherrmap_get(OM_uint32 minor, gss_OID mech_oid, 191 OM_uint32 *mech_minor); 192 OM_uint32 gssint_mecherrmap_map_errcode(OM_uint32 errcode); 193 194 /* 195 * Transfer contents of a k5buf to a gss_buffer and invalidate the source 196 * On unix, this is a simple pointer copy 197 * On windows, memory is reallocated and copied. 198 */ 199 static inline OM_uint32 200 k5buf_to_gss(OM_uint32 *minor, 201 struct k5buf *input_k5buf, 202 gss_buffer_t output_buffer) 203 { 204 OM_uint32 status = GSS_S_COMPLETE; 205 206 if (k5_buf_status(input_k5buf) != 0) { 207 *minor = ENOMEM; 208 return GSS_S_FAILURE; 209 } 210 output_buffer->length = input_k5buf->len; 211 #if defined(_WIN32) || defined(DEBUG_GSSALLOC) 212 if (output_buffer->length > 0) { 213 output_buffer->value = gssalloc_malloc(output_buffer->length); 214 if (output_buffer->value) { 215 memcpy(output_buffer->value, input_k5buf->data, 216 output_buffer->length); 217 } else { 218 status = GSS_S_FAILURE; 219 *minor = ENOMEM; 220 } 221 } else { 222 output_buffer->value = NULL; 223 } 224 k5_buf_free(input_k5buf); 225 #else 226 output_buffer->value = input_k5buf->data; 227 memset(input_k5buf, 0, sizeof(*input_k5buf)); 228 #endif 229 return status; 230 } 231 232 OM_uint32 generic_gss_create_empty_buffer_set 233 (OM_uint32 * /*minor_status*/, 234 gss_buffer_set_t * /*buffer_set*/); 235 236 OM_uint32 generic_gss_add_buffer_set_member 237 (OM_uint32 * /*minor_status*/, 238 const gss_buffer_t /*member_buffer*/, 239 gss_buffer_set_t * /*buffer_set*/); 240 241 OM_uint32 generic_gss_release_buffer_set 242 (OM_uint32 * /*minor_status*/, 243 gss_buffer_set_t * /*buffer_set*/); 244 245 OM_uint32 generic_gss_copy_oid_set 246 (OM_uint32 *, /* minor_status */ 247 const gss_OID_set_desc * const /*oidset*/, 248 gss_OID_set * /*new_oidset*/); 249 250 extern gss_OID_set gss_ma_known_attrs; 251 252 OM_uint32 generic_gss_display_mech_attr( 253 OM_uint32 *minor_status, 254 gss_const_OID mech_attr, 255 gss_buffer_t name, 256 gss_buffer_t short_desc, 257 gss_buffer_t long_desc); 258 259 #endif /* _GSSAPIP_GENERIC_H_ */ 260