]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:utils: let net_rpc_testjoin() work for ad domains and no ipv4 address
authorStefan Metzmacher <metze@samba.org>
Fri, 11 Oct 2024 13:38:07 +0000 (13:38 +0000)
committerStefan Metzmacher <metze@samba.org>
Thu, 5 Dec 2024 16:46:37 +0000 (16:46 +0000)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/utils/net_rpc.c

index 4e4de84b6e390b469ffd67d7e6fc4ba9aba93a39..384c2218d4395aba7b6592f1d643ab43b613060b 100644 (file)
@@ -502,6 +502,7 @@ int net_rpc_testjoin(struct net_context *c, int argc, const char **argv)
 
        if (!dc) {
                struct netr_DsRGetDCNameInfo *info;
+               uint32_t flags = DS_RETURN_DNS_NAME;
 
                if (!c->msg_ctx) {
                        d_fprintf(stderr, _("Could not initialise message context. "
@@ -510,13 +511,31 @@ int net_rpc_testjoin(struct net_context *c, int argc, const char **argv)
                        return -1;
                }
 
+               if (strequal(domain, lp_workgroup())) {
+                       flags |= DS_IS_FLAT_NAME;
+               }
+
                status = dsgetdcname(mem_ctx,
                                     c->msg_ctx,
                                     domain,
                                     NULL,
                                     NULL,
-                                    DS_RETURN_DNS_NAME,
+                                    flags,
                                     &info);
+               if (NT_STATUS_EQUAL(status, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND) &&
+                   strequal(domain, lp_workgroup()) &&
+                   lp_realm() != NULL)
+               {
+                       flags &= ~DS_IS_FLAT_NAME;
+                       flags |= DS_IS_DNS_NAME;
+                       status = dsgetdcname(mem_ctx,
+                                            c->msg_ctx,
+                                            lp_realm(),
+                                            NULL,
+                                            NULL,
+                                            flags,
+                                            &info);
+               }
                if (!NT_STATUS_IS_OK(status)) {
                        talloc_destroy(mem_ctx);
                        return -1;