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"
27 /****************************************************************
28 ****************************************************************/
30 static NTSTATUS
map_srvsvc_share_info_to_SHARE_INFO_buffer(TALLOC_CTX
*mem_ctx
,
32 union srvsvc_NetShareInfo
*info
,
36 struct SHARE_INFO_0 i0
;
37 struct SHARE_INFO_1 i1
;
38 struct SHARE_INFO_2 i2
;
39 struct SHARE_INFO_501 i501
;
40 struct SHARE_INFO_1005 i1005
;
42 struct srvsvc_NetShareInfo0
*s0
;
43 struct srvsvc_NetShareInfo1
*s1
;
44 struct srvsvc_NetShareInfo2
*s2
;
45 struct srvsvc_NetShareInfo501
*s501
;
46 struct srvsvc_NetShareInfo1005
*s1005
;
49 return NT_STATUS_INVALID_PARAMETER
;
56 i0
.shi0_netname
= talloc_strdup(mem_ctx
, s0
->name
);
58 ADD_TO_ARRAY(mem_ctx
, struct SHARE_INFO_0
, i0
,
59 (struct SHARE_INFO_0
**)buffer
,
66 i1
.shi1_netname
= talloc_strdup(mem_ctx
, s1
->name
);
67 i1
.shi1_type
= s1
->type
;
68 i1
.shi1_remark
= talloc_strdup(mem_ctx
, s1
->comment
);
70 ADD_TO_ARRAY(mem_ctx
, struct SHARE_INFO_1
, i1
,
71 (struct SHARE_INFO_1
**)buffer
,
78 i2
.shi2_netname
= talloc_strdup(mem_ctx
, s2
->name
);
79 i2
.shi2_type
= s2
->type
;
80 i2
.shi2_remark
= talloc_strdup(mem_ctx
, s2
->comment
);
81 i2
.shi2_permissions
= s2
->permissions
;
82 i2
.shi2_max_uses
= s2
->max_users
;
83 i2
.shi2_current_uses
= s2
->current_users
;
84 i2
.shi2_path
= talloc_strdup(mem_ctx
, s2
->path
);
85 i2
.shi2_passwd
= talloc_strdup(mem_ctx
, s2
->password
);
87 ADD_TO_ARRAY(mem_ctx
, struct SHARE_INFO_2
, i2
,
88 (struct SHARE_INFO_2
**)buffer
,
95 i501
.shi501_netname
= talloc_strdup(mem_ctx
, s501
->name
);
96 i501
.shi501_type
= s501
->type
;
97 i501
.shi501_remark
= talloc_strdup(mem_ctx
, s501
->comment
);
98 i501
.shi501_flags
= s501
->csc_policy
;
100 ADD_TO_ARRAY(mem_ctx
, struct SHARE_INFO_501
, i501
,
101 (struct SHARE_INFO_501
**)buffer
,
106 s1005
= info
->info1005
;
108 i1005
.shi1005_flags
= s1005
->dfs_flags
;
110 ADD_TO_ARRAY(mem_ctx
, struct SHARE_INFO_1005
, i1005
,
111 (struct SHARE_INFO_1005
**)buffer
,
116 return NT_STATUS_INVALID_PARAMETER
;
122 /****************************************************************
123 ****************************************************************/
125 static NTSTATUS
map_SHARE_INFO_buffer_to_srvsvc_share_info(TALLOC_CTX
*mem_ctx
,
128 union srvsvc_NetShareInfo
*info
)
130 struct SHARE_INFO_2
*i2
= NULL
;
131 struct SHARE_INFO_1004
*i1004
= NULL
;
132 struct srvsvc_NetShareInfo2
*s2
= NULL
;
133 struct srvsvc_NetShareInfo1004
*s1004
= NULL
;
136 return NT_STATUS_INVALID_PARAMETER
;
141 i2
= (struct SHARE_INFO_2
*)buffer
;
143 s2
= TALLOC_P(mem_ctx
, struct srvsvc_NetShareInfo2
);
144 NT_STATUS_HAVE_NO_MEMORY(s2
);
146 s2
->name
= i2
->shi2_netname
;
147 s2
->type
= i2
->shi2_type
;
148 s2
->comment
= i2
->shi2_remark
;
149 s2
->permissions
= i2
->shi2_permissions
;
150 s2
->max_users
= i2
->shi2_max_uses
;
151 s2
->current_users
= i2
->shi2_current_uses
;
152 s2
->path
= i2
->shi2_path
;
153 s2
->password
= i2
->shi2_passwd
;
159 i1004
= (struct SHARE_INFO_1004
*)buffer
;
161 s1004
= TALLOC_P(mem_ctx
, struct srvsvc_NetShareInfo1004
);
162 NT_STATUS_HAVE_NO_MEMORY(s1004
);
164 s1004
->comment
= i1004
->shi1004_remark
;
166 info
->info1004
= s1004
;
170 return NT_STATUS_INVALID_PARAMETER
;
176 /****************************************************************
177 ****************************************************************/
179 WERROR
NetShareAdd_r(struct libnetapi_ctx
*ctx
,
180 struct NetShareAdd
*r
)
184 struct cli_state
*cli
= NULL
;
185 struct rpc_pipe_client
*pipe_cli
= NULL
;
186 union srvsvc_NetShareInfo info
;
189 return WERR_INVALID_PARAM
;
192 switch (r
->in
.level
) {
197 return WERR_NOT_SUPPORTED
;
199 return WERR_UNKNOWN_LEVEL
;
202 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
203 &ndr_table_srvsvc
.syntax_id
,
206 if (!W_ERROR_IS_OK(werr
)) {
210 status
= map_SHARE_INFO_buffer_to_srvsvc_share_info(ctx
,
214 if (!NT_STATUS_IS_OK(status
)) {
215 werr
= ntstatus_to_werror(status
);
219 status
= rpccli_srvsvc_NetShareAdd(pipe_cli
, ctx
,
225 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 cli_state
*cli
= NULL
;
255 struct rpc_pipe_client
*pipe_cli
= NULL
;
257 if (!r
->in
.net_name
) {
258 return WERR_INVALID_PARAM
;
261 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
262 &ndr_table_srvsvc
.syntax_id
,
265 if (!W_ERROR_IS_OK(werr
)) {
269 status
= rpccli_srvsvc_NetShareDel(pipe_cli
, ctx
,
274 if (!NT_STATUS_IS_OK(status
)) {
275 werr
= ntstatus_to_werror(status
);
287 /****************************************************************
288 ****************************************************************/
290 WERROR
NetShareDel_l(struct libnetapi_ctx
*ctx
,
291 struct NetShareDel
*r
)
293 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetShareDel
);
296 /****************************************************************
297 ****************************************************************/
299 WERROR
NetShareEnum_r(struct libnetapi_ctx
*ctx
,
300 struct NetShareEnum
*r
)
304 struct cli_state
*cli
= NULL
;
305 struct rpc_pipe_client
*pipe_cli
= NULL
;
306 struct srvsvc_NetShareInfoCtr info_ctr
;
307 struct srvsvc_NetShareCtr0 ctr0
;
308 struct srvsvc_NetShareCtr1 ctr1
;
309 struct srvsvc_NetShareCtr2 ctr2
;
312 if (!r
->out
.buffer
) {
313 return WERR_INVALID_PARAM
;
316 switch (r
->in
.level
) {
323 return WERR_NOT_SUPPORTED
;
325 return WERR_UNKNOWN_LEVEL
;
328 ZERO_STRUCT(info_ctr
);
330 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
331 &ndr_table_srvsvc
.syntax_id
,
334 if (!W_ERROR_IS_OK(werr
)) {
338 info_ctr
.level
= r
->in
.level
;
339 switch (r
->in
.level
) {
342 info_ctr
.ctr
.ctr0
= &ctr0
;
346 info_ctr
.ctr
.ctr1
= &ctr1
;
350 info_ctr
.ctr
.ctr2
= &ctr2
;
354 status
= rpccli_srvsvc_NetShareEnumAll(pipe_cli
, ctx
,
358 r
->out
.total_entries
,
359 r
->out
.resume_handle
,
361 if (NT_STATUS_IS_ERR(status
)) {
365 for (i
=0; i
< info_ctr
.ctr
.ctr1
->count
; i
++) {
366 union srvsvc_NetShareInfo _i
;
367 switch (r
->in
.level
) {
369 _i
.info0
= &info_ctr
.ctr
.ctr0
->array
[i
];
372 _i
.info1
= &info_ctr
.ctr
.ctr1
->array
[i
];
375 _i
.info2
= &info_ctr
.ctr
.ctr2
->array
[i
];
379 status
= map_srvsvc_share_info_to_SHARE_INFO_buffer(ctx
,
383 r
->out
.entries_read
);
384 if (!NT_STATUS_IS_OK(status
)) {
385 werr
= ntstatus_to_werror(status
);
397 /****************************************************************
398 ****************************************************************/
400 WERROR
NetShareEnum_l(struct libnetapi_ctx
*ctx
,
401 struct NetShareEnum
*r
)
403 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetShareEnum
);
406 /****************************************************************
407 ****************************************************************/
409 WERROR
NetShareGetInfo_r(struct libnetapi_ctx
*ctx
,
410 struct NetShareGetInfo
*r
)
414 struct cli_state
*cli
= NULL
;
415 struct rpc_pipe_client
*pipe_cli
= NULL
;
416 union srvsvc_NetShareInfo info
;
417 uint32_t num_entries
= 0;
419 if (!r
->in
.net_name
|| !r
->out
.buffer
) {
420 return WERR_INVALID_PARAM
;
423 switch (r
->in
.level
) {
432 return WERR_NOT_SUPPORTED
;
434 return WERR_UNKNOWN_LEVEL
;
437 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
438 &ndr_table_srvsvc
.syntax_id
,
441 if (!W_ERROR_IS_OK(werr
)) {
445 status
= rpccli_srvsvc_NetShareGetInfo(pipe_cli
, ctx
,
452 if (!W_ERROR_IS_OK(werr
)) {
456 status
= map_srvsvc_share_info_to_SHARE_INFO_buffer(ctx
,
461 if (!NT_STATUS_IS_OK(status
)) {
462 werr
= ntstatus_to_werror(status
);
473 /****************************************************************
474 ****************************************************************/
476 WERROR
NetShareGetInfo_l(struct libnetapi_ctx
*ctx
,
477 struct NetShareGetInfo
*r
)
479 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetShareGetInfo
);
482 /****************************************************************
483 ****************************************************************/
485 WERROR
NetShareSetInfo_r(struct libnetapi_ctx
*ctx
,
486 struct NetShareSetInfo
*r
)
490 struct cli_state
*cli
= NULL
;
491 struct rpc_pipe_client
*pipe_cli
= NULL
;
492 union srvsvc_NetShareInfo info
;
495 return WERR_INVALID_PARAM
;
498 switch (r
->in
.level
) {
508 return WERR_NOT_SUPPORTED
;
510 return WERR_UNKNOWN_LEVEL
;
513 werr
= libnetapi_open_pipe(ctx
, r
->in
.server_name
,
514 &ndr_table_srvsvc
.syntax_id
,
517 if (!W_ERROR_IS_OK(werr
)) {
521 status
= map_SHARE_INFO_buffer_to_srvsvc_share_info(ctx
,
525 if (!NT_STATUS_IS_OK(status
)) {
526 werr
= ntstatus_to_werror(status
);
530 status
= rpccli_srvsvc_NetShareSetInfo(pipe_cli
, ctx
,
537 if (!W_ERROR_IS_OK(werr
)) {
549 /****************************************************************
550 ****************************************************************/
552 WERROR
NetShareSetInfo_l(struct libnetapi_ctx
*ctx
,
553 struct NetShareSetInfo
*r
)
555 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx
, r
, NetShareSetInfo
);