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

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