1ab9b2e15Sgtb /* 25e01956fSGlenn Barry * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 3ab9b2e15Sgtb */ 47c478bd9Sstevel@tonic-gate /* 57c478bd9Sstevel@tonic-gate * Copyright 1993 by OpenVision Technologies, Inc. 6*55fea89dSDan Cross * 77c478bd9Sstevel@tonic-gate * Permission to use, copy, modify, distribute, and sell this software 87c478bd9Sstevel@tonic-gate * and its documentation for any purpose is hereby granted without fee, 97c478bd9Sstevel@tonic-gate * provided that the above copyright notice appears in all copies and 107c478bd9Sstevel@tonic-gate * that both that copyright notice and this permission notice appear in 117c478bd9Sstevel@tonic-gate * supporting documentation, and that the name of OpenVision not be used 127c478bd9Sstevel@tonic-gate * in advertising or publicity pertaining to distribution of the software 137c478bd9Sstevel@tonic-gate * without specific, written prior permission. OpenVision makes no 147c478bd9Sstevel@tonic-gate * representations about the suitability of this software for any 157c478bd9Sstevel@tonic-gate * purpose. It is provided "as is" without express or implied warranty. 16*55fea89dSDan Cross * 177c478bd9Sstevel@tonic-gate * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 187c478bd9Sstevel@tonic-gate * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 197c478bd9Sstevel@tonic-gate * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR 207c478bd9Sstevel@tonic-gate * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF 217c478bd9Sstevel@tonic-gate * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 227c478bd9Sstevel@tonic-gate * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 237c478bd9Sstevel@tonic-gate * PERFORMANCE OF THIS SOFTWARE. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _GSSAPIP_GENERIC_H_ 277c478bd9Sstevel@tonic-gate #define _GSSAPIP_GENERIC_H_ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 30159d09a2SMark Phalan * $Id: gssapiP_generic.h 18396 2006-07-25 20:29:43Z lxs $ 317c478bd9Sstevel@tonic-gate */ 327c478bd9Sstevel@tonic-gate 33ab9b2e15Sgtb #if defined(_WIN32) 34ab9b2e15Sgtb #include "k5-int.h" 357c478bd9Sstevel@tonic-gate #else 36ab9b2e15Sgtb #include "autoconf.h" 377c478bd9Sstevel@tonic-gate #ifndef _KERNEL 38ab9b2e15Sgtb #ifdef HAVE_STDLIB_H 397c478bd9Sstevel@tonic-gate #include <stdlib.h> 407c478bd9Sstevel@tonic-gate #endif /* !_KERNEL */ 417c478bd9Sstevel@tonic-gate #endif 42ab9b2e15Sgtb #endif 43ab9b2e15Sgtb 44ab9b2e15Sgtb #include "k5-thread.h" 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate #include "gssapi_generic.h" 47ab9b2e15Sgtb 487c478bd9Sstevel@tonic-gate #include "gssapi_err_generic.h" 49ab9b2e15Sgtb #ifndef _KERNEL 507c478bd9Sstevel@tonic-gate #include <errno.h> 51ab9b2e15Sgtb #else 52ab9b2e15Sgtb #include <sys/errno.h> 53ab9b2e15Sgtb #endif /* !_KERNEL */ 547c478bd9Sstevel@tonic-gate 55ab9b2e15Sgtb #include "k5-platform.h" 56ab9b2e15Sgtb typedef UINT64_TYPE gssint_uint64; 577c478bd9Sstevel@tonic-gate 58ab9b2e15Sgtb #include "gssapi/gssapi_ext.h" 597c478bd9Sstevel@tonic-gate 60ab9b2e15Sgtb /** helper macros **/ 61ab9b2e15Sgtb 62ab9b2e15Sgtb #if 0 /* SUNW15resync - on Solaris g_OID_equal is in gssapi_ext.h */ 63159d09a2SMark Phalan #define g_OID_equal(o1, o2) \ 64159d09a2SMark Phalan (((o1)->length == (o2)->length) && \ 65159d09a2SMark Phalan (memcmp((o1)->elements,(o2)->elements,(unsigned int) (o1)->length) == 0)) 667c478bd9Sstevel@tonic-gate #endif 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* this code knows that an int on the wire is 32 bits. The type of 697c478bd9Sstevel@tonic-gate num should be at least this big, or the extra shifts may do weird 707c478bd9Sstevel@tonic-gate things */ 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate #define TWRITE_INT(ptr, num, bigend) \ 737c478bd9Sstevel@tonic-gate (ptr)[0] = (char) ((bigend)?((num)>>24):((num)&0xff)); \ 747c478bd9Sstevel@tonic-gate (ptr)[1] = (char) ((bigend)?(((num)>>16)&0xff):(((num)>>8)&0xff)); \ 757c478bd9Sstevel@tonic-gate (ptr)[2] = (char) ((bigend)?(((num)>>8)&0xff):(((num)>>16)&0xff)); \ 767c478bd9Sstevel@tonic-gate (ptr)[3] = (char) ((bigend)?((num)&0xff):((num)>>24)); \ 777c478bd9Sstevel@tonic-gate (ptr) += 4; 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate #define TWRITE_INT16(ptr, num, bigend) \ 807c478bd9Sstevel@tonic-gate (ptr)[0] = (char) ((bigend)?((num)>>24):((num)&0xff)); \ 817c478bd9Sstevel@tonic-gate (ptr)[1] = (char) ((bigend)?(((num)>>16)&0xff):(((num)>>8)&0xff)); \ 827c478bd9Sstevel@tonic-gate (ptr) += 2; 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate #define TREAD_INT(ptr, num, bigend) \ 857c478bd9Sstevel@tonic-gate (num) = (((ptr)[0]<<((bigend)?24: 0)) | \ 867c478bd9Sstevel@tonic-gate ((ptr)[1]<<((bigend)?16: 8)) | \ 877c478bd9Sstevel@tonic-gate ((ptr)[2]<<((bigend)? 8:16)) | \ 887c478bd9Sstevel@tonic-gate ((ptr)[3]<<((bigend)? 0:24))); \ 897c478bd9Sstevel@tonic-gate (ptr) += 4; 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate #define TREAD_INT16(ptr, num, bigend) \ 927c478bd9Sstevel@tonic-gate (num) = (((ptr)[0]<<((bigend)?24: 0)) | \ 937c478bd9Sstevel@tonic-gate ((ptr)[1]<<((bigend)?16: 8))); \ 947c478bd9Sstevel@tonic-gate (ptr) += 2; 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate #define TWRITE_STR(ptr, str, len) \ 97159d09a2SMark Phalan (void) memcpy((ptr), (char *) (str), (len)); \ 987c478bd9Sstevel@tonic-gate (ptr) += (len); 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate #define TREAD_STR(ptr, str, len) \ 1017c478bd9Sstevel@tonic-gate (str) = (ptr); \ 1027c478bd9Sstevel@tonic-gate (ptr) += (len); 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate #define TWRITE_BUF(ptr, buf, bigend) \ 1057c478bd9Sstevel@tonic-gate TWRITE_INT((ptr), (buf).length, (bigend)); \ 1067c478bd9Sstevel@tonic-gate TWRITE_STR((ptr), (buf).value, (buf).length); 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate /** malloc wrappers; these may actually do something later */ 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate #ifdef _KERNEL 1117c478bd9Sstevel@tonic-gate #define xmalloc(n) MALLOC(n) 1127c478bd9Sstevel@tonic-gate #else 1137c478bd9Sstevel@tonic-gate #define xmalloc(n) malloc(n) 1147c478bd9Sstevel@tonic-gate #endif 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate #define xrealloc(p,n) realloc(p,n) 1177c478bd9Sstevel@tonic-gate #ifdef xfree 1187c478bd9Sstevel@tonic-gate #undef xfree 1197c478bd9Sstevel@tonic-gate #endif 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate #ifdef _KERNEL 1227c478bd9Sstevel@tonic-gate #define xfree_wrap(p,sze) kmem_free(p,sze) 1237c478bd9Sstevel@tonic-gate #else 1247c478bd9Sstevel@tonic-gate #define xfree_wrap(p,sze) free(p) 1257c478bd9Sstevel@tonic-gate #define xfree(p) free(p) 1267c478bd9Sstevel@tonic-gate #endif 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate /** helper functions **/ 1297c478bd9Sstevel@tonic-gate 130ab9b2e15Sgtb /* hide names from applications, especially glib applications */ 131ab9b2e15Sgtb #define g_set_init gssint_g_set_init 132ab9b2e15Sgtb #define g_set_destroy gssint_g_set_destroy 133ab9b2e15Sgtb #define g_set_entry_add gssint_g_set_entry_add 134ab9b2e15Sgtb #define g_set_entry_delete gssint_g_set_entry_delete 135ab9b2e15Sgtb #define g_set_entry_get gssint_g_set_entry_get 136ab9b2e15Sgtb #define g_save_name gssint_g_save_name 137ab9b2e15Sgtb #define g_save_cred_id gssint_g_save_cred_id 138ab9b2e15Sgtb #define g_save_ctx_id gssint_g_save_ctx_id 139ab9b2e15Sgtb #define g_save_lucidctx_id gssint_g_save_lucidctx_id 140ab9b2e15Sgtb #define g_validate_name gssint_g_validate_name 141ab9b2e15Sgtb #define g_validate_cred_id gssint_g_validate_cred_id 142ab9b2e15Sgtb #define g_validate_ctx_id gssint_g_validate_ctx_id 143ab9b2e15Sgtb #define g_validate_lucidctx_id gssint_g_validate_lucidctx_id 144ab9b2e15Sgtb #define g_delete_name gssint_g_delete_name 145ab9b2e15Sgtb #define g_delete_cred_id gssint_g_delete_cred_id 146ab9b2e15Sgtb #define g_delete_ctx_id gssint_g_delete_ctx_id 147ab9b2e15Sgtb #define g_delete_lucidctx_id gssint_g_delete_lucidctx_id 148ab9b2e15Sgtb #define g_make_string_buffer gssint_g_make_string_buffer 149ab9b2e15Sgtb #define g_token_size gssint_g_token_size 150ab9b2e15Sgtb #define g_make_token_header gssint_g_make_token_header 151ab9b2e15Sgtb #define g_verify_token_header gssint_g_verify_token_header 152ab9b2e15Sgtb #define g_display_major_status gssint_g_display_major_status 153ab9b2e15Sgtb #define g_display_com_err_status gssint_g_display_com_err_status 154ab9b2e15Sgtb #define g_order_init gssint_g_order_init 155ab9b2e15Sgtb #define g_order_check gssint_g_order_check 156ab9b2e15Sgtb #define g_order_free gssint_g_order_free 157ab9b2e15Sgtb #define g_queue_size gssint_g_queue_size 158ab9b2e15Sgtb #define g_queue_externalize gssint_g_queue_externalize 159ab9b2e15Sgtb #define g_queue_internalize gssint_g_queue_internalize 160ab9b2e15Sgtb #define g_canonicalize_host gssint_g_canonicalize_host 161ab9b2e15Sgtb #define g_local_host_name gssint_g_local_host_name 162ab9b2e15Sgtb #define g_strdup gssint_g_strdup 163ab9b2e15Sgtb 164ab9b2e15Sgtb typedef struct _g_set_elt *g_set_elt; 165ab9b2e15Sgtb typedef struct { 166ab9b2e15Sgtb k5_mutex_t mutex; 167ab9b2e15Sgtb void *data; 168ab9b2e15Sgtb } g_set; 169ab9b2e15Sgtb #define G_SET_INIT { K5_MUTEX_PARTIAL_INITIALIZER, 0 } 170ab9b2e15Sgtb 171ab9b2e15Sgtb int g_set_init (g_set_elt *s); 172ab9b2e15Sgtb int g_set_destroy (g_set_elt *s); 173ab9b2e15Sgtb int g_set_entry_add (g_set_elt *s, void *key, void *value); 174ab9b2e15Sgtb int g_set_entry_delete (g_set_elt *s, void *key); 175ab9b2e15Sgtb int g_set_entry_get (g_set_elt *s, void *key, void **value); 176ab9b2e15Sgtb 177ab9b2e15Sgtb int g_save_name (g_set *vdb, gss_name_t name); 178ab9b2e15Sgtb int g_save_cred_id (g_set *vdb, gss_cred_id_t cred); 179ab9b2e15Sgtb int g_save_ctx_id (g_set *vdb, gss_ctx_id_t ctx); 180ab9b2e15Sgtb int g_save_lucidctx_id (g_set *vdb, void *lctx); 181ab9b2e15Sgtb 182ab9b2e15Sgtb int g_validate_name (g_set *vdb, gss_name_t name); 183ab9b2e15Sgtb int g_validate_cred_id (g_set *vdb, gss_cred_id_t cred); 184ab9b2e15Sgtb int g_validate_ctx_id (g_set *vdb, gss_ctx_id_t ctx); 185ab9b2e15Sgtb int g_validate_lucidctx_id (g_set *vdb, void *lctx); 186ab9b2e15Sgtb 187ab9b2e15Sgtb int g_delete_name (g_set *vdb, gss_name_t name); 188ab9b2e15Sgtb int g_delete_cred_id (g_set *vdb, gss_cred_id_t cred); 189ab9b2e15Sgtb int g_delete_ctx_id (g_set *vdb, gss_ctx_id_t ctx); 190ab9b2e15Sgtb int g_delete_lucidctx_id (g_set *vdb, void *lctx); 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate int g_make_string_buffer (const char *str, gss_buffer_t buffer); 1937c478bd9Sstevel@tonic-gate 194ab9b2e15Sgtb unsigned int g_token_size (const gss_OID_desc * mech, unsigned int body_size); 1957c478bd9Sstevel@tonic-gate 196ab9b2e15Sgtb void g_make_token_header (const gss_OID_desc * mech, unsigned int body_size, 1977c478bd9Sstevel@tonic-gate unsigned char **buf, int tok_type); 1987c478bd9Sstevel@tonic-gate 199*55fea89dSDan Cross gss_int32 g_verify_token_header (const gss_OID_desc * mech, 200ab9b2e15Sgtb unsigned int *body_size, 201*55fea89dSDan Cross unsigned char **buf, int tok_type, 202ab9b2e15Sgtb unsigned int toksize_in, 203ab9b2e15Sgtb int wrapper_required); 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate OM_uint32 g_display_major_status (OM_uint32 *minor_status, 2067c478bd9Sstevel@tonic-gate OM_uint32 status_value, 2077c478bd9Sstevel@tonic-gate OM_uint32 *message_context, 2087c478bd9Sstevel@tonic-gate gss_buffer_t status_string); 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate OM_uint32 g_display_com_err_status (OM_uint32 *minor_status, 2117c478bd9Sstevel@tonic-gate OM_uint32 status_value, 2127c478bd9Sstevel@tonic-gate gss_buffer_t status_string); 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate gss_int32 g_order_init (void **queue, gssint_uint64 seqnum, 215ab9b2e15Sgtb int do_replay, int do_sequence, int wide); 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate gss_int32 g_order_check (void **queue, gssint_uint64 seqnum); 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate void g_order_free (void **queue); 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate gss_uint32 g_queue_size(void *vqueue, size_t *sizep); 2227c478bd9Sstevel@tonic-gate gss_uint32 g_queue_externalize(void *vqueue, unsigned char **buf, 2237c478bd9Sstevel@tonic-gate size_t *lenremain); 2247c478bd9Sstevel@tonic-gate gss_uint32 g_queue_internalize(void **vqueue, unsigned char **buf, 2257c478bd9Sstevel@tonic-gate size_t *lenremain); 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate char *g_strdup (char *str); 2287c478bd9Sstevel@tonic-gate 229ab9b2e15Sgtb /** declarations of internal name mechanism functions **/ 230ab9b2e15Sgtb 231ab9b2e15Sgtb #if 0 /* SUNW15resync - mved to mglueP.h for sake of non-krb5 mechs */ 232ab9b2e15Sgtb OM_uint32 generic_gss_release_buffer 233ab9b2e15Sgtb (OM_uint32*, /* minor_status */ 234ab9b2e15Sgtb gss_buffer_t /* buffer */ 235ab9b2e15Sgtb ); 236ab9b2e15Sgtb 237ab9b2e15Sgtb OM_uint32 generic_gss_release_oid_set 238ab9b2e15Sgtb (OM_uint32*, /* minor_status */ 239ab9b2e15Sgtb gss_OID_set* /* set */ 240ab9b2e15Sgtb ); 241ab9b2e15Sgtb 242ab9b2e15Sgtb OM_uint32 generic_gss_release_oid 243ab9b2e15Sgtb (OM_uint32*, /* minor_status */ 244ab9b2e15Sgtb gss_OID* /* set */ 245ab9b2e15Sgtb ); 246ab9b2e15Sgtb 247ab9b2e15Sgtb OM_uint32 generic_gss_copy_oid 248ab9b2e15Sgtb (OM_uint32 *, /* minor_status */ 249ab9b2e15Sgtb gss_OID_desc * const, /* oid */ /* SUNW15resync */ 250ab9b2e15Sgtb gss_OID * /* new_oid */ 251ab9b2e15Sgtb ); 252ab9b2e15Sgtb 253ab9b2e15Sgtb OM_uint32 generic_gss_create_empty_oid_set 254ab9b2e15Sgtb (OM_uint32 *, /* minor_status */ 255ab9b2e15Sgtb gss_OID_set * /* oid_set */ 256ab9b2e15Sgtb ); 257ab9b2e15Sgtb 258ab9b2e15Sgtb OM_uint32 generic_gss_add_oid_set_member 259ab9b2e15Sgtb (OM_uint32 *, /* minor_status */ 260159d09a2SMark Phalan const gss_OID_desc * const, /* member_oid */ 261ab9b2e15Sgtb gss_OID_set * /* oid_set */ 262ab9b2e15Sgtb ); 263ab9b2e15Sgtb 264ab9b2e15Sgtb OM_uint32 generic_gss_test_oid_set_member 265ab9b2e15Sgtb (OM_uint32 *, /* minor_status */ 266159d09a2SMark Phalan const gss_OID_desc * const, /* member */ 267ab9b2e15Sgtb gss_OID_set, /* set */ 268ab9b2e15Sgtb int * /* present */ 269ab9b2e15Sgtb ); 270ab9b2e15Sgtb 271ab9b2e15Sgtb OM_uint32 generic_gss_oid_to_str 272ab9b2e15Sgtb (OM_uint32 *, /* minor_status */ 273159d09a2SMark Phalan const gss_OID_desc * const, /* oid */ 274ab9b2e15Sgtb gss_buffer_t /* oid_str */ 275ab9b2e15Sgtb ); 276ab9b2e15Sgtb 277ab9b2e15Sgtb OM_uint32 generic_gss_str_to_oid 278ab9b2e15Sgtb (OM_uint32 *, /* minor_status */ 279ab9b2e15Sgtb gss_buffer_t, /* oid_str */ 280ab9b2e15Sgtb gss_OID * /* oid */ 281ab9b2e15Sgtb ); 282ba7b222eSGlenn Barry 283ba7b222eSGlenn Barry OM_uint32 284ba7b222eSGlenn Barry generic_gss_oid_compose( 285ba7b222eSGlenn Barry OM_uint32 *, /* minor_status */ 286ba7b222eSGlenn Barry const char *, /* prefix */ 287ba7b222eSGlenn Barry size_t, /* prefix_len */ 288ba7b222eSGlenn Barry int, /* suffix */ 289ba7b222eSGlenn Barry gss_OID_desc *); /* oid */ 290ba7b222eSGlenn Barry 291ba7b222eSGlenn Barry OM_uint32 292ba7b222eSGlenn Barry generic_gss_oid_decompose( 293ba7b222eSGlenn Barry OM_uint32 *, /* minor_status */ 294ba7b222eSGlenn Barry const char *, /*prefix */ 295ba7b222eSGlenn Barry size_t, /* prefix_len */ 296ba7b222eSGlenn Barry gss_OID_desc *, /* oid */ 297ba7b222eSGlenn Barry int *); /* suffix */ 298ba7b222eSGlenn Barry 299ab9b2e15Sgtb #endif /* 0 */ 3007c478bd9Sstevel@tonic-gate 3015e01956fSGlenn Barry #ifndef _KERNEL 3025e01956fSGlenn Barry int gssint_mecherrmap_init(void); 3035e01956fSGlenn Barry void gssint_mecherrmap_destroy(void); 3045e01956fSGlenn Barry OM_uint32 gssint_mecherrmap_map(OM_uint32 minor, const gss_OID_desc *oid); 3055e01956fSGlenn Barry int gssint_mecherrmap_get(OM_uint32 minor, gss_OID mech_oid, 3065e01956fSGlenn Barry OM_uint32 *mech_minor); 3075e01956fSGlenn Barry OM_uint32 gssint_mecherrmap_map_errcode(OM_uint32 errcode); 3085e01956fSGlenn Barry #endif 3095e01956fSGlenn Barry 3107c478bd9Sstevel@tonic-gate #endif /* _GSSAPIP_GENERIC_H_ */ 311