[SCM] Samba Shared Repository - branch v3-devel updated - release-3-2-0pre2-4121-g969bc7c

Günther Deschner gd at samba.org
Thu Sep 11 12:33:14 GMT 2008


The branch, v3-devel has been updated
       via  969bc7ce3d3f266bf07784a980ea35ab458e6eae (commit)
       via  7d05936ff455b40449fe2e5280f15c81ccc7f4d0 (commit)
       via  299f76f4ce9d6f617431149e2502c27faa4431aa (commit)
       via  b31209e4495de31140c57338a891569b3436d91e (commit)
       via  3c07bcfb30ae5bb849291a5ca61b54798f14ee0a (commit)
       via  4f13450c6a27a329131a6027fc31fd627f2e61fa (commit)
       via  a977e18a669a220fd3f98161ced5bebd642e628b (commit)
       via  7b77dacde5f667d36868a2a8474cf719d9cce331 (commit)
       via  0ba0ffdb3023cd0bb6aa5c479309c871ff15ed0c (commit)
       via  dc7994195c9e34d85db8c9406edaa704027ab47f (commit)
       via  72a0b27aecc9113445dd03bdcd549ac50dd988aa (commit)
       via  4d92d000a1676d2da45e8113ade60250c6c7eebe (commit)
       via  00af97de407e2c0447714095340bd9494cc53b0f (commit)
       via  5040f6af41250220c5ccf1cbdc206c4b6e7025a5 (commit)
       via  2ddee7577de1d6d2b7a39b949ed6a925da2e9db8 (commit)
       via  1355939b4c9c2883f9542ef4189cac7418104b68 (commit)
       via  3e96cd229c1536a7e16441f600c379ceb651b2b3 (commit)
       via  165be948fab1c64526421b44b08de700849bba25 (commit)
       via  4efbd569478d6d98078833084aaae5a97cd5182b (commit)
       via  6b35856c21d300bf20dd7bc7c27c5e12aca6b2ff (commit)
       via  87fc15d9b52bbb15550015cb106062d24c5674ba (commit)
      from  7e8903b53beba3ad1bb8617ed435249257724be3 (commit)

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


- Log -----------------------------------------------------------------
commit 969bc7ce3d3f266bf07784a980ea35ab458e6eae
Author: Günther Deschner <gd at samba.org>
Date:   Tue Sep 9 18:44:40 2008 +0200

    netapi: implement NetUserGetLocalGroups_r.
    
    Guenther

commit 7d05936ff455b40449fe2e5280f15c81ccc7f4d0
Author: Günther Deschner <gd at samba.org>
Date:   Tue Sep 9 14:48:06 2008 +0200

    netapi: add NetUserGetLocalGroups example code.
    
    Guenther

commit 299f76f4ce9d6f617431149e2502c27faa4431aa
Author: Günther Deschner <gd at samba.org>
Date:   Tue Sep 9 13:44:09 2008 +0200

    netapi: add NetUserGetLocalGroups to public header.
    
    Guenther

commit b31209e4495de31140c57338a891569b3436d91e
Author: Günther Deschner <gd at samba.org>
Date:   Tue Sep 9 13:42:27 2008 +0200

    netapi: add NetUserGetLocalGroups skeleton.
    
    Guenther

commit 3c07bcfb30ae5bb849291a5ca61b54798f14ee0a
Author: Günther Deschner <gd at samba.org>
Date:   Tue Sep 9 13:40:39 2008 +0200

    re-run make idl.
    
    Guenther

commit 4f13450c6a27a329131a6027fc31fd627f2e61fa
Author: Günther Deschner <gd at samba.org>
Date:   Tue Sep 9 13:40:18 2008 +0200

    netapi: add NetUserGetLocalGroups to IDL.
    
    Guenther

commit a977e18a669a220fd3f98161ced5bebd642e628b
Author: Günther Deschner <gd at samba.org>
Date:   Mon Sep 8 16:43:06 2008 +0200

    netapi: fix group_getusers example.
    
    Guenther

commit 7b77dacde5f667d36868a2a8474cf719d9cce331
Author: Günther Deschner <gd at samba.org>
Date:   Mon Sep 8 16:42:38 2008 +0200

    netapi: implement NetGroupGetUsers_r.
    
    Guenther

