From fda55b178c12bba1474ae2c63bc7b803cdc9730f Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Fri, 13 Nov 2009 16:33:52 +0000 Subject: [PATCH] Better errors from aklog Since the great com_err fracture, aklog has only returned decent error messages from AFS, leaving Kerberos errors untranslated. Needless to say, this causes user confusion and distress. This patch uses the error display proc hook to call out to the real com_err in situations where AFS can't supply an error message, giving clearer errors for Kerberos problems. Change-Id: I8832b755beb84c593e1b2eace5c356e71a582b2a Reviewed-on: http://gerrit.openafs.org/821 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/aklog/aklog_main.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/aklog/aklog_main.c b/src/aklog/aklog_main.c index 147db907d..6c7021760 100644 --- a/src/aklog/aklog_main.c +++ b/src/aklog/aklog_main.c @@ -64,6 +64,7 @@ #include #include +#include #ifndef HAVE_KERBEROSV_HEIM_ERR_H #include @@ -313,6 +314,33 @@ static linked_list zsublist; /* List of zephyr subscriptions */ static linked_list hostlist; /* List of host addresses */ static linked_list authedcells; /* List of cells already logged to */ +/* A com_error bodge. The idea here is that this routine lets us lookup + * things in the system com_err, if the AFS one just tells us the error + * is unknown + */ + +void +redirect_errors(const char *who, afs_int32 code, const char *fmt, va_list ap) +{ + if (who) { + fputs(who, stderr); + fputs(": ", stderr); + } + if (code) { + const char *str = afs_error_message(code); + if (strncmp(str, "unknown", strlen("unknown")) == 0) { + str = error_message(code); + } + fputs(str, stderr); + fputs(" ", stderr); + } + if (fmt) { + vfprintf(stderr, fmt, ap); + } + putc('\n', stderr); + fflush(stderr); +} + /* ANL - CMU lifetime convert routine */ /* for K5.4.1 don't use this for now. Need to see if it is needed */ /* maybe needed in the krb524d module as well */ @@ -1215,7 +1243,7 @@ static void usage(void) void aklog(int argc, char *argv[]) { - krb5_context context; + krb5_context context; int status = AKLOG_SUCCESS; int i; int somethingswrong = FALSE; @@ -1257,6 +1285,7 @@ void aklog(int argc, char *argv[]) krb5_init_context(&context); initialize_ktc_error_table (); + afs_set_com_err_hook(redirect_errors); /* Initialize list of cells to which we have authenticated */ (void)ll_init(&authedcells); -- 2.39.5