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.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
;
33 struct srvsvc_NetShareCtr0 ctr0
;
35 c
.level
= LIBNET_RPC_CONNECT_SERVER
;
36 c
.in
.domain_name
= r
->in
.server_name
;
37 c
.in
.dcerpc_iface_name
= DCERPC_SRVSVC_NAME
;
38 c
.in
.dcerpc_iface_uuid
= DCERPC_SRVSVC_UUID
;
39 c
.in
.dcerpc_iface_version
= DCERPC_SRVSVC_VERSION
;
41 status
= libnet_RpcConnect(ctx
, mem_ctx
, &c
);
42 if (!NT_STATUS_IS_OK(status
)) {
43 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
44 "Connection to SRVSVC pipe of server %s "
51 s
.in
.level
= r
->in
.level
;
52 s
.in
.ctr
.ctr0
= &ctr0
;
54 s
.in
.resume_handle
= &resume_handle
;
58 status
= dcerpc_srvsvc_NetShareEnumAll(c
.out
.dcerpc_pipe
, mem_ctx
, &s
);
60 if (!NT_STATUS_IS_OK(status
)) {
61 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
62 "srvsvc_NetShareEnumAll on server '%s' failed"
64 r
->in
.server_name
, nt_errstr(status
));
68 if (!W_ERROR_IS_OK(s
.out
.result
) && !W_ERROR_EQUAL(s
.out
.result
, WERR_MORE_DATA
)) {
72 r
->out
.ctr
= s
.out
.ctr
;
75 talloc_free(c
.out
.dcerpc_pipe
);
81 NTSTATUS
libnet_AddShare(struct libnet_context
*ctx
,
82 TALLOC_CTX
*mem_ctx
, struct libnet_AddShare
*r
)
85 struct libnet_RpcConnect c
;
86 struct srvsvc_NetShareAdd s
;
88 c
.level
= LIBNET_RPC_CONNECT_SERVER
;
89 c
.in
.domain_name
= r
->in
.server_name
;
90 c
.in
.dcerpc_iface_name
= DCERPC_SRVSVC_NAME
;
91 c
.in
.dcerpc_iface_uuid
= DCERPC_SRVSVC_UUID
;
92 c
.in
.dcerpc_iface_version
= DCERPC_SRVSVC_VERSION
;
94 status
= libnet_RpcConnect(ctx
, mem_ctx
, &c
);
95 if (!NT_STATUS_IS_OK(status
)) {
96 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
97 "Connection to SRVSVC pipe of server %s "
99 r
->in
.server_name
, nt_errstr(status
));
103 s
.in
.level
= r
->in
.level
;
104 s
.in
.info
.info2
= &r
->in
.share
;
105 s
.in
.server_unc
= talloc_asprintf(mem_ctx
, "\\\\%s", r
->in
.server_name
);
107 status
= dcerpc_srvsvc_NetShareAdd(c
.out
.dcerpc_pipe
, mem_ctx
,&s
);
109 if (!NT_STATUS_IS_OK(status
)) {
110 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
111 "srvsvc_NetShareAdd on server '%s' failed"
113 r
->in
.server_name
, nt_errstr(status
));
116 talloc_free(c
.out
.dcerpc_pipe
);
122 NTSTATUS
libnet_DelShare(struct libnet_context
*ctx
,
123 TALLOC_CTX
*mem_ctx
, struct libnet_DelShare
*r
)
126 struct libnet_RpcConnect c
;
127 struct srvsvc_NetShareDel s
;
129 c
.level
= LIBNET_RPC_CONNECT_SERVER
;
130 c
.in
.domain_name
= r
->in
.server_name
;
131 c
.in
.dcerpc_iface_name
= DCERPC_SRVSVC_NAME
;
132 c
.in
.dcerpc_iface_uuid
= DCERPC_SRVSVC_UUID
;
133 c
.in
.dcerpc_iface_version
= DCERPC_SRVSVC_VERSION
;
135 status
= libnet_RpcConnect(ctx
, mem_ctx
, &c
);
136 if (!NT_STATUS_IS_OK(status
)) {
137 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
138 "Connection to SRVSVC pipe of server %s "
140 r
->in
.server_name
, nt_errstr(status
));
144 s
.in
.server_unc
= talloc_asprintf(mem_ctx
, "\\\\%s", r
->in
.server_name
);
145 s
.in
.share_name
= r
->in
.share_name
;
147 status
= dcerpc_srvsvc_NetShareDel(c
.out
.dcerpc_pipe
, mem_ctx
, &s
);
148 if (!NT_STATUS_IS_OK(status
)) {
149 r
->out
.error_string
= talloc_asprintf(mem_ctx
,
150 "srvsvc_NetShareDel on server '%s' failed"
152 r
->in
.server_name
, nt_errstr(status
));
155 talloc_free(c
.out
.dcerpc_pipe
);