commit 0ba0ffdb3023cd0bb6aa5c479309c871ff15ed0c
Author: Günther Deschner <gd at samba.org>
Date:   Tue Sep 9 13:17:22 2008 +0200

    netapi: implement NetGroupSetUsers_r.
    
    Guenther

commit dc7994195c9e34d85db8c9406edaa704027ab47f
Author: Günther Deschner <gd at samba.org>
Date:   Fri Sep 5 17:05:49 2008 +0200

    netapi: add example code for NetGroupSetUsers.
    
    Guenther

commit 72a0b27aecc9113445dd03bdcd549ac50dd988aa
Author: Günther Deschner <gd at samba.org>
Date:   Mon Sep 8 10:23:07 2008 +0200

    netapi: add NetGroupSetUsers to public header.
    
    Guenther

commit 4d92d000a1676d2da45e8113ade60250c6c7eebe
Author: Günther Deschner <gd at samba.org>
Date:   Mon Sep 8 10:21:17 2008 +0200

    netapi: add skeleton for NetGroupSetUsers.
    
    Guenther

commit 00af97de407e2c0447714095340bd9494cc53b0f
Author: Günther Deschner <gd at samba.org>
Date:   Fri Sep 5 17:00:41 2008 +0200

    re-run make idl.
    
    Guenther

commit 5040f6af41250220c5ccf1cbdc206c4b6e7025a5
Author: Günther Deschner <gd at samba.org>
Date:   Fri Sep 5 16:59:21 2008 +0200

    netapi: add IDL for NetGroupSetUsers.
    
    Guenther

commit 2ddee7577de1d6d2b7a39b949ed6a925da2e9db8
Author: Günther Deschner <gd at samba.org>
Date:   Mon Sep 8 19:10:00 2008 +0200

    netapi: implement NetUserSetGroups_r.
    
    Guenther

commit 1355939b4c9c2883f9542ef4189cac7418104b68
Author: Günther Deschner <gd at samba.org>
Date:   Fri Sep 5 17:01:23 2008 +0200

    netapi: add example code for NetUserSetGroups.
    
    Guenther

commit 3e96cd229c1536a7e16441f600c379ceb651b2b3
Author: Günther Deschner <gd at samba.org>
Date:   Mon Sep 8 10:26:11 2008 +0200

    netapi: add NetUserSetGroups to public header.
    
    Guenther

commit 165be948fab1c64526421b44b08de700849bba25
Author: Günther Deschner <gd at samba.org>
Date:   Fri Sep 5 16:51:55 2008 +0200

    netapi: add skeleton for NetUserSetGroups.
    
    Guenther

commit 4efbd569478d6d98078833084aaae5a97cd5182b
Author: Günther Deschner <gd at samba.org>
Date:   Fri Sep 5 16:50:04 2008 +0200

    re-run make idl.
    
    Guenther

commit 6b35856c21d300bf20dd7bc7c27c5e12aca6b2ff
Author: Günther Deschner <gd at samba.org>
Date:   Fri Sep 5 16:49:09 2008 +0200

    netapi: add IDL for NetUserSetGroups.
    
    Guenther

commit 87fc15d9b52bbb15550015cb106062d24c5674ba
Author: Günther Deschner <gd at samba.org>
Date:   Mon Sep 8 16:42:10 2008 +0200

    netapi: make add_GROUP_USERS_INFO_X_buffer non-static.
    
    Guenther

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

Summary of changes:
 source/lib/netapi/examples/Makefile.in             |   18 +
 source/lib/netapi/examples/group/group_getusers.c  |    4 +-
 source/lib/netapi/examples/group/group_setusers.c  |  142 ++++++
 .../lib/netapi/examples/user/user_getlocalgroups.c |  122 +++++
 source/lib/netapi/examples/user/user_setgroups.c   |  144 ++++++
 source/lib/netapi/group.c                          |  381 ++++++++++++++-
 source/lib/netapi/libnetapi.c                      |  150 ++++++
 source/lib/netapi/libnetapi.h                      |   30 ++
 source/lib/netapi/netapi.h                         |   76 +++
 source/lib/netapi/netapi_private.h                 |    7 +
 source/lib/netapi/user.c                           |  527 +++++++++++++++++++-
 source/librpc/gen_ndr/libnetapi.h                  |   56 ++
 source/librpc/gen_ndr/ndr_libnetapi.c              |  101 ++++
 source/librpc/gen_ndr/ndr_libnetapi.h              |   69 ++-
 source/librpc/idl/libnetapi.idl                    |   45 ++
 15 files changed, 1836 insertions(+), 36 deletions(-)
 create mode 100644 source/lib/netapi/examples/group/group_setusers.c
 create mode 100644 source/lib/netapi/examples/user/user_getlocalgroups.c
 create mode 100644 source/lib/netapi/examples/user/user_setgroups.c


