[SCM] Samba Shared Repository - branch v3-2-test updated - initial-v3-2-unstable-1151-gf550ed0

Günther Deschner gd at samba.org
Mon Jan 7 18:42:41 GMT 2008


The branch, v3-2-test has been updated
       via  f550ed02ff9e0546c63064ab9dac760eac7e1e16 (commit)
       via  ed164b523e63c3ebf2c822a00a877ef169738a3a (commit)
       via  18ae8580420c37aa4b189eb5ce53cc65a9827d95 (commit)
       via  985d45206990988894e05ea6fb0aacc7396a6db4 (commit)
       via  4f9985bb33aa5973e6b685a45039c8e227487db1 (commit)
       via  89669c66f27fb47c9769d1058e29bff83f862752 (commit)
       via  5abae9ef15fa9884c5c4a0e256274f70f6ecd779 (commit)
       via  e7258a4408e40686ff090d0f8e120ce78acbd097 (commit)
       via  a72ad63163a8c642ea762087a739e6d63c37647a (commit)
      from  195c519377c2fdc655e25760b52bc0694b8dda81 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit f550ed02ff9e0546c63064ab9dac760eac7e1e16
Author: Günther Deschner <gd at samba.org>
Date:   Mon Jan 7 19:31:20 2008 +0100

    Add libnet_join_find_machine_acct().
    
    Guenther

commit ed164b523e63c3ebf2c822a00a877ef169738a3a
Author: Günther Deschner <gd at samba.org>
Date:   Mon Jan 7 19:11:26 2008 +0100

    Honor the WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE flag when unjoining from AD.
    
    Guenther

commit 18ae8580420c37aa4b189eb5ce53cc65a9827d95
Author: Günther Deschner <gd at samba.org>
Date:   Mon Jan 7 19:07:38 2008 +0100

    Rearrange libnet join code and add support for account pre-creation in AD.
    
    Guenther

commit 985d45206990988894e05ea6fb0aacc7396a6db4
Author: Günther Deschner <gd at samba.org>
Date:   Mon Jan 7 18:58:04 2008 +0100

    Add ADS_STRUCTs to libnetjoin and -unjoin, with talloc destructors.
    
    Guenther

commit 4f9985bb33aa5973e6b685a45039c8e227487db1
Author: Günther Deschner <gd at samba.org>
Date:   Mon Jan 7 18:46:07 2008 +0100

    Add error_string to libnetjoin and libnetunjoin structures incl. set functions.
    
    Guenther

commit 89669c66f27fb47c9769d1058e29bff83f862752
Author: Günther Deschner <gd at samba.org>
Date:   Mon Jan 7 18:41:49 2008 +0100

    Rearrange order of libnet join context init.
    
    Guenther

commit 5abae9ef15fa9884c5c4a0e256274f70f6ecd779
Author: Günther Deschner <gd at samba.org>
Date:   Mon Jan 7 18:40:25 2008 +0100

    Free libnet_JoinCtx after joining.
    
    Guenther

commit e7258a4408e40686ff090d0f8e120ce78acbd097
Author: Günther Deschner <gd at samba.org>
Date:   Mon Jan 7 18:37:04 2008 +0100

    Close registry in libnetapi_free().
    
    Guenther

commit a72ad63163a8c642ea762087a739e6d63c37647a
Author: Günther Deschner <gd at samba.org>
Date:   Mon Jan 7 18:36:06 2008 +0100

    Add NET_API_STATUS_SUCCESS define.
    
    Guenther

-----------------------------------------------------------------------

Summary of changes:
 source/lib/netapi/joindomain.c |   11 +-
 source/lib/netapi/netapi.c     |   19 +-
 source/lib/netapi/netapi.h     |    6 +-
 source/libnet/libnet_join.c    |  397 +++++++++++++++++++++++++++++++++++++---
 source/libnet/libnet_join.h    |    5 +
 5 files changed, 402 insertions(+), 36 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/lib/netapi/joindomain.c b/source/lib/netapi/joindomain.c
