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

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