s3:libads: Add net ads leave keep-account option
authorJustin Stephenson <jstephen@redhat.com>
Wed, 27 Jun 2018 15:32:31 +0000 (11:32 -0400)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 30 Jul 2018 05:34:11 +0000 (07:34 +0200)
Add the ability to leave the domain with --keep-account argument to avoid
removal of the host machine account.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13498

Signed-off-by: Justin Stephenson <jstephen@redhat.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
docs-xml/manpages/net.8.xml
source3/libnet/libnet_join.c
source3/utils/net.c
source3/utils/net.h
source3/utils/net_ads.c

index 3154ee5ff8503673f95dd33ce78e2f74089bda35..d2bcd24c5028cc7e3cd0e24652e4cff76d10c2fd 100644 (file)
                </para></listitem>
                </varlistentry>
 
+               <varlistentry>
+               <term>--keep-account</term>
+               <listitem><para>Prevent the machine account removal as
+               part of "net ads leave".
+               </para></listitem>
+               </varlistentry>
+
                &stdarg.encrypt;
                &popt.common.samba.client;
 
@@ -1276,7 +1283,7 @@ against an NT4 Domain Controller.
 </refsect2>
 
 <refsect2>
-<title>ADS LEAVE</title>
+<title>ADS LEAVE [--keep-account]</title>
 
 <para>Make the remote host leave the domain it is part of. </para>
 
index a9405e8d288a15321ee54c195a19d89a5771eafc..27fc5135442cf47bb36ad7e64bc8e24cc3b6acf9 100644 (file)
@@ -2868,6 +2868,8 @@ static WERROR libnet_DomainUnjoin(TALLOC_CTX *mem_ctx,
                        return ntstatus_to_werror(status);
                }
 
+               r->out.dns_domain_name = talloc_strdup(mem_ctx,
+                                                     r->in.domain_name);
                r->out.disabled_machine_account = true;
        }
 
index 44daa6088ca6ba8c5abc2255ab08ca69fbe2e0a4..69564f65232e8943b20b54e4ffe7a8761b5a6b2b 100644 (file)
@@ -971,8 +971,9 @@ static struct functable net_func[] = {
                {"wipe", 0, POPT_ARG_NONE, &c->opt_wipe},
                /* Options for 'net registry import' */
                {"precheck", 0, POPT_ARG_STRING, &c->opt_precheck},
-               /* Options for 'net ads join' */
+               /* Options for 'net ads join or leave' */
                {"no-dns-updates", 0, POPT_ARG_NONE, &c->opt_no_dns_updates},
+               {"keep-account", 0, POPT_ARG_NONE, &c->opt_keep_account},
                POPT_COMMON_SAMBA
                { 0, 0, 0, 0}
        };
index d6dfeb6208f86cb5c17632687108bcbe5db63819..5e70fd3aafadfedb1cf1557434d49847d43cc0c7 100644 (file)
@@ -85,6 +85,7 @@ struct net_context {
        int opt_wipe;
        const char *opt_precheck;
        int opt_no_dns_updates;
+       int opt_keep_account;
 
        int opt_have_ip;
        struct sockaddr_storage opt_dest_ip;
index ffa67d8f5254aadc96c85b147146b3a8ee72a633..afe47dad83965d7848d36ab2950a9f0e3ce8d7cb 100644 (file)
@@ -964,7 +964,7 @@ static int net_ads_leave(struct net_context *c, int argc, const char **argv)
 
        if (c->display_usage) {
                d_printf(  "%s\n"
-                          "net ads leave\n"
+                          "net ads leave [--keep-account]\n"
                           "    %s\n",
                         _("Usage:"),
                         _("Leave an AD domain"));
@@ -1009,7 +1009,12 @@ static int net_ads_leave(struct net_context *c, int argc, const char **argv)
           WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE really means "disable */
        r->in.unjoin_flags      = WKSSVC_JOIN_FLAGS_JOIN_TYPE |
                                  WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE;
-       r->in.delete_machine_account = true;
+       if (c->opt_keep_account) {
+               r->in.delete_machine_account = false;
+       } else {
+               r->in.delete_machine_account = true;
+       }
+
        r->in.msg_ctx           = c->msg_ctx;
 
        werr = libnet_Unjoin(ctx, r);