s3:libsmb: Plumb cli_smb2_list() inside cli_list().
[Samba.git] / source3 / modules / non_posix_acls.c
blobb1c24205d13f644560b4eaf4100fca4b36f9305e
1 /*
2 Unix SMB/CIFS implementation.
3 Access Control List handling
4 Copyright (C) Andrew Bartlett 2012.
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.
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.
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/>.
20 #include "includes.h"
21 #include "../librpc/gen_ndr/ndr_xattr.h"
22 #include "modules/non_posix_acls.h"
24 int non_posix_sys_acl_blob_get_file_helper(vfs_handle_struct *handle,
25 const char *path_p,
26 DATA_BLOB acl_as_blob,
27 TALLOC_CTX *mem_ctx,
28 DATA_BLOB *blob)
30 int ret;
31 TALLOC_CTX *frame = talloc_stackframe();
32 struct xattr_sys_acl_hash_wrapper acl_wrapper = {};
33 struct smb_filename *smb_fname;
35 smb_fname = synthetic_smb_fname_split(frame, path_p, NULL);
36 if (smb_fname == NULL) {
37 TALLOC_FREE(frame);
38 errno = ENOMEM;
39 return -1;
42 acl_wrapper.acl_as_blob = acl_as_blob;
44 ret = smb_vfs_call_stat(handle, smb_fname);
45 if (ret == -1) {
46 TALLOC_FREE(frame);
47 return -1;
50 acl_wrapper.owner = smb_fname->st.st_ex_uid;
51 acl_wrapper.group = smb_fname->st.st_ex_gid;
52 acl_wrapper.mode = smb_fname->st.st_ex_mode;
54 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_struct_blob(blob, mem_ctx,
55 &acl_wrapper,
56 (ndr_push_flags_fn_t)ndr_push_xattr_sys_acl_hash_wrapper))) {
57 errno = EINVAL;
58 TALLOC_FREE(frame);
59 return -1;
62 TALLOC_FREE(frame);
63 return 0;
66 int non_posix_sys_acl_blob_get_fd_helper(vfs_handle_struct *handle,
67 files_struct *fsp,
68 DATA_BLOB acl_as_blob,
69 TALLOC_CTX *mem_ctx,
70 DATA_BLOB *blob)
72 SMB_STRUCT_STAT sbuf;
73 TALLOC_CTX *frame;
74 struct xattr_sys_acl_hash_wrapper acl_wrapper;
75 int ret;
77 frame = talloc_stackframe();
79 acl_wrapper.acl_as_blob = acl_as_blob;
81 if (!VALID_STAT(fsp->fsp_name->st)) {
82 ret = smb_vfs_call_fstat(handle, fsp, &sbuf);
83 if (ret == -1) {
84 TALLOC_FREE(frame);
85 return -1;
87 } else {
88 sbuf = fsp->fsp_name->st;
91 acl_wrapper.owner = sbuf.st_ex_uid;
92 acl_wrapper.group = sbuf.st_ex_gid;
93 acl_wrapper.mode = sbuf.st_ex_mode;
95 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_push_struct_blob(blob, mem_ctx,
96 &acl_wrapper,
97 (ndr_push_flags_fn_t)ndr_push_xattr_sys_acl_hash_wrapper))) {
98 errno = EINVAL;
99 TALLOC_FREE(frame);
100 return -1;
103 TALLOC_FREE(frame);
104 return 0;