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

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