security descriptors are no longer a "special" type, they are handled
[gd/samba-autobuild/.git] / source4 / 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_pull *ndr;
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         ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx);
77         if (!ndr) {
78                 return NT_STATUS_INVALID_PARAMETER;
79         }
80
81         query->out.sd = talloc(mem_ctx, sizeof(query->out.sd));
82         if (!query->out.sd) {
83                 return NT_STATUS_NO_MEMORY;
84         }
85         status = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, query->out.sd);
86
87         return NT_STATUS_OK;
88 }
89
90
91 /****************************************************************************
92 fetch file ACL (sync interface)
93 ****************************************************************************/
94 NTSTATUS smb_raw_query_secdesc(struct cli_tree *tree, 
95                                TALLOC_CTX *mem_ctx, 
96                                struct smb_query_secdesc *query)
97 {
98         struct cli_request *req = smb_raw_query_secdesc_send(tree, query);
99         return smb_raw_query_secdesc_recv(req, mem_ctx, query);
100 }
101
102
103
104 /****************************************************************************
105 set file ACL (async send)
106 ****************************************************************************/
107 struct cli_request *smb_raw_set_secdesc_send(struct cli_tree *tree, 
108                                              struct smb_set_secdesc *set)
109 {
110         struct smb_nttrans nt;
111         uint8 params[8];
112         struct ndr_push *ndr;
113         struct cli_request *req;
114         NTSTATUS status;
115
116         nt.in.max_setup = 0;
117         nt.in.max_param = 0;
118         nt.in.max_data = 0;
119         nt.in.setup_count = 0;
120         nt.in.function = NT_TRANSACT_SET_SECURITY_DESC;
121         nt.in.setup = NULL;
122
123         SSVAL(params, 0, set->in.fnum);
124         SSVAL(params, 2, 0); /* padding */
125         SIVAL(params, 4, set->in.secinfo_flags);
126
127         nt.in.params.data = params;
128         nt.in.params.length = 8;
129
130         ndr = ndr_push_init();
131         if (!ndr) return NULL;
132
133 //      status = ndr_push_security_descriptor(ndr, set->in.sd);
134         if (!NT_STATUS_IS_OK(status)) {
135                 ndr_push_free(ndr);
136                 return NULL;
137         }
138         
139         nt.in.data = ndr_push_blob(ndr);
140
141         req = smb_raw_nttrans_send(tree, &nt);
142
143         ndr_push_free(ndr);
144         return req;
145 }