index c7849c9..ceb7ca1 100644
--- a/source/lib/netapi/joindomain.c
+++ b/source/lib/netapi/joindomain.c
@@ -33,13 +33,13 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx,
 	struct libnet_JoinCtx *r = NULL;
 	WERROR werr;
 
-	werr = libnet_init_JoinCtx(mem_ctx, &r);
-	W_ERROR_NOT_OK_RETURN(werr);
-
 	if (!domain_name) {
 		return WERR_INVALID_PARAM;
 	}
 
+	werr = libnet_init_JoinCtx(mem_ctx, &r);
+	W_ERROR_NOT_OK_RETURN(werr);
+
 	r->in.domain_name = talloc_strdup(mem_ctx, domain_name);
 	W_ERROR_HAVE_NO_MEMORY(r->in.domain_name);
 
@@ -77,7 +77,10 @@ static WERROR NetJoinDomainLocal(struct libnetapi_ctx *mem_ctx,
 	r->in.join_flags = join_flags;
 	r->in.modify_config = true;
 
-	return libnet_Join(mem_ctx, r);
+	werr = libnet_Join(mem_ctx, r);
+	TALLOC_FREE(r);
+
+	return werr;
 }
 
 static WERROR NetJoinDomainRemote(struct libnetapi_ctx *ctx,
diff --git a/source/lib/netapi/netapi.c b/source/lib/netapi/netapi.c
index 9c418f2..33ca67e 100644
--- a/source/lib/netapi/netapi.c
+++ b/source/lib/netapi/netapi.c
@@ -32,7 +32,7 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context)
 
 	if (stat_ctx && libnetapi_initialized) {
 		*context = stat_ctx;
-		return W_ERROR_V(WERR_OK);
+		return NET_API_STATUS_SUCCESS;
 	}
 
 	frame = talloc_stackframe();
@@ -69,14 +69,14 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context)
 
 	*context = stat_ctx = ctx;
 
-	return W_ERROR_V(WERR_OK);
+	return NET_API_STATUS_SUCCESS;
 }
 
 NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx)
 {
 	if (stat_ctx) {
 		*ctx = stat_ctx;
-		return W_ERROR_V(WERR_OK);
+		return NET_API_STATUS_SUCCESS;
 	}
 
 	return libnetapi_init(ctx);
@@ -92,13 +92,14 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx)
 
 	gencache_shutdown();
 	secrets_shutdown();
+	regdb_close();
 
 	TALLOC_FREE(ctx);
 	TALLOC_FREE(frame);
 
 	gfree_debugsyms();
 
-	return W_ERROR_V(WERR_OK);
+	return NET_API_STATUS_SUCCESS;
 }
 
 NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx,
@@ -109,14 +110,14 @@ NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx,
 	if (!debug_parse_levels(debuglevel)) {
 		return W_ERROR_V(WERR_GENERAL_FAILURE);
 	}
-	return W_ERROR_V(WERR_OK);
+	return NET_API_STATUS_SUCCESS;
 }
 
 NET_API_STATUS libnetapi_get_debuglevel(struct libnetapi_ctx *ctx,
 					const char **debuglevel)
 {
 	*debuglevel = ctx->debuglevel;
-	return W_ERROR_V(WERR_OK);
+	return NET_API_STATUS_SUCCESS;
 }
 
 NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx,