Changeset truncated at 500 lines:

diff --git a/source/lib/netapi/examples/Makefile.in b/source/lib/netapi/examples/Makefile.in
index 0fca4c7..3eea96a 100644
--- a/source/lib/netapi/examples/Makefile.in
+++ b/source/lib/netapi/examples/Makefile.in
@@ -33,6 +33,8 @@ PROGS = bin/getdc at EXEEXT@ \
 	bin/user_modalsget at EXEEXT@ \
 	bin/user_modalsset at EXEEXT@ \
 	bin/user_getgroups at EXEEXT@ \
+	bin/user_setgroups at EXEEXT@ \
+	bin/user_getlocalgroups at EXEEXT@ \
 	bin/group_add at EXEEXT@ \
 	bin/group_del at EXEEXT@ \
 	bin/group_enum at EXEEXT@ \
@@ -41,6 +43,7 @@ PROGS = bin/getdc at EXEEXT@ \
 	bin/group_adduser at EXEEXT@ \
 	bin/group_deluser at EXEEXT@ \
 	bin/group_getusers at EXEEXT@ \
+	bin/group_setusers at EXEEXT@ \
 	bin/localgroup_add at EXEEXT@ \
 	bin/localgroup_del at EXEEXT@ \
 	bin/localgroup_getinfo at EXEEXT@ \
@@ -101,6 +104,8 @@ USERSETINFO_OBJ = user/user_setinfo.o $(CMDLINE_OBJ)
 USERMODALSGET_OBJ = user/user_modalsget.o $(CMDLINE_OBJ)
 USERMODALSSET_OBJ = user/user_modalsset.o $(CMDLINE_OBJ)
 USERGETGROUPS_OBJ = user/user_getgroups.o $(CMDLINE_OBJ)
+USERSETGROUPS_OBJ = user/user_setgroups.o $(CMDLINE_OBJ)
+USERGETLOCALGROUPS_OBJ = user/user_getlocalgroups.o $(CMDLINE_OBJ)
 GROUPADD_OBJ = group/group_add.o $(CMDLINE_OBJ)
 GROUPDEL_OBJ = group/group_del.o $(CMDLINE_OBJ)
 GROUPENUM_OBJ = group/group_enum.o $(CMDLINE_OBJ)
@@ -109,6 +114,7 @@ GROUPGETINFO_OBJ = group/group_getinfo.o $(CMDLINE_OBJ)
 GROUPADDUSER_OBJ = group/group_adduser.o $(CMDLINE_OBJ)
 GROUPDELUSER_OBJ = group/group_deluser.o $(CMDLINE_OBJ)
 GROUPGETUSERS_OBJ = group/group_getusers.o $(CMDLINE_OBJ)
+GROUPSETUSERS_OBJ = group/group_setusers.o $(CMDLINE_OBJ)
 LOCALGROUPADD_OBJ = localgroup/localgroup_add.o $(CMDLINE_OBJ)
 LOCALGROUPDEL_OBJ = localgroup/localgroup_del.o $(CMDLINE_OBJ)
 LOCALGROUPGETINFO_OBJ = localgroup/localgroup_getinfo.o $(CMDLINE_OBJ)
@@ -190,6 +196,14 @@ bin/user_getgroups at EXEEXT@: $(BINARY_PREREQS) $(USERGETGROUPS_OBJ)
 	@echo Linking $@
 	@$(CC) $(FLAGS) -o $@ $(USERGETGROUPS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS)
 
+bin/user_setgroups at EXEEXT@: $(BINARY_PREREQS) $(USERSETGROUPS_OBJ)
+	@echo Linking $@
+	@$(CC) $(FLAGS) -o $@ $(USERSETGROUPS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS)
+
+bin/user_getlocalgroups at EXEEXT@: $(BINARY_PREREQS) $(USERGETLOCALGROUPS_OBJ)
+	@echo Linking $@
+	@$(CC) $(FLAGS) -o $@ $(USERGETLOCALGROUPS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS)
+
 bin/group_add at EXEEXT@: $(BINARY_PREREQS) $(GROUPADD_OBJ)
 	@echo Linking $@
 	@$(CC) $(FLAGS) -o $@ $(GROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS)
