1 /*
2 * Unix SMB/CIFS implementation.
3 * NetLocalGroupGetInfo query
4 * Copyright (C) Guenther Deschner 2008
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20 #include <sys/types.h>
21 #include <inttypes.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include <netapi.h>
27
28 #include "common.h"
29
main(int argc,const char ** argv)30 int main(int argc, const char **argv)
31 {
32 NET_API_STATUS status;
33 struct libnetapi_ctx *ctx = NULL;
34 const char *hostname = NULL;
35 const char *groupname = NULL;
36 uint8_t *buffer = NULL;
37 uint32_t level = 0;
38 struct LOCALGROUP_INFO_0 *g0;
39 struct LOCALGROUP_INFO_1 *g1;
40 struct LOCALGROUP_INFO_1002 *g1002;
41
42 poptContext pc;
43 int opt;
44
45 struct poptOption long_options[] = {
46 POPT_AUTOHELP
47 POPT_COMMON_LIBNETAPI_EXAMPLES
48 POPT_TABLEEND
49 };
50
51 status = libnetapi_init(&ctx);
52 if (status != 0) {
53 return status;
54 }
55
56 pc = poptGetContext("localgroup_getinfo", argc, argv, long_options, 0);
57
58 poptSetOtherOptionHelp(pc, "hostname groupname level");
59 while((opt = poptGetNextOpt(pc)) != -1) {
60 }
61
62 if (!poptPeekArg(pc)) {
63 poptPrintHelp(pc, stderr, 0);
64 goto out;
65 }
66 hostname = poptGetArg(pc);
67
68 if (!poptPeekArg(pc)) {
69 poptPrintHelp(pc, stderr, 0);
70 goto out;
71 }
72 groupname = poptGetArg(pc);
73
74 if (poptPeekArg(pc)) {
75 level = atoi(poptGetArg(pc));
76 }
77
78 /* NetLocalGroupGetInfo */
79
80 status = NetLocalGroupGetInfo(hostname,
81 groupname,
82 level,
83 &buffer);
84 if (status != 0) {
85 printf("NetLocalGroupGetInfo failed with: %s\n",
86 libnetapi_get_error_string(ctx, status));
87 goto out;
88 }
89
90 switch (level) {
91 case 0:
92 g0 = (struct LOCALGROUP_INFO_0 *)buffer;
93 printf("name: %s\n", g0->lgrpi0_name);
94 break;
95 case 1:
96 g1 = (struct LOCALGROUP_INFO_1 *)buffer;
97 printf("name: %s\n", g1->lgrpi1_name);
98 printf("comment: %s\n", g1->lgrpi1_comment);
99 break;
100 case 1002:
101 g1002 = (struct LOCALGROUP_INFO_1002 *)buffer;
102 printf("comment: %s\n", g1002->lgrpi1002_comment);
103 break;
104 }
105 NetApiBufferFree(buffer);
106
107 out:
108 libnetapi_free(ctx);
109 poptFreeContext(pc);
110
111 return status;
112 }
113