1 | /*
|
---|
2 | * Unix SMB/CIFS implementation.
|
---|
3 | * NetApi Server Support
|
---|
4 | * Copyright (C) Guenther Deschner 2007
|
---|
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 "includes.h"
|
---|
21 |
|
---|
22 | #include "librpc/gen_ndr/libnetapi.h"
|
---|
23 | #include "lib/netapi/netapi.h"
|
---|
24 | #include "lib/netapi/netapi_private.h"
|
---|
25 | #include "lib/netapi/libnetapi.h"
|
---|
26 | #include "libnet/libnet.h"
|
---|
27 |
|
---|
28 | /****************************************************************
|
---|
29 | ****************************************************************/
|
---|
30 |
|
---|
31 | static WERROR NetServerGetInfo_l_101(struct libnetapi_ctx *ctx,
|
---|
32 | uint8_t **buffer)
|
---|
33 | {
|
---|
34 | struct SERVER_INFO_101 i;
|
---|
35 |
|
---|
36 | i.sv101_platform_id = PLATFORM_ID_NT;
|
---|
37 | i.sv101_name = global_myname();
|
---|
38 | i.sv101_version_major = lp_major_announce_version();
|
---|
39 | i.sv101_version_minor = lp_minor_announce_version();
|
---|
40 | i.sv101_type = lp_default_server_announce();
|
---|
41 | i.sv101_comment = lp_serverstring();
|
---|
42 |
|
---|
43 | *buffer = (uint8_t *)talloc_memdup(ctx, &i, sizeof(i));
|
---|
44 | if (!*buffer) {
|
---|
45 | return WERR_NOMEM;
|
---|
46 | }
|
---|
47 |
|
---|
48 | return WERR_OK;
|
---|
49 | }
|
---|
50 |
|
---|
51 | /****************************************************************
|
---|
52 | ****************************************************************/
|
---|
53 |
|
---|
54 | static WERROR NetServerGetInfo_l_1005(struct libnetapi_ctx *ctx,
|
---|
55 | uint8_t **buffer)
|
---|
56 | {
|
---|
57 | struct SERVER_INFO_1005 info1005;
|
---|
58 |
|
---|
59 | info1005.sv1005_comment = lp_serverstring();
|
---|
60 | *buffer = (uint8_t *)talloc_memdup(ctx, &info1005, sizeof(info1005));
|
---|
61 | if (!*buffer) {
|
---|
62 | return WERR_NOMEM;
|
---|
63 | }
|
---|
64 |
|
---|
65 | return WERR_OK;
|
---|
66 | }
|
---|
67 |
|
---|
68 | /****************************************************************
|
---|
69 | ****************************************************************/
|
---|
70 |
|
---|
71 | WERROR NetServerGetInfo_l(struct libnetapi_ctx *ctx,
|
---|
72 | struct NetServerGetInfo *r)
|
---|
73 | {
|
---|
74 | switch (r->in.level) {
|
---|
75 | case 101:
|
---|
76 | return NetServerGetInfo_l_101(ctx, r->out.buffer);
|
---|
77 | case 1005:
|
---|
78 | return NetServerGetInfo_l_1005(ctx, r->out.buffer);
|
---|
79 | default:
|
---|
80 | return WERR_UNKNOWN_LEVEL;
|
---|
81 | }
|
---|
82 |
|
---|
83 | return WERR_UNKNOWN_LEVEL;
|
---|
84 | }
|
---|
85 |
|
---|
86 | /****************************************************************
|
---|
87 | ****************************************************************/
|
---|
88 |
|
---|
89 | static NTSTATUS map_server_info_to_SERVER_INFO_buffer(TALLOC_CTX *mem_ctx,
|
---|
90 | uint32_t level,
|
---|
91 | union srvsvc_NetSrvInfo *i,
|
---|
92 | uint8_t **buffer)
|
---|
93 | {
|
---|
94 | struct SERVER_INFO_100 i100;
|
---|
95 | struct SERVER_INFO_101 i101;
|
---|
96 | struct SERVER_INFO_102 i102;
|
---|
97 | struct SERVER_INFO_1005 i1005;
|
---|
98 |
|
---|
99 | uint32_t num_info = 0;
|
---|
100 |
|
---|
101 | switch (level) {
|
---|
102 | case 100:
|
---|
103 | i100.sv100_platform_id = i->info100->platform_id;
|
---|
104 | i100.sv100_name = talloc_strdup(mem_ctx, i->info100->server_name);
|
---|
105 |
|
---|
106 | ADD_TO_ARRAY(mem_ctx, struct SERVER_INFO_100, i100,
|
---|
107 | (struct SERVER_INFO_100 **)buffer,
|
---|
108 | &num_info);
|
---|
109 | break;
|
---|
110 |
|
---|
111 | case 101:
|
---|
112 | i101.sv101_platform_id = i->info101->platform_id;
|
---|
113 | i101.sv101_name = talloc_strdup(mem_ctx, i->info101->server_name);
|
---|
114 | i101.sv101_version_major = i->info101->version_major;
|
---|
115 | i101.sv101_version_minor = i->info101->version_minor;
|
---|
116 | i101.sv101_type = i->info101->server_type;
|
---|
117 | i101.sv101_comment = talloc_strdup(mem_ctx, i->info101->comment);
|
---|
118 |
|
---|
119 | ADD_TO_ARRAY(mem_ctx, struct SERVER_INFO_101, i101,
|
---|
120 | (struct SERVER_INFO_101 **)buffer,
|
---|
121 | &num_info);
|
---|
122 | break;
|
---|
123 |
|
---|
124 | case 102:
|
---|
125 | i102.sv102_platform_id = i->info102->platform_id;
|
---|
126 | i102.sv102_name = talloc_strdup(mem_ctx, i->info102->server_name);
|
---|
127 | i102.sv102_version_major = i->info102->version_major;
|
---|
128 | i102.sv102_version_minor = i->info102->version_minor;
|
---|
129 | i102.sv102_type = i->info102->server_type;
|
---|
130 | i102.sv102_comment = talloc_strdup(mem_ctx, i->info102->comment);
|
---|
131 | i102.sv102_users = i->info102->users;
|
---|
132 | i102.sv102_disc = i->info102->disc;
|
---|
133 | i102.sv102_hidden = i->info102->hidden;
|
---|
134 | i102.sv102_announce = i->info102->announce;
|
---|
135 | i102.sv102_anndelta = i->info102->anndelta;
|
---|
136 | i102.sv102_licenses = i->info102->licenses;
|
---|
137 | i102.sv102_userpath = talloc_strdup(mem_ctx, i->info102->userpath);
|
---|
138 |
|
---|
139 | ADD_TO_ARRAY(mem_ctx, struct SERVER_INFO_102, i102,
|
---|
140 | (struct SERVER_INFO_102 **)buffer,
|
---|
141 | &num_info);
|
---|
142 | break;
|
---|
143 |
|
---|
144 | case 1005:
|
---|
145 | i1005.sv1005_comment = talloc_strdup(mem_ctx, i->info1005->comment);
|
---|
146 |
|
---|
147 | ADD_TO_ARRAY(mem_ctx, struct SERVER_INFO_1005, i1005,
|
---|
148 | (struct SERVER_INFO_1005 **)buffer,
|
---|
149 | &num_info);
|
---|
150 | break;
|
---|
151 | default:
|
---|
152 | return NT_STATUS_NOT_SUPPORTED;
|
---|
153 | }
|
---|
154 |
|
---|
155 | return NT_STATUS_OK;
|
---|
156 | }
|
---|
157 |
|
---|
158 | /****************************************************************
|
---|
159 | ****************************************************************/
|
---|
160 |
|
---|
161 | WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx,
|
---|
162 | struct NetServerGetInfo *r)
|
---|
163 | {
|
---|
164 | struct cli_state *cli = NULL;
|
---|
165 | struct rpc_pipe_client *pipe_cli = NULL;
|
---|
166 | NTSTATUS status;
|
---|
167 | WERROR werr;
|
---|
168 | union srvsvc_NetSrvInfo info;
|
---|
169 |
|
---|
170 | if (!r->out.buffer) {
|
---|
171 | return WERR_INVALID_PARAM;
|
---|
172 | }
|
---|
173 |
|
---|
174 | switch (r->in.level) {
|
---|
175 | case 100:
|
---|
176 | case 101:
|
---|
177 | case 102:
|
---|
178 | case 1005:
|
---|
179 | break;
|
---|
180 | default:
|
---|
181 | return WERR_UNKNOWN_LEVEL;
|
---|
182 | }
|
---|
183 |
|
---|
184 | werr = libnetapi_open_pipe(ctx, r->in.server_name,
|
---|
185 | &ndr_table_srvsvc.syntax_id,
|
---|
186 | &cli,
|
---|
187 | &pipe_cli);
|
---|
188 | if (!W_ERROR_IS_OK(werr)) {
|
---|
189 | goto done;
|
---|
190 | }
|
---|
191 |
|
---|
192 | status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, ctx,
|
---|
193 | r->in.server_name,
|
---|
194 | r->in.level,
|
---|
195 | &info,
|
---|
196 | &werr);
|
---|
197 | if (!NT_STATUS_IS_OK(status)) {
|
---|
198 | werr = ntstatus_to_werror(status);
|
---|
199 | goto done;
|
---|
200 | }
|
---|
201 |
|
---|
202 | status = map_server_info_to_SERVER_INFO_buffer(ctx, r->in.level, &info,
|
---|
203 | r->out.buffer);
|
---|
204 | if (!NT_STATUS_IS_OK(status)) {
|
---|
205 | werr = ntstatus_to_werror(status);
|
---|
206 | goto done;
|
---|
207 | }
|
---|
208 |
|
---|
209 | done:
|
---|
210 | return werr;
|
---|
211 | }
|
---|
212 |
|
---|
213 | /****************************************************************
|
---|
214 | ****************************************************************/
|
---|
215 |
|
---|
216 | static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx,
|
---|
217 | struct NetServerSetInfo *r)
|
---|
218 | {
|
---|
219 | WERROR werr;
|
---|
220 | struct smbconf_ctx *conf_ctx;
|
---|
221 | struct srvsvc_NetSrvInfo1005 *info1005;
|
---|
222 |
|
---|
223 | if (!r->in.buffer) {
|
---|
224 | *r->out.parm_error = 1005; /* sure here ? */
|
---|
225 | return WERR_INVALID_PARAM;
|
---|
226 | }
|
---|
227 |
|
---|
228 | info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
|
---|
229 |
|
---|
230 | if (!info1005->comment) {
|
---|
231 | *r->out.parm_error = 1005;
|
---|
232 | return WERR_INVALID_PARAM;
|
---|
233 | }
|
---|
234 |
|
---|
235 | if (!lp_config_backend_is_registry()) {
|
---|
236 | libnetapi_set_error_string(ctx,
|
---|
237 | "Configuration manipulation requested but not "
|
---|
238 | "supported by backend");
|
---|
239 | return WERR_NOT_SUPPORTED;
|
---|
240 | }
|
---|
241 |
|
---|
242 | werr = smbconf_init_reg(ctx, &conf_ctx, NULL);
|
---|
243 | if (!W_ERROR_IS_OK(werr)) {
|
---|
244 | goto done;
|
---|
245 | }
|
---|
246 |
|
---|
247 | werr = smbconf_set_global_parameter(conf_ctx, "server string",
|
---|
248 | info1005->comment);
|
---|
249 |
|
---|
250 | done:
|
---|
251 | smbconf_shutdown(conf_ctx);
|
---|
252 | return werr;
|
---|
253 | }
|
---|
254 |
|
---|
255 | /****************************************************************
|
---|
256 | ****************************************************************/
|
---|
257 |
|
---|
258 | WERROR NetServerSetInfo_l(struct libnetapi_ctx *ctx,
|
---|
259 | struct NetServerSetInfo *r)
|
---|
260 | {
|
---|
261 | switch (r->in.level) {
|
---|
262 | case 1005:
|
---|
263 | return NetServerSetInfo_l_1005(ctx, r);
|
---|
264 | default:
|
---|
265 | return WERR_UNKNOWN_LEVEL;
|
---|
266 | }
|
---|
267 |
|
---|
268 | return WERR_UNKNOWN_LEVEL;
|
---|
269 | }
|
---|
270 |
|
---|
271 | /****************************************************************
|
---|
272 | ****************************************************************/
|
---|
273 |
|
---|
274 | WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx,
|
---|
275 | struct NetServerSetInfo *r)
|
---|
276 | {
|
---|
277 | struct cli_state *cli = NULL;
|
---|
278 | struct rpc_pipe_client *pipe_cli = NULL;
|
---|
279 | NTSTATUS status;
|
---|
280 | WERROR werr;
|
---|
281 | union srvsvc_NetSrvInfo info;
|
---|
282 |
|
---|
283 | werr = libnetapi_open_pipe(ctx, r->in.server_name,
|
---|
284 | &ndr_table_srvsvc.syntax_id,
|
---|
285 | &cli,
|
---|
286 | &pipe_cli);
|
---|
287 | if (!W_ERROR_IS_OK(werr)) {
|
---|
288 | goto done;
|
---|
289 | }
|
---|
290 |
|
---|
291 | switch (r->in.level) {
|
---|
292 | case 1005:
|
---|
293 | info.info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
|
---|
294 | break;
|
---|
295 | default:
|
---|
296 | werr = WERR_NOT_SUPPORTED;
|
---|
297 | goto done;
|
---|
298 | }
|
---|
299 |
|
---|
300 | status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx,
|
---|
301 | r->in.server_name,
|
---|
302 | r->in.level,
|
---|
303 | &info,
|
---|
304 | r->out.parm_error,
|
---|
305 | &werr);
|
---|
306 | if (!NT_STATUS_IS_OK(status)) {
|
---|
307 | werr = ntstatus_to_werror(status);
|
---|
308 | goto done;
|
---|
309 | }
|
---|
310 |
|
---|
311 | done:
|
---|
312 | return werr;
|
---|
313 | }
|
---|
314 |
|
---|
315 | /****************************************************************
|
---|
316 | ****************************************************************/
|
---|
317 |
|
---|
318 | WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx,
|
---|
319 | struct NetRemoteTOD *r)
|
---|
320 | {
|
---|
321 | struct cli_state *cli = NULL;
|
---|
322 | struct rpc_pipe_client *pipe_cli = NULL;
|
---|
323 | NTSTATUS status;
|
---|
324 | WERROR werr;
|
---|
325 | struct srvsvc_NetRemoteTODInfo *info = NULL;
|
---|
326 |
|
---|
327 | werr = libnetapi_open_pipe(ctx, r->in.server_name,
|
---|
328 | &ndr_table_srvsvc.syntax_id,
|
---|
329 | &cli,
|
---|
330 | &pipe_cli);
|
---|
331 | if (!W_ERROR_IS_OK(werr)) {
|
---|
332 | goto done;
|
---|
333 | }
|
---|
334 |
|
---|
335 | status = rpccli_srvsvc_NetRemoteTOD(pipe_cli, ctx,
|
---|
336 | r->in.server_name,
|
---|
337 | &info,
|
---|
338 | &werr);
|
---|
339 | if (!NT_STATUS_IS_OK(status)) {
|
---|
340 | werr = ntstatus_to_werror(status);
|
---|
341 | goto done;
|
---|
342 | }
|
---|
343 |
|
---|
344 | *r->out.buffer = (uint8_t *)talloc_memdup(ctx, info,
|
---|
345 | sizeof(struct srvsvc_NetRemoteTODInfo));
|
---|
346 | W_ERROR_HAVE_NO_MEMORY(*r->out.buffer);
|
---|
347 |
|
---|
348 | done:
|
---|
349 | return werr;
|
---|
350 | }
|
---|
351 |
|
---|
352 | /****************************************************************
|
---|
353 | ****************************************************************/
|
---|
354 |
|
---|
355 | WERROR NetRemoteTOD_l(struct libnetapi_ctx *ctx,
|
---|
356 | struct NetRemoteTOD *r)
|
---|
357 | {
|
---|
358 | LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetRemoteTOD);
|
---|
359 | }
|
---|
360 |
|
---|