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
;
40 c
.level
= LIBNET_RPC_CONNECT_SERVER
;
41 c
.in
.name
= r
->in
.server_name
;
42 c
.in
.dcerpc_iface
= &ndr_table_srvsvc
;
44 s
.in
.server_unc
= talloc_asprintf(mem_ctx
, "\\\\%s", c
.in
.name
);
46 status
= libnet_RpcConnect(ctx
, mem_ctx
, &c
);
47 if (!NT_STATUS_IS_OK(status
)) {
48 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
49 "Connection to SRVSVC pipe of server %s "
56 info_ctr
.level
= r
->in
.level
;
57 switch (info_ctr
.level
) {
59 info_ctr
.ctr
.ctr0
= &ctr0
;
63 info_ctr
.ctr
.ctr1
= &ctr1
;
67 info_ctr
.ctr
.ctr2
= &ctr2
;
71 info_ctr
.ctr
.ctr501
= &ctr501
;
75 info_ctr
.ctr
.ctr502
= &ctr502
;
79 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
80 "libnet_ListShares: Invalid info level requested: %d",
82 return NT_STATUS_INVALID_PARAMETER
;
85 s
.in
.resume_handle
= &resume_handle
;
86 s
.in
.info_ctr
= &info_ctr
;
87 s
.out
.info_ctr
= &info_ctr
;
88 s
.out
.totalentries
= &totalentries
;
90 status
= dcerpc_srvsvc_NetShareEnumAll(c
.out
.dcerpc_pipe
, mem_ctx
, &s
);
92 if (!NT_STATUS_IS_OK(status
)) {
93 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
94 "srvsvc_NetShareEnumAll on server '%s' failed"
96 r
->in
.server_name
, nt_errstr(status
));
100 if (!W_ERROR_IS_OK(s
.out
.result
) && !W_ERROR_EQUAL(s
.out
.result
, WERR_MORE_DATA
)) {
101 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
102 "srvsvc_NetShareEnumAll on server '%s' failed: %s",
103 r
->in
.server_name
, win_errstr(s
.out
.result
));
107 r
->out
.ctr
= s
.out
.info_ctr
->ctr
;
110 talloc_free(c
.out
.dcerpc_pipe
);
116 NTSTATUS
libnet_AddShare(struct libnet_context
*ctx
,
117 TALLOC_CTX
*mem_ctx
, struct libnet_AddShare
*r
)
120 struct libnet_RpcConnect c
;
121 struct srvsvc_NetShareAdd s
;
122 union srvsvc_NetShareInfo info
;
124 c
.level
= LIBNET_RPC_CONNECT_SERVER
;
125 c
.in
.name
= r
->in
.server_name
;
126 c
.in
.dcerpc_iface
= &ndr_table_srvsvc
;
128 status
= libnet_RpcConnect(ctx
, mem_ctx
, &c
);
129 if (!NT_STATUS_IS_OK(status
)) {
130 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
131 "Connection to SRVSVC pipe of server %s "
133 r
->in
.server_name
, nt_errstr(status
));
137 info
.info2
= &r
->in
.share
;
141 s
.in
.server_unc
= talloc_asprintf(mem_ctx
, "\\\\%s", r
->in
.server_name
);
143 status
= dcerpc_srvsvc_NetShareAdd(c
.out
.dcerpc_pipe
, mem_ctx
, &s
);
145 if (!NT_STATUS_IS_OK(status
)) {
146 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
147 "srvsvc_NetShareAdd '%s' on server '%s' failed"
149 r
->in
.share
.name
, r
->in
.server_name
,
151 } else if (!W_ERROR_IS_OK(s
.out
.result
)) {
152 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
153 "srvsvc_NetShareAdd '%s' on server '%s' failed"
155 r
->in
.share
.name
, r
->in
.server_name
,
156 win_errstr(s
.out
.result
));
157 status
= werror_to_ntstatus(s
.out
.result
);
160 talloc_free(c
.out
.dcerpc_pipe
);
166 NTSTATUS
libnet_DelShare(struct libnet_context
*ctx
,
167 TALLOC_CTX
*mem_ctx
, struct libnet_DelShare
*r
)
170 struct libnet_RpcConnect c
;
171 struct srvsvc_NetShareDel s
;
173 c
.level
= LIBNET_RPC_CONNECT_SERVER
;
174 c
.in
.name
= r
->in
.server_name
;
175 c
.in
.dcerpc_iface
= &ndr_table_srvsvc
;
177 status
= libnet_RpcConnect(ctx
, mem_ctx
, &c
);
178 if (!NT_STATUS_IS_OK(status
)) {
179 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
180 "Connection to SRVSVC pipe of server %s "
182 r
->in
.server_name
, nt_errstr(status
));
186 s
.in
.server_unc
= talloc_asprintf(mem_ctx
, "\\\\%s", r
->in
.server_name
);
187 s
.in
.share_name
= r
->in
.share_name
;
189 status
= dcerpc_srvsvc_NetShareDel(c
.out
.dcerpc_pipe
, mem_ctx
, &s
);
190 if (!NT_STATUS_IS_OK(status
)) {
191 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
192 "srvsvc_NetShareDel '%s' on server '%s' failed"
194 r
->in
.share_name
, r
->in
.server_name
,
196 } else if (!W_ERROR_IS_OK(s
.out
.result
)) {
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
,
201 win_errstr(s
.out
.result
));
202 status
= werror_to_ntstatus(s
.out
.result
);
205 talloc_free(c
.out
.dcerpc_pipe
);