2 * Store Windows ACLs in a tdb.
4 * Copyright (C) Volker Lendecke, 2008
5 * Copyright (C) Jeremy Allison, 2008
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 3 of the License, or
10 * (at your option) any later version.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 /* NOTE: This is an experimental module, not yet finished. JRA. */
24 #include "librpc/gen_ndr/xattr.h"
25 #include "librpc/gen_ndr/ndr_xattr.h"
28 #define DBGC_CLASS DBGC_VFS
30 static unsigned int ref_count;
31 static struct db_context *acl_db;
33 /*******************************************************************
34 Open acl_db if not already open, increment ref count.
35 *******************************************************************/
37 static bool acl_tdb_init(struct db_context **pp_db)
47 dbname = state_path("file_ntacls.tdb");
55 *pp_db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
73 /*******************************************************************
74 Lower ref count and close acl_db if zero.
75 *******************************************************************/
77 static void free_acl_tdb_data(void **pptr)
79 struct db_context **pp_db = (struct db_context **)pptr;
88 /*******************************************************************
89 Fetch_lock the tdb acl record for a file
90 *******************************************************************/
92 static struct db_record *acl_tdb_lock(TALLOC_CTX *mem_ctx,
93 struct db_context *db,
94 const struct file_id *id)
98 /* For backwards compatibility only store the dev/inode. */
99 push_file_id_16((char *)id_buf, id);
100 return db->fetch_locked(db,
102 make_tdb_data(id_buf,
106 /*******************************************************************
107 Delete the tdb acl record for a file
108 *******************************************************************/
110 static NTSTATUS acl_tdb_delete(vfs_handle_struct *handle,
111 struct db_context *db,
112 SMB_STRUCT_STAT *psbuf)
115 struct file_id id = vfs_file_id_from_sbuf(handle->conn, psbuf);
116 struct db_record *rec = acl_tdb_lock(talloc_tos(), db, &id);
119 * If rec == NULL there's not much we can do about it
123 DEBUG(10,("acl_tdb_delete: rec == NULL\n"));
128 status = rec->delete_rec(rec);
133 /*******************************************************************
134 Parse out a struct security_descriptor from a DATA_BLOB.
135 *******************************************************************/
137 static NTSTATUS parse_acl_blob(const DATA_BLOB *pblob,
138 uint32 security_info,
139 struct security_descriptor **ppdesc)
141 TALLOC_CTX *ctx = talloc_tos();
142 struct xattr_NTACL xacl;
143 enum ndr_err_code ndr_err;
146 ndr_err = ndr_pull_struct_blob(pblob, ctx, NULL, &xacl,
147 (ndr_pull_flags_fn_t)ndr_pull_xattr_NTACL);
149 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
150 DEBUG(5, ("parse_acl_blob: ndr_pull_xattr_NTACL failed: %s\n",
151 ndr_errstr(ndr_err)));
152 return ndr_map_error2ntstatus(ndr_err);;
155 if (xacl.version != 2) {
156 return NT_STATUS_REVISION_MISMATCH;
159 *ppdesc = make_sec_desc(ctx, SEC_DESC_REVISION, xacl.info.sd_hs->sd->type | SEC_DESC_SELF_RELATIVE,
160 (security_info & OWNER_SECURITY_INFORMATION)
161 ? xacl.info.sd_hs->sd->owner_sid : NULL,
162 (security_info & GROUP_SECURITY_INFORMATION)
163 ? xacl.info.sd_hs->sd->group_sid : NULL,
164 (security_info & SACL_SECURITY_INFORMATION)
165 ? xacl.info.sd_hs->sd->sacl : NULL,
166 (security_info & DACL_SECURITY_INFORMATION)
167 ? xacl.info.sd_hs->sd->dacl : NULL,
170 TALLOC_FREE(xacl.info.sd);
172 return (*ppdesc != NULL) ? NT_STATUS_OK : NT_STATUS_NO_MEMORY;
175 /*******************************************************************
176 Pull a security descriptor into a DATA_BLOB from a tdb store.
177 *******************************************************************/
179 static NTSTATUS get_acl_blob(TALLOC_CTX *ctx,
180 vfs_handle_struct *handle,
188 struct db_context *db;
190 SMB_STRUCT_STAT sbuf;
192 SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context,
193 return NT_STATUS_INTERNAL_DB_CORRUPTION);
195 if (fsp && fsp->fh->fd != -1) {
196 ret = SMB_VFS_FSTAT(fsp, &sbuf);
198 if (fsp && fsp->posix_open) {
199 ret = vfs_lstat_smb_fname(handle->conn, name, &sbuf);
201 ret = vfs_stat_smb_fname(handle->conn, name, &sbuf);
206 return map_nt_error_from_unix(errno);
209 id = vfs_file_id_from_sbuf(handle->conn, &sbuf);
211 /* For backwards compatibility only store the dev/inode. */
212 push_file_id_16((char *)id_buf, &id);
216 make_tdb_data(id_buf, sizeof(id_buf)),
218 return NT_STATUS_INTERNAL_DB_CORRUPTION;
221 pblob->data = data.dptr;
222 pblob->length = data.dsize;
224 DEBUG(10,("get_acl_blob: returned %u bytes from file %s\n",
225 (unsigned int)data.dsize, name ));
227 if (pblob->length == 0 || pblob->data == NULL) {
228 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
233 /*******************************************************************
234 Create a DATA_BLOB from a security descriptor.
235 *******************************************************************/
237 static NTSTATUS create_acl_blob(const struct security_descriptor *psd, DATA_BLOB *pblob)
239 struct xattr_NTACL xacl;
240 struct security_descriptor_hash sd_hs;
241 enum ndr_err_code ndr_err;
242 TALLOC_CTX *ctx = talloc_tos();
248 xacl.info.sd_hs = &sd_hs;
249 xacl.info.sd_hs->sd = CONST_DISCARD(struct security_descriptor *, psd);
250 memset(&xacl.info.sd_hs->hash[0], '\0', 16);
252 ndr_err = ndr_push_struct_blob(
253 pblob, ctx, NULL, &xacl,
254 (ndr_push_flags_fn_t)ndr_push_xattr_NTACL);
256 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
257 DEBUG(5, ("create_acl_blob: ndr_push_xattr_NTACL failed: %s\n",
258 ndr_errstr(ndr_err)));
259 return ndr_map_error2ntstatus(ndr_err);;
265 /*******************************************************************
266 Store a DATA_BLOB into a tdb record given an fsp pointer.
267 *******************************************************************/
269 static NTSTATUS store_acl_blob_fsp(vfs_handle_struct *handle,
275 SMB_STRUCT_STAT sbuf;
277 struct db_context *db;
278 struct db_record *rec;
281 DEBUG(10,("store_acl_blob_fsp: storing blob length %u on file %s\n",
282 (unsigned int)pblob->length, fsp->fsp_name));
284 SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context,
285 return NT_STATUS_INTERNAL_DB_CORRUPTION);
287 if (fsp->fh->fd != -1) {
288 ret = SMB_VFS_FSTAT(fsp, &sbuf);
290 if (fsp->posix_open) {
291 ret = vfs_lstat_smb_fname(handle->conn, fsp->fsp_name,
294 ret = vfs_stat_smb_fname(handle->conn, fsp->fsp_name,
300 return map_nt_error_from_unix(errno);
303 id = vfs_file_id_from_sbuf(handle->conn, &sbuf);
305 /* For backwards compatibility only store the dev/inode. */
306 push_file_id_16((char *)id_buf, &id);
307 rec = db->fetch_locked(db, talloc_tos(),
308 make_tdb_data(id_buf,
311 DEBUG(0, ("store_acl_blob_fsp_tdb: fetch_lock failed\n"));
312 return NT_STATUS_INTERNAL_DB_CORRUPTION;
314 data.dptr = pblob->data;
315 data.dsize = pblob->length;
316 return rec->store(rec, data, 0);
319 /*******************************************************************
320 Store a DATA_BLOB into a tdb record given a pathname.
321 *******************************************************************/
323 static NTSTATUS store_acl_blob_pathname(vfs_handle_struct *handle,
330 SMB_STRUCT_STAT sbuf;
331 struct db_context *db;
332 struct db_record *rec;
335 DEBUG(10,("store_acl_blob_pathname: storing blob "
336 "length %u on file %s\n",
337 (unsigned int)pblob->length, fname));
339 SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context,
340 return NT_STATUS_INTERNAL_DB_CORRUPTION);
342 if (lp_posix_pathnames()) {
343 ret = vfs_lstat_smb_fname(handle->conn, fname, &sbuf);
345 ret = vfs_stat_smb_fname(handle->conn, fname, &sbuf);
349 return map_nt_error_from_unix(errno);
352 id = vfs_file_id_from_sbuf(handle->conn, &sbuf);
354 /* For backwards compatibility only store the dev/inode. */
355 push_file_id_16((char *)id_buf, &id);
357 rec = db->fetch_locked(db, talloc_tos(),
358 make_tdb_data(id_buf,
361 DEBUG(0, ("store_acl_blob_pathname_tdb: fetch_lock failed\n"));
362 return NT_STATUS_INTERNAL_DB_CORRUPTION;
364 data.dptr = pblob->data;
365 data.dsize = pblob->length;
366 return rec->store(rec, data, 0);
369 /*******************************************************************
370 Store a DATA_BLOB into an tdb given a pathname.
371 *******************************************************************/
373 static NTSTATUS get_nt_acl_tdb_internal(vfs_handle_struct *handle,
376 uint32 security_info,
377 struct security_descriptor **ppdesc)
379 TALLOC_CTX *ctx = talloc_tos();
383 if (fsp && name == NULL) {
384 name = fsp->fsp_name;
387 DEBUG(10, ("get_nt_acl_tdb_internal: name=%s\n", name));
389 status = get_acl_blob(ctx, handle, fsp, name, &blob);
390 if (!NT_STATUS_IS_OK(status)) {
391 DEBUG(10, ("get_acl_blob returned %s\n", nt_errstr(status)));
395 status = parse_acl_blob(&blob, security_info, ppdesc);
396 if (!NT_STATUS_IS_OK(status)) {
397 DEBUG(10, ("parse_acl_blob returned %s\n",
402 TALLOC_FREE(blob.data);
406 /*********************************************************************
407 Create a default security descriptor for a file in case no inheritance
408 exists. All permissions to the owner and SYSTEM.
409 *********************************************************************/
411 static struct security_descriptor *default_file_sd(TALLOC_CTX *mem_ctx,
412 SMB_STRUCT_STAT *psbuf)
414 struct dom_sid owner_sid, group_sid;
416 struct security_ace *pace = NULL;
417 struct security_acl *pacl = NULL;
419 uid_to_sid(&owner_sid, psbuf->st_ex_uid);
420 gid_to_sid(&group_sid, psbuf->st_ex_gid);
422 pace = TALLOC_ARRAY(mem_ctx, struct security_ace, 2);
427 init_sec_ace(&pace[0], &owner_sid, SEC_ACE_TYPE_ACCESS_ALLOWED,
428 SEC_RIGHTS_FILE_ALL, 0);
429 init_sec_ace(&pace[1], &global_sid_System, SEC_ACE_TYPE_ACCESS_ALLOWED,
430 SEC_RIGHTS_FILE_ALL, 0);
432 pacl = make_sec_acl(mem_ctx,
439 return make_sec_desc(mem_ctx,
440 SECURITY_DESCRIPTOR_REVISION_1,
441 SEC_DESC_SELF_RELATIVE|SEC_DESC_DACL_PRESENT,
449 /*********************************************************************
450 *********************************************************************/
452 static NTSTATUS inherit_new_acl(vfs_handle_struct *handle,
457 TALLOC_CTX *ctx = talloc_tos();
459 struct security_descriptor *parent_desc = NULL;
460 struct security_descriptor *psd = NULL;
465 if (!parent_dirname(ctx, fname, &parent_name, NULL)) {
466 return NT_STATUS_NO_MEMORY;
469 DEBUG(10,("inherit_new_acl: check directory %s\n",
472 status = get_nt_acl_tdb_internal(handle,
475 (OWNER_SECURITY_INFORMATION |
476 GROUP_SECURITY_INFORMATION |
477 DACL_SECURITY_INFORMATION),
479 if (NT_STATUS_IS_OK(status)) {
480 /* Create an inherited descriptor from the parent. */
482 if (DEBUGLEVEL >= 10) {
483 DEBUG(10,("inherit_new_acl: parent acl is:\n"));
484 NDR_PRINT_DEBUG(security_descriptor, parent_desc);
487 status = se_create_child_secdesc(ctx,
491 &handle->conn->server_info->ptok->user_sids[PRIMARY_USER_SID_INDEX],
492 &handle->conn->server_info->ptok->user_sids[PRIMARY_GROUP_SID_INDEX],
494 if (!NT_STATUS_IS_OK(status)) {
498 if (DEBUGLEVEL >= 10) {
499 DEBUG(10,("inherit_new_acl: child acl is:\n"));
500 NDR_PRINT_DEBUG(security_descriptor, psd);
504 DEBUG(10,("inherit_new_acl: directory %s failed "
507 nt_errstr(status) ));
510 if (!psd || psd->dacl == NULL) {
511 SMB_STRUCT_STAT sbuf;
515 if (fsp && !fsp->is_directory && fsp->fh->fd != -1) {
516 ret = SMB_VFS_FSTAT(fsp, &sbuf);
518 if (fsp && fsp->posix_open) {
519 ret = vfs_lstat_smb_fname(handle->conn,fname,
522 ret = vfs_stat_smb_fname(handle->conn,fname,
527 return map_nt_error_from_unix(errno);
529 psd = default_file_sd(ctx, &sbuf);
531 return NT_STATUS_NO_MEMORY;
534 if (DEBUGLEVEL >= 10) {
535 DEBUG(10,("inherit_new_acl: default acl is:\n"));
536 NDR_PRINT_DEBUG(security_descriptor, psd);
540 status = create_acl_blob(psd, &blob);
541 if (!NT_STATUS_IS_OK(status)) {
545 return store_acl_blob_fsp(handle, fsp, &blob);
547 return store_acl_blob_pathname(handle, fname, &blob);
551 /*********************************************************************
552 Check ACL on open. For new files inherit from parent directory.
553 *********************************************************************/
555 static int open_acl_tdb(vfs_handle_struct *handle,
556 struct smb_filename *smb_fname,
561 uint32_t access_granted = 0;
562 struct security_descriptor *pdesc = NULL;
563 bool file_existed = true;
567 status = get_full_smb_filename(talloc_tos(), smb_fname,
569 if (!NT_STATUS_IS_OK(status)) {
570 errno = map_errno_from_nt_status(status);
574 status = get_nt_acl_tdb_internal(handle,
577 (OWNER_SECURITY_INFORMATION |
578 GROUP_SECURITY_INFORMATION |
579 DACL_SECURITY_INFORMATION),
581 if (NT_STATUS_IS_OK(status)) {
582 /* See if we can access it. */
583 status = smb1_file_se_access_check(pdesc,
584 handle->conn->server_info->ptok,
587 if (!NT_STATUS_IS_OK(status)) {
588 DEBUG(10,("open_acl_tdb: file %s open "
589 "refused with error %s\n",
590 smb_fname_str_dbg(smb_fname),
591 nt_errstr(status) ));
592 errno = map_errno_from_nt_status(status);
595 } else if (NT_STATUS_EQUAL(status,NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
596 file_existed = false;
599 DEBUG(10,("open_acl_tdb: get_nt_acl_attr_internal for "
600 "file %s returned %s\n",
601 smb_fname_str_dbg(smb_fname),
602 nt_errstr(status) ));
604 fsp->fh->fd = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
606 if (!file_existed && fsp->fh->fd != -1) {
607 /* File was created. Inherit from parent directory. */
608 string_set(&fsp->fsp_name, fname);
609 inherit_new_acl(handle, fname, fsp, false);
615 /*********************************************************************
616 On unlink we need to delete the tdb record (if using tdb).
617 *********************************************************************/
619 static int unlink_acl_tdb(vfs_handle_struct *handle,
620 const struct smb_filename *smb_fname)
622 struct smb_filename *smb_fname_tmp = NULL;
623 struct db_context *db;
627 SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1);
629 status = copy_smb_filename(talloc_tos(), smb_fname, &smb_fname_tmp);
630 if (!NT_STATUS_IS_OK(status)) {
631 errno = map_errno_from_nt_status(status);
635 if (lp_posix_pathnames()) {
636 ret = SMB_VFS_LSTAT(handle->conn, smb_fname_tmp);
638 ret = SMB_VFS_STAT(handle->conn, smb_fname_tmp);
645 ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname_tmp);
651 acl_tdb_delete(handle, db, &smb_fname_tmp->st);
656 /*********************************************************************
657 Store an inherited SD on mkdir.
658 *********************************************************************/
660 static int mkdir_acl_tdb(vfs_handle_struct *handle, const char *path, mode_t mode)
662 int ret = SMB_VFS_NEXT_MKDIR(handle, path, mode);
667 /* New directory - inherit from parent. */
668 inherit_new_acl(handle, path, NULL, true);
672 /*********************************************************************
673 On rmdir we need to delete the tdb record (if using tdb).
674 *********************************************************************/
676 static int rmdir_acl_tdb(vfs_handle_struct *handle, const char *path)
679 SMB_STRUCT_STAT sbuf;
680 struct db_context *db;
683 SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1);
685 if (lp_posix_pathnames()) {
686 ret = vfs_lstat_smb_fname(handle->conn, path, &sbuf);
688 ret = vfs_stat_smb_fname(handle->conn, path, &sbuf);
695 ret = SMB_VFS_NEXT_RMDIR(handle, path);
700 acl_tdb_delete(handle, db, &sbuf);
704 /*********************************************************************
705 Fetch a security descriptor given an fsp.
706 *********************************************************************/
708 static NTSTATUS fget_nt_acl_tdb(vfs_handle_struct *handle, files_struct *fsp,
709 uint32 security_info, struct security_descriptor **ppdesc)
711 NTSTATUS status = get_nt_acl_tdb_internal(handle, fsp,
712 NULL, security_info, ppdesc);
713 if (NT_STATUS_IS_OK(status)) {
714 if (DEBUGLEVEL >= 10) {
715 DEBUG(10,("fget_nt_acl_tdb: returning tdb sd for file %s\n",
717 NDR_PRINT_DEBUG(security_descriptor, *ppdesc);
722 DEBUG(10,("fget_nt_acl_tdb: failed to get tdb sd for file %s, Error %s\n",
724 nt_errstr(status) ));
726 return SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp,
727 security_info, ppdesc);
730 /*********************************************************************
731 Fetch a security descriptor given a pathname.
732 *********************************************************************/
734 static NTSTATUS get_nt_acl_tdb(vfs_handle_struct *handle,
735 const char *name, uint32 security_info, struct security_descriptor **ppdesc)
737 NTSTATUS status = get_nt_acl_tdb_internal(handle, NULL,
738 name, security_info, ppdesc);
739 if (NT_STATUS_IS_OK(status)) {
740 if (DEBUGLEVEL >= 10) {
741 DEBUG(10,("get_nt_acl_tdb: returning tdb sd for file %s\n",
743 NDR_PRINT_DEBUG(security_descriptor, *ppdesc);
748 DEBUG(10,("get_nt_acl_tdb: failed to get tdb sd for file %s, Error %s\n",
750 nt_errstr(status) ));
752 return SMB_VFS_NEXT_GET_NT_ACL(handle, name,
753 security_info, ppdesc);
756 /*********************************************************************
757 Store a security descriptor given an fsp.
758 *********************************************************************/
760 static NTSTATUS fset_nt_acl_tdb(vfs_handle_struct *handle, files_struct *fsp,
761 uint32 security_info_sent, const struct security_descriptor *psd)
766 if (DEBUGLEVEL >= 10) {
767 DEBUG(10,("fset_nt_acl_tdb: incoming sd for file %s\n",
769 NDR_PRINT_DEBUG(security_descriptor,
770 CONST_DISCARD(struct security_descriptor *,psd));
773 status = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
774 if (!NT_STATUS_IS_OK(status)) {
778 /* Ensure owner and group are set. */
779 if (!psd->owner_sid || !psd->group_sid) {
781 SMB_STRUCT_STAT sbuf;
782 DOM_SID owner_sid, group_sid;
783 struct security_descriptor *nc_psd = dup_sec_desc(talloc_tos(), psd);
788 if (fsp->is_directory || fsp->fh->fd == -1) {
789 if (fsp->posix_open) {
790 ret = vfs_lstat_smb_fname(fsp->conn,
794 ret = vfs_stat_smb_fname(fsp->conn,
799 ret = SMB_VFS_FSTAT(fsp, &sbuf);
802 /* Lower level acl set succeeded,
803 * so still return OK. */
806 create_file_sids(&sbuf, &owner_sid, &group_sid);
807 /* This is safe as nc_psd is discarded at fn exit. */
808 nc_psd->owner_sid = &owner_sid;
809 nc_psd->group_sid = &group_sid;
810 security_info_sent |= (OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION);
815 if ((security_info_sent & DACL_SECURITY_INFORMATION) &&
817 (psd->type & (SE_DESC_DACL_AUTO_INHERITED|
818 SE_DESC_DACL_AUTO_INHERIT_REQ))==
819 (SE_DESC_DACL_AUTO_INHERITED|
820 SE_DESC_DACL_AUTO_INHERIT_REQ) ) {
821 struct security_descriptor *new_psd = NULL;
822 status = append_parent_acl(fsp, psd, &new_psd);
823 if (!NT_STATUS_IS_OK(status)) {
824 /* Lower level acl set succeeded,
825 * so still return OK. */
832 if (DEBUGLEVEL >= 10) {
833 DEBUG(10,("fset_nt_acl_tdb: storing tdb sd for file %s\n",
835 NDR_PRINT_DEBUG(security_descriptor,
836 CONST_DISCARD(struct security_descriptor *,psd));
838 create_acl_blob(psd, &blob);
839 store_acl_blob_fsp(handle, fsp, &blob);
844 /*******************************************************************
845 Handle opening the storage tdb if so configured.
846 *******************************************************************/
848 static int connect_acl_tdb(struct vfs_handle_struct *handle,
852 struct db_context *db;
855 res = SMB_VFS_NEXT_CONNECT(handle, service, user);
860 if (!acl_tdb_init(&db)) {
861 SMB_VFS_NEXT_DISCONNECT(handle);
865 SMB_VFS_HANDLE_SET_DATA(handle, db, free_acl_tdb_data,
866 struct db_context, return -1);
871 /*********************************************************************
872 Remove a Windows ACL - we're setting the underlying POSIX ACL.
873 *********************************************************************/
875 static int sys_acl_set_file_tdb(vfs_handle_struct *handle,
880 SMB_STRUCT_STAT sbuf;
881 struct db_context *db;
884 SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1);
886 if (lp_posix_pathnames()) {
887 ret = vfs_lstat_smb_fname(handle->conn, path, &sbuf);
889 ret = vfs_stat_smb_fname(handle->conn, path, &sbuf);
896 ret = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle,
904 acl_tdb_delete(handle, db, &sbuf);
908 /*********************************************************************
909 Remove a Windows ACL - we're setting the underlying POSIX ACL.
910 *********************************************************************/
912 static int sys_acl_set_fd_tdb(vfs_handle_struct *handle,
916 SMB_STRUCT_STAT sbuf;
917 struct db_context *db;
920 SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1);
922 if (fsp->is_directory || fsp->fh->fd == -1) {
923 if (fsp->posix_open) {
924 ret = vfs_lstat_smb_fname(fsp->conn,fsp->fsp_name,
927 ret = vfs_stat_smb_fname(fsp->conn,fsp->fsp_name,
931 ret = SMB_VFS_FSTAT(fsp, &sbuf);
937 ret = SMB_VFS_NEXT_SYS_ACL_SET_FD(handle,
944 acl_tdb_delete(handle, db, &sbuf);
948 /* VFS operations structure */
950 static vfs_op_tuple skel_op_tuples[] =
952 {SMB_VFS_OP(connect_acl_tdb), SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_TRANSPARENT},
954 {SMB_VFS_OP(mkdir_acl_tdb), SMB_VFS_OP_MKDIR, SMB_VFS_LAYER_TRANSPARENT},
955 {SMB_VFS_OP(rmdir_acl_tdb), SMB_VFS_OP_RMDIR, SMB_VFS_LAYER_TRANSPARENT},
957 {SMB_VFS_OP(open_acl_tdb), SMB_VFS_OP_OPEN, SMB_VFS_LAYER_TRANSPARENT},
958 {SMB_VFS_OP(unlink_acl_tdb), SMB_VFS_OP_UNLINK, SMB_VFS_LAYER_TRANSPARENT},
960 /* NT File ACL operations */
962 {SMB_VFS_OP(fget_nt_acl_tdb),SMB_VFS_OP_FGET_NT_ACL,SMB_VFS_LAYER_TRANSPARENT},
963 {SMB_VFS_OP(get_nt_acl_tdb), SMB_VFS_OP_GET_NT_ACL, SMB_VFS_LAYER_TRANSPARENT},
964 {SMB_VFS_OP(fset_nt_acl_tdb),SMB_VFS_OP_FSET_NT_ACL,SMB_VFS_LAYER_TRANSPARENT},
966 /* POSIX ACL operations. */
967 {SMB_VFS_OP(sys_acl_set_file_tdb), SMB_VFS_OP_SYS_ACL_SET_FILE, SMB_VFS_LAYER_TRANSPARENT},
968 {SMB_VFS_OP(sys_acl_set_fd_tdb), SMB_VFS_OP_SYS_ACL_SET_FD, SMB_VFS_LAYER_TRANSPARENT},
970 {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
973 NTSTATUS vfs_acl_tdb_init(void)
975 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "acl_tdb", skel_op_tuples);