Fix very old bug in ASQ
[Samba/ekacnet.git] / source4 / libnet / libnet_share.c
blobe24ba8161a9d5fd67a38ef55c8820c2f58a664a3
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 3 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, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "libnet/libnet.h"
22 #include "librpc/gen_ndr/ndr_srvsvc_c.h"
25 NTSTATUS libnet_ListShares(struct libnet_context *ctx,
26 TALLOC_CTX *mem_ctx, struct libnet_ListShares *r)
28 NTSTATUS status;
29 struct libnet_RpcConnect c;
30 struct srvsvc_NetShareEnumAll s;
31 uint32_t resume_handle = 0;
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 = &ndr_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 "
48 "failed: %s",
49 r->in.server_name,
50 nt_errstr(status));
51 return status;
54 s.in.level = r->in.level;
55 switch (s.in.level) {
56 case 0:
57 s.in.ctr.ctr0 = &ctr0;
58 ZERO_STRUCT(ctr0);
59 break;
60 case 1:
61 s.in.ctr.ctr1 = &ctr1;
62 ZERO_STRUCT(ctr1);
63 break;
64 case 2:
65 s.in.ctr.ctr2 = &ctr2;
66 ZERO_STRUCT(ctr2);
67 break;
68 case 501:
69 s.in.ctr.ctr501 = &ctr501;
70 ZERO_STRUCT(ctr501);
71 break;
72 case 502:
73 s.in.ctr.ctr502 = &ctr502;
74 ZERO_STRUCT(ctr502);
75 break;
76 default:
77 r->out.error_string = talloc_asprintf(mem_ctx,
78 "libnet_ListShares: Invalid info level requested: %d",
79 s.in.level);
80 return NT_STATUS_INVALID_PARAMETER;
82 s.in.max_buffer = ~0;
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"
91 ": %s",
92 r->in.server_name, nt_errstr(status));
93 goto disconnect;
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));
100 goto disconnect;
103 r->out.ctr = s.out.ctr;
105 disconnect:
106 talloc_free(c.out.dcerpc_pipe);
108 return status;
112 NTSTATUS libnet_AddShare(struct libnet_context *ctx,
113 TALLOC_CTX *mem_ctx, struct libnet_AddShare *r)
115 NTSTATUS status;
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 = &ndr_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 "
127 "failed: %s",
128 r->in.server_name, nt_errstr(status));
129 return status;
132 s.in.level = 2;
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 '%s' on server '%s' failed"
141 ": %s",
142 r->in.share.name, r->in.server_name,
143 nt_errstr(status));
144 } else if (!W_ERROR_IS_OK(s.out.result)) {
145 r->out.error_string = talloc_asprintf(mem_ctx,
146 "srvsvc_NetShareAdd '%s' on server '%s' failed"
147 ": %s",
148 r->in.share.name, r->in.server_name,
149 win_errstr(s.out.result));
150 status = werror_to_ntstatus(s.out.result);
153 talloc_free(c.out.dcerpc_pipe);
155 return status;
159 NTSTATUS libnet_DelShare(struct libnet_context *ctx,
160 TALLOC_CTX *mem_ctx, struct libnet_DelShare *r)
162 NTSTATUS status;
163 struct libnet_RpcConnect c;
164 struct srvsvc_NetShareDel s;
166 c.level = LIBNET_RPC_CONNECT_SERVER;
167 c.in.name = r->in.server_name;
168 c.in.dcerpc_iface = &ndr_table_srvsvc;
170 status = libnet_RpcConnect(ctx, mem_ctx, &c);
171 if (!NT_STATUS_IS_OK(status)) {
172 r->out.error_string = talloc_asprintf(mem_ctx,
173 "Connection to SRVSVC pipe of server %s "
174 "failed: %s",
175 r->in.server_name, nt_errstr(status));
176 return status;
179 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", r->in.server_name);
180 s.in.share_name = r->in.share_name;
182 status = dcerpc_srvsvc_NetShareDel(c.out.dcerpc_pipe, mem_ctx, &s);
183 if (!NT_STATUS_IS_OK(status)) {
184 r->out.error_string = talloc_asprintf(mem_ctx,
185 "srvsvc_NetShareDel '%s' on server '%s' failed"
186 ": %s",
187 r->in.share_name, r->in.server_name,
188 nt_errstr(status));
189 } else if (!W_ERROR_IS_OK(s.out.result)) {
190 r->out.error_string = talloc_asprintf(mem_ctx,
191 "srvsvc_NetShareDel '%s' on server '%s' failed"
192 ": %s",
193 r->in.share_name, r->in.server_name,
194 win_errstr(s.out.result));
195 status = werror_to_ntstatus(s.out.result);
198 talloc_free(c.out.dcerpc_pipe);
200 return status;