r14464: Don't include ndr_BASENAME.h files unless strictly required, instead
[bbaumbach/samba-autobuild/.git] / source4 / 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 2 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, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "libcli/raw/libcliraw.h"
24 #include "librpc/gen_ndr/ndr_security.h"
25
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)
31 {
32         struct smb_nttrans nt;
33         uint8_t params[8];
34
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;
41
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);
45
46         nt.in.params.data = params;
47         nt.in.params.length = 8;
48         
49         nt.in.data = data_blob(NULL, 0);
50
51         return smb_raw_nttrans_send(tree, &nt);
52 }
53
54
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)
61 {
62         NTSTATUS status;
63         struct smb_nttrans nt;
64         struct ndr_pull *ndr;
65
66         status = smb_raw_nttrans_recv(req, mem_ctx, &nt);
67         if (!NT_STATUS_IS_OK(status)) {
68                 return status;
69         }
70
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;
75         }
76
77         nt.out.data.length = IVAL(nt.out.params.data, 0);
78
79         ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx);
80         if (!ndr) {
81                 return NT_STATUS_INVALID_PARAMETER;
82         }
83
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;
87         }
88         status = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, 
89                                               io->query_secdesc.out.sd);
90
91         return status;
92 }
93
94
95 /****************************************************************************
96 fetch file ACL (sync interface)
97 ****************************************************************************/
98 NTSTATUS smb_raw_query_secdesc(struct smbcli_tree *tree, 
99                                TALLOC_CTX *mem_ctx, 
100                                union smb_fileinfo *io)
101 {
102         struct smbcli_request *req = smb_raw_query_secdesc_send(tree, io);
103         return smb_raw_query_secdesc_recv(req, mem_ctx, io);
104 }
105
106
107
108 /****************************************************************************
109 set file ACL (async send)
110 ****************************************************************************/
111 struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, 
112                                                 union smb_setfileinfo *io)
113 {
114         struct smb_nttrans nt;
115         uint8_t params[8];
116         struct ndr_push *ndr;
117         struct smbcli_request *req;
118         NTSTATUS status;
119
120         nt.in.max_setup = 0;
121         nt.in.max_param = 0;
122         nt.in.max_data = 0;
123         nt.in.setup_count = 0;
124         nt.in.function = NT_TRANSACT_SET_SECURITY_DESC;
125         nt.in.setup = NULL;
126
127         SSVAL(params, 0, io->set_secdesc.in.file.fnum);
128         SSVAL(params, 2, 0); /* padding */
129         SIVAL(params, 4, io->set_secdesc.in.secinfo_flags);
130
131         nt.in.params.data = params;
132         nt.in.params.length = 8;
133
134         ndr = ndr_push_init();
135         if (!ndr) return NULL;
136
137         status = ndr_push_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, io->set_secdesc.in.sd);
138         if (!NT_STATUS_IS_OK(status)) {
139                 ndr_push_free(ndr);
140                 return NULL;
141         }
142
143         nt.in.data = ndr_push_blob(ndr);
144
145         req = smb_raw_nttrans_send(tree, &nt);
146
147         ndr_push_free(ndr);
148         return req;
149 }
150
151 /****************************************************************************
152 set file ACL (sync interface)
153 ****************************************************************************/
154 NTSTATUS smb_raw_set_secdesc(struct smbcli_tree *tree, 
155                              union smb_setfileinfo *io)
156 {
157         struct smbcli_request *req = smb_raw_set_secdesc_send(tree, io);
158         return smbcli_request_simple_recv(req);
159 }