Add net-ads-join dnshostname=fqdn option
authorIsaac Boukris <iboukris@gmail.com>
Wed, 27 May 2020 13:54:12 +0000 (15:54 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 29 May 2020 13:33:28 +0000 (13:33 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14396

Signed-off-by: Isaac Boukris <iboukris@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Fri May 29 13:33:28 UTC 2020 on sn-devel-184

docs-xml/manpages/net.8.xml
source3/libnet/libnet_join.c
source3/librpc/idl/libnet_join.idl
source3/utils/net_ads.c
testprogs/blackbox/test_net_ads.sh

index 37dd30b7864282e6ff34bf4018dfe629fb02f2ae..cbab9c63a5e60af6e9f866ccc3602d1a89f69ba2 100644 (file)
@@ -481,7 +481,7 @@ The remote server must be specified with the -S option.
 
 <refsect2>
 <title>[RPC|ADS] JOIN [TYPE] [--no-dns-updates] [-U username[%password]]
-[createupn=UPN] [createcomputer=OU] [machinepass=PASS]
+[dnshostname=FQDN] [createupn=UPN] [createcomputer=OU] [machinepass=PASS]
 [osName=string osVer=string] [options]</title>
 
 <para>
@@ -496,6 +496,11 @@ be created.</para>
 joining the domain.
 </para>
 
+<para>
+[FQDN] (ADS only) set the dnsHosName attribute during the join.
+The default format is netbiosname.dnsdomain.
+</para>
+
 <para>
 [UPN] (ADS only) set the principalname attribute during the join.  The default
 format is host/netbiosname@REALM.
index 78e0612eb0fb8e12cb6f93be71c7d4284ecbd9eb..349386036065a05a200908082419362c650394cb 100644 (file)
@@ -546,7 +546,12 @@ static ADS_STATUS libnet_join_set_machine_spn(TALLOC_CTX *mem_ctx,
                goto done;
        }
 
-       fstr_sprintf(my_fqdn, "%s.%s", r->in.machine_name, lp_dnsdomain());
+       if (r->in.dnshostname != NULL) {
+               fstr_sprintf(my_fqdn, "%s", r->in.dnshostname);
+       } else {
+               fstr_sprintf(my_fqdn, "%s.%s", r->in.machine_name,
+                            lp_dnsdomain());
+       }
 
        if (!strlower_m(my_fqdn)) {
                status = ADS_ERROR_LDAP(LDAP_NO_MEMORY);
index e45034d40dae25a422bd211d2ea831a13267c336..03d919863b5b8261c37ff8ddf3deae1080b4b47e 100644 (file)
@@ -37,6 +37,7 @@ interface libnetjoin
                [in] string os_servicepack,
                [in] boolean8 create_upn,
                [in] string upn,
+               [in] string dnshostname,
                [in] boolean8 modify_config,
                [in,unique] ads_struct *ads,
                [in] boolean8 debug,
index 9d9bc5f7982296ca43839c13ac022883b0cd1b05..d4bf5fa12b386b1c35081c8b146a0b09c53fb2ff 100644 (file)
@@ -1711,6 +1711,8 @@ static int net_ads_join_usage(struct net_context *c, int argc, const char **argv
 {
        d_printf(_("net ads join [--no-dns-updates] [options]\n"
                   "Valid options:\n"));
+       d_printf(_("   dnshostname=FQDN      Set the dnsHostName attribute during the join.\n"
+                  "                         The default is in the form netbiosname.dnsdomain\n"));
        d_printf(_("   createupn[=UPN]       Set the userPrincipalName attribute during the join.\n"
                   "                         The default UPN is in the form host/netbiosname@REALM.\n"));
        d_printf(_("   createcomputer=OU     Precreate the computer account in a specific OU.\n"
@@ -1831,6 +1833,7 @@ int net_ads_join(struct net_context *c, int argc, const char **argv)
        const char *domain = lp_realm();
        WERROR werr = WERR_NERR_SETUPNOTJOINED;
        bool createupn = false;
+       const char *dnshostname = NULL;
        const char *machineupn = NULL;
        const char *machine_password = NULL;
        const char *create_in_ou = NULL;
@@ -1871,7 +1874,10 @@ int net_ads_join(struct net_context *c, int argc, const char **argv)
        /* process additional command line args */
 
        for ( i=0; i<argc; i++ ) {
-               if ( !strncasecmp_m(argv[i], "createupn", strlen("createupn")) ) {
+               if ( !strncasecmp_m(argv[i], "dnshostname", strlen("dnshostname")) ) {
+                       dnshostname = get_string_param(argv[i]);
+               }
+               else if ( !strncasecmp_m(argv[i], "createupn", strlen("createupn")) ) {
                        createupn = true;
                        machineupn = get_string_param(argv[i]);
                }
@@ -1939,6 +1945,7 @@ int net_ads_join(struct net_context *c, int argc, const char **argv)
        r->in.domain_name_type  = domain_name_type;
        r->in.create_upn        = createupn;
        r->in.upn               = machineupn;
+       r->in.dnshostname       = dnshostname;
        r->in.account_ou        = create_in_ou;
        r->in.os_name           = os_name;
        r->in.os_version        = os_version;
index a40b477a1739f30edd6257db2f748b1f20cf095a..85257f445d806171700dca67e5d4da2570036f46 100755 (executable)
@@ -277,6 +277,21 @@ rm -f $dedicated_keytab_file
 
 testit "leave+createupn" $VALGRIND $net_tool ads leave -U$DC_USERNAME%$DC_PASSWORD || failed=`expr $failed + 1`
 
+#
+# Test dnshostname option of 'net ads join'
+#
+testit "join+dnshostname" $VALGRIND $net_tool ads join -U$DC_USERNAME%$DC_PASSWORD dnshostname="alt.hostname.$HOSTNAME" || failed=`expr $failed + 1`
+
+testit_grep "check dnshostname opt" "dNSHostName: alt.hostname.$HOSTNAME" $ldbsearch -U$DC_USERNAME%$DC_PASSWORD -H ldap://$SERVER.$REALM -s base -b "CN=$HOSTNAME,CN=Computers,$base_dn" || failed=`expr $failed + 1`
+
+testit "create_keytab+dnshostname" $VALGRIND $net_tool ads keytab create --option="kerberosmethod=dedicatedkeytab" --option="dedicatedkeytabfile=$dedicated_keytab_file" || failed=`expr $failed + 1`
+
+testit_grep "check dnshostname+keytab" "host/alt.hostname.$HOSTNAME@$REALM" $net_tool ads keytab list --option="kerberosmethod=dedicatedkeytab" --option="dedicatedkeytabfile=$dedicated_keytab_file" || failed=`expr $failed + 1`
+
+rm -f $dedicated_keytab_file
+
+testit "leave+dnshostname" $VALGRIND $net_tool ads leave -U$DC_USERNAME%$DC_PASSWORD || failed=`expr $failed + 1`
+
 rm -rf $BASEDIR/$WORKDIR
 
 exit $failed