s4-drs: add defines for replication flags on attributes
[Samba/gebeck_regimport.git] / source4 / libnet / libnet_share.c
blobe9ad83db36a6b2644b5ddfca52874a8672d18a21
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 struct srvsvc_NetShareInfoCtr info_ctr;
32 uint32_t resume_handle = 0;
33 uint32_t totalentries = 0;
34 struct srvsvc_NetShareCtr0 ctr0;
35 struct srvsvc_NetShareCtr1 ctr1;
36 struct srvsvc_NetShareCtr2 ctr2;
37 struct srvsvc_NetShareCtr501 ctr501;
38 struct srvsvc_NetShareCtr502 ctr502;
40 ZERO_STRUCT(c);
42 c.level = LIBNET_RPC_CONNECT_SERVER;
43 c.in.name = r->in.server_name;
44 c.in.dcerpc_iface = &ndr_table_srvsvc;
46 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", c.in.name);
48 status = libnet_RpcConnect(ctx, mem_ctx, &c);
49 if (!NT_STATUS_IS_OK(status)) {
50 r->out.error_string = talloc_asprintf(mem_ctx,
51 "Connection to SRVSVC pipe of server %s "
52 "failed: %s",
53 r->in.server_name,
54 nt_errstr(status));
55 return status;
58 info_ctr.level = r->in.level;
59 switch (info_ctr.level) {
60 case 0:
61 info_ctr.ctr.ctr0 = &ctr0;
62 ZERO_STRUCT(ctr0);
63 break;
64 case 1:
65 info_ctr.ctr.ctr1 = &ctr1;
66 ZERO_STRUCT(ctr1);
67 break;
68 case 2:
69 info_ctr.ctr.ctr2 = &ctr2;
70 ZERO_STRUCT(ctr2);
71 break;
72 case 501:
73 info_ctr.ctr.ctr501 = &ctr501;
74 ZERO_STRUCT(ctr501);
75 break;
76 case 502:
77 info_ctr.ctr.ctr502 = &ctr502;
78 ZERO_STRUCT(ctr502);
79 break;
80 default:
81 r->out.error_string = talloc_asprintf(mem_ctx,
82 "libnet_ListShares: Invalid info level requested: %d",
83 info_ctr.level);
84 return NT_STATUS_INVALID_PARAMETER;
86 s.in.max_buffer = ~0;
87 s.in.resume_handle = &resume_handle;
88 s.in.info_ctr = &info_ctr;
89 s.out.info_ctr = &info_ctr;
90 s.out.totalentries = &totalentries;
92 status = dcerpc_srvsvc_NetShareEnumAll(c.out.dcerpc_pipe, mem_ctx, &s);
94 if (!NT_STATUS_IS_OK(status)) {
95 r->out.error_string = talloc_asprintf(mem_ctx,
96 "srvsvc_NetShareEnumAll on server '%s' failed"
97 ": %s",
98 r->in.server_name, nt_errstr(status));
99 goto disconnect;
102 if (!W_ERROR_IS_OK(s.out.result) && !W_ERROR_EQUAL(s.out.result, WERR_MORE_DATA)) {
103 r->out.error_string = talloc_asprintf(mem_ctx,
104 "srvsvc_NetShareEnumAll on server '%s' failed: %s",
105 r->in.server_name, win_errstr(s.out.result));
106 goto disconnect;
109 r->out.ctr = s.out.info_ctr->ctr;
111 disconnect:
112 talloc_free(c.out.dcerpc_pipe);
114 return status;
118 NTSTATUS libnet_AddShare(struct libnet_context *ctx,
119 TALLOC_CTX *mem_ctx, struct libnet_AddShare *r)
121 NTSTATUS status;
122 struct libnet_RpcConnect c;
123 struct srvsvc_NetShareAdd s;
124 union srvsvc_NetShareInfo info;
126 ZERO_STRUCT(c);
128 c.level = LIBNET_RPC_CONNECT_SERVER;
129 c.in.name = r->in.server_name;
130 c.in.dcerpc_iface = &ndr_table_srvsvc;
132 status = libnet_RpcConnect(ctx, mem_ctx, &c);
133 if (!NT_STATUS_IS_OK(status)) {
134 r->out.error_string = talloc_asprintf(mem_ctx,
135 "Connection to SRVSVC pipe of server %s "
136 "failed: %s",
137 r->in.server_name, nt_errstr(status));
138 return status;
141 info.info2 = &r->in.share;
143 s.in.level = 2;
144 s.in.info = &info;
145 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", r->in.server_name);
147 status = dcerpc_srvsvc_NetShareAdd(c.out.dcerpc_pipe, mem_ctx, &s);
149 if (!NT_STATUS_IS_OK(status)) {
150 r->out.error_string = talloc_asprintf(mem_ctx,
151 "srvsvc_NetShareAdd '%s' on server '%s' failed"
152 ": %s",
153 r->in.share.name, r->in.server_name,
154 nt_errstr(status));
155 } else if (!W_ERROR_IS_OK(s.out.result)) {
156 r->out.error_string = talloc_asprintf(mem_ctx,
157 "srvsvc_NetShareAdd '%s' on server '%s' failed"
158 ": %s",
159 r->in.share.name, r->in.server_name,
160 win_errstr(s.out.result));
161 status = werror_to_ntstatus(s.out.result);
164 talloc_free(c.out.dcerpc_pipe);
166 return status;
170 NTSTATUS libnet_DelShare(struct libnet_context *ctx,
171 TALLOC_CTX *mem_ctx, struct libnet_DelShare *r)
173 NTSTATUS status;
174 struct libnet_RpcConnect c;
175 struct srvsvc_NetShareDel s;
177 ZERO_STRUCT(c);
179 c.level = LIBNET_RPC_CONNECT_SERVER;
180 c.in.name = r->in.server_name;
181 c.in.dcerpc_iface = &ndr_table_srvsvc;
183 status = libnet_RpcConnect(ctx, mem_ctx, &c);
184 if (!NT_STATUS_IS_OK(status)) {
185 r->out.error_string = talloc_asprintf(mem_ctx,
186 "Connection to SRVSVC pipe of server %s "
187 "failed: %s",
188 r->in.server_name, nt_errstr(status));
189 return status;
192 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", r->in.server_name);
193 s.in.share_name = r->in.share_name;
195 status = dcerpc_srvsvc_NetShareDel(c.out.dcerpc_pipe, mem_ctx, &s);
196 if (!NT_STATUS_IS_OK(status)) {
197 r->out.error_string = talloc_asprintf(mem_ctx,
198 "srvsvc_NetShareDel '%s' on server '%s' failed"
199 ": %s",
200 r->in.share_name, r->in.server_name,
201 nt_errstr(status));
202 } else if (!W_ERROR_IS_OK(s.out.result)) {
203 r->out.error_string = talloc_asprintf(mem_ctx,
204 "srvsvc_NetShareDel '%s' on server '%s' failed"
205 ": %s",
206 r->in.share_name, r->in.server_name,
207 win_errstr(s.out.result));
208 status = werror_to_ntstatus(s.out.result);
211 talloc_free(c.out.dcerpc_pipe);
213 return status;