From: Isaac Boukris Date: Wed, 27 May 2020 13:54:12 +0000 (+0200) Subject: Add net-ads-join dnshostname=fqdn option X-Git-Tag: ldb-2.2.0~249 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce0e96e6f48e059b1ceeacaa10de7cab54a466af;p=thirdparty%2Fsamba.git Add net-ads-join dnshostname=fqdn option BUG: https://bugzilla.samba.org/show_bug.cgi?id=14396 Signed-off-by: Isaac Boukris Reviewed-by: Andreas Schneider Autobuild-User(master): Andreas Schneider Autobuild-Date(master): Fri May 29 13:33:28 UTC 2020 on sn-devel-184 --- diff --git a/docs-xml/manpages/net.8.xml b/docs-xml/manpages/net.8.xml index 37dd30b7864..cbab9c63a5e 100644 --- a/docs-xml/manpages/net.8.xml +++ b/docs-xml/manpages/net.8.xml @@ -481,7 +481,7 @@ The remote server must be specified with the -S option. [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] @@ -496,6 +496,11 @@ be created. joining the domain. + +[FQDN] (ADS only) set the dnsHosName attribute during the join. +The default format is netbiosname.dnsdomain. + + [UPN] (ADS only) set the principalname attribute during the join. The default format is host/netbiosname@REALM. diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c index 78e0612eb0f..34938603606 100644 --- a/source3/libnet/libnet_join.c +++ b/source3/libnet/libnet_join.c @@ -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); diff --git a/source3/librpc/idl/libnet_join.idl b/source3/librpc/idl/libnet_join.idl index e45034d40da..03d919863b5 100644 --- a/source3/librpc/idl/libnet_join.idl +++ b/source3/librpc/idl/libnet_join.idl @@ -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, diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index 9d9bc5f7982..d4bf5fa12b3 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -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; iin.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; diff --git a/testprogs/blackbox/test_net_ads.sh b/testprogs/blackbox/test_net_ads.sh index a40b477a173..85257f445d8 100755 --- a/testprogs/blackbox/test_net_ads.sh +++ b/testprogs/blackbox/test_net_ads.sh @@ -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