summaryrefslogtreecommitdiff
path: root/library/adkrb5.c
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2024-11-05 19:00:54 +0100
committerSumit Bose <sbose@redhat.com>2024-11-20 16:53:47 +0100
commitd3db46e8b03f0f2db0df01466b597fde588a06bf (patch)
treea5a03dc4c597c393bd0c7f992ea0e6b18d001059 /library/adkrb5.c
parentfab13daeaf23cc4a26b10cfe0c3d7ac469a9da76 (diff)
krb5: add adcli_krb5_get_error_message()HEADmaster
The krb5_get_error_message() call returns an error message in an allocated string which must be freed. This makes it hard to simply use krb5_get_error_message() in a printf() argument list. adcli_krb5_get_error_message() used a static memory area to make the usage more easy.
Diffstat (limited to 'library/adkrb5.c')
-rw-r--r--library/adkrb5.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/library/adkrb5.c b/library/adkrb5.c
index be3ede5..7a9ee8f 100644
--- a/library/adkrb5.c
+++ b/library/adkrb5.c
@@ -33,6 +33,7 @@
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
+#include <sys/param.h>
krb5_error_code
_adcli_krb5_build_principal (krb5_context k5,
@@ -174,7 +175,7 @@ _adcli_krb5_init_context (krb5_context *k5)
} else if (code != 0) {
_adcli_err ("Failed to create kerberos context: %s",
- krb5_get_error_message (NULL, code));
+ adcli_krb5_get_error_message (NULL, code));
return ADCLI_ERR_UNEXPECTED;
}
@@ -192,7 +193,7 @@ _adcli_krb5_open_keytab (krb5_context k5,
code = krb5_kt_resolve (k5, keytab_name, keytab);
if (code != 0) {
_adcli_err ("Failed to open keytab: %s: %s",
- keytab_name, krb5_get_error_message (k5, code));
+ keytab_name, adcli_krb5_get_error_message (k5, code));
return ADCLI_ERR_FAIL;
}
@@ -200,7 +201,7 @@ _adcli_krb5_open_keytab (krb5_context k5,
code = krb5_kt_default (k5, keytab);
if (code != 0) {
_adcli_err ("Failed to open default keytab: %s",
- krb5_get_error_message (k5, code));
+ adcli_krb5_get_error_message (k5, code));
return ADCLI_ERR_FAIL;
}
}
@@ -570,3 +571,18 @@ _adcli_krb5_format_enctypes (krb5_enctype *enctypes)
return value;
}
+
+const char *adcli_krb5_get_error_message (krb5_context ctx, krb5_error_code code)
+{
+ static char out[4096];
+ const char *tmp;
+ size_t len;
+
+ tmp = krb5_get_error_message (ctx, code);
+ len = strlen (tmp);
+ memcpy (out, tmp, MIN (sizeof (out), len));
+ out[sizeof(out) - 1] = '\0';
+ krb5_free_error_message (ctx, tmp);
+
+ return out;
+}