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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "libnet/libnet.h"
23 #include "librpc/gen_ndr/ndr_srvsvc_c.h"
26 NTSTATUS
libnet_ListShares(struct libnet_context
*ctx
,
27 TALLOC_CTX
*mem_ctx
, struct libnet_ListShares
*r
)
30 struct libnet_RpcConnect c
;
31 struct srvsvc_NetShareEnumAll s
;
32 uint32_t resume_handle
= 0;
33 struct srvsvc_NetShareCtr0 ctr0
;
34 struct srvsvc_NetShareCtr1 ctr1
;
35 struct srvsvc_NetShareCtr2 ctr2
;
36 struct srvsvc_NetShareCtr501 ctr501
;
37 struct srvsvc_NetShareCtr502 ctr502
;
39 c
.level
= LIBNET_RPC_CONNECT_SERVER
;
40 c
.in
.name
= r
->in
.server_name
;
41 c
.in
.dcerpc_iface
= &dcerpc_table_srvsvc
;
43 s
.in
.server_unc
= talloc_asprintf(mem_ctx
, "\\\\%s", c
.in
.name
);
45 status
= libnet_RpcConnect(ctx
, mem_ctx
, &c
);
46 if (!NT_STATUS_IS_OK(status
)) {
47 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
48 "Connection to SRVSVC pipe of server %s "
55 s
.in
.level
= r
->in
.level
;
58 s
.in
.ctr
.ctr0
= &ctr0
;
62 s
.in
.ctr
.ctr1
= &ctr1
;
66 s
.in
.ctr
.ctr2
= &ctr2
;
70 s
.in
.ctr
.ctr501
= &ctr501
;
74 s
.in
.ctr
.ctr502
= &ctr502
;
78 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
79 "libnet_ListShares: Invalid info level requested: %d",
81 return NT_STATUS_INVALID_PARAMETER
;
84 s
.in
.resume_handle
= &resume_handle
;
87 status
= dcerpc_srvsvc_NetShareEnumAll(c
.out
.dcerpc_pipe
, mem_ctx
, &s
);
89 if (!NT_STATUS_IS_OK(status
)) {
90 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
91 "srvsvc_NetShareEnumAll on server '%s' failed"
93 r
->in
.server_name
, nt_errstr(status
));
97 if (!W_ERROR_IS_OK(s
.out
.result
) && !W_ERROR_EQUAL(s
.out
.result
, WERR_MORE_DATA
)) {
98 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
99 "srvsvc_NetShareEnumAll on server '%s' failed: %s",
100 r
->in
.server_name
, win_errstr(s
.out
.result
));
104 r
->out
.ctr
= s
.out
.ctr
;
107 talloc_free(c
.out
.dcerpc_pipe
);
113 NTSTATUS
libnet_AddShare(struct libnet_context
*ctx
,
114 TALLOC_CTX
*mem_ctx
, struct libnet_AddShare
*r
)
117 struct libnet_RpcConnect c
;
118 struct srvsvc_NetShareAdd s
;
120 c
.level
= LIBNET_RPC_CONNECT_SERVER
;
121 c
.in
.name
= r
->in
.server_name
;
122 c
.in
.dcerpc_iface
= &dcerpc_table_srvsvc
;
124 status
= libnet_RpcConnect(ctx
, mem_ctx
, &c
);
125 if (!NT_STATUS_IS_OK(status
)) {
126 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
127 "Connection to SRVSVC pipe of server %s "
129 r
->in
.server_name
, nt_errstr(status
));
134 s
.in
.info
.info2
= &r
->in
.share
;
135 s
.in
.server_unc
= talloc_asprintf(mem_ctx
, "\\\\%s", r
->in
.server_name
);
137 status
= dcerpc_srvsvc_NetShareAdd(c
.out
.dcerpc_pipe
, mem_ctx
, &s
);
139 if (!NT_STATUS_IS_OK(status
)) {
140 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
141 "srvsvc_NetShareAdd '%s' on server '%s' failed"
143 r
->in
.share
.name
, r
->in
.server_name
,
145 } else if (!W_ERROR_IS_OK(s
.out
.result
)) {
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
,
150 win_errstr(s
.out
.result
));
151 status
= werror_to_ntstatus(s
.out
.result
);
154 talloc_free(c
.out
.dcerpc_pipe
);
160 NTSTATUS
libnet_DelShare(struct libnet_context
*ctx
,
161 TALLOC_CTX
*mem_ctx
, struct libnet_DelShare
*r
)
164 struct libnet_RpcConnect c
;
165 struct srvsvc_NetShareDel s
;
167 c
.level
= LIBNET_RPC_CONNECT_SERVER
;
168 c
.in
.name
= r
->in
.server_name
;
169 c
.in
.dcerpc_iface
= &dcerpc_table_srvsvc
;
171 status
= libnet_RpcConnect(ctx
, mem_ctx
, &c
);
172 if (!NT_STATUS_IS_OK(status
)) {
173 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
174 "Connection to SRVSVC pipe of server %s "
176 r
->in
.server_name
, nt_errstr(status
));
180 s
.in
.server_unc
= talloc_asprintf(mem_ctx
, "\\\\%s", r
->in
.server_name
);
181 s
.in
.share_name
= r
->in
.share_name
;
183 status
= dcerpc_srvsvc_NetShareDel(c
.out
.dcerpc_pipe
, mem_ctx
, &s
);
184 if (!NT_STATUS_IS_OK(status
)) {
185 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
186 "srvsvc_NetShareDel '%s' on server '%s' failed"
188 r
->in
.share_name
, r
->in
.server_name
,
190 } else if (!W_ERROR_IS_OK(s
.out
.result
)) {
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
,
195 win_errstr(s
.out
.result
));
196 status
= werror_to_ntstatus(s
.out
.result
);
199 talloc_free(c
.out
.dcerpc_pipe
);