|
|
341f9a |
From fa7926c7a9d92bc7c42c610ba6f1706c635aa901 Mon Sep 17 00:00:00 2001
|
|
|
341f9a |
From: Sumit Bose <sbose@redhat.com>
|
|
|
341f9a |
Date: Mon, 15 Apr 2019 17:54:27 +0200
|
|
|
341f9a |
Subject: [PATCH 1/7] tools: remove errx from computer commands
|
|
|
341f9a |
|
|
|
341f9a |
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1588596
|
|
|
341f9a |
---
|
|
|
341f9a |
tools/computer.c | 166 ++++++++++++++++++++++++++++++-----------------
|
|
|
341f9a |
1 file changed, 107 insertions(+), 59 deletions(-)
|
|
|
341f9a |
|
|
|
341f9a |
diff --git a/tools/computer.c b/tools/computer.c
|
|
|
341f9a |
index bee695c..9cbbb28 100644
|
|
|
341f9a |
--- a/tools/computer.c
|
|
|
341f9a |
+++ b/tools/computer.c
|
|
|
341f9a |
@@ -379,8 +379,10 @@ adcli_tool_computer_join (adcli_conn *conn,
|
|
|
341f9a |
};
|
|
|
341f9a |
|
|
|
341f9a |
enroll = adcli_enroll_new (conn);
|
|
|
341f9a |
- if (enroll == NULL)
|
|
|
341f9a |
- errx (-1, "unexpected memory problems");
|
|
|
341f9a |
+ if (enroll == NULL) {
|
|
|
341f9a |
+ warnx ("unexpected memory problems");
|
|
|
341f9a |
+ return -1;
|
|
|
341f9a |
+ }
|
|
|
341f9a |
|
|
|
341f9a |
while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
|
|
|
341f9a |
switch (opt) {
|
|
|
341f9a |
@@ -415,21 +417,28 @@ adcli_tool_computer_join (adcli_conn *conn,
|
|
|
341f9a |
|
|
|
341f9a |
if (argc == 1)
|
|
|
341f9a |
adcli_conn_set_domain_name (conn, argv[0]);
|
|
|
341f9a |
- else if (argc > 1)
|
|
|
341f9a |
- errx (2, "extra arguments specified");
|
|
|
341f9a |
+ else if (argc > 1) {
|
|
|
341f9a |
+ warnx ("extra arguments specified");
|
|
|
341f9a |
+ adcli_enroll_unref (enroll);
|
|
|
341f9a |
+ return 2;
|
|
|
341f9a |
+ }
|
|
|
341f9a |
|
|
|
341f9a |
res = adcli_conn_connect (conn);
|
|
|
341f9a |
if (res != ADCLI_SUCCESS) {
|
|
|
341f9a |
- errx (-res, "couldn't connect to %s domain: %s",
|
|
|
341f9a |
- adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
- adcli_get_last_error ());
|
|
|
341f9a |
+ warnx ("couldn't connect to %s domain: %s",
|
|
|
341f9a |
+ adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
+ adcli_get_last_error ());
|
|
|
341f9a |
+ adcli_enroll_unref (enroll);
|
|
|
341f9a |
+ return -res;
|
|
|
341f9a |
}
|
|
|
341f9a |
|
|
|
341f9a |
res = adcli_enroll_join (enroll, flags);
|
|
|
341f9a |
if (res != ADCLI_SUCCESS) {
|
|
|
341f9a |
- errx (-res, "joining domain %s failed: %s",
|
|
|
341f9a |
- adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
- adcli_get_last_error ());
|
|
|
341f9a |
+ warnx ("joining domain %s failed: %s",
|
|
|
341f9a |
+ adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
+ adcli_get_last_error ());
|
|
|
341f9a |
+ adcli_enroll_unref (enroll);
|
|
|
341f9a |
+ return -res;
|
|
|
341f9a |
}
|
|
|
341f9a |
|
|
|
341f9a |
if (details)
|
|
|
341f9a |
@@ -486,8 +495,10 @@ adcli_tool_computer_update (adcli_conn *conn,
|
|
|
341f9a |
};
|
|
|
341f9a |
|
|
|
341f9a |
enroll = adcli_enroll_new (conn);
|
|
|
341f9a |
- if (enroll == NULL)
|
|
|
341f9a |
- errx (-1, "unexpected memory problems");
|
|
|
341f9a |
+ if (enroll == NULL) {
|
|
|
341f9a |
+ warnx ("unexpected memory problems");
|
|
|
341f9a |
+ return -1;
|
|
|
341f9a |
+ }
|
|
|
341f9a |
|
|
|
341f9a |
while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
|
|
|
341f9a |
switch (opt) {
|
|
|
341f9a |
@@ -525,22 +536,28 @@ adcli_tool_computer_update (adcli_conn *conn,
|
|
|
341f9a |
|
|
|
341f9a |
res = adcli_enroll_load (enroll);
|
|
|
341f9a |
if (res != ADCLI_SUCCESS) {
|
|
|
341f9a |
- errx (-res, "couldn't lookup domain info from keytab: %s",
|
|
|
341f9a |
- adcli_get_last_error ());
|
|
|
341f9a |
+ warnx ("couldn't lookup domain info from keytab: %s",
|
|
|
341f9a |
+ adcli_get_last_error ());
|
|
|
341f9a |
+ adcli_enroll_unref (enroll);
|
|
|
341f9a |
+ return -res;
|
|
|
341f9a |
}
|
|
|
341f9a |
|
|
|
341f9a |
res = adcli_conn_connect (conn);
|
|
|
341f9a |
if (res != ADCLI_SUCCESS) {
|
|
|
341f9a |
- errx (-res, "couldn't connect to %s domain: %s",
|
|
|
341f9a |
- adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
- adcli_get_last_error ());
|
|
|
341f9a |
+ warnx ("couldn't connect to %s domain: %s",
|
|
|
341f9a |
+ adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
+ adcli_get_last_error ());
|
|
|
341f9a |
+ adcli_enroll_unref (enroll);
|
|
|
341f9a |
+ return -res;
|
|
|
341f9a |
}
|
|
|
341f9a |
|
|
|
341f9a |
res = adcli_enroll_update (enroll, flags);
|
|
|
341f9a |
if (res != ADCLI_SUCCESS) {
|
|
|
341f9a |
- errx (-res, "updating membership with domain %s failed: %s",
|
|
|
341f9a |
- adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
- adcli_get_last_error ());
|
|
|
341f9a |
+ warnx ("updating membership with domain %s failed: %s",
|
|
|
341f9a |
+ adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
+ adcli_get_last_error ());
|
|
|
341f9a |
+ adcli_enroll_unref (enroll);
|
|
|
341f9a |
+ return -res;
|
|
|
341f9a |
}
|
|
|
341f9a |
|
|
|
341f9a |
if (details)
|
|
|
341f9a |
@@ -578,8 +595,10 @@ adcli_tool_computer_testjoin (adcli_conn *conn,
|
|
|
341f9a |
};
|
|
|
341f9a |
|
|
|
341f9a |
enroll = adcli_enroll_new (conn);
|
|
|
341f9a |
- if (enroll == NULL)
|
|
|
341f9a |
- errx (-1, "unexpected memory problems");
|
|
|
341f9a |
+ if (enroll == NULL) {
|
|
|
341f9a |
+ warnx ("unexpected memory problems");
|
|
|
341f9a |
+ return -1;
|
|
|
341f9a |
+ }
|
|
|
341f9a |
|
|
|
341f9a |
while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
|
|
|
341f9a |
switch (opt) {
|
|
|
341f9a |
@@ -604,18 +623,18 @@ adcli_tool_computer_testjoin (adcli_conn *conn,
|
|
|
341f9a |
res = adcli_enroll_load (enroll);
|
|
|
341f9a |
if (res != ADCLI_SUCCESS) {
|
|
|
341f9a |
adcli_enroll_unref (enroll);
|
|
|
341f9a |
- adcli_conn_unref (conn);
|
|
|
341f9a |
- errx (-res, "couldn't lookup domain info from keytab: %s",
|
|
|
341f9a |
- adcli_get_last_error ());
|
|
|
341f9a |
+ warnx ("couldn't lookup domain info from keytab: %s",
|
|
|
341f9a |
+ adcli_get_last_error ());
|
|
|
341f9a |
+ return -res;
|
|
|
341f9a |
}
|
|
|
341f9a |
|
|
|
341f9a |
res = adcli_conn_connect (conn);
|
|
|
341f9a |
if (res != ADCLI_SUCCESS) {
|
|
|
341f9a |
adcli_enroll_unref (enroll);
|
|
|
341f9a |
- adcli_conn_unref (conn);
|
|
|
341f9a |
- errx (-res, "couldn't connect to %s domain: %s",
|
|
|
341f9a |
+ warnx ("couldn't connect to %s domain: %s",
|
|
|
341f9a |
adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
adcli_get_last_error ());
|
|
|
341f9a |
+ return -res;
|
|
|
341f9a |
}
|
|
|
341f9a |
|
|
|
341f9a |
printf ("Sucessfully validated join to domain %s\n",
|
|
|
341f9a |
@@ -665,8 +684,10 @@ adcli_tool_computer_preset (adcli_conn *conn,
|
|
|
341f9a |
};
|
|
|
341f9a |
|
|
|
341f9a |
enroll = adcli_enroll_new (conn);
|
|
|
341f9a |
- if (enroll == NULL)
|
|
|
341f9a |
- errx (-1, "unexpected memory problems");
|
|
|
341f9a |
+ if (enroll == NULL) {
|
|
|
341f9a |
+ warnx ("unexpected memory problems");
|
|
|
341f9a |
+ return -1;
|
|
|
341f9a |
+ }
|
|
|
341f9a |
flags = ADCLI_ENROLL_NO_KEYTAB;
|
|
|
341f9a |
|
|
|
341f9a |
while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
|
|
|
341f9a |
@@ -694,17 +715,22 @@ adcli_tool_computer_preset (adcli_conn *conn,
|
|
|
341f9a |
argc -= optind;
|
|
|
341f9a |
argv += optind;
|
|
|
341f9a |
|
|
|
341f9a |
- if (argc < 1)
|
|
|
341f9a |
- errx (EUSAGE, "specify one or more host names of computer accounts to preset");
|
|
|
341f9a |
+ if (argc < 1) {
|
|
|
341f9a |
+ warnx ("specify one or more host names of computer accounts to preset");
|
|
|
341f9a |
+ adcli_enroll_unref (enroll);
|
|
|
341f9a |
+ return EUSAGE;
|
|
|
341f9a |
+ }
|
|
|
341f9a |
|
|
|
341f9a |
adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
|
|
|
341f9a |
reset_password = (adcli_enroll_get_computer_password (enroll) == NULL);
|
|
|
341f9a |
|
|
|
341f9a |
res = adcli_conn_connect (conn);
|
|
|
341f9a |
if (res != ADCLI_SUCCESS) {
|
|
|
341f9a |
- errx (-res, "couldn't connect to %s domain: %s",
|
|
|
341f9a |
- adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
- adcli_get_last_error ());
|
|
|
341f9a |
+ warnx ("couldn't connect to %s domain: %s",
|
|
|
341f9a |
+ adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
+ adcli_get_last_error ());
|
|
|
341f9a |
+ adcli_enroll_unref (enroll);
|
|
|
341f9a |
+ return -res;
|
|
|
341f9a |
}
|
|
|
341f9a |
|
|
|
341f9a |
for (i = 0; i < argc; i++) {
|
|
|
341f9a |
@@ -715,9 +741,11 @@ adcli_tool_computer_preset (adcli_conn *conn,
|
|
|
341f9a |
|
|
|
341f9a |
res = adcli_enroll_join (enroll, flags);
|
|
|
341f9a |
if (res != ADCLI_SUCCESS) {
|
|
|
341f9a |
- errx (-res, "presetting %s in %s domain failed: %s", argv[i],
|
|
|
341f9a |
- adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
- adcli_get_last_error ());
|
|
|
341f9a |
+ warnx ("presetting %s in %s domain failed: %s", argv[i],
|
|
|
341f9a |
+ adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
+ adcli_get_last_error ());
|
|
|
341f9a |
+ adcli_enroll_unref (enroll);
|
|
|
341f9a |
+ return -res;
|
|
|
341f9a |
}
|
|
|
341f9a |
|
|
|
341f9a |
printf ("computer-name: %s\n", adcli_enroll_get_computer_name (enroll));
|
|
|
341f9a |
@@ -758,8 +786,10 @@ adcli_tool_computer_reset (adcli_conn *conn,
|
|
|
341f9a |
};
|
|
|
341f9a |
|
|
|
341f9a |
enroll = adcli_enroll_new (conn);
|
|
|
341f9a |
- if (enroll == NULL)
|
|
|
341f9a |
- errx (-1, "unexpected memory problems");
|
|
|
341f9a |
+ if (enroll == NULL) {
|
|
|
341f9a |
+ warnx ("unexpected memory problems");
|
|
|
341f9a |
+ return -1;
|
|
|
341f9a |
+ }
|
|
|
341f9a |
|
|
|
341f9a |
while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
|
|
|
341f9a |
switch (opt) {
|
|
|
341f9a |
@@ -779,14 +809,19 @@ adcli_tool_computer_reset (adcli_conn *conn,
|
|
|
341f9a |
argc -= optind;
|
|
|
341f9a |
argv += optind;
|
|
|
341f9a |
|
|
|
341f9a |
- if (argc != 1)
|
|
|
341f9a |
- errx (EUSAGE, "specify one host name of computer account to reset");
|
|
|
341f9a |
+ if (argc != 1) {
|
|
|
341f9a |
+ warnx ("specify one host name of computer account to reset");
|
|
|
341f9a |
+ adcli_enroll_unref (enroll);
|
|
|
341f9a |
+ return EUSAGE;
|
|
|
341f9a |
+ }
|
|
|
341f9a |
|
|
|
341f9a |
res = adcli_conn_connect (conn);
|
|
|
341f9a |
if (res != ADCLI_SUCCESS) {
|
|
|
341f9a |
- errx (-res, "couldn't connect to %s domain: %s",
|
|
|
341f9a |
- adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
- adcli_get_last_error ());
|
|
|
341f9a |
+ warnx ("couldn't connect to %s domain: %s",
|
|
|
341f9a |
+ adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
+ adcli_get_last_error ());
|
|
|
341f9a |
+ adcli_enroll_unref (enroll);
|
|
|
341f9a |
+ return -res;
|
|
|
341f9a |
}
|
|
|
341f9a |
|
|
|
341f9a |
parse_fqdn_or_name (enroll, argv[0]);
|
|
|
341f9a |
@@ -794,9 +829,11 @@ adcli_tool_computer_reset (adcli_conn *conn,
|
|
|
341f9a |
|
|
|
341f9a |
res = adcli_enroll_password (enroll, 0);
|
|
|
341f9a |
if (res != ADCLI_SUCCESS) {
|
|
|
341f9a |
- errx (-res, "resetting %s in %s domain failed: %s", argv[0],
|
|
|
341f9a |
- adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
- adcli_get_last_error ());
|
|
|
341f9a |
+ warnx ("resetting %s in %s domain failed: %s", argv[0],
|
|
|
341f9a |
+ adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
+ adcli_get_last_error ());
|
|
|
341f9a |
+ adcli_enroll_unref (enroll);
|
|
|
341f9a |
+ return -res;
|
|
|
341f9a |
}
|
|
|
341f9a |
|
|
|
341f9a |
adcli_enroll_unref (enroll);
|
|
|
341f9a |
@@ -832,8 +869,10 @@ adcli_tool_computer_delete (adcli_conn *conn,
|
|
|
341f9a |
};
|
|
|
341f9a |
|
|
|
341f9a |
enroll = adcli_enroll_new (conn);
|
|
|
341f9a |
- if (enroll == NULL)
|
|
|
341f9a |
- errx (-1, "unexpected memory problems");
|
|
|
341f9a |
+ if (enroll == NULL) {
|
|
|
341f9a |
+ warnx ("unexpected memory problems");
|
|
|
341f9a |
+ return -1;
|
|
|
341f9a |
+ }
|
|
|
341f9a |
|
|
|
341f9a |
while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
|
|
|
341f9a |
switch (opt) {
|
|
|
341f9a |
@@ -853,22 +892,29 @@ adcli_tool_computer_delete (adcli_conn *conn,
|
|
|
341f9a |
argc -= optind;
|
|
|
341f9a |
argv += optind;
|
|
|
341f9a |
|
|
|
341f9a |
- if (argc > 1)
|
|
|
341f9a |
- errx (EUSAGE, "specify one host name of computer account to delete");
|
|
|
341f9a |
+ if (argc > 1) {
|
|
|
341f9a |
+ warnx ("specify one host name of computer account to delete");
|
|
|
341f9a |
+ adcli_enroll_unref (enroll);
|
|
|
341f9a |
+ return EUSAGE;
|
|
|
341f9a |
+ }
|
|
|
341f9a |
|
|
|
341f9a |
adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_USER_ACCOUNT);
|
|
|
341f9a |
|
|
|
341f9a |
res = adcli_enroll_load (enroll);
|
|
|
341f9a |
if (res != ADCLI_SUCCESS) {
|
|
|
341f9a |
- errx (-res, "couldn't lookup domain info from keytab: %s",
|
|
|
341f9a |
- adcli_get_last_error ());
|
|
|
341f9a |
+ warnx ("couldn't lookup domain info from keytab: %s",
|
|
|
341f9a |
+ adcli_get_last_error ());
|
|
|
341f9a |
+ adcli_enroll_unref (enroll);
|
|
|
341f9a |
+ return -res;
|
|
|
341f9a |
}
|
|
|
341f9a |
|
|
|
341f9a |
res = adcli_conn_connect (conn);
|
|
|
341f9a |
if (res != ADCLI_SUCCESS) {
|
|
|
341f9a |
- errx (-res, "couldn't connect to %s domain: %s",
|
|
|
341f9a |
- adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
- adcli_get_last_error ());
|
|
|
341f9a |
+ warnx ("couldn't connect to %s domain: %s",
|
|
|
341f9a |
+ adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
+ adcli_get_last_error ());
|
|
|
341f9a |
+ adcli_enroll_unref (enroll);
|
|
|
341f9a |
+ return -res;
|
|
|
341f9a |
}
|
|
|
341f9a |
|
|
|
341f9a |
if (argc == 1)
|
|
|
341f9a |
@@ -876,9 +922,11 @@ adcli_tool_computer_delete (adcli_conn *conn,
|
|
|
341f9a |
|
|
|
341f9a |
res = adcli_enroll_delete (enroll, 0);
|
|
|
341f9a |
if (res != ADCLI_SUCCESS) {
|
|
|
341f9a |
- errx (-res, "deleting %s in %s domain failed: %s", argv[0],
|
|
|
341f9a |
- adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
- adcli_get_last_error ());
|
|
|
341f9a |
+ warnx ("deleting %s in %s domain failed: %s", argv[0],
|
|
|
341f9a |
+ adcli_conn_get_domain_name (conn),
|
|
|
341f9a |
+ adcli_get_last_error ());
|
|
|
341f9a |
+ adcli_enroll_unref (enroll);
|
|
|
341f9a |
+ return -res;
|
|
|
341f9a |
}
|
|
|
341f9a |
|
|
|
341f9a |
adcli_enroll_unref (enroll);
|
|
|
341f9a |
--
|
|
|
341f9a |
2.20.1
|
|
|
341f9a |
|