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

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