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 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 "
54 s
.in
.level
= r
->in
.level
;
57 s
.in
.ctr
.ctr0
= &ctr0
;
61 s
.in
.ctr
.ctr1
= &ctr1
;
65 s
.in
.ctr
.ctr2
= &ctr2
;
69 s
.in
.ctr
.ctr501
= &ctr501
;
73 s
.in
.ctr
.ctr502
= &ctr502
;
77 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
78 "libnet_ListShares: Invalid info level requested: %d",
80 return NT_STATUS_INVALID_PARAMETER
;
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"
92 r
->in
.server_name
, nt_errstr(status
));
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
));
103 r
->out
.ctr
= s
.out
.ctr
;
106 talloc_free(c
.out
.dcerpc_pipe
);
112 NTSTATUS
libnet_AddShare(struct libnet_context
*ctx
,
113 TALLOC_CTX
*mem_ctx
, struct libnet_AddShare
*r
)
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 "
128 r
->in
.server_name
, nt_errstr(status
));
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"
142 r
->in
.share
.name
, r
->in
.server_name
,
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"
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
);
159 NTSTATUS
libnet_DelShare(struct libnet_context
*ctx
,
160 TALLOC_CTX
*mem_ctx
, struct libnet_DelShare
*r
)
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 "
175 r
->in
.server_name
, nt_errstr(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"
187 r
->in
.share_name
, r
->in
.server_name
,
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"
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
);