diff options
Diffstat (limited to 'lib/krb5/error_string.c')
| -rw-r--r-- | lib/krb5/error_string.c | 118 |
1 files changed, 22 insertions, 96 deletions
diff --git a/lib/krb5/error_string.c b/lib/krb5/error_string.c index fa181733d1e9..da86b375f83c 100644 --- a/lib/krb5/error_string.c +++ b/lib/krb5/error_string.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2003, 2005 - 2006 Kungliga Tekniska Högskolan + * Copyright (c) 2001, 2003, 2005 - 2020 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -47,12 +47,7 @@ KRB5_LIB_FUNCTION void KRB5_LIB_CALL krb5_clear_error_message(krb5_context context) { - HEIMDAL_MUTEX_lock(&context->mutex); - if (context->error_string) - free(context->error_string); - context->error_code = 0; - context->error_string = NULL; - HEIMDAL_MUTEX_unlock(&context->mutex); + heim_clear_error_message(context->hcontext); } /** @@ -96,27 +91,21 @@ krb5_set_error_message(krb5_context context, krb5_error_code ret, KRB5_LIB_FUNCTION void KRB5_LIB_CALL -krb5_vset_error_message (krb5_context context, krb5_error_code ret, - const char *fmt, va_list args) +krb5_vset_error_message(krb5_context context, krb5_error_code ret, + const char *fmt, va_list args) __attribute__ ((__format__ (__printf__, 3, 0))) { - int r; + const char *msg; if (context == NULL) return; - HEIMDAL_MUTEX_lock(&context->mutex); - if (context->error_string) { - free(context->error_string); - context->error_string = NULL; + heim_vset_error_message(context->hcontext, ret, fmt, args); + msg = heim_get_error_message(context->hcontext, ret); + if (msg) { + _krb5_debug(context, 100, "error message: %s: %d", msg, ret); + heim_free_error_message(context->hcontext, msg); } - context->error_code = ret; - r = vasprintf(&context->error_string, fmt, args); - if (r < 0) - context->error_string = NULL; - HEIMDAL_MUTEX_unlock(&context->mutex); - if (context->error_string) - _krb5_debug(context, 100, "error message: %s: %d", context->error_string, ret); } /** @@ -163,33 +152,8 @@ krb5_vprepend_error_message(krb5_context context, krb5_error_code ret, const char *fmt, va_list args) __attribute__ ((__format__ (__printf__, 3, 0))) { - char *str = NULL, *str2 = NULL; - - if (context == NULL) - return; - - HEIMDAL_MUTEX_lock(&context->mutex); - if (context->error_code != ret) { - HEIMDAL_MUTEX_unlock(&context->mutex); - return; - } - if (vasprintf(&str, fmt, args) < 0 || str == NULL) { - HEIMDAL_MUTEX_unlock(&context->mutex); - return; - } - if (context->error_string) { - int e; - - e = asprintf(&str2, "%s: %s", str, context->error_string); - free(context->error_string); - if (e < 0 || str2 == NULL) - context->error_string = NULL; - else - context->error_string = str2; - free(str); - } else - context->error_string = str; - HEIMDAL_MUTEX_unlock(&context->mutex); + if (context) + heim_vprepend_error_message(context->hcontext, ret, fmt, args); } /** @@ -208,10 +172,7 @@ krb5_vprepend_error_message(krb5_context context, krb5_error_code ret, KRB5_LIB_FUNCTION const char * KRB5_LIB_CALL krb5_get_error_message(krb5_context context, krb5_error_code code) { - char *str = NULL; const char *cstr = NULL; - char buf[128]; - int free_context = 0; if (code == 0) return strdup("Success"); @@ -224,42 +185,15 @@ krb5_get_error_message(krb5_context context, krb5_error_code code) * might be provided is if the krb5_init_context() call itself * failed. */ - if (context) - { - HEIMDAL_MUTEX_lock(&context->mutex); - if (context->error_string && - (code == context->error_code || context->error_code == 0)) - { - str = strdup(context->error_string); - } - HEIMDAL_MUTEX_unlock(&context->mutex); - - if (str) - return str; - } - else - { - if (krb5_init_context(&context) == 0) - free_context = 1; - } - - if (context) - cstr = com_right_r(context->et_list, code, buf, sizeof(buf)); - - if (free_context) + if (context == NULL && krb5_init_context(&context) == 0) { + cstr = heim_get_error_message(context->hcontext, code); krb5_free_context(context); - - if (cstr) - return strdup(cstr); - - cstr = error_message(code); - if (cstr) - return strdup(cstr); - - if (asprintf(&str, "<unknown error: %d>", (int)code) == -1 || str == NULL) - return NULL; - - return str; + } else if (context) { + cstr = heim_get_error_message(context->hcontext, code); + } else { + cstr = heim_get_error_message(NULL, code); + } + return cstr; } @@ -276,7 +210,7 @@ krb5_get_error_message(krb5_context context, krb5_error_code code) KRB5_LIB_FUNCTION void KRB5_LIB_CALL krb5_free_error_message(krb5_context context, const char *msg) { - free(rk_UNCONST(msg)); + heim_free_error_message(context ? context->hcontext : NULL, msg); } @@ -298,13 +232,5 @@ KRB5_LIB_FUNCTION const char* KRB5_LIB_CALL krb5_get_err_text(krb5_context context, krb5_error_code code) KRB5_DEPRECATED_FUNCTION("Use krb5_get_error_message instead") { - const char *p = NULL; - if(context != NULL) - p = com_right(context->et_list, code); - if(p == NULL) - p = strerror(code); - if (p == NULL) - p = "Unknown error"; - return p; + return krb5_get_error_message(context, code); } - |
