Blame 0007-tools-computer-remove-errx-from-parse_option.patch

603fc1b
From f127ddef23a532cd9763190527bf79b4e47fa2ab Mon Sep 17 00:00:00 2001
603fc1b
From: Sumit Bose <sbose@redhat.com>
603fc1b
Date: Mon, 8 Apr 2019 17:33:17 +0200
603fc1b
Subject: [PATCH 7/7] tools: computer - remove errx from parse_option
603fc1b
603fc1b
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1588596
603fc1b
---
603fc1b
 tools/computer.c | 128 +++++++++++++++++++++++++++++------------------
603fc1b
 1 file changed, 80 insertions(+), 48 deletions(-)
603fc1b
603fc1b
diff --git a/tools/computer.c b/tools/computer.c
603fc1b
index 9cbbb28..ac8a203 100644
603fc1b
--- a/tools/computer.c
603fc1b
+++ b/tools/computer.c
603fc1b
@@ -159,7 +159,7 @@ static adcli_tool_desc common_usages[] = {
603fc1b
 	{ 0 },
603fc1b
 };
603fc1b
 
603fc1b
-static void
603fc1b
+static int
603fc1b
 parse_option (Option opt,
603fc1b
               const char *optarg,
603fc1b
               adcli_conn *conn,
603fc1b
@@ -175,132 +175,139 @@ parse_option (Option opt,
603fc1b
 	switch (opt) {
603fc1b
 	case opt_login_ccache:
603fc1b
 		adcli_conn_set_login_ccache_name (conn, optarg ? optarg : "");
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_login_user:
603fc1b
 		if (adcli_conn_get_allowed_login_types (conn) & ADCLI_LOGIN_USER_ACCOUNT) {
603fc1b
 			adcli_conn_set_login_user (conn, optarg);
603fc1b
 			adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
603fc1b
 		} else {
603fc1b
-			errx (EUSAGE, "cannot set --user if --login-type not set to 'user'");
603fc1b
+			warnx ("cannot set --user if --login-type not set to 'user'");
603fc1b
+			return EUSAGE;
603fc1b
 		}
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_login_type:
603fc1b
 		if (optarg && strcmp (optarg, "computer") == 0) {
603fc1b
-			if (adcli_conn_get_login_user (conn) != NULL)
603fc1b
-				errx (EUSAGE, "cannot set --login-type to 'computer' if --user is set");
603fc1b
-			else
603fc1b
+			if (adcli_conn_get_login_user (conn) != NULL) {
603fc1b
+				warnx ("cannot set --login-type to 'computer' if --user is set");
603fc1b
+				return EUSAGE;
603fc1b
+			} else
603fc1b
 				adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_COMPUTER_ACCOUNT);
603fc1b
 		} else if (optarg && strcmp (optarg, "user") == 0) {
603fc1b
 			adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
603fc1b
 
603fc1b
 		} else {
603fc1b
-			errx (EUSAGE, "unknown login type '%s'", optarg);
603fc1b
+			warnx ("unknown login type '%s'", optarg);
603fc1b
+			return EUSAGE;
603fc1b
 		}
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_host_fqdn:
603fc1b
 		adcli_conn_set_host_fqdn (conn, optarg);
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_host_keytab:
603fc1b
 		adcli_enroll_set_keytab_name (enroll, optarg);
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_computer_name:
603fc1b
 		adcli_conn_set_computer_name (conn, optarg);
603fc1b
 		adcli_enroll_set_computer_name (enroll, optarg);
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_domain:
603fc1b
 		adcli_conn_set_domain_name (conn, optarg);
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_domain_realm:
603fc1b
 		adcli_conn_set_domain_realm (conn, optarg);
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_domain_controller:
603fc1b
 		adcli_conn_set_domain_controller (conn, optarg);
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_domain_ou:
603fc1b
 		adcli_enroll_set_domain_ou (enroll, optarg);
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_service_name:
603fc1b
 		adcli_enroll_add_service_name (enroll, optarg);
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_no_password:
603fc1b
 		if (stdin_password || prompt_password) {
603fc1b
-			errx (EUSAGE, "cannot use --no-password argument with %s",
603fc1b
-			      stdin_password ? "--stdin-password" : "--prompt-password");
603fc1b
+			warnx ("cannot use --no-password argument with %s",
603fc1b
+			       stdin_password ? "--stdin-password" : "--prompt-password");
603fc1b
+			return EUSAGE;
603fc1b
 		} else {
603fc1b
 			adcli_conn_set_password_func (conn, NULL, NULL, NULL);
603fc1b
 			no_password = 1;
603fc1b
 		}
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_prompt_password:
603fc1b
 		if (stdin_password || no_password) {
603fc1b
-			errx (EUSAGE, "cannot use --prompt-password argument with %s",
603fc1b
-			      stdin_password ? "--stdin-password" : "--no-password");
603fc1b
+			warnx ("cannot use --prompt-password argument with %s",
603fc1b
+			       stdin_password ? "--stdin-password" : "--no-password");
603fc1b
+			return EUSAGE;
603fc1b
 		} else {
603fc1b
 			adcli_conn_set_password_func (conn, adcli_prompt_password_func, NULL, NULL);
603fc1b
 			prompt_password = 1;
603fc1b
 		}
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_stdin_password:
603fc1b
 		if (prompt_password || no_password) {
603fc1b
-			errx (EUSAGE, "cannot use --stdin-password argument with %s",
603fc1b
-			      prompt_password ? "--prompt-password" : "--no-password");
603fc1b
+			warnx ("cannot use --stdin-password argument with %s",
603fc1b
+			       prompt_password ? "--prompt-password" : "--no-password");
603fc1b
+			return EUSAGE;
603fc1b
 		} else {
603fc1b
 			adcli_conn_set_password_func (conn, adcli_read_password_func, NULL, NULL);
603fc1b
 			stdin_password = 1;
603fc1b
 		}
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_os_name:
603fc1b
 		adcli_enroll_set_os_name (enroll, optarg);
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_os_version:
603fc1b
 		adcli_enroll_set_os_version (enroll, optarg);
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_os_service_pack:
603fc1b
 		adcli_enroll_set_os_service_pack (enroll, optarg);
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_user_principal:
603fc1b
 		if (optarg && optarg[0])
603fc1b
 			adcli_enroll_set_user_principal (enroll, optarg);
603fc1b
 		else
603fc1b
 			adcli_enroll_auto_user_principal (enroll);
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_computer_password_lifetime:
603fc1b
 		errno = 0;
603fc1b
 		lifetime = strtoul (optarg, &endptr, 10);
603fc1b
 		if (errno != 0 || *endptr != '\0' || endptr == optarg) {
603fc1b
-			errx (EUSAGE,
603fc1b
-			      "failure to parse value '%s' of option 'computer-password-lifetime'; "
603fc1b
-			      "expecting non-negative integer indicating the lifetime in days",
603fc1b
-			      optarg);
603fc1b
+			warnx ("failure to parse value '%s' of option 'computer-password-lifetime'; "
603fc1b
+			       "expecting non-negative integer indicating the lifetime in days",
603fc1b
+			       optarg);
603fc1b
+			return EUSAGE;
603fc1b
 		}
603fc1b
 
603fc1b
 		adcli_enroll_set_computer_password_lifetime (enroll, lifetime);
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_samba_data_tool:
603fc1b
 		errno = 0;
603fc1b
 		ret = access (optarg, X_OK);
603fc1b
 		if (ret != 0) {
603fc1b
 			ret = errno;
603fc1b
-			errx (EUSAGE, "Failed to access tool to add Samba data: %s", strerror (ret));
603fc1b
+			warnx ("Failed to access tool to add Samba data: %s", strerror (ret));
603fc1b
+			return EUSAGE;
603fc1b
 		} else {
603fc1b
 			adcli_enroll_set_samba_data_tool (enroll, optarg);
603fc1b
 		}
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_trusted_for_delegation:
603fc1b
 		if (strcasecmp (optarg, "true") == 0 || strcasecmp (optarg, "yes") == 0) {
603fc1b
 			adcli_enroll_set_trusted_for_delegation (enroll, true);
603fc1b
 		} else {
603fc1b
 			adcli_enroll_set_trusted_for_delegation (enroll, false);
603fc1b
 		}
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_add_service_principal:
603fc1b
 		adcli_enroll_add_service_principal_to_add (enroll, optarg);
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_remove_service_principal:
603fc1b
 		adcli_enroll_add_service_principal_to_remove (enroll, optarg);
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_verbose:
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 
603fc1b
 	/* Should be handled by caller */
603fc1b
 	case opt_show_details:
603fc1b
@@ -311,7 +318,8 @@ parse_option (Option opt,
603fc1b
 		break;
603fc1b
 	}
603fc1b
 
603fc1b
-	errx (EUSAGE, "failure to parse option '%c'", opt);
603fc1b
+	warnx ("failure to parse option '%c'", opt);
603fc1b
+	return EUSAGE;
603fc1b
 }
603fc1b
 
603fc1b
 static void
603fc1b
@@ -407,7 +415,11 @@ adcli_tool_computer_join (adcli_conn *conn,
603fc1b
 			adcli_enroll_unref (enroll);
603fc1b
 			return opt == 'h' ? 0 : 2;
603fc1b
 		default:
603fc1b
-			parse_option ((Option)opt, optarg, conn, enroll);
603fc1b
+			res = parse_option ((Option)opt, optarg, conn, enroll);
603fc1b
+			if (res != ADCLI_SUCCESS) {
603fc1b
+				adcli_enroll_unref (enroll);
603fc1b
+				return res;
603fc1b
+			}
603fc1b
 			break;
603fc1b
 		}
603fc1b
 	}
