From 879b2383e1487170f7df30d6f901d5e9ef5a7706 Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Mon, 11 May 2009 20:55:51 +0000 Subject: [PATCH] pull up r22291 from trunk ------------------------------------------------------------------------ r22291 | ghudson | 2009-04-29 19:21:21 -0400 (Wed, 29 Apr 2009) | 9 lines Changed paths: M /trunk/src/include/k5-err.h M /trunk/src/include/k5-int.h M /trunk/src/lib/krb5/krb/kerrs.c M /trunk/src/lib/krb5/libkrb5.exports M /trunk/src/util/support/errors.c M /trunk/src/util/support/libkrb5support-fixed.exports ticket: 6479 subject: Add DEBUG_ERROR_LOCATIONS support If DEBUG_ERROR_LOCATIONS is defined, replace uses of krb5_set_error_message and krb5int_set_error with calls to the new _fl variants of those functions, and include filename and line number information in the calls. Requires C99-style variadic macros if defined. ticket: 6479 version_fixed: 1.7 git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-7@22333 dc483132-0cff-0310-8789-dd5450dbe970 --- src/include/k5-err.h | 21 ++++++++++++ src/include/k5-int.h | 5 +++ src/lib/krb5/krb/kerrs.c | 23 +++++++++++++ src/lib/krb5/libkrb5.exports | 1 + src/util/support/errors.c | 34 +++++++++++++++++-- src/util/support/libkrb5support-fixed.exports | 2 ++ 6 files changed, 84 insertions(+), 2 deletions(-) diff --git a/src/include/k5-err.h b/src/include/k5-err.h index a6dedcc88..e5fc9bddf 100644 --- a/src/include/k5-err.h +++ b/src/include/k5-err.h @@ -65,6 +65,22 @@ krb5int_vset_error (struct errinfo *ep, long code, __attribute__((__format__(__printf__, 3, 0))) #endif ; +void +krb5int_set_error_fl (struct errinfo *ep, long code, + const char *file, int line, + const char *fmt, ...) +#if !defined(__cplusplus) && (__GNUC__ > 2) + __attribute__((__format__(__printf__, 5, 6))) +#endif + ; +void +krb5int_vset_error_fl (struct errinfo *ep, long code, + const char *file, int line, + const char *fmt, va_list args) +#if !defined(__cplusplus) && (__GNUC__ > 2) + __attribute__((__format__(__printf__, 5, 0))) +#endif + ; const char * krb5int_get_error (struct errinfo *ep, long code); void @@ -74,4 +90,9 @@ krb5int_clear_error (struct errinfo *ep); void krb5int_set_error_info_callout_fn (const char *(KRB5_CALLCONV *f)(long)); +#ifdef DEBUG_ERROR_LOCATIONS +#define krb5int_set_error(ep, code, ...) \ + krb5int_set_error_fl(ep, code, __FILE__, __LINE__, __VA_ARGS__) +#endif + #endif /* K5_ERR_H */ diff --git a/src/include/k5-int.h b/src/include/k5-int.h index b991accb1..ca6769c11 100644 --- a/src/include/k5-int.h +++ b/src/include/k5-int.h @@ -2828,4 +2828,9 @@ krb5int_pac_sign(krb5_context context, const krb5_keyblock *privsvr_key, krb5_data *data); +#ifdef DEBUG_ERROR_LOCATIONS +#define krb5_set_error_message(ctx, code, ...) \ + krb5_set_error_message_fl(ctx, code, __FILE__, __LINE__, __VA_ARGS__) +#endif + #endif /* _KRB5_INT_H */ diff --git a/src/lib/krb5/krb/kerrs.c b/src/lib/krb5/krb/kerrs.c index 647076485..b7e4fc1c7 100644 --- a/src/lib/krb5/krb/kerrs.c +++ b/src/lib/krb5/krb/kerrs.c @@ -35,6 +35,7 @@ static int error_message_debug = 0; #endif #endif +#undef krb5_set_error_message void KRB5_CALLCONV_C krb5_set_error_message (krb5_context ctx, krb5_error_code code, const char *fmt, ...) @@ -57,6 +58,28 @@ krb5_set_error_message (krb5_context ctx, krb5_error_code code, va_end (args); } +void KRB5_CALLCONV_C +krb5_set_error_message_fl (krb5_context ctx, krb5_error_code code, + const char *file, int line, const char *fmt, ...) +{ + va_list args; + if (ctx == NULL) + return; + va_start (args, fmt); +#ifdef DEBUG + if (ERROR_MESSAGE_DEBUG()) + fprintf(stderr, + "krb5_set_error_message(ctx=%p/err=%p, code=%ld, ...)\n", + ctx, &ctx->err, (long) code); +#endif + krb5int_vset_error_fl (&ctx->err, code, file, line, fmt, args); +#ifdef DEBUG + if (ERROR_MESSAGE_DEBUG()) + fprintf(stderr, "->%s\n", ctx->err.msg); +#endif + va_end (args); +} + void KRB5_CALLCONV krb5_vset_error_message (krb5_context ctx, krb5_error_code code, const char *fmt, va_list args) diff --git a/src/lib/krb5/libkrb5.exports b/src/lib/krb5/libkrb5.exports index f30b57114..45e5002f0 100644 --- a/src/lib/krb5/libkrb5.exports +++ b/src/lib/krb5/libkrb5.exports @@ -487,6 +487,7 @@ krb5_set_default_realm krb5_set_default_tgs_enctypes krb5_set_default_tgs_ktypes krb5_set_error_message +krb5_set_error_message_fl krb5_set_password krb5_set_password_using_ccache krb5_set_principal_realm diff --git a/src/util/support/errors.c b/src/util/support/errors.c index d85ba4244..0e75cd1db 100644 --- a/src/util/support/errors.c +++ b/src/util/support/errors.c @@ -34,21 +34,40 @@ krb5int_err_init (void) #define lock() k5_mutex_lock(&krb5int_error_info_support_mutex) #define unlock() k5_mutex_unlock(&krb5int_error_info_support_mutex) +#undef krb5int_set_error void krb5int_set_error (struct errinfo *ep, long code, const char *fmt, ...) { va_list args; va_start (args, fmt); - krb5int_vset_error (ep, code, fmt, args); + krb5int_vset_error_fl (ep, code, NULL, 0, fmt, args); + va_end (args); +} + +void +krb5int_set_error_fl (struct errinfo *ep, long code, + const char *file, int line, const char *fmt, ...) +{ + va_list args; + va_start (args, fmt); + krb5int_vset_error_fl (ep, code, file, line, fmt, args); va_end (args); } void krb5int_vset_error (struct errinfo *ep, long code, const char *fmt, va_list args) +{ + krb5int_vset_error_fl(ep, code, NULL, 0, fmt, args); +} + +void +krb5int_vset_error_fl (struct errinfo *ep, long code, + const char *file, int line, + const char *fmt, va_list args) { va_list args2; - char *str = NULL; + char *str = NULL, *str2, *slash; const char *loc_fmt = NULL; #ifdef USE_KIM @@ -66,6 +85,17 @@ krb5int_vset_error (struct errinfo *ep, long code, str = NULL; } va_end(args2); + + if (str && line) { + /* Try to add file and line suffix. */ + slash = strrchr(file, '/'); + if (slash) + file = slash + 1; + if (asprintf(&str2, "%s (%s: %d)", str, file, line) > 0) { + free(str); + str = str2; + } + } /* If that failed, try using scratch_buf */ if (str == NULL) { diff --git a/src/util/support/libkrb5support-fixed.exports b/src/util/support/libkrb5support-fixed.exports index 4638bb659..3560ce63a 100644 --- a/src/util/support/libkrb5support-fixed.exports +++ b/src/util/support/libkrb5support-fixed.exports @@ -24,6 +24,8 @@ krb5int_mutex_lock krb5int_mutex_unlock krb5int_set_error krb5int_vset_error +krb5int_set_error_fl +krb5int_vset_error_fl krb5int_get_error krb5int_free_error krb5int_clear_error -- 2.26.2