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;
33 struct srvsvc_NetShareCtr1 ctr1;
34 struct srvsvc_NetShareCtr2 ctr2;
35 struct srvsvc_NetShareCtr501 ctr501;
36 struct srvsvc_NetShareCtr502 ctr502;
38 c.level = LIBNET_RPC_CONNECT_SERVER;
39 c.in.name = r->in.server_name;
40 c.in.dcerpc_iface = &dcerpc_table_srvsvc;
42 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", c.in.name);
44 status = libnet_RpcConnect(ctx, mem_ctx, &c);
45 if (!NT_STATUS_IS_OK(status)) {
46 r->out.error_string = talloc_asprintf(mem_ctx,
47 "Connection to SRVSVC pipe of server %s "
54 s.in.level = r->in.level;
57 s.in.ctr.ctr0 = &ctr0;
61 s.in.ctr.ctr1 = &ctr1;
65 s.in.ctr.ctr2 = &ctr2;
69 s.in.ctr.ctr501 = &ctr501;
73 s.in.ctr.ctr502 = &ctr502;
77 r->out.error_string = talloc_asprintf(mem_ctx,
78 "libnet_ListShares: Invalid info level requested: %d\n",
80 return NT_STATUS_INVALID_PARAMETER;
83 s.in.resume_handle = &resume_handle;
86 status = dcerpc_srvsvc_NetShareEnumAll(c.out.dcerpc_pipe, mem_ctx, &s);
88 if (!NT_STATUS_IS_OK(status)) {
89 r->out.error_string = talloc_asprintf(mem_ctx,
90 "srvsvc_NetShareEnumAll on server '%s' failed"
92 r->in.server_name, nt_errstr(status));
96 if (!W_ERROR_IS_OK(s.out.result) && !W_ERROR_EQUAL(s.out.result, WERR_MORE_DATA)) {
97 r->out.error_string = talloc_asprintf(mem_ctx,
98 "srvsvc_NetShareEnumAll on server '%s' failed: %s",
99 r->in.server_name, win_errstr(s.out.result));
103 r->out.ctr = s.out.ctr;
106 talloc_free(c.out.dcerpc_pipe);
112 NTSTATUS libnet_AddShare(struct libnet_context *ctx,
113 TALLOC_CTX *mem_ctx, struct libnet_AddShare *r)
116 struct libnet_RpcConnect c;
117 struct srvsvc_NetShareAdd s;
119 c.level = LIBNET_RPC_CONNECT_SERVER;
120 c.in.name = r->in.server_name;
121 c.in.dcerpc_iface = &dcerpc_table_srvsvc;
123 status = libnet_RpcConnect(ctx, mem_ctx, &c);
124 if (!NT_STATUS_IS_OK(status)) {
125 r->out.error_string = talloc_asprintf(mem_ctx,
126 "Connection to SRVSVC pipe of server %s "
128 r->in.server_name, nt_errstr(status));
132 s.in.level = r->in.level;
133 s.in.info.info2 = &r->in.share;
134 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", r->in.server_name);
136 status = dcerpc_srvsvc_NetShareAdd(c.out.dcerpc_pipe, mem_ctx,&s);
138 if (!NT_STATUS_IS_OK(status)) {
139 r->out.error_string = talloc_asprintf(mem_ctx,
140 "srvsvc_NetShareAdd on server '%s' failed"
142 r->in.server_name, nt_errstr(status));
145 talloc_free(c.out.dcerpc_pipe);
151 NTSTATUS libnet_DelShare(struct libnet_context *ctx,
152 TALLOC_CTX *mem_ctx, struct libnet_DelShare *r)
155 struct libnet_RpcConnect c;
156 struct srvsvc_NetShareDel s;
158 c.level = LIBNET_RPC_CONNECT_SERVER;
159 c.in.name = r->in.server_name;
160 c.in.dcerpc_iface = &dcerpc_table_srvsvc;
162 status = libnet_RpcConnect(ctx, mem_ctx, &c);
163 if (!NT_STATUS_IS_OK(status)) {
164 r->out.error_string = talloc_asprintf(mem_ctx,
165 "Connection to SRVSVC pipe of server %s "
167 r->in.server_name, nt_errstr(status));
171 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", r->in.server_name);
172 s.in.share_name = r->in.share_name;
174 status = dcerpc_srvsvc_NetShareDel(c.out.dcerpc_pipe, mem_ctx, &s);
175 if (!NT_STATUS_IS_OK(status)) {
176 r->out.error_string = talloc_asprintf(mem_ctx,
177 "srvsvc_NetShareDel on server '%s' failed"
179 r->in.server_name, nt_errstr(status));
182 talloc_free(c.out.dcerpc_pipe);