diff options
Diffstat (limited to 'source4/heimdal/lib/krb5/error_string.c')
-rw-r--r-- | source4/heimdal/lib/krb5/error_string.c | 102 |
1 files changed, 97 insertions, 5 deletions
diff --git a/source4/heimdal/lib/krb5/error_string.c b/source4/heimdal/lib/krb5/error_string.c index 829c080a555..d2661dcaf5c 100644 --- a/source4/heimdal/lib/krb5/error_string.c +++ b/source4/heimdal/lib/krb5/error_string.c @@ -104,6 +104,68 @@ krb5_vset_error_message (krb5_context context, krb5_error_code ret, HEIMDAL_MUTEX_unlock(context->mutex); } +/** + * Prepend the context full error string for a specific error code. + * The error that is stored should be internationalized. + * + * @param context Kerberos 5 context + * @param ret The error code + * @param fmt Error string for the error code + * @param ... printf(3) style parameters. + * + * @ingroup krb5_error + */ + +void KRB5_LIB_FUNCTION +krb5_prepend_error_message(krb5_context context, krb5_error_code ret, + const char *fmt, ...) + __attribute__ ((format (printf, 3, 4))) +{ + va_list ap; + + va_start(ap, fmt); + krb5_vset_error_message (context, ret, fmt, ap); + va_end(ap); +} + +/** + * Prepend the contexts's full error string for a specific error code. + * + * @param context Kerberos 5 context + * @param ret The error code + * @param fmt Error string for the error code + * @param args printf(3) style parameters. + * + * @ingroup krb5_error + */ + +void KRB5_LIB_FUNCTION +krb5_vprepend_error_message (krb5_context context, krb5_error_code ret, + const char *fmt, va_list args) + __attribute__ ((format (printf, 3, 0))) +{ + char *str, *str2; + HEIMDAL_MUTEX_lock(context->mutex); + if (context->error_code != ret) { + HEIMDAL_MUTEX_unlock(context->mutex); + return; + } + vasprintf(&str, fmt, args); + if (context->error_string) { + int e; + + e = asprintf(&str2, "%s: %s", str, context->error_string); + free(context->error_string); + if (e < 0) + context->error_string = NULL; + else + context->error_string = str2; + free(str); + } else + context->error_string = str; + HEIMDAL_MUTEX_unlock(context->mutex); +} + /** * Return the error message in context. On error or no error string, @@ -155,7 +217,6 @@ krb5_have_error_string(krb5_context context) const char * KRB5_LIB_FUNCTION krb5_get_error_message(krb5_context context, krb5_error_code code) { - const char *cstr; char *str; HEIMDAL_MUTEX_lock(context->mutex); @@ -172,10 +233,13 @@ krb5_get_error_message(krb5_context context, krb5_error_code code) if (code == 0) return strdup("Success"); - - cstr = krb5_get_err_text(context, code); - if (cstr) - return strdup(cstr); + { + const char *msg; + char buf[128]; + msg = com_right_r(context->et_list, code, buf, sizeof(buf)); + if (msg) + return strdup(msg); + } if (asprintf(&str, "<unknown error: %d>", (int)code) == -1) return NULL; @@ -199,3 +263,31 @@ krb5_free_error_message(krb5_context context, const char *msg) { free(rk_UNCONST(msg)); } + + +/** + * Return the error string for the error code. The caller must not + * free the string. + * + * This function is deprecated since its not threadsafe. + * + * @param context Kerberos 5 context. + * @param code Kerberos error code. + * + * @return the error message matching code + * + * @ingroup krb5 + */ + +const char* KRB5_LIB_FUNCTION +krb5_get_err_text(krb5_context context, krb5_error_code code) KRB5_DEPRECATED +{ + 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; +} |