[SCM] Samba Shared Repository - branch v3-3-test updated -
release-3-2-0pre2-3335-gf930900
Günther Deschner
gd at samba.org
Fri Jul 18 15:27:22 GMT 2008
The branch, v3-3-test has been updated
via f93090037798ffb4d9b875a4320f970ae10a64b6 (commit)
via 2cd91e7d4d4847e1daef2585b09da4e6da6c9d11 (commit)
via a5a8d03699220e1f237debb84a75cacbbb8899fa (commit)
via 151c8fa7901983a3e7a82f1af599c839249b6cd7 (commit)
via 71bd0109d6c393d4361729b514e63fab113bf78a (commit)
via 4b79d54574722552346bbc17947fd26fc1a0deda (commit)
via 95432c8b57aac684064a20a7bba0734fb5d27d18 (commit)
from dc0f737bd5e86369b2bbfbef420a095205c2d3cb (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-3-test
- Log -----------------------------------------------------------------
commit f93090037798ffb4d9b875a4320f970ae10a64b6
Author: Günther Deschner <gd at samba.org>
Date: Fri Jul 18 16:24:02 2008 +0200
netapi: let libnetapi_samr_lookup_and_open_alias compose lsa string.
Guenther
commit 2cd91e7d4d4847e1daef2585b09da4e6da6c9d11
Author: Günther Deschner <gd at samba.org>
Date: Fri Jul 18 15:11:08 2008 +0200
netapi: implement NetLocalGroupEnum_r.
Guenther
commit a5a8d03699220e1f237debb84a75cacbbb8899fa
Author: Günther Deschner <gd at samba.org>
Date: Fri Jul 18 01:41:30 2008 +0200
netapi: add NetLocalGroupEnum example code.
Guenther
commit 151c8fa7901983a3e7a82f1af599c839249b6cd7
Author: Günther Deschner <gd at samba.org>
Date: Fri Jul 18 01:40:34 2008 +0200
netapi: add NetLocalGroupEnum to public header.
Guenther
commit 71bd0109d6c393d4361729b514e63fab113bf78a
Author: Günther Deschner <gd at samba.org>
Date: Fri Jul 18 01:23:26 2008 +0200
netapi: add skeleton for NetLocalGroupEnum().
Guenther
commit 4b79d54574722552346bbc17947fd26fc1a0deda
Author: Günther Deschner <gd at samba.org>
Date: Fri Jul 18 01:21:38 2008 +0200
re-run make idl.
Guenther
commit 95432c8b57aac684064a20a7bba0734fb5d27d18
Author: Günther Deschner <gd at samba.org>
Date: Fri Jul 18 01:20:56 2008 +0200
netapi: add NetLocalGroupEnum to IDL.
Guenther
-----------------------------------------------------------------------
Summary of changes:
source/lib/netapi/examples/Makefile.in | 6 +
.../localgroup_enum.c} | 66 +++++--
source/lib/netapi/libnetapi.c | 53 +++++
source/lib/netapi/libnetapi.h | 11 +
source/lib/netapi/localgroup.c | 212 ++++++++++++++++++--
source/lib/netapi/netapi.h | 28 +++
source/librpc/gen_ndr/libnetapi.h | 19 ++
source/librpc/gen_ndr/ndr_libnetapi.c | 49 +++++
source/librpc/gen_ndr/ndr_libnetapi.h | 9 +-
source/librpc/idl/libnetapi.idl | 14 ++
10 files changed, 428 insertions(+), 39 deletions(-)
copy source/lib/netapi/examples/{user/user_dispinfo.c => localgroup/localgroup_enum.c} (59%)
Changeset truncated at 500 lines:
diff --git a/source/lib/netapi/examples/Makefile.in b/source/lib/netapi/examples/Makefile.in
index b853f2f..ca387ee 100644
--- a/source/lib/netapi/examples/Makefile.in
+++ b/source/lib/netapi/examples/Makefile.in
@@ -40,6 +40,7 @@ PROGS = bin/getdc at EXEEXT@ \
bin/localgroup_del at EXEEXT@ \
bin/localgroup_getinfo at EXEEXT@ \
bin/localgroup_setinfo at EXEEXT@ \
+ bin/localgroup_enum at EXEEXT@ \
bin/remote_tod at EXEEXT@
all: $(PROGS)
@@ -92,6 +93,7 @@ LOCALGROUPADD_OBJ = localgroup/localgroup_add.o $(CMDLINE_OBJ)
LOCALGROUPDEL_OBJ = localgroup/localgroup_del.o $(CMDLINE_OBJ)
LOCALGROUPGETINFO_OBJ = localgroup/localgroup_getinfo.o $(CMDLINE_OBJ)
LOCALGROUPSETINFO_OBJ = localgroup/localgroup_setinfo.o $(CMDLINE_OBJ)
+LOCALGROUPENUM_OBJ = localgroup/localgroup_enum.o $(CMDLINE_OBJ)
REMOTETOD_OBJ = server/remote_tod.o $(CMDLINE_OBJ)
bin/getdc at EXEEXT@: $(BINARY_PREREQS) $(GETDC_OBJ)
@@ -186,6 +188,10 @@ bin/localgroup_setinfo at EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPSETINFO_OBJ)
@echo Linking $@
@$(CC) $(FLAGS) -o $@ $(LOCALGROUPSETINFO_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS)
+bin/localgroup_enum at EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPENUM_OBJ)
+ @echo Linking $@
+ @$(CC) $(FLAGS) -o $@ $(LOCALGROUPENUM_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS)
+
bin/remote_tod at EXEEXT@: $(BINARY_PREREQS) $(REMOTETOD_OBJ)
@echo Linking $@
@$(CC) $(FLAGS) -o $@ $(REMOTETOD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS)
diff --git a/source/lib/netapi/examples/user/user_dispinfo.c b/source/lib/netapi/examples/localgroup/localgroup_enum.c
similarity index 59%
copy from source/lib/netapi/examples/user/user_dispinfo.c
copy to source/lib/netapi/examples/localgroup/localgroup_enum.c
index 23024fe..6fe0cf4 100644
--- a/source/lib/netapi/examples/user/user_dispinfo.c
+++ b/source/lib/netapi/examples/localgroup/localgroup_enum.c
@@ -1,6 +1,6 @@
/*
* Unix SMB/CIFS implementation.
- * NetQueryDisplayInformation query
+ * NetLocalGroupEnum query
* Copyright (C) Guenther Deschner 2008
*
* This program is free software; you can redistribute it and/or modify
@@ -32,12 +32,15 @@ int main(int argc, const char **argv)
NET_API_STATUS status;
struct libnetapi_ctx *ctx = NULL;
const char *hostname = NULL;
- void *buffer = NULL;
+ uint32_t level = 0;
+ uint8_t *buffer = NULL;
uint32_t entries_read = 0;
- uint32_t idx = 0;
+ uint32_t total_entries = 0;
+ uint32_t resume_handle = 0;
int i;
- struct NET_DISPLAY_USER *user;
+ struct LOCALGROUP_INFO_0 *info0 = NULL;
+ struct LOCALGROUP_INFO_1 *info1 = NULL;
poptContext pc;
int opt;
@@ -53,9 +56,9 @@ int main(int argc, const char **argv)
return status;
}
- pc = poptGetContext("user_dispinfo", argc, argv, long_options, 0);
+ pc = poptGetContext("localgroup_enum", argc, argv, long_options, 0);
- poptSetOtherOptionHelp(pc, "hostname");
+ poptSetOtherOptionHelp(pc, "hostname level");
while((opt = poptGetNextOpt(pc)) != -1) {
}
@@ -65,30 +68,53 @@ int main(int argc, const char **argv)
}
hostname = poptGetArg(pc);
- /* NetQueryDisplayInformation */
+ if (poptPeekArg(pc)) {
+ level = atoi(poptGetArg(pc));
+ }
+
+ /* NetLocalGroupEnum */
do {
- status = NetQueryDisplayInformation(hostname,
- 1,
- idx,
- 1000,
- (uint32_t)-1,
- &entries_read,
- &buffer);
+ status = NetLocalGroupEnum(hostname,
+ level,
+ &buffer,
+ (uint32_t)-1,
+ &entries_read,
+ &total_entries,
+ &resume_handle);
if (status == 0 || status == ERROR_MORE_DATA) {
- user = (struct NET_DISPLAY_USER *)buffer;
+ printf("total entries: %d\n", total_entries);
+ switch (level) {
+ case 0:
+ info0 = (struct LOCALGROUP_INFO_0 *)buffer;
+ break;
+ case 1:
+ info1 = (struct LOCALGROUP_INFO_1 *)buffer;
+ break;
+ default:
+ break;
+ }
for (i=0; i<entries_read; i++) {
- printf("user %d: %s\n", i + idx,
- user->usri1_name);
- user++;
+ switch (level) {
+ case 0:
+ printf("#%d group: %s\n", i, info0->lgrpi0_name);
+ info0++;
+ break;
+ case 1:
+ printf("#%d group: %s\n", i, info1->lgrpi1_name);
+ printf("#%d comment: %s\n", i, info1->lgrpi1_comment);
+ info1++;
+ break;
+ default:
+ break;
+ }
}
NetApiBufferFree(buffer);
}
- idx += entries_read;
} while (status == ERROR_MORE_DATA);
if (status != 0) {
- printf("NetQueryDisplayInformation failed with: %s\n",
+ printf("NetLocalGroupEnum failed with: %s\n",
libnetapi_get_error_string(ctx, status));
}
diff --git a/source/lib/netapi/libnetapi.c b/source/lib/netapi/libnetapi.c
index 567fab6..1ebe338 100644
--- a/source/lib/netapi/libnetapi.c
+++ b/source/lib/netapi/libnetapi.c
@@ -1283,6 +1283,59 @@ NET_API_STATUS NetLocalGroupSetInfo(const char * server_name /* [in] */,
}
/****************************************************************
+ NetLocalGroupEnum
+****************************************************************/
+
+NET_API_STATUS NetLocalGroupEnum(const char * server_name /* [in] */,
+ uint32_t level /* [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 NetLocalGroupEnum 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.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(NetLocalGroupEnum, &r);
+ }
+
+ if (LIBNETAPI_LOCAL_SERVER(server_name)) {
+ werr = NetLocalGroupEnum_l(ctx, &r);
+ } else {
+ werr = NetLocalGroupEnum_r(ctx, &r);
+ }
+
+ r.out.result = W_ERROR_V(werr);
+
+ if (DEBUGLEVEL >= 10) {
+ NDR_PRINT_OUT_DEBUG(NetLocalGroupEnum, &r);
+ }
+
+ return r.out.result;
+}
+
+/****************************************************************
NetRemoteTOD
****************************************************************/
diff --git a/source/lib/netapi/libnetapi.h b/source/lib/netapi/libnetapi.h
index f104b72..774a0ac 100644
--- a/source/lib/netapi/libnetapi.h
+++ b/source/lib/netapi/libnetapi.h
@@ -223,6 +223,17 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx,
struct NetLocalGroupSetInfo *r);
WERROR NetLocalGroupSetInfo_l(struct libnetapi_ctx *ctx,
struct NetLocalGroupSetInfo *r);
+NET_API_STATUS NetLocalGroupEnum(const char * server_name /* [in] */,
+ uint32_t level /* [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 NetLocalGroupEnum_r(struct libnetapi_ctx *ctx,
+ struct NetLocalGroupEnum *r);
+WERROR NetLocalGroupEnum_l(struct libnetapi_ctx *ctx,
+ struct NetLocalGroupEnum *r);
NET_API_STATUS NetRemoteTOD(const char * server_name /* [in] */,
uint8_t **buf /* [out] [ref] */);
WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx,
diff --git a/source/lib/netapi/localgroup.c b/source/lib/netapi/localgroup.c
index d91045b..2c1e9df 100644
--- a/source/lib/netapi/localgroup.c
+++ b/source/lib/netapi/localgroup.c
@@ -27,18 +27,22 @@
static WERROR libnetapi_samr_lookup_and_open_alias(TALLOC_CTX *mem_ctx,
struct rpc_pipe_client *pipe_cli,
struct policy_handle *domain_handle,
- struct lsa_String *lsa_account_name,
+ const char *group_name,
uint32_t access_rights,
struct policy_handle *alias_handle)
{
NTSTATUS status;
WERROR werr;
+
+ struct lsa_String lsa_account_name;
struct samr_Ids user_rids, name_types;
+ init_lsa_String(&lsa_account_name, group_name);
+
status = rpccli_samr_LookupNames(pipe_cli, mem_ctx,
domain_handle,
1,
- lsa_account_name,
+ &lsa_account_name,
&user_rids,
&name_types);
if (!NT_STATUS_IS_OK(status)) {
@@ -177,11 +181,9 @@ WERROR NetLocalGroupAdd_r(struct libnetapi_ctx *ctx,
goto done;
}
- init_lsa_String(&lsa_account_name, alias_name);
-
werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli,
&builtin_handle,
- &lsa_account_name,
+ alias_name,
SAMR_ALIAS_ACCESS_LOOKUP_INFO,
&alias_handle);
@@ -275,7 +277,6 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx,
struct rpc_pipe_client *pipe_cli = NULL;
NTSTATUS status;
WERROR werr;
- struct lsa_String lsa_account_name;
struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle;
struct dom_sid2 *domain_sid = NULL;
@@ -308,11 +309,9 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx,
goto done;
}
- init_lsa_String(&lsa_account_name, r->in.group_name);
-
werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli,
&builtin_handle,
- &lsa_account_name,
+ r->in.group_name,
SEC_STD_DELETE,
&alias_handle);
@@ -336,7 +335,7 @@ WERROR NetLocalGroupDel_r(struct libnetapi_ctx *ctx,
werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli,
&domain_handle,
- &lsa_account_name,
+ r->in.group_name,
SEC_STD_DELETE,
&alias_handle);
@@ -445,7 +444,6 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx,
struct rpc_pipe_client *pipe_cli = NULL;
NTSTATUS status;
WERROR werr;
- struct lsa_String lsa_account_name;
struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle;
struct dom_sid2 *domain_sid = NULL;
union samr_AliasInfo *alias_info = NULL;
@@ -489,11 +487,9 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx,
goto done;
}
- init_lsa_String(&lsa_account_name, r->in.group_name);
-
werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli,
&builtin_handle,
- &lsa_account_name,
+ r->in.group_name,
SAMR_ALIAS_ACCESS_LOOKUP_INFO,
&alias_handle);
@@ -517,7 +513,7 @@ WERROR NetLocalGroupGetInfo_r(struct libnetapi_ctx *ctx,
werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli,
&domain_handle,
- &lsa_account_name,
+ r->in.group_name,
SAMR_ALIAS_ACCESS_LOOKUP_INFO,
&alias_handle);
@@ -672,7 +668,7 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx,
werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli,
&builtin_handle,
- &lsa_account_name,
+ r->in.group_name,
SAMR_ALIAS_ACCESS_SET_INFO,
&alias_handle);
@@ -695,7 +691,7 @@ WERROR NetLocalGroupSetInfo_r(struct libnetapi_ctx *ctx,
werr = libnetapi_samr_lookup_and_open_alias(ctx, pipe_cli,
&domain_handle,
- &lsa_account_name,
+ r->in.group_name,
SAMR_ALIAS_ACCESS_SET_INFO,
&alias_handle);
if (!W_ERROR_IS_OK(werr)) {
@@ -752,3 +748,185 @@ WERROR NetLocalGroupSetInfo_l(struct libnetapi_ctx *ctx,
{
return NetLocalGroupSetInfo_r(ctx, r);
}
+
+/****************************************************************
+****************************************************************/
+
+WERROR NetLocalGroupEnum_r(struct libnetapi_ctx *ctx,
+ struct NetLocalGroupEnum *r)
+{
+ struct cli_state *cli = NULL;
+ struct rpc_pipe_client *pipe_cli = NULL;
+ NTSTATUS status;
+ WERROR werr;
+ struct policy_handle connect_handle, domain_handle, builtin_handle, alias_handle;
+ struct dom_sid2 *domain_sid = NULL;
+ uint32_t entries_read = 0;
+ union samr_DomainInfo *domain_info = NULL;
+ union samr_DomainInfo *builtin_info = NULL;
+ struct samr_SamArray *domain_sam_array = NULL;
+ struct samr_SamArray *builtin_sam_array = NULL;
+ int i;
+
+ if (!r->out.buffer) {
+ return WERR_INVALID_PARAM;
+ }
+
+ switch (r->in.level) {
+ case 0:
+ case 1:
+ break;
+ default:
+ return WERR_UNKNOWN_LEVEL;
+ }
+
+ ZERO_STRUCT(connect_handle);
+ ZERO_STRUCT(builtin_handle);
+ ZERO_STRUCT(domain_handle);
+ ZERO_STRUCT(alias_handle);
+
+ werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
+ if (!W_ERROR_IS_OK(werr)) {
+ goto done;
+ }
+
+ werr = libnetapi_open_pipe(ctx, cli, PI_SAMR, &pipe_cli);
+ if (!W_ERROR_IS_OK(werr)) {
+ goto done;
+ }
+
+ werr = libnetapi_samr_open_builtin_domain(ctx, pipe_cli,
+ SAMR_ACCESS_OPEN_DOMAIN |
+ SAMR_ACCESS_ENUM_DOMAINS,
+ SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 |
+ SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS |
+ SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
+ &connect_handle,
+ &builtin_handle);
+ if (!W_ERROR_IS_OK(werr)) {
+ goto done;
+ }
+
+ werr = libnetapi_samr_open_domain(ctx, pipe_cli,
+ SAMR_ACCESS_OPEN_DOMAIN |
+ SAMR_ACCESS_ENUM_DOMAINS,
+ SAMR_DOMAIN_ACCESS_LOOKUP_INFO_2 |
+ SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS |
+ SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
+ &connect_handle,
+ &domain_handle,
+ &domain_sid);
+ if (!W_ERROR_IS_OK(werr)) {
+ goto done;
+ }
+
+ status = rpccli_samr_QueryDomainInfo(pipe_cli, ctx,
+ &builtin_handle,
+ 2,
+ &builtin_info);
+ if (!NT_STATUS_IS_OK(status)) {
+ werr = ntstatus_to_werror(status);
+ goto done;
+ }
+
+ status = rpccli_samr_QueryDomainInfo(pipe_cli, ctx,
+ &domain_handle,
+ 2,
+ &domain_info);
+ if (!NT_STATUS_IS_OK(status)) {
+ werr = ntstatus_to_werror(status);
+ goto done;
+ }
+
+ status = rpccli_samr_EnumDomainAliases(pipe_cli, ctx,
+ &builtin_handle,
+ r->in.resume_handle,
+ &builtin_sam_array,
+ r->in.prefmaxlen,
+ &entries_read);
+ if (!NT_STATUS_IS_OK(status)) {
+ werr = ntstatus_to_werror(status);
+ goto done;
+ }
+
+ for (i=0; i<builtin_sam_array->count; i++) {
+ union samr_AliasInfo *alias_info = NULL;
+
+ if (r->in.level == 1) {
+
+ status = libnetapi_samr_open_alias_queryinfo(ctx, pipe_cli,
+ &builtin_handle,
+ builtin_sam_array->entries[i].idx,
+ SAMR_ALIAS_ACCESS_LOOKUP_INFO,
+ ALIASINFOALL,
+ &alias_info);
+ if (!NT_STATUS_IS_OK(status)) {
+ werr = ntstatus_to_werror(status);
+ goto done;
+ }
+ }
+
+ werr = map_alias_info_to_buffer(ctx,
+ builtin_sam_array->entries[i].name.string,
+ alias_info ? &alias_info->all : NULL,
+ r->in.level,
+ r->out.entries_read,
+ r->out.buffer);
+ }
+
+ status = rpccli_samr_EnumDomainAliases(pipe_cli, ctx,
+ &domain_handle,
+ r->in.resume_handle,
+ &domain_sam_array,
+ r->in.prefmaxlen,
+ &entries_read);
+ if (!NT_STATUS_IS_OK(status)) {
+ werr = ntstatus_to_werror(status);
+ goto done;
+ }
+
+ for (i=0; i<domain_sam_array->count; i++) {
+
+ union samr_AliasInfo *alias_info = NULL;
+
+ if (r->in.level == 1) {
+ status = libnetapi_samr_open_alias_queryinfo(ctx, pipe_cli,
+ &domain_handle,
+ domain_sam_array->entries[i].idx,
--
Samba Shared Repository
More information about the samba-cvs
mailing list