/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- main
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetGroupGetInfo 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
30 int main(int argc, const char **argv)
/* [<][>][^][v][top][bottom][index][help] */
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 GROUP_INFO_0 *g0;
39 struct GROUP_INFO_1 *g1;
40 struct GROUP_INFO_2 *g2;
41 struct GROUP_INFO_3 *g3;
42 char *sid_str = NULL;
43
44 poptContext pc;
45 int opt;
46
47 struct poptOption long_options[] = {
48 POPT_AUTOHELP
49 POPT_COMMON_LIBNETAPI_EXAMPLES
50 POPT_TABLEEND
51 };
52
53 status = libnetapi_init(&ctx);
54 if (status != 0) {
55 return status;
56 }
57
58 pc = poptGetContext("group_getinfo", argc, argv, long_options, 0);
59
60 poptSetOtherOptionHelp(pc, "hostname groupname level");
61 while((opt = poptGetNextOpt(pc)) != -1) {
62 }
63
64 if (!poptPeekArg(pc)) {
65 poptPrintHelp(pc, stderr, 0);
66 goto out;
67 }
68 hostname = poptGetArg(pc);
69
70 if (!poptPeekArg(pc)) {
71 poptPrintHelp(pc, stderr, 0);
72 goto out;
73 }
74 groupname = poptGetArg(pc);
75
76 if (poptPeekArg(pc)) {
77 level = atoi(poptGetArg(pc));
78 }
79
80 /* NetGroupGetInfo */
81
82 status = NetGroupGetInfo(hostname,
83 groupname,
84 level,
85 &buffer);
86 if (status != 0) {
87 printf("NetGroupGetInfo failed with: %s\n",
88 libnetapi_get_error_string(ctx, status));
89 goto out;
90 }
91
92 switch (level) {
93 case 0:
94 g0 = (struct GROUP_INFO_0 *)buffer;
95 printf("name: %s\n", g0->grpi0_name);
96 break;
97 case 1:
98 g1 = (struct GROUP_INFO_1 *)buffer;
99 printf("name: %s\n", g1->grpi1_name);
100 printf("comment: %s\n", g1->grpi1_comment);
101 break;
102 case 2:
103 g2 = (struct GROUP_INFO_2 *)buffer;
104 printf("name: %s\n", g2->grpi2_name);
105 printf("comment: %s\n", g2->grpi2_comment);
106 printf("group_id: %d\n", g2->grpi2_group_id);
107 printf("attributes: %d\n", g2->grpi2_attributes);
108 break;
109 case 3:
110 g3 = (struct GROUP_INFO_3 *)buffer;
111 printf("name: %s\n", g3->grpi3_name);
112 printf("comment: %s\n", g3->grpi3_comment);
113 if (ConvertSidToStringSid(g3->grpi3_group_sid,
114 &sid_str)) {
115 printf("group_sid: %s\n", sid_str);
116 free(sid_str);
117 }
118 printf("attributes: %d\n", g3->grpi3_attributes);
119 break;
120 }
121
122 out:
123 libnetapi_free(ctx);
124 poptFreeContext(pc);
125
126 return status;
127 }