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