603fc1b
From d9912e19e48ec482351b9c384140ad71922ec5c0 Mon Sep 17 00:00:00 2001
603fc1b
From: Sumit Bose <sbose@redhat.com>
603fc1b
Date: Mon, 8 Apr 2019 17:22:00 +0200
603fc1b
Subject: [PATCH 6/7] tools: entry - remove errx from parse_option
603fc1b
603fc1b
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1588596
603fc1b
---
603fc1b
 tools/entry.c | 70 ++++++++++++++++++++++++++++++++++-----------------
603fc1b
 1 file changed, 47 insertions(+), 23 deletions(-)
603fc1b
603fc1b
diff --git a/tools/entry.c b/tools/entry.c
603fc1b
index 97ec6e7..f361845 100644
603fc1b
--- a/tools/entry.c
603fc1b
+++ b/tools/entry.c
603fc1b
@@ -81,7 +81,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
@@ -93,54 +93,58 @@ parse_option (Option opt,
603fc1b
 	switch (opt) {
603fc1b
 	case opt_login_ccache:
603fc1b
 		adcli_conn_set_login_ccache_name (conn, optarg);
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	case opt_login_user:
603fc1b
 		adcli_conn_set_login_user (conn, 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_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_verbose:
603fc1b
-		return;
603fc1b
+		return ADCLI_SUCCESS;
603fc1b
 	default:
603fc1b
 		assert (0 && "not reached");
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
 int
603fc1b
@@ -224,7 +228,11 @@ adcli_tool_user_create (adcli_conn *conn,
603fc1b
 			adcli_attrs_free (attrs);
603fc1b
 			return opt == 'h' ? 0 : 2;
603fc1b
 		default:
603fc1b
-			parse_option ((Option)opt, optarg, conn);
603fc1b
+			res = parse_option ((Option)opt, optarg, conn);
603fc1b
+			if (res != ADCLI_SUCCESS) {
603fc1b
+				adcli_attrs_free (attrs);
603fc1b
+				return res;
603fc1b
+			}
603fc1b
 			break;
603fc1b
 		}
603fc1b
 	}
603fc1b
@@ -322,7 +330,10 @@ adcli_tool_user_delete (adcli_conn *conn,
603fc1b
 			adcli_tool_usage (options, common_usages);
603fc1b
 			return opt == 'h' ? 0 : 2;
603fc1b
 		default:
603fc1b
-			parse_option ((Option)opt, optarg, conn);
603fc1b
+			res = parse_option ((Option)opt, optarg, conn);
603fc1b
+			if (res != ADCLI_SUCCESS) {
603fc1b
+				return res;
603fc1b
+			}
603fc1b
 			break;
603fc1b
 		}
603fc1b
 	}
603fc1b
@@ -417,7 +428,11 @@ adcli_tool_group_create (adcli_conn *conn,
603fc1b
 			adcli_attrs_free (attrs);
603fc1b
 			return opt == 'h' ? 0 : 2;
603fc1b
 		default:
603fc1b
-			parse_option ((Option)opt, optarg, conn);
603fc1b
+			res = parse_option ((Option)opt, optarg, conn);
603fc1b
+			if (res != ADCLI_SUCCESS) {
603fc1b
+				adcli_attrs_free (attrs);
603fc1b
+				return res;
603fc1b
+			}
603fc1b
 			break;
603fc1b
 		}
603fc1b
 	}
603fc1b
@@ -505,7 +520,10 @@ adcli_tool_group_delete (adcli_conn *conn,
603fc1b
 			adcli_tool_usage (options, common_usages);
603fc1b
 			return opt == 'h' ? 0 : 2;
603fc1b
 		default:
603fc1b
-			parse_option ((Option)opt, optarg, conn);
603fc1b
+			res = parse_option ((Option)opt, optarg, conn);
603fc1b
+			if (res != ADCLI_SUCCESS) {
603fc1b
+				return res;
603fc1b
+			}
603fc1b
 			break;
603fc1b
 		}
603fc1b
 	}
603fc1b
@@ -628,7 +646,10 @@ adcli_tool_member_add (adcli_conn *conn,
603fc1b
 			adcli_tool_usage (options, common_usages);
603fc1b
 			return opt == 'h' ? 0 : 2;
603fc1b
 		default:
603fc1b
-			parse_option ((Option)opt, optarg, conn);
603fc1b
+			res = parse_option ((Option)opt, optarg, conn);
603fc1b
+			if (res != ADCLI_SUCCESS) {
603fc1b
+				return res;
603fc1b
+			}
603fc1b
 			break;
603fc1b
 		}
603fc1b
 	}
603fc1b
@@ -725,7 +746,10 @@ adcli_tool_member_remove (adcli_conn *conn,
603fc1b
 			adcli_tool_usage (options, common_usages);
603fc1b
 			return opt == 'h' ? 0 : 2;
603fc1b
 		default:
603fc1b
-			parse_option ((Option)opt, optarg, conn);
603fc1b
+			res = parse_option ((Option)opt, optarg, conn);
603fc1b
+			if (res != ADCLI_SUCCESS) {
603fc1b
+				return res;
603fc1b
+			}
603fc1b
 			break;
603fc1b
 		}
603fc1b
 	}
603fc1b
-- 
603fc1b
2.20.1
603fc1b