[SCM] Samba Shared Repository - branch v3-2-test updated - release-3-2-0pre2-725-g6c933d0

Günther Deschner gd at samba.org
Wed Apr 9 11:49:28 GMT 2008


The branch, v3-2-test has been updated
       via  6c933d0b3838808aeee7f4b29ee89aab8d203538 (commit)
       via  285072479bebf09c94fccf55578ef587627c888e (commit)
       via  dbbefb4e97df49dc28d47b5d9ba759f90efb9aab (commit)
      from  3123e68bda70ad1cff9bd8f9375fd7935bf755dd (commit)

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


- Log -----------------------------------------------------------------
commit 6c933d0b3838808aeee7f4b29ee89aab8d203538
Author: Günther Deschner <gd at samba.org>
Date:   Wed Apr 9 13:47:51 2008 +0200

    Add NetUserEnum to libnetapi.
    
    Guenther

commit 285072479bebf09c94fccf55578ef587627c888e
Author: Günther Deschner <gd at samba.org>
Date:   Wed Apr 9 13:42:48 2008 +0200

    Re-run make idl.
    
    Guenther

commit dbbefb4e97df49dc28d47b5d9ba759f90efb9aab
Author: Günther Deschner <gd at samba.org>
Date:   Wed Apr 9 13:41:54 2008 +0200

    Add NetUserEnum to libnetapi IDL.
    
    Guenther

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

Summary of changes:
 source/lib/netapi/libnetapi.c         |   55 +++++++++
 source/lib/netapi/libnetapi.h         |   12 ++
 source/lib/netapi/netapi.h            |   16 +++-
 source/lib/netapi/user.c              |  197 +++++++++++++++++++++++++++++++++
 source/librpc/gen_ndr/libnetapi.h     |   21 ++++
 source/librpc/gen_ndr/ndr_libnetapi.c |   55 +++++++++
 source/librpc/gen_ndr/ndr_libnetapi.h |    7 +-
 source/librpc/idl/libnetapi.idl       |   13 ++
 8 files changed, 374 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/lib/netapi/libnetapi.c b/source/lib/netapi/libnetapi.c
index 7fd1e76..eeff7c5 100644
--- a/source/lib/netapi/libnetapi.c
+++ b/source/lib/netapi/libnetapi.c
@@ -529,3 +529,58 @@ NET_API_STATUS NetUserDel(const char * server_name /* [in] [unique] */,
 	return r.out.result;
 }
 
+/****************************************************************
+ NetUserEnum
+****************************************************************/
+
+NET_API_STATUS NetUserEnum(const char * server_name /* [in] [unique] */,
+			   uint32_t level /* [in] */,
+			   uint32_t filter /* [in] */,
+			   uint8_t **buffer /* [out] [ref] */,
+			   uint32_t prefmaxlen /* [in] */,
+			   uint32_t *entries_read /* [out] [ref] */,
+			   uint32_t *total_entries /* [out] [ref] */,
+			   uint32_t *resume_handle /* [in,out] [ref] */)
+{
+	struct NetUserEnum r;
+	struct libnetapi_ctx *ctx = NULL;
+	NET_API_STATUS status;
+	WERROR werr;
+
+	status = libnetapi_getctx(&ctx);
+	if (status != 0) {
+		return status;
+	}
+
+	/* In parameters */
+	r.in.server_name = server_name;
+	r.in.level = level;
+	r.in.filter = filter;
+	r.in.prefmaxlen = prefmaxlen;
+	r.in.resume_handle = resume_handle;
+
+	/* Out parameters */
+	r.out.buffer = buffer;
+	r.out.entries_read = entries_read;
+	r.out.total_entries = total_entries;
+	r.out.resume_handle = resume_handle;
+
+	if (DEBUGLEVEL >= 10) {
+		NDR_PRINT_IN_DEBUG(NetUserEnum, &r);
+	}
+
+	if (LIBNETAPI_LOCAL_SERVER(server_name)) {
+		werr = NetUserEnum_l(ctx, &r);
+	} else {
+		werr = NetUserEnum_r(ctx, &r);
+	}
+
+	r.out.result = W_ERROR_V(werr);
+
+	if (DEBUGLEVEL >= 10) {
+		NDR_PRINT_OUT_DEBUG(NetUserEnum, &r);
+	}
+
+	return r.out.result;
+}
+
diff --git a/source/lib/netapi/libnetapi.h b/source/lib/netapi/libnetapi.h
index 9ab5481..5cd4165 100644
--- a/source/lib/netapi/libnetapi.h
+++ b/source/lib/netapi/libnetapi.h
@@ -88,4 +88,16 @@ WERROR NetUserDel_r(struct libnetapi_ctx *ctx,
 		    struct NetUserDel *r);
 WERROR NetUserDel_l(struct libnetapi_ctx *ctx,
 		    struct NetUserDel *r);
