Blame 0005-tools-remove-errx-from-setup_krb5_conf_directory.patch

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