s3: VFS: Change SMB_VFS_SYS_ACL_BLOB_GET_FILE to use const struct smb_filename *...
[samba.git] / source3 / modules / non_posix_acls.c
1 /*
2    Unix SMB/CIFS implementation.
3    Access Control List handling
4    Copyright (C) Andrew Bartlett 2012.
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 3 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, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21 #include "../librpc/gen_ndr/ndr_xattr.h"
22 #include "modules/non_posix_acls.h"
23
24 int non_posix_sys_acl_blob_get_file_helper(vfs_handle_struct *handle,
25                                    const struct smb_filename *smb_fname_in,
26                                    DATA_BLOB acl_as_blob,
27                                    TALLOC_CTX *mem_ctx,
28                                    DATA_BLOB *blob)
29 {
30         int ret;
31         TALLOC_CTX *frame = talloc_stackframe();
32         struct xattr_sys_acl_hash_wrapper acl_wrapper = {};
33         struct smb_filename *smb_fname = cp_smb_filename_nostream(frame,
34                                                 smb_fname_in);
35
36         if (smb_fname == NULL) {
37                 TALLOC_FREE(frame);
38                 return -1;
39         }
40
41         acl_wrapper.acl_as_blob = acl_as_blob;
42
43         ret = smb_vfs_call_stat(handle, smb_fname);
44         if (ret == -1) {
45                 TALLOC_FREE(frame);
46                 return -1;
47         }
48
49         acl_wrapper.owner = smb_fname->st.st_ex_uid;
50         acl_wrapper.group = smb_fname->st.st_ex_gid;
51         acl_wrapper.mode = smb_fname->st.st_ex_mode;
52
53         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_struct_blob(blob, mem_ctx,
54                                                           &acl_wrapper,
55                                                           (ndr_push_flags_fn_t)ndr_push_xattr_sys_acl_hash_wrapper))) {
56                 errno = EINVAL;
57                 TALLOC_FREE(frame);
58                 return -1;
59         }
60
61         TALLOC_FREE(frame);
62         return 0;
63 }
64
65 int non_posix_sys_acl_blob_get_fd_helper(vfs_handle_struct *handle,
66                                          files_struct *fsp,
67                                          DATA_BLOB acl_as_blob,
68                                          TALLOC_CTX *mem_ctx,
69                                          DATA_BLOB *blob)
70 {
71         SMB_STRUCT_STAT sbuf;
72         TALLOC_CTX *frame;
73         struct xattr_sys_acl_hash_wrapper acl_wrapper;
74         int ret;
75
76         frame = talloc_stackframe();
77
78         acl_wrapper.acl_as_blob = acl_as_blob;
79
80         if (!VALID_STAT(fsp->fsp_name->st)) {
81                 ret = smb_vfs_call_fstat(handle, fsp, &sbuf);
82                 if (ret == -1) {
83                         TALLOC_FREE(frame);
84                         return -1;
85                 }
86         } else {
87                 sbuf = fsp->fsp_name->st;
88         }
89
90         acl_wrapper.owner = sbuf.st_ex_uid;
91         acl_wrapper.group = sbuf.st_ex_gid;
92         acl_wrapper.mode = sbuf.st_ex_mode;
93
94         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_struct_blob(blob, mem_ctx,
95                                                           &acl_wrapper,
96                                                           (ndr_push_flags_fn_t)ndr_push_xattr_sys_acl_hash_wrapper))) {
97                 errno = EINVAL;
98                 TALLOC_FREE(frame);
99                 return -1;
100         }
101
102         TALLOC_FREE(frame);
103         return 0;
104 }