Blame SOURCES/0006-tools-entry-remove-errx-from-parse_option.patch

341f9a
From d9912e19e48ec482351b9c384140ad71922ec5c0 Mon Sep 17 00:00:00 2001
341f9a
From: Sumit Bose <sbose@redhat.com>
341f9a
Date: Mon, 8 Apr 2019 17:22:00 +0200
341f9a
Subject: [PATCH 6/7] tools: entry - remove errx from parse_option
341f9a
341f9a
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1588596
341f9a
---
341f9a
 tools/entry.c | 70 ++++++++++++++++++++++++++++++++++-----------------
341f9a
 1 file changed, 47 insertions(+), 23 deletions(-)
341f9a
341f9a
diff --git a/tools/entry.c b/tools/entry.c
341f9a
index 97ec6e7..f361845 100644
341f9a
--- a/tools/entry.c
341f9a
+++ b/tools/entry.c
341f9a
@@ -81,7 +81,7 @@ static adcli_tool_desc common_usages[] = {
341f9a
 	{ 0 },
341f9a
 };
341f9a
 
341f9a
-static void
341f9a
+static int
341f9a
 parse_option (Option opt,
341f9a
               const char *optarg,
341f9a
               adcli_conn *conn)
341f9a
@@ -93,54 +93,58 @@ parse_option (Option opt,
341f9a
 	switch (opt) {
341f9a
 	case opt_login_ccache:
341f9a
 		adcli_conn_set_login_ccache_name (conn, optarg);
341f9a
-		return;
341f9a
+		return ADCLI_SUCCESS;
341f9a
 	case opt_login_user:
341f9a
 		adcli_conn_set_login_user (conn, optarg);
341f9a
-		return;
341f9a
+		return ADCLI_SUCCESS;
341f9a
 	case opt_domain:
341f9a
 		adcli_conn_set_domain_name (conn, optarg);
341f9a
-		return;
341f9a
+		return ADCLI_SUCCESS;
341f9a
 	case opt_domain_realm:
341f9a
 		adcli_conn_set_domain_realm (conn, optarg);
341f9a
-		return;
341f9a
+		return ADCLI_SUCCESS;
341f9a
 	case opt_domain_controller:
341f9a
 		adcli_conn_set_domain_controller (conn, optarg);
341f9a
-		return;
341f9a
+		return ADCLI_SUCCESS;
341f9a
 	case opt_no_password:
341f9a
 		if (stdin_password || prompt_password) {
341f9a
-			errx (EUSAGE, "cannot use --no-password argument with %s",
341f9a
-			      stdin_password ? "--stdin-password" : "--prompt-password");
341f9a
+			warnx ("cannot use --no-password argument with %s",
341f9a
+			       stdin_password ? "--stdin-password" : "--prompt-password");
341f9a
+			return EUSAGE;
341f9a
 		} else {
341f9a
 			adcli_conn_set_password_func (conn, NULL, NULL, NULL);
341f9a
 			no_password = 1;
341f9a
 		}
341f9a
-		return;
341f9a
+		return ADCLI_SUCCESS;
341f9a
 	case opt_prompt_password:
341f9a
 		if (stdin_password || no_password) {
341f9a
-			errx (EUSAGE, "cannot use --prompt-password argument with %s",
341f9a
-			      stdin_password ? "--stdin-password" : "--no-password");
341f9a
+			warnx ("cannot use --prompt-password argument with %s",
341f9a
+			       stdin_password ? "--stdin-password" : "--no-password");
341f9a
+			return EUSAGE;
341f9a
 		} else {
341f9a
 			adcli_conn_set_password_func (conn, adcli_prompt_password_func, NULL, NULL);
341f9a
 			prompt_password = 1;
341f9a
 		}
341f9a
-		return;
341f9a
+		return ADCLI_SUCCESS;
341f9a
 	case opt_stdin_password:
341f9a
 		if (prompt_password || no_password) {
341f9a
-			errx (EUSAGE, "cannot use --stdin-password argument with %s",
341f9a
-			      prompt_password ? "--prompt-password" : "--no-password");
341f9a
+			warnx ("cannot use --stdin-password argument with %s",
341f9a
+			       prompt_password ? "--prompt-password" : "--no-password");
341f9a
+			return EUSAGE;
341f9a
 		} else {
341f9a
 			adcli_conn_set_password_func (conn, adcli_read_password_func, NULL, NULL);
341f9a
 			stdin_password = 1;
341f9a
 		}
341f9a
-		return;
341f9a
+		return ADCLI_SUCCESS;
341f9a
 	case opt_verbose:
341f9a
-		return;
341f9a
+		return ADCLI_SUCCESS;
341f9a
 	default:
341f9a
 		assert (0 && "not reached");
341f9a
 		break;
341f9a
 	}
341f9a
 
341f9a
-	errx (EUSAGE, "failure to parse option '%c'", opt);
341f9a
+	warnx ("failure to parse option '%c'", opt);
341f9a
+	return EUSAGE;
341f9a
 }
