1 /* #pragma ident "@(#)g_inquire_names.c 1.16 04/02/23 SMI" */ 2 3 /* 4 * Copyright 1996 by Sun Microsystems, Inc. 5 * 6 * Permission to use, copy, modify, distribute, and sell this software 7 * and its documentation for any purpose is hereby granted without fee, 8 * provided that the above copyright notice appears in all copies and 9 * that both that copyright notice and this permission notice appear in 10 * supporting documentation, and that the name of Sun Microsystems not be used 11 * in advertising or publicity pertaining to distribution of the software 12 * without specific, written prior permission. Sun Microsystems makes no 13 * representations about the suitability of this software for any 14 * purpose. It is provided "as is" without express or implied warranty. 15 * 16 * SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 18 * EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF 20 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 21 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 22 * PERFORMANCE OF THIS SOFTWARE. 23 */ 24 25 /* 26 * glue routine for gss_inquire_context 27 */ 28 29 #include "mglueP.h" 30 31 #define MAX_MECH_OID_PAIRS 32 32 33 /* Last argument new for V2 */ 34 OM_uint32 KRB5_CALLCONV 35 gss_inquire_names_for_mech(minor_status, mechanism, name_types) 36 37 OM_uint32 * minor_status; 38 gss_OID mechanism; 39 gss_OID_set * name_types; 40 41 { 42 OM_uint32 status; 43 gss_OID selected_mech = GSS_C_NO_OID, public_mech; 44 gss_mechanism mech; 45 46 /* Initialize outputs. */ 47 48 if (minor_status != NULL) 49 *minor_status = 0; 50 51 if (name_types != NULL) 52 *name_types = GSS_C_NO_OID_SET; 53 54 /* Validate arguments. */ 55 56 if (minor_status == NULL) 57 return (GSS_S_CALL_INACCESSIBLE_WRITE); 58 59 if (name_types == NULL) 60 return (GSS_S_CALL_INACCESSIBLE_WRITE); 61 62 /* 63 * select the approprate underlying mechanism routine and 64 * call it. 65 */ 66 67 status = gssint_select_mech_type(minor_status, mechanism, 68 &selected_mech); 69 if (status != GSS_S_COMPLETE) 70 return (status); 71 72 mech = gssint_get_mechanism(selected_mech); 73 if (mech == NULL) 74 return GSS_S_BAD_MECH; 75 else if (mech->gss_inquire_names_for_mech == NULL) 76 return GSS_S_UNAVAILABLE; 77 public_mech = gssint_get_public_oid(selected_mech); 78 status = mech->gss_inquire_names_for_mech(minor_status, public_mech, 79 name_types); 80 if (status != GSS_S_COMPLETE) 81 map_error(minor_status, mech); 82 83 return status; 84 } 85 86 static OM_uint32 87 val_inq_mechs4name_args( 88 OM_uint32 *minor_status, 89 const gss_name_t input_name, 90 gss_OID_set *mech_set) 91 { 92 93 /* Initialize outputs. */ 94 if (minor_status != NULL) 95 *minor_status = 0; 96 97 if (mech_set != NULL) 98 *mech_set = GSS_C_NO_OID_SET; 99 100 /* Validate arguments.e 101 */ 102 if (minor_status == NULL) 103 return (GSS_S_CALL_INACCESSIBLE_WRITE); 104 105 if (input_name == GSS_C_NO_NAME) 106 return (GSS_S_BAD_NAME); 107 108 return (GSS_S_COMPLETE); 109 } 110 111 static int 112 mech_supports_nametype(gss_OID mech_oid, gss_OID name_type) 113 { 114 OM_uint32 status, minor; 115 gss_OID_set types = GSS_C_NO_OID_SET; 116 int present; 117 118 status = gss_inquire_names_for_mech(&minor, mech_oid, &types); 119 if (status != GSS_S_COMPLETE) 120 return (0); 121 status = gss_test_oid_set_member(&minor, name_type, types, &present); 122 (void) gss_release_oid_set(&minor, &types); 123 return (status == GSS_S_COMPLETE && present); 124 } 125 126 OM_uint32 KRB5_CALLCONV 127 gss_inquire_mechs_for_name(OM_uint32 *minor_status, 128 const gss_name_t input_name, gss_OID_set *mech_set) 129 { 130 OM_uint32 status, tmpmin; 131 gss_OID_set all_mechs = GSS_C_NO_OID_SET; 132 gss_OID_set mechs = GSS_C_NO_OID_SET; 133 gss_OID mech_oid, name_type; 134 gss_buffer_desc name_buffer = GSS_C_EMPTY_BUFFER; 135 size_t i; 136 137 status = val_inq_mechs4name_args(minor_status, input_name, mech_set); 138 if (status != GSS_S_COMPLETE) 139 return (status); 140 141 status = gss_display_name(minor_status, input_name, &name_buffer, 142 &name_type); 143 if (status != GSS_S_COMPLETE) 144 goto cleanup; 145 status = gss_indicate_mechs(minor_status, &all_mechs); 146 if (status != GSS_S_COMPLETE) 147 goto cleanup; 148 status = gss_create_empty_oid_set(minor_status, &mechs); 149 if (status != GSS_S_COMPLETE) 150 goto cleanup; 151 for (i = 0; i < all_mechs->count; i++) { 152 mech_oid = &all_mechs->elements[i]; 153 if (mech_supports_nametype(mech_oid, name_type)) { 154 status = gss_add_oid_set_member(minor_status, mech_oid, &mechs); 155 if (status != GSS_S_COMPLETE) 156 goto cleanup; 157 } 158 } 159 160 *mech_set = mechs; 161 mechs = GSS_C_NO_OID_SET; 162 163 cleanup: 164 (void) gss_release_buffer(&tmpmin, &name_buffer); 165 (void) gss_release_oid_set(&tmpmin, &all_mechs); 166 (void) gss_release_oid_set(&tmpmin, &mechs); 167 return (status); 168 } 169