- a few portability fixes from Jim Myers
[jelmer/samba4-debian.git] / source / libcli / raw / rawacl.c
1 /* 
2    Unix SMB/CIFS implementation.
3    ACL get/set operations
4    Copyright (C) Andrew Tridgell 2003
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22
23 /****************************************************************************
24 fetch file ACL (async send)
25 ****************************************************************************/
26 struct cli_request *smb_raw_query_secdesc_send(struct cli_tree *tree, 
27                                                struct smb_query_secdesc *query)
28 {
29         struct smb_nttrans nt;
30         uint8 params[8];
31
32         nt.in.max_setup = 0;
33         nt.in.max_param = 4;
34         nt.in.max_data = 0x10000;
35         nt.in.setup_count = 0;
36         nt.in.function = NT_TRANSACT_QUERY_SECURITY_DESC;
37         nt.in.setup = NULL;
38
39         SSVAL(params, 0, query->in.fnum);
40         SSVAL(params, 2, 0); /* padding */
41         SIVAL(params, 4, query->in.secinfo_flags);
42
43         nt.in.params.data = params;
44         nt.in.params.length = 8;
45         
46         nt.in.data = data_blob(NULL, 0);
47
48         return smb_raw_nttrans_send(tree, &nt);
49 }
50
51
52 /****************************************************************************
53 fetch file ACL (async recv)
54 ****************************************************************************/
55 NTSTATUS smb_raw_query_secdesc_recv(struct cli_request *req, 
56                                     TALLOC_CTX *mem_ctx, 
57                                     struct smb_query_secdesc *query)
58 {
59         NTSTATUS status;
60         struct smb_nttrans nt;
61         struct ndr_parse *rpc;
62
63         status = smb_raw_nttrans_recv(req, mem_ctx, &nt);
64         if (!NT_STATUS_IS_OK(status)) {
65                 return status;
66         }
67
68         /* check that the basics are valid */
69         if (nt.out.params.length != 4 ||
70             IVAL(nt.out.params.data, 0) > nt.out.data.length) {
71                 return NT_STATUS_INVALID_PARAMETER;
72         }
73
74         nt.out.data.length = IVAL(nt.out.params.data, 0);
75
76         rpc = ndr_parse_init_blob(&nt.out.data, mem_ctx);
77         if (!rpc) {
78                 return NT_STATUS_INVALID_PARAMETER;
79         }
80
81         status = ndr_parse_security_descriptor(rpc, &query->out.sd);
82
83         return NT_STATUS_OK;
84 }
85
86
87 /****************************************************************************
88 fetch file ACL (sync interface)
89 ****************************************************************************/
90 NTSTATUS smb_raw_query_secdesc(struct cli_tree *tree, 
91                                TALLOC_CTX *mem_ctx, 
92                                struct smb_query_secdesc *query)
93 {
94         struct cli_request *req = smb_raw_query_secdesc_send(tree, query);
95         return smb_raw_query_secdesc_recv(req, mem_ctx, query);
96 }
97