603fc1b
@@ -519,7 +531,11 @@ adcli_tool_computer_update (adcli_conn *conn,
603fc1b
 			adcli_enroll_unref (enroll);
603fc1b
 			return opt == 'h' ? 0 : 2;
603fc1b
 		default:
603fc1b
-			parse_option ((Option)opt, optarg, conn, enroll);
603fc1b
+			res = parse_option ((Option)opt, optarg, conn, enroll);
603fc1b
+			if (res != ADCLI_SUCCESS) {
603fc1b
+				adcli_enroll_unref (enroll);
603fc1b
+				return res;
603fc1b
+			}
603fc1b
 			break;
603fc1b
 		}
603fc1b
 	}
603fc1b
@@ -610,7 +626,11 @@ adcli_tool_computer_testjoin (adcli_conn *conn,
603fc1b
 			adcli_enroll_unref (enroll);
603fc1b
 			return opt == 'h' ? 0 : 2;
603fc1b
 		default:
603fc1b
-			parse_option ((Option)opt, optarg, conn, enroll);
603fc1b
+			res = parse_option ((Option)opt, optarg, conn, enroll);
603fc1b
+			if (res != ADCLI_SUCCESS) {
603fc1b
+				adcli_enroll_unref (enroll);
603fc1b
+				return res;
603fc1b
+			}
603fc1b
 			break;
603fc1b
 		}
