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

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