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/>.
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
)
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
;
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 "
58 info_ctr
.level
= r
->in
.level
;
59 switch (info_ctr
.level
) {
61 info_ctr
.ctr
.ctr0
= &ctr0
;
65 info_ctr
.ctr
.ctr1
= &ctr1
;
69 info_ctr
.ctr
.ctr2
= &ctr2
;
73 info_ctr
.ctr
.ctr501
= &ctr501
;
77 info_ctr
.ctr
.ctr502
= &ctr502
;
81 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
82 "libnet_ListShares: Invalid info level requested: %d",
84 return NT_STATUS_INVALID_PARAMETER
;
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_r(c
.out
.dcerpc_pipe
->binding_handle
, 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"
98 r
->in
.server_name
, nt_errstr(status
));
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
));
109 r
->out
.ctr
= s
.out
.info_ctr
->ctr
;
112 talloc_free(c
.out
.dcerpc_pipe
);
118 NTSTATUS
libnet_AddShare(struct libnet_context
*ctx
,
119 TALLOC_CTX
*mem_ctx
, struct libnet_AddShare
*r
)
122 struct libnet_RpcConnect c
;
123 struct srvsvc_NetShareAdd s
;
124 union srvsvc_NetShareInfo info
;
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 "
137 r
->in
.server_name
, nt_errstr(status
));
141 info
.info2
= &r
->in
.share
;
145 s
.in
.server_unc
= talloc_asprintf(mem_ctx
, "\\\\%s", r
->in
.server_name
);
147 status
= dcerpc_srvsvc_NetShareAdd_r(c
.out
.dcerpc_pipe
->binding_handle
, 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"
153 r
->in
.share
.name
, r
->in
.server_name
,
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"
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
);
170 NTSTATUS
libnet_DelShare(struct libnet_context
*ctx
,
171 TALLOC_CTX
*mem_ctx
, struct libnet_DelShare
*r
)
174 struct libnet_RpcConnect c
;
175 struct srvsvc_NetShareDel s
;
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 "
188 r
->in
.server_name
, nt_errstr(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_r(c
.out
.dcerpc_pipe
->binding_handle
, 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"
200 r
->in
.share_name
, r
->in
.server_name
,
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"
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
);