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_c.h"
26 NTSTATUS libnet_ListShares(struct libnet_context *ctx,
27 TALLOC_CTX *mem_ctx, struct libnet_ListShares *r)
30 struct libnet_RpcConnect c;
31 struct srvsvc_NetShareEnumAll s;
32 uint32_t resume_handle = 0;
33 struct srvsvc_NetShareCtr0 ctr0;
34 struct srvsvc_NetShareCtr1 ctr1;
35 struct srvsvc_NetShareCtr2 ctr2;
36 struct srvsvc_NetShareCtr501 ctr501;
37 struct srvsvc_NetShareCtr502 ctr502;
39 c.level = LIBNET_RPC_CONNECT_SERVER;
40 c.in.name = r->in.server_name;
41 c.in.dcerpc_iface = &dcerpc_table_srvsvc;
43 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", c.in.name);
45 status = libnet_RpcConnect(ctx, mem_ctx, &c);
46 if (!NT_STATUS_IS_OK(status)) {
47 r->out.error_string = talloc_asprintf(mem_ctx,
48 "Connection to SRVSVC pipe of server %s "
55 s.in.level = r->in.level;
58 s.in.ctr.ctr0 = &ctr0;
62 s.in.ctr.ctr1 = &ctr1;
66 s.in.ctr.ctr2 = &ctr2;
70 s.in.ctr.ctr501 = &ctr501;
74 s.in.ctr.ctr502 = &ctr502;
78 r->out.error_string = talloc_asprintf(mem_ctx,
79 "libnet_ListShares: Invalid info level requested: %d\n",
81 return NT_STATUS_INVALID_PARAMETER;
84 s.in.resume_handle = &resume_handle;
87 status = dcerpc_srvsvc_NetShareEnumAll(c.out.dcerpc_pipe, mem_ctx, &s);
89 if (!NT_STATUS_IS_OK(status)) {
90 r->out.error_string = talloc_asprintf(mem_ctx,
91 "srvsvc_NetShareEnumAll on server '%s' failed"
93 r->in.server_name, nt_errstr(status));
97 if (!W_ERROR_IS_OK(s.out.result) && !W_ERROR_EQUAL(s.out.result, WERR_MORE_DATA)) {
98 r->out.error_string = talloc_asprintf(mem_ctx,
99 "srvsvc_NetShareEnumAll on server '%s' failed: %s",
100 r->in.server_name, win_errstr(s.out.result));
104 r->out.ctr = s.out.ctr;
107 talloc_free(c.out.dcerpc_pipe);
113 NTSTATUS libnet_AddShare(struct libnet_context *ctx,
114 TALLOC_CTX *mem_ctx, struct libnet_AddShare *r)
117 struct libnet_RpcConnect c;
118 struct srvsvc_NetShareAdd s;
120 c.level = LIBNET_RPC_CONNECT_SERVER;
121 c.in.name = r->in.server_name;
122 c.in.dcerpc_iface = &dcerpc_table_srvsvc;
124 status = libnet_RpcConnect(ctx, mem_ctx, &c);
125 if (!NT_STATUS_IS_OK(status)) {
126 r->out.error_string = talloc_asprintf(mem_ctx,
127 "Connection to SRVSVC pipe of server %s "
129 r->in.server_name, nt_errstr(status));
133 s.in.level = r->in.level;
134 s.in.info.info2 = &r->in.share;
135 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", r->in.server_name);
137 status = dcerpc_srvsvc_NetShareAdd(c.out.dcerpc_pipe, mem_ctx,&s);
139 if (!NT_STATUS_IS_OK(status)) {
140 r->out.error_string = talloc_asprintf(mem_ctx,
141 "srvsvc_NetShareAdd on server '%s' failed"
143 r->in.server_name, nt_errstr(status));
146 talloc_free(c.out.dcerpc_pipe);
152 NTSTATUS libnet_DelShare(struct libnet_context *ctx,
153 TALLOC_CTX *mem_ctx, struct libnet_DelShare *r)
156 struct libnet_RpcConnect c;
157 struct srvsvc_NetShareDel s;
159 c.level = LIBNET_RPC_CONNECT_SERVER;
160 c.in.name = r->in.server_name;
161 c.in.dcerpc_iface = &dcerpc_table_srvsvc;
163 status = libnet_RpcConnect(ctx, mem_ctx, &c);
164 if (!NT_STATUS_IS_OK(status)) {
165 r->out.error_string = talloc_asprintf(mem_ctx,
166 "Connection to SRVSVC pipe of server %s "
168 r->in.server_name, nt_errstr(status));
172 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", r->in.server_name);
173 s.in.share_name = r->in.share_name;
175 status = dcerpc_srvsvc_NetShareDel(c.out.dcerpc_pipe, mem_ctx, &s);
176 if (!NT_STATUS_IS_OK(status)) {
177 r->out.error_string = talloc_asprintf(mem_ctx,
178 "srvsvc_NetShareDel on server '%s' failed"
180 r->in.server_name, nt_errstr(status));
183 talloc_free(c.out.dcerpc_pipe);