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"
25 NTSTATUS libnet_ListShares(struct libnet_context *ctx,
26 TALLOC_CTX *mem_ctx, struct libnet_ListShares *r)
29 struct libnet_RpcConnect c;
30 struct srvsvc_NetShareEnumAll s;
31 uint32_t resume_handle;
32 struct srvsvc_NetShareCtr0 ctr0;
34 c.level = LIBNET_RPC_CONNECT_SERVER;
35 c.in.domain_name = r->in.server_name;
36 c.in.dcerpc_iface = &dcerpc_table_srvsvc;
38 status = libnet_RpcConnect(ctx, mem_ctx, &c);
39 if (!NT_STATUS_IS_OK(status)) {
40 r->out.error_string = talloc_asprintf(mem_ctx,
41 "Connection to SRVSVC pipe of server %s "
48 s.in.level = r->in.level;
49 s.in.ctr.ctr0 = &ctr0;
51 s.in.resume_handle = &resume_handle;
55 status = dcerpc_srvsvc_NetShareEnumAll(c.out.dcerpc_pipe, mem_ctx, &s);
57 if (!NT_STATUS_IS_OK(status)) {
58 r->out.error_string = talloc_asprintf(mem_ctx,
59 "srvsvc_NetShareEnumAll on server '%s' failed"
61 r->in.server_name, nt_errstr(status));
65 if (!W_ERROR_IS_OK(s.out.result) && !W_ERROR_EQUAL(s.out.result, WERR_MORE_DATA)) {
69 r->out.ctr = s.out.ctr;
72 talloc_free(c.out.dcerpc_pipe);
78 NTSTATUS libnet_AddShare(struct libnet_context *ctx,
79 TALLOC_CTX *mem_ctx, struct libnet_AddShare *r)
82 struct libnet_RpcConnect c;
83 struct srvsvc_NetShareAdd s;
85 c.level = LIBNET_RPC_CONNECT_SERVER;
86 c.in.domain_name = r->in.server_name;
87 c.in.dcerpc_iface = &dcerpc_table_srvsvc;
89 status = libnet_RpcConnect(ctx, mem_ctx, &c);
90 if (!NT_STATUS_IS_OK(status)) {
91 r->out.error_string = talloc_asprintf(mem_ctx,
92 "Connection to SRVSVC pipe of server %s "
94 r->in.server_name, nt_errstr(status));
98 s.in.level = r->in.level;
99 s.in.info.info2 = &r->in.share;
100 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", r->in.server_name);
102 status = dcerpc_srvsvc_NetShareAdd(c.out.dcerpc_pipe, mem_ctx,&s);
104 if (!NT_STATUS_IS_OK(status)) {
105 r->out.error_string = talloc_asprintf(mem_ctx,
106 "srvsvc_NetShareAdd on server '%s' failed"
108 r->in.server_name, nt_errstr(status));
111 talloc_free(c.out.dcerpc_pipe);
117 NTSTATUS libnet_DelShare(struct libnet_context *ctx,
118 TALLOC_CTX *mem_ctx, struct libnet_DelShare *r)
121 struct libnet_RpcConnect c;
122 struct srvsvc_NetShareDel s;
124 c.level = LIBNET_RPC_CONNECT_SERVER;
125 c.in.domain_name = r->in.server_name;
126 c.in.dcerpc_iface = &dcerpc_table_srvsvc;
128 status = libnet_RpcConnect(ctx, mem_ctx, &c);
129 if (!NT_STATUS_IS_OK(status)) {
130 r->out.error_string = talloc_asprintf(mem_ctx,
131 "Connection to SRVSVC pipe of server %s "
133 r->in.server_name, nt_errstr(status));
137 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", r->in.server_name);
138 s.in.share_name = r->in.share_name;
140 status = dcerpc_srvsvc_NetShareDel(c.out.dcerpc_pipe, mem_ctx, &s);
141 if (!NT_STATUS_IS_OK(status)) {
142 r->out.error_string = talloc_asprintf(mem_ctx,
143 "srvsvc_NetShareDel on server '%s' failed"
145 r->in.server_name, nt_errstr(status));
148 talloc_free(c.out.dcerpc_pipe);