source: vendor/current/source3/lib/netapi/share.c

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 13.3 KB
Line 
1/*
2 * Unix SMB/CIFS implementation.
3 * NetApi Share Support
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 "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 "../librpc/gen_ndr/ndr_srvsvc_c.h"
27#include "librpc/gen_ndr/ndr_security.h"
28
29/****************************************************************
30****************************************************************/
31
32static NTSTATUS map_srvsvc_share_info_to_SHARE_INFO_buffer(TALLOC_CTX *mem_ctx,
33 uint32_t level,
34 union srvsvc_NetShareInfo *info,
35 uint8_t **buffer,
36 uint32_t *num_shares)
37{
38 struct SHARE_INFO_0 i0;
39 struct SHARE_INFO_1 i1;
40 struct SHARE_INFO_2 i2;
41 struct SHARE_INFO_501 i501;
42 struct SHARE_INFO_1005 i1005;
43
44 struct srvsvc_NetShareInfo0 *s0;
45 struct srvsvc_NetShareInfo1 *s1;
46 struct srvsvc_NetShareInfo2 *s2;
47 struct srvsvc_NetShareInfo501 *s501;
48 struct srvsvc_NetShareInfo1005 *s1005;
49
50 if (!buffer) {
51 return NT_STATUS_INVALID_PARAMETER;
52 }
53
54 switch (level) {
55 case 0:
56 s0 = info->info0;
57
58 i0.shi0_netname = talloc_strdup(mem_ctx, s0->name);
59
60 ADD_TO_ARRAY(mem_ctx, struct SHARE_INFO_0, i0,
61 (struct SHARE_INFO_0 **)buffer,
62 num_shares);
63 break;
64
65 case 1:
66 s1 = info->info1;
67
68 i1.shi1_netname = talloc_strdup(mem_ctx, s1->name);
69 i1.shi1_type = s1->type;
70 i1.shi1_remark = talloc_strdup(mem_ctx, s1->comment);
71
72 ADD_TO_ARRAY(mem_ctx, struct SHARE_INFO_1, i1,
73 (struct SHARE_INFO_1 **)buffer,
74 num_shares);
75 break;
76
77 case 2:
78 s2 = info->info2;
79
80 i2.shi2_netname = talloc_strdup(mem_ctx, s2->name);
81 i2.shi2_type = s2->type;
82 i2.shi2_remark = talloc_strdup(mem_ctx, s2->comment);
83 i2.shi2_permissions = s2->permissions;
84 i2.shi2_max_uses = s2->max_users;
85 i2.shi2_current_uses = s2->current_users;
86 i2.shi2_path = talloc_strdup(mem_ctx, s2->path);
87 i2.shi2_passwd = talloc_strdup(mem_ctx, s2->password);
88
89 ADD_TO_ARRAY(mem_ctx, struct SHARE_INFO_2, i2,
90 (struct SHARE_INFO_2 **)buffer,
91 num_shares);
92 break;
93
94 case 501:
95 s501 = info->info501;
96
97 i501.shi501_netname = talloc_strdup(mem_ctx, s501->name);
98 i501.shi501_type = s501->type;
99 i501.shi501_remark = talloc_strdup(mem_ctx, s501->comment);
100 i501.shi501_flags = s501->csc_policy;
101
102 ADD_TO_ARRAY(mem_ctx, struct SHARE_INFO_501, i501,
103 (struct SHARE_INFO_501 **)buffer,
104 num_shares);
105 break;
106
107 case 1005:
108 s1005 = info->info1005;
109
110 i1005.shi1005_flags = s1005->dfs_flags;
111
112 ADD_TO_ARRAY(mem_ctx, struct SHARE_INFO_1005, i1005,
113 (struct SHARE_INFO_1005 **)buffer,
114 num_shares);
115 break;
116
117 default:
118 return NT_STATUS_INVALID_PARAMETER;
119 }
120
121 return NT_STATUS_OK;
122}
123
124/****************************************************************
125****************************************************************/
126
127static NTSTATUS map_SHARE_INFO_buffer_to_srvsvc_share_info(TALLOC_CTX *mem_ctx,
128 uint8_t *buffer,
129 uint32_t level,
130 union srvsvc_NetShareInfo *info)
131{
132 struct SHARE_INFO_2 *i2 = NULL;
133 struct SHARE_INFO_502 *i502 = NULL;
134 struct SHARE_INFO_1004 *i1004 = NULL;
135 struct srvsvc_NetShareInfo2 *s2 = NULL;
136 struct srvsvc_NetShareInfo502 *s502 = NULL;
137 struct srvsvc_NetShareInfo1004 *s1004 = NULL;
138
139 if (!buffer) {
140 return NT_STATUS_INVALID_PARAMETER;
141 }
142
143 switch (level) {
144 case 2:
145 i2 = (struct SHARE_INFO_2 *)buffer;
146
147 s2 = talloc(mem_ctx, struct srvsvc_NetShareInfo2);
148 NT_STATUS_HAVE_NO_MEMORY(s2);
149
150 s2->name = i2->shi2_netname;
151 s2->type = i2->shi2_type;
152 s2->comment = i2->shi2_remark;
153 s2->permissions = i2->shi2_permissions;
154 s2->max_users = i2->shi2_max_uses;
155 s2->current_users = i2->shi2_current_uses;
156 s2->path = i2->shi2_path;
157 s2->password = i2->shi2_passwd;
158
159 info->info2 = s2;
160
161 break;
162
163 case 502:
164 i502 = (struct SHARE_INFO_502 *)buffer;
165
166 s502 = talloc(mem_ctx, struct srvsvc_NetShareInfo502);
167 NT_STATUS_HAVE_NO_MEMORY(s502);
168
169 s502->name = i502->shi502_netname;
170 s502->type = i502->shi502_type;
171 s502->comment = i502->shi502_remark;
172 s502->permissions = i502->shi502_permissions;
173 s502->max_users = i502->shi502_max_uses;
174 s502->current_users = i502->shi502_current_uses;
175 s502->path = i502->shi502_path;
176 s502->password = i502->shi502_passwd;
177 s502->sd_buf.sd_size =
178 ndr_size_security_descriptor(i502->shi502_security_descriptor, 0);
179 s502->sd_buf.sd = i502->shi502_security_descriptor;
180
181 info->info502 = s502;
182
183 break;
184
185 case 1004:
186 i1004 = (struct SHARE_INFO_1004 *)buffer;
187
188 s1004 = talloc(mem_ctx, struct srvsvc_NetShareInfo1004);
189 NT_STATUS_HAVE_NO_MEMORY(s1004);
190
191 s1004->comment = i1004->shi1004_remark;
192
193 info->info1004 = s1004;
194
195 break;
196 default:
197 return NT_STATUS_INVALID_PARAMETER;
198 }
199
200 return NT_STATUS_OK;
201}
202
203/****************************************************************
204****************************************************************/
205
206WERROR NetShareAdd_r(struct libnetapi_ctx *ctx,
207 struct NetShareAdd *r)
208{
209 WERROR werr;
210 NTSTATUS status;
211 union srvsvc_NetShareInfo info;
212 struct dcerpc_binding_handle *b;
213
214 if (!r->in.buffer) {
215 return WERR_INVALID_PARAM;
216 }
217
218 switch (r->in.level) {
219 case 2:
220 case 502:
221 break;
222 case 503:
223 return WERR_NOT_SUPPORTED;
224 default:
225 return WERR_UNKNOWN_LEVEL;
226 }
227
228 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
229 &ndr_table_srvsvc,
230 &b);
231 if (!W_ERROR_IS_OK(werr)) {
232 goto done;
233 }
234
235 status = map_SHARE_INFO_buffer_to_srvsvc_share_info(ctx,
236 r->in.buffer,
237 r->in.level,
238 &info);
239 if (!NT_STATUS_IS_OK(status)) {
240 werr = ntstatus_to_werror(status);
241 goto done;
242 }
243
244 status = dcerpc_srvsvc_NetShareAdd(b, talloc_tos(),
245 r->in.server_name,
246 r->in.level,
247 &info,
248 r->out.parm_err,
249 &werr);
250 if (!NT_STATUS_IS_OK(status)) {
251 werr = ntstatus_to_werror(status);
252 goto done;
253 }
254
255 if (!W_ERROR_IS_OK(werr)) {
256 goto done;
257 }
258
259 done:
260 return werr;
261}
262
263/****************************************************************
264****************************************************************/
265
266WERROR NetShareAdd_l(struct libnetapi_ctx *ctx,
267 struct NetShareAdd *r)
268{
269 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareAdd);
270}
271
272/****************************************************************
273****************************************************************/
274
275WERROR NetShareDel_r(struct libnetapi_ctx *ctx,
276 struct NetShareDel *r)
277{
278 WERROR werr;
279 NTSTATUS status;
280 struct dcerpc_binding_handle *b;
281
282 if (!r->in.net_name) {
283 return WERR_INVALID_PARAM;
284 }
285
286 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
287 &ndr_table_srvsvc,
288 &b);
289 if (!W_ERROR_IS_OK(werr)) {
290 goto done;
291 }
292
293 status = dcerpc_srvsvc_NetShareDel(b, talloc_tos(),
294 r->in.server_name,
295 r->in.net_name,
296 r->in.reserved,
297 &werr);
298 if (!NT_STATUS_IS_OK(status)) {
299 werr = ntstatus_to_werror(status);
300 goto done;
301 }
302
303 done:
304 return werr;
305}
306
307/****************************************************************
308****************************************************************/
309
310WERROR NetShareDel_l(struct libnetapi_ctx *ctx,
311 struct NetShareDel *r)
312{
313 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareDel);
314}
315
316/****************************************************************
317****************************************************************/
318
319WERROR NetShareEnum_r(struct libnetapi_ctx *ctx,
320 struct NetShareEnum *r)
321{
322 WERROR werr;
323 NTSTATUS status;
324 struct srvsvc_NetShareInfoCtr info_ctr;
325 struct srvsvc_NetShareCtr0 ctr0;
326 struct srvsvc_NetShareCtr1 ctr1;
327 struct srvsvc_NetShareCtr2 ctr2;
328 uint32_t i;
329 struct dcerpc_binding_handle *b;
330
331 if (!r->out.buffer) {
332 return WERR_INVALID_PARAM;
333 }
334
335 switch (r->in.level) {
336 case 0:
337 case 1:
338 case 2:
339 break;
340 case 502:
341 case 503:
342 return WERR_NOT_SUPPORTED;
343 default:
344 return WERR_UNKNOWN_LEVEL;
345 }
346
347 ZERO_STRUCT(info_ctr);
348
349 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
350 &ndr_table_srvsvc,
351 &b);
352 if (!W_ERROR_IS_OK(werr)) {
353 goto done;
354 }
355
356 info_ctr.level = r->in.level;
357 switch (r->in.level) {
358 case 0:
359 ZERO_STRUCT(ctr0);
360 info_ctr.ctr.ctr0 = &ctr0;
361 break;
362 case 1:
363 ZERO_STRUCT(ctr1);
364 info_ctr.ctr.ctr1 = &ctr1;
365 break;
366 case 2:
367 ZERO_STRUCT(ctr2);
368 info_ctr.ctr.ctr2 = &ctr2;
369 break;
370 }
371
372 status = dcerpc_srvsvc_NetShareEnumAll(b, talloc_tos(),
373 r->in.server_name,
374 &info_ctr,
375 r->in.prefmaxlen,
376 r->out.total_entries,
377 r->out.resume_handle,
378 &werr);
379 if (!NT_STATUS_IS_OK(status)) {
380 werr = ntstatus_to_werror(status);
381 goto done;
382 }
383
384 if (!W_ERROR_IS_OK(werr) && !W_ERROR_EQUAL(werr, WERR_MORE_DATA)) {
385 goto done;
386 }
387
388 for (i=0; i < info_ctr.ctr.ctr1->count; i++) {
389 union srvsvc_NetShareInfo _i = {0};
390 switch (r->in.level) {
391 case 0:
392 _i.info0 = &info_ctr.ctr.ctr0->array[i];
393 break;
394 case 1:
395 _i.info1 = &info_ctr.ctr.ctr1->array[i];
396 break;
397 case 2:
398 _i.info2 = &info_ctr.ctr.ctr2->array[i];
399 break;
400 }
401
402 status = map_srvsvc_share_info_to_SHARE_INFO_buffer(ctx,
403 r->in.level,
404 &_i,
405 r->out.buffer,
406 r->out.entries_read);
407 if (!NT_STATUS_IS_OK(status)) {
408 werr = ntstatus_to_werror(status);
409 goto done;
410 }
411 }
412
413 done:
414 return werr;
415}
416
417/****************************************************************
418****************************************************************/
419
420WERROR NetShareEnum_l(struct libnetapi_ctx *ctx,
421 struct NetShareEnum *r)
422{
423 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareEnum);
424}
425
426/****************************************************************
427****************************************************************/
428
429WERROR NetShareGetInfo_r(struct libnetapi_ctx *ctx,
430 struct NetShareGetInfo *r)
431{
432 WERROR werr;
433 NTSTATUS status;
434 union srvsvc_NetShareInfo info;
435 uint32_t num_entries = 0;
436 struct dcerpc_binding_handle *b;
437
438 if (!r->in.net_name || !r->out.buffer) {
439 return WERR_INVALID_PARAM;
440 }
441
442 switch (r->in.level) {
443 case 0:
444 case 1:
445 case 2:
446 case 501:
447 case 1005:
448 break;
449 case 502:
450 case 503:
451 return WERR_NOT_SUPPORTED;
452 default:
453 return WERR_UNKNOWN_LEVEL;
454 }
455
456 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
457 &ndr_table_srvsvc,
458 &b);
459 if (!W_ERROR_IS_OK(werr)) {
460 goto done;
461 }
462
463 status = dcerpc_srvsvc_NetShareGetInfo(b, talloc_tos(),
464 r->in.server_name,
465 r->in.net_name,
466 r->in.level,
467 &info,
468 &werr);
469 if (!NT_STATUS_IS_OK(status)) {
470 werr = ntstatus_to_werror(status);
471 goto done;
472 }
473
474 if (!W_ERROR_IS_OK(werr)) {
475 goto done;
476 }
477
478 status = map_srvsvc_share_info_to_SHARE_INFO_buffer(ctx,
479 r->in.level,
480 &info,
481 r->out.buffer,
482 &num_entries);
483 if (!NT_STATUS_IS_OK(status)) {
484 werr = ntstatus_to_werror(status);
485 }
486
487 done:
488 return werr;
489}
490
491/****************************************************************
492****************************************************************/
493
494WERROR NetShareGetInfo_l(struct libnetapi_ctx *ctx,
495 struct NetShareGetInfo *r)
496{
497 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareGetInfo);
498}
499
500/****************************************************************
501****************************************************************/
502
503WERROR NetShareSetInfo_r(struct libnetapi_ctx *ctx,
504 struct NetShareSetInfo *r)
505{
506 WERROR werr;
507 NTSTATUS status;
508 union srvsvc_NetShareInfo info;
509 struct dcerpc_binding_handle *b;
510
511 if (!r->in.buffer) {
512 return WERR_INVALID_PARAM;
513 }
514
515 switch (r->in.level) {
516 case 2:
517 case 1004:
518 break;
519 case 1:
520 case 502:
521 case 503:
522 case 1005:
523 case 1006:
524 case 1501:
525 return WERR_NOT_SUPPORTED;
526 default:
527 return WERR_UNKNOWN_LEVEL;
528 }
529
530 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
531 &ndr_table_srvsvc,
532 &b);
533 if (!W_ERROR_IS_OK(werr)) {
534 goto done;
535 }
536
537 status = map_SHARE_INFO_buffer_to_srvsvc_share_info(ctx,
538 r->in.buffer,
539 r->in.level,
540 &info);
541 if (!NT_STATUS_IS_OK(status)) {
542 werr = ntstatus_to_werror(status);
543 goto done;
544 }
545
546 status = dcerpc_srvsvc_NetShareSetInfo(b, talloc_tos(),
547 r->in.server_name,
548 r->in.net_name,
549 r->in.level,
550 &info,
551 r->out.parm_err,
552 &werr);
553 if (!NT_STATUS_IS_OK(status)) {
554 werr = ntstatus_to_werror(status);
555 goto done;
556 }
557
558 if (!W_ERROR_IS_OK(werr)) {
559 goto done;
560 }
561
562 done:
563 return werr;
564}
565
566/****************************************************************
567****************************************************************/
568
569WERROR NetShareSetInfo_l(struct libnetapi_ctx *ctx,
570 struct NetShareSetInfo *r)
571{
572 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareSetInfo);
573}
Note: See TracBrowser for help on using the repository browser.