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"
28 /****************************************************************
29 ****************************************************************/
31 static NTSTATUS
map_srvsvc_share_info_to_SHARE_INFO_buffer(TALLOC_CTX
*mem_ctx
,
33 union srvsvc_NetShareInfo
*info
,
37 struct SHARE_INFO_0 i0
;
38 struct SHARE_INFO_1 i1
;
39 struct SHARE_INFO_2 i2
;
40 struct SHARE_INFO_501 i501
;
41 struct SHARE_INFO_1005 i1005
;
43 struct srvsvc_NetShareInfo0
*s0
;
44 struct srvsvc_NetShareInfo1
*s1
;
45 struct srvsvc_NetShareInfo2
*s2
;
46 struct srvsvc_NetShareInfo501
*s501
;
47 struct srvsvc_NetShareInfo1005
*s1005
;
50 return NT_STATUS_INVALID_PARAMETER
;
57 i0
.shi0_netname
= talloc_strdup(mem_ctx
, s0
->name
);
59 ADD_TO_ARRAY(mem_ctx
, struct SHARE_INFO_0
, i0
,
60 (struct SHARE_INFO_0
**)buffer
,
67 i1
.shi1_netname
= talloc_strdup(mem_ctx
, s1
->name
);
68 i1
.shi1_type
= s1
->type
;
69 i1
.shi1_remark
= talloc_strdup(mem_ctx
, s1
->comment
);
71 ADD_TO_ARRAY(mem_ctx
, struct SHARE_INFO_1
, i1
,
72 (struct SHARE_INFO_1
**)buffer
,
79 i2
.shi2_netname
= talloc_strdup(mem_ctx
, s2
->name
);
80 i2
.shi2_type
= s2
->type
;
81 i2
.shi2_remark
= talloc_strdup(mem_ctx
, s2
->comment
);
82 i2
.shi2_permissions
= s2
->permissions
;
83 i2
.shi2_max_uses
= s2
->max_users
;
84 i2
.shi2_current_uses
= s2
->current_users
;
85 i2
.shi2_path
= talloc_strdup(mem_ctx
, s2
->path
);
86 i2
.shi2_passwd
= talloc_strdup(mem_ctx
, s2
->password
);
88 ADD_TO_ARRAY(mem_ctx
, struct SHARE_INFO_2
, i2
,
89 (struct SHARE_INFO_2
**)buffer
,
96 i501
.shi501_netname
= talloc_strdup(mem_ctx
, s501
->name
);
97 i501
.shi501_type
= s501
->type
;
98 i501
.shi501_remark
= talloc_strdup(mem_ctx
, s501
->comment
);
99 i501
.shi501_flags
= s501
->csc_policy
;
101 ADD_TO_ARRAY(mem_ctx
, struct SHARE_INFO_501
, i501
,
102 (struct SHARE_INFO_501
**)buffer
,
107 s1005
= info
->info1005
;
109 i1005
.shi1005_flags
= s1005
->dfs_flags
;
111 ADD_TO_ARRAY(mem_ctx
, struct SHARE_INFO_1005
, i1005
,
112 (struct SHARE_INFO_1005
**)buffer
,
117 return NT_STATUS_INVALID_PARAMETER
;
123 /****************************************************************
124 ****************************************************************/
126 static NTSTATUS
map_SHARE_INFO_buffer_to_srvsvc_share_info(TALLOC_CTX
*mem_ctx
,
129 union srvsvc_NetShareInfo
*info
)
131 struct SHARE_INFO_2
*i2
= NULL
;
132 struct SHARE_INFO_1004
*i1004
= NULL
;
133 struct srvsvc_NetShareInfo2
*s2
= NULL
;
134 struct srvsvc_NetShareInfo1004
*s1004
= NULL
;
137 return NT_STATUS_INVALID_PARAMETER
;
142 i2
= (struct SHARE_INFO_2
*)buffer
;
144 s2
= TALLOC_P(mem_ctx
, struct srvsvc_NetShareInfo2
);
145 NT_STATUS_HAVE_NO_MEMORY(s2
);
147 s2
->name
= i2
->shi2_netname
;
148 s2
->type
= i2
->shi2_type
;
149 s2
->comment
= i2
->shi2_remark
;
150 s2
->permissions
= i2
->shi2_permissions
;
151 s2
->max_users
= i2
->shi2_max_uses
;
152 s2
->current_users
= i2
->shi2_current_uses
;
153 s2
->path
= i2
->shi2_path
;
154 s2
->password
= i2
->shi2_passwd
;
160 i1004
= (struct SHARE_INFO_1004
*)buffer
;
162 s1004
= TALLOC_P(mem_ctx
, struct srvsvc_NetShareInfo1004
);
163 NT_STATUS_HAVE_NO_MEMORY(s1004
);
165 s1004
->comment
= i1004
->shi1004_remark
;
167 info
->info1004
= s1004
;
171 return NT_STATUS_INVALID_PARAMETER
;
177 /****************************************************************
178 ****************************************************************/
180 WERROR
NetShareAdd_r(struct libnetapi_ctx
*ctx
,
181 struct NetShareAdd
*r
)
185 union srvsvc_NetShareInfo info
;
186 struct dcerpc_binding_handle
*b
;
189 return WERR_INVALID_PARAM
;
192 switch (r
->in
.level
) {
197 return WERR_NOT_SUPPORTED
;
199 return WERR_UNKNOWN_LEVEL
;
202 werr
= libnetapi_get_binding_handle(ctx
, r
->in
.server_name
,
203 &ndr_table_srvsvc
.syntax_id
,
205 if (!W_ERROR_IS_OK(werr
)) {
209 status
= map_SHARE_INFO_buffer_to_srvsvc_share_info(ctx
,
213 if (!NT_STATUS_IS_OK(status
)) {
214 werr
= ntstatus_to_werror(status
);
218 status
= dcerpc_srvsvc_NetShareAdd(b
, talloc_tos(),
224 if (!NT_STATUS_IS_OK(status
)) {
225 werr
= ntstatus_to_werror(status
);
229 if (!W_ERROR_IS_OK(werr
)) {
237 /****************************************************************
238 ****************************************************************/
240 WERROR
NetShareAdd_l(struct libnetapi_ctx
*ctx
,
241 struct NetShareAdd
*r
)
243 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetShareAdd
);
246 /****************************************************************
247 ****************************************************************/
249 WERROR
NetShareDel_r(struct libnetapi_ctx
*ctx
,
250 struct NetShareDel
*r
)
254 struct dcerpc_binding_handle
*b
;
256 if (!r
->in
.net_name
) {
257 return WERR_INVALID_PARAM
;
260 werr
= libnetapi_get_binding_handle(ctx
, r
->in
.server_name
,
261 &ndr_table_srvsvc
.syntax_id
,
263 if (!W_ERROR_IS_OK(werr
)) {
267 status
= dcerpc_srvsvc_NetShareDel(b
, talloc_tos(),
272 if (!NT_STATUS_IS_OK(status
)) {
273 werr
= ntstatus_to_werror(status
);
281 /****************************************************************
282 ****************************************************************/
284 WERROR
NetShareDel_l(struct libnetapi_ctx
*ctx
,
285 struct NetShareDel
*r
)
287 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetShareDel
);
290 /****************************************************************
291 ****************************************************************/
293 WERROR
NetShareEnum_r(struct libnetapi_ctx
*ctx
,
294 struct NetShareEnum
*r
)
298 struct srvsvc_NetShareInfoCtr info_ctr
;
299 struct srvsvc_NetShareCtr0 ctr0
;
300 struct srvsvc_NetShareCtr1 ctr1
;
301 struct srvsvc_NetShareCtr2 ctr2
;
303 struct dcerpc_binding_handle
*b
;
305 if (!r
->out
.buffer
) {
306 return WERR_INVALID_PARAM
;
309 switch (r
->in
.level
) {
316 return WERR_NOT_SUPPORTED
;
318 return WERR_UNKNOWN_LEVEL
;
321 ZERO_STRUCT(info_ctr
);
323 werr
= libnetapi_get_binding_handle(ctx
, r
->in
.server_name
,
324 &ndr_table_srvsvc
.syntax_id
,
326 if (!W_ERROR_IS_OK(werr
)) {
330 info_ctr
.level
= r
->in
.level
;
331 switch (r
->in
.level
) {
334 info_ctr
.ctr
.ctr0
= &ctr0
;
338 info_ctr
.ctr
.ctr1
= &ctr1
;
342 info_ctr
.ctr
.ctr2
= &ctr2
;
346 status
= dcerpc_srvsvc_NetShareEnumAll(b
, talloc_tos(),
350 r
->out
.total_entries
,
351 r
->out
.resume_handle
,
353 if (!NT_STATUS_IS_OK(status
)) {
354 werr
= ntstatus_to_werror(status
);
358 if (!W_ERROR_IS_OK(werr
) && !W_ERROR_EQUAL(werr
, WERR_MORE_DATA
)) {
362 for (i
=0; i
< info_ctr
.ctr
.ctr1
->count
; i
++) {
363 union srvsvc_NetShareInfo _i
;
364 switch (r
->in
.level
) {
366 _i
.info0
= &info_ctr
.ctr
.ctr0
->array
[i
];
369 _i
.info1
= &info_ctr
.ctr
.ctr1
->array
[i
];
372 _i
.info2
= &info_ctr
.ctr
.ctr2
->array
[i
];
376 status
= map_srvsvc_share_info_to_SHARE_INFO_buffer(ctx
,
380 r
->out
.entries_read
);
381 if (!NT_STATUS_IS_OK(status
)) {
382 werr
= ntstatus_to_werror(status
);
391 /****************************************************************
392 ****************************************************************/
394 WERROR
NetShareEnum_l(struct libnetapi_ctx
*ctx
,
395 struct NetShareEnum
*r
)
397 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetShareEnum
);
400 /****************************************************************
401 ****************************************************************/
403 WERROR
NetShareGetInfo_r(struct libnetapi_ctx
*ctx
,
404 struct NetShareGetInfo
*r
)
408 union srvsvc_NetShareInfo info
;
409 uint32_t num_entries
= 0;
410 struct dcerpc_binding_handle
*b
;
412 if (!r
->in
.net_name
|| !r
->out
.buffer
) {
413 return WERR_INVALID_PARAM
;
416 switch (r
->in
.level
) {
425 return WERR_NOT_SUPPORTED
;
427 return WERR_UNKNOWN_LEVEL
;
430 werr
= libnetapi_get_binding_handle(ctx
, r
->in
.server_name
,
431 &ndr_table_srvsvc
.syntax_id
,
433 if (!W_ERROR_IS_OK(werr
)) {
437 status
= dcerpc_srvsvc_NetShareGetInfo(b
, talloc_tos(),
443 if (!NT_STATUS_IS_OK(status
)) {
444 werr
= ntstatus_to_werror(status
);
448 if (!W_ERROR_IS_OK(werr
)) {
452 status
= map_srvsvc_share_info_to_SHARE_INFO_buffer(ctx
,
457 if (!NT_STATUS_IS_OK(status
)) {
458 werr
= ntstatus_to_werror(status
);
465 /****************************************************************
466 ****************************************************************/
468 WERROR
NetShareGetInfo_l(struct libnetapi_ctx
*ctx
,
469 struct NetShareGetInfo
*r
)
471 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetShareGetInfo
);
474 /****************************************************************
475 ****************************************************************/
477 WERROR
NetShareSetInfo_r(struct libnetapi_ctx
*ctx
,
478 struct NetShareSetInfo
*r
)
482 union srvsvc_NetShareInfo info
;
483 struct dcerpc_binding_handle
*b
;
486 return WERR_INVALID_PARAM
;
489 switch (r
->in
.level
) {
499 return WERR_NOT_SUPPORTED
;
501 return WERR_UNKNOWN_LEVEL
;
504 werr
= libnetapi_get_binding_handle(ctx
, r
->in
.server_name
,
505 &ndr_table_srvsvc
.syntax_id
,
507 if (!W_ERROR_IS_OK(werr
)) {
511 status
= map_SHARE_INFO_buffer_to_srvsvc_share_info(ctx
,
515 if (!NT_STATUS_IS_OK(status
)) {
516 werr
= ntstatus_to_werror(status
);
520 status
= dcerpc_srvsvc_NetShareSetInfo(b
, talloc_tos(),
527 if (!NT_STATUS_IS_OK(status
)) {
528 werr
= ntstatus_to_werror(status
);
532 if (!W_ERROR_IS_OK(werr
)) {
540 /****************************************************************
541 ****************************************************************/
543 WERROR
NetShareSetInfo_l(struct libnetapi_ctx
*ctx
,
544 struct NetShareSetInfo
*r
)
546 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetShareSetInfo
);