+NET_API_STATUS NetUserEnum(const char * server_name /* [in] [unique] */,
+			   uint32_t level /* [in] */,
+			   uint32_t filter /* [in] */,
+			   uint8_t **buffer /* [out] [ref] */,
+			   uint32_t prefmaxlen /* [in] */,
+			   uint32_t *entries_read /* [out] [ref] */,
+			   uint32_t *total_entries /* [out] [ref] */,
+			   uint32_t *resume_handle /* [in,out] [ref] */);
+WERROR NetUserEnum_r(struct libnetapi_ctx *ctx,
+		     struct NetUserEnum *r);
+WERROR NetUserEnum_l(struct libnetapi_ctx *ctx,
+		     struct NetUserEnum *r);
 #endif /* __LIBNETAPI_LIBNETAPI__ */
diff --git a/source/lib/netapi/netapi.h b/source/lib/netapi/netapi.h
index 67919ee..4839735 100644
--- a/source/lib/netapi/netapi.h
+++ b/source/lib/netapi/netapi.h
@@ -23,11 +23,12 @@
 /****************************************************************
  NET_API_STATUS
 ****************************************************************/
-
 typedef enum {
 	NET_API_STATUS_SUCCESS = 0
 } NET_API_STATUS;
 
+#define ERROR_MORE_DATA	( 234L )
+
 /****************************************************************
 ****************************************************************/
 
