File 0038-Remove-errx-from-tools.patch of Package adcli.35968

From 37ee307eae2bfb1ce09bffa287e54ec8c349a1e7 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Mon, 15 Apr 2019 17:54:27 +0200
Subject: [PATCH 1/7] tools: remove errx from computer commands

Related to https://bugzilla.redhat.com/show_bug.cgi?id=1588596

(cherry picked from commit fa7926c7a9d92bc7c42c610ba6f1706c635aa901)
---
 tools/computer.c | 166 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 107 insertions(+), 59 deletions(-)

diff --git a/tools/computer.c b/tools/computer.c
index 8221fc8..71ebb6f 100644
--- a/tools/computer.c
+++ b/tools/computer.c
@@ -396,8 +396,10 @@ adcli_tool_computer_join (adcli_conn *conn,
 	};
 
 	enroll = adcli_enroll_new (conn);
-	if (enroll == NULL)
-		errx (-1, "unexpected memory problems");
+	if (enroll == NULL) {
+		warnx ("unexpected memory problems");
+		return -1;
+	}
 
 	while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
 		switch (opt) {
@@ -432,21 +434,28 @@ adcli_tool_computer_join (adcli_conn *conn,
 
 	if (argc == 1)
 		adcli_conn_set_domain_name (conn, argv[0]);
-	else if (argc > 1)
-		errx (2, "extra arguments specified");
+	else if (argc > 1) {
+		warnx ("extra arguments specified");
+		adcli_enroll_unref (enroll);
+		return 2;
+	}
 
 	res = adcli_conn_connect (conn);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "couldn't connect to %s domain: %s",
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("couldn't connect to %s domain: %s",
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_enroll_unref (enroll);
+		return -res;
 	}
 
 	res = adcli_enroll_join (enroll, flags);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "joining domain %s failed: %s",
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("joining domain %s failed: %s",
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_enroll_unref (enroll);
+		return -res;
 	}
 
 	if (details)
@@ -504,8 +513,10 @@ adcli_tool_computer_update (adcli_conn *conn,
 	};
 
 	enroll = adcli_enroll_new (conn);
-	if (enroll == NULL)
-		errx (-1, "unexpected memory problems");
+	if (enroll == NULL) {
+		warnx ("unexpected memory problems");
+		return -1;
+	}
 
 	while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
 		switch (opt) {
@@ -543,22 +554,28 @@ adcli_tool_computer_update (adcli_conn *conn,
 
 	res = adcli_enroll_load (enroll);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "couldn't lookup domain info from keytab: %s",
-		      adcli_get_last_error ());
+		warnx ("couldn't lookup domain info from keytab: %s",
+		       adcli_get_last_error ());
+		adcli_enroll_unref (enroll);
+		return -res;
 	}
 
 	res = adcli_conn_connect (conn);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "couldn't connect to %s domain: %s",
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("couldn't connect to %s domain: %s",
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_enroll_unref (enroll);
+		return -res;
 	}
 
 	res = adcli_enroll_update (enroll, flags);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "updating membership with domain %s failed: %s",
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("updating membership with domain %s failed: %s",
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_enroll_unref (enroll);
+		return -res;
 	}
 
 	if (details)
@@ -596,8 +613,10 @@ adcli_tool_computer_testjoin (adcli_conn *conn,
 	};
 
 	enroll = adcli_enroll_new (conn);
-	if (enroll == NULL)
-		errx (-1, "unexpected memory problems");
+	if (enroll == NULL) {
+		warnx ("unexpected memory problems");
+		return -1;
+	}
 
 	while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
 		switch (opt) {
@@ -622,18 +641,18 @@ adcli_tool_computer_testjoin (adcli_conn *conn,
 	res = adcli_enroll_load (enroll);
 	if (res != ADCLI_SUCCESS) {
 		adcli_enroll_unref (enroll);
-		adcli_conn_unref (conn);
-		errx (-res, "couldn't lookup domain info from keytab: %s",
-		      adcli_get_last_error ());
+		warnx ("couldn't lookup domain info from keytab: %s",
+		       adcli_get_last_error ());
+		return -res;
 	}
 
 	res = adcli_conn_connect (conn);
 	if (res != ADCLI_SUCCESS) {
 		adcli_enroll_unref (enroll);
-		adcli_conn_unref (conn);
-		errx (-res, "couldn't connect to %s domain: %s",
+		warnx ("couldn't connect to %s domain: %s",
 		      adcli_conn_get_domain_name (conn),
 		      adcli_get_last_error ());
+		return -res;
 	}
 
 	printf ("Sucessfully validated join to domain %s\n",
@@ -684,8 +703,10 @@ adcli_tool_computer_preset (adcli_conn *conn,
 	};
 
 	enroll = adcli_enroll_new (conn);
-	if (enroll == NULL)
-		errx (-1, "unexpected memory problems");
+	if (enroll == NULL) {
+		warnx ("unexpected memory problems");
+		return -1;
+	}
 	flags = ADCLI_ENROLL_NO_KEYTAB;
 
 	while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
@@ -713,17 +734,22 @@ adcli_tool_computer_preset (adcli_conn *conn,
 	argc -= optind;
 	argv += optind;
 
-	if (argc < 1)
-		errx (EUSAGE, "specify one or more host names of computer accounts to preset");
+	if (argc < 1) {
+		warnx ("specify one or more host names of computer accounts to preset");
+		adcli_enroll_unref (enroll);
+		return EUSAGE;
+	}
 
 	adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
 	reset_password = (adcli_enroll_get_computer_password (enroll) == NULL);
 
 	res = adcli_conn_connect (conn);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "couldn't connect to %s domain: %s",
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("couldn't connect to %s domain: %s",
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_enroll_unref (enroll);
+		return -res;
 	}
 
 	for (i = 0; i < argc; i++) {
@@ -734,9 +760,11 @@ adcli_tool_computer_preset (adcli_conn *conn,
 
 		res = adcli_enroll_join (enroll, flags);
 		if (res != ADCLI_SUCCESS) {
-			errx (-res, "presetting %s in %s domain failed: %s", argv[i],
-			      adcli_conn_get_domain_name (conn),
-			      adcli_get_last_error ());
+			warnx ("presetting %s in %s domain failed: %s", argv[i],
+			       adcli_conn_get_domain_name (conn),
+			       adcli_get_last_error ());
+			adcli_enroll_unref (enroll);
+			return -res;
 		}
 
 		printf ("computer-name: %s\n", adcli_enroll_get_computer_name (enroll));
@@ -778,8 +806,10 @@ adcli_tool_computer_reset (adcli_conn *conn,
 	};
 
 	enroll = adcli_enroll_new (conn);
-	if (enroll == NULL)
-		errx (-1, "unexpected memory problems");
+	if (enroll == NULL) {
+		warnx ("unexpected memory problems");
+		return -1;
+	}
 
 	while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
 		switch (opt) {
@@ -799,14 +829,19 @@ adcli_tool_computer_reset (adcli_conn *conn,
 	argc -= optind;
 	argv += optind;
 
-	if (argc != 1)
-		errx (EUSAGE, "specify one host name of computer account to reset");
+	if (argc != 1) {
+		warnx ("specify one host name of computer account to reset");
+		adcli_enroll_unref (enroll);
+		return EUSAGE;
+	}
 
 	res = adcli_conn_connect (conn);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "couldn't connect to %s domain: %s",
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("couldn't connect to %s domain: %s",
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_enroll_unref (enroll);
+		return -res;
 	}
 
 	parse_fqdn_or_name (enroll, argv[0]);
@@ -814,9 +849,11 @@ adcli_tool_computer_reset (adcli_conn *conn,
 
 	res = adcli_enroll_password (enroll, 0);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "resetting %s in %s domain failed: %s", argv[0],
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("resetting %s in %s domain failed: %s", argv[0],
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_enroll_unref (enroll);
+		return -res;
 	}
 
 	adcli_enroll_unref (enroll);
@@ -853,8 +890,10 @@ adcli_tool_computer_delete (adcli_conn *conn,
 	};
 
 	enroll = adcli_enroll_new (conn);
-	if (enroll == NULL)
-		errx (-1, "unexpected memory problems");
+	if (enroll == NULL) {
+		warnx ("unexpected memory problems");
+		return -1;
+	}
 
 	while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
 		switch (opt) {
@@ -874,22 +913,29 @@ adcli_tool_computer_delete (adcli_conn *conn,
 	argc -= optind;
 	argv += optind;
 
-	if (argc > 1)
-		errx (EUSAGE, "specify one host name of computer account to delete");
+	if (argc > 1) {
+		warnx ("specify one host name of computer account to delete");
+		adcli_enroll_unref (enroll);
+		return EUSAGE;
+	}
 
 	adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
 
 	res = adcli_enroll_load (enroll);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "couldn't lookup domain info from keytab: %s",
-		      adcli_get_last_error ());
+		warnx ("couldn't lookup domain info from keytab: %s",
+		       adcli_get_last_error ());
+		adcli_enroll_unref (enroll);
+		return -res;
 	}
 
 	res = adcli_conn_connect (conn);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "couldn't connect to %s domain: %s",
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("couldn't connect to %s domain: %s",
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_enroll_unref (enroll);
+		return -res;
 	}
 
 	if (argc == 1)
@@ -897,9 +943,11 @@ adcli_tool_computer_delete (adcli_conn *conn,
 
 	res = adcli_enroll_delete (enroll, 0);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "deleting %s in %s domain failed: %s", argv[0],
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("deleting %s in %s domain failed: %s", argv[0],
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_enroll_unref (enroll);
+		return -res;
 	}
 
 	adcli_enroll_unref (enroll);
-- 
2.37.2


From 80621d4ba43abc4731639091de417bc15c597fdf Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Mon, 15 Apr 2019 17:56:37 +0200
Subject: [PATCH 2/7] tools: remove errx from user and group commands

Related to https://bugzilla.redhat.com/show_bug.cgi?id=1588596

(cherry picked from commit cac0fa9df8888245399f2db187e05e31f93d1471)
---
 tools/entry.c | 229 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 152 insertions(+), 77 deletions(-)

diff --git a/tools/entry.c b/tools/entry.c
index 737fefe..3d5b938 100644
--- a/tools/entry.c
+++ b/tools/entry.c
@@ -225,29 +225,41 @@ adcli_tool_user_create (adcli_conn *conn,
 	argc -= optind;
 	argv += optind;
 
-	if (argc != 1)
-		errx (2, "specify one user name to create");
+	if (argc != 1) {
+		warnx ("specify one user name to create");
+		adcli_attrs_free (attrs);
+		return 2;
+	}
 
 	entry = adcli_entry_new_user (conn, argv[0]);
-	if (entry == NULL)
-		errx (-1, "unexpected memory problems");
+	if (entry == NULL) {
+		warnx ("unexpected memory problems");
+		adcli_attrs_free (attrs);
+		return -1;
+	}
 	adcli_entry_set_domain_ou (entry, ou);
 
 	adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
 
 	res = adcli_conn_connect (conn);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "couldn't connect to %s domain: %s",
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("couldn't connect to %s domain: %s",
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_entry_unref (entry);
+		adcli_attrs_free (attrs);
+		return -res;
 	}
 
 	res = adcli_entry_create (entry, attrs);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "creating user %s in domain %s failed: %s",
-		      adcli_entry_get_sam_name (entry),
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("creating user %s in domain %s failed: %s",
+		       adcli_entry_get_sam_name (entry),
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_entry_unref (entry);
+		adcli_attrs_free (attrs);
+		return -res;
 	}
 
 	adcli_entry_unref (entry);
@@ -302,28 +314,36 @@ adcli_tool_user_delete (adcli_conn *conn,
 	argc -= optind;
 	argv += optind;
 
-	if (argc != 1)
-		errx (2, "specify one user name to delete");
+	if (argc != 1) {
+		warnx ("specify one user name to delete");
+		return 2;
+	}
 
 	entry = adcli_entry_new_user (conn, argv[0]);
-	if (entry == NULL)
-		errx (-1, "unexpected memory problems");
+	if (entry == NULL) {
+		warnx ("unexpected memory problems");
+		return -1;
+	}
 
 	adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
 
 	res = adcli_conn_connect (conn);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "couldn't connect to %s domain: %s",
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("couldn't connect to %s domain: %s",
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_entry_unref (entry);
+		return -res;
 	}
 
 	res = adcli_entry_delete (entry);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "deleting user %s in domain %s failed: %s",
-		      adcli_entry_get_sam_name (entry),
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("deleting user %s in domain %s failed: %s",
+		       adcli_entry_get_sam_name (entry),
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_entry_unref (entry);
+		return -res;
 	}
 
 	adcli_entry_unref (entry);
@@ -390,29 +410,41 @@ adcli_tool_group_create (adcli_conn *conn,
 	argc -= optind;
 	argv += optind;
 
-	if (argc != 1)
-		errx (2, "specify one group to create");
+	if (argc != 1) {
+		warnx ("specify one group to create");
+		adcli_attrs_free (attrs);
+		return 2;
+	}
 
 	entry = adcli_entry_new_group (conn, argv[0]);
-	if (entry == NULL)
-		errx (-1, "unexpected memory problems");
+	if (entry == NULL) {
+		warnx ("unexpected memory problems");
+		adcli_attrs_free (attrs);
+		return -1;
+	}
 	adcli_entry_set_domain_ou (entry, ou);
 
 	adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
 
 	res = adcli_conn_connect (conn);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "couldn't connect to domain %s: %s",
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("couldn't connect to domain %s: %s",
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_entry_unref (entry);
+		adcli_attrs_free (attrs);
+		return -res;
 	}
 
 	res = adcli_entry_create (entry, attrs);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "creating group %s in domain %s failed: %s",
-		      adcli_entry_get_sam_name (entry),
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("creating group %s in domain %s failed: %s",
+		       adcli_entry_get_sam_name (entry),
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_entry_unref (entry);
+		adcli_attrs_free (attrs);
+		return -res;
 	}
 
 	adcli_entry_unref (entry);
@@ -467,28 +499,36 @@ adcli_tool_group_delete (adcli_conn *conn,
 	argc -= optind;
 	argv += optind;
 
-	if (argc != 1)
-		errx (2, "specify one group name to delete");
+	if (argc != 1) {
+		warnx ("specify one group name to delete");
+		return 2;
+	}
 
 	entry = adcli_entry_new_group (conn, argv[0]);
-	if (entry == NULL)
-		errx (-1, "unexpected memory problems");
+	if (entry == NULL) {
+		warnx ("unexpected memory problems");
+		return -1;
+	}
 
 	adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
 
 	res = adcli_conn_connect (conn);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "couldn't connect to %s domain: %s",
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("couldn't connect to %s domain: %s",
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_entry_unref (entry);
+		return -res;
 	}
 
 	res = adcli_entry_delete (entry);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "deleting group %s in domain %s failed: %s",
-		      adcli_entry_get_sam_name (entry),
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("deleting group %s in domain %s failed: %s",
+		       adcli_entry_get_sam_name (entry),
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_entry_unref (entry);
+		return -res;
 	}
 
 	adcli_entry_unref (entry);
@@ -496,7 +536,7 @@ adcli_tool_group_delete (adcli_conn *conn,
 	return 0;
 }
 
-static void
+static int
 expand_user_dn_as_member (adcli_conn *conn,
                           adcli_attrs *attrs,
                           const char *user,
@@ -510,16 +550,19 @@ expand_user_dn_as_member (adcli_conn *conn,
 
 	res = adcli_entry_load (entry);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "couldn't lookup user %s in domain %s: %s",
-		      user, adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("couldn't lookup user %s in domain %s: %s",
+		       user, adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_entry_unref (entry);
+		return -res;
 	}
 
 	dn = adcli_entry_get_dn (entry);
 	if (dn == NULL) {
-		errx (-ADCLI_ERR_CONFIG,
-		      "couldn't found user %s in domain %s",
-		      user, adcli_conn_get_domain_name (conn));
+		warnx ("couldn't found user %s in domain %s",
+		       user, adcli_conn_get_domain_name (conn));
+		adcli_entry_unref (entry);
+		return -ADCLI_ERR_CONFIG;
 	}
 
 	if (adding)
@@ -528,6 +571,8 @@ expand_user_dn_as_member (adcli_conn *conn,
 		adcli_attrs_delete1 (attrs, "member", dn);
 
 	adcli_entry_unref (entry);
+
+	return ADCLI_SUCCESS;
 }
 
 int
@@ -578,33 +623,48 @@ adcli_tool_member_add (adcli_conn *conn,
 	argc -= optind;
 	argv += optind;
 
-	if (argc < 2)
-		errx (2, "specify a group name and a user to add");
+	if (argc < 2) {
+		warnx ("specify a group name and a user to add");
+		return 2;
+	}
 
 	entry = adcli_entry_new_group (conn, argv[0]);
-	if (entry == NULL)
-		errx (-1, "unexpected memory problems");
+	if (entry == NULL) {
+		warnx ("unexpected memory problems");
+		return -1;
+	}
 
 	adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
 
 	res = adcli_conn_connect (conn);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "couldn't connect to %s domain: %s",
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("couldn't connect to %s domain: %s",
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_entry_unref (entry);
+		return -res;
 	}
 
 	attrs = adcli_attrs_new ();
 
-	for (i = 1; i < argc; i++)
-		expand_user_dn_as_member (conn, attrs, argv[i], 1);
+	for (i = 1; i < argc; i++) {
+		res = expand_user_dn_as_member (conn, attrs, argv[i], 1);
+		if (res != ADCLI_SUCCESS) {
+			adcli_attrs_free (attrs);
+			adcli_entry_unref (entry);
+			return res;
+		}
+	}
 
 	res = adcli_entry_modify (entry, attrs);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "adding member(s) to group %s in domain %s failed: %s",
-		      adcli_entry_get_sam_name (entry),
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("adding member(s) to group %s in domain %s failed: %s",
+		       adcli_entry_get_sam_name (entry),
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_attrs_free (attrs);
+		adcli_entry_unref (entry);
+		return -res;
 	}
 
 	adcli_attrs_free (attrs);
@@ -661,33 +721,48 @@ adcli_tool_member_remove (adcli_conn *conn,
 	argc -= optind;
 	argv += optind;
 
-	if (argc < 2)
-		errx (2, "specify a group name and a user to remove");
+	if (argc < 2) {
+		warnx ("specify a group name and a user to remove");
+		return 2;
+	}
 
 	entry = adcli_entry_new_group (conn, argv[0]);
-	if (entry == NULL)
-		errx (-1, "unexpected memory problems");
+	if (entry == NULL) {
+		warnx ("unexpected memory problems");
+		return -1;
+	}
 
 	adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
 
 	res = adcli_conn_connect (conn);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "couldn't connect to %s domain: %s",
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("couldn't connect to %s domain: %s",
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_entry_unref (entry);
+		return -res;
 	}
 
 	attrs = adcli_attrs_new ();
 
-	for (i = 1; i < argc; i++)
-		expand_user_dn_as_member (conn, attrs, argv[i], 0);
+	for (i = 1; i < argc; i++) {
+		res = expand_user_dn_as_member (conn, attrs, argv[i], 0);
+		if (res != ADCLI_SUCCESS) {
+			adcli_attrs_free (attrs);
+			adcli_entry_unref (entry);
+			return res;
+		}
+	}
 
 	res = adcli_entry_modify (entry, attrs);
 	if (res != ADCLI_SUCCESS) {
-		errx (-res, "adding member(s) to group %s in domain %s failed: %s",
-		      adcli_entry_get_sam_name (entry),
-		      adcli_conn_get_domain_name (conn),
-		      adcli_get_last_error ());
+		warnx ("adding member(s) to group %s in domain %s failed: %s",
+		       adcli_entry_get_sam_name (entry),
+		       adcli_conn_get_domain_name (conn),
+		       adcli_get_last_error ());
+		adcli_attrs_free (attrs);
+		adcli_entry_unref (entry);
+		return -res;
 	}
 
 	adcli_attrs_free (attrs);
-- 
2.37.2


From 555d323a828467ca44afa0449c107379214668ba Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Mon, 15 Apr 2019 17:57:37 +0200
Subject: [PATCH 3/7] tools: remove errx from info commands

Related to https://bugzilla.redhat.com/show_bug.cgi?id=1588596

(cherry picked from commit 4794812cc98c8783921f534d20dae8b44f3826d2)
---
 tools/info.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/tools/info.c b/tools/info.c
index e7e20ad..c63e0ff 100644
--- a/tools/info.c
+++ b/tools/info.c
@@ -162,21 +162,28 @@ adcli_tool_info (adcli_conn *unused,
 
 	if (argc == 1)
 		domain = argv[0];
-	else if (argc != 0)
-		errx (2, "specify one user name to create");
+	else if (argc != 0) {
+		warnx ("specify one user name to create");
+		return 2;
+	}
 
 	if (server) {
 		adcli_disco_host (server, &disco);
-		if (disco == NULL)
-			errx (1, "couldn't discover domain controller: %s", server);
+		if (disco == NULL) {
+			warnx ("couldn't discover domain controller: %s", server);
+			return 1;
+		}
 		for_host = 1;
 	} else if (domain) {
 		adcli_disco_domain (domain, &disco);
-		if (disco == NULL)
-			errx (1, "couldn't discover domain: %s", domain);
+		if (disco == NULL) {
+			warnx ("couldn't discover domain: %s", domain);
+			return 1;
+		}
 		for_host = 0;
 	} else {
-		errx (2, "specify a domain to discover");
+		warnx ("specify a domain to discover");
+		return 2;
 	}
 
 	print_info (disco, for_host);
-- 
2.37.2


From b18a45b768d4f5812f2c0b9749a8f639a650fda5 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Mon, 15 Apr 2019 17:59:17 +0200
Subject: [PATCH 4/7] tools: remove errx from adcli_read_password_func

Related to https://bugzilla.redhat.com/show_bug.cgi?id=1588596

(cherry picked from commit 251d7d0c71226afb8e51f7bc5794a7a3164f5a20)
---
 tools/tools.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/tools/tools.c b/tools/tools.c
index c4e2851..bdf6d38 100644
--- a/tools/tools.c
+++ b/tools/tools.c
@@ -247,7 +247,9 @@ adcli_read_password_func (adcli_login_type login_type,
 		if (res < 0) {
 			if (errno == EAGAIN || errno == EINTR)
 				continue;
-			err (EFAIL, "couldn't read password from stdin");
+			warn ("couldn't read password from stdin");
+			free (buffer);
+			return NULL;
 
 		} else if (res == 0) {
 			buffer[offset] = '\0';
@@ -261,8 +263,11 @@ adcli_read_password_func (adcli_login_type login_type,
 			return buffer;
 
 		} else {
-			if (memchr (buffer + offset, 0, res))
-				errx (EUSAGE, "unsupported null character present in password");
+			if (memchr (buffer + offset, 0, res)) {
+				warnx ("unsupported null character present in password");
+				free (buffer);
+				return NULL;
+			}
 			offset += res;
 		}
 	}
-- 
2.37.2


From 21ce739561f51ce4932c583f24536445e9a27343 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Mon, 15 Apr 2019 18:00:52 +0200
Subject: [PATCH 5/7] tools: remove errx from setup_krb5_conf_directory

Related to https://bugzilla.redhat.com/show_bug.cgi?id=1588596

(cherry picked from commit b8f5d995d30c17eb8bec3ac5e0777ea94f5b76c3)
---
 tools/tools.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/tools/tools.c b/tools/tools.c
index bdf6d38..fc9fa9a 100644
--- a/tools/tools.c
+++ b/tools/tools.c
@@ -327,21 +327,31 @@ setup_krb5_conf_directory (adcli_conn *conn)
 	}
 
 	if (asprintf (&directory, "%s%sadcli-krb5-XXXXXX", parent,
-	              (parent[0] && parent[strlen(parent) - 1] == '/') ? "" : "/") < 0)
-		errx (1, "unexpected: out of memory");
-
-	if (mkdtemp (directory) == NULL) {
-		errn = errno;
+	              (parent[0] && parent[strlen(parent) - 1] == '/') ? "" : "/") < 0) {
+		warnx ("unexpected: out of memory");
+		directory = NULL; /* content is undefined */
 		failed = 1;
-		warnx ("couldn't create temporary directory in: %s: %s",
-		       parent, strerror (errn));
-	} else {
-		if (asprintf (&filename, "%s/krb5.conf", directory) < 0 ||
-		    asprintf (&snippets, "%s/krb5.d", directory) < 0 ||
-		    asprintf (&contents, "includedir %s\n%s%s\n", snippets,
-		              krb5_conf ? "include " : "",
-		              krb5_conf ? krb5_conf : "") < 0)
-			errx (1, "unexpected: out of memory");
+	}
+
+	if (!failed) {
+		if (mkdtemp (directory) == NULL) {
+			errn = errno;
+			failed = 1;
+			warnx ("couldn't create temporary directory in: %s: %s",
+			       parent, strerror (errn));
+		} else {
+			if (asprintf (&filename, "%s/krb5.conf", directory) < 0 ||
+			    asprintf (&snippets, "%s/krb5.d", directory) < 0 ||
+			    asprintf (&contents, "includedir %s\n%s%s\n", snippets,
+			              krb5_conf ? "include " : "",
+			              krb5_conf ? krb5_conf : "") < 0) {
+				warnx ("unexpected: out of memory");
+				filename = NULL; /* content is undefined */
+				snippets = NULL; /* content is undefined */
+				contents = NULL; /* content is undefined */
+				failed = 1;
+			}
+		}
 	}
 
 	if (!failed) {
-- 
2.37.2


From 30a4751ba84f01a4c13bccb3c90930030479db61 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Mon, 8 Apr 2019 17:22:00 +0200
Subject: [PATCH 6/7] tools: entry - remove errx from parse_option

Related to https://bugzilla.redhat.com/show_bug.cgi?id=1588596

(cherry picked from commit d9912e19e48ec482351b9c384140ad71922ec5c0)
---
 tools/entry.c | 72 ++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 48 insertions(+), 24 deletions(-)

diff --git a/tools/entry.c b/tools/entry.c
index 3d5b938..2e36b12 100644
--- a/tools/entry.c
+++ b/tools/entry.c
@@ -81,7 +81,7 @@ static adcli_tool_desc common_usages[] = {
 	{ 0 },
 };
 
-static void
+static int
 parse_option (Option opt,
               const char *optarg,
               adcli_conn *conn)
@@ -93,57 +93,61 @@ parse_option (Option opt,
 	switch (opt) {
 	case opt_login_ccache:
 		adcli_conn_set_login_ccache_name (conn, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_login_user:
 		adcli_conn_set_login_user (conn, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_domain:
 		adcli_conn_set_domain_name (conn, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_domain_realm:
 		adcli_conn_set_domain_realm (conn, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_domain_controller:
 		adcli_conn_set_domain_controller (conn, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_no_password:
 		if (stdin_password || prompt_password) {
-			errx (EUSAGE, "cannot use --no-password argument with %s",
-			      stdin_password ? "--stdin-password" : "--prompt-password");
+			warnx ("cannot use --no-password argument with %s",
+			       stdin_password ? "--stdin-password" : "--prompt-password");
+			return EUSAGE;
 		} else {
 			adcli_conn_set_password_func (conn, NULL, NULL, NULL);
 			no_password = 1;
 		}
-		return;
+		return ADCLI_SUCCESS;
 	case opt_prompt_password:
 		if (stdin_password || no_password) {
-			errx (EUSAGE, "cannot use --prompt-password argument with %s",
-			      stdin_password ? "--stdin-password" : "--no-password");
+			warnx ("cannot use --prompt-password argument with %s",
+			       stdin_password ? "--stdin-password" : "--no-password");
+			return EUSAGE;
 		} else {
 			adcli_conn_set_password_func (conn, adcli_prompt_password_func, NULL, NULL);
 			prompt_password = 1;
 		}
-		return;
+		return ADCLI_SUCCESS;
 	case opt_stdin_password:
 		if (prompt_password || no_password) {
-			errx (EUSAGE, "cannot use --stdin-password argument with %s",
-			      prompt_password ? "--prompt-password" : "--no-password");
+			warnx ("cannot use --stdin-password argument with %s",
+			       prompt_password ? "--prompt-password" : "--no-password");
+			return EUSAGE;
 		} else {
 			adcli_conn_set_password_func (conn, adcli_read_password_func, NULL, NULL);
 			stdin_password = 1;
 		}
-		return;
+		return ADCLI_SUCCESS;
 	case opt_use_ldaps:
 		adcli_conn_set_use_ldaps (conn, true);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_verbose:
-		return;
+		return ADCLI_SUCCESS;
 	default:
 		assert (0 && "not reached");
 		break;
 	}
 
-	errx (EUSAGE, "failure to parse option '%c'", opt);
+	warnx ("failure to parse option '%c'", opt);
+	return EUSAGE;
 }
 
 int
@@ -217,7 +221,11 @@ adcli_tool_user_create (adcli_conn *conn,
 			adcli_attrs_free (attrs);
 			return opt == 'h' ? 0 : 2;
 		default:
-			parse_option ((Option)opt, optarg, conn);
+			res = parse_option ((Option)opt, optarg, conn);
+			if (res != ADCLI_SUCCESS) {
+				adcli_attrs_free (attrs);
+				return res;
+			}
 			break;
 		}
 	}
@@ -306,7 +314,10 @@ adcli_tool_user_delete (adcli_conn *conn,
 			adcli_tool_usage (options, common_usages);
 			return opt == 'h' ? 0 : 2;
 		default:
-			parse_option ((Option)opt, optarg, conn);
+			res = parse_option ((Option)opt, optarg, conn);
+			if (res != ADCLI_SUCCESS) {
+				return res;
+			}
 			break;
 		}
 	}
@@ -402,7 +413,11 @@ adcli_tool_group_create (adcli_conn *conn,
 			adcli_attrs_free (attrs);
 			return opt == 'h' ? 0 : 2;
 		default:
-			parse_option ((Option)opt, optarg, conn);
+			res = parse_option ((Option)opt, optarg, conn);
+			if (res != ADCLI_SUCCESS) {
+				adcli_attrs_free (attrs);
+				return res;
+			}
 			break;
 		}
 	}
@@ -491,7 +506,10 @@ adcli_tool_group_delete (adcli_conn *conn,
 			adcli_tool_usage (options, common_usages);
 			return opt == 'h' ? 0 : 2;
 		default:
-			parse_option ((Option)opt, optarg, conn);
+			res = parse_option ((Option)opt, optarg, conn);
+			if (res != ADCLI_SUCCESS) {
+				return res;
+			}
 			break;
 		}
 	}
@@ -615,7 +633,10 @@ adcli_tool_member_add (adcli_conn *conn,
 			adcli_tool_usage (options, common_usages);
 			return opt == 'h' ? 0 : 2;
 		default:
-			parse_option ((Option)opt, optarg, conn);
+			res = parse_option ((Option)opt, optarg, conn);
+			if (res != ADCLI_SUCCESS) {
+				return res;
+			}
 			break;
 		}
 	}
@@ -713,7 +734,10 @@ adcli_tool_member_remove (adcli_conn *conn,
 			adcli_tool_usage (options, common_usages);
 			return opt == 'h' ? 0 : 2;
 		default:
-			parse_option ((Option)opt, optarg, conn);
+			res = parse_option ((Option)opt, optarg, conn);
+			if (res != ADCLI_SUCCESS) {
+				return res;
+			}
 			break;
 		}
 	}
-- 
2.37.2


From 7bb88b67dc543d6d3060977066f84bb247b91fd2 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Mon, 8 Apr 2019 17:33:17 +0200
Subject: [PATCH 7/7] tools: computer - remove errx from parse_option

Related to https://bugzilla.redhat.com/show_bug.cgi?id=1588596

(cherry picked from commit f127ddef23a532cd9763190527bf79b4e47fa2ab)
---
 tools/computer.c | 132 +++++++++++++++++++++++++++++------------------
 1 file changed, 82 insertions(+), 50 deletions(-)

diff --git a/tools/computer.c b/tools/computer.c
index 71ebb6f..a3872d5 100644
--- a/tools/computer.c
+++ b/tools/computer.c
@@ -164,7 +164,7 @@ static adcli_tool_desc common_usages[] = {
 	{ 0 },
 };
 
-static void
+static int
 parse_option (Option opt,
               const char *optarg,
               adcli_conn *conn,
@@ -180,142 +180,149 @@ parse_option (Option opt,
 	switch (opt) {
 	case opt_login_ccache:
 		adcli_conn_set_login_ccache_name (conn, optarg ? optarg : "");
-		return;
+		return ADCLI_SUCCESS;
 	case opt_login_user:
 		if (adcli_conn_get_allowed_login_types (conn) & ADCLI_LOGIN_USER_ACCOUNT) {
 			adcli_conn_set_login_user (conn, optarg);
 			adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
 		} else {
-			errx (EUSAGE, "cannot set --user if --login-type not set to 'user'");
+			warnx ("cannot set --user if --login-type not set to 'user'");
+			return EUSAGE;
 		}
-		return;
+		return ADCLI_SUCCESS;
 	case opt_login_type:
 		if (optarg && strcmp (optarg, "computer") == 0) {
-			if (adcli_conn_get_login_user (conn) != NULL)
-				errx (EUSAGE, "cannot set --login-type to 'computer' if --user is set");
-			else
+			if (adcli_conn_get_login_user (conn) != NULL) {
+				warnx ("cannot set --login-type to 'computer' if --user is set");
+				return EUSAGE;
+			} else
 				adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_COMPUTER_ACCOUNT);
 		} else if (optarg && strcmp (optarg, "user") == 0) {
 			adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
 
 		} else {
-			errx (EUSAGE, "unknown login type '%s'", optarg);
+			warnx ("unknown login type '%s'", optarg);
+			return EUSAGE;
 		}
-		return;
+		return ADCLI_SUCCESS;
 	case opt_host_fqdn:
 		adcli_conn_set_host_fqdn (conn, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_host_keytab:
 		adcli_enroll_set_keytab_name (enroll, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_computer_name:
 		adcli_conn_set_computer_name (conn, optarg);
 		adcli_enroll_set_computer_name (enroll, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_domain:
 		adcli_conn_set_domain_name (conn, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_domain_realm:
 		adcli_conn_set_domain_realm (conn, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_domain_controller:
 		adcli_conn_set_domain_controller (conn, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_domain_ou:
 		adcli_enroll_set_domain_ou (enroll, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_service_name:
 		adcli_enroll_add_service_name (enroll, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_no_password:
 		if (stdin_password || prompt_password) {
-			errx (EUSAGE, "cannot use --no-password argument with %s",
-			      stdin_password ? "--stdin-password" : "--prompt-password");
+			warnx ("cannot use --no-password argument with %s",
+			       stdin_password ? "--stdin-password" : "--prompt-password");
+			return EUSAGE;
 		} else {
 			adcli_conn_set_password_func (conn, NULL, NULL, NULL);
 			no_password = 1;
 		}
-		return;
+		return ADCLI_SUCCESS;
 	case opt_prompt_password:
 		if (stdin_password || no_password) {
-			errx (EUSAGE, "cannot use --prompt-password argument with %s",
-			      stdin_password ? "--stdin-password" : "--no-password");
+			warnx ("cannot use --prompt-password argument with %s",
+			       stdin_password ? "--stdin-password" : "--no-password");
+			return EUSAGE;
 		} else {
 			adcli_conn_set_password_func (conn, adcli_prompt_password_func, NULL, NULL);
 			prompt_password = 1;
 		}
-		return;
+		return ADCLI_SUCCESS;
 	case opt_stdin_password:
 		if (prompt_password || no_password) {
-			errx (EUSAGE, "cannot use --stdin-password argument with %s",
-			      prompt_password ? "--prompt-password" : "--no-password");
+			warnx ("cannot use --stdin-password argument with %s",
+			       prompt_password ? "--prompt-password" : "--no-password");
+			return EUSAGE;
 		} else {
 			adcli_conn_set_password_func (conn, adcli_read_password_func, NULL, NULL);
 			stdin_password = 1;
 		}
-		return;
+		return ADCLI_SUCCESS;
 	case opt_os_name:
 		adcli_enroll_set_os_name (enroll, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_os_version:
 		adcli_enroll_set_os_version (enroll, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_os_service_pack:
 		adcli_enroll_set_os_service_pack (enroll, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_user_principal:
 		if (optarg && optarg[0])
 			adcli_enroll_set_user_principal (enroll, optarg);
 		else
 			adcli_enroll_auto_user_principal (enroll);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_computer_password_lifetime:
 		errno = 0;
 		lifetime = strtoul (optarg, &endptr, 10);
 		if (errno != 0 || *endptr != '\0' || endptr == optarg) {
-			errx (EUSAGE,
-			      "failure to parse value '%s' of option 'computer-password-lifetime'; "
-			      "expecting non-negative integer indicating the lifetime in days",
-			      optarg);
+			warnx ("failure to parse value '%s' of option 'computer-password-lifetime'; "
+			       "expecting non-negative integer indicating the lifetime in days",
+			       optarg);
+			return EUSAGE;
 		}
 
 		adcli_enroll_set_computer_password_lifetime (enroll, lifetime);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_samba_data_tool:
 		errno = 0;
 		ret = access (optarg, X_OK);
 		if (ret != 0) {
 			ret = errno;
-			errx (EUSAGE, "Failed to access tool to add Samba data: %s", strerror (ret));
+			warnx ("Failed to access tool to add Samba data: %s", strerror (ret));
+			return EUSAGE;
 		} else {
 			adcli_enroll_set_samba_data_tool (enroll, optarg);
 		}
-		return;
+		return ADCLI_SUCCESS;
 	case opt_trusted_for_delegation:
 		if (strcasecmp (optarg, "true") == 0 || strcasecmp (optarg, "yes") == 0) {
 			adcli_enroll_set_trusted_for_delegation (enroll, true);
 		} else {
 			adcli_enroll_set_trusted_for_delegation (enroll, false);
 		}
-		return;
+		return ADCLI_SUCCESS;
 	case opt_dont_expire_password:
 		if (strcasecmp (optarg, "true") == 0 || strcasecmp (optarg, "yes") == 0) {
 			adcli_enroll_set_dont_expire_password (enroll, true);
 		} else {
 			adcli_enroll_set_dont_expire_password (enroll, false);
 		}
-		return;
+		return ADCLI_SUCCESS;
 	case opt_add_service_principal:
 		adcli_enroll_add_service_principal_to_add (enroll, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_remove_service_principal:
 		adcli_enroll_add_service_principal_to_remove (enroll, optarg);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_use_ldaps:
 		adcli_conn_set_use_ldaps (conn, true);
-		return;
+		return ADCLI_SUCCESS;
 	case opt_verbose:
-		return;
+		return ADCLI_SUCCESS;
 
 	/* Should be handled by caller */
 	case opt_show_details:
@@ -326,7 +333,8 @@ parse_option (Option opt,
 		break;
 	}
 
-	errx (EUSAGE, "failure to parse option '%c'", opt);
+	warnx ("failure to parse option '%c'", opt);
+	return EUSAGE;
 }
 
 static void
@@ -424,7 +432,11 @@ adcli_tool_computer_join (adcli_conn *conn,
 			adcli_enroll_unref (enroll);
 			return opt == 'h' ? 0 : 2;
 		default:
-			parse_option ((Option)opt, optarg, conn, enroll);
+			res = parse_option ((Option)opt, optarg, conn, enroll);
+			if (res != ADCLI_SUCCESS) {
+				adcli_enroll_unref (enroll);
+				return res;
+			}
 			break;
 		}
 	}
@@ -537,7 +549,11 @@ adcli_tool_computer_update (adcli_conn *conn,
 			adcli_enroll_unref (enroll);
 			return opt == 'h' ? 0 : 2;
 		default:
-			parse_option ((Option)opt, optarg, conn, enroll);
+			res = parse_option ((Option)opt, optarg, conn, enroll);
+			if (res != ADCLI_SUCCESS) {
+				adcli_enroll_unref (enroll);
+				return res;
+			}
 			break;
 		}
 	}
@@ -628,7 +644,11 @@ adcli_tool_computer_testjoin (adcli_conn *conn,
 			adcli_enroll_unref (enroll);
 			return opt == 'h' ? 0 : 2;
 		default:
-			parse_option ((Option)opt, optarg, conn, enroll);
+			res = parse_option ((Option)opt, optarg, conn, enroll);
+			if (res != ADCLI_SUCCESS) {
+				adcli_enroll_unref (enroll);
+				return res;
+			}
 			break;
 		}
 	}
@@ -726,7 +746,11 @@ adcli_tool_computer_preset (adcli_conn *conn,
 			adcli_enroll_unref (enroll);
 			return 2;
 		default:
-			parse_option ((Option)opt, optarg, conn, enroll);
+			res = parse_option ((Option)opt, optarg, conn, enroll);
+			if (res != ADCLI_SUCCESS) {
+				adcli_enroll_unref (enroll);
+				return res;
+			}
 			break;
 		}
 	}
@@ -821,7 +845,11 @@ adcli_tool_computer_reset (adcli_conn *conn,
 			adcli_enroll_unref (enroll);
 			return opt == 'h' ? 0 : 2;
 		default:
-			parse_option ((Option)opt, optarg, conn, enroll);
+			res = parse_option ((Option)opt, optarg, conn, enroll);
+			if (res != ADCLI_SUCCESS) {
+				adcli_enroll_unref (enroll);
+				return res;
+			}
 			break;
 		}
 	}
@@ -905,7 +933,11 @@ adcli_tool_computer_delete (adcli_conn *conn,
 			adcli_enroll_unref (enroll);
 			return opt == 'h' ? 0 : 2;
 		default:
-			parse_option ((Option)opt, optarg, conn, enroll);
+			res = parse_option ((Option)opt, optarg, conn, enroll);
+			if (res != ADCLI_SUCCESS) {
+				adcli_enroll_unref (enroll);
+				return res;
+			}
 			break;
 		}
 	}
-- 
2.37.2

openSUSE Build Service is sponsored by