Check the return value of krb5_init_context(), and bail out if it failed.

Also, when failing, don't try to use the non-initialized context value
to determine the error text.

This avoids dumping core in the following programs when /etc/krb5.conf is
missing or broken: klist, kdestroy, kpasswd, kadmin, kadmind, ktutil, kdc.

XXX Better error reporting in this failure case would be nice.
This commit is contained in:
nathanw 2000-12-19 21:31:11 +00:00
parent 95ecff2f0d
commit 1cc86f8ba4
7 changed files with 22 additions and 14 deletions

View File

@ -33,7 +33,7 @@
#include "ktutil_locl.h"
RCSID("$Id: ktutil.c,v 1.1.1.2 2000/08/02 19:58:04 assar Exp $");
RCSID("$Id: ktutil.c,v 1.2 2000/12/19 21:31:11 nathanw Exp $");
static int help_flag;
static int version_flag;
@ -129,7 +129,9 @@ main(int argc, char **argv)
int optind = 0;
krb5_error_code ret;
set_progname(argv[0]);
krb5_init_context(&context);
ret = krb5_init_context(&context);
if (ret)
errx(1, "krb5_init_context failed: %u", ret);
if(getarg(args, num_args, argc, argv, &optind))
usage(1);
if(help_flag)

View File

@ -34,7 +34,7 @@
#include "kadmin_locl.h"
#include <sl.h>
RCSID("$Id: kadmin.c,v 1.1.1.2 2000/08/02 19:58:51 assar Exp $");
RCSID("$Id: kadmin.c,v 1.2 2000/12/19 21:31:11 nathanw Exp $");
static char *config_file;
static char *keyfile;
@ -205,7 +205,9 @@ main(int argc, char **argv)
set_progname(argv[0]);
krb5_init_context(&context);
ret = krb5_init_context(&context);
if (ret)
errx(1, "krb5_init_context failed: %u", ret);
while((e = getarg(args, num_args, argc, argv, &optind)))
errx(1, "error at argument `%s'", argv[optind]);

View File

@ -33,7 +33,7 @@
#include "kadmin_locl.h"
RCSID("$Id: kadmind.c,v 1.2 2000/08/06 06:48:50 thorpej Exp $");
RCSID("$Id: kadmind.c,v 1.3 2000/12/19 21:31:11 nathanw Exp $");
static char *config_file;
static char *keyfile;
@ -95,7 +95,9 @@ main(int argc, char **argv)
set_progname(argv[0]);
krb5_init_context(&context);
ret = krb5_init_context(&context);
if (ret)
errx(1, "krb5_init_context failed: %u", ret);
ret = krb5_openlog(context, "kadmind", &logf);
ret = krb5_set_warn_dest(context, logf);

View File

@ -35,7 +35,7 @@
#include <util.h>
RCSID("$Id: main.c,v 1.2 2000/08/06 18:42:19 thorpej Exp $");
RCSID("$Id: main.c,v 1.3 2000/12/19 21:31:11 nathanw Exp $");
sig_atomic_t exit_flag = 0;
krb5_context context;
@ -52,7 +52,9 @@ main(int argc, char **argv)
krb5_error_code ret;
set_progname(argv[0]);
krb5_init_context(&context);
ret = krb5_init_context(&context);
if (ret)
errx(1, "krb5_init_context failed: %u", ret);
configure(argc, argv);

View File

@ -32,7 +32,7 @@
*/
#include "kpasswd_locl.h"
RCSID("$Id: kpasswd.c,v 1.1.1.2 2000/08/02 19:58:57 assar Exp $");
RCSID("$Id: kpasswd.c,v 1.2 2000/12/19 21:31:11 nathanw Exp $");
static int version_flag;
static int help_flag;
@ -87,7 +87,7 @@ main (int argc, char **argv)
ret = krb5_init_context (&context);
if (ret)
errx (1, "krb5_init_context: %s", krb5_get_err_text(context, ret));
errx(1, "krb5_init_context failed: %u", ret);
if(argv[0]) {
ret = krb5_parse_name (context, argv[0], &principal);

View File

@ -32,7 +32,7 @@
*/
#include "kuser_locl.h"
RCSID("$Id: kdestroy.c,v 1.1.1.2 2000/08/02 19:58:58 assar Exp $");
RCSID("$Id: kdestroy.c,v 1.2 2000/12/19 21:31:11 nathanw Exp $");
static const char *cache;
static int help_flag;
@ -89,7 +89,7 @@ main (int argc, char **argv)
ret = krb5_init_context (&context);
if (ret)
errx (1, "krb5_init_context: %s", krb5_get_err_text(context, ret));
errx(1, "krb5_init_context failed: %u", ret);
if(cache == NULL)
cache = krb5_cc_default_name(context);

View File

@ -34,7 +34,7 @@
#include "kuser_locl.h"
#include "rtbl.h"
RCSID("$Id: klist.c,v 1.1.1.2 2000/08/02 19:58:59 assar Exp $");
RCSID("$Id: klist.c,v 1.2 2000/12/19 21:31:12 nathanw Exp $");
static char*
printable_time(time_t t)
@ -526,7 +526,7 @@ display_v5_ccache (const char *cred_cache, int do_test, int do_verbose,
ret = krb5_init_context (&context);
if (ret)
krb5_err(context, 1, ret, "krb5_init_context");
errx(1, "krb5_init_context failed: %u", ret);
if(cred_cache) {
ret = krb5_cc_resolve(context, cred_cache, &ccache);