r20272: Fix for BASE-BENCH-READWRITE from Mathias Dietz <MDIETZ@de.ibm.com>
[Samba/ekacnet.git] / source4 / libnet / libnet_share.c
blobc22256fe4bc177644a88051d45411b12b532f5b0
1 /*
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.
21 #include "includes.h"
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)
29 NTSTATUS status;
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 "
49 "failed: %s",
50 r->in.server_name,
51 nt_errstr(status));
52 return status;
55 s.in.level = r->in.level;
56 switch (s.in.level) {
57 case 0:
58 s.in.ctr.ctr0 = &ctr0;
59 ZERO_STRUCT(ctr0);
60 break;
61 case 1:
62 s.in.ctr.ctr1 = &ctr1;
63 ZERO_STRUCT(ctr1);
64 break;
65 case 2:
66 s.in.ctr.ctr2 = &ctr2;
67 ZERO_STRUCT(ctr2);
68 break;
69 case 501:
70 s.in.ctr.ctr501 = &ctr501;
71 ZERO_STRUCT(ctr501);
72 break;
73 case 502:
74 s.in.ctr.ctr502 = &ctr502;
75 ZERO_STRUCT(ctr502);
76 break;
77 default:
78 r->out.error_string = talloc_asprintf(mem_ctx,
79 "libnet_ListShares: Invalid info level requested: %d",
80 s.in.level);
81 return NT_STATUS_INVALID_PARAMETER;
83 s.in.max_buffer = ~0;
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"
92 ": %s",
93 r->in.server_name, nt_errstr(status));
94 goto disconnect;
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));
101 goto disconnect;
104 r->out.ctr = s.out.ctr;
106 disconnect:
107 talloc_free(c.out.dcerpc_pipe);
109 return status;
113 NTSTATUS libnet_AddShare(struct libnet_context *ctx,
114 TALLOC_CTX *mem_ctx, struct libnet_AddShare *r)
116 NTSTATUS status;
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 "
128 "failed: %s",
129 r->in.server_name, nt_errstr(status));
130 return status;
133 s.in.level = 2;
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 '%s' on server '%s' failed"
142 ": %s",
143 r->in.share.name, r->in.server_name,
144 nt_errstr(status));
145 } else if (!W_ERROR_IS_OK(s.out.result)) {
146 r->out.error_string = talloc_asprintf(mem_ctx,
147 "srvsvc_NetShareAdd '%s' on server '%s' failed"
148 ": %s",
149 r->in.share.name, r->in.server_name,
150 win_errstr(s.out.result));
151 status = werror_to_ntstatus(s.out.result);
154 talloc_free(c.out.dcerpc_pipe);
156 return status;
160 NTSTATUS libnet_DelShare(struct libnet_context *ctx,
161 TALLOC_CTX *mem_ctx, struct libnet_DelShare *r)
163 NTSTATUS status;
164 struct libnet_RpcConnect c;
165 struct srvsvc_NetShareDel s;
167 c.level = LIBNET_RPC_CONNECT_SERVER;
168 c.in.name = r->in.server_name;
169 c.in.dcerpc_iface = &dcerpc_table_srvsvc;
171 status = libnet_RpcConnect(ctx, mem_ctx, &c);
172 if (!NT_STATUS_IS_OK(status)) {
173 r->out.error_string = talloc_asprintf(mem_ctx,
174 "Connection to SRVSVC pipe of server %s "
175 "failed: %s",
176 r->in.server_name, nt_errstr(status));
177 return status;
180 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", r->in.server_name);
181 s.in.share_name = r->in.share_name;
183 status = dcerpc_srvsvc_NetShareDel(c.out.dcerpc_pipe, mem_ctx, &s);
184 if (!NT_STATUS_IS_OK(status)) {
185 r->out.error_string = talloc_asprintf(mem_ctx,
186 "srvsvc_NetShareDel '%s' on server '%s' failed"
187 ": %s",
188 r->in.share_name, r->in.server_name,
189 nt_errstr(status));
190 } else if (!W_ERROR_IS_OK(s.out.result)) {
191 r->out.error_string = talloc_asprintf(mem_ctx,
192 "srvsvc_NetShareDel '%s' on server '%s' failed"
193 ": %s",
194 r->in.share_name, r->in.server_name,
195 win_errstr(s.out.result));
196 status = werror_to_ntstatus(s.out.result);
199 talloc_free(c.out.dcerpc_pipe);
201 return status;