2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Guenther Deschner 2008
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.
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.
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/>.
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"
29 /****************************************************************
30 ****************************************************************/
32 static NTSTATUS
map_srvsvc_share_info_to_SHARE_INFO_buffer(TALLOC_CTX
*mem_ctx
,
34 union srvsvc_NetShareInfo
*info
,
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
;
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
;
51 return NT_STATUS_INVALID_PARAMETER
;
58 i0
.shi0_netname
= talloc_strdup(mem_ctx
, s0
->name
);
60 ADD_TO_ARRAY(mem_ctx
, struct SHARE_INFO_0
, i0
,
61 (struct SHARE_INFO_0
**)buffer
,
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
);
72 ADD_TO_ARRAY(mem_ctx
, struct SHARE_INFO_1
, i1
,
73 (struct SHARE_INFO_1
**)buffer
,
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
);
89 ADD_TO_ARRAY(mem_ctx
, struct SHARE_INFO_2
, i2
,
90 (struct SHARE_INFO_2
**)buffer
,
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
;
102 ADD_TO_ARRAY(mem_ctx
, struct SHARE_INFO_501
, i501
,
103 (struct SHARE_INFO_501
**)buffer
,
108 s1005
= info
->info1005
;
110 i1005
.shi1005_flags
= s1005
->dfs_flags
;
112 ADD_TO_ARRAY(mem_ctx
, struct SHARE_INFO_1005
, i1005
,
113 (struct SHARE_INFO_1005
**)buffer
,
118 return NT_STATUS_INVALID_PARAMETER
;
124 /****************************************************************
125 ****************************************************************/
127 static NTSTATUS
map_SHARE_INFO_buffer_to_srvsvc_share_info(TALLOC_CTX
*mem_ctx
,
130 union srvsvc_NetShareInfo
*info
)
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
;
140 return NT_STATUS_INVALID_PARAMETER
;
145 i2
= (struct SHARE_INFO_2
*)buffer
;
147 s2
= talloc(mem_ctx
, struct srvsvc_NetShareInfo2
);
148 NT_STATUS_HAVE_NO_MEMORY(s2
);
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
;
164 i502
= (struct SHARE_INFO_502
*)buffer
;
166 s502
= talloc(mem_ctx
, struct srvsvc_NetShareInfo502
);
167 NT_STATUS_HAVE_NO_MEMORY(s502
);
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
;
181 info
->info502
= s502
;
186 i1004
= (struct SHARE_INFO_1004
*)buffer
;
188 s1004
= talloc(mem_ctx
, struct srvsvc_NetShareInfo1004
);
189 NT_STATUS_HAVE_NO_MEMORY(s1004
);
191 s1004
->comment
= i1004
->shi1004_remark
;
193 info
->info1004
= s1004
;
197 return NT_STATUS_INVALID_PARAMETER
;
203 /****************************************************************
204 ****************************************************************/
206 WERROR
NetShareAdd_r(struct libnetapi_ctx
*ctx
,
207 struct NetShareAdd
*r
)
211 union srvsvc_NetShareInfo info
;
212 struct dcerpc_binding_handle
*b
;
215 return WERR_INVALID_PARAMETER
;
218 switch (r
->in
.level
) {
223 return WERR_NOT_SUPPORTED
;
225 return WERR_INVALID_LEVEL
;
228 werr
= libnetapi_get_binding_handle(ctx
, r
->in
.server_name
,
231 if (!W_ERROR_IS_OK(werr
)) {
235 status
= map_SHARE_INFO_buffer_to_srvsvc_share_info(ctx
,
239 if (!NT_STATUS_IS_OK(status
)) {
240 werr
= ntstatus_to_werror(status
);
244 status
= dcerpc_srvsvc_NetShareAdd(b
, talloc_tos(),
250 if (!NT_STATUS_IS_OK(status
)) {
251 werr
= ntstatus_to_werror(status
);
255 if (!W_ERROR_IS_OK(werr
)) {
263 /****************************************************************
264 ****************************************************************/
266 WERROR
NetShareAdd_l(struct libnetapi_ctx
*ctx
,
267 struct NetShareAdd
*r
)
269 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetShareAdd
);
272 /****************************************************************
273 ****************************************************************/
275 WERROR
NetShareDel_r(struct libnetapi_ctx
*ctx
,
276 struct NetShareDel
*r
)
280 struct dcerpc_binding_handle
*b
;
282 if (!r
->in
.net_name
) {
283 return WERR_INVALID_PARAMETER
;
286 werr
= libnetapi_get_binding_handle(ctx
, r
->in
.server_name
,
289 if (!W_ERROR_IS_OK(werr
)) {
293 status
= dcerpc_srvsvc_NetShareDel(b
, talloc_tos(),
298 if (!NT_STATUS_IS_OK(status
)) {
299 werr
= ntstatus_to_werror(status
);
307 /****************************************************************
308 ****************************************************************/
310 WERROR
NetShareDel_l(struct libnetapi_ctx
*ctx
,
311 struct NetShareDel
*r
)
313 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetShareDel
);
316 /****************************************************************
317 ****************************************************************/
319 WERROR
NetShareEnum_r(struct libnetapi_ctx
*ctx
,
320 struct NetShareEnum
*r
)
324 struct srvsvc_NetShareInfoCtr info_ctr
;
325 struct srvsvc_NetShareCtr0 ctr0
;
326 struct srvsvc_NetShareCtr1 ctr1
;
327 struct srvsvc_NetShareCtr2 ctr2
;
329 struct dcerpc_binding_handle
*b
;
331 if (!r
->out
.buffer
) {
332 return WERR_INVALID_PARAMETER
;
335 switch (r
->in
.level
) {
342 return WERR_NOT_SUPPORTED
;
344 return WERR_INVALID_LEVEL
;
347 ZERO_STRUCT(info_ctr
);
349 werr
= libnetapi_get_binding_handle(ctx
, r
->in
.server_name
,
352 if (!W_ERROR_IS_OK(werr
)) {
356 info_ctr
.level
= r
->in
.level
;
357 switch (r
->in
.level
) {
360 info_ctr
.ctr
.ctr0
= &ctr0
;
364 info_ctr
.ctr
.ctr1
= &ctr1
;
368 info_ctr
.ctr
.ctr2
= &ctr2
;
372 status
= dcerpc_srvsvc_NetShareEnumAll(b
, talloc_tos(),
376 r
->out
.total_entries
,
377 r
->out
.resume_handle
,
379 if (!NT_STATUS_IS_OK(status
)) {
380 werr
= ntstatus_to_werror(status
);
384 if (!W_ERROR_IS_OK(werr
) && !W_ERROR_EQUAL(werr
, WERR_MORE_DATA
)) {
388 for (i
=0; i
< info_ctr
.ctr
.ctr1
->count
; i
++) {
389 union srvsvc_NetShareInfo _i
= {0};
390 switch (r
->in
.level
) {
392 _i
.info0
= &info_ctr
.ctr
.ctr0
->array
[i
];
395 _i
.info1
= &info_ctr
.ctr
.ctr1
->array
[i
];
398 _i
.info2
= &info_ctr
.ctr
.ctr2
->array
[i
];
402 status
= map_srvsvc_share_info_to_SHARE_INFO_buffer(ctx
,
406 r
->out
.entries_read
);
407 if (!NT_STATUS_IS_OK(status
)) {
408 werr
= ntstatus_to_werror(status
);
417 /****************************************************************
418 ****************************************************************/
420 WERROR
NetShareEnum_l(struct libnetapi_ctx
*ctx
,
421 struct NetShareEnum
*r
)
423 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetShareEnum
);
426 /****************************************************************
427 ****************************************************************/
429 WERROR
NetShareGetInfo_r(struct libnetapi_ctx
*ctx
,
430 struct NetShareGetInfo
*r
)
434 union srvsvc_NetShareInfo info
;
435 uint32_t num_entries
= 0;
436 struct dcerpc_binding_handle
*b
;
438 if (!r
->in
.net_name
|| !r
->out
.buffer
) {
439 return WERR_INVALID_PARAMETER
;
442 switch (r
->in
.level
) {
451 return WERR_NOT_SUPPORTED
;
453 return WERR_INVALID_LEVEL
;
456 werr
= libnetapi_get_binding_handle(ctx
, r
->in
.server_name
,
459 if (!W_ERROR_IS_OK(werr
)) {
463 status
= dcerpc_srvsvc_NetShareGetInfo(b
, talloc_tos(),
469 if (!NT_STATUS_IS_OK(status
)) {
470 werr
= ntstatus_to_werror(status
);
474 if (!W_ERROR_IS_OK(werr
)) {
478 status
= map_srvsvc_share_info_to_SHARE_INFO_buffer(ctx
,
483 if (!NT_STATUS_IS_OK(status
)) {
484 werr
= ntstatus_to_werror(status
);
491 /****************************************************************
492 ****************************************************************/
494 WERROR
NetShareGetInfo_l(struct libnetapi_ctx
*ctx
,
495 struct NetShareGetInfo
*r
)
497 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetShareGetInfo
);
500 /****************************************************************
501 ****************************************************************/
503 WERROR
NetShareSetInfo_r(struct libnetapi_ctx
*ctx
,
504 struct NetShareSetInfo
*r
)
508 union srvsvc_NetShareInfo info
;
509 struct dcerpc_binding_handle
*b
;
512 return WERR_INVALID_PARAMETER
;
515 switch (r
->in
.level
) {
525 return WERR_NOT_SUPPORTED
;
527 return WERR_INVALID_LEVEL
;
530 werr
= libnetapi_get_binding_handle(ctx
, r
->in
.server_name
,
533 if (!W_ERROR_IS_OK(werr
)) {
537 status
= map_SHARE_INFO_buffer_to_srvsvc_share_info(ctx
,
541 if (!NT_STATUS_IS_OK(status
)) {
542 werr
= ntstatus_to_werror(status
);
546 status
= dcerpc_srvsvc_NetShareSetInfo(b
, talloc_tos(),
553 if (!NT_STATUS_IS_OK(status
)) {
554 werr
= ntstatus_to_werror(status
);
558 if (!W_ERROR_IS_OK(werr
)) {
566 /****************************************************************
567 ****************************************************************/
569 WERROR
NetShareSetInfo_l(struct libnetapi_ctx
*ctx
,
570 struct NetShareSetInfo
*r
)
572 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetShareSetInfo
);