WHATSNEW: Add release notes for Samba 4.1.0rc2.
[Samba.git] / source4 / libcli / raw / rawacl.c
blobc2de2cc7d22cacf26aaf81202ed7d73bb66db27c
1 /*
2 Unix SMB/CIFS implementation.
3 ACL get/set operations
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/>.
21 #include "includes.h"
22 #include "libcli/raw/libcliraw.h"
23 #include "libcli/raw/raw_proto.h"
24 #include "librpc/gen_ndr/ndr_security.h"
26 /****************************************************************************
27 fetch file ACL (async send)
28 ****************************************************************************/
29 struct smbcli_request *smb_raw_query_secdesc_send(struct smbcli_tree *tree,
30 union smb_fileinfo *io)
32 struct smb_nttrans nt;
33 uint8_t params[8];
35 nt.in.max_setup = 0;
36 nt.in.max_param = 4;
37 nt.in.max_data = 0xFFFF;
38 nt.in.setup_count = 0;
39 nt.in.function = NT_TRANSACT_QUERY_SECURITY_DESC;
40 nt.in.setup = NULL;
42 SSVAL(params, 0, io->query_secdesc.in.file.fnum);
43 SSVAL(params, 2, 0); /* padding */
44 SIVAL(params, 4, io->query_secdesc.in.secinfo_flags);
46 nt.in.params.data = params;
47 nt.in.params.length = 8;
49 nt.in.data = data_blob(NULL, 0);
51 return smb_raw_nttrans_send(tree, &nt);
55 /****************************************************************************
56 fetch file ACL (async recv)
57 ****************************************************************************/
58 NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req,
59 TALLOC_CTX *mem_ctx,
60 union smb_fileinfo *io)
62 NTSTATUS status;
63 struct smb_nttrans nt;
64 struct ndr_pull *ndr;
65 enum ndr_err_code ndr_err;
67 status = smb_raw_nttrans_recv(req, mem_ctx, &nt);
68 if (!NT_STATUS_IS_OK(status)) {
69 return status;
72 /* check that the basics are valid */
73 if (nt.out.params.length != 4 ||
74 IVAL(nt.out.params.data, 0) > nt.out.data.length) {
75 return NT_STATUS_INVALID_PARAMETER;
78 nt.out.data.length = IVAL(nt.out.params.data, 0);
80 ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx);
81 if (!ndr) {
82 return NT_STATUS_INVALID_PARAMETER;
85 io->query_secdesc.out.sd = talloc(mem_ctx, struct security_descriptor);
86 if (!io->query_secdesc.out.sd) {
87 return NT_STATUS_NO_MEMORY;
89 ndr_err = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS,
90 io->query_secdesc.out.sd);
91 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
92 return ndr_map_error2ntstatus(ndr_err);
95 return NT_STATUS_OK;
99 /****************************************************************************
100 fetch file ACL (sync interface)
101 ****************************************************************************/
102 NTSTATUS smb_raw_query_secdesc(struct smbcli_tree *tree,
103 TALLOC_CTX *mem_ctx,
104 union smb_fileinfo *io)
106 struct smbcli_request *req = smb_raw_query_secdesc_send(tree, io);
107 return smb_raw_query_secdesc_recv(req, mem_ctx, io);
112 /****************************************************************************
113 set file ACL (async send)
114 ****************************************************************************/
115 struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree,
116 union smb_setfileinfo *io)
118 struct smb_nttrans nt;
119 uint8_t params[8];
120 struct ndr_push *ndr;
121 struct smbcli_request *req;
122 enum ndr_err_code ndr_err;
124 nt.in.max_setup = 0;
125 nt.in.max_param = 0;
126 nt.in.max_data = 0;
127 nt.in.setup_count = 0;
128 nt.in.function = NT_TRANSACT_SET_SECURITY_DESC;
129 nt.in.setup = NULL;
131 SSVAL(params, 0, io->set_secdesc.in.file.fnum);
132 SSVAL(params, 2, 0); /* padding */
133 SIVAL(params, 4, io->set_secdesc.in.secinfo_flags);
135 nt.in.params.data = params;
136 nt.in.params.length = 8;
138 ndr = ndr_push_init_ctx(NULL);
139 if (!ndr) return NULL;
141 ndr_err = ndr_push_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, io->set_secdesc.in.sd);
142 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
143 talloc_free(ndr);
144 return NULL;
147 nt.in.data = ndr_push_blob(ndr);
149 req = smb_raw_nttrans_send(tree, &nt);
151 talloc_free(ndr);
152 return req;
155 /****************************************************************************
156 set file ACL (sync interface)
157 ****************************************************************************/
158 NTSTATUS smb_raw_set_secdesc(struct smbcli_tree *tree,
159 union smb_setfileinfo *io)
161 struct smbcli_request *req = smb_raw_set_secdesc_send(tree, io);
162 return smbcli_request_simple_recv(req);