/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- main
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetLocalGroupSetInfo 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 LOCALGROUP_INFO_0 g0;
39 struct LOCALGROUP_INFO_1 g1;
40 struct LOCALGROUP_INFO_1002 g1002;
41 const char *newname = NULL;
42 const char *newcomment = NULL;
43 uint32_t parm_err = 0;
44
45 poptContext pc;
46 int opt;
47
48 struct poptOption long_options[] = {
49 POPT_AUTOHELP
50 POPT_COMMON_LIBNETAPI_EXAMPLES
51 { "newname", 0, POPT_ARG_STRING, NULL, 'n', "New Local Group Name", "NEWNAME" },
52 { "newcomment", 0, POPT_ARG_STRING, NULL, 'c', "New Local Group Comment", "NETCOMMENT" },
53 POPT_TABLEEND
54 };
55
56 status = libnetapi_init(&ctx);
57 if (status != 0) {
58 return status;
59 }
60
61 pc = poptGetContext("localgroup_setinfo", argc, argv, long_options, 0);
62
63 poptSetOtherOptionHelp(pc, "hostname groupname level");
64 while((opt = poptGetNextOpt(pc)) != -1) {
65 switch (opt) {
66 case 'n':
67 newname = poptGetOptArg(pc);
68 break;
69 case 'c':
70 newcomment = poptGetOptArg(pc);
71 break;
72 }
73
74 }
75
76 if (!poptPeekArg(pc)) {
77 poptPrintHelp(pc, stderr, 0);
78 goto out;
79 }
80 hostname = poptGetArg(pc);
81
82 if (!poptPeekArg(pc)) {
83 poptPrintHelp(pc, stderr, 0);
84 goto out;
85 }
86 groupname = poptGetArg(pc);
87
88 if (poptPeekArg(pc)) {
89 level = atoi(poptGetArg(pc));
90 }
91
92 if (newname && !newcomment) {
93 g0.lgrpi0_name = newname;
94 buffer = (uint8_t *)&g0;
95 level = 0;
96 } else if (newcomment && !newname) {
97 g1002.lgrpi1002_comment = newcomment;
98 buffer = (uint8_t *)&g1002;
99 level = 1002;
100 } else if (newname && newcomment) {
101 g1.lgrpi1_name = newname;
102 g1.lgrpi1_comment = newcomment;
103 buffer = (uint8_t *)&g1;
104 level = 1;
105 } else {
106 printf("not enough input\n");
107 goto out;
108 }
109
110 /* NetLocalGroupSetInfo */
111
112 status = NetLocalGroupSetInfo(hostname,
113 groupname,
114 level,
115 buffer,
116 &parm_err);
117 if (status != 0) {
118 printf("NetLocalGroupSetInfo failed with: %s\n",
119 libnetapi_get_error_string(ctx, status));
120 goto out;
121 }
122
123 out:
124 libnetapi_free(ctx);
125 poptFreeContext(pc);
126
127 return status;
128 }