summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 d12751a16e..99f7b447ec 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 a0d3319998..c6bf3d687a 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,