r12608: Remove some unused #include lines.
[abartlet/samba.git/.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
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)
30 {
31         struct smb_nttrans nt;
32         uint8_t params[8];
33
34         nt.in.max_setup = 0;
35         nt.in.max_param = 4;
36         nt.in.max_data = 0xFFFF;
37         nt.in.setup_count = 0;
38         nt.in.function = NT_TRANSACT_QUERY_SECURITY_DESC;
39         nt.in.setup = NULL;
40
41         SSVAL(params, 0, io->query_secdesc.in.fnum);
42         SSVAL(params, 2, 0); /* padding */
43         SIVAL(params, 4, io->query_secdesc.secinfo_flags);
44
45         nt.in.params.data = params;
46         nt.in.params.length = 8;
47         
48         nt.in.data = data_blob(NULL, 0);
49
50         return smb_raw_nttrans_send(tree, &nt);
51 }
52
53
54 /****************************************************************************
55 fetch file ACL (async recv)
56 ****************************************************************************/
57 NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req, 
58                                     TALLOC_CTX *mem_ctx, 
59                                     union smb_fileinfo *io)
60 {
61         NTSTATUS status;
62         struct smb_nttrans nt;
63         struct ndr_pull *ndr;
64
65         status = smb_raw_nttrans_recv(req, mem_ctx, &nt);
66         if (!NT_STATUS_IS_OK(status)) {
67                 return status;
68         }
69
70         /* check that the basics are valid */
71         if (nt.out.params.length != 4 ||
72             IVAL(nt.out.params.data, 0) > nt.out.data.length) {
73                 return NT_STATUS_INVALID_PARAMETER;
74         }
75
76         nt.out.data.length = IVAL(nt.out.params.data, 0);
77
78         ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx);
79         if (!ndr) {
80                 return NT_STATUS_INVALID_PARAMETER;
81         }
82
83         io->query_secdesc.out.sd = talloc(mem_ctx, struct security_descriptor);
84         if (!io->query_secdesc.out.sd) {
85                 return NT_STATUS_NO_MEMORY;
86         }
87         status = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, 
88                                               io->query_secdesc.out.sd);
89
90         return status;
91 }
92
93
94 /****************************************************************************
95 fetch file ACL (sync interface)
96 ****************************************************************************/
97 NTSTATUS smb_raw_query_secdesc(struct smbcli_tree *tree, 
98                                TALLOC_CTX *mem_ctx, 
99                                union smb_fileinfo *io)
100 {
101         struct smbcli_request *req = smb_raw_query_secdesc_send(tree, io);
102         return smb_raw_query_secdesc_recv(req, mem_ctx, io);
103 }
104
105
106
107 /****************************************************************************
108 set file ACL (async send)
109 ****************************************************************************/
110 struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, 
111                                                 union smb_setfileinfo *io)
112 {
113         struct smb_nttrans nt;
114         uint8_t params[8];
115         struct ndr_push *ndr;
116         struct smbcli_request *req;
117         NTSTATUS status;
118
119         nt.in.max_setup = 0;
120         nt.in.max_param = 0;
121         nt.in.max_data = 0;
122         nt.in.setup_count = 0;
123         nt.in.function = NT_TRANSACT_SET_SECURITY_DESC;
124         nt.in.setup = NULL;
125
126         SSVAL(params, 0, io->set_secdesc.file.fnum);
127         SSVAL(params, 2, 0); /* padding */
128         SIVAL(params, 4, io->set_secdesc.in.secinfo_flags);
129
130         nt.in.params.data = params;
131         nt.in.params.length = 8;
132
133         ndr = ndr_push_init();
134         if (!ndr) return NULL;
135
136         status = ndr_push_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, io->set_secdesc.in.sd);
137         if (!NT_STATUS_IS_OK(status)) {
138                 ndr_push_free(ndr);
139                 return NULL;
140         }
141
142         nt.in.data = ndr_push_blob(ndr);
143
144         req = smb_raw_nttrans_send(tree, &nt);
145
146         ndr_push_free(ndr);
147         return req;
148 }
149
150 /****************************************************************************
151 set file ACL (sync interface)
152 ****************************************************************************/
153 NTSTATUS smb_raw_set_secdesc(struct smbcli_tree *tree, 
154                              union smb_setfileinfo *io)
155 {
156         struct smbcli_request *req = smb_raw_set_secdesc_send(tree, io);
157         return smbcli_request_simple_recv(req);
158 }