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 (!W_ERROR_IS_OK(werr)) {
286 /****************************************************************
287 ****************************************************************/
289 WERROR NetShareDel_l(struct libnetapi_ctx *ctx,
290 struct NetShareDel *r)
292 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareDel);
295 /****************************************************************
296 ****************************************************************/
298 WERROR NetShareEnum_r(struct libnetapi_ctx *ctx,
299 struct NetShareEnum *r)
303 struct cli_state *cli = NULL;
304 struct rpc_pipe_client *pipe_cli = NULL;
305 struct srvsvc_NetShareInfoCtr info_ctr;
306 struct srvsvc_NetShareCtr0 ctr0;
307 struct srvsvc_NetShareCtr1 ctr1;
308 struct srvsvc_NetShareCtr2 ctr2;
311 if (!r->out.buffer) {
312 return WERR_INVALID_PARAM;
315 switch (r->in.level) {
322 return WERR_NOT_SUPPORTED;
324 return WERR_UNKNOWN_LEVEL;
327 ZERO_STRUCT(info_ctr);
329 werr = libnetapi_open_pipe(ctx, r->in.server_name,
330 &ndr_table_srvsvc.syntax_id,
333 if (!W_ERROR_IS_OK(werr)) {
337 info_ctr.level = r->in.level;
338 switch (r->in.level) {
340 info_ctr.ctr.ctr0 = &ctr0;
343 info_ctr.ctr.ctr1 = &ctr1;
346 info_ctr.ctr.ctr2 = &ctr2;
350 status = rpccli_srvsvc_NetShareEnumAll(pipe_cli, ctx,
354 r->out.total_entries,
355 r->out.resume_handle,
357 if (NT_STATUS_IS_ERR(status)) {
361 for (i=0; i < info_ctr.ctr.ctr1->count; i++) {
362 union srvsvc_NetShareInfo _i;
363 switch (r->in.level) {
365 _i.info0 = &info_ctr.ctr.ctr0->array[i];
368 _i.info1 = &info_ctr.ctr.ctr1->array[i];
371 _i.info2 = &info_ctr.ctr.ctr2->array[i];
375 status = map_srvsvc_share_info_to_SHARE_INFO_buffer(ctx,
379 r->out.entries_read);
380 if (!NT_STATUS_IS_OK(status)) {
381 werr = ntstatus_to_werror(status);
393 /****************************************************************
394 ****************************************************************/
396 WERROR NetShareEnum_l(struct libnetapi_ctx *ctx,
397 struct NetShareEnum *r)
399 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareEnum);
402 /****************************************************************
403 ****************************************************************/
405 WERROR NetShareGetInfo_r(struct libnetapi_ctx *ctx,
406 struct NetShareGetInfo *r)
410 struct cli_state *cli = NULL;
411 struct rpc_pipe_client *pipe_cli = NULL;
412 union srvsvc_NetShareInfo info;
413 uint32_t num_entries = 0;
415 if (!r->in.net_name) {
416 return WERR_INVALID_PARAM;
419 switch (r->in.level) {
428 return WERR_NOT_SUPPORTED;
430 return WERR_UNKNOWN_LEVEL;
433 werr = libnetapi_open_pipe(ctx, r->in.server_name,
434 &ndr_table_srvsvc.syntax_id,
437 if (!W_ERROR_IS_OK(werr)) {
441 status = rpccli_srvsvc_NetShareGetInfo(pipe_cli, ctx,
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);
469 /****************************************************************
470 ****************************************************************/
472 WERROR NetShareGetInfo_l(struct libnetapi_ctx *ctx,
473 struct NetShareGetInfo *r)
475 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareGetInfo);
478 /****************************************************************
479 ****************************************************************/
481 WERROR NetShareSetInfo_r(struct libnetapi_ctx *ctx,
482 struct NetShareSetInfo *r)
486 struct cli_state *cli = NULL;
487 struct rpc_pipe_client *pipe_cli = NULL;
488 union srvsvc_NetShareInfo info;
491 return WERR_INVALID_PARAM;
494 switch (r->in.level) {
504 return WERR_NOT_SUPPORTED;
506 return WERR_UNKNOWN_LEVEL;
509 werr = libnetapi_open_pipe(ctx, r->in.server_name,
510 &ndr_table_srvsvc.syntax_id,
513 if (!W_ERROR_IS_OK(werr)) {
517 status = map_SHARE_INFO_buffer_to_srvsvc_share_info(ctx,
521 if (!NT_STATUS_IS_OK(status)) {
522 werr = ntstatus_to_werror(status);
526 status = rpccli_srvsvc_NetShareSetInfo(pipe_cli, ctx,
533 if (!W_ERROR_IS_OK(werr)) {
545 /****************************************************************
546 ****************************************************************/
548 WERROR NetShareSetInfo_l(struct libnetapi_ctx *ctx,
549 struct NetShareSetInfo *r)
551 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetShareSetInfo);