[15910] in Kerberos_V5_Development
Re: krb5_get_error_message() and krb5_free_error_message() functions
daemon@ATHENA.MIT.EDU (Russ Allbery)
Mon Jun 21 03:28:25 2010
From: Russ Allbery <rra@stanford.edu>
To: "krbdev\@mit.edu" <krbdev@mit.edu>
In-Reply-To: <736081.62182.qm@web50108.mail.re2.yahoo.com> (vir vir's message
of "Sun, 20 Jun 2010 14:12:54 -0700 (PDT)")
Date: Mon, 21 Jun 2010 00:28:20 -0700
Message-ID: <8739wg3kvf.fsf@windlord.stanford.edu>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Errors-To: krbdev-bounces@mit.edu
Content-Transfer-Encoding: 8bit
vir vir <vitrou2004@yahoo.com> writes:
> Thank you for your response.> I am using krb5 earlier then 1.4 that provided by the Linux OS.> Can you please recommend what are the best functions to use instead?
If you want maximum portability, you have to do something like this (seehttp://www.eyrie.org/~eagle/software/rra-c-util/ for the complete contextand corresponding M4 macros). However, for more situations, falling backon com_err if the new functions aren't available will work. (You losewith native AIX Kerberos, but you may or may not care.)
/* Figure out what header files to include for error reporting. */#if !defined(HAVE_KRB5_GET_ERROR_MESSAGE) && !defined(HAVE_KRB5_GET_ERR_TEXT)# if !defined(HAVE_KRB5_GET_ERROR_STRING)# if defined(HAVE_IBM_SVC_KRB5_SVC_H)# include <ibm_svc/krb5_svc.h># elif defined(HAVE_ET_COM_ERR_H)# include <et/com_err.h># else# include <com_err.h># endif# endif#endif
/* Used for unused parameters to silence gcc warnings. */#define UNUSED __attribute__((__unused__))
/* * This string is returned for unknown error messages. We use a static * variable so that we can be sure not to free it. */static const char error_unknown[] = "unknown error";
#ifndef HAVE_KRB5_GET_ERROR_MESSAGE/* * Given a Kerberos error code, return the corresponding error. Prefer the * Kerberos interface if available since it will provide context-specific * error information, whereas the error_message() call will only provide a * fixed message. */const char *krb5_get_error_message(krb5_context ctx UNUSED, krb5_error_code code UNUSED){ const char *msg = NULL;
# if defined(HAVE_KRB5_GET_ERROR_STRING) msg = krb5_get_error_string(ctx);# elif defined(HAVE_KRB5_GET_ERR_TEXT) msg = krb5_get_err_text(ctx, code);# elif defined(HAVE_KRB5_SVC_GET_MSG) krb5_svc_get_msg(code, (char **) &msg);# else msg = error_message(code);# endif if (msg == NULL) return error_unknown; else return msg;}#endif /* !HAVE_KRB5_GET_ERROR_MESSAGE */
#ifndef HAVE_KRB5_FREE_ERROR_MESSAGE/* * Free an error string if necessary. If we returned a static string, make * sure we don't free it. * * This code assumes that the set of implementations that have * krb5_free_error_message is a subset of those with krb5_get_error_message. * If this assumption ever breaks, we may call the wrong free function. */voidkrb5_free_error_message(krb5_context ctx UNUSED, const char *msg){ if (msg == error_unknown) return;# if defined(HAVE_KRB5_GET_ERROR_STRING) krb5_free_error_string(ctx, (char *) msg);# elif defined(HAVE_KRB5_SVC_GET_MSG) krb5_free_string(ctx, (char *) msg);# endif}#endif /* !HAVE_KRB5_FREE_ERROR_MESSAGE */
-- Russ Allbery (rra@stanford.edu) <http://www.eyrie.org/~eagle/>
_______________________________________________krbdev mailing list krbdev@mit.eduhttps://mailman.mit.edu/mailman/listinfo/krbdev