2 Unix SMB/CIFS implementation.
4 Copyright (C) Grégory LEOCADIE <gleocadie@idealx.com>
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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "libnet/libnet.h"
23 #include "librpc/gen_ndr/ndr_srvsvc.h"
26 NTSTATUS libnet_ListShares(struct libnet_context *ctx,
27 TALLOC_CTX *mem_ctx, struct libnet_ListShares *r)
30 union libnet_rpc_connect c;
31 struct srvsvc_NetShareEnumAll s;
32 uint32_t resume_handle;
33 struct srvsvc_NetShareCtr0 ctr0;
35 c.standard.level = LIBNET_RPC_CONNECT_STANDARD;
36 c.standard.in.server_name = r->in.server_name;
37 c.standard.in.dcerpc_iface_name = DCERPC_SRVSVC_NAME;
38 c.standard.in.dcerpc_iface_uuid = DCERPC_SRVSVC_UUID;
39 c.standard.in.dcerpc_iface_version = DCERPC_SRVSVC_VERSION;
41 status = libnet_rpc_connect(ctx, mem_ctx, &c);
42 if (!NT_STATUS_IS_OK(status)) {
43 r->out.error_string = talloc_asprintf(mem_ctx,
44 "Connection to SRVSVC pipe of server %s "
51 s.in.level = r->in.level;
52 s.in.ctr.ctr0 = &ctr0;
54 s.in.resume_handle = &resume_handle;
58 status = dcerpc_srvsvc_NetShareEnumAll(c.standard.out.dcerpc_pipe, mem_ctx, &s);
60 if (!NT_STATUS_IS_OK(status)) {
61 r->out.error_string = talloc_asprintf(mem_ctx,
62 "srvsvc_NetShareEnumAll on server '%s' failed"
64 r->in.server_name, nt_errstr(status));
68 if (!W_ERROR_IS_OK(s.out.result) && !W_ERROR_EQUAL(s.out.result, WERR_MORE_DATA)) {
72 r->out.ctr = s.out.ctr;
75 talloc_free(c.standard.out.dcerpc_pipe);
81 NTSTATUS libnet_AddShare(struct libnet_context *ctx,
82 TALLOC_CTX *mem_ctx, struct libnet_AddShare *r)
85 union libnet_rpc_connect c;
86 struct srvsvc_NetShareAdd s;
88 c.standard.level = LIBNET_RPC_CONNECT_STANDARD;
89 c.standard.in.server_name = r->in.server_name;
90 c.standard.in.dcerpc_iface_name = DCERPC_SRVSVC_NAME;
91 c.standard.in.dcerpc_iface_uuid = DCERPC_SRVSVC_UUID;
92 c.standard.in.dcerpc_iface_version = DCERPC_SRVSVC_VERSION;
94 status = libnet_rpc_connect(ctx, mem_ctx, &c);
95 if (!NT_STATUS_IS_OK(status)) {
96 r->out.error_string = talloc_asprintf(mem_ctx,
97 "Connection to SRVSVC pipe of server %s "
99 r->in.server_name, nt_errstr(status));
103 s.in.level = r->in.level;
104 s.in.info.info2 = &r->in.share;
105 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", r->in.server_name);
107 status = dcerpc_srvsvc_NetShareAdd(c.standard.out.dcerpc_pipe, mem_ctx,&s);
109 if (!NT_STATUS_IS_OK(status)) {
110 r->out.error_string = talloc_asprintf(mem_ctx,
111 "srvsvc_NetShareAdd on server '%s' failed"
113 r->in.server_name, nt_errstr(status));
117 talloc_free(c.standard.out.dcerpc_pipe);
123 NTSTATUS libnet_DelShare(struct libnet_context *ctx,
124 TALLOC_CTX *mem_ctx, struct libnet_DelShare *r)
127 union libnet_rpc_connect c;
128 struct srvsvc_NetShareDel s;
130 c.standard.level = LIBNET_RPC_CONNECT_STANDARD;
131 c.standard.in.server_name = r->in.server_name;
132 c.standard.in.dcerpc_iface_name = DCERPC_SRVSVC_NAME;
133 c.standard.in.dcerpc_iface_uuid = DCERPC_SRVSVC_UUID;
134 c.standard.in.dcerpc_iface_version = DCERPC_SRVSVC_VERSION;
136 status = libnet_rpc_connect(ctx, mem_ctx, &c);
137 if (!NT_STATUS_IS_OK(status)) {
138 r->out.error_string = talloc_asprintf(mem_ctx,
139 "Connection to SRVSVC pipe of server %s "
141 r->in.server_name, nt_errstr(status));
145 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", r->in.server_name);
146 s.in.share_name = r->in.share_name;
148 status = dcerpc_srvsvc_NetShareDel(c.standard.out.dcerpc_pipe, mem_ctx, &s);
149 if (!NT_STATUS_IS_OK(status)) {
150 r->out.error_string = talloc_asprintf(mem_ctx,
151 "srvsvc_NetShareDel on server '%s' failed"
153 r->in.server_name, nt_errstr(status));
157 talloc_free(c.standard.out.dcerpc_pipe);