@@ -208,4 +209,17 @@ NET_API_STATUS NetUserAdd(const char * server_name /* [in] */,
 NET_API_STATUS NetUserDel(const char * server_name /* [in] */,
 			  const char * user_name /* [in] */);
 
+/****************************************************************
+ NetUserEnum
+****************************************************************/
+
+NET_API_STATUS NetUserEnum(const char * server_name /* [in] */,
+			   uint32_t level /* [in] */,
+			   uint32_t filter /* [in] */,
+			   uint8_t **buffer /* [out] [ref] */,
+			   uint32_t prefmaxlen /* [in] */,
+			   uint32_t *entries_read /* [out] [ref] */,
+			   uint32_t *total_entries /* [out] [ref] */,
+			   uint32_t *resume_handle /* [in,out] [ref] */);
+
 #endif
diff --git a/source/lib/netapi/user.c b/source/lib/netapi/user.c
index f5bdc27..8dcc159 100644
--- a/source/lib/netapi/user.c
+++ b/source/lib/netapi/user.c
@@ -546,3 +546,200 @@ WERROR NetUserDel_l(struct libnetapi_ctx *ctx,
 {
 	return WERR_NOT_SUPPORTED;
 }
+
+/****************************************************************
+****************************************************************/
+
+static WERROR convert_samr_samarray_to_USER_INFO_buffer(TALLOC_CTX *mem_ctx,
+							struct samr_SamArray *sam_array,
+							uint32_t level,
+							uint8_t **buffer)
+{
+	struct USER_INFO_0 *info0 = NULL;
+	int i;
+
+	switch (level) {
+		case 0:
+			info0 = TALLOC_ZERO_ARRAY(mem_ctx, struct USER_INFO_0,
+						  sam_array->count);
+			W_ERROR_HAVE_NO_MEMORY(info0);
+
+			for (i=0; i<sam_array->count; i++) {
+				info0[i].usri0_name = talloc_strdup(mem_ctx,
+					sam_array->entries[i].name.string);
+				W_ERROR_HAVE_NO_MEMORY(info0[i].usri0_name);
+			}
+
+			*buffer = (uint8_t *)talloc_memdup(mem_ctx, info0,
+				sizeof(struct USER_INFO_0) * sam_array->count);
+			W_ERROR_HAVE_NO_MEMORY(*buffer);
+			break;
+		default:
+			return WERR_NOT_SUPPORTED;
+	}
+
+	return WERR_OK;
+}
+
+/****************************************************************
+****************************************************************/
+
+WERROR NetUserEnum_r(struct libnetapi_ctx *ctx,
+		     struct NetUserEnum *r)
+{
+	struct cli_state *cli = NULL;
+	struct rpc_pipe_client *pipe_cli = NULL;
+	struct policy_handle connect_handle;
+	struct dom_sid2 *domain_sid = NULL;
+	struct policy_handle domain_handle;
+	struct samr_SamArray *sam = NULL;
+	uint32_t num_entries = 0;
+	int i;
+	const char *domain_name = NULL;
+	bool domain_found = true;
+	uint32_t dom_resume_handle = 0;
+	struct lsa_String lsa_domain_name;
+
+	NTSTATUS status;
+	WERROR werr;
+
+	ZERO_STRUCT(connect_handle);
+	ZERO_STRUCT(domain_handle);
+
+	switch (r->in.level) {
+		case 0:
+			break;
+		case 1:
+		case 2:
+		case 3:
+		case 10:
+		case 11:
+		case 20:
+		case 23:
+		default:
+			return WERR_NOT_SUPPORTED;
+	}
+
+	status = cli_full_connection(&cli, NULL, r->in.server_name,
+				     NULL, 0,
+				     "IPC$", "IPC",
+				     ctx->username,
+				     ctx->workgroup,
+				     ctx->password,
+				     CLI_FULL_CONNECTION_USE_KERBEROS |
+				     CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS,
+				     Undefined, NULL);
+
+	if (!NT_STATUS_IS_OK(status)) {
+		werr = ntstatus_to_werror(status);
+		goto done;
+	}
+
+	pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SAMR, &status);
+	if (!pipe_cli) {
+		werr = ntstatus_to_werror(status);
+		goto done;
+	}
+
+	status = rpccli_try_samr_connects(pipe_cli, ctx,
+					  SAMR_ACCESS_OPEN_DOMAIN |
+					  SAMR_ACCESS_ENUM_DOMAINS,
+					  &connect_handle);
+	if (!NT_STATUS_IS_OK(status)) {
+		werr = ntstatus_to_werror(status);
+		goto done;
+	}
+
+	status = rpccli_samr_EnumDomains(pipe_cli, ctx,
+					 &connect_handle,
+					 &dom_resume_handle,
+					 &sam,
+					 0xffffffff,
+					 &num_entries);
+	if (!NT_STATUS_IS_OK(status)) {
+		werr = ntstatus_to_werror(status);
+		goto done;
+	}
+
+	for (i=0; i<num_entries; i++) {
+
+		domain_name = sam->entries[i].name.string;
+
+		if (strequal(domain_name, builtin_domain_name())) {
+			continue;
+		}
+
+		domain_found = true;
+		break;
+	}
+
+	if (!domain_found) {
+		werr = WERR_NO_SUCH_DOMAIN;
+		goto done;
+	}
+
+	init_lsa_String(&lsa_domain_name, domain_name);
+
+	status = rpccli_samr_LookupDomain(pipe_cli, ctx,
+					  &connect_handle,
+					  &lsa_domain_name,
+					  &domain_sid);
+	if (!NT_STATUS_IS_OK(status)) {
+		werr = ntstatus_to_werror(status);
+		goto done;
+	}
+
+	status = rpccli_samr_OpenDomain(pipe_cli,
+					ctx,
+					&connect_handle,
+					SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 |
+					SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS |
+					SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
+					domain_sid,
+					&domain_handle);
+	if (!NT_STATUS_IS_OK(status)) {
+		werr = ntstatus_to_werror(status);
+		goto done;
+	}
+
+	status = rpccli_samr_EnumDomainUsers(pipe_cli,
+					     ctx,
+					     &domain_handle,
+					     r->in.resume_handle,
+					     r->in.filter,
+					     &sam,
+					     r->in.prefmaxlen,
+					     r->out.entries_read);
+	if (!NT_STATUS_IS_OK(status)) {
+		werr = ntstatus_to_werror(status);
+		goto done;
+	}
+
+	werr = convert_samr_samarray_to_USER_INFO_buffer(ctx, sam,
+							 r->in.level,
+							 r->out.buffer);
+
+ done:
+	if (is_valid_policy_hnd(&domain_handle)) {
+		rpccli_samr_Close(pipe_cli, ctx, &domain_handle);
+	}
+	if (is_valid_policy_hnd(&connect_handle)) {
+		rpccli_samr_Close(pipe_cli, ctx, &connect_handle);
+	}
+
+	if (cli) {
+		cli_shutdown(cli);
+	}
+
+	return werr;
+}
+
+/****************************************************************
+****************************************************************/
+
+WERROR NetUserEnum_l(struct libnetapi_ctx *ctx,
+		     struct NetUserEnum *r)
+{
+	return WERR_NOT_SUPPORTED;
+}
+
diff --git a/source/librpc/gen_ndr/libnetapi.h b/source/librpc/gen_ndr/libnetapi.h
index dda4fad..08b4545 100644
--- a/source/librpc/gen_ndr/libnetapi.h
+++ b/source/librpc/gen_ndr/libnetapi.h
@@ -6,6 +6,7 @@
 #ifndef _HEADER_libnetapi
 #define _HEADER_libnetapi
 
+#define ERROR_MORE_DATA	( 234L )
 enum NET_API_STATUS
 #ifndef USE_UINT_ENUMS
  {
@@ -209,4 +210,24 @@ struct NetUserDel {
 
 };
 
+
+struct NetUserEnum {
+	struct {
+		const char * server_name;/* [unique] */
+		uint32_t level;
+		uint32_t filter;
+		uint32_t prefmaxlen;
+		uint32_t *resume_handle;/* [ref] */
+	} in;
+
+	struct {
+		uint8_t **buffer;/* [ref] */
+		uint32_t *entries_read;/* [ref] */
+		uint32_t *total_entries;/* [ref] */
+		uint32_t *resume_handle;/* [ref] */
+		enum NET_API_STATUS result;
+	} out;
+
+};
+
 #endif /* _HEADER_libnetapi */
diff --git a/source/librpc/gen_ndr/ndr_libnetapi.c b/source/librpc/gen_ndr/ndr_libnetapi.c
index 54b3d3e..cd8df4d 100644
--- a/source/librpc/gen_ndr/ndr_libnetapi.c
+++ b/source/librpc/gen_ndr/ndr_libnetapi.c
@@ -630,3 +630,58 @@ _PUBLIC_ void ndr_print_NetUserDel(struct ndr_print *ndr, const char *name, int
 	ndr->depth--;
 }
 
+_PUBLIC_ void ndr_print_NetUserEnum(struct ndr_print *ndr, const char *name, int flags, const struct NetUserEnum *r)
+{
+	ndr_print_struct(ndr, name, "NetUserEnum");
+	ndr->depth++;
+	if (flags & NDR_SET_VALUES) {
+		ndr->flags |= LIBNDR_PRINT_SET_VALUES;
+	}
+	if (flags & NDR_IN) {
+		ndr_print_struct(ndr, "in", "NetUserEnum");
+		ndr->depth++;
+		ndr_print_ptr(ndr, "server_name", r->in.server_name);
+		ndr->depth++;
+		if (r->in.server_name) {
+			ndr_print_string(ndr, "server_name", r->in.server_name);
+		}
+		ndr->depth--;
+		ndr_print_uint32(ndr, "level", r->in.level);
+		ndr_print_uint32(ndr, "filter", r->in.filter);
+		ndr_print_uint32(ndr, "prefmaxlen", r->in.prefmaxlen);
+		ndr_print_ptr(ndr, "resume_handle", r->in.resume_handle);
+		ndr->depth++;
+		ndr_print_uint32(ndr, "resume_handle", *r->in.resume_handle);
+		ndr->depth--;
+		ndr->depth--;
+	}
+	if (flags & NDR_OUT) {
+		ndr_print_struct(ndr, "out", "NetUserEnum");
+		ndr->depth++;
+		ndr_print_ptr(ndr, "buffer", r->out.buffer);
+		ndr->depth++;
+		ndr_print_ptr(ndr, "buffer", *r->out.buffer);
+		ndr->depth++;
+		if (*r->out.buffer) {
+			ndr_print_uint8(ndr, "buffer", **r->out.buffer);
+		}
+		ndr->depth--;
+		ndr->depth--;
+		ndr_print_ptr(ndr, "entries_read", r->out.entries_read);
+		ndr->depth++;
+		ndr_print_uint32(ndr, "entries_read", *r->out.entries_read);
+		ndr->depth--;
+		ndr_print_ptr(ndr, "total_entries", r->out.total_entries);
+		ndr->depth++;
+		ndr_print_uint32(ndr, "total_entries", *r->out.total_entries);
+		ndr->depth--;
+		ndr_print_ptr(ndr, "resume_handle", r->out.resume_handle);
+		ndr->depth++;
+		ndr_print_uint32(ndr, "resume_handle", *r->out.resume_handle);
+		ndr->depth--;
+		ndr_print_NET_API_STATUS(ndr, "result", r->out.result);
+		ndr->depth--;
+	}
+	ndr->depth--;
+}
+
diff --git a/source/librpc/gen_ndr/ndr_libnetapi.h b/source/librpc/gen_ndr/ndr_libnetapi.h
index 879e2d6..32ad926 100644
--- a/source/librpc/gen_ndr/ndr_libnetapi.h
+++ b/source/librpc/gen_ndr/ndr_libnetapi.h
@@ -28,7 +28,9 @@
 
 #define NDR_NETUSERDEL (0x0a)
 
-#define NDR_LIBNETAPI_CALL_COUNT (11)
+#define NDR_NETUSERENUM (0x0b)
+
+#define NDR_LIBNETAPI_CALL_COUNT (12)
 enum ndr_err_code ndr_push_NET_API_STATUS(struct ndr_push *ndr, int ndr_flags, enum NET_API_STATUS r);
 enum ndr_err_code ndr_pull_NET_API_STATUS(struct ndr_pull *ndr, int ndr_flags, enum NET_API_STATUS *r);
 void ndr_print_NET_API_STATUS(struct ndr_print *ndr, const char *name, enum NET_API_STATUS r);
@@ -74,4 +76,7 @@ void ndr_print_NetUserAdd(struct ndr_print *ndr, const char *name, int flags, co
 enum ndr_err_code ndr_push_NetUserDel(struct ndr_push *ndr, int flags, const struct NetUserDel *r);
 enum ndr_err_code ndr_pull_NetUserDel(struct ndr_pull *ndr, int flags, struct NetUserDel *r);
 void ndr_print_NetUserDel(struct ndr_print *ndr, const char *name, int flags, const struct NetUserDel *r);
+enum ndr_err_code ndr_push_NetUserEnum(struct ndr_push *ndr, int flags, const struct NetUserEnum *r);
+enum ndr_err_code ndr_pull_NetUserEnum(struct ndr_pull *ndr, int flags, struct NetUserEnum *r);
+void ndr_print_NetUserEnum(struct ndr_print *ndr, const char *name, int flags, const struct NetUserEnum *r);
 #endif /* _HEADER_NDR_libnetapi */
diff --git a/source/librpc/idl/libnetapi.idl b/source/librpc/idl/libnetapi.idl
index 82d2693..d74df18 100644
--- a/source/librpc/idl/libnetapi.idl
+++ b/source/librpc/idl/libnetapi.idl
@@ -9,6 +9,8 @@ cpp_quote("#define LIBNETAPI_LOCAL_SERVER(x) (!x || is_myname_or_ipaddr(x))")
 ]
 interface libnetapi
 {
+	const int ERROR_MORE_DATA = 234L;
+
 	[public] typedef [v1_enum] enum {
 		NERR_Success=0
 	} NET_API_STATUS;
@@ -116,4 +118,15 @@ interface libnetapi
 		[in,unique] string *server_name,
 		[in,ref] string *user_name
 		);
+
+	[nopush,nopull] NET_API_STATUS NetUserEnum(
+		[in,unique] string *server_name,
+		[in] uint32 level,
+		[in] uint32 filter,
+		[out,ref] uint8 **buffer,
+		[in] uint32 prefmaxlen,
+		[out,ref] uint32 *entries_read,
+		[out,ref] uint32 *total_entries,
+		[in,out,ref] uint32 *resume_handle
+		);
 }


-- 
Samba Shared Repository


More information about the samba-cvs mailing list