2
* Unix SMB/CIFS implementation.
3
* NetGroupSetUsers query
4
* Copyright (C) Guenther Deschner 2008
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, see <http://www.gnu.org/licenses/>.
20
#include <sys/types.h>
30
int main(int argc, const char **argv)
32
NET_API_STATUS status;
33
struct libnetapi_ctx *ctx = NULL;
34
const char *hostname = NULL;
35
const char *groupname = NULL;
37
uint8_t *buffer = NULL;
38
uint32_t num_entries = 0;
39
const char **names = NULL;
43
struct GROUP_USERS_INFO_0 *g0 = NULL;
44
struct GROUP_USERS_INFO_1 *g1 = NULL;
49
struct poptOption long_options[] = {
51
POPT_COMMON_LIBNETAPI_EXAMPLES
55
status = libnetapi_init(&ctx);
60
pc = poptGetContext("group_setusers", argc, argv, long_options, 0);
62
poptSetOtherOptionHelp(pc, "hostname groupname level");
63
while((opt = poptGetNextOpt(pc)) != -1) {
66
if (!poptPeekArg(pc)) {
67
poptPrintHelp(pc, stderr, 0);
70
hostname = poptGetArg(pc);
72
if (!poptPeekArg(pc)) {
73
poptPrintHelp(pc, stderr, 0);
76
groupname = poptGetArg(pc);
78
if (!poptPeekArg(pc)) {
79
poptPrintHelp(pc, stderr, 0);
83
names = poptGetArgs(pc);
84
for (i=0; names[i] != NULL; i++) {
90
buf_size = sizeof(struct GROUP_USERS_INFO_0) * num_entries;
92
status = NetApiBufferAllocate(buf_size, (void **)&g0);
94
printf("NetApiBufferAllocate failed with: %s\n",
95
libnetapi_get_error_string(ctx, status));
99
for (i=0; i<num_entries; i++) {
100
g0[i].grui0_name = names[i];
103
buffer = (uint8_t *)g0;
106
buf_size = sizeof(struct GROUP_USERS_INFO_1) * num_entries;
108
status = NetApiBufferAllocate(buf_size, (void **)&g1);
110
printf("NetApiBufferAllocate failed with: %s\n",
111
libnetapi_get_error_string(ctx, status));
115
for (i=0; i<num_entries; i++) {
116
g1[i].grui1_name = names[i];
119
buffer = (uint8_t *)g1;
125
/* NetGroupSetUsers */
127
status = NetGroupSetUsers(hostname,
133
printf("NetGroupSetUsers failed with: %s\n",
134
libnetapi_get_error_string(ctx, status));