@@ -127,7 +128,7 @@ NET_API_STATUS libnetapi_set_username(struct libnetapi_ctx *ctx,
 	if (!ctx->username) {
 		return W_ERROR_V(WERR_NOMEM);
 	}
-	return W_ERROR_V(WERR_OK);
+	return NET_API_STATUS_SUCCESS;
 }
 
 NET_API_STATUS libnetapi_set_password(struct libnetapi_ctx *ctx,
@@ -138,7 +139,7 @@ NET_API_STATUS libnetapi_set_password(struct libnetapi_ctx *ctx,
 	if (!ctx->password) {
 		return W_ERROR_V(WERR_NOMEM);
 	}
-	return W_ERROR_V(WERR_OK);
+	return NET_API_STATUS_SUCCESS;
 }
 
 NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx,
@@ -149,7 +150,7 @@ NET_API_STATUS libnetapi_set_workgroup(struct libnetapi_ctx *ctx,
 	if (!ctx->workgroup) {
 		return W_ERROR_V(WERR_NOMEM);
 	}
-	return W_ERROR_V(WERR_OK);
+	return NET_API_STATUS_SUCCESS;
 }
 
 const char *libnetapi_errstr(struct libnetapi_ctx *ctx,
diff --git a/source/lib/netapi/netapi.h b/source/lib/netapi/netapi.h
index 0dd6d95..2c6e126 100644
--- a/source/lib/netapi/netapi.h
+++ b/source/lib/netapi/netapi.h
@@ -1,7 +1,7 @@
 /*
  *  Unix SMB/CIFS implementation.
  *  NetApi Support
- *  Copyright (C) Guenther Deschner 2007
+ *  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
@@ -21,6 +21,10 @@
 #define __LIB_NETAPI_H__
 
 #define NET_API_STATUS uint32_t
+#define NET_API_STATUS_SUCCESS 0
+
+/****************************************************************
+****************************************************************/
 
 struct libnetapi_ctx {
 	const char *debuglevel;
diff --git a/source/libnet/libnet_join.c b/source/libnet/libnet_join.c
index 36d5c0a..bc775a9 100644
--- a/source/libnet/libnet_join.c
+++ b/source/libnet/libnet_join.c
@@ -22,6 +22,236 @@
 #include "libnet/libnet_join.h"
 #include "libnet/libnet_proto.h"
 
+/****************************************************************
+****************************************************************/
+
+static void libnet_join_set_error_string(TALLOC_CTX *mem_ctx,
+					 struct libnet_JoinCtx *r,
+					 const char *format, ...)
+{
+	va_list args;
+	char *tmp = NULL;
+
+	va_start(args, format);
+	tmp = talloc_vasprintf(mem_ctx, format, args);
+	va_end(args);
+
+	TALLOC_FREE(r->out.error_string);
+	r->out.error_string = tmp;
+}
+
+/****************************************************************
+****************************************************************/
+
+static void libnet_unjoin_set_error_string(TALLOC_CTX *mem_ctx,
+					   struct libnet_UnjoinCtx *r,
+					   const char *format, ...)
+{
+	va_list args;
+	char *tmp = NULL;
+
+	va_start(args, format);
+	tmp = talloc_vasprintf(mem_ctx, format, args);
+	va_end(args);
+
+	TALLOC_FREE(r->out.error_string);
+	r->out.error_string = tmp;
+}
+
+/****************************************************************
+****************************************************************/
+
+static ADS_STATUS libnet_connect_ads(const char *dns_domain_name,
+				     const char *netbios_domain_name,
+				     const char *dc_name,
+				     const char *user_name,
+				     const char *password,
+				     ADS_STRUCT **ads)
+{
+	ADS_STATUS status;
+	ADS_STRUCT *my_ads = NULL;
+
+	my_ads = ads_init(dns_domain_name,
+			  netbios_domain_name,
+			  dc_name);
+	if (!my_ads) {
+		return ADS_ERROR_LDAP(LDAP_NO_MEMORY);
+	}
+
+	if (user_name) {
+		SAFE_FREE(my_ads->auth.user_name);
+		my_ads->auth.user_name = SMB_STRDUP(user_name);
+	}
+
+	if (password) {
+		SAFE_FREE(my_ads->auth.password);
+		my_ads->auth.password = SMB_STRDUP(password);
+	}
+
+	status = ads_connect(my_ads);
+	if (!ADS_ERR_OK(status)) {
+		ads_destroy(&my_ads);
+		return status;
+	}
+
+	*ads = my_ads;
+	return ADS_SUCCESS;
+}
+
+/****************************************************************
+****************************************************************/
+
+static ADS_STATUS libnet_join_connect_ads(TALLOC_CTX *mem_ctx,
+					  struct libnet_JoinCtx *r)
+{
+	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,
+				    r->in.admin_account,
+				    r->in.admin_password,
+				    &r->in.ads);
+	if (!ADS_ERR_OK(status)) {
+		libnet_join_set_error_string(mem_ctx, r,
+			"failed to connect to AD: %s\n",
+			ads_errstr(status));
+	}
+
+	return status;
+}
+
+/****************************************************************
+****************************************************************/
+
+static ADS_STATUS libnet_unjoin_connect_ads(TALLOC_CTX *mem_ctx,
+					    struct libnet_UnjoinCtx *r)
+{
+	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,
+				    r->in.admin_account,
+				    r->in.admin_password,
+				    &r->in.ads);
+	if (!ADS_ERR_OK(status)) {
+		libnet_unjoin_set_error_string(mem_ctx, r,
+			"failed to connect to AD: %s\n",
+			ads_errstr(status));
+	}
+
+	return status;
+}
+
+/****************************************************************
+****************************************************************/
+
+static ADS_STATUS libnet_join_precreate_machine_acct(TALLOC_CTX *mem_ctx,
+						     struct libnet_JoinCtx *r)
+{
+	ADS_STATUS status;
+	LDAPMessage *res = NULL;
+	const char *attrs[] = { "dn", NULL };
+
+	status = ads_search_dn(r->in.ads, &res, r->in.account_ou, attrs);
+	if (!ADS_ERR_OK(status)) {
+		return status;
+	}
+
+	if (ads_count_replies(r->in.ads, res) != 1) {
+		ads_msgfree(r->in.ads, res);
+		return ADS_ERROR_LDAP(LDAP_NO_SUCH_OBJECT);
+	}
+
+	status = ads_create_machine_acct(r->in.ads,
+					 r->in.machine_name,
+					 r->in.account_ou);
+	ads_msgfree(r->in.ads, res);
+
+	if ((status.error_type == ENUM_ADS_ERROR_LDAP) &&
+	    (status.err.rc == LDAP_ALREADY_EXISTS)) {
+		status = ADS_SUCCESS;
+	}
+
+	return status;
+}
+
+/****************************************************************
+****************************************************************/
+
+static ADS_STATUS libnet_unjoin_remove_machine_acct(TALLOC_CTX *mem_ctx,
+						    struct libnet_UnjoinCtx *r)
+{
+	ADS_STATUS status;
+
+	if (!r->in.ads) {
+		status = libnet_unjoin_connect_ads(mem_ctx, r);
+		if (!ADS_ERR_OK(status)) {
+			return status;
+		}
+	}
+
+	return ads_leave_realm(r->in.ads, r->in.machine_name);
+}
+
+/****************************************************************
+****************************************************************/
+
+static ADS_STATUS libnet_join_find_machine_acct(TALLOC_CTX *mem_ctx,
+						struct libnet_JoinCtx *r)
+{
+	ADS_STATUS status;
+	LDAPMessage *res = NULL;
+	char *dn = NULL;
+
+	if (!r->in.machine_name) {
+		return ADS_ERROR(LDAP_NO_MEMORY);
+	}
+
+	status = ads_find_machine_acct(r->in.ads,
+				       &res,
+				       r->in.machine_name);
+	if (!ADS_ERR_OK(status)) {
+		return status;
+	}
+
+	if (ads_count_replies(r->in.ads, res) != 1) {
+		status = ADS_ERROR_LDAP(LDAP_NO_MEMORY);
+		goto done;
+	}
+
+	dn = ads_get_dn(r->in.ads, res);
+	if (!dn) {
+		status = ADS_ERROR_LDAP(LDAP_NO_MEMORY);
+		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);
+		goto done;
+	}
+
+ done:
+	ads_msgfree(r->in.ads, res);
+	ads_memfree(r->in.ads, dn);
+
+	return status;
+}
+
+/****************************************************************
+****************************************************************/
+
 static bool libnet_join_joindomain_store_secrets(TALLOC_CTX *mem_ctx,
 						 struct libnet_JoinCtx *r)
 {
@@ -41,6 +271,9 @@ static bool libnet_join_joindomain_store_secrets(TALLOC_CTX *mem_ctx,
 	return true;
 }
 
+/****************************************************************
+****************************************************************/
+
 static NTSTATUS libnet_join_joindomain_rpc(TALLOC_CTX *mem_ctx,
 					   struct libnet_JoinCtx *r)
 {
@@ -229,6 +462,9 @@ static NTSTATUS libnet_join_joindomain_rpc(TALLOC_CTX *mem_ctx,
 	return status;
 }
 
+/****************************************************************
+****************************************************************/
+
 static bool libnet_join_unjoindomain_remove_secrets(TALLOC_CTX *mem_ctx,
 						    struct libnet_UnjoinCtx *r)
 {
@@ -243,6 +479,9 @@ static bool libnet_join_unjoindomain_remove_secrets(TALLOC_CTX *mem_ctx,
 	return true;
 }
 
+/****************************************************************
+****************************************************************/
+
 static NTSTATUS libnet_join_unjoindomain_rpc(TALLOC_CTX *mem_ctx,
 					     struct libnet_UnjoinCtx *r)
 {
@@ -348,6 +587,9 @@ done:
 	return status;
 }
 
+/****************************************************************
+****************************************************************/
+
 static WERROR do_join_modify_vals_config(struct libnet_JoinCtx *r)
 {
 	WERROR werr;
@@ -386,6 +628,9 @@ static WERROR do_join_modify_vals_config(struct libnet_JoinCtx *r)
 	return werr;
 }
 
+/****************************************************************
+****************************************************************/
+
 static WERROR do_unjoin_modify_vals_config(struct libnet_UnjoinCtx *r)
 {
 	WERROR werr = WERR_OK;
@@ -401,6 +646,8 @@ static WERROR do_unjoin_modify_vals_config(struct libnet_UnjoinCtx *r)
 	return werr;
 }
 
+/****************************************************************
+****************************************************************/
 
 static WERROR do_JoinConfig(struct libnet_JoinCtx *r)
 {
@@ -425,6 +672,9 @@ static WERROR do_JoinConfig(struct libnet_JoinCtx *r)
 	return werr;
 }
 
+/****************************************************************
+****************************************************************/
+
 static WERROR do_UnjoinConfig(struct libnet_UnjoinCtx *r)
 {
 	WERROR werr;
@@ -448,6 +698,33 @@ static WERROR do_UnjoinConfig(struct libnet_UnjoinCtx *r)
 	return werr;
 }
 
+/****************************************************************
+****************************************************************/
+
+static int libnet_destroy_JoinCtx(struct libnet_JoinCtx *r)
+{
+	if (r->in.ads) {
+		ads_destroy(&r->in.ads);
+	}
+
+	return 0;
+}
+
+/****************************************************************
+****************************************************************/
+
+static int libnet_destroy_UnjoinCtx(struct libnet_UnjoinCtx *r)
+{
+	if (r->in.ads) {
+		ads_destroy(&r->in.ads);
+	}
+
+	return 0;
+}
+
+/****************************************************************
+****************************************************************/
+
 WERROR libnet_init_JoinCtx(TALLOC_CTX *mem_ctx,
 			   struct libnet_JoinCtx **r)
 {
@@ -458,11 +735,19 @@ WERROR libnet_init_JoinCtx(TALLOC_CTX *mem_ctx,
 		return WERR_NOMEM;
 	}
 
+	talloc_set_destructor(ctx, libnet_destroy_JoinCtx);
+
+	ctx->in.machine_name = talloc_strdup(mem_ctx, global_myname());
+	W_ERROR_HAVE_NO_MEMORY(ctx->in.machine_name);
+


-- 
Samba Shared Repository


More information about the samba-cvs mailing list