net ads join: Add support for specifying the machine account password
authorAndrew Bartlett <abartlet@samba.org>
Thu, 28 Feb 2013 11:59:48 +0000 (22:59 +1100)
committerJeremy Allison <jra@samba.org>
Wed, 6 Mar 2013 22:46:43 +0000 (14:46 -0800)
This allows a predictable password to be specified, just like --machinepass does on samba-tool domain join.

Andrew Bartlett
Reviewed-by: Jeremy Allison <jra@samba.org>
docs-xml/manpages/net.8.xml
source3/utils/net_ads.c

index 01044e104563bc4fe640ae596a7a5d88a56d304f..0cdadea9e215b30154a22f87b3a20b95463f8f9b 100644 (file)
@@ -194,7 +194,8 @@ the remote server using <command>/bin/date</command>. </para>
 </refsect2>
 
 <refsect2>
-<title>[RPC|ADS] JOIN [TYPE] [-U username[%password]] [createupn=UPN] [createcomputer=OU] [options]</title>
+<title>[RPC|ADS] JOIN [TYPE] [-U username[%password]] [createupn=UPN]
+[createcomputer=OU] [machinepass=PASS] [options]</title>
 
 <para>
 Join a domain.  If the account already exists on the server, and 
@@ -220,6 +221,10 @@ a '/'.  Please note that '\' is used for escape by both the shell
 and ldap, so it may need to be doubled or quadrupled to pass through, 
 and it is not used as a delimiter.
 </para>
+<para>
+[PASS] (ADS only) Set a specific password on the computer account
+being created by the join.
+</para>
 </refsect2>
 
 <refsect2>
index 013884d17607ff8db1b0ccd77b086a48c20599d4..569994362d9294cfa015d9f3183a77709b4cba42 100644 (file)
@@ -1315,6 +1315,8 @@ static int net_ads_join_usage(struct net_context *c, int argc, const char **argv
                   "                      E.g. \"createcomputer=Computers/Servers/Unix\"\n"
                   "                      NB: A backslash '\\' is used as escape at multiple levels and may\n"
                   "                          need to be doubled or even quadrupled.  It is not used as a separator.\n"));
+       d_printf(_("   machinepass=PASS   Set the machine password to a specific value during the join.\n"
+                  "                      The deault password is random.\n"));
        d_printf(_("   osName=string      Set the operatingSystem attribute during the join.\n"));
        d_printf(_("   osVer=string       Set the operatingSystemVersion attribute during the join.\n"
                   "                      NB: osName and osVer must be specified together for either to take effect.\n"
@@ -1421,6 +1423,7 @@ int net_ads_join(struct net_context *c, int argc, const char **argv)
        WERROR werr = WERR_SETUP_NOT_JOINED;
        bool createupn = false;
        const char *machineupn = NULL;
+       const char *machine_password = NULL;
        const char *create_in_ou = NULL;
        int i;
        const char *os_name = NULL;
@@ -1482,6 +1485,13 @@ int net_ads_join(struct net_context *c, int argc, const char **argv)
                                goto fail;
                        }
                }
+               else if ( !strncasecmp_m(argv[i], "machinepass", strlen("machinepass")) ) {
+                       if ( (machine_password = get_string_param(argv[i])) == NULL ) {
+                               d_fprintf(stderr, _("Please supply a valid password to set as trust account password.\n"));
+                               werr = WERR_INVALID_PARAM;
+                               goto fail;
+                       }
+               }
                else {
                        domain = argv[i];
                }
@@ -1511,6 +1521,7 @@ int net_ads_join(struct net_context *c, int argc, const char **argv)
        r->in.dc_name           = c->opt_host;
        r->in.admin_account     = c->opt_user_name;
        r->in.admin_password    = net_prompt_pass(c, c->opt_user_name);
+       r->in.machine_password  = machine_password;
        r->in.debug             = true;
        r->in.use_kerberos      = c->opt_kerberos;
        r->in.modify_config     = modify_config;