summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2007-12-19 02:25:15 +0100
committerGünther Deschner <gd@samba.org>2007-12-21 15:29:10 +0100
commitd1548d035f3c296d5044b9aa47fc350cb62e4e2d (patch)
tree519ff4a4e62cc0b30f034f8d6e96e7a2ce335d33
parent8f65326e9993a5caefde89f9a48cd677a9f0cefd (diff)
downloadsamba-d1548d035f3c296d5044b9aa47fc350cb62e4e2d.tar.gz
samba-d1548d035f3c296d5044b9aa47fc350cb62e4e2d.tar.xz
samba-d1548d035f3c296d5044b9aa47fc350cb62e4e2d.zip
Use DsGetDcName in local libnetapi join to find a dc.
Guenther (This used to be commit fbc60c1648ff8b1fa0ae33c09237e41232f9769c)
-rw-r--r--source3/Makefile.in3
-rw-r--r--source3/lib/netapi/joindomain.c34
2 files changed, 22 insertions, 15 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index d12751a16e8..99f7b447ec9 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -715,7 +715,8 @@ LIBNETAPI_OBJ = $(LIBNETAPI_OBJ1) $(LIBNET_OBJ) \
$(PARAM_WITHOUT_REG_OBJ) $(LIB_NONSMBD_OBJ) \
$(LIBSMB_OBJ) $(KRBCLIENT_OBJ) \
$(LIBMSRPC_OBJ) $(LIBMSRPC_GEN_OBJ) $(RPC_PARSE_OBJ) \
- $(SECRETS_OBJ) $(PASSDB_OBJ) $(SMBLDAP_OBJ) $(GROUPDB_OBJ) $(LDB_OBJ)
+ $(SECRETS_OBJ) $(PASSDB_OBJ) $(SMBLDAP_OBJ) $(GROUPDB_OBJ) $(LDB_OBJ) \
+ $(DCUTIL_OBJ) $(LIBADS_OBJ)
LIBNET_OBJ = libnet/libnet_conf.o libnet/libnet_join.o
diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c
index a0d3319998f..c6bf3d687af 100644
--- a/source3/lib/netapi/joindomain.c
+++ b/source3/lib/netapi/joindomain.c
@@ -36,16 +36,31 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx,
werr = libnet_init_JoinCtx(mem_ctx, &r);
W_ERROR_NOT_OK_RETURN(werr);
- if (!server_name || !domain_name) {
+ if (!domain_name) {
return WERR_INVALID_PARAM;
}
- r->in.server_name = talloc_strdup(mem_ctx, server_name);
- W_ERROR_HAVE_NO_MEMORY(r->in.server_name);
-
r->in.domain_name = talloc_strdup(mem_ctx, domain_name);
W_ERROR_HAVE_NO_MEMORY(r->in.domain_name);
+ if (server_name) {
+ r->in.server_name = talloc_strdup(mem_ctx, server_name);
+ W_ERROR_HAVE_NO_MEMORY(r->in.server_name);
+ } else if (join_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) {
+ NTSTATUS status;
+ struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
+ uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED |
+ DS_WRITABLE_REQUIRED |
+ DS_RETURN_DNS_NAME;
+ status = DsGetDcName(mem_ctx, NULL, domain_name,
+ NULL, NULL, flags, &info);
+ if (!NT_STATUS_IS_OK(status)) {
+ return ntstatus_to_werror(status);
+ }
+ r->in.server_name = talloc_strdup(mem_ctx, info->domain_controller_name);
+ W_ERROR_HAVE_NO_MEMORY(r->in.server_name);
+ }
+
if (account_ou) {
r->in.account_ou = talloc_strdup(mem_ctx, account_ou);
W_ERROR_HAVE_NO_MEMORY(r->in.account_ou);
@@ -158,17 +173,8 @@ static WERROR libnetapi_NetJoinDomain(struct libnetapi_ctx *ctx,
if (!server_name || is_myname_or_ipaddr(server_name)) {
- const char *dc = NULL;
-
- /* FIXME: DsGetDcName */
- if (server_name == NULL) {
- dc = domain_name;
- } else {
- dc = domain_name;
- }
-
werr = NetJoinDomainLocal(ctx,
- dc,
+ server_name,
domain_name,
account_ou,
Account,