-: 0:Source:disp_status.c -: 0:Graph:/var/tsitkova/Sources/v10/trunk/src/lib/gssapi/krb5/disp_status.so.gcno -: 0:Data:/var/tsitkova/Sources/v10/trunk/src/lib/gssapi/krb5/disp_status.so.gcda -: 0:Runs:1064 -: 0:Programs:1 -: 1:/* -*- mode: c; c-basic-offset: 4; 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:#include "gssapiP_krb5.h" -: 25:#include "com_err.h" -: 26: -: 27:/* XXXX internationalization!! */ -: 28: -: 29:static inline int 18: 30:compare_OM_uint32 (OM_uint32 a, OM_uint32 b) -: 31:{ 18: 32: if (a < b) #####: 33: return -1; 18: 34: else if (a == b) 13: 35: return 0; -: 36: else 5: 37: return 1; -: 38:} -: 39:static inline void 6: 40:free_string (char *s) -: 41:{ 6: 42: free(s); 6: 43:} -: 44:#include "error_map.h" -: 45:#include 7: 46:char *get_error_message(OM_uint32 minor_code) -: 47:{ 7: 48: gsserrmap *p = k5_getspecific(K5_KEY_GSS_KRB5_ERROR_MESSAGE); 7: 49: char *msg = NULL; -: 50:#ifdef DEBUG -: 51: fprintf(stderr, "%s(%lu, p=%p)", __func__, (unsigned long) minor_code, -: 52: (void *) p); -: 53:#endif 7: 54: if (p) { 7: 55: char **v = gsserrmap_find(p, minor_code); 7: 56: if (v) { 7: 57: msg = *v; -: 58:#ifdef DEBUG -: 59: fprintf(stderr, " FOUND!"); -: 60:#endif -: 61: } -: 62: } 7: 63: if (msg == 0) #####: 64: msg = (char *)error_message((krb5_error_code)minor_code); -: 65:#ifdef DEBUG -: 66: fprintf(stderr, " -> %p/%s\n", (void *) msg, msg); -: 67:#endif 7: 68: return msg; -: 69:} -: 70:#define save_error_string_nocopy gss_krb5_save_error_string_nocopy 35: 71:static int save_error_string_nocopy(OM_uint32 minor_code, char *msg) -: 72:{ -: 73: gsserrmap *p; -: 74: int ret; -: 75: -: 76:#ifdef DEBUG -: 77: fprintf(stderr, "%s(%lu, %s)", __func__, (unsigned long) minor_code, msg); -: 78:#endif 35: 79: p = k5_getspecific(K5_KEY_GSS_KRB5_ERROR_MESSAGE); 35: 80: if (!p) { 24: 81: p = malloc(sizeof(*p)); 24: 82: if (p == NULL) { #####: 83: ret = 1; #####: 84: goto fail; -: 85: } 24: 86: if (gsserrmap_init(p) != 0) { #####: 87: free(p); #####: 88: p = NULL; #####: 89: ret = 1; #####: 90: goto fail; -: 91: } 24: 92: if (k5_setspecific(K5_KEY_GSS_KRB5_ERROR_MESSAGE, p) != 0) { #####: 93: gsserrmap_destroy(p); #####: 94: free(p); #####: 95: p = NULL; #####: 96: ret = 1; #####: 97: goto fail; -: 98: } -: 99: } 35: 100: ret = gsserrmap_replace_or_insert(p, minor_code, msg); -: 101:fail: -: 102:#ifdef DEBUG -: 103: fprintf(stderr, " p=%p %s\n", (void *)p, ret ? "FAIL" : "SUCCESS"); -: 104:#endif 35: 105: return ret; -: 106:} 35: 107:void save_error_string(OM_uint32 minor_code, char *msg) -: 108:{ 35: 109: char *s = strdup(msg); 35: 110: if (s) { 35: 111: if (save_error_string_nocopy(minor_code, s) != 0) #####: 112: free(s); -: 113: } 35: 114:} #####: 115:void save_error_message(OM_uint32 minor_code, const char *format, ...) -: 116:{ -: 117: char *s; -: 118: int n; -: 119: va_list ap; -: 120: #####: 121: va_start(ap, format); #####: 122: n = vasprintf(&s, format, ap); #####: 123: va_end(ap); #####: 124: if (n >= 0) { #####: 125: if (save_error_string_nocopy(minor_code, s) != 0) #####: 126: free(s); -: 127: } #####: 128:} 35: 129:void krb5_gss_save_error_info(OM_uint32 minor_code, krb5_context ctx) -: 130:{ -: 131: char *s; -: 132: -: 133:#ifdef DEBUG -: 134: fprintf(stderr, "%s(%lu, ctx=%p)\n", __func__, -: 135: (unsigned long) minor_code, (void *)ctx); -: 136:#endif 35: 137: s = (char *)krb5_get_error_message(ctx, (krb5_error_code)minor_code); -: 138:#ifdef DEBUG -: 139: fprintf(stderr, "%s(%lu, ctx=%p) saving: %s\n", __func__, -: 140: (unsigned long) minor_code, (void *)ctx, s); -: 141:#endif 35: 142: save_error_string(minor_code, s); -: 143: /* The get_error_message call above resets the error message in -: 144: ctx. Put it back, in case we make this call again *sigh*. */ 35: 145: krb5_set_error_message(ctx, (krb5_error_code)minor_code, "%s", s); 35: 146: krb5_free_error_message(ctx, s); 35: 147:} #####: 148:void krb5_gss_delete_error_info(void *p) -: 149:{ #####: 150: gsserrmap_destroy(p); #####: 151: free(p); #####: 152:} -: 153: -: 154:/**/ -: 155: -: 156:OM_uint32 KRB5_CALLCONV 7: 157:krb5_gss_display_status(minor_status, status_value, status_type, -: 158: mech_type, message_context, status_string) -: 159: OM_uint32 *minor_status; -: 160: OM_uint32 status_value; -: 161: int status_type; -: 162: gss_OID mech_type; -: 163: OM_uint32 *message_context; -: 164: gss_buffer_t status_string; -: 165:{ 7: 166: status_string->length = 0; 7: 167: status_string->value = NULL; -: 168: 28: 169: if ((mech_type != GSS_C_NULL_OID) && 21: 170: !g_OID_equal(gss_mech_krb5, mech_type) && #####: 171: !g_OID_equal(gss_mech_krb5_old, mech_type)) { #####: 172: *minor_status = 0; #####: 173: return(GSS_S_BAD_MECH); -: 174: } -: 175: 7: 176: if (status_type == GSS_C_GSS_CODE) { #####: 177: return(g_display_major_status(minor_status, status_value, -: 178: message_context, status_string)); 7: 179: } else if (status_type == GSS_C_MECH_CODE) { 7: 180: (void) gss_krb5int_initialize_library(); -: 181: 7: 182: if (*message_context) { #####: 183: *minor_status = (OM_uint32) G_BAD_MSG_CTX; #####: 184: return(GSS_S_FAILURE); -: 185: } -: 186: -: 187: /* If this fails, there's not much we can do... */ 7: 188: if (!g_make_string_buffer(krb5_gss_get_error_message(status_value), -: 189: status_string)) { #####: 190: *minor_status = ENOMEM; #####: 191: return(GSS_S_FAILURE); -: 192: } 7: 193: *minor_status = 0; 7: 194: return(GSS_S_COMPLETE); -: 195: } else { #####: 196: *minor_status = 0; #####: 197: return(GSS_S_BAD_STATUS); -: 198: } -: 199:}