summaryrefslogtreecommitdiff
path: root/source3/libnet
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2008-01-15 10:19:47 -0800
committerJeremy Allison <jra@samba.org>2008-01-15 10:19:47 -0800
commit9c63e1820bab51a7cc09878d78ddce061c3292ec (patch)
tree9e88fcb9ad8012e26c1e70b9e0a07b1f23f9e39f /source3/libnet
parent19e4e99bfb02b8fa722883b04237ad714d402cb3 (diff)
parentee8cf0ce40820b3e1ec025339f2b25c0001fda13 (diff)
downloadsamba-9c63e1820bab51a7cc09878d78ddce061c3292ec.tar.gz
samba-9c63e1820bab51a7cc09878d78ddce061c3292ec.tar.bz2
samba-9c63e1820bab51a7cc09878d78ddce061c3292ec.zip
Merge branch 'v3-2-test' of ssh://jra@git.samba.org/data/git/samba into v3-2-test
(This used to be commit 6e17a56039be13ac1ef7004f15d154141bad7196)
Diffstat (limited to 'source3/libnet')
-rw-r--r--source3/libnet/libnet.h2
-rw-r--r--source3/libnet/libnet_join.c146
-rw-r--r--source3/libnet/libnet_join.h75
3 files changed, 121 insertions, 102 deletions
diff --git a/source3/libnet/libnet.h b/source3/libnet/libnet.h
index d6238ca982..97e720f617 100644
--- a/source3/libnet/libnet.h
+++ b/source3/libnet/libnet.h
@@ -20,7 +20,7 @@
#ifndef __LIBNET_H__
#define __LIBNET_H__
-#include "libnet/libnet_join.h"
+#include "librpc/gen_ndr/libnet_join.h"
#include "libnet/libnet_conf.h"
#include "libnet/libnet_proto.h"
diff --git a/source3/libnet/libnet_join.c b/source3/libnet/libnet_join.c
index eaf851ccec..a189a38ea3 100644
--- a/source3/libnet/libnet_join.c
+++ b/source3/libnet/libnet_join.c
@@ -107,10 +107,6 @@ static ADS_STATUS libnet_join_connect_ads(TALLOC_CTX *mem_ctx,
{
ADS_STATUS status;
- if (r->in.ads) {
- ads_destroy(&r->in.ads);
- }
-
status = libnet_connect_ads(r->in.domain_name,
r->in.domain_name,
r->in.dc_name,
@@ -134,10 +130,6 @@ static ADS_STATUS libnet_unjoin_connect_ads(TALLOC_CTX *mem_ctx,
{
ADS_STATUS status;
- if (r->in.ads) {
- ads_destroy(&r->in.ads);
- }
-
status = libnet_connect_ads(r->in.domain_name,
r->in.domain_name,
r->in.dc_name,
@@ -244,7 +236,6 @@ static ADS_STATUS libnet_join_find_machine_acct(TALLOC_CTX *mem_ctx,
goto done;
}
- TALLOC_FREE(r->out.dn);
r->out.dn = talloc_strdup(mem_ctx, dn);
if (!r->out.dn) {
status = ADS_ERROR_LDAP(LDAP_NO_MEMORY);
@@ -1013,6 +1004,58 @@ static WERROR do_UnjoinConfig(struct libnet_UnjoinCtx *r)
/****************************************************************
****************************************************************/
+static WERROR libnet_join_pre_processing(TALLOC_CTX *mem_ctx,
+ struct libnet_JoinCtx *r)
+{
+
+ if (!r->in.domain_name) {
+ return WERR_INVALID_PARAM;
+ }
+
+ if (r->in.modify_config && !lp_include_registry_globals()) {
+ return WERR_NOT_SUPPORTED;
+ }
+
+ if (IS_DC) {
+ return WERR_SETUP_DOMAIN_CONTROLLER;
+ }
+
+ if (!secrets_init()) {
+ libnet_join_set_error_string(mem_ctx, r,
+ "Unable to open secrets database");
+ return WERR_CAN_NOT_COMPLETE;
+ }
+
+ return WERR_OK;
+}
+
+/****************************************************************
+****************************************************************/
+
+static WERROR libnet_join_post_processing(TALLOC_CTX *mem_ctx,
+ struct libnet_JoinCtx *r)
+{
+ WERROR werr;
+
+ if (!W_ERROR_IS_OK(r->out.result)) {
+ return r->out.result;
+ }
+
+ werr = do_JoinConfig(r);
+ if (!W_ERROR_IS_OK(werr)) {
+ return werr;
+ }
+
+ if (r->in.join_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) {
+ saf_store(r->in.domain_name, r->in.dc_name);
+ }
+
+ return WERR_OK;
+}
+
+/****************************************************************
+****************************************************************/
+
static int libnet_destroy_JoinCtx(struct libnet_JoinCtx *r)
{
if (r->in.ads) {
@@ -1170,30 +1213,30 @@ WERROR libnet_Join(TALLOC_CTX *mem_ctx,
{
WERROR werr;
- if (!r->in.domain_name) {
- return WERR_INVALID_PARAM;
+ if (r->in.debug) {
+ NDR_PRINT_IN_DEBUG(libnet_JoinCtx, r);
}
- if (r->in.modify_config && !lp_include_registry_globals()) {
- return WERR_NOT_SUPPORTED;
- }
-
- if (IS_DC) {
- return WERR_SETUP_DOMAIN_CONTROLLER;
+ werr = libnet_join_pre_processing(mem_ctx, r);
+ if (!W_ERROR_IS_OK(werr)) {
+ goto done;
}
if (r->in.join_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) {
werr = libnet_DomainJoin(mem_ctx, r);
if (!W_ERROR_IS_OK(werr)) {
- return werr;
+ goto done;
}
}
- werr = do_JoinConfig(r);
+ werr = libnet_join_post_processing(mem_ctx, r);
if (!W_ERROR_IS_OK(werr)) {
- return werr;
+ goto done;
+ }
+ done:
+ if (r->in.debug) {
+ NDR_PRINT_OUT_DEBUG(libnet_JoinCtx, r);
}
-
return werr;
}
@@ -1205,6 +1248,29 @@ static WERROR libnet_DomainUnjoin(TALLOC_CTX *mem_ctx,
{
NTSTATUS status;
+ if (!r->in.dc_name) {
+ struct DS_DOMAIN_CONTROLLER_INFO *info;
+ status = dsgetdcname(mem_ctx,
+ NULL,
+ r->in.domain_name,
+ NULL,
+ NULL,
+ DS_DIRECTORY_SERVICE_REQUIRED |
+ DS_WRITABLE_REQUIRED |
+ DS_RETURN_DNS_NAME,
+ &info);
+ if (!NT_STATUS_IS_OK(status)) {
+ libnet_unjoin_set_error_string(mem_ctx, r,
+ "failed to find DC: %s",
+ nt_errstr(status));
+ return WERR_DOMAIN_CONTROLLER_NOT_FOUND;
+ }
+
+ r->in.dc_name = talloc_strdup(mem_ctx,
+ info->domain_controller_name);
+ W_ERROR_HAVE_NO_MEMORY(r->in.dc_name);
+ }
+
status = libnet_join_unjoindomain_rpc(mem_ctx, r);
if (!NT_STATUS_IS_OK(status)) {
libnet_unjoin_set_error_string(mem_ctx, r,
@@ -1237,26 +1303,54 @@ static WERROR libnet_DomainUnjoin(TALLOC_CTX *mem_ctx,
/****************************************************************
****************************************************************/
+static WERROR libnet_unjoin_pre_processing(TALLOC_CTX *mem_ctx,
+ struct libnet_UnjoinCtx *r)
+{
+ if (r->in.modify_config && !lp_include_registry_globals()) {
+ return WERR_NOT_SUPPORTED;
+ }
+
+ if (!secrets_init()) {
+ libnet_unjoin_set_error_string(mem_ctx, r,
+ "Unable to open secrets database");
+ return WERR_CAN_NOT_COMPLETE;
+ }
+
+ return WERR_OK;
+}
+
+/****************************************************************
+****************************************************************/
+
WERROR libnet_Unjoin(TALLOC_CTX *mem_ctx,
struct libnet_UnjoinCtx *r)
{
WERROR werr;
- if (r->in.modify_config && !lp_include_registry_globals()) {
- return WERR_NOT_SUPPORTED;
+ if (r->in.debug) {
+ NDR_PRINT_IN_DEBUG(libnet_UnjoinCtx, r);
+ }
+
+ werr = libnet_unjoin_pre_processing(mem_ctx, r);
+ if (!W_ERROR_IS_OK(werr)) {
+ goto done;
}
if (r->in.unjoin_flags & WKSSVC_JOIN_FLAGS_JOIN_TYPE) {
werr = libnet_DomainUnjoin(mem_ctx, r);
if (!W_ERROR_IS_OK(werr)) {
- do_UnjoinConfig(r);
- return werr;
+ goto done;
}
}
werr = do_UnjoinConfig(r);
if (!W_ERROR_IS_OK(werr)) {
- return werr;
+ goto done;
+ }
+
+ done:
+ if (r->in.debug) {
+ NDR_PRINT_OUT_DEBUG(libnet_UnjoinCtx, r);
}
return werr;
diff --git a/source3/libnet/libnet_join.h b/source3/libnet/libnet_join.h
deleted file mode 100644
index c47e8d934c..0000000000
--- a/source3/libnet/libnet_join.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Unix SMB/CIFS implementation.
- * libnet Join Support
- * Copyright (C) Guenther Deschner 2007-2008
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __LIBNET_JOIN_H__
-#define __LIBNET_JOIN_H__
-
-struct libnet_JoinCtx {
- struct {
- const char *dc_name;
- const char *machine_name;
- const char *domain_name;
- const char *account_ou;
- const char *admin_account;
- const char *admin_password;
- const char *machine_password;
- uint32_t join_flags;
- const char *os_version;
- const char *os_name;
- bool create_upn;
- const char *upn;
- bool modify_config;
- struct ads_struct *ads;
- bool debug;
- } in;
-
- struct {
- char *account_name;
- char *netbios_domain_name;
- char *dns_domain_name;
- char *dn;
- struct dom_sid *domain_sid;
- bool modified_config;
- WERROR result;
- char *error_string;
- bool domain_is_ad;
- } out;
-};
-
-struct libnet_UnjoinCtx {
- struct {
- const char *dc_name;
- const char *machine_name;
- const char *domain_name;
- const char *admin_account;
- const char *admin_password;
- uint32_t unjoin_flags;
- bool modify_config;
- struct dom_sid *domain_sid;
- struct ads_struct *ads;
- } in;
-
- struct {
- bool modified_config;
- WERROR result;
- char *error_string;
- } out;
-};
-
-#endif