2 Unix SMB/CIFS implementation.
5 Copyright (C) Andrew Tridgell 2003-2004
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "libcli/raw/libcliraw.h"
23 #include "librpc/gen_ndr/ndr_security.h"
25 /****************************************************************************
26 fetch file ACL (async send)
27 ****************************************************************************/
28 struct smbcli_request *smb_raw_query_secdesc_send(struct smbcli_tree *tree,
29 union smb_fileinfo *io)
31 struct smb_nttrans nt;
36 nt.in.max_data = 0xFFFF;
37 nt.in.setup_count = 0;
38 nt.in.function = NT_TRANSACT_QUERY_SECURITY_DESC;
41 SSVAL(params, 0, io->query_secdesc.in.file.fnum);
42 SSVAL(params, 2, 0); /* padding */
43 SIVAL(params, 4, io->query_secdesc.in.secinfo_flags);
45 nt.in.params.data = params;
46 nt.in.params.length = 8;
48 nt.in.data = data_blob(NULL, 0);
50 return smb_raw_nttrans_send(tree, &nt);
54 /****************************************************************************
55 fetch file ACL (async recv)
56 ****************************************************************************/
57 NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req,
59 union smb_fileinfo *io)
62 struct smb_nttrans nt;
64 enum ndr_err_code ndr_err;
66 status = smb_raw_nttrans_recv(req, mem_ctx, &nt);
67 if (!NT_STATUS_IS_OK(status)) {
71 /* check that the basics are valid */
72 if (nt.out.params.length != 4 ||
73 IVAL(nt.out.params.data, 0) > nt.out.data.length) {
74 return NT_STATUS_INVALID_PARAMETER;
77 nt.out.data.length = IVAL(nt.out.params.data, 0);
79 ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx);
81 return NT_STATUS_INVALID_PARAMETER;
84 io->query_secdesc.out.sd = talloc(mem_ctx, struct security_descriptor);
85 if (!io->query_secdesc.out.sd) {
86 return NT_STATUS_NO_MEMORY;
88 ndr_err = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS,
89 io->query_secdesc.out.sd);
90 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
91 return ndr_map_error2ntstatus(ndr_err);
98 /****************************************************************************
99 fetch file ACL (sync interface)
100 ****************************************************************************/
101 NTSTATUS smb_raw_query_secdesc(struct smbcli_tree *tree,
103 union smb_fileinfo *io)
105 struct smbcli_request *req = smb_raw_query_secdesc_send(tree, io);
106 return smb_raw_query_secdesc_recv(req, mem_ctx, io);
111 /****************************************************************************
112 set file ACL (async send)
113 ****************************************************************************/
114 struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree,
115 union smb_setfileinfo *io)
117 struct smb_nttrans nt;
119 struct ndr_push *ndr;
120 struct smbcli_request *req;
121 enum ndr_err_code ndr_err;
126 nt.in.setup_count = 0;
127 nt.in.function = NT_TRANSACT_SET_SECURITY_DESC;
130 SSVAL(params, 0, io->set_secdesc.in.file.fnum);
131 SSVAL(params, 2, 0); /* padding */
132 SIVAL(params, 4, io->set_secdesc.in.secinfo_flags);
134 nt.in.params.data = params;
135 nt.in.params.length = 8;
137 ndr = ndr_push_init_ctx(NULL);
138 if (!ndr) return NULL;
140 ndr_err = ndr_push_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, io->set_secdesc.in.sd);
141 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
146 nt.in.data = ndr_push_blob(ndr);
148 req = smb_raw_nttrans_send(tree, &nt);
154 /****************************************************************************
155 set file ACL (sync interface)
156 ****************************************************************************/
157 NTSTATUS smb_raw_set_secdesc(struct smbcli_tree *tree,
158 union smb_setfileinfo *io)
160 struct smbcli_request *req = smb_raw_set_secdesc_send(tree, io);
161 return smbcli_request_simple_recv(req);