/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- main
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetUserModalsSet 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 uint8_t *buffer = NULL;
36 uint32_t level = 0;
37 uint32_t value = 0;
38 uint32_t parm_err = 0;
39
40 struct USER_MODALS_INFO_0 u0;
41 struct USER_MODALS_INFO_1 u1;
42 struct USER_MODALS_INFO_2 u2;
43 struct USER_MODALS_INFO_3 u3;
44 struct USER_MODALS_INFO_1001 u1001;
45 struct USER_MODALS_INFO_1002 u1002;
46 struct USER_MODALS_INFO_1003 u1003;
47 struct USER_MODALS_INFO_1004 u1004;
48 struct USER_MODALS_INFO_1005 u1005;
49 struct USER_MODALS_INFO_1006 u1006;
50 struct USER_MODALS_INFO_1007 u1007;
51
52 poptContext pc;
53 int opt;
54
55 struct poptOption long_options[] = {
56 POPT_AUTOHELP
57 POPT_COMMON_LIBNETAPI_EXAMPLES
58 POPT_TABLEEND
59 };
60
61 status = libnetapi_init(&ctx);
62 if (status != 0) {
63 return status;
64 }
65
66 pc = poptGetContext("user_modalsset", argc, argv, long_options, 0);
67
68 poptSetOtherOptionHelp(pc, "hostname level value");
69 while((opt = poptGetNextOpt(pc)) != -1) {
70 }
71
72 if (!poptPeekArg(pc)) {
73 poptPrintHelp(pc, stderr, 0);
74 goto out;
75 }
76 hostname = poptGetArg(pc);
77
78 if (poptPeekArg(pc)) {
79 level = atoi(poptGetArg(pc));
80 }
81
82 if (poptPeekArg(pc)) {
83 value = atoi(poptGetArg(pc));
84 }
85
86 switch (level) {
87 case 0:
88 u0.usrmod0_min_passwd_len = 0;
89 u0.usrmod0_max_passwd_age = (86400 * 30); /* once a month */
90 u0.usrmod0_min_passwd_age = 0;
91 u0.usrmod0_force_logoff = TIMEQ_FOREVER;
92 u0.usrmod0_password_hist_len = 0;
93 buffer = (uint8_t *)&u0;
94 break;
95 case 1:
96 case 2:
97 case 3:
98 break;
99 case 1001:
100 u1001.usrmod1001_min_passwd_len = 0;
101 buffer = (uint8_t *)&u1001;
102 break;
103 case 1002:
104 u1002.usrmod1002_max_passwd_age = 0;
105 buffer = (uint8_t *)&u1002;
106 break;
107 case 1003:
108 u1003.usrmod1003_min_passwd_age = (86400 * 30); /* once a month */
109 buffer = (uint8_t *)&u1003;
110 break;
111 case 1004:
112 u1004.usrmod1004_force_logoff = TIMEQ_FOREVER;
113 buffer = (uint8_t *)&u1004;
114 break;
115 case 1005:
116 u1005.usrmod1005_password_hist_len = 0;
117 buffer = (uint8_t *)&u1005;
118 break;
119 case 1006:
120 case 1007:
121 default:
122 break;
123 }
124
125 /* NetUserModalsSet */
126
127 status = NetUserModalsSet(hostname,
128 level,
129 buffer,
130 &parm_err);
131 if (status != 0) {
132 printf("NetUserModalsSet failed with: %s\n",
133 libnetapi_get_error_string(ctx, status));
134 goto out;
135 }
136
137 out:
138 libnetapi_free(ctx);
139 poptFreeContext(pc);
140
141 return status;
142 }