|
|
f441eb |
From 6fd99ff6c5dd6ef0be8d942989b1c6dcee3102d9 Mon Sep 17 00:00:00 2001
|
|
|
f441eb |
From: Sumit Bose <sbose@redhat.com>
|
|
|
f441eb |
Date: Fri, 22 Mar 2019 12:37:39 +0100
|
|
|
f441eb |
Subject: [PATCH] Implement 'adcli testjoin'
|
|
|
f441eb |
|
|
|
f441eb |
By calling adcli testjoin it will be checked if the host credentials
|
|
|
f441eb |
stored in the keytab are still valid.
|
|
|
f441eb |
|
|
|
f441eb |
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1622583
|
|
|
f441eb |
---
|
|
|
f441eb |
doc/adcli.xml | 34 +++++++++++++++++++++++
|
|
|
f441eb |
tools/computer.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
f441eb |
tools/tools.c | 1 +
|
|
|
f441eb |
tools/tools.h | 4 +++
|
|
|
f441eb |
4 files changed, 111 insertions(+)
|
|
|
f441eb |
|
|
|
f441eb |
diff --git a/doc/adcli.xml b/doc/adcli.xml
|
|
|
f441eb |
index af73433..9605b4a 100644
|
|
|
f441eb |
--- a/doc/adcli.xml
|
|
|
f441eb |
+++ b/doc/adcli.xml
|
|
|
f441eb |
@@ -43,6 +43,9 @@
|
|
|
f441eb |
<cmdsynopsis>
|
|
|
f441eb |
<command>adcli update</command>
|
|
|
f441eb |
</cmdsynopsis>
|
|
|
f441eb |
+ <cmdsynopsis>
|
|
|
f441eb |
+ <command>adcli testjoin</command>
|
|
|
f441eb |
+ </cmdsynopsis>
|
|
|
f441eb |
<cmdsynopsis>
|
|
|
f441eb |
<command>adcli create-user</command>
|
|
|
f441eb |
<arg choice="opt">--domain=domain.example.com</arg>
|
|
|
f441eb |
@@ -474,6 +477,37 @@ $ adcli update --login-ccache=/tmp/krbcc_123
|
|
|
f441eb |
|
|
|
f441eb |
</refsect1>
|
|
|
f441eb |
|
|
|
f441eb |
+<refsect1 id='testjoin'>
|
|
|
f441eb |
+ <title>Testing if the machine account password is valid</title>
|
|
|
f441eb |
+
|
|
|
f441eb |
+ <para><command>adcli testjoin</command> uses the current credentials in
|
|
|
f441eb |
+ the keytab and tries to authenticate with the machine account to the AD
|
|
|
f441eb |
+ domain. If this works the machine account password and the join are
|
|
|
f441eb |
+ still valid. If it fails the machine account password or the whole
|
|
|
f441eb |
+ machine account have to be refreshed with
|
|
|
f441eb |
+ <command>adcli join</command> or <command>adcli update</command>.
|
|
|
f441eb |
+ </para>
|
|
|
f441eb |
+
|
|
|
f441eb |
+<programlisting>
|
|
|
f441eb |
+$ adcli testjoin
|
|
|
f441eb |
+</programlisting>
|
|
|
f441eb |
+
|
|
|
f441eb |
+ <para>Only the global options not related to authentication are
|
|
|
f441eb |
+ available, additionally you can specify the following options to
|
|
|
f441eb |
+ control how this operation is done.</para>
|
|
|
f441eb |
+
|
|
|
f441eb |
+ <variablelist>
|
|
|
f441eb |
+ <varlistentry>
|
|
|
f441eb |
+ <term><option>-K, --host-keytab=<parameter>/path/to/keytab</parameter></option></term>
|
|
|
f441eb |
+ <listitem><para>Specify the path to the host keytab where
|
|
|
f441eb |
+ current host credentials are stored and the new ones
|
|
|
f441eb |
+ will be written to. If not specified, the default
|
|
|
f441eb |
+ location will be used, usually
|
|
|
f441eb |
+ <filename>/etc/krb5.keytab</filename>.</para></listitem>
|
|
|
f441eb |
+ </varlistentry>
|
|
|
f441eb |
+ </variablelist>
|
|
|
f441eb |
+</refsect1>
|
|
|
f441eb |
+
|
|
|
f441eb |
<refsect1 id='create_user'>
|
|
|
f441eb |
<title>Creating a User</title>
|
|
|
f441eb |
|
|
|
f441eb |
diff --git a/tools/computer.c b/tools/computer.c
|
|
|
f441eb |
index 112340e..610ed2b 100644
|
|
|
f441eb |
--- a/tools/computer.c
|
|
|
f441eb |
+++ b/tools/computer.c
|
|
|
f441eb |
@@ -566,6 +566,78 @@ adcli_tool_computer_update (adcli_conn *conn,
|
|
|
f441eb |
return 0;
|
|
|
f441eb |
}
|
|
|
f441eb |
|
|
|
f441eb |
+int
|
|
|
f441eb |
+adcli_tool_computer_testjoin (adcli_conn *conn,
|
|
|
f441eb |
+ int argc,
|
|
|
f441eb |
+ char *argv[])
|
|
|
f441eb |
+{
|
|
|
f441eb |
+ adcli_enroll *enroll;
|
|
|
f441eb |
+ adcli_result res;
|
|
|
f441eb |
+ const char *ktname;
|
|
|
f441eb |
+ int opt;
|
|
|
f441eb |
+
|
|
|
f441eb |
+ struct option options[] = {
|
|
|
f441eb |
+ { "domain", required_argument, NULL, opt_domain },
|
|
|
f441eb |
+ { "domain-controller", required_argument, NULL, opt_domain_controller },
|
|
|
f441eb |
+ { "host-keytab", required_argument, 0, opt_host_keytab },
|
|
|
f441eb |
+ { "verbose", no_argument, NULL, opt_verbose },
|
|
|
f441eb |
+ { "help", no_argument, NULL, 'h' },
|
|
|
f441eb |
+ { 0 },
|
|
|
f441eb |
+ };
|
|
|
f441eb |
+
|
|
|
f441eb |
+ static adcli_tool_desc usages[] = {
|
|
|
f441eb |
+ { 0, "usage: adcli testjoin" },
|
|
|
f441eb |
+ { 0 },
|
|
|
f441eb |
+ };
|
|
|
f441eb |
+
|
|
|
f441eb |
+ enroll = adcli_enroll_new (conn);
|
|
|
f441eb |
+ if (enroll == NULL)
|
|
|
f441eb |
+ errx (-1, "unexpected memory problems");
|
|
|
f441eb |
+
|
|
|
f441eb |
+ while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
|
|
|
f441eb |
+ switch (opt) {
|
|
|
f441eb |
+ case 'h':
|
|
|
f441eb |
+ case '?':
|
|
|
f441eb |
+ case ':':
|
|
|
f441eb |
+ adcli_tool_usage (options, usages);
|
|
|
f441eb |
+ adcli_tool_usage (options, common_usages);
|
|
|
f441eb |
+ adcli_enroll_unref (enroll);
|
|
|
f441eb |
+ return opt == 'h' ? 0 : 2;
|
|
|
f441eb |
+ default:
|
|
|
f441eb |
+ parse_option ((Option)opt, optarg, conn, enroll);
|
|
|
f441eb |
+ break;
|
|
|
f441eb |
+ }
|
|
|
f441eb |
+ }
|
|
|
f441eb |
+
|
|
|
f441eb |
+ /* Force use of a keytab to test the join/machine account password */
|
|
|
f441eb |
+ adcli_conn_set_allowed_login_types (conn, ADCLI_LOGIN_COMPUTER_ACCOUNT);
|
|
|
f441eb |
+ ktname = adcli_enroll_get_keytab_name (enroll);
|
|
|
f441eb |
+ adcli_conn_set_login_keytab_name (conn, ktname ? ktname : "");
|
|
|
f441eb |
+
|
|
|
f441eb |
+ res = adcli_enroll_load (enroll);
|
|
|
f441eb |
+ if (res != ADCLI_SUCCESS) {
|
|
|
f441eb |
+ adcli_enroll_unref (enroll);
|
|
|
f441eb |
+ adcli_conn_unref (conn);
|
|
|
f441eb |
+ errx (-res, "couldn't lookup domain info from keytab: %s",
|
|
|
f441eb |
+ adcli_get_last_error ());
|
|
|
f441eb |
+ }
|
|
|
f441eb |
+
|
|
|
f441eb |
+ res = adcli_conn_connect (conn);
|
|
|
f441eb |
+ if (res != ADCLI_SUCCESS) {
|
|
|
f441eb |
+ adcli_enroll_unref (enroll);
|
|
|
f441eb |
+ adcli_conn_unref (conn);
|
|
|
f441eb |
+ errx (-res, "couldn't connect to %s domain: %s",
|
|
|
f441eb |
+ adcli_conn_get_domain_name (conn),
|
|
|
f441eb |
+ adcli_get_last_error ());
|
|
|
f441eb |
+ }
|
|
|
f441eb |
+
|
|
|
f441eb |
+ printf ("Sucessfully validated join to domain %s\n",
|
|
|
f441eb |
+ adcli_conn_get_domain_name (conn));
|
|
|
f441eb |
+
|
|
|
f441eb |
+ adcli_enroll_unref (enroll);
|
|
|
f441eb |
+
|
|
|
f441eb |
+ return 0;
|
|
|
f441eb |
+}
|
|
|
f441eb |
|
|
|
f441eb |
int
|
|
|
f441eb |
adcli_tool_computer_preset (adcli_conn *conn,
|
|
|
f441eb |
diff --git a/tools/tools.c b/tools/tools.c
|
|
|
f441eb |
index 915130e..c4e2851 100644
|
|
|
f441eb |
--- a/tools/tools.c
|
|
|
f441eb |
+++ b/tools/tools.c
|
|
|
f441eb |
@@ -55,6 +55,7 @@ struct {
|
|
|
f441eb |
{ "info", adcli_tool_info, "Print information about a domain", CONNECTION_LESS },
|
|
|
f441eb |
{ "join", adcli_tool_computer_join, "Join this machine to a domain", },
|
|
|
f441eb |
{ "update", adcli_tool_computer_update, "Update machine membership in a domain", },
|
|
|
f441eb |
+ { "testjoin", adcli_tool_computer_testjoin, "Test if machine account password is valid", },
|
|
|
f441eb |
{ "preset-computer", adcli_tool_computer_preset, "Pre setup computers accounts", },
|
|
|
f441eb |
{ "reset-computer", adcli_tool_computer_reset, "Reset a computer account", },
|
|
|
f441eb |
{ "delete-computer", adcli_tool_computer_delete, "Delete a computer account", },
|
|
|
f441eb |
diff --git a/tools/tools.h b/tools/tools.h
|
|
|
f441eb |
index 6c97ccf..8cebbf9 100644
|
|
|
f441eb |
--- a/tools/tools.h
|
|
|
f441eb |
+++ b/tools/tools.h
|
|
|
f441eb |
@@ -70,6 +70,10 @@ int adcli_tool_computer_update (adcli_conn *conn,
|
|
|
f441eb |
int argc,
|
|
|
f441eb |
char *argv[]);
|
|
|
f441eb |
|
|
|
f441eb |
+int adcli_tool_computer_testjoin (adcli_conn *conn,
|
|
|
f441eb |
+ int argc,
|
|
|
f441eb |
+ char *argv[]);
|
|
|
f441eb |
+
|
|
|
f441eb |
int adcli_tool_computer_delete (adcli_conn *conn,
|
|
|
f441eb |
int argc,
|
|
|
f441eb |
char *argv[]);
|
|
|
f441eb |
--
|
|
|
f441eb |
2.20.1
|
|
|
f441eb |
|