@@ -222,6 +236,10 @@ bin/group_getusers at EXEEXT@: $(BINARY_PREREQS) $(GROUPGETUSERS_OBJ)
 	@echo Linking $@
 	@$(CC) $(FLAGS) -o $@ $(GROUPGETUSERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS)
 
+bin/group_setusers at EXEEXT@: $(BINARY_PREREQS) $(GROUPSETUSERS_OBJ)
+	@echo Linking $@
+	@$(CC) $(FLAGS) -o $@ $(GROUPSETUSERS_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS)
+
 bin/localgroup_add at EXEEXT@: $(BINARY_PREREQS) $(LOCALGROUPADD_OBJ)
 	@echo Linking $@
 	@$(CC) $(FLAGS) -o $@ $(LOCALGROUPADD_OBJ) $(LDFLAGS) $(DYNEXP) $(CMDLINE_LIBS)
diff --git a/source/lib/netapi/examples/group/group_getusers.c b/source/lib/netapi/examples/group/group_getusers.c
index 55d0717..72e79ec 100644
--- a/source/lib/netapi/examples/group/group_getusers.c
+++ b/source/lib/netapi/examples/group/group_getusers.c
@@ -105,11 +105,11 @@ int main(int argc, const char **argv)
 			for (i=0; i<entries_read; i++) {
 				switch (level) {
 					case 0:
-						printf("#%d group: %s\n", i, info0->grui0_name);
+						printf("#%d member: %s\n", i, info0->grui0_name);
 						info0++;
 						break;
 					case 1:
-						printf("#%d group: %s\n", i, info1->grui1_name);
+						printf("#%d member: %s\n", i, info1->grui1_name);
 						printf("#%d attributes: %d\n", i, info1->grui1_attributes);
 						info1++;
 						break;
diff --git a/source/lib/netapi/examples/group/group_setusers.c b/source/lib/netapi/examples/group/group_setusers.c
new file mode 100644
index 0000000..70cf105
--- /dev/null
+++ b/source/lib/netapi/examples/group/group_setusers.c
@@ -0,0 +1,142 @@
+/*
+ *  Unix SMB/CIFS implementation.
+ *  NetGroupSetUsers query
+ *  Copyright (C) Guenther Deschner 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/>.
+ */
+
+#include <sys/types.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <netapi.h>
+
+#include "common.h"
+
+int main(int argc, const char **argv)
+{
+	NET_API_STATUS status;
+	struct libnetapi_ctx *ctx = NULL;
+	const char *hostname = NULL;
+	const char *groupname = NULL;
+	uint32_t level = 0;
+	uint8_t *buffer = NULL;
+	uint32_t num_entries = 0;
+	const char **names = NULL;
+	int i = 0;
+	size_t buf_size = 0;
+
+	struct GROUP_USERS_INFO_0 *g0 = NULL;
+	struct GROUP_USERS_INFO_1 *g1 = NULL;
+
+	poptContext pc;
+	int opt;
+
+	struct poptOption long_options[] = {
+		POPT_AUTOHELP
+		POPT_COMMON_LIBNETAPI_EXAMPLES
+		POPT_TABLEEND
+	};
+
+	status = libnetapi_init(&ctx);
+	if (status != 0) {
+		return status;
+	}
+
+	pc = poptGetContext("group_setusers", argc, argv, long_options, 0);
+
+	poptSetOtherOptionHelp(pc, "hostname groupname level");
+	while((opt = poptGetNextOpt(pc)) != -1) {
+	}
+
+	if (!poptPeekArg(pc)) {
+		poptPrintHelp(pc, stderr, 0);
+		goto out;
+	}
+	hostname = poptGetArg(pc);
+
+	if (!poptPeekArg(pc)) {
+		poptPrintHelp(pc, stderr, 0);
+		goto out;
+	}
+	groupname = poptGetArg(pc);
+
+	if (!poptPeekArg(pc)) {
+		poptPrintHelp(pc, stderr, 0);
+		goto out;
+	}
+
+	names = poptGetArgs(pc);
+	for (i=0; names[i] != NULL; i++) {
+		num_entries++;
+	}
+
+	switch (level) {
+		case 0:
+			buf_size = sizeof(struct GROUP_USERS_INFO_0) * num_entries;
+
+			status = NetApiBufferAllocate(buf_size, (void **)&g0);
+			if (status) {
+				printf("NetApiBufferAllocate failed with: %s\n",
+					libnetapi_get_error_string(ctx, status));
+				goto out;
+			}
+
+			for (i=0; i<num_entries; i++) {
+				g0[i].grui0_name = names[i];
+			}
+
+			buffer = (uint8_t *)g0;
+			break;
+		case 1:
+			buf_size = sizeof(struct GROUP_USERS_INFO_1) * num_entries;
+
+			status = NetApiBufferAllocate(buf_size, (void **)&g1);
+			if (status) {
+				printf("NetApiBufferAllocate failed with: %s\n",
+					libnetapi_get_error_string(ctx, status));
+				goto out;
+			}
+
+			for (i=0; i<num_entries; i++) {
+				g1[i].grui1_name = names[i];
+			}
+
+			buffer = (uint8_t *)g1;
+			break;
+		default:
+			break;
+	}
+
+	/* NetGroupSetUsers */
+
+	status = NetGroupSetUsers(hostname,
+				  groupname,
+				  level,
+				  buffer,
+				  num_entries);
+	if (status != 0) {
+		printf("NetGroupSetUsers failed with: %s\n",
+			libnetapi_get_error_string(ctx, status));
+	}
+
+ out:
+	libnetapi_free(ctx);
+	poptFreeContext(pc);
+
+	return status;
+}
diff --git a/source/lib/netapi/examples/user/user_getlocalgroups.c b/source/lib/netapi/examples/user/user_getlocalgroups.c
new file mode 100644
index 0000000..133104d
--- /dev/null
+++ b/source/lib/netapi/examples/user/user_getlocalgroups.c
@@ -0,0 +1,122 @@
+/*
+ *  Unix SMB/CIFS implementation.
+ *  NetUserGetLocalGroups query
+ *  Copyright (C) Guenther Deschner 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/>.
+ */
+
+#include <sys/types.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <netapi.h>
+
+#include "common.h"
+
+int main(int argc, const char **argv)
+{
+	NET_API_STATUS status;
+	struct libnetapi_ctx *ctx = NULL;
+	const char *hostname = NULL;
+	const char *username = NULL;
+	uint32_t level = 0;
+	uint8_t *buffer = NULL;
+	uint32_t entries_read = 0;
+	uint32_t total_entries = 0;
+	uint32_t flags = 0;
+	int i;
+
+	struct LOCALGROUP_USERS_INFO_0 *info0 = NULL;
+
+	poptContext pc;
+	int opt;
+
+	struct poptOption long_options[] = {
+		POPT_AUTOHELP
+		POPT_COMMON_LIBNETAPI_EXAMPLES
+		POPT_TABLEEND
+	};
+
+	status = libnetapi_init(&ctx);
+	if (status != 0) {
+		return status;
+	}
+
+	pc = poptGetContext("user_getlocalgroups", argc, argv, long_options, 0);
+
+	poptSetOtherOptionHelp(pc, "hostname username");
+	while((opt = poptGetNextOpt(pc)) != -1) {
+	}
+
+	if (!poptPeekArg(pc)) {
+		poptPrintHelp(pc, stderr, 0);
+		goto out;
+	}
+	hostname = poptGetArg(pc);
+
+	if (!poptPeekArg(pc)) {
+		poptPrintHelp(pc, stderr, 0);
+		goto out;
+	}
+	username = poptGetArg(pc);
+
+	/* NetUserGetLocalGroups */
+
+	do {
+		status = NetUserGetLocalGroups(hostname,
+					       username,
+					       level,
+					       flags,
+					       &buffer,
+					       (uint32_t)-1,
+					       &entries_read,
+					       &total_entries);
+		if (status == 0 || status == ERROR_MORE_DATA) {
+
+			switch (level) {
+				case 0:
+					info0 = (struct LOCALGROUP_USERS_INFO_0 *)buffer;
+					break;
+				default:
+					break;
+			}
+
+			for (i=0; i<entries_read; i++) {
+				switch (level) {
+					case 0:
+						printf("#%d group: %s\n", i, info0->lgrui0_name);
+						info0++;
+						break;
+					default:
+						break;
+				}
+			}
+			NetApiBufferFree(buffer);
+		}
+	} while (status == ERROR_MORE_DATA);
+
+	if (status != 0) {
+		printf("NetUserGetLocalGroups failed with: %s\n",
+			libnetapi_get_error_string(ctx, status));
+	}
+
+ out:
+	libnetapi_free(ctx);
+	poptFreeContext(pc);
+
+	return status;
+}
diff --git a/source/lib/netapi/examples/user/user_setgroups.c b/source/lib/netapi/examples/user/user_setgroups.c
new file mode 100644
index 0000000..de3ff22
--- /dev/null
+++ b/source/lib/netapi/examples/user/user_setgroups.c
@@ -0,0 +1,144 @@
+/*
+ *  Unix SMB/CIFS implementation.
+ *  NetUserSetGroups query
+ *  Copyright (C) Guenther Deschner 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/>.
+ */
+
+#include <sys/types.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <netapi.h>
+
+#include "common.h"
+
+int main(int argc, const char **argv)
+{
+	NET_API_STATUS status;
+	struct libnetapi_ctx *ctx = NULL;
+	const char *hostname = NULL;
+	const char *username = NULL;
+	uint32_t level = 0;
+	uint8_t *buffer = NULL;
+	uint32_t num_entries = 0;
+	const char **names = NULL;
+	int i = 0;
+	size_t buf_size = 0;
+
+	struct GROUP_USERS_INFO_0 *g0 = NULL;
+	struct GROUP_USERS_INFO_1 *g1 = NULL;
+
+	poptContext pc;
+	int opt;
+
+	struct poptOption long_options[] = {
+		POPT_AUTOHELP
+		POPT_COMMON_LIBNETAPI_EXAMPLES
+		POPT_TABLEEND
+	};
+
+	status = libnetapi_init(&ctx);
+	if (status != 0) {
+		return status;
+	}
+
+	pc = poptGetContext("user_setgroups", argc, argv, long_options, 0);
+
+	poptSetOtherOptionHelp(pc, "hostname username group1 group2 ...");
+	while((opt = poptGetNextOpt(pc)) != -1) {
+	}
+
+	if (!poptPeekArg(pc)) {
+		poptPrintHelp(pc, stderr, 0);
+		goto out;
+	}
+	hostname = poptGetArg(pc);
+
+	if (!poptPeekArg(pc)) {
+		poptPrintHelp(pc, stderr, 0);
+		goto out;
+	}
+	username = poptGetArg(pc);
+
+	if (!poptPeekArg(pc)) {
+		poptPrintHelp(pc, stderr, 0);
+		goto out;
+	}
+
+	names = poptGetArgs(pc);
+	for (i=0; names[i] != NULL; i++) {
+		num_entries++;
+	}
+
+	switch (level) {
+		case 0:
+			buf_size = sizeof(struct GROUP_USERS_INFO_0) * num_entries;
+
+			status = NetApiBufferAllocate(buf_size, (void **)&g0);
+			if (status) {
+				printf("NetApiBufferAllocate failed with: %s\n",
+					libnetapi_get_error_string(ctx, status));
+				goto out;
+			}
+
+			for (i=0; i<num_entries; i++) {
+				g0[i].grui0_name = names[i];
+			}
+
+			buffer = (uint8_t *)g0;
+			break;
+		case 1:
+			buf_size = sizeof(struct GROUP_USERS_INFO_1) * num_entries;
+
+			status = NetApiBufferAllocate(buf_size, (void **)&g1);
+			if (status) {
+				printf("NetApiBufferAllocate failed with: %s\n",
+					libnetapi_get_error_string(ctx, status));
+				goto out;
+			}
+
+			for (i=0; i<num_entries; i++) {
+				g1[i].grui1_name = names[i];
+				g1[i].grui1_attributes = 0; /* ? */
+			}
+
+			buffer = (uint8_t *)g1;
+			break;
+		default:
+			break;
+	}
+
+	/* NetUserSetGroups */
+
+	status = NetUserSetGroups(hostname,
+				  username,
+				  level,
+				  buffer,
+				  num_entries);
+	if (status != 0) {
+		printf("NetUserSetGroups failed with: %s\n",
+			libnetapi_get_error_string(ctx, status));
+	}


-- 
Samba Shared Repository


More information about the samba-cvs mailing list