341f9a
 
341f9a
 int
341f9a
@@ -224,7 +228,11 @@ adcli_tool_user_create (adcli_conn *conn,
341f9a
 			adcli_attrs_free (attrs);
341f9a
 			return opt == 'h' ? 0 : 2;
341f9a
 		default:
341f9a
-			parse_option ((Option)opt, optarg, conn);
341f9a
+			res = parse_option ((Option)opt, optarg, conn);
341f9a
+			if (res != ADCLI_SUCCESS) {
341f9a
+				adcli_attrs_free (attrs);
341f9a
+				return res;
341f9a
+			}
341f9a
 			break;
341f9a
 		}
341f9a
 	}
341f9a
@@ -322,7 +330,10 @@ adcli_tool_user_delete (adcli_conn *conn,
341f9a
 			adcli_tool_usage (options, common_usages);
341f9a
 			return opt == 'h' ? 0 : 2;
341f9a
 		default:
341f9a
-			parse_option ((Option)opt, optarg, conn);
341f9a
+			res = parse_option ((Option)opt, optarg, conn);
341f9a
+			if (res != ADCLI_SUCCESS) {
341f9a
+				return res;
341f9a
+			}
341f9a
 			break;
341f9a
 		}
341f9a
 	}
341f9a
@@ -417,7 +428,11 @@ adcli_tool_group_create (adcli_conn *conn,
341f9a
 			adcli_attrs_free (attrs);
341f9a
 			return opt == 'h' ? 0 : 2;
341f9a
 		default:
341f9a
-			parse_option ((Option)opt, optarg, conn);
341f9a
+			res = parse_option ((Option)opt, optarg, conn);
341f9a
+			if (res != ADCLI_SUCCESS) {
341f9a
+				adcli_attrs_free (attrs);
341f9a
+				return res;
341f9a
+			}
341f9a
 			break;
341f9a
 		}
341f9a
 	}
341f9a
@@ -505,7 +520,10 @@ adcli_tool_group_delete (adcli_conn *conn,
341f9a
 			adcli_tool_usage (options, common_usages);
341f9a
 			return opt == 'h' ? 0 : 2;
341f9a
 		default:
341f9a
-			parse_option ((Option)opt, optarg, conn);
341f9a
+			res = parse_option ((Option)opt, optarg, conn);
341f9a
+			if (res != ADCLI_SUCCESS) {
341f9a
+				return res;
341f9a
+			}
341f9a
 			break;
341f9a
 		}
341f9a
 	}
341f9a
@@ -628,7 +646,10 @@ adcli_tool_member_add (adcli_conn *conn,
341f9a
 			adcli_tool_usage (options, common_usages);
341f9a
 			return opt == 'h' ? 0 : 2;
341f9a
 		default:
341f9a
-			parse_option ((Option)opt, optarg, conn);
341f9a
+			res = parse_option ((Option)opt, optarg, conn);
341f9a
+			if (res != ADCLI_SUCCESS) {
341f9a
+				return res;
341f9a
+			}
341f9a
 			break;
341f9a
 		}
341f9a
 	}
341f9a
@@ -725,7 +746,10 @@ adcli_tool_member_remove (adcli_conn *conn,
341f9a
 			adcli_tool_usage (options, common_usages);
341f9a
 			return opt == 'h' ? 0 : 2;
341f9a
 		default:
341f9a
-			parse_option ((Option)opt, optarg, conn);
341f9a
+			res = parse_option ((Option)opt, optarg, conn);
341f9a
+			if (res != ADCLI_SUCCESS) {
341f9a
+				return res;
341f9a
+			}
341f9a
 			break;
341f9a
 		}
341f9a
 	}
341f9a
-- 
341f9a
2.20.1
341f9a