Blame SOURCES/0001-tools-remove-errx-from-computer-commands.patch

ee8dc1
From fa7926c7a9d92bc7c42c610ba6f1706c635aa901 Mon Sep 17 00:00:00 2001
ee8dc1
From: Sumit Bose <sbose@redhat.com>
ee8dc1
Date: Mon, 15 Apr 2019 17:54:27 +0200
ee8dc1
Subject: [PATCH 1/7] tools: remove errx from computer commands
ee8dc1
ee8dc1
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1588596
ee8dc1
---
ee8dc1
 tools/computer.c | 166 ++++++++++++++++++++++++++++++-----------------
ee8dc1
 1 file changed, 107 insertions(+), 59 deletions(-)
ee8dc1
ee8dc1
diff --git a/tools/computer.c b/tools/computer.c
ee8dc1
index bee695c..9cbbb28 100644
ee8dc1
--- a/tools/computer.c
ee8dc1
+++ b/tools/computer.c
ee8dc1
@@ -379,8 +379,10 @@ adcli_tool_computer_join (adcli_conn *conn,
ee8dc1
 	};
ee8dc1
 
ee8dc1
 	enroll = adcli_enroll_new (conn);
ee8dc1
-	if (enroll == NULL)
ee8dc1
-		errx (-1, "unexpected memory problems");
ee8dc1
+	if (enroll == NULL) {
ee8dc1
+		warnx ("unexpected memory problems");
ee8dc1
+		return -1;
ee8dc1
+	}
ee8dc1
 
ee8dc1
 	while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