603fc1b
 	}
603fc1b
@@ -707,7 +727,11 @@ adcli_tool_computer_preset (adcli_conn *conn,
603fc1b
 			adcli_enroll_unref (enroll);
603fc1b
 			return 2;
603fc1b
 		default:
603fc1b
-			parse_option ((Option)opt, optarg, conn, enroll);
603fc1b
+			res = parse_option ((Option)opt, optarg, conn, enroll);
603fc1b
+			if (res != ADCLI_SUCCESS) {
603fc1b
+				adcli_enroll_unref (enroll);
603fc1b
+				return res;
603fc1b
+			}
603fc1b
 			break;
603fc1b
 		}
603fc1b
 	}
603fc1b
@@ -801,7 +825,11 @@ adcli_tool_computer_reset (adcli_conn *conn,
603fc1b
 			adcli_enroll_unref (enroll);
603fc1b
 			return opt == 'h' ? 0 : 2;
603fc1b
 		default:
603fc1b
-			parse_option ((Option)opt, optarg, conn, enroll);
603fc1b
+			res = parse_option ((Option)opt, optarg, conn, enroll);
603fc1b
+			if (res != ADCLI_SUCCESS) {
603fc1b
+				adcli_enroll_unref (enroll);
603fc1b
+				return res;
603fc1b
+			}
603fc1b
 			break;
603fc1b
 		}
603fc1b
 	}
603fc1b
@@ -884,7 +912,11 @@ adcli_tool_computer_delete (adcli_conn *conn,
603fc1b
 			adcli_enroll_unref (enroll);
603fc1b
 			return opt == 'h' ? 0 : 2;
603fc1b
 		default:
603fc1b
-			parse_option ((Option)opt, optarg, conn, enroll);
603fc1b
+			res = parse_option ((Option)opt, optarg, conn, enroll);
603fc1b
+			if (res != ADCLI_SUCCESS) {
603fc1b
+				adcli_enroll_unref (enroll);
603fc1b
+				return res;
603fc1b
+			}
603fc1b
 			break;
603fc1b
 		}
603fc1b
 	}
603fc1b
-- 
603fc1b
2.20.1
603fc1b