From b8f5d995d30c17eb8bec3ac5e0777ea94f5b76c3 Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Mon, 15 Apr 2019 18:00:52 +0200 Subject: [PATCH 5/7] tools: remove errx from setup_krb5_conf_directory Related to https://bugzilla.redhat.com/show_bug.cgi?id=1588596 --- tools/tools.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/tools/tools.c b/tools/tools.c index bdf6d38..fc9fa9a 100644 --- a/tools/tools.c +++ b/tools/tools.c @@ -327,21 +327,31 @@ setup_krb5_conf_directory (adcli_conn *conn) } if (asprintf (&directory, "%s%sadcli-krb5-XXXXXX", parent, - (parent[0] && parent[strlen(parent) - 1] == '/') ? "" : "/") < 0) - errx (1, "unexpected: out of memory"); - - if (mkdtemp (directory) == NULL) { - errn = errno; + (parent[0] && parent[strlen(parent) - 1] == '/') ? "" : "/") < 0) { + warnx ("unexpected: out of memory"); + directory = NULL; /* content is undefined */ failed = 1; - warnx ("couldn't create temporary directory in: %s: %s", - parent, strerror (errn)); - } else { - if (asprintf (&filename, "%s/krb5.conf", directory) < 0 || - asprintf (&snippets, "%s/krb5.d", directory) < 0 || - asprintf (&contents, "includedir %s\n%s%s\n", snippets, - krb5_conf ? "include " : "", - krb5_conf ? krb5_conf : "") < 0) - errx (1, "unexpected: out of memory"); + } + + if (!failed) { + if (mkdtemp (directory) == NULL) { + errn = errno; + failed = 1; + warnx ("couldn't create temporary directory in: %s: %s", + parent, strerror (errn)); + } else { + if (asprintf (&filename, "%s/krb5.conf", directory) < 0 || + asprintf (&snippets, "%s/krb5.d", directory) < 0 || + asprintf (&contents, "includedir %s\n%s%s\n", snippets, + krb5_conf ? "include " : "", + krb5_conf ? krb5_conf : "") < 0) { + warnx ("unexpected: out of memory"); + filename = NULL; /* content is undefined */ + snippets = NULL; /* content is undefined */ + contents = NULL; /* content is undefined */ + failed = 1; + } + } } if (!failed) { -- 2.20.1