ee8dc1
 		switch (opt) {
ee8dc1
@@ -415,21 +417,28 @@ adcli_tool_computer_join (adcli_conn *conn,
ee8dc1
 
ee8dc1
 	if (argc == 1)
ee8dc1
 		adcli_conn_set_domain_name (conn, argv[0]);
ee8dc1
-	else if (argc > 1)
ee8dc1
-		errx (2, "extra arguments specified");
ee8dc1
+	else if (argc > 1) {
ee8dc1
+		warnx ("extra arguments specified");
ee8dc1
+		adcli_enroll_unref (enroll);
ee8dc1
+		return 2;
ee8dc1
+	}
ee8dc1
 
ee8dc1
 	res = adcli_conn_connect (conn);
ee8dc1
 	if (res != ADCLI_SUCCESS) {
ee8dc1
-		errx (-res, "couldn't connect to %s domain: %s",
ee8dc1
-		      adcli_conn_get_domain_name (conn),
ee8dc1
-		      adcli_get_last_error ());
ee8dc1
+		warnx ("couldn't connect to %s domain: %s",
ee8dc1
+		       adcli_conn_get_domain_name (conn),
ee8dc1
+		       adcli_get_last_error ());
ee8dc1
+		adcli_enroll_unref (enroll);
ee8dc1
+		return -res;
ee8dc1
 	}
ee8dc1
 
ee8dc1
 	res = adcli_enroll_join (enroll, flags);
ee8dc1
 	if (res != ADCLI_SUCCESS) {
ee8dc1
-		errx (-res, "joining domain %s failed: %s",
ee8dc1
-		      adcli_conn_get_domain_name (conn),
ee8dc1
-		      adcli_get_last_error ());
ee8dc1
+		warnx ("joining domain %s failed: %s",
ee8dc1
+		       adcli_conn_get_domain_name (conn),
ee8dc1
+		       adcli_get_last_error ());
ee8dc1
+		adcli_enroll_unref (enroll);
ee8dc1
+		return -res;
ee8dc1
 	}
ee8dc1
 
ee8dc1
 	if (details)
ee8dc1
@@ -486,8 +495,10 @@ adcli_tool_computer_update (adcli_conn *conn,
ee8dc1
 	};
ee8dc1
 
ee8dc1
 	enroll = adcli_enroll_new (conn);
ee8dc1
-	if (enroll == NULL)
ee8dc1
-		errx (-1, "unexpected memory problems");
ee8dc1
+	if (enroll == NULL) {
ee8dc1
+		warnx ("unexpected memory problems");
ee8dc1
+		return -1;
ee8dc1
+	}
ee8dc1
 
ee8dc1
 	while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
ee8dc1
 		switch (opt) {
ee8dc1
@@ -525,22 +536,28 @@ adcli_tool_computer_update (adcli_conn *conn,
ee8dc1
 
ee8dc1
 	res = adcli_enroll_load (enroll);
ee8dc1
 	if (res != ADCLI_SUCCESS) {
ee8dc1
-		errx (-res, "couldn't lookup domain info from keytab: %s",
ee8dc1
-		      adcli_get_last_error ());
ee8dc1
+		warnx ("couldn't lookup domain info from keytab: %s",
ee8dc1
+		       adcli_get_last_error ());
ee8dc1
+		adcli_enroll_unref (enroll);
ee8dc1
+		return -res;
ee8dc1
 	}
ee8dc1
 
ee8dc1
 	res = adcli_conn_connect (conn);
ee8dc1
 	if (res != ADCLI_SUCCESS) {
ee8dc1
-		errx (-res, "couldn't connect to %s domain: %s",
ee8dc1
-		      adcli_conn_get_domain_name (conn),
ee8dc1
-		      adcli_get_last_error ());
ee8dc1
+		warnx ("couldn't connect to %s domain: %s",
ee8dc1
+		       adcli_conn_get_domain_name (conn),
ee8dc1
+		       adcli_get_last_error ());
ee8dc1
+		adcli_enroll_unref (enroll);
ee8dc1
+		return -res;
ee8dc1
 	}
ee8dc1
 
ee8dc1
 	res = adcli_enroll_update (enroll, flags);
ee8dc1
 	if (res != ADCLI_SUCCESS) {
ee8dc1
-		errx (-res, "updating membership with domain %s failed: %s",
ee8dc1
-		      adcli_conn_get_domain_name (conn),
ee8dc1
-		      adcli_get_last_error ());
ee8dc1
+		warnx ("updating membership with domain %s failed: %s",
ee8dc1
+		       adcli_conn_get_domain_name (conn),
ee8dc1
+		       adcli_get_last_error ());
ee8dc1
+		adcli_enroll_unref (enroll);
ee8dc1
+		return -res;
ee8dc1
 	}
ee8dc1
 
ee8dc1
 	if (details)
ee8dc1
@@ -578,8 +595,10 @@ adcli_tool_computer_testjoin (adcli_conn *conn,
ee8dc1
 	};
ee8dc1
 
ee8dc1
 	enroll = adcli_enroll_new (conn);
ee8dc1
-	if (enroll == NULL)
ee8dc1
-		errx (-1, "unexpected memory problems");
ee8dc1
+	if (enroll == NULL) {
ee8dc1
+		warnx ("unexpected memory problems");
ee8dc1
+		return -1;
ee8dc1
+	}
ee8dc1
 
ee8dc1
 	while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
ee8dc1
 		switch (opt) {
ee8dc1
@@ -604,18 +623,18 @@ adcli_tool_computer_testjoin (adcli_conn *conn,
ee8dc1
 	res = adcli_enroll_load (enroll);
ee8dc1
 	if (res != ADCLI_SUCCESS) {
ee8dc1
 		adcli_enroll_unref (enroll);
ee8dc1
-		adcli_conn_unref (conn);
ee8dc1
-		errx (-res, "couldn't lookup domain info from keytab: %s",
ee8dc1
-		      adcli_get_last_error ());
ee8dc1
+		warnx ("couldn't lookup domain info from keytab: %s",
ee8dc1
+		       adcli_get_last_error ());
ee8dc1
+		return -res;
ee8dc1
 	}
ee8dc1
 
ee8dc1
 	res = adcli_conn_connect (conn);
ee8dc1
 	if (res != ADCLI_SUCCESS) {
ee8dc1
 		adcli_enroll_unref (enroll);
ee8dc1
-		adcli_conn_unref (conn);
ee8dc1
-		errx (-res, "couldn't connect to %s domain: %s",
ee8dc1
+		warnx ("couldn't connect to %s domain: %s",
ee8dc1
 		      adcli_conn_get_domain_name (conn),
ee8dc1
 		      adcli_get_last_error ());
ee8dc1
+		return -res;
ee8dc1
 	}
ee8dc1
 
ee8dc1
 	printf ("Sucessfully validated join to domain %s\n",
ee8dc1
@@ -665,8 +684,10 @@ adcli_tool_computer_preset (adcli_conn *conn,
ee8dc1
 	};
ee8dc1
 
ee8dc1
 	enroll = adcli_enroll_new (conn);
ee8dc1
-	if (enroll == NULL)
ee8dc1
-		errx (-1, "unexpected memory problems");
ee8dc1
+	if (enroll == NULL) {
ee8dc1
+		warnx ("unexpected memory problems");
ee8dc1
+		return -1;
ee8dc1
+	}
ee8dc1
 	flags = ADCLI_ENROLL_NO_KEYTAB;
ee8dc1
 
ee8dc1
 	while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
ee8dc1
@@ -694,17 +715,22 @@ adcli_tool_computer_preset (adcli_conn *conn,
ee8dc1
 	argc -= optind;
ee8dc1
 	argv += optind;
ee8dc1
 
ee8dc1
-	if (argc < 1)
ee8dc1
-		errx (EUSAGE, "specify one or more host names of computer accounts to preset");
ee8dc1
+	if (argc < 1) {
ee8dc1
+		warnx ("specify one or more host names of computer accounts to preset");
ee8dc1
+		adcli_enroll_unref (enroll);
ee8dc1
+		return EUSAGE;
ee8dc1
+	}
ee8dc1
 
ee8dc1
 	adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
ee8dc1
 	reset_password = (adcli_enroll_get_computer_password (enroll) == NULL);
ee8dc1
 
ee8dc1
 	res = adcli_conn_connect (conn);
ee8dc1
 	if (res != ADCLI_SUCCESS) {
ee8dc1
-		errx (-res, "couldn't connect to %s domain: %s",
ee8dc1
-		      adcli_conn_get_domain_name (conn),
ee8dc1
-		      adcli_get_last_error ());
ee8dc1
+		warnx ("couldn't connect to %s domain: %s",
ee8dc1
+		       adcli_conn_get_domain_name (conn),
ee8dc1
+		       adcli_get_last_error ());
ee8dc1
+		adcli_enroll_unref (enroll);
ee8dc1
+		return -res;
ee8dc1
 	}
ee8dc1
 
ee8dc1
 	for (i = 0; i < argc; i++) {
ee8dc1
@@ -715,9 +741,11 @@ adcli_tool_computer_preset (adcli_conn *conn,
ee8dc1
 
ee8dc1
 		res = adcli_enroll_join (enroll, flags);
ee8dc1
 		if (res != ADCLI_SUCCESS) {
ee8dc1
-			errx (-res, "presetting %s in %s domain failed: %s", argv[i],
ee8dc1
-			      adcli_conn_get_domain_name (conn),
ee8dc1
-			      adcli_get_last_error ());
ee8dc1
+			warnx ("presetting %s in %s domain failed: %s", argv[i],
ee8dc1
+			       adcli_conn_get_domain_name (conn),
ee8dc1
+			       adcli_get_last_error ());
ee8dc1
+			adcli_enroll_unref (enroll);
ee8dc1
+			return -res;
ee8dc1
 		}
ee8dc1
 
ee8dc1
 		printf ("computer-name: %s\n", adcli_enroll_get_computer_name (enroll));
ee8dc1
@@ -758,8 +786,10 @@ adcli_tool_computer_reset (adcli_conn *conn,
ee8dc1
 	};
ee8dc1
 
ee8dc1
 	enroll = adcli_enroll_new (conn);
ee8dc1
-	if (enroll == NULL)
ee8dc1
-		errx (-1, "unexpected memory problems");
ee8dc1
+	if (enroll == NULL) {
ee8dc1
+		warnx ("unexpected memory problems");
ee8dc1
+		return -1;
ee8dc1
+	}
ee8dc1
 
ee8dc1
 	while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
ee8dc1
 		switch (opt) {
ee8dc1
@@ -779,14 +809,19 @@ adcli_tool_computer_reset (adcli_conn *conn,
ee8dc1
 	argc -= optind;
ee8dc1
 	argv += optind;
ee8dc1
 
ee8dc1
-	if (argc != 1)
ee8dc1
-		errx (EUSAGE, "specify one host name of computer account to reset");
ee8dc1
+	if (argc != 1) {
ee8dc1
+		warnx ("specify one host name of computer account to reset");
ee8dc1
+		adcli_enroll_unref (enroll);
ee8dc1
+		return EUSAGE;
ee8dc1
+	}
ee8dc1
 
ee8dc1
 	res = adcli_conn_connect (conn);
ee8dc1
 	if (res != ADCLI_SUCCESS) {
ee8dc1
-		errx (-res, "couldn't connect to %s domain: %s",
ee8dc1
-		      adcli_conn_get_domain_name (conn),
ee8dc1
-		      adcli_get_last_error ());
ee8dc1
+		warnx ("couldn't connect to %s domain: %s",
ee8dc1
+		       adcli_conn_get_domain_name (conn),
ee8dc1
+		       adcli_get_last_error ());
ee8dc1
+		adcli_enroll_unref (enroll);
ee8dc1
+		return -res;
ee8dc1
 	}
ee8dc1
 
ee8dc1
 	parse_fqdn_or_name (enroll, argv[0]);
ee8dc1
@@ -794,9 +829,11 @@ adcli_tool_computer_reset (adcli_conn *conn,
ee8dc1
 
ee8dc1
 	res = adcli_enroll_password (enroll, 0);
ee8dc1
 	if (res != ADCLI_SUCCESS) {
ee8dc1
-		errx (-res, "resetting %s in %s domain failed: %s", argv[0],
ee8dc1
-		      adcli_conn_get_domain_name (conn),
ee8dc1
-		      adcli_get_last_error ());
ee8dc1
+		warnx ("resetting %s in %s domain failed: %s", argv[0],
ee8dc1
+		       adcli_conn_get_domain_name (conn),
ee8dc1
+		       adcli_get_last_error ());
ee8dc1
+		adcli_enroll_unref (enroll);
ee8dc1
+		return -res;
ee8dc1
 	}
ee8dc1
 
ee8dc1
 	adcli_enroll_unref (enroll);
ee8dc1
@@ -832,8 +869,10 @@ adcli_tool_computer_delete (adcli_conn *conn,
ee8dc1
 	};
ee8dc1
 
ee8dc1
 	enroll = adcli_enroll_new (conn);
ee8dc1
-	if (enroll == NULL)
ee8dc1
-		errx (-1, "unexpected memory problems");
ee8dc1
+	if (enroll == NULL) {
ee8dc1
+		warnx ("unexpected memory problems");
ee8dc1
+		return -1;
ee8dc1
+	}
ee8dc1
 
ee8dc1
 	while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
ee8dc1
 		switch (opt) {
ee8dc1
@@ -853,22 +892,29 @@ adcli_tool_computer_delete (adcli_conn *conn,
ee8dc1
 	argc -= optind;
ee8dc1
 	argv += optind;
ee8dc1
 
ee8dc1
-	if (argc > 1)
ee8dc1
-		errx (EUSAGE, "specify one host name of computer account to delete");
ee8dc1
+	if (argc > 1) {
ee8dc1
+		warnx ("specify one host name of computer account to delete");
ee8dc1
+		adcli_enroll_unref (enroll);
ee8dc1
+		return EUSAGE;
ee8dc1
+	}
ee8dc1
 
ee8dc1
 	adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
ee8dc1
 
ee8dc1
 	res = adcli_enroll_load (enroll);
ee8dc1
 	if (res != ADCLI_SUCCESS) {
ee8dc1
-		errx (-res, "couldn't lookup domain info from keytab: %s",
ee8dc1
-		      adcli_get_last_error ());
ee8dc1
+		warnx ("couldn't lookup domain info from keytab: %s",
ee8dc1
+		       adcli_get_last_error ());
ee8dc1
+		adcli_enroll_unref (enroll);
ee8dc1
+		return -res;
ee8dc1
 	}
ee8dc1
 
ee8dc1
 	res = adcli_conn_connect (conn);
ee8dc1
 	if (res != ADCLI_SUCCESS) {
ee8dc1
-		errx (-res, "couldn't connect to %s domain: %s",
ee8dc1
-		      adcli_conn_get_domain_name (conn),
ee8dc1
-		      adcli_get_last_error ());
ee8dc1
+		warnx ("couldn't connect to %s domain: %s",
ee8dc1
+		       adcli_conn_get_domain_name (conn),
ee8dc1
+		       adcli_get_last_error ());
ee8dc1
+		adcli_enroll_unref (enroll);
ee8dc1
+		return -res;
ee8dc1
 	}
ee8dc1
 
ee8dc1
 	if (argc == 1)
ee8dc1
@@ -876,9 +922,11 @@ adcli_tool_computer_delete (adcli_conn *conn,
ee8dc1
 
ee8dc1
 	res = adcli_enroll_delete (enroll, 0);
ee8dc1
 	if (res != ADCLI_SUCCESS) {
ee8dc1
-		errx (-res, "deleting %s in %s domain failed: %s", argv[0],
ee8dc1
-		      adcli_conn_get_domain_name (conn),
ee8dc1
-		      adcli_get_last_error ());
ee8dc1
+		warnx ("deleting %s in %s domain failed: %s", argv[0],
ee8dc1
+		       adcli_conn_get_domain_name (conn),
ee8dc1
+		       adcli_get_last_error ());
ee8dc1
+		adcli_enroll_unref (enroll);
ee8dc1
+		return -res;
ee8dc1
 	}
ee8dc1
 
ee8dc1
 	adcli_enroll_unref (enroll);
ee8dc1
-- 
ee8dc1
2.20.1
ee8dc1