From 072d69ac27587b6d384aae52de27b6e9b83fdea3 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Thu, 19 Nov 2009 11:35:12 -0500 Subject: [PATCH] Windows: provide enhanced error output to aklog Add Simon Wilkinson's change from Unix aklog to Windows aklog If afs_com_err fails to describe the error, allow the krb5 error_message function try. LICENSE MIT Change-Id: I47bb6806f1076116a68967617d32d69b98a5bba9 Reviewed-on: http://gerrit.openafs.org/852 Reviewed-by: Derrick Brashear Reviewed-by: Rod Widdowson Tested-by: Jeffrey Altman Reviewed-by: Jeffrey Altman --- src/WINNT/aklog/aklog.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/WINNT/aklog/aklog.c b/src/WINNT/aklog/aklog.c index 3242af135..36810ab57 100644 --- a/src/WINNT/aklog/aklog.c +++ b/src/WINNT/aklog/aklog.c @@ -204,6 +204,33 @@ void akexit(int exit_code) exit(exit_code); } +/* 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(str)) == 0) { + str = error_message(code); + } + fputs(str, stderr); + fputs(" ", stderr); + } + if (fmt) { + vfprintf(stderr, fmt, ap); + } + putc('\n', stderr); + fflush(stderr); +} + long GetLocalCell(struct afsconf_dir **pconfigdir, char *local_cell) { if (!(*pconfigdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH))) @@ -304,8 +331,9 @@ void ViceIDToUsername(char *username, char *realm_of_user, char *realm_of_cell, } if ((*status = ktc_SetToken(aserver, atoken, aclient, 0))) { - printf("%s: unable to set tokens for cell %s " - "(status: %d).\n", progname, cell_to_use, *status); + afs_com_err(progname, *status, + "while obtaining tokens for cell %s\n", + cell_to_use); *status = AKLOG_TOKEN; return ; } @@ -990,9 +1018,9 @@ static int auth_to_cell(krb5_context context, char *cell, char *realm) printf("Getting tokens.\n"); if (status = ktc_SetToken(&aserver, &atoken, &aclient, 0)) { - fprintf(stderr, - "%s: unable to obtain tokens for cell %s (status: %d).\n", - progname, cell_to_use, status); + afs_com_err(progname, status, + "while obtaining tokens for cell %s\n", + cell_to_use); status = AKLOG_TOKEN; } @@ -1494,7 +1522,7 @@ int main(int argc, char *argv[]) return(AKLOG_KERBEROS); } else validate_krb4_availability(); - + afs_set_com_err_hook(redirect_errors); /* If nothing was given, log to the local cell. */ if ((cells.nelements + paths.nelements) == 0) -- 2.39.5