2
* Unix SMB/CIFS implementation.
3
* NetLocalGroupDelMembers 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;
36
struct LOCALGROUP_MEMBERS_INFO_0 *g0;
37
struct LOCALGROUP_MEMBERS_INFO_3 *g3;
38
uint32_t total_entries = 0;
39
uint8_t *buffer = NULL;
41
const char **names = NULL;
47
struct poptOption long_options[] = {
49
POPT_COMMON_LIBNETAPI_EXAMPLES
53
status = libnetapi_init(&ctx);
58
pc = poptGetContext("localgroup_delmembers", argc, argv, long_options, 0);
60
poptSetOtherOptionHelp(pc, "hostname groupname member1 member2 ...");
61
while((opt = poptGetNextOpt(pc)) != -1) {
64
if (!poptPeekArg(pc)) {
65
poptPrintHelp(pc, stderr, 0);
68
hostname = poptGetArg(pc);
70
if (!poptPeekArg(pc)) {
71
poptPrintHelp(pc, stderr, 0);
74
groupname = poptGetArg(pc);
76
if (!poptPeekArg(pc)) {
77
poptPrintHelp(pc, stderr, 0);
81
names = poptGetArgs(pc);
82
for (i=0; names[i] != NULL; i++) {
88
status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_0) * total_entries,
91
printf("NetApiBufferAllocate failed with: %s\n",
92
libnetapi_get_error_string(ctx, status));
96
for (i=0; i<total_entries; i++) {
97
if (!ConvertStringSidToSid(names[i], &g0[i].lgrmi0_sid)) {
98
printf("could not convert sid\n");
103
buffer = (uint8_t *)g0;
106
status = NetApiBufferAllocate(sizeof(struct LOCALGROUP_MEMBERS_INFO_3) * total_entries,
109
printf("NetApiBufferAllocate failed with: %s\n",
110
libnetapi_get_error_string(ctx, status));
114
for (i=0; i<total_entries; i++) {
115
g3[i].lgrmi3_domainandname = names[i];
118
buffer = (uint8_t *)g3;
124
/* NetLocalGroupDelMembers */
126
status = NetLocalGroupDelMembers(hostname,
132
printf("NetLocalGroupDelMembers failed with: %s\n",
133
libnetapi_get_error_string(ctx, status));