Install public header files again and include required prototypes.
[jelmer/samba4-debian.git] / source / libcli / raw / rawacl.c
1 /* 
2    Unix SMB/CIFS implementation.
3    ACL get/set operations
4
5    Copyright (C) Andrew Tridgell 2003-2004
6    
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.
11    
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.
16    
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/>.
19 */
20
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"
25 #include "param/param.h"
26
27 /****************************************************************************
28 fetch file ACL (async send)
29 ****************************************************************************/
30 struct smbcli_request *smb_raw_query_secdesc_send(struct smbcli_tree *tree, 
31                                                   union smb_fileinfo *io)
32 {
33         struct smb_nttrans nt;
34         uint8_t params[8];
35
36         nt.in.max_setup = 0;
37         nt.in.max_param = 4;
38         nt.in.max_data = 0xFFFF;
39         nt.in.setup_count = 0;
40         nt.in.function = NT_TRANSACT_QUERY_SECURITY_DESC;
41         nt.in.setup = NULL;
42
43         SSVAL(params, 0, io->query_secdesc.in.file.fnum);
44         SSVAL(params, 2, 0); /* padding */
45         SIVAL(params, 4, io->query_secdesc.in.secinfo_flags);
46
47         nt.in.params.data = params;
48         nt.in.params.length = 8;
49         
50         nt.in.data = data_blob(NULL, 0);
51
52         return smb_raw_nttrans_send(tree, &nt);
53 }
54
55
56 /****************************************************************************
57 fetch file ACL (async recv)
58 ****************************************************************************/
59 NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req, 
60                                     TALLOC_CTX *mem_ctx, 
61                                     union smb_fileinfo *io)
62 {
63         NTSTATUS status;
64         struct smb_nttrans nt;
65         struct ndr_pull *ndr;
66         enum ndr_err_code ndr_err;
67
68         status = smb_raw_nttrans_recv(req, mem_ctx, &nt);
69         if (!NT_STATUS_IS_OK(status)) {
70                 return status;
71         }
72
73         /* check that the basics are valid */
74         if (nt.out.params.length != 4 ||
75             IVAL(nt.out.params.data, 0) > nt.out.data.length) {
76                 return NT_STATUS_INVALID_PARAMETER;
77         }
78
79         nt.out.data.length = IVAL(nt.out.params.data, 0);
80
81         ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx, NULL);
82         if (!ndr) {
83                 return NT_STATUS_INVALID_PARAMETER;
84         }
85
86         io->query_secdesc.out.sd = talloc(mem_ctx, struct security_descriptor);
87         if (!io->query_secdesc.out.sd) {
88                 return NT_STATUS_NO_MEMORY;
89         }
90         ndr_err = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS,
91                                                io->query_secdesc.out.sd);
92         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
93                 return ndr_map_error2ntstatus(ndr_err);
94         }
95
96         return NT_STATUS_OK;
97 }
98
99
100 /****************************************************************************
101 fetch file ACL (sync interface)
102 ****************************************************************************/
103 NTSTATUS smb_raw_query_secdesc(struct smbcli_tree *tree, 
104                                TALLOC_CTX *mem_ctx, 
105                                union smb_fileinfo *io)
106 {
107         struct smbcli_request *req = smb_raw_query_secdesc_send(tree, io);
108         return smb_raw_query_secdesc_recv(req, mem_ctx, io);
109 }
110
111
112
113 /****************************************************************************
114 set file ACL (async send)
115 ****************************************************************************/
116 struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, 
117                                                 union smb_setfileinfo *io)
118 {
119         struct smb_nttrans nt;
120         uint8_t params[8];
121         struct ndr_push *ndr;
122         struct smbcli_request *req;
123         enum ndr_err_code ndr_err;
124
125         nt.in.max_setup = 0;
126         nt.in.max_param = 0;
127         nt.in.max_data = 0;
128         nt.in.setup_count = 0;
129         nt.in.function = NT_TRANSACT_SET_SECURITY_DESC;
130         nt.in.setup = NULL;
131
132         SSVAL(params, 0, io->set_secdesc.in.file.fnum);
133         SSVAL(params, 2, 0); /* padding */
134         SIVAL(params, 4, io->set_secdesc.in.secinfo_flags);
135
136         nt.in.params.data = params;
137         nt.in.params.length = 8;
138
139         ndr = ndr_push_init_ctx(NULL, NULL);
140         if (!ndr) return NULL;
141
142         ndr_err = ndr_push_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, io->set_secdesc.in.sd);
143         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
144                 talloc_free(ndr);
145                 return NULL;
146         }
147
148         nt.in.data = ndr_push_blob(ndr);
149
150         req = smb_raw_nttrans_send(tree, &nt);
151
152         talloc_free(ndr);
153         return req;
154 }
155
156 /****************************************************************************
157 set file ACL (sync interface)
158 ****************************************************************************/
159 NTSTATUS smb_raw_set_secdesc(struct smbcli_tree *tree, 
160                              union smb_setfileinfo *io)
161 {
162         struct smbcli_request *req = smb_raw_set_secdesc_send(tree, io);
163         return smbcli_request_simple_recv(req);
164 }