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

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