diff options
author | Gerald Carter <jerry@samba.org> | 2007-02-28 14:35:26 +0000 |
---|---|---|
committer | Gerald Carter <jerry@samba.org> | 2007-02-28 14:35:26 +0000 |
commit | 80236f0d60ce013134c1ed5422d148e541f70a4f (patch) | |
tree | f71326fa71c0323e6b5d87b75b289d0608480f87 /source/modules | |
parent | f05f5dce39b11e937fb19270b7bcc888582edf35 (diff) | |
download | samba-80236f0d60ce013134c1ed5422d148e541f70a4f.tar.gz samba-80236f0d60ce013134c1ed5422d148e541f70a4f.tar.xz samba-80236f0d60ce013134c1ed5422d148e541f70a4f.zip |
r21585: Start syncing the monster that will become 3.0.25pre1
Still todo:
* release notes
* few minor outstanding patches
* additional idmap man pages
Diffstat (limited to 'source/modules')
34 files changed, 7616 insertions, 451 deletions
diff --git a/source/modules/README-gpfs-acl.txt b/source/modules/README-gpfs-acl.txt new file mode 100644 index 00000000000..49f3259c1e6 --- /dev/null +++ b/source/modules/README-gpfs-acl.txt @@ -0,0 +1,82 @@ +This patch has been taken against SAMBA_3_0 Release 20028. + +The patch basically moves the GPFS-ACL functionalities into the new GPFS VFS module( vfs_gpfs ). + +Please read SAMBA_3_0/source/modules/README.nfs4acls.txt - generalised README file on Samba support for NFS4-ACLS. +This README file is specific for GPFS only. + +Configuring GPFS ACL support +=============================== + +Binary: (default install path is [samba]/lib/vfs/) +- gpfs.so + +Its compiled by default, no additional configure option needed. + +To enable/use/load this module, include "vfs objects = gpfs" in the smb.conf file under concerned share-name. + +Example of smb.conf: + +[smbtest] +path = /gpfs-test +vfs objects = gpfs +nfs4: mode = special +nfs4: chown = yes +nfs4: acedup = merge + +Adding "vfs objects = gpfs" to a share should be done only in case when NFS4 is really supported by the filesystem. +(Otherwise you may get performance loss.) + +================================================== +Below are some limitations listed for this module: +================================================== +1. When a child file or child directory is created, the results are a bit different from windows as specified below: + +Eg: Prent directory is set to have 2 ACES - full access for owner and everyone + +Default ACL for Windows: 2 aces: allow ACE for owner and everyone +Default ACL for GPFS: 6 aces: allow and deny ACEs for owner, group and everyone + +The below mentioned inheritance flags and its combinations are applied only to the owner ACE and not to everyone ACE + +"fi"------>File Inherit +"di"------>Directory Inherit +"oi"------>Inherit Only + + +Parent dir: no inheritance flag set + Windows: index=0: GPFS(special mode): index=0: GPFS(simple mode): index=0: +child File: default acl: 2 aces child file: default acl: 6 aces child file: default acl: 6 aces +child dir: default acl: 2 aces child dir: default acl: 6 aces child dir: default acl: 6 aces + + +Parent dir: "fi" flag set + Windows: index=1: GPFS(special mode): index=1: GPFS(simple mode): index=1: +child file: no flag set child file: "fi" flag set child file: default acl: 6 aces +child dir: "fioi" flag set child dir: "fi" flag set child dir: "fi" flag set + + +Parent dir: "di" flag set + Windows: index=2: GPFS(special mode): index=2: GPFS(simple mode): index=2: +child file: default acl: 2 aces child file: default acl: 6 aces child file: default acl: 6 aces + + +Parent dir: "fidi" flag set + Windows: index=3: GPFS(special mode): index=3: GPFS(simple mode): index=3: +child file: no flag set child file: "fidi" flag set child file: default acl: 6 aces + + +Parent dir: "fioi" flag set + Windows: index=4: GPFS(special mode): index=4: GPFS(simple mode): index=4: +child file: no flag set child file: "fi" flag set child file: default acl: 6 aces +child dir: "fioi" flag set child dir: "fi" flag set child dir: "fi" flag set + + +Parent dir: "dioi" flag set + Windows: index=5: GPFS(special mode): index=5: GPFS(simple mode): index=5: +child file: default acl: 2 aces child file: default acl: 6 aces child file: default acl: 6 aces + + +Parent dir: "fidioi" flag set + Windows: index=6: GPFS(special mode): index=6: GPFS(simple mode): index=6: +child file: no flag set child file: "fidi" flag set child file: default acl: 6 aces diff --git a/source/modules/README.nfs4acls.txt b/source/modules/README.nfs4acls.txt new file mode 100644 index 00000000000..1cb08877d32 --- /dev/null +++ b/source/modules/README.nfs4acls.txt @@ -0,0 +1,82 @@ +Configuring NFS4 ACLs in Samba3 +=============================== +Created: Peter Somogyi, 2006-JUN-06 +Last modified: Peter Somogyi, 2006-JUL-20 +Revision no.: 4 +------------------------------- + + +Parameters in smb.conf: +======================= + +Each parameter must have a prefix "nfs4:". +Each one affects the behaviour only when _setting_ an acl on a file/dir: + +mode = [simple|special] +- simple: don't use OWNER@ and GROUP@ special IDs in ACEs. - default +- special: use OWNER@ and GROUP@ special IDs in ACEs instead of simple user&group ids. +Note: EVERYONE@ is always processed (if found such an ACE). +Note2: special mode will have side effect when _only_ chown is performed. Later this may be worked out. + +Use "simple" mode when the share is used mainly by windows users and unix side is not significant. You will loose unix bits in this case. +It's strongly advised setting "store dos attributes = yes" in smb.conf. + +chown = [true|false] +- true => enable changing owner and group - default. +- false => disable support for changing owner or group + +acedup = [dontcare|reject|ignore|merge] +- dontcare: copy ACEs as they come, don't care with "duplicate" records. Default. +- reject: stop operation, exit acl setter operation with an error +- ignore: don't include the second matching ACE +- merge: OR 2 ace.flag fields and 2 ace.mask fields of the 2 duplicate ACEs into 1 ACE + +Two ACEs are considered here "duplicate" when their type and id fields are matching. + +Example: + +[smbtest] +path = /tests/psomogyi/smbtest +writable = yes +vfs objects = aixacl2 +nfs4: mode = special +nfs4: chown = yes +nfs4: acedup = merge + +Configuring AIX ACL support +============================== + +Binaries: (default install path is [samba]/lib/vfs/) +- aixacl.so: provides AIXC ACL support only, can be compiled and works on all AIX platforms +- aixacl2.so: provides AIXC and JFS2-NFS4 ACL support, can be compiled and works only under AIX 5.3 and newer. +NFS4 acl currently has support only under JFS2 (ext. attr. format must be set to v2). +aixacl2.so always detects support for NFS4 acls and redirects to POSIX ACL handling automatically when NFS4 is not supported for a path. + +Adding "vfs objects = aixacl2" to a share should be done only in case when NFS4 is really supported by the filesystem. +(Otherwise you may get performance loss.) + +For configuration see also the example above. + +General notes +============= + +NFS4 handling logic is separated from AIX/jfs2 ACL parsing. + +Samba and its VFS modules dosn't reorder ACEs. Windows clients do that (and the smbcacl tool). MSDN also says deny ACEs must come first. +NFS4 ACL's validity is checked by the system API, not by Samba. +NFS4 ACL rights are enforced by the OS or filesystem, not by Samba. + +The flag INHERITED_ACE is never set (not required, as doesn't do WinNT/98/me, only since Win2k). +Win2k GUI behaves strangely when detecting inheritance (sometimes it doesn't detect, +but after adding an ace it shows that - it's some GUI error). + +Unknown (unmappable) SIDs are not accepted. + +TODOs +===== +- Creator Owner & Group SID handling (same way as posix) +- the 4 generic rights bits support (GENERIC_RIGHT_READ_ACCESS, WRITE, EXEC, ALL) +- chown & no ACL, but we have ONWER@ and GROUP@ +- DIALUP, ANONYMOUS, ... builtin SIDs +- audit & alarm support - in theory it's forwarded so it should work, but currently there's no platform which supports them to test +- support for a real NFS4 client (we don't have an accepted API yet) diff --git a/source/modules/charset_macosxfs.c b/source/modules/charset_macosxfs.c index 6f50d879ba4..3e5e2ff8bd2 100644 --- a/source/modules/charset_macosxfs.c +++ b/source/modules/charset_macosxfs.c @@ -62,7 +62,7 @@ static inline void *resize_buffer (void *buffer, size_t *size, size_t newsize) { if (newsize > *size) { *size = newsize + 128; - buffer = realloc(buffer, *size); + buffer = SMB_REALLOC(buffer, *size); } return buffer; } @@ -594,7 +594,7 @@ static struct charset_functions macosxfs_encoding_functions = { "MACOSXFS", macosxfs_encoding_pull, macosxfs_encoding_push }; -NTSTATUS init_module(void) +NTSTATUS charset_macosxfs_init(void) { return smb_register_charset(&macosxfs_encoding_functions); } diff --git a/source/modules/gpfs.c b/source/modules/gpfs.c new file mode 100644 index 00000000000..19050ad3ca5 --- /dev/null +++ b/source/modules/gpfs.c @@ -0,0 +1,236 @@ +/* + * Unix SMB/CIFS implementation. + * Provide a connection to GPFS specific features + * Copyright (C) Volker Lendecke 2005 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +#ifdef HAVE_GPFS + +#include "gpfs_gpl.h" + +static void *libgpfs_handle = NULL; + +static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny); +static int (*gpfs_set_lease_fn)(int fd, unsigned int leaseType); +static int (*gpfs_getacl_fn)(char *pathname, int flags, void *acl); +static int (*gpfs_putacl_fn)(char *pathname, int flags, void *acl); + + +BOOL set_gpfs_sharemode(files_struct *fsp, uint32 access_mask, + uint32 share_access) +{ + unsigned int allow = GPFS_SHARE_NONE; + unsigned int deny = GPFS_DENY_NONE; + int result; + + if (gpfs_set_share_fn == NULL) { + return False; + } + + if ((fsp == NULL) || (fsp->fh == NULL) || (fsp->fh->fd < 0)) { + /* No real file, don't disturb */ + return True; + } + + allow |= (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA| + DELETE_ACCESS)) ? GPFS_SHARE_WRITE : 0; + allow |= (access_mask & (FILE_READ_DATA|FILE_EXECUTE)) ? + GPFS_SHARE_READ : 0; + + if (allow == GPFS_SHARE_NONE) { + DEBUG(10, ("special case am=no_access:%x\n",access_mask)); + } + else { + deny |= (share_access & FILE_SHARE_WRITE) ? + 0 : GPFS_DENY_WRITE; + deny |= (share_access & (FILE_SHARE_READ)) ? + 0 : GPFS_DENY_READ; + } + DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n", + access_mask, allow, share_access, deny)); + + result = gpfs_set_share_fn(fsp->fh->fd, allow, deny); + if (result != 0) { + if (errno == ENOSYS) { + DEBUG(5, ("VFS module vfs_gpfs loaded, but no gpfs " + "support has been compiled into Samba. Allowing access\n")); + return True; + } else { + DEBUG(10, ("gpfs_set_share failed: %s\n", + strerror(errno))); + } + } + + return (result == 0); +} + +int set_gpfs_lease(int fd, int leasetype) +{ + int gpfs_type = GPFS_LEASE_NONE; + + if (gpfs_set_lease_fn == NULL) { + errno = EINVAL; + return -1; + } + + if (leasetype == F_RDLCK) { + gpfs_type = GPFS_LEASE_READ; + } + if (leasetype == F_WRLCK) { + gpfs_type = GPFS_LEASE_WRITE; + } + return gpfs_set_lease_fn(fd, gpfs_type); +} + +int smbd_gpfs_getacl(char *pathname, int flags, void *acl) +{ + if (gpfs_getacl_fn == NULL) { + errno = ENOSYS; + return -1; + } + + return gpfs_getacl_fn(pathname, flags, acl); +} + +int smbd_gpfs_putacl(char *pathname, int flags, void *acl) +{ + if (gpfs_putacl_fn == NULL) { + errno = ENOSYS; + return -1; + } + + return gpfs_putacl_fn(pathname, flags, acl); +} + +void init_gpfs(void) +{ + if (libgpfs_handle != NULL) { + return; + } + + libgpfs_handle = sys_dlopen("libgpfs_gpl.so", RTLD_LAZY); + + if (libgpfs_handle == NULL) { + DEBUG(10, ("sys_dlopen for libgpfs_gpl failed: %s\n", + strerror(errno))); + return; + } + + DEBUG(10, ("libgpfs_gpl.so loaded\n")); + + gpfs_set_share_fn = sys_dlsym(libgpfs_handle, "gpfs_set_share"); + if (gpfs_set_share_fn == NULL) { + DEBUG(3, ("libgpfs_gpl.so does not contain the symbol " + "'gpfs_set_share'\n")); + sys_dlclose(libgpfs_handle); + + /* leave libgpfs_handle != NULL around, no point + in trying twice */ + gpfs_set_share_fn = NULL; + gpfs_set_lease_fn = NULL; + gpfs_getacl_fn = NULL; + gpfs_putacl_fn = NULL; + return; + } + + gpfs_set_lease_fn = sys_dlsym(libgpfs_handle, "gpfs_set_lease"); + if (gpfs_set_lease_fn == NULL) { + DEBUG(3, ("libgpfs_gpl.so does not contain the symbol " + "'gpfs_set_lease'\n")); + sys_dlclose(libgpfs_handle); + + /* leave libgpfs_handle != NULL around, no point + in trying twice */ + gpfs_set_share_fn = NULL; + gpfs_set_lease_fn = NULL; + gpfs_getacl_fn = NULL; + gpfs_putacl_fn = NULL; + return; + } + + gpfs_getacl_fn = sys_dlsym(libgpfs_handle, "gpfs_getacl"); + if (gpfs_getacl_fn == NULL) { + DEBUG(3, ("libgpfs_gpl.so does not contain the symbol " + "'gpfs_getacl'\n")); + sys_dlclose(libgpfs_handle); + + /* leave libgpfs_handle != NULL around, no point + in trying twice */ + gpfs_set_share_fn = NULL; + gpfs_set_lease_fn = NULL; + gpfs_getacl_fn = NULL; + gpfs_putacl_fn = NULL; + return; + } + + gpfs_putacl_fn = sys_dlsym(libgpfs_handle, "gpfs_putacl"); + if (gpfs_putacl_fn == NULL) { + DEBUG(3, ("libgpfs_gpl.so does not contain the symbol " + "'gpfs_putacl'\n")); + sys_dlclose(libgpfs_handle); + + /* leave libgpfs_handle != NULL around, no point + in trying twice */ + gpfs_set_share_fn = NULL; + gpfs_set_lease_fn = NULL; + gpfs_getacl_fn = NULL; + gpfs_putacl_fn = NULL; + return; + } + +} + +#else + +int set_gpfs_lease(int snum, int leasetype) +{ + DEBUG(0, ("'VFS module smbgpfs loaded, without gpfs support compiled\n")); + + /* We need to indicate that no GPFS is around by returning ENOSYS, so + * that the normal linux kernel oplock code is called. */ + errno = ENOSYS; + return -1; +} + +BOOL set_gpfs_sharemode(files_struct *fsp, uint32 access_mask, + uint32 share_access) +{ + DEBUG(0, ("VFS module - smbgpfs.so loaded, without gpfs support compiled\n")); + /* Don't disturb but complain */ + return True; +} + +int smbd_gpfs_getacl(char *pathname, int flags, void *acl) +{ + errno = ENOSYS; + return -1; +} + +int smbd_gpfs_putacl(char *pathname, int flags, void *acl) +{ + errno = ENOSYS; + return -1; +} + +void init_gpfs(void) +{ + return; +} + +#endif /* HAVE_GPFS */ diff --git a/source/modules/nfs4_acls.c b/source/modules/nfs4_acls.c new file mode 100644 index 00000000000..91ebba1f588 --- /dev/null +++ b/source/modules/nfs4_acls.c @@ -0,0 +1,668 @@ +/* + * NFS4 ACL handling + * + * Copyright (C) Jim McDonough, 2006 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" +#include "nfs4_acls.h" + +#define SMBACL4_PARAM_TYPE_NAME "nfs4" + +#define SMB_ACE4_INT_MAGIC 0x76F8A967 +typedef struct _SMB_ACE4_INT_T +{ + uint32 magic; + SMB_ACE4PROP_T prop; + void *next; +} SMB_ACE4_INT_T; + +#define SMB_ACL4_INT_MAGIC 0x29A3E792 +typedef struct _SMB_ACL4_INT_T +{ + uint32 magic; + uint32 naces; + SMB_ACE4_INT_T *first; + SMB_ACE4_INT_T *last; +} SMB_ACL4_INT_T; + +extern struct current_user current_user; +extern int try_chown(connection_struct *conn, const char *fname, uid_t uid, gid_t gid); +extern BOOL unpack_nt_owners(int snum, uid_t *puser, gid_t *pgrp, + uint32 security_info_sent, SEC_DESC *psd); + +static SMB_ACL4_INT_T *get_validated_aclint(SMB4ACL_T *acl) +{ + SMB_ACL4_INT_T *aclint = (SMB_ACL4_INT_T *)acl; + if (acl==NULL) + { + DEBUG(2, ("acl is NULL\n")); + errno = EINVAL; + return NULL; + } + if (aclint->magic!=SMB_ACL4_INT_MAGIC) + { + DEBUG(2, ("aclint bad magic 0x%x\n", aclint->magic)); + errno = EINVAL; + return NULL; + } + return aclint; +} + +static SMB_ACE4_INT_T *get_validated_aceint(SMB4ACE_T *ace) +{ + SMB_ACE4_INT_T *aceint = (SMB_ACE4_INT_T *)ace; + if (ace==NULL) + { + DEBUG(2, ("ace is NULL\n")); + errno = EINVAL; + return NULL; + } + if (aceint->magic!=SMB_ACE4_INT_MAGIC) + { + DEBUG(2, ("aceint bad magic 0x%x\n", aceint->magic)); + errno = EINVAL; + return NULL; + } + return aceint; +} + +SMB4ACL_T *smb_create_smb4acl(void) +{ + TALLOC_CTX *mem_ctx = main_loop_talloc_get(); + SMB_ACL4_INT_T *acl = (SMB_ACL4_INT_T *)talloc_size(mem_ctx, sizeof(SMB_ACL4_INT_T)); + if (acl==NULL) + { + DEBUG(0, ("talloc_size failed\n")); + errno = ENOMEM; + return NULL; + } + memset(acl, 0, sizeof(SMB_ACL4_INT_T)); + acl->magic = SMB_ACL4_INT_MAGIC; + /* acl->first, last = NULL not needed */ + return (SMB4ACL_T *)acl; +} + +SMB4ACE_T *smb_add_ace4(SMB4ACL_T *acl, SMB_ACE4PROP_T *prop) +{ + SMB_ACL4_INT_T *aclint = get_validated_aclint(acl); + TALLOC_CTX *mem_ctx = main_loop_talloc_get(); + SMB_ACE4_INT_T *ace; + + ace = (SMB_ACE4_INT_T *)talloc_size(mem_ctx, sizeof(SMB_ACE4_INT_T)); + if (ace==NULL) + { + DEBUG(0, ("talloc_size failed\n")); + errno = ENOMEM; + return NULL; + } + memset(ace, 0, sizeof(SMB_ACE4_INT_T)); + ace->magic = SMB_ACE4_INT_MAGIC; + /* ace->next = NULL not needed */ + memcpy(&ace->prop, prop, sizeof(SMB_ACE4PROP_T)); + + if (aclint->first==NULL) + { + aclint->first = ace; + aclint->last = ace; + } else { + aclint->last->next = (void *)ace; + aclint->last = ace; + } + aclint->naces++; + + return (SMB4ACE_T *)ace; +} + +SMB_ACE4PROP_T *smb_get_ace4(SMB4ACE_T *ace) +{ + SMB_ACE4_INT_T *aceint = get_validated_aceint(ace); + if (aceint==NULL) + return NULL; + + return &aceint->prop; +} + +SMB4ACE_T *smb_next_ace4(SMB4ACE_T *ace) +{ + SMB_ACE4_INT_T *aceint = get_validated_aceint(ace); + if (aceint==NULL) + return NULL; + + return (SMB4ACE_T *)aceint->next; +} + +SMB4ACE_T *smb_first_ace4(SMB4ACL_T *acl) +{ + SMB_ACL4_INT_T *aclint = get_validated_aclint(acl); + if (aclint==NULL) + return NULL; + + return (SMB4ACE_T *)aclint->first; +} + +uint32 smb_get_naces(SMB4ACL_T *acl) +{ + SMB_ACL4_INT_T *aclint = get_validated_aclint(acl); + if (aclint==NULL) + return 0; + + return aclint->naces; +} + +static int smbacl4_GetFileOwner(files_struct *fsp, SMB_STRUCT_STAT *psbuf) +{ + memset(psbuf, 0, sizeof(SMB_STRUCT_STAT)); + if (fsp->is_directory || fsp->fh->fd == -1) { + /* Get the stat struct for the owner info. */ + if (SMB_VFS_STAT(fsp->conn,fsp->fsp_name, psbuf) != 0) + { + DEBUG(8, ("SMB_VFS_STAT failed with error %s\n", + strerror(errno))); + return -1; + } + } else { + if (SMB_VFS_FSTAT(fsp,fsp->fh->fd, psbuf) != 0) + { + DEBUG(8, ("SMB_VFS_FSTAT failed with error %s\n", + strerror(errno))); + return -1; + } + } + + return 0; +} + +static BOOL smbacl4_nfs42win(SMB4ACL_T *acl, /* in */ + DOM_SID *psid_owner, /* in */ + DOM_SID *psid_group, /* in */ + SEC_ACE **ppnt_ace_list, /* out */ + int *pgood_aces /* out */ +) +{ + SMB_ACL4_INT_T *aclint = (SMB_ACL4_INT_T *)acl; + SMB_ACE4_INT_T *aceint; + SEC_ACE *nt_ace_list = NULL; + int good_aces = 0; + TALLOC_CTX *mem_ctx = main_loop_talloc_get(); + + DEBUG(10, ("smbacl_nfs42win entered")); + + aclint = get_validated_aclint(acl); + if (aclint==NULL) + return False; + + nt_ace_list = (SEC_ACE *)talloc_size(mem_ctx, aclint->naces * sizeof(SEC_ACE)); + if (nt_ace_list==NULL) + { + DEBUG(10, ("talloc error")); + errno = ENOMEM; + return False; + } + memset(nt_ace_list, 0, aclint->naces * sizeof(SEC_ACE)); + + for (aceint=aclint->first; aceint!=NULL; aceint=(SMB_ACE4_INT_T *)aceint->next) { + SEC_ACCESS mask; + DOM_SID sid; + SMB_ACE4PROP_T *ace = &aceint->prop; + + DEBUG(10, ("magic: 0x%x, type: %d, iflags: %x, flags: %x, mask: %x, " + "who: %d\n", aceint->magic, ace->aceType, ace->flags, + ace->aceFlags, ace->aceMask, ace->who.id)); + + SMB_ASSERT(aceint->magic==SMB_ACE4_INT_MAGIC); + + if (ace->flags & SMB_ACE4_ID_SPECIAL) { + switch (ace->who.special_id) { + case SMB_ACE4_WHO_OWNER: + sid_copy(&sid, psid_owner); + break; + case SMB_ACE4_WHO_GROUP: + sid_copy(&sid, psid_group); + break; + case SMB_ACE4_WHO_EVERYONE: + sid_copy(&sid, &global_sid_World); + break; + default: + DEBUG(8, ("invalid special who id %d " + "ignored\n", ace->who.special_id)); + } + } else { + if (ace->aceFlags & SMB_ACE4_IDENTIFIER_GROUP) { + gid_to_sid(&sid, ace->who.gid); + } else { + uid_to_sid(&sid, ace->who.uid); + } + } + DEBUG(10, ("mapped %d to %s\n", ace->who.id, + sid_string_static(&sid))); + + init_sec_access(&mask, ace->aceMask); + init_sec_ace(&nt_ace_list[good_aces++], &sid, + ace->aceType, mask, + ace->aceFlags & 0xf); + } + + *ppnt_ace_list = nt_ace_list; + *pgood_aces = good_aces; + + return True; +} + +size_t smb_get_nt_acl_nfs4(files_struct *fsp, + uint32 security_info, + SEC_DESC **ppdesc, SMB4ACL_T *acl) +{ + int good_aces = 0; + SMB_STRUCT_STAT sbuf; + DOM_SID sid_owner, sid_group; + size_t sd_size = 0; + SEC_ACE *nt_ace_list = NULL; + SEC_ACL *psa = NULL; + TALLOC_CTX *mem_ctx = main_loop_talloc_get(); + + DEBUG(10, ("smb_get_nt_acl_nfs4 invoked for %s\n", fsp->fsp_name)); + + if (acl==NULL || smb_get_naces(acl)==0) + return 0; /* special because we shouldn't alloc 0 for win */ + + if (smbacl4_GetFileOwner(fsp, &sbuf)) + return 0; + + uid_to_sid(&sid_owner, sbuf.st_uid); + gid_to_sid(&sid_group, sbuf.st_gid); + + if (smbacl4_nfs42win(acl, + &sid_owner, + &sid_group, + &nt_ace_list, + &good_aces + )==False) { + DEBUG(8,("smbacl4_nfs42win failed\n")); + return 0; + } + + psa = make_sec_acl(mem_ctx, NT4_ACL_REVISION, + good_aces, nt_ace_list); + if (psa == NULL) { + DEBUG(2,("make_sec_acl failed\n")); + return 0; + } + + DEBUG(10,("after make sec_acl\n")); + *ppdesc = make_sec_desc(mem_ctx, SEC_DESC_REVISION, + SEC_DESC_SELF_RELATIVE, + (security_info & OWNER_SECURITY_INFORMATION) + ? &sid_owner : NULL, + (security_info & GROUP_SECURITY_INFORMATION) + ? &sid_group : NULL, + NULL, psa, &sd_size); + if (*ppdesc==NULL) { + DEBUG(2,("make_sec_desc failed\n")); + return 0; + } + + DEBUG(10, ("smb_get_nt_acl_nfs4 successfully exited with sd_size %d\n", sd_size)); + return sd_size; +} + +enum smbacl4_mode_enum {e_simple=0, e_special=1}; +enum smbacl4_acedup_enum {e_dontcare=0, e_reject=1, e_ignore=2, e_merge=3}; + +typedef struct _smbacl4_vfs_params { + enum smbacl4_mode_enum mode; + BOOL do_chown; + enum smbacl4_acedup_enum acedup; +} smbacl4_vfs_params; + +/* + * Gather special parameters for NFS4 ACL handling + */ +static int smbacl4_get_vfs_params( + const char *type_name, + files_struct *fsp, + smbacl4_vfs_params *params +) +{ + static const struct enum_list enum_smbacl4_modes[] = { + { e_simple, "simple" }, + { e_special, "special" } + }; + static const struct enum_list enum_smbacl4_acedups[] = { + { e_dontcare, "dontcare" }, + { e_reject, "reject" }, + { e_ignore, "ignore" }, + { e_merge, "merge" }, + }; + + memset(params, 0, sizeof(smbacl4_vfs_params)); + params->mode = (enum smbacl4_mode_enum)lp_parm_enum( + SNUM(fsp->conn), type_name, + "mode", enum_smbacl4_modes, e_simple); + params->do_chown = lp_parm_bool(SNUM(fsp->conn), type_name, + "chown", True); + params->acedup = (enum smbacl4_acedup_enum)lp_parm_enum( + SNUM(fsp->conn), type_name, + "acedup", enum_smbacl4_acedups, e_dontcare); + + DEBUG(10, ("mode:%s, do_chown:%s, acedup: %s\n", + enum_smbacl4_modes[params->mode].name, + params->do_chown ? "true" : "false", + enum_smbacl4_acedups[params->acedup].name)); + + return 0; +} + +static void smbacl4_dump_nfs4acl(int level, SMB4ACL_T *acl) +{ + SMB_ACL4_INT_T *aclint = get_validated_aclint(acl); + SMB_ACE4_INT_T *aceint; + + DEBUG(level, ("NFS4ACL: size=%d\n", aclint->naces)); + + for(aceint = aclint->first; aceint!=NULL; aceint=(SMB_ACE4_INT_T *)aceint->next) { + SMB_ACE4PROP_T *ace = &aceint->prop; + + DEBUG(level, ("\tACE: type=%d, flags=0x%x, fflags=0x%x, mask=0x%x, id=%d\n", + ace->aceType, + ace->aceFlags, ace->flags, + ace->aceMask, + ace->who.id)); + } +} + +/* + * Find 2 NFS4 who-special ACE property (non-copy!!!) + * match nonzero if "special" and who is equal + * return ace if found matching; otherwise NULL + */ +static SMB_ACE4PROP_T *smbacl4_find_equal_special( + SMB4ACL_T *acl, + SMB_ACE4PROP_T *aceNew) +{ + SMB_ACL4_INT_T *aclint = get_validated_aclint(acl); + SMB_ACE4_INT_T *aceint; + + for(aceint = aclint->first; aceint!=NULL; aceint=(SMB_ACE4_INT_T *)aceint->next) { + SMB_ACE4PROP_T *ace = &aceint->prop; + + if (ace->flags == aceNew->flags && + ace->aceType==aceNew->aceType && + (ace->aceFlags&SMB_ACE4_IDENTIFIER_GROUP)== + (aceNew->aceFlags&SMB_ACE4_IDENTIFIER_GROUP) + ) { + /* keep type safety; e.g. gid is an u.short */ + if (ace->flags & SMB_ACE4_ID_SPECIAL) + { + if (ace->who.special_id==aceNew->who.special_id) + return ace; + } else { + if (ace->aceFlags & SMB_ACE4_IDENTIFIER_GROUP) + { + if (ace->who.gid==aceNew->who.gid) + return ace; + } else { + if (ace->who.uid==aceNew->who.uid) + return ace; + } + } + } + } + + return NULL; +} + +static int smbacl4_fill_ace4( + TALLOC_CTX *mem_ctx, + smbacl4_vfs_params *params, + uid_t ownerUID, + gid_t ownerGID, + SEC_ACE *ace_nt, /* input */ + SMB_ACE4PROP_T *ace_v4 /* output */ +) +{ + const char *dom, *name; + enum lsa_SidType type; + uid_t uid; + gid_t gid; + + DEBUG(10, ("got ace for %s\n", + sid_string_static(&ace_nt->trustee))); + + memset(ace_v4, 0, sizeof(SMB_ACE4PROP_T)); + ace_v4->aceType = ace_nt->type; /* only ACCES|DENY supported right now */ + ace_v4->aceFlags = ace_nt->flags & SEC_ACE_FLAG_VALID_INHERIT; + ace_v4->aceMask = ace_nt->access_mask & + (STD_RIGHT_ALL_ACCESS | SA_RIGHT_FILE_ALL_ACCESS); + + if (ace_v4->aceFlags!=ace_nt->flags) + DEBUG(9, ("ace_v4->aceFlags(0x%x)!=ace_nt->flags(0x%x)\n", + ace_v4->aceFlags, ace_nt->flags)); + + if (ace_v4->aceMask!=ace_nt->access_mask) + DEBUG(9, ("ace_v4->aceMask(0x%x)!=ace_nt->access_mask(0x%x)\n", + ace_v4->aceMask, ace_nt->access_mask)); + + if (sid_equal(&ace_nt->trustee, &global_sid_World)) { + ace_v4->who.special_id = SMB_ACE4_WHO_EVERYONE; + ace_v4->flags |= SMB_ACE4_ID_SPECIAL; + } else { + if (!lookup_sid(mem_ctx, &ace_nt->trustee, &dom, &name, &type)) { + DEBUG(8, ("Could not find %s' type\n", + sid_string_static(&ace_nt->trustee))); + errno = EINVAL; + return -1; + } + + if (type == SID_NAME_USER) { + if (!sid_to_uid(&ace_nt->trustee, &uid)) { + DEBUG(2, ("Could not convert %s to uid\n", + sid_string_static(&ace_nt->trustee))); + return -1; + } + + if (params->mode==e_special && uid==ownerUID) { + ace_v4->flags |= SMB_ACE4_ID_SPECIAL; + ace_v4->who.special_id = SMB_ACE4_WHO_OWNER; + } else { + ace_v4->who.uid = uid; + } + } else { /* else group? - TODO check it... */ + if (!sid_to_gid(&ace_nt->trustee, &gid)) { + DEBUG(2, ("Could not convert %s to gid\n", + sid_string_static(&ace_nt->trustee))); + return -1; + } + ace_v4->aceFlags |= SMB_ACE4_IDENTIFIER_GROUP; + + if (params->mode==e_special && gid==ownerGID) { + ace_v4->flags |= SMB_ACE4_ID_SPECIAL; + ace_v4->who.special_id = SMB_ACE4_WHO_GROUP; + } else { + ace_v4->who.gid = gid; + } + } + } + + return 0; /* OK */ +} + +static int smbacl4_MergeIgnoreReject( + enum smbacl4_acedup_enum acedup, + SMB4ACL_T *acl, /* may modify it */ + SMB_ACE4PROP_T *ace, /* the "new" ACE */ + BOOL *paddNewACE, + int i +) +{ + int result = 0; + SMB_ACE4PROP_T *ace4found = smbacl4_find_equal_special(acl, ace); + if (ace4found) + { + switch(acedup) + { + case e_merge: /* "merge" flags */ + *paddNewACE = False; + ace4found->aceFlags |= ace->aceFlags; + ace4found->aceMask |= ace->aceMask; + break; + case e_ignore: /* leave out this record */ + *paddNewACE = False; + break; + case e_reject: /* do an error */ + DEBUG(8, ("ACL rejected by duplicate nt ace#%d\n", i)); + errno = EINVAL; /* SHOULD be set on any _real_ error */ + result = -1; + break; + default: + break; + } + } + return result; +} + +static SMB4ACL_T *smbacl4_win2nfs4( + SEC_ACL *dacl, + smbacl4_vfs_params *pparams, + uid_t ownerUID, + gid_t ownerGID +) +{ + SMB4ACL_T *acl; + uint32 i; + TALLOC_CTX *mem_ctx = main_loop_talloc_get(); + + DEBUG(10, ("smbacl4_win2nfs4 invoked\n")); + + acl = smb_create_smb4acl(); + if (acl==NULL) + return NULL; + + for(i=0; i<dacl->num_aces; i++) { + SMB_ACE4PROP_T ace_v4; + BOOL addNewACE = True; + + if (smbacl4_fill_ace4(mem_ctx, pparams, ownerUID, ownerGID, + dacl->aces + i, &ace_v4)) + return NULL; + + if (pparams->acedup!=e_dontcare) { + if (smbacl4_MergeIgnoreReject(pparams->acedup, acl, + &ace_v4, &addNewACE, i)) + return NULL; + } + + if (addNewACE) + smb_add_ace4(acl, &ace_v4); + } + + return acl; +} + +BOOL smb_set_nt_acl_nfs4(files_struct *fsp, + uint32 security_info_sent, + SEC_DESC *psd, + set_nfs4acl_native_fn_t set_nfs4_native) +{ + smbacl4_vfs_params params; + SMB4ACL_T *acl = NULL; + BOOL result; + + SMB_STRUCT_STAT sbuf; + BOOL need_chown = False; + uid_t newUID = (uid_t)-1; + gid_t newGID = (gid_t)-1; + + DEBUG(10, ("smb_set_nt_acl_nfs4 invoked for %s\n", fsp->fsp_name)); + + if ((security_info_sent & (DACL_SECURITY_INFORMATION | + GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION)) == 0) + { + DEBUG(9, ("security_info_sent (0x%x) ignored\n", + security_info_sent)); + return True; /* won't show error - later to be refined... */ + } + + /* Special behaviours */ + if (smbacl4_get_vfs_params(SMBACL4_PARAM_TYPE_NAME, fsp, ¶ms)) + return False; + + if (smbacl4_GetFileOwner(fsp, &sbuf)) + return False; + + /* chown logic is a copy/paste from posix_acl.c:set_nt_acl */ + if (!unpack_nt_owners(SNUM(fsp->conn), &newUID, &newGID, security_info_sent, psd)) + { + DEBUG(8, ("unpack_nt_owners failed")); + return False; + } + if (((newUID != (uid_t)-1) && (sbuf.st_uid != newUID)) || + ((newGID != (gid_t)-1) && (sbuf.st_gid != newGID))) { + need_chown = True; + } + if (need_chown) { + if ((newUID == (uid_t)-1 || newUID == current_user.ut.uid)) { + if(try_chown(fsp->conn, fsp->fsp_name, newUID, newGID)) { + DEBUG(3,("chown %s, %u, %u failed. Error = %s.\n", + fsp->fsp_name, (unsigned int)newUID, (unsigned int)newGID, strerror(errno) )); + return False; + } + DEBUG(10,("chown %s, %u, %u succeeded.\n", + fsp->fsp_name, (unsigned int)newUID, (unsigned int)newGID)); + if (smbacl4_GetFileOwner(fsp, &sbuf)) + return False; + need_chown = False; + } else { /* chown is needed, but _after_ changing acl */ + sbuf.st_uid = newUID; /* OWNER@ in case of e_special */ + sbuf.st_gid = newGID; /* GROUP@ in case of e_special */ + } + } + + if ((security_info_sent & DACL_SECURITY_INFORMATION)!=0 && psd->dacl!=NULL) + { + acl = smbacl4_win2nfs4(psd->dacl, ¶ms, sbuf.st_uid, sbuf.st_gid); + if (!acl) + return False; + + smbacl4_dump_nfs4acl(10, acl); + + result = set_nfs4_native(fsp, acl); + if (result!=True) + { + DEBUG(10, ("set_nfs4_native failed with %s\n", strerror(errno))); + return False; + } + } else + DEBUG(10, ("no dacl found; security_info_sent = 0x%x\n", security_info_sent)); + + /* Any chown pending? */ + if (need_chown) { + DEBUG(3,("chown#2 %s. uid = %u, gid = %u.\n", + fsp->fsp_name, (unsigned int)newUID, (unsigned int)newGID)); + if (try_chown(fsp->conn, fsp->fsp_name, newUID, newGID)) { + DEBUG(2,("chown#2 %s, %u, %u failed. Error = %s.\n", + fsp->fsp_name, (unsigned int)newUID, (unsigned int)newGID, + strerror(errno))); + return False; + } + DEBUG(10,("chown#2 %s, %u, %u succeeded.\n", + fsp->fsp_name, (unsigned int)newUID, (unsigned int)newGID)); + } + + DEBUG(10, ("smb_set_nt_acl_nfs4 succeeded\n")); + return True; +} diff --git a/source/modules/nfs4_acls.h b/source/modules/nfs4_acls.h new file mode 100644 index 00000000000..469a50af56a --- /dev/null +++ b/source/modules/nfs4_acls.h @@ -0,0 +1,146 @@ +/* + * NFS4 ACL handling + * + * Copyright (C) Jim McDonough, 2006 + * Reused & renamed some parts of AIX 5.3 sys/acl.h structures + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef __NFS4_ACLS_H__ +#define __NFS4_ACLS_H__ + +#define SMB_ACLTYPE_NONE 0 +#define SMB_ACLTYPE_UNKNOWN 1 +#define SMB_ACLTYPE_POSIX 2 +#define SMB_ACLTYPE_NFS4 4 + +/* + * Following union captures the identity as + * used in the NFS4 ACL structures. + */ +typedef union _SMB_NFS4_ACEWHOID_T { + uid_t uid; /* User id */ + gid_t gid; /* Group id */ + uint32 special_id; /* Identifies special identities in NFS4 */ + +#define SMB_ACE4_WHO_OWNER 0x00000001 /*The owner of the file. */ +#define SMB_ACE4_WHO_GROUP 0x00000002 /*The group associated with the file. */ +#define SMB_ACE4_WHO_EVERYONE 0x00000003 /*The world. */ +#define SMB_ACE4_WHO_INTERACTIVE 0x00000004 /*Accessed from an interactive terminal. */ +#define SMB_ACE4_WHO_NETWORK 0x00000005 /*Accessed via the network. */ +#define SMB_ACE4_WHO_DIALUP 0x00000006 /*Accessed as a dialup user to the server. */ +#define SMB_ACE4_WHO_BATCH 0x00000007 /*Accessed from a batch job. */ +#define SMB_ACE4_WHO_ANONYMOUS 0x00000008 /*Accessed without any authentication. */ +#define SMB_ACE4_WHO_AUTHENTICATED 0x00000009 /*Any authenticated user (opposite of ANONYMOUS) */ +#define SMB_ACE4_WHO_SERVICE 0x0000000A /*Access from a system service. */ +#define SMB_ACE4_WHO_MAX SMB_ACE4_WHO_SERVICE /* largest valid ACE4_WHO */ + uint32 id; +} SMB_NFS4_ACEWHOID_T; + +typedef struct _SMB_ACE4PROP_T { + uint32 flags; /* Bit mask defining details of ACE */ +/*The following are constants for flags field */ +/* #define SMB_ACE4_ID_NOT_VALID 0x00000001 - from aix/jfs2 */ +#define SMB_ACE4_ID_SPECIAL 0x00000002 + + SMB_NFS4_ACEWHOID_T who; /* Identifies to whom this ACE applies */ + + /* The following part of ACE has the same layout as NFSv4 wire format. */ + + uint32 aceType; /* Type of ACE PERMIT/ALLOW etc*/ +/*The constants used for the type field (acetype4) are as follows: */ +#define SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE 0x00000000 +#define SMB_ACE4_ACCESS_DENIED_ACE_TYPE 0x00000001 +#define SMB_ACE4_SYSTEM_AUDIT_ACE_TYPE 0x00000002 +#define SMB_ACE4_SYSTEM_ALARM_ACE_TYPE 0x00000003 +#define SMB_ACE4_MAX_TYPE ACE4_SYSTEM_ALARM_ACE_TYPE /* largest valid ACE4_TYPE */ + + uint32 aceFlags; /* Controls Inheritance and such */ +/*The bitmask constants used for the flag field are as follows: */ +#define SMB_ACE4_FILE_INHERIT_ACE 0x00000001 +#define SMB_ACE4_DIRECTORY_INHERIT_ACE 0x00000002 +#define SMB_ACE4_NO_PROPAGATE_INHERIT_ACE 0x00000004 +#define SMB_ACE4_INHERIT_ONLY_ACE 0x00000008 +#define SMB_ACE4_SUCCESSFUL_ACCESS_ACE_FLAG 0x00000010 +#define SMB_ACE4_FAILED_ACCESS_ACE_FLAG 0x00000020 +#define SMB_ACE4_IDENTIFIER_GROUP 0x00000040 +#define SMB_ACE4_ALL_FLAGS ( SMB_ACE4_FILE_INHERIT_ACE | SMB_ACE4_DIRECTORY_INHERIT_ACE \ +| SMB_ACE4_NO_PROPAGATE_INHERIT_ACE | SMB_ACE4_INHERIT_ONLY_ACE | SMB_ACE4_SUCCESSFUL_ACCESS_ACE_FLAG \ +| SMB_ACE4_FAILED_ACCESS_ACE_FLAG | SMB_ACE4_IDENTIFIER_GROUP ) + + uint32 aceMask; /* Access rights */ +/*The bitmask constants used for the access mask field are as follows: */ +#define SMB_ACE4_READ_DATA 0x00000001 +#define SMB_ACE4_LIST_DIRECTORY 0x00000001 +#define SMB_ACE4_WRITE_DATA 0x00000002 +#define SMB_ACE4_ADD_FILE 0x00000002 +#define SMB_ACE4_APPEND_DATA 0x00000004 +#define SMB_ACE4_ADD_SUBDIRECTORY 0x00000004 +#define SMB_ACE4_READ_NAMED_ATTRS 0x00000008 +#define SMB_ACE4_WRITE_NAMED_ATTRS 0x00000010 +#define SMB_ACE4_EXECUTE 0x00000020 +#define SMB_ACE4_DELETE_CHILD 0x00000040 +#define SMB_ACE4_READ_ATTRIBUTES 0x00000080 +#define SMB_ACE4_WRITE_ATTRIBUTES 0x00000100 +#define SMB_ACE4_DELETE 0x00010000 +#define SMB_ACE4_READ_ACL 0x00020000 +#define SMB_ACE4_WRITE_ACL 0x00040000 +#define SMB_ACE4_WRITE_OWNER 0x00080000 +#define SMB_ACE4_SYNCHRONIZE 0x00100000 +#define SMB_ACE4_ALL_MASKS ( SMB_ACE4_READ_DATA | SMB_ACE4_LIST_DIRECTORY \ +| SMB_ACE4_WRITE_DATA | SMB_ACE4_ADD_FILE | SMB_ACE4_APPEND_DATA | SMB_ACE4_ADD_SUBDIRECTORY \ +| SMB_ACE4_READ_NAMED_ATTRS | SMB_ACE4_WRITE_NAMED_ATTRS | SMB_ACE4_EXECUTE | SMB_ACE4_DELETE_CHILD \ +| SMB_ACE4_READ_ATTRIBUTES | SMB_ACE4_WRITE_ATTRIBUTES | SMB_ACE4_DELETE | SMB_ACE4_READ_ACL \ +| SMB_ACE4_WRITE_ACL | SMB_ACE4_WRITE_OWNER | SMB_ACE4_SYNCHRONIZE ) +} SMB_ACE4PROP_T; + +/* + * Never allocate these structures on your own + * use create_smb4acl instead + */ +typedef struct _SMB4ACL_T {char dontuse;} SMB4ACL_T; +typedef struct _SMB4ACE_T {char dontuse;} SMB4ACE_T; + +SMB4ACL_T *smb_create_smb4acl(void); + +/* prop's contents are copied */ +/* it doesn't change the order, appends */ +SMB4ACE_T *smb_add_ace4(SMB4ACL_T *acl, SMB_ACE4PROP_T *prop); + +SMB_ACE4PROP_T *smb_get_ace4(SMB4ACE_T *ace); + +/* Returns NULL if none - or error */ +SMB4ACE_T *smb_first_ace4(SMB4ACL_T *acl); + +/* Returns NULL in the end - or error */ +SMB4ACE_T *smb_next_ace4(SMB4ACE_T *ace); + +uint32 smb_get_naces(SMB4ACL_T *acl); + +size_t smb_get_nt_acl_nfs4(files_struct *fsp, + uint32 security_info, + SEC_DESC **ppdesc, SMB4ACL_T *acl); + +/* Callback function needed to set the native acl + * when applicable */ +typedef BOOL (*set_nfs4acl_native_fn_t)(files_struct *, SMB4ACL_T *); + +BOOL smb_set_nt_acl_nfs4(files_struct *fsp, + uint32 security_info_sent, + SEC_DESC *psd, + set_nfs4acl_native_fn_t set_nfs4_native); + +#endif /* __NFS4_ACLS_H__ */ diff --git a/source/modules/vfs_afsacl.c b/source/modules/vfs_afsacl.c index 90a3045126d..43fa537d734 100644 --- a/source/modules/vfs_afsacl.c +++ b/source/modules/vfs_afsacl.c @@ -48,7 +48,7 @@ struct afs_ace { BOOL positive; char *name; DOM_SID sid; - enum SID_NAME_USE type; + enum lsa_SidType type; uint32 rights; struct afs_ace *next; }; @@ -110,7 +110,7 @@ static struct afs_ace *new_afs_ace(TALLOC_CTX *mem_ctx, const char *name, uint32 rights) { DOM_SID sid; - enum SID_NAME_USE type; + enum lsa_SidType type; struct afs_ace *result; if (strcmp(name, "system:administrators") == 0) { @@ -589,7 +589,7 @@ static uint32 nt_to_afs_file_rights(const char *filename, const SEC_ACE *ace) static size_t afs_to_nt_acl(struct afs_acl *afs_acl, struct files_struct *fsp, uint32 security_info, - struct security_descriptor_info **ppdesc) + struct security_descriptor **ppdesc) { SEC_ACE *nt_ace_list; DOM_SID owner_sid, group_sid; @@ -691,7 +691,7 @@ static BOOL mappable_sid(const DOM_SID *sid) static BOOL nt_to_afs_acl(const char *filename, uint32 security_info_sent, - struct security_descriptor_info *psd, + struct security_descriptor *psd, uint32 (*nt_to_afs_rights)(const char *filename, const SEC_ACE *ace), struct afs_acl *afs_acl) @@ -713,7 +713,7 @@ static BOOL nt_to_afs_acl(const char *filename, for (i = 0; i < dacl->num_aces; i++) { SEC_ACE *ace = &(dacl->ace[i]); const char *dom_name, *name; - enum SID_NAME_USE name_type; + enum lsa_SidType name_type; char *p; if (ace->type != SEC_ACE_TYPE_ACCESS_ALLOWED) { @@ -827,7 +827,7 @@ static BOOL afs_get_afs_acl(char *filename, struct afs_acl *acl) } static size_t afs_get_nt_acl(struct files_struct *fsp, uint32 security_info, - struct security_descriptor_info **ppdesc) + struct security_descriptor **ppdesc) { struct afs_acl acl; size_t sd_size; @@ -881,7 +881,7 @@ static void merge_unknown_aces(struct afs_acl *src, struct afs_acl *dst) static BOOL afs_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, - struct security_descriptor_info *psd) + struct security_descriptor *psd) { struct afs_acl old_afs_acl, new_afs_acl; struct afs_acl dir_acl, file_acl; @@ -982,14 +982,14 @@ static BOOL afs_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, static size_t afsacl_fget_nt_acl(struct vfs_handle_struct *handle, struct files_struct *fsp, int fd, uint32 security_info, - struct security_descriptor_info **ppdesc) + struct security_descriptor **ppdesc) { return afs_get_nt_acl(fsp, security_info, ppdesc); } static size_t afsacl_get_nt_acl(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name, uint32 security_info, - struct security_descriptor_info **ppdesc) + struct security_descriptor **ppdesc) { return afs_get_nt_acl(fsp, security_info, ppdesc); } @@ -1011,7 +1011,6 @@ BOOL afsacl_set_nt_acl(vfs_handle_struct *handle, } static int afsacl_connect(vfs_handle_struct *handle, - connection_struct *conn, const char *service, const char *user) { @@ -1022,7 +1021,7 @@ static int afsacl_connect(vfs_handle_struct *handle, if (spc != NULL) space_replacement = spc[0]; - return SMB_VFS_NEXT_CONNECT(handle, conn, service, user); + return SMB_VFS_NEXT_CONNECT(handle, service, user); } /* VFS operations structure */ @@ -1041,6 +1040,7 @@ static vfs_op_tuple afsacl_ops[] = { {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} }; +NTSTATUS vfs_afsacl_init(void); NTSTATUS vfs_afsacl_init(void) { return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "afsacl", diff --git a/source/modules/vfs_aixacl.c b/source/modules/vfs_aixacl.c new file mode 100644 index 00000000000..20c469e36c0 --- /dev/null +++ b/source/modules/vfs_aixacl.c @@ -0,0 +1,216 @@ +/* + Unix SMB/Netbios implementation. + VFS module to get and set posix acls + Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +extern SMB_ACL_T aixacl_to_smbacl( struct acl *file_acl); +extern struct acl *aixacl_smb_to_aixacl(SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl); + +SMB_ACL_T aixacl_sys_acl_get_file(vfs_handle_struct *handle, + const char *path_p, + SMB_ACL_TYPE_T type) +{ + struct acl *file_acl = (struct acl *)NULL; + struct smb_acl_t *result = (struct smb_acl_t *)NULL; + + int rc = 0; + uid_t user_id; + + /* AIX has no DEFAULT */ + if ( type == SMB_ACL_TYPE_DEFAULT ) + return NULL; + + /* Get the acl using statacl */ + + DEBUG(10,("Entering AIX sys_acl_get_file\n")); + DEBUG(10,("path_p is %s\n",path_p)); + + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); + + if(file_acl == NULL) { + errno=ENOMEM; + DEBUG(0,("Error in AIX sys_acl_get_file: %d\n",errno)); + return(NULL); + } + + memset(file_acl,0,BUFSIZ); + + rc = statacl((char *)path_p,0,file_acl,BUFSIZ); + if( (rc == -1) && (errno == ENOSPC)) { + struct acl *new_acl = SMB_MALLOC(file_acl->acl_len + sizeof(struct acl)); + if( new_acl == NULL) { + SAFE_FREE(file_acl); + errno = ENOMEM; + return NULL; + } + file_acl = new_acl; + rc = statacl((char *)path_p,0,file_acl,file_acl->acl_len+sizeof(struct acl)); + if( rc == -1) { + DEBUG(0,("statacl returned %d with errno %d\n",rc,errno)); + SAFE_FREE(file_acl); + return(NULL); + } + } + + DEBUG(10,("Got facl and returned it\n")); + + + result = aixacl_to_smbacl(file_acl); + SAFE_FREE(file_acl); + return result; + + /*errno = ENOTSUP; + return NULL;*/ +} + +SMB_ACL_T aixacl_sys_acl_get_fd(vfs_handle_struct *handle, + files_struct *fsp, + int fd) +{ + + struct acl *file_acl = (struct acl *)NULL; + struct smb_acl_t *result = (struct smb_acl_t *)NULL; + + int rc = 0; + uid_t user_id; + + /* Get the acl using fstatacl */ + + DEBUG(10,("Entering AIX sys_acl_get_fd\n")); + DEBUG(10,("fd is %d\n",fd)); + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); + + if(file_acl == NULL) { + errno=ENOMEM; + DEBUG(0,("Error in AIX sys_acl_get_fd is %d\n",errno)); + return(NULL); + } + + memset(file_acl,0,BUFSIZ); + + rc = fstatacl(fd,0,file_acl,BUFSIZ); + if( (rc == -1) && (errno == ENOSPC)) { + struct acl *new_acl = SMB_MALLOC(file_acl->acl_len + sizeof(struct acl)); + if( new_acl == NULL) { + SAFE_FREE(file_acl); + errno = ENOMEM; + return NULL; + } + file_acl = new_acl; + rc = fstatacl(fd,0,file_acl,file_acl->acl_len + sizeof(struct acl)); + if( rc == -1) { + DEBUG(0,("fstatacl returned %d with errno %d\n",rc,errno)); + SAFE_FREE(file_acl); + return(NULL); + } + } + + DEBUG(10,("Got facl and returned it\n")); + + result = aixacl_to_smbacl(file_acl); + SAFE_FREE(file_acl); + return result; + + /*errno = ENOTSUP; + return NULL;*/ +} + +int aixacl_sys_acl_set_file(vfs_handle_struct *handle, + const char *name, + SMB_ACL_TYPE_T type, + SMB_ACL_T theacl) +{ + struct acl *file_acl = NULL; + uint rc; + + file_acl = aixacl_smb_to_aixacl(type, theacl); + if (!file_acl) + return -1; + + rc = chacl((char *)name,file_acl,file_acl->acl_len); + DEBUG(10,("errno is %d\n",errno)); + DEBUG(10,("return code is %d\n",rc)); + SAFE_FREE(file_acl); + DEBUG(10,("Exiting the aixacl_sys_acl_set_file\n")); + + return rc; +} + +int aixacl_sys_acl_set_fd(vfs_handle_struct *handle, + files_struct *fsp, + int fd, SMB_ACL_T theacl) +{ + struct acl *file_acl = NULL; + uint rc; + + file_acl = aixacl_smb_to_aixacl(SMB_ACL_TYPE_ACCESS, theacl); + if (!file_acl) + return -1; + + rc = fchacl(fd,file_acl,file_acl->acl_len); + DEBUG(10,("errno is %d\n",errno)); + DEBUG(10,("return code is %d\n",rc)); + SAFE_FREE(file_acl); + DEBUG(10,("Exiting aixacl_sys_acl_set_fd\n")); + + return rc; +} + +int aixacl_sys_acl_delete_def_file(vfs_handle_struct *handle, + const char *path) +{ + return 0; /* otherwise you can't set acl at upper level */ +} + +/* VFS operations structure */ + +static vfs_op_tuple aixacl_op_tuples[] = { + /* Disk operations */ + {SMB_VFS_OP(aixacl_sys_acl_get_file), + SMB_VFS_OP_SYS_ACL_GET_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(aixacl_sys_acl_get_fd), + SMB_VFS_OP_SYS_ACL_GET_FD, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(aixacl_sys_acl_set_file), + SMB_VFS_OP_SYS_ACL_SET_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(aixacl_sys_acl_set_fd), + SMB_VFS_OP_SYS_ACL_SET_FD, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(aixacl_sys_acl_delete_def_file), + SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(NULL), + SMB_VFS_OP_NOOP, + SMB_VFS_LAYER_NOOP} +}; + +NTSTATUS vfs_aixacl_init(void); +NTSTATUS vfs_aixacl_init(void) +{ + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "aixacl", + aixacl_op_tuples); +} diff --git a/source/modules/vfs_aixacl2.c b/source/modules/vfs_aixacl2.c new file mode 100644 index 00000000000..62a517a6e08 --- /dev/null +++ b/source/modules/vfs_aixacl2.c @@ -0,0 +1,538 @@ +/* + * Convert JFS2 NFS4/AIXC acls to NT acls and vice versa. + * + * Copyright (C) Volker Lendecke, 2006 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" +#include "nfs4_acls.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_VFS + +#define AIXACL2_MODULE_NAME "aixacl2" + +extern struct current_user current_user; +extern int try_chown(connection_struct *conn, const char *fname, uid_t uid, gid_t gid); +extern BOOL unpack_nt_owners(int snum, uid_t *puser, gid_t *pgrp, + uint32 security_info_sent, SEC_DESC *psd); + +extern SMB_ACL_T aixacl_to_smbacl( struct acl *file_acl); +extern struct acl *aixacl_smb_to_aixacl(SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl); + +typedef union aixjfs2_acl_t { + nfs4_acl_int_t jfs2_acl[1]; + aixc_acl_t aixc_acl[1]; +}AIXJFS2_ACL_T; + +static int32_t aixacl2_getlen(AIXJFS2_ACL_T *acl, acl_type_t *type) +{ + int32_t len; + + if(type->u64 == ACL_NFS4) { + len = acl->jfs2_acl[0].aclLength; + } + else { + if(type->u64 == ACL_AIXC) { + len = acl->aixc_acl[0].acl_len; + } else { + DEBUG(0,("aixacl2_getlen:unknown type:%d\n",type->u64)); + return False; + } + } + DEBUG(10,("aixacl2_getlen:%d\n",len)); + return len; +} + +static AIXJFS2_ACL_T *aixjfs2_getacl_alloc(const char *fname, acl_type_t *type) +{ + AIXJFS2_ACL_T *acl; + size_t len = 200; + mode_t mode; + int ret; + uint64_t ctl_flag=0; + TALLOC_CTX *mem_ctx; + + mem_ctx = main_loop_talloc_get(); + acl = (AIXJFS2_ACL_T *)talloc_size(mem_ctx, len); + if (acl == NULL) { + errno = ENOMEM; + return NULL; + } + + if(type->u64 == ACL_ANY) { + ctl_flag = ctl_flag | GET_ACLINFO_ONLY; + } + + ret = aclx_get((char *)fname, ctl_flag, type, acl, &len, &mode); + if ((ret != 0) && (errno == ENOSPC)) { + len = aixacl2_getlen(acl, type) + sizeof(AIXJFS2_ACL_T); + DEBUG(10,("aixjfs2_getacl_alloc - acl_len:%d\n",len)); + + acl = (AIXJFS2_ACL_T *)talloc_size(mem_ctx, len); + if (acl == NULL) { + errno = ENOMEM; + return NULL; + } + + ret = aclx_get((char *)fname, ctl_flag, type, acl, &len, &mode); + } + if (ret != 0) { + DEBUG(8, ("aclx_get failed with %s\n", strerror(errno))); + return NULL; + } + + return acl; +} + +static BOOL aixjfs2_get_nfs4_acl(files_struct *fsp, + SMB4ACL_T **ppacl, BOOL *pretryPosix) +{ + int32_t i; + + AIXJFS2_ACL_T *pacl = NULL; + nfs4_acl_int_t *jfs2_acl = NULL; + nfs4_ace_int_t *jfs2_ace = NULL; + acl_type_t type; + + DEBUG(10,("jfs2 get_nt_acl invoked for %s\n", fsp->fsp_name)); + + memset(&type, 0, sizeof(acl_type_t)); + type.u64 = ACL_NFS4; + + pacl = aixjfs2_getacl_alloc(fsp->fsp_name, &type); + if (pacl == NULL) { + DEBUG(9, ("aixjfs2_getacl_alloc failed for %s with %s\n", + fsp->fsp_name, strerror(errno))); + if (errno==ENOSYS) + *pretryPosix = True; + return False; + } + + jfs2_acl = &pacl->jfs2_acl[0]; + DEBUG(10, ("len: %d, version: %d, nace: %d, type: 0x%x\n", + jfs2_acl->aclLength, jfs2_acl->aclVersion, jfs2_acl->aclEntryN, type.u64)); + + *ppacl = smb_create_smb4acl(); + if (*ppacl==NULL) + return False; + + jfs2_ace = &jfs2_acl->aclEntry[0]; + for (i=0; i<jfs2_acl->aclEntryN; i++) { + SMB_ACE4PROP_T aceprop; + + DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, " + "who: %d, aclLen: %d\n", jfs2_ace->aceType, jfs2_ace->flags, + jfs2_ace->aceFlags, jfs2_ace->aceMask, jfs2_ace->aceWho.id, jfs2_ace->entryLen)); + + aceprop.aceType = jfs2_ace->aceType; + aceprop.aceFlags = jfs2_ace->aceFlags; + aceprop.aceMask = jfs2_ace->aceMask; + aceprop.flags = (jfs2_ace->flags&ACE4_ID_SPECIAL) ? SMB_ACE4_ID_SPECIAL : 0; + + /* don't care it's real content is only 16 or 32 bit */ + aceprop.who.id = jfs2_ace->aceWho.id; + + if (smb_add_ace4(*ppacl, &aceprop)==NULL) + return False; + + /* iterate to the next jfs2 ace */ + jfs2_ace = (nfs4_ace_int_t *)(((char *)jfs2_ace) + jfs2_ace->entryLen); + } + + DEBUG(10,("jfs2 get_nt_acl finished successfully\n")); + + return True; +} + +static size_t aixjfs2_get_nt_acl_common(files_struct *fsp, + uint32 security_info, SEC_DESC **ppdesc) +{ + SMB4ACL_T *pacl = NULL; + BOOL result; + BOOL retryPosix = False; + + *ppdesc = NULL; + result = aixjfs2_get_nfs4_acl(fsp, &pacl, &retryPosix); + if (retryPosix) + { + DEBUG(10, ("retrying with posix acl...\n")); + return get_nt_acl(fsp, security_info, ppdesc); + } + if (result==False) + return 0; + + return smb_get_nt_acl_nfs4(fsp, security_info, ppdesc, pacl); +} + +size_t aixjfs2_fget_nt_acl(vfs_handle_struct *handle, + files_struct *fsp, int fd, uint32 security_info, + SEC_DESC **ppdesc) +{ + return aixjfs2_get_nt_acl_common(fsp, security_info, ppdesc); +} + +size_t aixjfs2_get_nt_acl(vfs_handle_struct *handle, + files_struct *fsp, const char *name, + uint32 security_info, SEC_DESC **ppdesc) +{ + return aixjfs2_get_nt_acl_common(fsp, security_info, ppdesc); +} + +static SMB_ACL_T aixjfs2_get_posix_acl(const char *path, acl_type_t type) +{ + aixc_acl_t *pacl; + AIXJFS2_ACL_T *acl; + SMB_ACL_T result = NULL; + int ret; + + acl = aixjfs2_getacl_alloc(path, &type); + + if (acl == NULL) { + DEBUG(10, ("aixjfs2_getacl failed for %s with %s\n", + path, strerror(errno))); + if (errno == 0) { + errno = EINVAL; + } + goto done; + } + + pacl = &acl->aixc_acl[0]; + DEBUG(10, ("len: %d, mode: %d\n", + pacl->acl_len, pacl->acl_mode)); + + result = aixacl_to_smbacl(pacl); + if (result == NULL) { + goto done; + } + + done: + if (errno != 0) { + SAFE_FREE(result); + } + return result; +} + +SMB_ACL_T aixjfs2_sys_acl_get_file(vfs_handle_struct *handle, + const char *path_p, + SMB_ACL_TYPE_T type) +{ + acl_type_t aixjfs2_type; + + switch(type) { + case SMB_ACL_TYPE_ACCESS: + aixjfs2_type.u64 = ACL_AIXC; + break; + case SMB_ACL_TYPE_DEFAULT: + DEBUG(0, ("Got AIX JFS2 unsupported type: %d\n", type)); + return NULL; + default: + DEBUG(0, ("Got invalid type: %d\n", type)); + smb_panic("exiting"); + } + + return aixjfs2_get_posix_acl(path_p, aixjfs2_type); +} + +SMB_ACL_T aixjfs2_sys_acl_get_fd(vfs_handle_struct *handle, + files_struct *fsp, + int fd) +{ + acl_type_t aixjfs2_type; + aixjfs2_type.u64 = ACL_AIXC; + + return aixjfs2_get_posix_acl(fsp->fsp_name, aixjfs2_type); +} + +/* + * Test whether we have that aclType support on the given path + */ +static int aixjfs2_query_acl_support( + char *filepath, + uint64_t aclType, + acl_type_t *pacl_type_info +) +{ + acl_types_list_t acl_type_list; + size_t acl_type_list_len = sizeof(acl_types_list_t); + uint32_t i; + + memset(&acl_type_list, 0, sizeof(acl_type_list)); + + if (aclx_gettypes(filepath, &acl_type_list, &acl_type_list_len)) { + DEBUG(2, ("aclx_gettypes failed with error %s for %s\n", + strerror(errno), filepath)); + return -1; + } + + for(i=0; i<acl_type_list.num_entries; i++) { + if (acl_type_list.entries[i].u64==aclType) { + memcpy(pacl_type_info, acl_type_list.entries + i, sizeof(acl_type_t)); + DEBUG(10, ("found %s ACL support for %s\n", + pacl_type_info->acl_type, filepath)); + return 0; + } + } + + return 1; /* haven't found that ACL type. */ +} + +static BOOL aixjfs2_process_smbacl(files_struct *fsp, SMB4ACL_T *smbacl) +{ + SMB4ACE_T *smbace; + TALLOC_CTX *mem_ctx; + nfs4_acl_int_t *jfs2acl; + int32_t entryLen; + uint32 aclLen, naces; + int rc; + acl_type_t acltype; + + DEBUG(10, ("jfs2_process_smbacl invoked on %s\n", fsp->fsp_name)); + + /* no need to be freed which is alloced with mem_ctx */ + mem_ctx = main_loop_talloc_get(); + + entryLen = sizeof(nfs4_ace_int_t); + if (entryLen & 0x03) + entryLen = entryLen + 4 - (entryLen%4); + + naces = smb_get_naces(smbacl); + aclLen = ACL_V4_SIZ + naces * entryLen; + jfs2acl = (nfs4_acl_int_t *)talloc_size(mem_ctx, aclLen); + if (jfs2acl==NULL) { + DEBUG(0, ("talloc_size failed\n")); + errno = ENOMEM; + return False; + } + + jfs2acl->aclLength = ACL_V4_SIZ; + jfs2acl->aclVersion = NFS4_ACL_INT_STRUCT_VERSION; + jfs2acl->aclEntryN = 0; + + for(smbace = smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) + { + SMB_ACE4PROP_T *aceprop = smb_get_ace4(smbace); + nfs4_ace_int_t *jfs2_ace = (nfs4_ace_int_t *)(((char *)jfs2acl) + jfs2acl->aclLength); + + memset(jfs2_ace, 0, entryLen); + jfs2_ace->entryLen = entryLen; /* won't store textual "who" */ + jfs2_ace->aceType = aceprop->aceType; /* only ACCES|DENY supported by jfs2 */ + jfs2_ace->aceFlags = aceprop->aceFlags; + jfs2_ace->aceMask = aceprop->aceMask; + jfs2_ace->flags = (aceprop->flags&SMB_ACE4_ID_SPECIAL) ? ACE4_ID_SPECIAL : 0; + + /* don't care it's real content is only 16 or 32 bit */ + jfs2_ace->aceWho.id = aceprop->who.id; + + /* iterate to the next jfs2 ace */ + jfs2acl->aclLength += jfs2_ace->entryLen; + jfs2acl->aclEntryN++; + } + SMB_ASSERT(jfs2acl->aclEntryN==naces); + + /* Don't query it (again) */ + memset(&acltype, 0, sizeof(acl_type_t)); + acltype.u64 = ACL_NFS4; + + /* won't set S_ISUID - the only one JFS2/NFS4 accepts */ + rc = aclx_put( + fsp->fsp_name, + SET_ACL, /* set only the ACL, not mode bits */ + acltype, /* not a pointer !!! */ + jfs2acl, + jfs2acl->aclLength, + 0 /* don't set here mode bits */ + ); + if (rc) { + DEBUG(8, ("aclx_put failed with %s\n", strerror(errno))); + return False; + } + + DEBUG(10, ("jfs2_process_smbacl succeeded.\n")); + return True; +} + +static BOOL aixjfs2_set_nt_acl_common(files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd) +{ + acl_type_t acl_type_info; + BOOL result = False; + int rc; + + rc = aixjfs2_query_acl_support( + fsp->fsp_name, + ACL_NFS4, + &acl_type_info); + + if (rc==0) + { + result = smb_set_nt_acl_nfs4( + fsp, security_info_sent, psd, + aixjfs2_process_smbacl); + } else if (rc==1) { /* assume POSIX ACL - by default... */ + result = set_nt_acl(fsp, security_info_sent, psd); + } else + result = False; /* query failed */ + + return result; +} + +BOOL aixjfs2_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, int fd, uint32 security_info_sent, SEC_DESC *psd) +{ + return aixjfs2_set_nt_acl_common(fsp, security_info_sent, psd); +} + +BOOL aixjfs2_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, const char *name, uint32 security_info_sent, SEC_DESC *psd) +{ + return aixjfs2_set_nt_acl_common(fsp, security_info_sent, psd); +} + +int aixjfs2_sys_acl_set_file(vfs_handle_struct *handle, + const char *name, + SMB_ACL_TYPE_T type, + SMB_ACL_T theacl) +{ + struct acl *acl_aixc; + acl_type_t acl_type_info; + int rc; + + DEBUG(10, ("aixjfs2_sys_acl_set_file invoked for %s", name)); + + rc = aixjfs2_query_acl_support((char *)name, ACL_AIXC, &acl_type_info); + if (rc) { + DEBUG(8, ("jfs2_set_nt_acl: AIXC support not found\n")); + return -1; + } + + acl_aixc = aixacl_smb_to_aixacl(type, theacl); + if (!acl_aixc) + return -1; + + rc = aclx_put( + (char *)name, + SET_ACL, /* set only the ACL, not mode bits */ + acl_type_info, + acl_aixc, + acl_aixc->acl_len, + 0 + ); + if (rc) { + DEBUG(2, ("aclx_put failed with %s for %s\n", + strerror(errno), name)); + return -1; + } + + return 0; +} + +int aixjfs2_sys_acl_set_fd(vfs_handle_struct *handle, + files_struct *fsp, + int fd, SMB_ACL_T theacl) +{ + struct acl *acl_aixc; + acl_type_t acl_type_info; + int rc; + + DEBUG(10, ("aixjfs2_sys_acl_set_fd invoked for %s", fsp->fsp_name)); + + rc = aixjfs2_query_acl_support(fsp->fsp_name, ACL_AIXC, &acl_type_info); + if (rc) { + DEBUG(8, ("jfs2_set_nt_acl: AIXC support not found\n")); + return -1; + } + + acl_aixc = aixacl_smb_to_aixacl(SMB_ACL_TYPE_ACCESS, theacl); + if (!acl_aixc) + return -1; + + rc = aclx_fput( + fd, + SET_ACL, /* set only the ACL, not mode bits */ + acl_type_info, + acl_aixc, + acl_aixc->acl_len, + 0 + ); + if (rc) { + DEBUG(2, ("aclx_fput failed with %s for %s\n", + strerror(errno), fsp->fsp_name)); + return -1; + } + + return 0; +} + +int aixjfs2_sys_acl_delete_def_file(vfs_handle_struct *handle, + const char *path) +{ + /* Not available under AIXC ACL */ + /* Don't report here any error otherwise */ + /* upper layer will break the normal execution */ + return 0; +} + + +/* VFS operations structure */ + +static vfs_op_tuple aixjfs2_ops[] = +{ + {SMB_VFS_OP(aixjfs2_fget_nt_acl), + SMB_VFS_OP_FGET_NT_ACL, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(aixjfs2_get_nt_acl), + SMB_VFS_OP_GET_NT_ACL, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(aixjfs2_fset_nt_acl), + SMB_VFS_OP_FSET_NT_ACL, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(aixjfs2_set_nt_acl), + SMB_VFS_OP_SET_NT_ACL, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(aixjfs2_sys_acl_get_file), + SMB_VFS_OP_SYS_ACL_GET_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(aixjfs2_sys_acl_get_fd), + SMB_VFS_OP_SYS_ACL_GET_FD, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(aixjfs2_sys_acl_set_file), + SMB_VFS_OP_SYS_ACL_SET_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(aixjfs2_sys_acl_set_fd), + SMB_VFS_OP_SYS_ACL_SET_FD, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(aixjfs2_sys_acl_delete_def_file), + SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(NULL), + SMB_VFS_OP_NOOP, + SMB_VFS_LAYER_NOOP} +}; + +NTSTATUS vfs_aixacl2_init(void); +NTSTATUS vfs_aixacl2_init(void) +{ + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, AIXACL2_MODULE_NAME, + aixjfs2_ops); +} diff --git a/source/modules/vfs_aixacl_util.c b/source/modules/vfs_aixacl_util.c new file mode 100644 index 00000000000..fd7481af3ef --- /dev/null +++ b/source/modules/vfs_aixacl_util.c @@ -0,0 +1,297 @@ +/* + Unix SMB/Netbios implementation. + VFS module to get and set posix acls + Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +SMB_ACL_T aixacl_to_smbacl(struct acl *file_acl) +{ + struct acl_entry *acl_entry; + struct ace_id *idp; + + struct smb_acl_t *result = SMB_MALLOC_P(struct smb_acl_t); + struct smb_acl_entry *ace; + int i; + + if (result == NULL) { + return NULL; + } + ZERO_STRUCTP(result); + + /* Point to the first acl entry in the acl */ + acl_entry = file_acl->acl_ext; + + + + DEBUG(10,("acl_entry is %d\n",acl_entry)); + DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl))); + + /* Check if the extended acl bit is on. * + * If it isn't, do not show the * + * contents of the acl since AIX intends * + * the extended info to remain unused */ + + if(file_acl->acl_mode & S_IXACL){ + /* while we are not pointing to the very end */ + while(acl_entry < acl_last(file_acl)) { + /* before we malloc anything, make sure this is */ + /* a valid acl entry and one that we want to map */ + idp = id_nxt(acl_entry->ace_id); + if((acl_entry->ace_type == ACC_SPECIFY || + (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) { + acl_entry = acl_nxt(acl_entry); + continue; + } + + idp = acl_entry->ace_id; + DEBUG(10,("idp->id_data is %d\n",idp->id_data[0])); + + result = SMB_REALLOC(result, sizeof(struct smb_acl_t) + + (sizeof(struct smb_acl_entry) * + (result->count+1))); + if (result == NULL) { + DEBUG(0, ("SMB_REALLOC failed\n")); + errno = ENOMEM; + return NULL; + } + + + DEBUG(10,("idp->id_type is %d\n",idp->id_type)); + ace = &result->acl[result->count]; + + ace->a_type = idp->id_type; + + switch(ace->a_type) { + case ACEID_USER: { + ace->uid = idp->id_data[0]; + DEBUG(10,("case ACEID_USER ace->uid is %d\n",ace->uid)); + ace->a_type = SMB_ACL_USER; + break; + } + + case ACEID_GROUP: { + ace->gid = idp->id_data[0]; + DEBUG(10,("case ACEID_GROUP ace->gid is %d\n",ace->gid)); + ace->a_type = SMB_ACL_GROUP; + break; + } + default: + break; + } + /* The access in the acl entries must be left shifted by * + * three bites, because they will ultimately be compared * + * to S_IRUSR, S_IWUSR, and S_IXUSR. */ + + switch(acl_entry->ace_type){ + case ACC_PERMIT: + case ACC_SPECIFY: + ace->a_perm = acl_entry->ace_access; + ace->a_perm <<= 6; + DEBUG(10,("ace->a_perm is %d\n",ace->a_perm)); + break; + case ACC_DENY: + /* Since there is no way to return a DENY acl entry * + * change to PERMIT and then shift. */ + DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access)); + ace->a_perm = ~acl_entry->ace_access & 7; + DEBUG(10,("ace->a_perm is %d\n",ace->a_perm)); + ace->a_perm <<= 6; + break; + default: + DEBUG(0, ("unknown ace->type\n")); + SAFE_FREE(result); + return(0); + } + + result->count++; + ace->a_perm |= (ace->a_perm & S_IRUSR) ? SMB_ACL_READ : 0; + ace->a_perm |= (ace->a_perm & S_IWUSR) ? SMB_ACL_WRITE : 0; + ace->a_perm |= (ace->a_perm & S_IXUSR) ? SMB_ACL_EXECUTE : 0; + DEBUG(10,("ace->a_perm is %d\n",ace->a_perm)); + + DEBUG(10,("acl_entry = %d\n",acl_entry)); + DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type)); + + acl_entry = acl_nxt(acl_entry); + } + } /* end of if enabled */ + + /* Since owner, group, other acl entries are not * + * part of the acl entries in an acl, they must * + * be dummied up to become part of the list. */ + + for( i = 1; i < 4; i++) { + DEBUG(10,("i is %d\n",i)); + + result = SMB_REALLOC(result, sizeof(struct smb_acl_t) + + (sizeof(struct smb_acl_entry) * + (result->count+1))); + if (result == NULL) { + DEBUG(0, ("SMB_REALLOC failed\n")); + errno = ENOMEM; + DEBUG(0,("Error in AIX sys_acl_get_file is %d\n",errno)); + return NULL; + } + + ace = &result->acl[result->count]; + + ace->uid = 0; + ace->gid = 0; + DEBUG(10,("ace->uid = %d\n",ace->uid)); + + switch(i) { + case 2: + ace->a_perm = file_acl->g_access << 6; + ace->a_type = SMB_ACL_GROUP_OBJ; + break; + + case 3: + ace->a_perm = file_acl->o_access << 6; + ace->a_type = SMB_ACL_OTHER; + break; + + case 1: + ace->a_perm = file_acl->u_access << 6; + ace->a_type = SMB_ACL_USER_OBJ; + break; + + default: + return(NULL); + + } + ace->a_perm |= ((ace->a_perm & S_IRUSR) ? SMB_ACL_READ : 0); + ace->a_perm |= ((ace->a_perm & S_IWUSR) ? SMB_ACL_WRITE : 0); + ace->a_perm |= ((ace->a_perm & S_IXUSR) ? SMB_ACL_EXECUTE : 0); + + memcpy(&result->acl[result->count],ace,sizeof(struct smb_acl_entry)); + result->count++; + DEBUG(10,("ace->a_perm = %d\n",ace->a_perm)); + DEBUG(10,("ace->a_type = %d\n",ace->a_type)); + } + + + return result; + + +} + +static ushort aixacl_smb_to_aixperm(SMB_ACL_PERM_T a_perm) +{ + ushort ret = (ushort)0; + if (a_perm & SMB_ACL_READ) + ret |= R_ACC; + if (a_perm & SMB_ACL_WRITE) + ret |= W_ACC; + if (a_perm & SMB_ACL_EXECUTE) + ret |= X_ACC; + return ret; +} + +struct acl *aixacl_smb_to_aixacl(SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) +{ + struct smb_acl_entry *smb_entry = NULL; + struct acl *file_acl = NULL; + struct acl *file_acl_temp = NULL; + struct acl_entry *acl_entry = NULL; + struct ace_id *ace_id = NULL; + uint id_type; + uint user_id; + uint acl_length; + int i; + + DEBUG(10,("Entering aixacl_smb_to_aixacl\n")); + /* AIX has no default ACL */ + if(acltype == SMB_ACL_TYPE_DEFAULT) + return NULL; + + acl_length = BUFSIZ; + file_acl = (struct acl *)SMB_MALLOC(BUFSIZ); + if(file_acl == NULL) { + errno = ENOMEM; + DEBUG(0,("Error in aixacl_smb_to_aixacl is %d\n",errno)); + return NULL; + } + + memset(file_acl,0,BUFSIZ); + + file_acl->acl_len = ACL_SIZ; + file_acl->acl_mode = S_IXACL; + + for(i=0; i<theacl->count; i++ ) { + smb_entry = &(theacl->acl[i]); + id_type = smb_entry->a_type; + DEBUG(10,("The id_type is %d\n",id_type)); + + switch(id_type) { + case SMB_ACL_USER_OBJ: + file_acl->u_access = aixacl_smb_to_aixperm(smb_entry->a_perm); + continue; + case SMB_ACL_GROUP_OBJ: + file_acl->g_access = aixacl_smb_to_aixperm(smb_entry->a_perm); + continue; + case SMB_ACL_OTHER: + file_acl->o_access = aixacl_smb_to_aixperm(smb_entry->a_perm); + continue; + case SMB_ACL_MASK: + continue; + case SMB_ACL_GROUP: + break; /* process this */ + case SMB_ACL_USER: + break; /* process this */ + default: /* abnormal case */ + DEBUG(10,("The id_type is unknown !\n")); + continue; + } + + if((file_acl->acl_len + sizeof(struct acl_entry)) > acl_length) { + acl_length += sizeof(struct acl_entry); + file_acl_temp = (struct acl *)SMB_MALLOC(acl_length); + if(file_acl_temp == NULL) { + SAFE_FREE(file_acl); + errno = ENOMEM; + DEBUG(0,("Error in aixacl_smb_to_aixacl is %d\n",errno)); + return NULL; + } + + memcpy(file_acl_temp,file_acl,file_acl->acl_len); + SAFE_FREE(file_acl); + file_acl = file_acl_temp; + } + + acl_entry = (struct acl_entry *)((char *)file_acl + file_acl->acl_len); + file_acl->acl_len += sizeof(struct acl_entry); + acl_entry->ace_len = sizeof(struct acl_entry); /* contains 1 ace_id */ + acl_entry->ace_access = aixacl_smb_to_aixperm(smb_entry->a_perm); + + /* In order to use this, we'll need to wait until we can get denies */ + /* if(!acl_entry->ace_access && acl_entry->ace_type == ACC_PERMIT) + acl_entry->ace_type = ACC_SPECIFY; */ + + acl_entry->ace_type = ACC_SPECIFY; + + ace_id = acl_entry->ace_id; + + ace_id->id_type = (smb_entry->a_type==SMB_ACL_GROUP) ? ACEID_GROUP : ACEID_USER; + DEBUG(10,("The id type is %d\n",ace_id->id_type)); + ace_id->id_len = sizeof(struct ace_id); /* contains 1 id_data */ + ace_id->id_data[0] = (smb_entry->a_type==SMB_ACL_GROUP) ? smb_entry->gid : smb_entry->uid; + } + + return file_acl; +} diff --git a/source/modules/vfs_audit.c b/source/modules/vfs_audit.c index 9f5179a47ce..fb146c1ad4f 100644 --- a/source/modules/vfs_audit.c +++ b/source/modules/vfs_audit.c @@ -29,17 +29,17 @@ /* Function prototypes */ -static int audit_connect(vfs_handle_struct *handle, connection_struct *conn, const char *svc, const char *user); -static void audit_disconnect(vfs_handle_struct *handle, connection_struct *conn); -static SMB_STRUCT_DIR *audit_opendir(vfs_handle_struct *handle, connection_struct *conn, const char *fname, const char *mask, uint32 attr); -static int audit_mkdir(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode); -static int audit_rmdir(vfs_handle_struct *handle, connection_struct *conn, const char *path); -static int audit_open(vfs_handle_struct *handle, connection_struct *conn, const char *fname, int flags, mode_t mode); +static int audit_connect(vfs_handle_struct *handle, const char *svc, const char *user); +static void audit_disconnect(vfs_handle_struct *handle); +static SMB_STRUCT_DIR *audit_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr); +static int audit_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode); +static int audit_rmdir(vfs_handle_struct *handle, const char *path); +static int audit_open(vfs_handle_struct *handle, const char *fname, files_struct *fsp, int flags, mode_t mode); static int audit_close(vfs_handle_struct *handle, files_struct *fsp, int fd); -static int audit_rename(vfs_handle_struct *handle, connection_struct *conn, const char *oldname, const char *newname); -static int audit_unlink(vfs_handle_struct *handle, connection_struct *conn, const char *path); -static int audit_chmod(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode); -static int audit_chmod_acl(vfs_handle_struct *handle, connection_struct *conn, const char *name, mode_t mode); +static int audit_rename(vfs_handle_struct *handle, const char *oldname, const char *newname); +static int audit_unlink(vfs_handle_struct *handle, const char *path); +static int audit_chmod(vfs_handle_struct *handle, const char *path, mode_t mode); +static int audit_chmod_acl(vfs_handle_struct *handle, const char *name, mode_t mode); static int audit_fchmod(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode); static int audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode); @@ -120,7 +120,7 @@ static int audit_syslog_priority(vfs_handle_struct *handle) /* Implementation of vfs_ops. Pass everything on to the default operation but log event first. */ -static int audit_connect(vfs_handle_struct *handle, connection_struct *conn, const char *svc, const char *user) +static int audit_connect(vfs_handle_struct *handle, const char *svc, const char *user) { int result; @@ -129,24 +129,24 @@ static int audit_connect(vfs_handle_struct *handle, connection_struct *conn, con syslog(audit_syslog_priority(handle), "connect to service %s by user %s\n", svc, user); - result = SMB_VFS_NEXT_CONNECT(handle, conn, svc, user); + result = SMB_VFS_NEXT_CONNECT(handle, svc, user); return result; } -static void audit_disconnect(vfs_handle_struct *handle, connection_struct *conn) +static void audit_disconnect(vfs_handle_struct *handle) { syslog(audit_syslog_priority(handle), "disconnected\n"); - SMB_VFS_NEXT_DISCONNECT(handle, conn); + SMB_VFS_NEXT_DISCONNECT(handle); return; } -static SMB_STRUCT_DIR *audit_opendir(vfs_handle_struct *handle, connection_struct *conn, const char *fname, const char *mask, uint32 attr) +static SMB_STRUCT_DIR *audit_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr) { SMB_STRUCT_DIR *result; - result = SMB_VFS_NEXT_OPENDIR(handle, conn, fname, mask, attr); + result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr); syslog(audit_syslog_priority(handle), "opendir %s %s%s\n", fname, @@ -156,11 +156,11 @@ static SMB_STRUCT_DIR *audit_opendir(vfs_handle_struct *handle, connection_struc return result; } -static int audit_mkdir(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode) +static int audit_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode) { int result; - result = SMB_VFS_NEXT_MKDIR(handle, conn, path, mode); + result = SMB_VFS_NEXT_MKDIR(handle, path, mode); syslog(audit_syslog_priority(handle), "mkdir %s %s%s\n", path, @@ -170,11 +170,11 @@ static int audit_mkdir(vfs_handle_struct *handle, connection_struct *conn, const return result; } -static int audit_rmdir(vfs_handle_struct *handle, connection_struct *conn, const char *path) +static int audit_rmdir(vfs_handle_struct *handle, const char *path) { int result; - result = SMB_VFS_NEXT_RMDIR(handle, conn, path); + result = SMB_VFS_NEXT_RMDIR(handle, path); syslog(audit_syslog_priority(handle), "rmdir %s %s%s\n", path, @@ -184,11 +184,11 @@ static int audit_rmdir(vfs_handle_struct *handle, connection_struct *conn, const return result; } -static int audit_open(vfs_handle_struct *handle, connection_struct *conn, const char *fname, int flags, mode_t mode) +static int audit_open(vfs_handle_struct *handle, const char *fname, files_struct *fsp, int flags, mode_t mode) { int result; - result = SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode); + result = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode); syslog(audit_syslog_priority(handle), "open %s (fd %d) %s%s%s\n", fname, result, @@ -213,11 +213,11 @@ static int audit_close(vfs_handle_struct *handle, files_struct *fsp, int fd) return result; } -static int audit_rename(vfs_handle_struct *handle, connection_struct *conn, const char *oldname, const char *newname) +static int audit_rename(vfs_handle_struct *handle, const char *oldname, const char *newname) { int result; - result = SMB_VFS_NEXT_RENAME(handle, conn, oldname, newname); + result = SMB_VFS_NEXT_RENAME(handle, oldname, newname); syslog(audit_syslog_priority(handle), "rename %s -> %s %s%s\n", oldname, newname, @@ -227,11 +227,11 @@ static int audit_rename(vfs_handle_struct *handle, connection_struct *conn, cons return result; } -static int audit_unlink(vfs_handle_struct *handle, connection_struct *conn, const char *path) +static int audit_unlink(vfs_handle_struct *handle, const char *path) { int result; - result = SMB_VFS_NEXT_UNLINK(handle, conn, path); + result = SMB_VFS_NEXT_UNLINK(handle, path); syslog(audit_syslog_priority(handle), "unlink %s %s%s\n", path, @@ -241,11 +241,11 @@ static int audit_unlink(vfs_handle_struct *handle, connection_struct *conn, cons return result; } -static int audit_chmod(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode) +static int audit_chmod(vfs_handle_struct *handle, const char *path, mode_t mode) { int result; - result = SMB_VFS_NEXT_CHMOD(handle, conn, path, mode); + result = SMB_VFS_NEXT_CHMOD(handle, path, mode); syslog(audit_syslog_priority(handle), "chmod %s mode 0x%x %s%s\n", path, mode, @@ -255,11 +255,11 @@ static int audit_chmod(vfs_handle_struct *handle, connection_struct *conn, const return result; } -static int audit_chmod_acl(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode) +static int audit_chmod_acl(vfs_handle_struct *handle, const char *path, mode_t mode) { int result; - result = SMB_VFS_NEXT_CHMOD_ACL(handle, conn, path, mode); + result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode); syslog(audit_syslog_priority(handle), "chmod_acl %s mode 0x%x %s%s\n", path, mode, @@ -297,6 +297,7 @@ static int audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp, int fd return result; } +NTSTATUS vfs_audit_init(void); NTSTATUS vfs_audit_init(void) { return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "audit", audit_op_tuples); diff --git a/source/modules/vfs_cacheprime.c b/source/modules/vfs_cacheprime.c new file mode 100644 index 00000000000..61a92a02324 --- /dev/null +++ b/source/modules/vfs_cacheprime.c @@ -0,0 +1,201 @@ +/* + * Copyright (c) James Peach 2005-2006 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +/* Cache priming module. + * + * The purpose of this module is to do RAID stripe width reads to prime the + * buffer cache to do zero-copy I/O for subsequent sendfile calls. The idea is + * to do a single large read at the start of the file to make sure that most or + * all of the file is pulled into the buffer cache. Subsequent I/Os have + * reduced latency. + * + * Tunables. + * + * cacheprime:rsize Amount of readahead in bytes. This should be a + * multiple of the RAID stripe width. + * cacheprime:debug Debug level at which to emit messages. + */ + +#define READAHEAD_MIN (128 * 1024) /* min is 128 KiB */ +#define READAHEAD_MAX (100 * 1024 * 1024) /* max is 100 MiB */ + +#define MODULE "cacheprime" + +static int module_debug; +static ssize_t g_readsz = 0; +static void * g_readbuf = NULL; + +/* Prime the kernel buffer cache with data from the specified file. We use + * per-fsp data to make sure we only ever do this once. If pread is being + * emulated by seek/read/seek, when this will suck quite a lot. + */ +static BOOL prime_cache( + struct vfs_handle_struct * handle, + files_struct * fsp, + int fd, + SMB_OFF_T offset, + size_t count) +{ + SMB_OFF_T * last; + ssize_t nread; + + last = VFS_ADD_FSP_EXTENSION(handle, fsp, SMB_OFF_T); + if (!last) { + return False; + } + + if (*last == -1) { + /* Readahead disabled. */ + return False; + } + + if ((*last + g_readsz) > (offset + count)) { + /* Skip readahead ... we've already been here. */ + return False; + } + + DEBUG(module_debug, + ("%s: doing readahead of %lld bytes at %lld for %s\n", + MODULE, (long long)g_readsz, (long long)*last, + fsp->fsp_name)); + + nread = sys_pread(fd, g_readbuf, g_readsz, *last); + if (nread < 0) { + *last = -1; + return False; + } + + *last += nread; + return True; +} + +static int cprime_connect( + struct vfs_handle_struct * handle, + const char * service, + const char * user) +{ + module_debug = lp_parm_int(SNUM(handle->conn), MODULE, "debug", 100); + if (g_readbuf) { + /* Only allocate g_readbuf once. If the config changes and + * another client multiplexes onto this smbd, we don't want + * to risk memory corruption. + */ + return SMB_VFS_NEXT_CONNECT(handle, service, user); + } + + g_readsz = conv_str_size(lp_parm_const_string(SNUM(handle->conn), + MODULE, "rsize", NULL)); + + if (g_readsz < READAHEAD_MIN) { + DEBUG(module_debug, ("%s: %ld bytes of readahead " + "requested, using minimum of %u\n", + MODULE, (long)g_readsz, READAHEAD_MIN)); + g_readsz = READAHEAD_MIN; + } else if (g_readsz > READAHEAD_MAX) { + DEBUG(module_debug, ("%s: %ld bytes of readahead " + "requested, using maximum of %u\n", + MODULE, (long)g_readsz, READAHEAD_MAX)); + g_readsz = READAHEAD_MAX; + } + + if ((g_readbuf = SMB_MALLOC(g_readsz)) == NULL) { + /* Turn off readahead if we can't get a buffer. */ + g_readsz = 0; + } + + return SMB_VFS_NEXT_CONNECT(handle, service, user); +} + +static ssize_t cprime_sendfile( + struct vfs_handle_struct * handle, + int tofd, + files_struct * fsp, + int fromfd, + const DATA_BLOB * header, + SMB_OFF_T offset, + size_t count) +{ + if (g_readbuf && offset == 0) { + prime_cache(handle, fsp, fromfd, offset, count); + } + + return SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, fromfd, + header, offset, count); +} + +static ssize_t cprime_read( + vfs_handle_struct * handle, + files_struct * fsp, + int fd, + void * data, + size_t count) +{ + SMB_OFF_T offset; + + offset = SMB_VFS_LSEEK(fsp, fd, 0, SEEK_CUR); + if (offset >= 0 && g_readbuf) { + prime_cache(handle, fsp, fd, offset, count); + SMB_VFS_LSEEK(fsp, fd, offset, SEEK_SET); + } + + return SMB_VFS_NEXT_READ(handle, fsp, fd, data, count); +} + +static ssize_t cprime_pread( + vfs_handle_struct * handle, + files_struct * fsp, + int fd, + void * data, + size_t count, + SMB_OFF_T offset) +{ + if (g_readbuf) { + prime_cache(handle, fsp, fd, offset, count); + } + + return SMB_VFS_NEXT_PREAD(handle, fsp, fd, data, count, offset); +} + +static vfs_op_tuple cprime_ops [] = +{ + {SMB_VFS_OP(cprime_sendfile), + SMB_VFS_OP_SENDFILE, SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(cprime_pread), + SMB_VFS_OP_PREAD, SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(cprime_read), + SMB_VFS_OP_READ, SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(cprime_connect), + SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} +}; + +/* ------------------------------------------------------------------------- + * Samba module initialisation entry point. + * ------------------------------------------------------------------------- + */ + +NTSTATUS vfs_cacheprime_init(void); +NTSTATUS vfs_cacheprime_init(void) +{ + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, MODULE, cprime_ops); +} + +/* vim: set sw=4 ts=4 tw=79 et: */ diff --git a/source/modules/vfs_cap.c b/source/modules/vfs_cap.c index b1bfcd75f2f..e058c9660c7 100644 --- a/source/modules/vfs_cap.c +++ b/source/modules/vfs_cap.c @@ -28,28 +28,28 @@ static char *capencode(char *to, const char *from); static char *capdecode(char *to, const char *from); -static SMB_BIG_UINT cap_disk_free(vfs_handle_struct *handle, connection_struct *conn, const char *path, +static SMB_BIG_UINT cap_disk_free(vfs_handle_struct *handle, const char *path, BOOL small_query, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { pstring cappath; capencode(cappath, path); - return SMB_VFS_NEXT_DISK_FREE(handle, conn, cappath, small_query, bsize, + return SMB_VFS_NEXT_DISK_FREE(handle, cappath, small_query, bsize, dfree, dsize); } -static SMB_STRUCT_DIR *cap_opendir(vfs_handle_struct *handle, connection_struct *conn, const char *fname, const char *mask, uint32 attr) +static SMB_STRUCT_DIR *cap_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr) { pstring capname; capencode(capname, fname); - return SMB_VFS_NEXT_OPENDIR(handle, conn, capname, mask, attr); + return SMB_VFS_NEXT_OPENDIR(handle, capname, mask, attr); } -static SMB_STRUCT_DIRENT *cap_readdir(vfs_handle_struct *handle, connection_struct *conn, SMB_STRUCT_DIR *dirp) +static SMB_STRUCT_DIRENT *cap_readdir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp) { SMB_STRUCT_DIRENT *result; DEBUG(3,("cap: cap_readdir\n")); - result = SMB_VFS_NEXT_READDIR(handle, conn, dirp); + result = SMB_VFS_NEXT_READDIR(handle, dirp); if (result) { DEBUG(3,("cap: cap_readdir: %s\n", result->d_name)); capdecode(result->d_name, result->d_name); @@ -57,124 +57,124 @@ static SMB_STRUCT_DIRENT *cap_readdir(vfs_handle_struct *handle, connection_stru return result; } -static int cap_mkdir(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode) +static int cap_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode) { pstring cappath; capencode(cappath, path); - return SMB_VFS_NEXT_MKDIR(handle, conn, cappath, mode); + return SMB_VFS_NEXT_MKDIR(handle, cappath, mode); } -static int cap_rmdir(vfs_handle_struct *handle, connection_struct *conn, const char *path) +static int cap_rmdir(vfs_handle_struct *handle, const char *path) { pstring cappath; capencode(cappath, path); - return SMB_VFS_NEXT_RMDIR(handle, conn, cappath); + return SMB_VFS_NEXT_RMDIR(handle, cappath); } -static int cap_open(vfs_handle_struct *handle, connection_struct *conn, const char *fname, int flags, mode_t mode) +static int cap_open(vfs_handle_struct *handle, const char *fname, files_struct *fsp, int flags, mode_t mode) { pstring capname; DEBUG(3,("cap: cap_open for %s\n", fname)); capencode(capname, fname); - return SMB_VFS_NEXT_OPEN(handle, conn, capname, flags, mode); + return SMB_VFS_NEXT_OPEN(handle, capname, fsp, flags, mode); } -static int cap_rename(vfs_handle_struct *handle, connection_struct *conn, const char *oldname, const char *newname) +static int cap_rename(vfs_handle_struct *handle, const char *oldname, const char *newname) { pstring capold, capnew; capencode(capold, oldname); capencode(capnew, newname); - return SMB_VFS_NEXT_RENAME(handle, conn, capold, capnew); + return SMB_VFS_NEXT_RENAME(handle, capold, capnew); } -static int cap_stat(vfs_handle_struct *handle, connection_struct *conn, const char *fname, SMB_STRUCT_STAT *sbuf) +static int cap_stat(vfs_handle_struct *handle, const char *fname, SMB_STRUCT_STAT *sbuf) { pstring capname; capencode(capname, fname); - return SMB_VFS_NEXT_STAT(handle, conn, capname, sbuf); + return SMB_VFS_NEXT_STAT(handle, capname, sbuf); } -static int cap_lstat(vfs_handle_struct *handle, connection_struct *conn, const char *path, SMB_STRUCT_STAT *sbuf) +static int cap_lstat(vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf) { pstring cappath; capencode(cappath, path); - return SMB_VFS_NEXT_LSTAT(handle, conn, cappath, sbuf); + return SMB_VFS_NEXT_LSTAT(handle, cappath, sbuf); } -static int cap_unlink(vfs_handle_struct *handle, connection_struct *conn, const char *path) +static int cap_unlink(vfs_handle_struct *handle, const char *path) { pstring cappath; capencode(cappath, path); - return SMB_VFS_NEXT_UNLINK(handle, conn, cappath); + return SMB_VFS_NEXT_UNLINK(handle, cappath); } -static int cap_chmod(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode) +static int cap_chmod(vfs_handle_struct *handle, const char *path, mode_t mode) { pstring cappath; capencode(cappath, path); - return SMB_VFS_NEXT_CHMOD(handle, conn, cappath, mode); + return SMB_VFS_NEXT_CHMOD(handle, cappath, mode); } -static int cap_chown(vfs_handle_struct *handle, connection_struct *conn, const char *path, uid_t uid, gid_t gid) +static int cap_chown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid) { pstring cappath; capencode(cappath, path); - return SMB_VFS_NEXT_CHOWN(handle, conn, cappath, uid, gid); + return SMB_VFS_NEXT_CHOWN(handle, cappath, uid, gid); } -static int cap_chdir(vfs_handle_struct *handle, connection_struct *conn, const char *path) +static int cap_chdir(vfs_handle_struct *handle, const char *path) { pstring cappath; DEBUG(3,("cap: cap_chdir for %s\n", path)); capencode(cappath, path); - return SMB_VFS_NEXT_CHDIR(handle, conn, cappath); + return SMB_VFS_NEXT_CHDIR(handle, cappath); } -static int cap_utime(vfs_handle_struct *handle, connection_struct *conn, const char *path, struct utimbuf *times) +static int cap_utime(vfs_handle_struct *handle, const char *path, struct utimbuf *times) { pstring cappath; capencode(cappath, path); - return SMB_VFS_NEXT_UTIME(handle, conn, cappath, times); + return SMB_VFS_NEXT_UTIME(handle, cappath, times); } -static BOOL cap_symlink(vfs_handle_struct *handle, connection_struct *conn, const char *oldpath, const char *newpath) +static BOOL cap_symlink(vfs_handle_struct *handle, const char *oldpath, const char *newpath) { pstring capoldpath, capnewpath; capencode(capoldpath, oldpath); capencode(capnewpath, newpath); - return SMB_VFS_NEXT_SYMLINK(handle, conn, capoldpath, capnewpath); + return SMB_VFS_NEXT_SYMLINK(handle, capoldpath, capnewpath); } -static BOOL cap_readlink(vfs_handle_struct *handle, connection_struct *conn, const char *path, char *buf, size_t bufsiz) +static BOOL cap_readlink(vfs_handle_struct *handle, const char *path, char *buf, size_t bufsiz) { pstring cappath; capencode(cappath, path); - return SMB_VFS_NEXT_READLINK(handle, conn, cappath, buf, bufsiz); + return SMB_VFS_NEXT_READLINK(handle, cappath, buf, bufsiz); } -static int cap_link(vfs_handle_struct *handle, connection_struct *conn, const char *oldpath, const char *newpath) +static int cap_link(vfs_handle_struct *handle, const char *oldpath, const char *newpath) { pstring capoldpath, capnewpath; capencode(capoldpath, oldpath); capencode(capnewpath, newpath); - return SMB_VFS_NEXT_LINK(handle, conn, capoldpath, capnewpath); + return SMB_VFS_NEXT_LINK(handle, capoldpath, capnewpath); } -static int cap_mknod(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode, SMB_DEV_T dev) +static int cap_mknod(vfs_handle_struct *handle, const char *path, mode_t mode, SMB_DEV_T dev) { pstring cappath; capencode(cappath, path); - return SMB_VFS_NEXT_MKNOD(handle, conn, cappath, mode, dev); + return SMB_VFS_NEXT_MKNOD(handle, cappath, mode, dev); } -static char *cap_realpath(vfs_handle_struct *handle, connection_struct *conn, const char *path, char *resolved_path) +static char *cap_realpath(vfs_handle_struct *handle, const char *path, char *resolved_path) { /* monyo need capencode'ed and capdecode'ed? */ pstring cappath; capencode(cappath, path); - return SMB_VFS_NEXT_REALPATH(handle, conn, path, resolved_path); + return SMB_VFS_NEXT_REALPATH(handle, path, resolved_path); } static BOOL cap_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, const char *name, uint32 security_info_sent, struct security_descriptor_info *psd) @@ -184,7 +184,7 @@ static BOOL cap_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, const c return SMB_VFS_NEXT_SET_NT_ACL(handle, fsp, capname, security_info_sent, psd); } -static int cap_chmod_acl(vfs_handle_struct *handle, connection_struct *conn, const char *name, mode_t mode) +static int cap_chmod_acl(vfs_handle_struct *handle, const char *name, mode_t mode) { pstring capname; capencode(capname, name); @@ -194,45 +194,45 @@ static int cap_chmod_acl(vfs_handle_struct *handle, connection_struct *conn, con errno = ENOSYS; return -1; } - return SMB_VFS_NEXT_CHMOD_ACL(handle, conn, capname, mode); + return SMB_VFS_NEXT_CHMOD_ACL(handle, capname, mode); } -static SMB_ACL_T cap_sys_acl_get_file(vfs_handle_struct *handle, connection_struct *conn, const char *path_p, SMB_ACL_TYPE_T type) +static SMB_ACL_T cap_sys_acl_get_file(vfs_handle_struct *handle, const char *path_p, SMB_ACL_TYPE_T type) { pstring cappath_p; capencode(cappath_p, path_p); - return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, conn, cappath_p, type); + return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, cappath_p, type); } -static int cap_sys_acl_set_file(vfs_handle_struct *handle, connection_struct *conn, const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) +static int cap_sys_acl_set_file(vfs_handle_struct *handle, const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) { pstring capname; capencode(capname, name); - return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, conn, capname, acltype, theacl); + return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, capname, acltype, theacl); } -static int cap_sys_acl_delete_def_file(vfs_handle_struct *handle, connection_struct *conn, const char *path) +static int cap_sys_acl_delete_def_file(vfs_handle_struct *handle, const char *path) { pstring cappath; capencode(cappath, path); - return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, conn, cappath); + return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, cappath); } -static ssize_t cap_getxattr(vfs_handle_struct *handle, struct connection_struct *conn,const char *path, const char *name, void *value, size_t size) +static ssize_t cap_getxattr(vfs_handle_struct *handle, const char *path, const char *name, void *value, size_t size) { pstring cappath, capname; capencode(cappath, path); capencode(capname, name); - return SMB_VFS_NEXT_GETXATTR(handle, conn, cappath, capname, value, size); + return SMB_VFS_NEXT_GETXATTR(handle, cappath, capname, value, size); } -static ssize_t cap_lgetxattr(vfs_handle_struct *handle, struct connection_struct *conn,const char *path, const char *name, void *value, size_t +static ssize_t cap_lgetxattr(vfs_handle_struct *handle, const char *path, const char *name, void *value, size_t size) { pstring cappath, capname; capencode(cappath, path); capencode(capname, name); - return SMB_VFS_NEXT_LGETXATTR(handle, conn, cappath, capname, value, size); + return SMB_VFS_NEXT_LGETXATTR(handle, cappath, capname, value, size); } static ssize_t cap_fgetxattr(vfs_handle_struct *handle, struct files_struct *fsp,int fd, const char *name, void *value, size_t size) @@ -242,34 +242,34 @@ static ssize_t cap_fgetxattr(vfs_handle_struct *handle, struct files_struct *fsp return SMB_VFS_NEXT_FGETXATTR(handle, fsp, fd, capname, value, size); } -static ssize_t cap_listxattr(vfs_handle_struct *handle, struct connection_struct *conn,const char *path, char *list, size_t size) +static ssize_t cap_listxattr(vfs_handle_struct *handle, const char *path, char *list, size_t size) { pstring cappath; capencode(cappath, path); - return SMB_VFS_NEXT_LISTXATTR(handle, conn, cappath, list, size); + return SMB_VFS_NEXT_LISTXATTR(handle, cappath, list, size); } -static ssize_t cap_llistxattr(vfs_handle_struct *handle, struct connection_struct *conn,const char *path, char *list, size_t size) +static ssize_t cap_llistxattr(vfs_handle_struct *handle, const char *path, char *list, size_t size) { pstring cappath; capencode(cappath, path); - return SMB_VFS_NEXT_LLISTXATTR(handle, conn, cappath, list, size); + return SMB_VFS_NEXT_LLISTXATTR(handle, cappath, list, size); } -static int cap_removexattr(vfs_handle_struct *handle, struct connection_struct *conn,const char *path, const char *name) +static int cap_removexattr(vfs_handle_struct *handle, const char *path, const char *name) { pstring cappath, capname; capencode(cappath, path); capencode(capname, name); - return SMB_VFS_NEXT_REMOVEXATTR(handle, conn, cappath, capname); + return SMB_VFS_NEXT_REMOVEXATTR(handle, cappath, capname); } -static int cap_lremovexattr(vfs_handle_struct *handle, struct connection_struct *conn,const char *path, const char *name) +static int cap_lremovexattr(vfs_handle_struct *handle, const char *path, const char *name) { pstring cappath, capname; capencode(cappath, path); capencode(capname, name); - return SMB_VFS_NEXT_LREMOVEXATTR(handle, conn, cappath, capname); + return SMB_VFS_NEXT_LREMOVEXATTR(handle, cappath, capname); } static int cap_fremovexattr(vfs_handle_struct *handle, struct files_struct *fsp,int fd, const char *name) @@ -279,20 +279,20 @@ static int cap_fremovexattr(vfs_handle_struct *handle, struct files_struct *fsp, return SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, fd, capname); } -static int cap_setxattr(vfs_handle_struct *handle, struct connection_struct *conn,const char *path, const char *name, const void *value, size_t size, int flags) +static int cap_setxattr(vfs_handle_struct *handle, const char *path, const char *name, const void *value, size_t size, int flags) { pstring cappath, capname; capencode(cappath, path); capencode(capname, name); - return SMB_VFS_NEXT_SETXATTR(handle, conn, cappath, capname, value, size, flags); + return SMB_VFS_NEXT_SETXATTR(handle, cappath, capname, value, size, flags); } -static int cap_lsetxattr(vfs_handle_struct *handle, struct connection_struct *conn,const char *path, const char *name, const void *value, size_t size, int flags) +static int cap_lsetxattr(vfs_handle_struct *handle, const char *path, const char *name, const void *value, size_t size, int flags) { pstring cappath, capname; capencode(cappath, path); capencode(capname, name); - return SMB_VFS_NEXT_LSETXATTR(handle, conn, cappath, capname, value, size, flags); + return SMB_VFS_NEXT_LSETXATTR(handle, cappath, capname, value, size, flags); } static int cap_fsetxattr(vfs_handle_struct *handle, struct files_struct *fsp,int fd, const char *name, const void *value, size_t size, int flags) @@ -362,6 +362,7 @@ static vfs_op_tuple cap_op_tuples[] = { {NULL, SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} }; +NTSTATUS vfs_cap_init(void); NTSTATUS vfs_cap_init(void) { return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "cap", cap_op_tuples); diff --git a/source/modules/vfs_catia.c b/source/modules/vfs_catia.c index 69735de3f43..478dab6cbed 100644 --- a/source/modules/vfs_catia.c +++ b/source/modules/vfs_catia.c @@ -71,20 +71,20 @@ static void to_unix(char *s) catia_string_replace(s, '\xb1', ' '); } -static SMB_STRUCT_DIR *catia_opendir(vfs_handle_struct *handle, connection_struct - *conn, const char *fname, const char *mask, uint32 attr) +static SMB_STRUCT_DIR *catia_opendir(vfs_handle_struct *handle, + const char *fname, const char *mask, uint32 attr) { pstring name; pstrcpy(name, fname); to_unix(name); - return SMB_VFS_NEXT_OPENDIR(handle, conn, name, mask, attr); + return SMB_VFS_NEXT_OPENDIR(handle, name, mask, attr); } static SMB_STRUCT_DIRENT *catia_readdir(vfs_handle_struct *handle, - connection_struct *conn, SMB_STRUCT_DIR *dirp) + SMB_STRUCT_DIR *dirp) { - SMB_STRUCT_DIRENT *result = SMB_VFS_NEXT_READDIR(handle, conn, dirp); + SMB_STRUCT_DIRENT *result = SMB_VFS_NEXT_READDIR(handle, dirp); if (result == NULL) return result; @@ -93,18 +93,18 @@ static SMB_STRUCT_DIRENT *catia_readdir(vfs_handle_struct *handle, return result; } -static int catia_open(vfs_handle_struct *handle, connection_struct *conn, - const char *fname, int flags, mode_t mode) +static int catia_open(vfs_handle_struct *handle, + const char *fname, files_struct *fsp, int flags, mode_t mode) { pstring name; pstrcpy(name, fname); to_unix(name); - return SMB_VFS_NEXT_OPEN(handle, conn, name, flags, mode); + return SMB_VFS_NEXT_OPEN(handle, name, fsp, flags, mode); } -static int catia_rename(vfs_handle_struct *handle, connection_struct *conn, +static int catia_rename(vfs_handle_struct *handle, const char *oldname, const char *newname) { pstring oname, nname; @@ -117,114 +117,112 @@ static int catia_rename(vfs_handle_struct *handle, connection_struct *conn, DEBUG(10, ("converted old name: %s\n", oname)); DEBUG(10, ("converted new name: %s\n", nname)); - return SMB_VFS_NEXT_RENAME(handle, conn, oname, nname); + return SMB_VFS_NEXT_RENAME(handle, oname, nname); } -static int catia_stat(vfs_handle_struct *handle, connection_struct *conn, +static int catia_stat(vfs_handle_struct *handle, const char *fname, SMB_STRUCT_STAT *sbuf) { pstring name; pstrcpy(name, fname); to_unix(name); - return SMB_VFS_NEXT_STAT(handle, conn, name, sbuf); + return SMB_VFS_NEXT_STAT(handle, name, sbuf); } -static int catia_lstat(vfs_handle_struct *handle, connection_struct *conn, +static int catia_lstat(vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf) { pstring name; pstrcpy(name, path); to_unix(name); - return SMB_VFS_NEXT_LSTAT(handle, conn, name, sbuf); + return SMB_VFS_NEXT_LSTAT(handle, name, sbuf); } -static int catia_unlink(vfs_handle_struct *handle, connection_struct *conn, - const char *path) +static int catia_unlink(vfs_handle_struct *handle, const char *path) { pstring name; pstrcpy(name, path); to_unix(name); - return SMB_VFS_NEXT_UNLINK(handle, conn, name); + return SMB_VFS_NEXT_UNLINK(handle, name); } -static int catia_chmod(vfs_handle_struct *handle, connection_struct *conn, +static int catia_chmod(vfs_handle_struct *handle, const char *path, mode_t mode) { pstring name; pstrcpy(name, path); to_unix(name); - return SMB_VFS_NEXT_CHMOD(handle, conn, name, mode); + return SMB_VFS_NEXT_CHMOD(handle, name, mode); } -static int catia_chown(vfs_handle_struct *handle, connection_struct *conn, +static int catia_chown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid) { pstring name; pstrcpy(name, path); to_unix(name); - return SMB_VFS_NEXT_CHOWN(handle, conn, name, uid, gid); + return SMB_VFS_NEXT_CHOWN(handle, name, uid, gid); } -static int catia_chdir(vfs_handle_struct *handle, connection_struct *conn, +static int catia_chdir(vfs_handle_struct *handle, const char *path) { pstring name; pstrcpy(name, path); to_unix(name); - return SMB_VFS_NEXT_CHDIR(handle, conn, name); + return SMB_VFS_NEXT_CHDIR(handle, name); } -static char *catia_getwd(vfs_handle_struct *handle, connection_struct *conn, - char *buf) +static char *catia_getwd(vfs_handle_struct *handle, char *buf) { - return SMB_VFS_NEXT_GETWD(handle, conn, buf); + return SMB_VFS_NEXT_GETWD(handle, buf); } -static int catia_utime(vfs_handle_struct *handle, connection_struct *conn, +static int catia_utime(vfs_handle_struct *handle, const char *path, struct utimbuf *times) { - return SMB_VFS_NEXT_UTIME(handle, conn, path, times); + return SMB_VFS_NEXT_UTIME(handle, path, times); } -static BOOL catia_symlink(vfs_handle_struct *handle, connection_struct *conn, +static BOOL catia_symlink(vfs_handle_struct *handle, const char *oldpath, const char *newpath) { - return SMB_VFS_NEXT_SYMLINK(handle, conn, oldpath, newpath); + return SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath); } -static BOOL catia_readlink(vfs_handle_struct *handle, connection_struct *conn, +static BOOL catia_readlink(vfs_handle_struct *handle, const char *path, char *buf, size_t bufsiz) { - return SMB_VFS_NEXT_READLINK(handle, conn, path, buf, bufsiz); + return SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz); } -static int catia_link(vfs_handle_struct *handle, connection_struct *conn, +static int catia_link(vfs_handle_struct *handle, const char *oldpath, const char *newpath) { - return SMB_VFS_NEXT_LINK(handle, conn, oldpath, newpath); + return SMB_VFS_NEXT_LINK(handle, oldpath, newpath); } -static int catia_mknod(vfs_handle_struct *handle, connection_struct *conn, +static int catia_mknod(vfs_handle_struct *handle, const char *path, mode_t mode, SMB_DEV_T dev) { - return SMB_VFS_NEXT_MKNOD(handle, conn, path, mode, dev); + return SMB_VFS_NEXT_MKNOD(handle, path, mode, dev); } -static char *catia_realpath(vfs_handle_struct *handle, connection_struct *conn, +static char *catia_realpath(vfs_handle_struct *handle, const char *path, char *resolved_path) { - return SMB_VFS_NEXT_REALPATH(handle, conn, path, resolved_path); + return SMB_VFS_NEXT_REALPATH(handle, path, resolved_path); } static size_t catia_get_nt_acl(vfs_handle_struct *handle, files_struct *fsp, const char *name, uint32 security_info, - struct security_descriptor_info **ppdesc) + struct security_descriptor **ppdesc) { return SMB_VFS_NEXT_GET_NT_ACL(handle, fsp, name, security_info, ppdesc); @@ -232,13 +230,13 @@ static size_t catia_get_nt_acl(vfs_handle_struct *handle, files_struct *fsp, static BOOL catia_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, const char *name, uint32 security_info_sent, - struct security_descriptor_info *psd) + struct security_descriptor *psd) { return SMB_VFS_NEXT_SET_NT_ACL(handle, fsp, name, security_info_sent, psd); } -static int catia_chmod_acl(vfs_handle_struct *handle, connection_struct *conn, +static int catia_chmod_acl(vfs_handle_struct *handle, const char *name, mode_t mode) { /* If the underlying VFS doesn't have ACL support... */ @@ -246,7 +244,7 @@ static int catia_chmod_acl(vfs_handle_struct *handle, connection_struct *conn, errno = ENOSYS; return -1; } - return SMB_VFS_NEXT_CHMOD_ACL(handle, conn, name, mode); + return SMB_VFS_NEXT_CHMOD_ACL(handle, name, mode); } /* VFS operations structure */ @@ -310,7 +308,8 @@ SMB_VFS_LAYER_TRANSPARENT}, SMB_VFS_LAYER_NOOP} }; -NTSTATUS init_module(void) +NTSTATUS vfs_catia_init(void); +NTSTATUS vfs_catia_init(void) { return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "catia", catia_op_tuples); diff --git a/source/modules/vfs_commit.c b/source/modules/vfs_commit.c new file mode 100644 index 00000000000..4407490d223 --- /dev/null +++ b/source/modules/vfs_commit.c @@ -0,0 +1,190 @@ +/* + * Copyright (c) James Peach 2006 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +/* Commit data module. + * + * The purpose of this module is to flush data to disk at regular intervals, + * just like the NFS commit operation. There's two rationales for this. First, + * it minimises the data loss in case of a power outage without incurring + * the poor performance of synchronous I/O. Second, a steady flush rate + * can produce better throughput than suddenly dumping massive amounts of + * writes onto a disk. + * + * Tunables: + * + * commit: dthresh Amount of dirty data that can accumulate + * before we commit (sync) it. + * + * commit: debug Debug level at which to emit messages. + * + */ + +#define MODULE "commit" + +static int module_debug; + +struct commit_info +{ + SMB_OFF_T dbytes; /* Dirty (uncommitted) bytes */ + SMB_OFF_T dthresh; /* Dirty data threshold */ +}; + +static void commit_all( + struct vfs_handle_struct * handle, + files_struct * fsp) +{ + struct commit_info *c; + + if ((c = VFS_FETCH_FSP_EXTENSION(handle, fsp))) { + if (c->dbytes) { + DEBUG(module_debug, + ("%s: flushing %lu dirty bytes\n", + MODULE, (unsigned long)c->dbytes)); + + fdatasync(fsp->fh->fd); + c->dbytes = 0; + } + } +} + +static void commit( + struct vfs_handle_struct * handle, + files_struct * fsp, + ssize_t last_write) +{ + struct commit_info *c; + + if ((c = VFS_FETCH_FSP_EXTENSION(handle, fsp))) { + + if (last_write > 0) { + c->dbytes += last_write; + } + + if (c->dbytes > c->dthresh) { + DEBUG(module_debug, + ("%s: flushing %lu dirty bytes\n", + MODULE, (unsigned long)c->dbytes)); + + fdatasync(fsp->fh->fd); + c->dbytes = 0; + } + } +} + +static int commit_connect( + struct vfs_handle_struct * handle, + const char * service, + const char * user) +{ + module_debug = lp_parm_int(SNUM(handle->conn), MODULE, "debug", 100); + return SMB_VFS_NEXT_CONNECT(handle, service, user); +} + +static int commit_open( + vfs_handle_struct * handle, + const char * fname, + files_struct * fsp, + int flags, + mode_t mode) +{ + SMB_OFF_T dthresh; + + /* Don't bother with read-only files. */ + if ((flags & O_ACCMODE) == O_RDONLY) { + return SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode); + } + + dthresh = conv_str_size(lp_parm_const_string(SNUM(handle->conn), + MODULE, "dthresh", NULL)); + + if (dthresh > 0) { + struct commit_info * c; + c = VFS_ADD_FSP_EXTENSION(handle, fsp, struct commit_info); + if (c) { + c->dthresh = dthresh; + c->dbytes = 0; + } + } + + return SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode); +} + +static ssize_t commit_write( + vfs_handle_struct * handle, + files_struct * fsp, + int fd, + void * data, + size_t count) +{ + ssize_t ret; + + ret = SMB_VFS_NEXT_WRITE(handle, fsp, fd, data, count); + commit(handle, fsp, ret); + + return ret; +} + +static ssize_t commit_pwrite( + vfs_handle_struct * handle, + files_struct * fsp, + int fd, + void * data, + size_t count, + SMB_OFF_T offset) +{ + ssize_t ret; + + ret = SMB_VFS_NEXT_PWRITE(handle, fsp, fd, data, count, offset); + commit(handle, fsp, ret); + + return ret; +} + +static ssize_t commit_close( + vfs_handle_struct * handle, + files_struct * fsp, + int fd) +{ + commit_all(handle, fsp); + return SMB_VFS_NEXT_CLOSE(handle, fsp, fd); +} + +static vfs_op_tuple commit_ops [] = +{ + {SMB_VFS_OP(commit_open), + SMB_VFS_OP_OPEN, SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(commit_close), + SMB_VFS_OP_CLOSE, SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(commit_write), + SMB_VFS_OP_WRITE, SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(commit_pwrite), + SMB_VFS_OP_PWRITE, SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(commit_connect), + SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} +}; + +NTSTATUS vfs_commit_init(void); +NTSTATUS vfs_commit_init(void) +{ + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, MODULE, commit_ops); +} + diff --git a/source/modules/vfs_default.c b/source/modules/vfs_default.c new file mode 100644 index 00000000000..bd7bea5258a --- /dev/null +++ b/source/modules/vfs_default.c @@ -0,0 +1,1389 @@ +/* + Unix SMB/CIFS implementation. + Wrap disk only vfs functions to sidestep dodgy compilers. + Copyright (C) Tim Potter 1998 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_VFS + +/* Check for NULL pointer parameters in vfswrap_* functions */ + +/* We don't want to have NULL function pointers lying around. Someone + is sure to try and execute them. These stubs are used to prevent + this possibility. */ + +static int vfswrap_connect(vfs_handle_struct *handle, const char *service, const char *user) +{ + return 0; /* Return >= 0 for success */ +} + +static void vfswrap_disconnect(vfs_handle_struct *handle) +{ +} + +/* Disk operations */ + +static SMB_BIG_UINT vfswrap_disk_free(vfs_handle_struct *handle, const char *path, BOOL small_query, SMB_BIG_UINT *bsize, + SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) +{ + SMB_BIG_UINT result; + + result = sys_disk_free(handle->conn, path, small_query, bsize, dfree, dsize); + return result; +} + +static int vfswrap_get_quota(struct vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt) +{ +#ifdef HAVE_SYS_QUOTAS + int result; + + START_PROFILE(syscall_get_quota); + result = sys_get_quota(handle->conn->connectpath, qtype, id, qt); + END_PROFILE(syscall_get_quota); + return result; +#else + errno = ENOSYS; + return -1; +#endif +} + +static int vfswrap_set_quota(struct vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt) +{ +#ifdef HAVE_SYS_QUOTAS + int result; + + START_PROFILE(syscall_set_quota); + result = sys_set_quota(handle->conn->connectpath, qtype, id, qt); + END_PROFILE(syscall_set_quota); + return result; +#else + errno = ENOSYS; + return -1; +#endif +} + +static int vfswrap_get_shadow_copy_data(struct vfs_handle_struct *handle, struct files_struct *fsp, SHADOW_COPY_DATA *shadow_copy_data, BOOL labels) +{ + errno = ENOSYS; + return -1; /* Not implemented. */ +} + +static int vfswrap_statvfs(struct vfs_handle_struct *handle, const char *path, vfs_statvfs_struct *statbuf) +{ + return sys_statvfs(path, statbuf); +} + +/* Directory operations */ + +static SMB_STRUCT_DIR *vfswrap_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr) +{ + SMB_STRUCT_DIR *result; + + START_PROFILE(syscall_opendir); + result = sys_opendir(fname); + END_PROFILE(syscall_opendir); + return result; +} + +static SMB_STRUCT_DIRENT *vfswrap_readdir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp) +{ + SMB_STRUCT_DIRENT *result; + + START_PROFILE(syscall_readdir); + result = sys_readdir(dirp); + END_PROFILE(syscall_readdir); + return result; +} + +static void vfswrap_seekdir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp, long offset) +{ + START_PROFILE(syscall_seekdir); + sys_seekdir(dirp, offset); + END_PROFILE(syscall_seekdir); +} + +static long vfswrap_telldir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp) +{ + long result; + START_PROFILE(syscall_telldir); + result = sys_telldir(dirp); + END_PROFILE(syscall_telldir); + return result; +} + +static void vfswrap_rewinddir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp) +{ + START_PROFILE(syscall_rewinddir); + sys_rewinddir(dirp); + END_PROFILE(syscall_rewinddir); +} + +static int vfswrap_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode) +{ + int result; + BOOL has_dacl = False; + + START_PROFILE(syscall_mkdir); + + if (lp_inherit_acls(SNUM(handle->conn)) && (has_dacl = directory_has_default_acl(handle->conn, parent_dirname(path)))) + mode = 0777; + + result = mkdir(path, mode); + + if (result == 0 && !has_dacl) { + /* + * We need to do this as the default behavior of POSIX ACLs + * is to set the mask to be the requested group permission + * bits, not the group permission bits to be the requested + * group permission bits. This is not what we want, as it will + * mess up any inherited ACL bits that were set. JRA. + */ + int saved_errno = errno; /* We may get ENOSYS */ + if ((SMB_VFS_CHMOD_ACL(handle->conn, path, mode) == -1) && (errno == ENOSYS)) + errno = saved_errno; + } + + END_PROFILE(syscall_mkdir); + return result; +} + +static int vfswrap_rmdir(vfs_handle_struct *handle, const char *path) +{ + int result; + + START_PROFILE(syscall_rmdir); + result = rmdir(path); + END_PROFILE(syscall_rmdir); + return result; +} + +static int vfswrap_closedir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp) +{ + int result; + + START_PROFILE(syscall_closedir); + result = sys_closedir(dirp); + END_PROFILE(syscall_closedir); + return result; +} + +/* File operations */ + +static int vfswrap_open(vfs_handle_struct *handle, const char *fname, + files_struct *fsp, int flags, mode_t mode) +{ + int result; + + START_PROFILE(syscall_open); + result = sys_open(fname, flags, mode); + END_PROFILE(syscall_open); + return result; +} + +static int vfswrap_close(vfs_handle_struct *handle, files_struct *fsp, int fd) +{ + int result; + + START_PROFILE(syscall_close); + + result = close(fd); + END_PROFILE(syscall_close); + return result; +} + +static ssize_t vfswrap_read(vfs_handle_struct *handle, files_struct *fsp, int fd, void *data, size_t n) +{ + ssize_t result; + + START_PROFILE_BYTES(syscall_read, n); + result = sys_read(fd, data, n); + END_PROFILE(syscall_read); + return result; +} + +static ssize_t vfswrap_pread(vfs_handle_struct *handle, files_struct *fsp, int fd, void *data, + size_t n, SMB_OFF_T offset) +{ + ssize_t result; + +#if defined(HAVE_PREAD) || defined(HAVE_PREAD64) + START_PROFILE_BYTES(syscall_pread, n); + result = sys_pread(fd, data, n, offset); + END_PROFILE(syscall_pread); + + if (result == -1 && errno == ESPIPE) { + /* Maintain the fiction that pipes can be seeked (sought?) on. */ + result = SMB_VFS_READ(fsp, fd, data, n); + fsp->fh->pos = 0; + } + +#else /* HAVE_PREAD */ + SMB_OFF_T curr; + int lerrno; + + curr = SMB_VFS_LSEEK(fsp, fd, 0, SEEK_CUR); + if (curr == -1 && errno == ESPIPE) { + /* Maintain the fiction that pipes can be seeked (sought?) on. */ + result = SMB_VFS_READ(fsp, fd, data, n); + fsp->fh->pos = 0; + return result; + } + + if (SMB_VFS_LSEEK(fsp, fd, offset, SEEK_SET) == -1) { + return -1; + } + + errno = 0; + result = SMB_VFS_READ(fsp, fd, data, n); + lerrno = errno; + + SMB_VFS_LSEEK(fsp, fd, curr, SEEK_SET); + errno = lerrno; + +#endif /* HAVE_PREAD */ + + return result; +} + +static ssize_t vfswrap_write(vfs_handle_struct *handle, files_struct *fsp, int fd, const void *data, size_t n) +{ + ssize_t result; + + START_PROFILE_BYTES(syscall_write, n); + result = sys_write(fd, data, n); + END_PROFILE(syscall_write); + return result; +} + +static ssize_t vfswrap_pwrite(vfs_handle_struct *handle, files_struct *fsp, int fd, const void *data, + size_t n, SMB_OFF_T offset) +{ + ssize_t result; + +#if defined(HAVE_PWRITE) || defined(HAVE_PRWITE64) + START_PROFILE_BYTES(syscall_pwrite, n); + result = sys_pwrite(fd, data, n, offset); + END_PROFILE(syscall_pwrite); + + if (result == -1 && errno == ESPIPE) { + /* Maintain the fiction that pipes can be sought on. */ + result = SMB_VFS_WRITE(fsp, fd, data, n); + } + +#else /* HAVE_PWRITE */ + SMB_OFF_T curr; + int lerrno; + + curr = SMB_VFS_LSEEK(fsp, fd, 0, SEEK_CUR); + if (curr == -1) { + return -1; + } + + if (SMB_VFS_LSEEK(fsp, fd, offset, SEEK_SET) == -1) { + return -1; + } + + result = SMB_VFS_WRITE(fsp, fd, data, n); + lerrno = errno; + + SMB_VFS_LSEEK(fsp, fd, curr, SEEK_SET); + errno = lerrno; + +#endif /* HAVE_PWRITE */ + + return result; +} + +static SMB_OFF_T vfswrap_lseek(vfs_handle_struct *handle, files_struct *fsp, int filedes, SMB_OFF_T offset, int whence) +{ + SMB_OFF_T result = 0; + + START_PROFILE(syscall_lseek); + + /* Cope with 'stat' file opens. */ + if (filedes != -1) + result = sys_lseek(filedes, offset, whence); + + /* + * We want to maintain the fiction that we can seek + * on a fifo for file system purposes. This allows + * people to set up UNIX fifo's that feed data to Windows + * applications. JRA. + */ + + if((result == -1) && (errno == ESPIPE)) { + result = 0; + errno = 0; + } + + END_PROFILE(syscall_lseek); + return result; +} + +static ssize_t vfswrap_sendfile(vfs_handle_struct *handle, int tofd, files_struct *fsp, int fromfd, const DATA_BLOB *hdr, + SMB_OFF_T offset, size_t n) +{ + ssize_t result; + + START_PROFILE_BYTES(syscall_sendfile, n); + result = sys_sendfile(tofd, fromfd, hdr, offset, n); + END_PROFILE(syscall_sendfile); + return result; +} + +/********************************************************* + For rename across filesystems Patch from Warren Birnbaum + <warrenb@hpcvscdp.cv.hp.com> +**********************************************************/ + +static int copy_reg(const char *source, const char *dest) +{ + SMB_STRUCT_STAT source_stats; + int saved_errno; + int ifd = -1; + int ofd = -1; + + if (sys_lstat (source, &source_stats) == -1) + return -1; + + if (!S_ISREG (source_stats.st_mode)) + return -1; + + if((ifd = sys_open (source, O_RDONLY, 0)) < 0) + return -1; + + if (unlink (dest) && errno != ENOENT) + return -1; + +#ifdef O_NOFOLLOW + if((ofd = sys_open (dest, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, 0600)) < 0 ) +#else + if((ofd = sys_open (dest, O_WRONLY | O_CREAT | O_TRUNC , 0600)) < 0 ) +#endif + goto err; + + if (transfer_file(ifd, ofd, (size_t)-1) == -1) + goto err; + + /* + * Try to preserve ownership. For non-root it might fail, but that's ok. + * But root probably wants to know, e.g. if NFS disallows it. + */ + +#ifdef HAVE_FCHOWN + if ((fchown(ofd, source_stats.st_uid, source_stats.st_gid) == -1) && (errno != EPERM)) +#else + if ((chown(dest, source_stats.st_uid, source_stats.st_gid) == -1) && (errno != EPERM)) +#endif + goto err; + + /* + * fchown turns off set[ug]id bits for non-root, + * so do the chmod last. + */ + +#if defined(HAVE_FCHMOD) + if (fchmod (ofd, source_stats.st_mode & 07777)) +#else + if (chmod (dest, source_stats.st_mode & 07777)) +#endif + goto err; + + if (close (ifd) == -1) + goto err; + + if (close (ofd) == -1) + return -1; + + /* Try to copy the old file's modtime and access time. */ + { + struct utimbuf tv; + + tv.actime = source_stats.st_atime; + tv.modtime = source_stats.st_mtime; + utime(dest, &tv); + } + + if (unlink (source) == -1) + return -1; + + return 0; + + err: + + saved_errno = errno; + if (ifd != -1) + close(ifd); + if (ofd != -1) + close(ofd); + errno = saved_errno; + return -1; +} + +static int vfswrap_rename(vfs_handle_struct *handle, const char *oldname, const char *newname) +{ + int result; + + START_PROFILE(syscall_rename); + result = rename(oldname, newname); + if (errno == EXDEV) { + /* Rename across filesystems needed. */ + result = copy_reg(oldname, newname); + } + + END_PROFILE(syscall_rename); + return result; +} + +static int vfswrap_fsync(vfs_handle_struct *handle, files_struct *fsp, int fd) +{ +#ifdef HAVE_FSYNC + int result; + + START_PROFILE(syscall_fsync); + result = fsync(fd); + END_PROFILE(syscall_fsync); + return result; +#else + return 0; +#endif +} + +static int vfswrap_stat(vfs_handle_struct *handle, const char *fname, SMB_STRUCT_STAT *sbuf) +{ + int result; + + START_PROFILE(syscall_stat); + result = sys_stat(fname, sbuf); + END_PROFILE(syscall_stat); + return result; +} + +static int vfswrap_fstat(vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_STRUCT_STAT *sbuf) +{ + int result; + + START_PROFILE(syscall_fstat); + result = sys_fstat(fd, sbuf); + END_PROFILE(syscall_fstat); + return result; +} + +int vfswrap_lstat(vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf) +{ + int result; + + START_PROFILE(syscall_lstat); + result = sys_lstat(path, sbuf); + END_PROFILE(syscall_lstat); + return result; +} + +static int vfswrap_unlink(vfs_handle_struct *handle, const char *path) +{ + int result; + + START_PROFILE(syscall_unlink); + result = unlink(path); + END_PROFILE(syscall_unlink); + return result; +} + +static int vfswrap_chmod(vfs_handle_struct *handle, const char *path, mode_t mode) +{ + int result; + + START_PROFILE(syscall_chmod); + + /* + * We need to do this due to the fact that the default POSIX ACL + * chmod modifies the ACL *mask* for the group owner, not the + * group owner bits directly. JRA. + */ + + + { + int saved_errno = errno; /* We might get ENOSYS */ + if ((result = SMB_VFS_CHMOD_ACL(handle->conn, path, mode)) == 0) { + END_PROFILE(syscall_chmod); + return result; + } + /* Error - return the old errno. */ + errno = saved_errno; + } + + result = chmod(path, mode); + END_PROFILE(syscall_chmod); + return result; +} + +static int vfswrap_fchmod(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode) +{ + int result; + + START_PROFILE(syscall_fchmod); + + /* + * We need to do this due to the fact that the default POSIX ACL + * chmod modifies the ACL *mask* for the group owner, not the + * group owner bits directly. JRA. + */ + + { + int saved_errno = errno; /* We might get ENOSYS */ + if ((result = SMB_VFS_FCHMOD_ACL(fsp, fd, mode)) == 0) { + END_PROFILE(syscall_fchmod); + return result; + } + /* Error - return the old errno. */ + errno = saved_errno; + } + +#if defined(HAVE_FCHMOD) + result = fchmod(fd, mode); +#else + result = -1; + errno = ENOSYS; +#endif + + END_PROFILE(syscall_fchmod); + return result; +} + +static int vfswrap_chown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid) +{ + int result; + + START_PROFILE(syscall_chown); + result = sys_chown(path, uid, gid); + END_PROFILE(syscall_chown); + return result; +} + +static int vfswrap_fchown(vfs_handle_struct *handle, files_struct *fsp, int fd, uid_t uid, gid_t gid) +{ +#ifdef HAVE_FCHOWN + int result; + + START_PROFILE(syscall_fchown); + result = fchown(fd, uid, gid); + END_PROFILE(syscall_fchown); + return result; +#else + errno = ENOSYS; + return -1; +#endif +} + +static int vfswrap_chdir(vfs_handle_struct *handle, const char *path) +{ + int result; + + START_PROFILE(syscall_chdir); + result = chdir(path); + END_PROFILE(syscall_chdir); + return result; +} + +static char *vfswrap_getwd(vfs_handle_struct *handle, char *path) +{ + char *result; + + START_PROFILE(syscall_getwd); + result = sys_getwd(path); + END_PROFILE(syscall_getwd); + return result; +} + +static int vfswrap_utime(vfs_handle_struct *handle, const char *path, struct utimbuf *times) +{ + int result; + + START_PROFILE(syscall_utime); + result = utime(path, times); + END_PROFILE(syscall_utime); + return result; +} + +/********************************************************************* + A version of ftruncate that will write the space on disk if strict + allocate is set. +**********************************************************************/ + +static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_OFF_T len) +{ + SMB_STRUCT_STAT st; + SMB_OFF_T currpos = SMB_VFS_LSEEK(fsp, fd, 0, SEEK_CUR); + unsigned char zero_space[4096]; + SMB_OFF_T space_to_write; + + if (currpos == -1) + return -1; + + if (SMB_VFS_FSTAT(fsp, fd, &st) == -1) + return -1; + + space_to_write = len - st.st_size; + +#ifdef S_ISFIFO + if (S_ISFIFO(st.st_mode)) + return 0; +#endif + + if (st.st_size == len) + return 0; + + /* Shrink - just ftruncate. */ + if (st.st_size > len) + return sys_ftruncate(fd, len); + + /* Write out the real space on disk. */ + if (SMB_VFS_LSEEK(fsp, fd, st.st_size, SEEK_SET) != st.st_size) + return -1; + + space_to_write = len - st.st_size; + + memset(zero_space, '\0', sizeof(zero_space)); + while ( space_to_write > 0) { + SMB_OFF_T retlen; + SMB_OFF_T current_len_to_write = MIN(sizeof(zero_space),space_to_write); + + retlen = SMB_VFS_WRITE(fsp,fsp->fh->fd,(char *)zero_space,current_len_to_write); + if (retlen <= 0) + return -1; + + space_to_write -= retlen; + } + + /* Seek to where we were */ + if (SMB_VFS_LSEEK(fsp, fd, currpos, SEEK_SET) != currpos) + return -1; + + return 0; +} + +static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_OFF_T len) +{ + int result = -1; + SMB_STRUCT_STAT st; + char c = 0; + SMB_OFF_T currpos; + + START_PROFILE(syscall_ftruncate); + + if (lp_strict_allocate(SNUM(fsp->conn))) { + result = strict_allocate_ftruncate(handle, fsp, fd, len); + END_PROFILE(syscall_ftruncate); + return result; + } + + /* we used to just check HAVE_FTRUNCATE_EXTEND and only use + sys_ftruncate if the system supports it. Then I discovered that + you can have some filesystems that support ftruncate + expansion and some that don't! On Linux fat can't do + ftruncate extend but ext2 can. */ + + result = sys_ftruncate(fd, len); + if (result == 0) + goto done; + + /* According to W. R. Stevens advanced UNIX prog. Pure 4.3 BSD cannot + extend a file with ftruncate. Provide alternate implementation + for this */ + currpos = SMB_VFS_LSEEK(fsp, fd, 0, SEEK_CUR); + if (currpos == -1) { + goto done; + } + + /* Do an fstat to see if the file is longer than the requested + size in which case the ftruncate above should have + succeeded or shorter, in which case seek to len - 1 and + write 1 byte of zero */ + if (SMB_VFS_FSTAT(fsp, fd, &st) == -1) { + goto done; + } + +#ifdef S_ISFIFO + if (S_ISFIFO(st.st_mode)) { + result = 0; + goto done; + } +#endif + + if (st.st_size == len) { + result = 0; + goto done; + } + + if (st.st_size > len) { + /* the sys_ftruncate should have worked */ + goto done; + } + + if (SMB_VFS_LSEEK(fsp, fd, len-1, SEEK_SET) != len -1) + goto done; + + if (SMB_VFS_WRITE(fsp, fd, &c, 1)!=1) + goto done; + + /* Seek to where we were */ + if (SMB_VFS_LSEEK(fsp, fd, currpos, SEEK_SET) != currpos) + goto done; + result = 0; + + done: + + END_PROFILE(syscall_ftruncate); + return result; +} + +static BOOL vfswrap_lock(vfs_handle_struct *handle, files_struct *fsp, int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type) +{ + BOOL result; + + START_PROFILE(syscall_fcntl_lock); + result = fcntl_lock(fd, op, offset, count, type); + END_PROFILE(syscall_fcntl_lock); + return result; +} + +static int vfswrap_kernel_flock(vfs_handle_struct *handle, files_struct *fsp, int fd, + uint32 share_mode) +{ + START_PROFILE(syscall_kernel_flock); + kernel_flock(fd, share_mode); + END_PROFILE(syscall_kernel_flock); + return 0; +} + +static BOOL vfswrap_getlock(vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid) +{ + BOOL result; + + START_PROFILE(syscall_fcntl_getlock); + result = fcntl_getlock(fd, poffset, pcount, ptype, ppid); + END_PROFILE(syscall_fcntl_getlock); + return result; +} + +static int vfswrap_linux_setlease(vfs_handle_struct *handle, files_struct *fsp, int fd, + int leasetype) +{ + int result; + + START_PROFILE(syscall_linux_setlease); + +#ifdef LINUX + /* first set the signal handler */ + if(linux_set_lease_sighandler(fd) == -1) + return -1; + + result = linux_setlease(fd, leasetype); + +#endif + END_PROFILE(syscall_linux_setlease); + return result; +} + +static int vfswrap_symlink(vfs_handle_struct *handle, const char *oldpath, const char *newpath) +{ + int result; + + START_PROFILE(syscall_symlink); + result = sys_symlink(oldpath, newpath); + END_PROFILE(syscall_symlink); + return result; +} + +static int vfswrap_readlink(vfs_handle_struct *handle, const char *path, char *buf, size_t bufsiz) +{ + int result; + + START_PROFILE(syscall_readlink); + result = sys_readlink(path, buf, bufsiz); + END_PROFILE(syscall_readlink); + return result; +} + +static int vfswrap_link(vfs_handle_struct *handle, const char *oldpath, const char *newpath) +{ + int result; + + START_PROFILE(syscall_link); + result = sys_link(oldpath, newpath); + END_PROFILE(syscall_link); + return result; +} + +static int vfswrap_mknod(vfs_handle_struct *handle, const char *pathname, mode_t mode, SMB_DEV_T dev) +{ + int result; + + START_PROFILE(syscall_mknod); + result = sys_mknod(pathname, mode, dev); + END_PROFILE(syscall_mknod); + return result; +} + +static char *vfswrap_realpath(vfs_handle_struct *handle, const char *path, char *resolved_path) +{ + char *result; + + START_PROFILE(syscall_realpath); + result = sys_realpath(path, resolved_path); + END_PROFILE(syscall_realpath); + return result; +} + +static NTSTATUS vfswrap_notify_watch(vfs_handle_struct *vfs_handle, + struct sys_notify_context *ctx, + struct notify_entry *e, + void (*callback)(struct sys_notify_context *ctx, + void *private_data, + struct notify_event *ev), + void *private_data, void *handle) +{ + /* + * So far inotify is the only supported default notify mechanism. If + * another platform like the the BSD's or a proprietary Unix comes + * along and wants another default, we can play the same trick we + * played with Posix ACLs. + * + * Until that is the case, hard-code inotify here. + */ +#ifdef HAVE_INOTIFY + if (lp_kernel_change_notify(ctx->conn->params)) { + return inotify_watch(ctx, e, callback, private_data, handle); + } +#endif + /* + * Do nothing, leave everything to notify_internal.c + */ + return NT_STATUS_OK; +} + +static size_t vfswrap_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp, int fd, uint32 security_info, SEC_DESC **ppdesc) +{ + size_t result; + + START_PROFILE(fget_nt_acl); + result = get_nt_acl(fsp, security_info, ppdesc); + END_PROFILE(fget_nt_acl); + return result; +} + +static size_t vfswrap_get_nt_acl(vfs_handle_struct *handle, files_struct *fsp, const char *name, uint32 security_info, SEC_DESC **ppdesc) +{ + size_t result; + + START_PROFILE(get_nt_acl); + result = get_nt_acl(fsp, security_info, ppdesc); + END_PROFILE(get_nt_acl); + return result; +} + +static BOOL vfswrap_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, int fd, uint32 security_info_sent, SEC_DESC *psd) +{ + BOOL result; + + START_PROFILE(fset_nt_acl); + result = set_nt_acl(fsp, security_info_sent, psd); + END_PROFILE(fset_nt_acl); + return result; +} + +static BOOL vfswrap_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, const char *name, uint32 security_info_sent, SEC_DESC *psd) +{ + BOOL result; + + START_PROFILE(set_nt_acl); + result = set_nt_acl(fsp, security_info_sent, psd); + END_PROFILE(set_nt_acl); + return result; +} + +static int vfswrap_chmod_acl(vfs_handle_struct *handle, const char *name, mode_t mode) +{ +#ifdef HAVE_NO_ACL + errno = ENOSYS; + return -1; +#else + int result; + + START_PROFILE(chmod_acl); + result = chmod_acl(handle->conn, name, mode); + END_PROFILE(chmod_acl); + return result; +#endif +} + +static int vfswrap_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode) +{ +#ifdef HAVE_NO_ACL + errno = ENOSYS; + return -1; +#else + int result; + + START_PROFILE(fchmod_acl); + result = fchmod_acl(fsp, fd, mode); + END_PROFILE(fchmod_acl); + return result; +#endif +} + +static int vfswrap_sys_acl_get_entry(vfs_handle_struct *handle, SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p) +{ + return sys_acl_get_entry(theacl, entry_id, entry_p); +} + +static int vfswrap_sys_acl_get_tag_type(vfs_handle_struct *handle, SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) +{ + return sys_acl_get_tag_type(entry_d, tag_type_p); +} + +static int vfswrap_sys_acl_get_permset(vfs_handle_struct *handle, SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) +{ + return sys_acl_get_permset(entry_d, permset_p); +} + +static void * vfswrap_sys_acl_get_qualifier(vfs_handle_struct *handle, SMB_ACL_ENTRY_T entry_d) +{ + return sys_acl_get_qualifier(entry_d); +} + +static SMB_ACL_T vfswrap_sys_acl_get_file(vfs_handle_struct *handle, const char *path_p, SMB_ACL_TYPE_T type) +{ + return sys_acl_get_file(handle, path_p, type); +} + +static SMB_ACL_T vfswrap_sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp, int fd) +{ + return sys_acl_get_fd(handle, fsp, fd); +} + +static int vfswrap_sys_acl_clear_perms(vfs_handle_struct *handle, SMB_ACL_PERMSET_T permset) +{ + return sys_acl_clear_perms(permset); +} + +static int vfswrap_sys_acl_add_perm(vfs_handle_struct *handle, SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) +{ + return sys_acl_add_perm(permset, perm); +} + +static char * vfswrap_sys_acl_to_text(vfs_handle_struct *handle, SMB_ACL_T theacl, ssize_t *plen) +{ + return sys_acl_to_text(theacl, plen); +} + +static SMB_ACL_T vfswrap_sys_acl_init(vfs_handle_struct *handle, int count) +{ + return sys_acl_init(count); +} + +static int vfswrap_sys_acl_create_entry(vfs_handle_struct *handle, SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) +{ + return sys_acl_create_entry(pacl, pentry); +} + +static int vfswrap_sys_acl_set_tag_type(vfs_handle_struct *handle, SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) +{ + return sys_acl_set_tag_type(entry, tagtype); +} + +static int vfswrap_sys_acl_set_qualifier(vfs_handle_struct *handle, SMB_ACL_ENTRY_T entry, void *qual) +{ + return sys_acl_set_qualifier(entry, qual); +} + +static int vfswrap_sys_acl_set_permset(vfs_handle_struct *handle, SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) +{ + return sys_acl_set_permset(entry, permset); +} + +static int vfswrap_sys_acl_valid(vfs_handle_struct *handle, SMB_ACL_T theacl ) +{ + return sys_acl_valid(theacl ); +} + +static int vfswrap_sys_acl_set_file(vfs_handle_struct *handle, const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) +{ + return sys_acl_set_file(handle, name, acltype, theacl); +} + +static int vfswrap_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_ACL_T theacl) +{ + return sys_acl_set_fd(handle, fsp, fd, theacl); +} + +static int vfswrap_sys_acl_delete_def_file(vfs_handle_struct *handle, const char *path) +{ + return sys_acl_delete_def_file(handle, path); +} + +static int vfswrap_sys_acl_get_perm(vfs_handle_struct *handle, SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) +{ + return sys_acl_get_perm(permset, perm); +} + +static int vfswrap_sys_acl_free_text(vfs_handle_struct *handle, char *text) +{ + return sys_acl_free_text(text); +} + +static int vfswrap_sys_acl_free_acl(vfs_handle_struct *handle, SMB_ACL_T posix_acl) +{ + return sys_acl_free_acl(posix_acl); +} + +static int vfswrap_sys_acl_free_qualifier(vfs_handle_struct *handle, void *qualifier, SMB_ACL_TAG_T tagtype) +{ + return sys_acl_free_qualifier(qualifier, tagtype); +} + +/**************************************************************** + Extended attribute operations. +*****************************************************************/ + +static ssize_t vfswrap_getxattr(struct vfs_handle_struct *handle,const char *path, const char *name, void *value, size_t size) +{ + return sys_getxattr(path, name, value, size); +} + +static ssize_t vfswrap_lgetxattr(struct vfs_handle_struct *handle,const char *path, const char *name, void *value, size_t size) +{ + return sys_lgetxattr(path, name, value, size); +} + +static ssize_t vfswrap_fgetxattr(struct vfs_handle_struct *handle, struct files_struct *fsp,int fd, const char *name, void *value, size_t size) +{ + return sys_fgetxattr(fd, name, value, size); +} + +static ssize_t vfswrap_listxattr(struct vfs_handle_struct *handle, const char *path, char *list, size_t size) +{ + return sys_listxattr(path, list, size); +} + +ssize_t vfswrap_llistxattr(struct vfs_handle_struct *handle, const char *path, char *list, size_t size) +{ + return sys_llistxattr(path, list, size); +} + +ssize_t vfswrap_flistxattr(struct vfs_handle_struct *handle, struct files_struct *fsp,int fd, char *list, size_t size) +{ + return sys_flistxattr(fd, list, size); +} + +static int vfswrap_removexattr(struct vfs_handle_struct *handle, const char *path, const char *name) +{ + return sys_removexattr(path, name); +} + +static int vfswrap_lremovexattr(struct vfs_handle_struct *handle, const char *path, const char *name) +{ + return sys_lremovexattr(path, name); +} + +static int vfswrap_fremovexattr(struct vfs_handle_struct *handle, struct files_struct *fsp,int fd, const char *name) +{ + return sys_fremovexattr(fd, name); +} + +static int vfswrap_setxattr(struct vfs_handle_struct *handle, const char *path, const char *name, const void *value, size_t size, int flags) +{ + return sys_setxattr(path, name, value, size, flags); +} + +static int vfswrap_lsetxattr(struct vfs_handle_struct *handle, const char *path, const char *name, const void *value, size_t size, int flags) +{ + return sys_lsetxattr(path, name, value, size, flags); +} + +static int vfswrap_fsetxattr(struct vfs_handle_struct *handle, struct files_struct *fsp,int fd, const char *name, const void *value, size_t size, int flags) +{ + return sys_fsetxattr(fd, name, value, size, flags); +} + +static int vfswrap_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb) +{ + return sys_aio_read(aiocb); +} + +static int vfswrap_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb) +{ + return sys_aio_write(aiocb); +} + +static ssize_t vfswrap_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb) +{ + return sys_aio_return(aiocb); +} + +static int vfswrap_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, int fd, SMB_STRUCT_AIOCB *aiocb) +{ + return sys_aio_cancel(fd, aiocb); +} + +static int vfswrap_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb) +{ + return sys_aio_error(aiocb); +} + +static int vfswrap_aio_fsync(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, SMB_STRUCT_AIOCB *aiocb) +{ + return sys_aio_fsync(op, aiocb); +} + +static int vfswrap_aio_suspend(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_AIOCB * const aiocb[], int n, const struct timespec *timeout) +{ + return sys_aio_suspend(aiocb, n, timeout); +} + +static vfs_op_tuple vfs_default_ops[] = { + + /* Disk operations */ + + {SMB_VFS_OP(vfswrap_connect), SMB_VFS_OP_CONNECT, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_disconnect), SMB_VFS_OP_DISCONNECT, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_disk_free), SMB_VFS_OP_DISK_FREE, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_get_quota), SMB_VFS_OP_GET_QUOTA, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_set_quota), SMB_VFS_OP_SET_QUOTA, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_get_shadow_copy_data), SMB_VFS_OP_GET_SHADOW_COPY_DATA, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_statvfs), SMB_VFS_OP_STATVFS, + SMB_VFS_LAYER_OPAQUE}, + + /* Directory operations */ + + {SMB_VFS_OP(vfswrap_opendir), SMB_VFS_OP_OPENDIR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_readdir), SMB_VFS_OP_READDIR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_seekdir), SMB_VFS_OP_SEEKDIR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_telldir), SMB_VFS_OP_TELLDIR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_rewinddir), SMB_VFS_OP_REWINDDIR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_mkdir), SMB_VFS_OP_MKDIR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_rmdir), SMB_VFS_OP_RMDIR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_closedir), SMB_VFS_OP_CLOSEDIR, + SMB_VFS_LAYER_OPAQUE}, + + /* File operations */ + + {SMB_VFS_OP(vfswrap_open), SMB_VFS_OP_OPEN, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_close), SMB_VFS_OP_CLOSE, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_read), SMB_VFS_OP_READ, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_pread), SMB_VFS_OP_PREAD, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_write), SMB_VFS_OP_WRITE, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_pwrite), SMB_VFS_OP_PWRITE, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_lseek), SMB_VFS_OP_LSEEK, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sendfile), SMB_VFS_OP_SENDFILE, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_rename), SMB_VFS_OP_RENAME, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_fsync), SMB_VFS_OP_FSYNC, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_stat), SMB_VFS_OP_STAT, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_fstat), SMB_VFS_OP_FSTAT, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_lstat), SMB_VFS_OP_LSTAT, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_unlink), SMB_VFS_OP_UNLINK, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_chmod), SMB_VFS_OP_CHMOD, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_fchmod), SMB_VFS_OP_FCHMOD, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_chown), SMB_VFS_OP_CHOWN, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_fchown), SMB_VFS_OP_FCHOWN, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_chdir), SMB_VFS_OP_CHDIR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_getwd), SMB_VFS_OP_GETWD, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_utime), SMB_VFS_OP_UTIME, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_ftruncate), SMB_VFS_OP_FTRUNCATE, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_lock), SMB_VFS_OP_LOCK, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_kernel_flock), SMB_VFS_OP_KERNEL_FLOCK, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_linux_setlease), SMB_VFS_OP_LINUX_SETLEASE, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_getlock), SMB_VFS_OP_GETLOCK, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_symlink), SMB_VFS_OP_SYMLINK, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_readlink), SMB_VFS_OP_READLINK, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_link), SMB_VFS_OP_LINK, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_mknod), SMB_VFS_OP_MKNOD, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_realpath), SMB_VFS_OP_REALPATH, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_notify_watch), SMB_VFS_OP_NOTIFY_WATCH, + SMB_VFS_LAYER_OPAQUE}, + + /* NT ACL operations. */ + + {SMB_VFS_OP(vfswrap_fget_nt_acl), SMB_VFS_OP_FGET_NT_ACL, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_get_nt_acl), SMB_VFS_OP_GET_NT_ACL, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_fset_nt_acl), SMB_VFS_OP_FSET_NT_ACL, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_set_nt_acl), SMB_VFS_OP_SET_NT_ACL, + SMB_VFS_LAYER_OPAQUE}, + + /* POSIX ACL operations. */ + + {SMB_VFS_OP(vfswrap_chmod_acl), SMB_VFS_OP_CHMOD_ACL, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_fchmod_acl), SMB_VFS_OP_FCHMOD_ACL, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_get_entry), SMB_VFS_OP_SYS_ACL_GET_ENTRY, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_get_tag_type), SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_get_permset), SMB_VFS_OP_SYS_ACL_GET_PERMSET, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_get_qualifier), SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_get_file), SMB_VFS_OP_SYS_ACL_GET_FILE, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_get_fd), SMB_VFS_OP_SYS_ACL_GET_FD, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_clear_perms), SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_add_perm), SMB_VFS_OP_SYS_ACL_ADD_PERM, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_to_text), SMB_VFS_OP_SYS_ACL_TO_TEXT, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_init), SMB_VFS_OP_SYS_ACL_INIT, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_create_entry), SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_set_tag_type), SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_set_qualifier), SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_set_permset), SMB_VFS_OP_SYS_ACL_SET_PERMSET, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_valid), SMB_VFS_OP_SYS_ACL_VALID, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_set_file), SMB_VFS_OP_SYS_ACL_SET_FILE, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_set_fd), SMB_VFS_OP_SYS_ACL_SET_FD, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_delete_def_file), SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_get_perm), SMB_VFS_OP_SYS_ACL_GET_PERM, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_free_text), SMB_VFS_OP_SYS_ACL_FREE_TEXT, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_free_acl), SMB_VFS_OP_SYS_ACL_FREE_ACL, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_sys_acl_free_qualifier), SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, + SMB_VFS_LAYER_OPAQUE}, + + /* EA operations. */ + + {SMB_VFS_OP(vfswrap_getxattr), SMB_VFS_OP_GETXATTR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_lgetxattr), SMB_VFS_OP_LGETXATTR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_fgetxattr), SMB_VFS_OP_FGETXATTR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_listxattr), SMB_VFS_OP_LISTXATTR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_llistxattr), SMB_VFS_OP_LLISTXATTR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_flistxattr), SMB_VFS_OP_FLISTXATTR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_removexattr), SMB_VFS_OP_REMOVEXATTR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_lremovexattr), SMB_VFS_OP_LREMOVEXATTR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_fremovexattr), SMB_VFS_OP_FREMOVEXATTR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_setxattr), SMB_VFS_OP_SETXATTR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_lsetxattr), SMB_VFS_OP_LSETXATTR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_fsetxattr), SMB_VFS_OP_FSETXATTR, + SMB_VFS_LAYER_OPAQUE}, + + {SMB_VFS_OP(vfswrap_aio_read), SMB_VFS_OP_AIO_READ, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_aio_write), SMB_VFS_OP_AIO_WRITE, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_aio_return), SMB_VFS_OP_AIO_RETURN, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_aio_cancel), SMB_VFS_OP_AIO_CANCEL, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_aio_error), SMB_VFS_OP_AIO_ERROR, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_aio_fsync), SMB_VFS_OP_AIO_FSYNC, + SMB_VFS_LAYER_OPAQUE}, + {SMB_VFS_OP(vfswrap_aio_suspend),SMB_VFS_OP_AIO_SUSPEND, + SMB_VFS_LAYER_OPAQUE}, + + /* Finish VFS operations definition */ + + {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, + SMB_VFS_LAYER_NOOP} +}; + +NTSTATUS vfs_default_init(void); +NTSTATUS vfs_default_init(void) +{ + unsigned int needed = SMB_VFS_OP_LAST + 1; /* convert from index to count */ + + if (ARRAY_SIZE(vfs_default_ops) != needed) { + DEBUG(0, ("%s: %u ops registered, but %u ops are required\n", + DEFAULT_VFS_MODULE_NAME, (unsigned int)ARRAY_SIZE(vfs_default_ops), needed)); + smb_panic("operation(s) missing from default VFS module"); + } + + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, + DEFAULT_VFS_MODULE_NAME, vfs_default_ops); +} diff --git a/source/modules/vfs_default_quota.c b/source/modules/vfs_default_quota.c index 9922a30315d..772c91dc473 100644 --- a/source/modules/vfs_default_quota.c +++ b/source/modules/vfs_default_quota.c @@ -92,11 +92,11 @@ #define DEFAULT_QUOTA_GID_NOLIMIT(handle) \ lp_parm_bool(SNUM((handle)->conn),DEFAULT_QUOTA_NAME,"gid nolimit",DEFAULT_QUOTA_GID_NOLIMIT_DEFAULT) -static int default_quota_get_quota(vfs_handle_struct *handle, connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dq) +static int default_quota_get_quota(vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dq) { int ret = -1; - if ((ret=SMB_VFS_NEXT_GET_QUOTA(handle, conn, qtype, id, dq))!=0) { + if ((ret=SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, dq))!=0) { return ret; } @@ -122,7 +122,7 @@ static int default_quota_get_quota(vfs_handle_struct *handle, connection_struct unid_t qid; uint32 qflags = dq->qflags; qid.uid = DEFAULT_QUOTA_UID(handle); - SMB_VFS_NEXT_GET_QUOTA(handle, conn, SMB_USER_QUOTA_TYPE, qid, dq); + SMB_VFS_NEXT_GET_QUOTA(handle, SMB_USER_QUOTA_TYPE, qid, dq); dq->qflags = qflags; } break; @@ -132,7 +132,7 @@ static int default_quota_get_quota(vfs_handle_struct *handle, connection_struct unid_t qid; uint32 qflags = dq->qflags; qid.gid = DEFAULT_QUOTA_GID(handle); - SMB_VFS_NEXT_GET_QUOTA(handle, conn, SMB_GROUP_QUOTA_TYPE, qid, dq); + SMB_VFS_NEXT_GET_QUOTA(handle, SMB_GROUP_QUOTA_TYPE, qid, dq); dq->qflags = qflags; } break; @@ -146,7 +146,7 @@ static int default_quota_get_quota(vfs_handle_struct *handle, connection_struct return ret; } -static int default_quota_set_quota(vfs_handle_struct *handle, connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dq) +static int default_quota_set_quota(vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dq) { int ret = -1; @@ -179,7 +179,7 @@ static int default_quota_set_quota(vfs_handle_struct *handle, connection_struct break; } - if ((ret=SMB_VFS_NEXT_SET_QUOTA(handle, conn, qtype, id, dq))!=0) { + if ((ret=SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, dq))!=0) { return ret; } @@ -194,7 +194,7 @@ static int default_quota_set_quota(vfs_handle_struct *handle, connection_struct { unid_t qid; qid.uid = DEFAULT_QUOTA_UID(handle); - ret = SMB_VFS_NEXT_SET_QUOTA(handle, conn, SMB_USER_QUOTA_TYPE, qid, dq); + ret = SMB_VFS_NEXT_SET_QUOTA(handle, SMB_USER_QUOTA_TYPE, qid, dq); } break; #ifdef HAVE_GROUP_QUOTA @@ -202,7 +202,7 @@ static int default_quota_set_quota(vfs_handle_struct *handle, connection_struct { unid_t qid; qid.gid = DEFAULT_QUOTA_GID(handle); - ret = SMB_VFS_NEXT_SET_QUOTA(handle, conn, SMB_GROUP_QUOTA_TYPE, qid, dq); + ret = SMB_VFS_NEXT_SET_QUOTA(handle, SMB_GROUP_QUOTA_TYPE, qid, dq); } break; #endif /* HAVE_GROUP_QUOTA */ @@ -224,6 +224,7 @@ static vfs_op_tuple default_quota_ops[] = { {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} }; +NTSTATUS vfs_default_quota_init(void); NTSTATUS vfs_default_quota_init(void) { return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, DEFAULT_QUOTA_NAME, default_quota_ops); diff --git a/source/modules/vfs_expand_msdfs.c b/source/modules/vfs_expand_msdfs.c index d22f6a7f98e..7176c11e4ab 100644 --- a/source/modules/vfs_expand_msdfs.c +++ b/source/modules/vfs_expand_msdfs.c @@ -23,6 +23,8 @@ #undef DBGC_CLASS #define DBGC_CLASS DBGC_VFS +extern userdom_struct current_user_info; + /********************************************************** Under mapfile we expect a table of the following format: @@ -135,7 +137,11 @@ static BOOL expand_msdfs_target(connection_struct* conn, pstring target) return False; } - standard_sub_conn(conn, mapfilename, sizeof(mapfilename)); + standard_sub_advanced(lp_servicename(SNUM(conn)), conn->user, + conn->connectpath, conn->gid, + get_current_username(), + current_user_info.domain, + mapfilename, sizeof(mapfilename)); DEBUG(10, ("Expanded targethost to %s\n", targethost)); @@ -150,13 +156,12 @@ static BOOL expand_msdfs_target(connection_struct* conn, pstring target) } static int expand_msdfs_readlink(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, char *buf, size_t bufsiz) { pstring target; int result; - result = SMB_VFS_NEXT_READLINK(handle, conn, path, target, + result = SMB_VFS_NEXT_READLINK(handle, path, target, sizeof(target)); if (result < 0) @@ -166,7 +171,7 @@ static int expand_msdfs_readlink(struct vfs_handle_struct *handle, if ((strncmp(target, "msdfs:", strlen("msdfs:")) == 0) && (strchr_m(target, '@') != NULL)) { - if (!expand_msdfs_target(conn, target)) { + if (!expand_msdfs_target(handle->conn, target)) { errno = ENOENT; return -1; } @@ -184,6 +189,7 @@ static vfs_op_tuple expand_msdfs_ops[] = { {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} }; +NTSTATUS vfs_expand_msdfs_init(void); NTSTATUS vfs_expand_msdfs_init(void) { return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "expand_msdfs", diff --git a/source/modules/vfs_extd_audit.c b/source/modules/vfs_extd_audit.c index cb8c3ffd6ab..06722b3b8c0 100644 --- a/source/modules/vfs_extd_audit.c +++ b/source/modules/vfs_extd_audit.c @@ -32,17 +32,17 @@ static int vfs_extd_audit_debug_level = DBGC_VFS; /* Function prototypes */ -static int audit_connect(vfs_handle_struct *handle, connection_struct *conn, const char *svc, const char *user); -static void audit_disconnect(vfs_handle_struct *handle, connection_struct *conn); -static SMB_STRUCT_DIR *audit_opendir(vfs_handle_struct *handle, connection_struct *conn, const char *fname, const char *mask, uint32 attr); -static int audit_mkdir(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode); -static int audit_rmdir(vfs_handle_struct *handle, connection_struct *conn, const char *path); -static int audit_open(vfs_handle_struct *handle, connection_struct *conn, const char *fname, int flags, mode_t mode); +static int audit_connect(vfs_handle_struct *handle, const char *svc, const char *user); +static void audit_disconnect(vfs_handle_struct *handle); +static SMB_STRUCT_DIR *audit_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr); +static int audit_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode); +static int audit_rmdir(vfs_handle_struct *handle, const char *path); +static int audit_open(vfs_handle_struct *handle, const char *fname, files_struct *fsp, int flags, mode_t mode); static int audit_close(vfs_handle_struct *handle, files_struct *fsp, int fd); -static int audit_rename(vfs_handle_struct *handle, connection_struct *conn, const char *oldname, const char *newname); -static int audit_unlink(vfs_handle_struct *handle, connection_struct *conn, const char *path); -static int audit_chmod(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode); -static int audit_chmod_acl(vfs_handle_struct *handle, connection_struct *conn, const char *name, mode_t mode); +static int audit_rename(vfs_handle_struct *handle, const char *oldname, const char *newname); +static int audit_unlink(vfs_handle_struct *handle, const char *path); +static int audit_chmod(vfs_handle_struct *handle, const char *path, mode_t mode); +static int audit_chmod_acl(vfs_handle_struct *handle, const char *name, mode_t mode); static int audit_fchmod(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode); static int audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode); @@ -123,7 +123,7 @@ static int audit_syslog_priority(vfs_handle_struct *handle) /* Implementation of vfs_ops. Pass everything on to the default operation but log event first. */ -static int audit_connect(vfs_handle_struct *handle, connection_struct *conn, const char *svc, const char *user) +static int audit_connect(vfs_handle_struct *handle, const char *svc, const char *user) { int result; @@ -134,25 +134,25 @@ static int audit_connect(vfs_handle_struct *handle, connection_struct *conn, con DEBUG(10, ("Connected to service %s as user %s\n", svc, user)); - result = SMB_VFS_NEXT_CONNECT(handle, conn, svc, user); + result = SMB_VFS_NEXT_CONNECT(handle, svc, user); return result; } -static void audit_disconnect(vfs_handle_struct *handle, connection_struct *conn) +static void audit_disconnect(vfs_handle_struct *handle) { syslog(audit_syslog_priority(handle), "disconnected\n"); DEBUG(10, ("Disconnected from VFS module extd_audit\n")); - SMB_VFS_NEXT_DISCONNECT(handle, conn); + SMB_VFS_NEXT_DISCONNECT(handle); return; } -static SMB_STRUCT_DIR *audit_opendir(vfs_handle_struct *handle, connection_struct *conn, const char *fname, const char *mask, uint32 attr) +static SMB_STRUCT_DIR *audit_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr) { SMB_STRUCT_DIR *result; - result = SMB_VFS_NEXT_OPENDIR(handle, conn, fname, mask, attr); + result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr); syslog(audit_syslog_priority(handle), "opendir %s %s%s\n", fname, @@ -166,11 +166,11 @@ static SMB_STRUCT_DIR *audit_opendir(vfs_handle_struct *handle, connection_struc return result; } -static int audit_mkdir(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode) +static int audit_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode) { int result; - result = SMB_VFS_NEXT_MKDIR(handle, conn, path, mode); + result = SMB_VFS_NEXT_MKDIR(handle, path, mode); syslog(audit_syslog_priority(handle), "mkdir %s %s%s\n", path, @@ -184,11 +184,11 @@ static int audit_mkdir(vfs_handle_struct *handle, connection_struct *conn, const return result; } -static int audit_rmdir(vfs_handle_struct *handle, connection_struct *conn, const char *path) +static int audit_rmdir(vfs_handle_struct *handle, const char *path) { int result; - result = SMB_VFS_NEXT_RMDIR(handle, conn, path); + result = SMB_VFS_NEXT_RMDIR(handle, path); syslog(audit_syslog_priority(handle), "rmdir %s %s%s\n", path, @@ -202,11 +202,11 @@ static int audit_rmdir(vfs_handle_struct *handle, connection_struct *conn, const return result; } -static int audit_open(vfs_handle_struct *handle, connection_struct *conn, const char *fname, int flags, mode_t mode) +static int audit_open(vfs_handle_struct *handle, const char *fname, files_struct *fsp, int flags, mode_t mode) { int result; - result = SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode); + result = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode); syslog(audit_syslog_priority(handle), "open %s (fd %d) %s%s%s\n", fname, result, @@ -239,11 +239,11 @@ static int audit_close(vfs_handle_struct *handle, files_struct *fsp, int fd) return result; } -static int audit_rename(vfs_handle_struct *handle, connection_struct *conn, const char *oldname, const char *newname) +static int audit_rename(vfs_handle_struct *handle, const char *oldname, const char *newname) { int result; - result = SMB_VFS_NEXT_RENAME(handle, conn, oldname, newname); + result = SMB_VFS_NEXT_RENAME(handle, oldname, newname); syslog(audit_syslog_priority(handle), "rename %s -> %s %s%s\n", oldname, newname, @@ -257,11 +257,11 @@ static int audit_rename(vfs_handle_struct *handle, connection_struct *conn, cons return result; } -static int audit_unlink(vfs_handle_struct *handle, connection_struct *conn, const char *path) +static int audit_unlink(vfs_handle_struct *handle, const char *path) { int result; - result = SMB_VFS_NEXT_UNLINK(handle, conn, path); + result = SMB_VFS_NEXT_UNLINK(handle, path); syslog(audit_syslog_priority(handle), "unlink %s %s%s\n", path, @@ -275,11 +275,11 @@ static int audit_unlink(vfs_handle_struct *handle, connection_struct *conn, cons return result; } -static int audit_chmod(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode) +static int audit_chmod(vfs_handle_struct *handle, const char *path, mode_t mode) { int result; - result = SMB_VFS_NEXT_CHMOD(handle, conn, path, mode); + result = SMB_VFS_NEXT_CHMOD(handle, path, mode); syslog(audit_syslog_priority(handle), "chmod %s mode 0x%x %s%s\n", path, mode, @@ -293,11 +293,11 @@ static int audit_chmod(vfs_handle_struct *handle, connection_struct *conn, const return result; } -static int audit_chmod_acl(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode) +static int audit_chmod_acl(vfs_handle_struct *handle, const char *path, mode_t mode) { int result; - result = SMB_VFS_NEXT_CHMOD_ACL(handle, conn, path, mode); + result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode); syslog(audit_syslog_priority(handle), "chmod_acl %s mode 0x%x %s%s\n", path, mode, @@ -347,6 +347,7 @@ static int audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp, int fd return result; } +NTSTATUS vfs_extd_audit_init(void); NTSTATUS vfs_extd_audit_init(void) { NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "extd_audit", audit_op_tuples); diff --git a/source/modules/vfs_fake_perms.c b/source/modules/vfs_fake_perms.c index decbe01d3ca..e31adb881c5 100644 --- a/source/modules/vfs_fake_perms.c +++ b/source/modules/vfs_fake_perms.c @@ -29,11 +29,11 @@ extern struct current_user current_user; #undef DBGC_CLASS #define DBGC_CLASS DBGC_VFS -static int fake_perms_stat(vfs_handle_struct *handle, connection_struct *conn, const char *fname, SMB_STRUCT_STAT *sbuf) +static int fake_perms_stat(vfs_handle_struct *handle, const char *fname, SMB_STRUCT_STAT *sbuf) { int ret = -1; - ret = SMB_VFS_NEXT_STAT(handle, conn, fname, sbuf); + ret = SMB_VFS_NEXT_STAT(handle, fname, sbuf); if (ret == 0) { if (S_ISDIR(sbuf->st_mode)) { sbuf->st_mode = S_IFDIR | S_IRWXU; @@ -73,6 +73,7 @@ static vfs_op_tuple fake_perms_ops[] = { {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} }; +NTSTATUS vfs_fake_perms_init(void); NTSTATUS vfs_fake_perms_init(void) { return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "fake_perms", fake_perms_ops); diff --git a/source/modules/vfs_full_audit.c b/source/modules/vfs_full_audit.c index b9ffd6fc05f..6036e49fc15 100644 --- a/source/modules/vfs_full_audit.c +++ b/source/modules/vfs_full_audit.c @@ -60,6 +60,8 @@ #include "includes.h" +extern userdom_struct current_user_info; + static int vfs_full_audit_debug_level = DBGC_VFS; struct vfs_full_audit_private_data { @@ -72,48 +74,44 @@ struct vfs_full_audit_private_data { /* Function prototypes */ -static int smb_full_audit_connect(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_connect(vfs_handle_struct *handle, const char *svc, const char *user); -static void smb_full_audit_disconnect(vfs_handle_struct *handle, - connection_struct *conn); +static void smb_full_audit_disconnect(vfs_handle_struct *handle); static SMB_BIG_UINT smb_full_audit_disk_free(vfs_handle_struct *handle, - connection_struct *conn, const char *path, + const char *path, BOOL small_query, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize); static int smb_full_audit_get_quota(struct vfs_handle_struct *handle, - struct connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt); static int smb_full_audit_set_quota(struct vfs_handle_struct *handle, - struct connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt); static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle, struct files_struct *fsp, SHADOW_COPY_DATA *shadow_copy_data, BOOL labels); static int smb_full_audit_statvfs(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, struct vfs_statvfs_struct *statbuf); -static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle, connection_struct *conn, +static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr); static SMB_STRUCT_DIRENT *smb_full_audit_readdir(vfs_handle_struct *handle, - connection_struct *conn, SMB_STRUCT_DIR *dirp); -static void smb_full_audit_seekdir(vfs_handle_struct *handle, connection_struct *conn, + SMB_STRUCT_DIR *dirp); +static void smb_full_audit_seekdir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp, long offset); -static long smb_full_audit_telldir(vfs_handle_struct *handle, connection_struct *conn, +static long smb_full_audit_telldir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp); -static void smb_full_audit_rewinddir(vfs_handle_struct *handle, connection_struct *conn, +static void smb_full_audit_rewinddir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp); -static int smb_full_audit_mkdir(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode); -static int smb_full_audit_rmdir(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_rmdir(vfs_handle_struct *handle, const char *path); -static int smb_full_audit_closedir(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_closedir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp); -static int smb_full_audit_open(vfs_handle_struct *handle, connection_struct *conn, - const char *fname, int flags, mode_t mode); +static int smb_full_audit_open(vfs_handle_struct *handle, + const char *fname, files_struct *fsp, int flags, mode_t mode); static int smb_full_audit_close(vfs_handle_struct *handle, files_struct *fsp, int fd); static ssize_t smb_full_audit_read(vfs_handle_struct *handle, files_struct *fsp, int fd, void *data, size_t n); @@ -130,46 +128,51 @@ static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd, files_struct *fsp, int fromfd, const DATA_BLOB *hdr, SMB_OFF_T offset, size_t n); -static int smb_full_audit_rename(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_rename(vfs_handle_struct *handle, const char *oldname, const char *newname); static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp, int fd); -static int smb_full_audit_stat(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_stat(vfs_handle_struct *handle, const char *fname, SMB_STRUCT_STAT *sbuf); static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_STRUCT_STAT *sbuf); -static int smb_full_audit_lstat(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_lstat(vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf); -static int smb_full_audit_unlink(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_unlink(vfs_handle_struct *handle, const char *path); -static int smb_full_audit_chmod(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_chmod(vfs_handle_struct *handle, const char *path, mode_t mode); static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode); -static int smb_full_audit_chown(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_chown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid); static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp, int fd, uid_t uid, gid_t gid); -static int smb_full_audit_chdir(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_chdir(vfs_handle_struct *handle, const char *path); -static char *smb_full_audit_getwd(vfs_handle_struct *handle, connection_struct *conn, +static char *smb_full_audit_getwd(vfs_handle_struct *handle, char *path); -static int smb_full_audit_utime(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_utime(vfs_handle_struct *handle, const char *path, struct utimbuf *times); static int smb_full_audit_ftruncate(vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_OFF_T len); static BOOL smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp, int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type); +static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle, + struct files_struct *fsp, int fd, + uint32 share_mode); +static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp, + int fd, int leasetype); static BOOL smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid); -static int smb_full_audit_symlink(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_symlink(vfs_handle_struct *handle, const char *oldpath, const char *newpath); -static int smb_full_audit_readlink(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_readlink(vfs_handle_struct *handle, const char *path, char *buf, size_t bufsiz); -static int smb_full_audit_link(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_link(vfs_handle_struct *handle, const char *oldpath, const char *newpath); -static int smb_full_audit_mknod(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_mknod(vfs_handle_struct *handle, const char *pathname, mode_t mode, SMB_DEV_T dev); -static char *smb_full_audit_realpath(vfs_handle_struct *handle, connection_struct *conn, +static char *smb_full_audit_realpath(vfs_handle_struct *handle, const char *path, char *resolved_path); static size_t smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp, int fd, uint32 security_info, @@ -183,120 +186,99 @@ static BOOL smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct * static BOOL smb_full_audit_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, const char *name, uint32 security_info_sent, SEC_DESC *psd); -static int smb_full_audit_chmod_acl(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_chmod_acl(vfs_handle_struct *handle, const char *path, mode_t mode); static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode); static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle, - connection_struct *conn, SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p); static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle, - connection_struct *conn, SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p); static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle, - connection_struct *conn, SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p); static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle, - connection_struct *conn, SMB_ACL_ENTRY_T entry_d); static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle, - connection_struct *conn, const char *path_p, SMB_ACL_TYPE_T type); static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp, int fd); static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle, - connection_struct *conn, SMB_ACL_PERMSET_T permset); static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle, - connection_struct *conn, SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle, - connection_struct *conn, SMB_ACL_T theacl, + SMB_ACL_T theacl, ssize_t *plen); static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle, - connection_struct *conn, int count); static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle, - connection_struct *conn, SMB_ACL_T *pacl, + SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry); static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle, - connection_struct *conn, SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype); static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle, - connection_struct *conn, SMB_ACL_ENTRY_T entry, void *qual); static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle, - connection_struct *conn, SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset); static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle, - connection_struct *conn, SMB_ACL_T theacl ); static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle, - connection_struct *conn, const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl); static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_ACL_T theacl); static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle, - connection_struct *conn, const char *path); static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle, - connection_struct *conn, SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle, - connection_struct *conn, char *text); static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle, - connection_struct *conn, SMB_ACL_T posix_acl); static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle, - connection_struct *conn, void *qualifier, SMB_ACL_TAG_T tagtype); static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, + const char *path, const char *name, void *value, size_t size); static ssize_t smb_full_audit_lgetxattr(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, const char *name, void *value, size_t size); static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, int fd, const char *name, void *value, size_t size); static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, char *list, size_t size); static ssize_t smb_full_audit_llistxattr(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, char *list, size_t size); static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, int fd, char *list, size_t size); static int smb_full_audit_removexattr(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, + const char *path, const char *name); static int smb_full_audit_lremovexattr(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, + const char *path, const char *name); static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle, struct files_struct *fsp, int fd, const char *name); static int smb_full_audit_setxattr(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, + const char *path, const char *name, const void *value, size_t size, int flags); static int smb_full_audit_lsetxattr(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, + const char *path, const char *name, const void *value, size_t size, int flags); static int smb_full_audit_fsetxattr(struct vfs_handle_struct *handle, @@ -399,6 +381,10 @@ static vfs_op_tuple audit_op_tuples[] = { SMB_VFS_LAYER_LOGGER}, {SMB_VFS_OP(smb_full_audit_lock), SMB_VFS_OP_LOCK, SMB_VFS_LAYER_LOGGER}, + {SMB_VFS_OP(smb_full_audit_kernel_flock), SMB_VFS_OP_KERNEL_FLOCK, + SMB_VFS_LAYER_LOGGER}, + {SMB_VFS_OP(smb_full_audit_linux_setlease), SMB_VFS_OP_LINUX_SETLEASE, + SMB_VFS_LAYER_LOGGER}, {SMB_VFS_OP(smb_full_audit_getlock), SMB_VFS_OP_GETLOCK, SMB_VFS_LAYER_LOGGER}, {SMB_VFS_OP(smb_full_audit_symlink), SMB_VFS_OP_SYMLINK, @@ -566,6 +552,8 @@ static struct { { SMB_VFS_OP_UTIME, "utime" }, { SMB_VFS_OP_FTRUNCATE, "ftruncate" }, { SMB_VFS_OP_LOCK, "lock" }, + { SMB_VFS_OP_KERNEL_FLOCK, "kernel_flock" }, + { SMB_VFS_OP_LINUX_SETLEASE, "linux_setlease" }, { SMB_VFS_OP_GETLOCK, "getlock" }, { SMB_VFS_OP_SYMLINK, "symlink" }, { SMB_VFS_OP_READLINK, "readlink" }, @@ -669,7 +657,11 @@ static char *audit_prefix(connection_struct *conn) pstrcpy(prefix, lp_parm_const_string(SNUM(conn), "full_audit", "prefix", "%u|%I")); - standard_sub_snum(SNUM(conn), prefix, sizeof(prefix)-1); + standard_sub_advanced(lp_servicename(SNUM(conn)), conn->user, + conn->connectpath, conn->gid, + get_current_username(), + current_user_info.domain, + prefix, sizeof(prefix)); return prefix; } @@ -811,7 +803,7 @@ static void free_private_data(void **p_data) /* Implementation of vfs_ops. Pass everything on to the default operation but log event first. */ -static int smb_full_audit_connect(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_connect(vfs_handle_struct *handle, const char *svc, const char *user) { int result; @@ -832,17 +824,17 @@ static int smb_full_audit_connect(vfs_handle_struct *handle, connection_struct * openlog("smbd_audit", 0, audit_syslog_facility(handle)); init_bitmap(&pd->success_ops, - lp_parm_string_list(SNUM(conn), "full_audit", "success", + lp_parm_string_list(SNUM(handle->conn), "full_audit", "success", none)); init_bitmap(&pd->failure_ops, - lp_parm_string_list(SNUM(conn), "full_audit", "failure", + lp_parm_string_list(SNUM(handle->conn), "full_audit", "failure", all)); /* Store the private data. */ SMB_VFS_HANDLE_SET_DATA(handle, pd, free_private_data, struct vfs_full_audit_private_data, return -1); - result = SMB_VFS_NEXT_CONNECT(handle, conn, svc, user); + result = SMB_VFS_NEXT_CONNECT(handle, svc, user); do_log(SMB_VFS_OP_CONNECT, True, handle, "%s", svc); @@ -850,13 +842,12 @@ static int smb_full_audit_connect(vfs_handle_struct *handle, connection_struct * return result; } -static void smb_full_audit_disconnect(vfs_handle_struct *handle, - connection_struct *conn) +static void smb_full_audit_disconnect(vfs_handle_struct *handle) { - SMB_VFS_NEXT_DISCONNECT(handle, conn); + SMB_VFS_NEXT_DISCONNECT(handle); do_log(SMB_VFS_OP_DISCONNECT, True, handle, - "%s", lp_servicename(SNUM(conn))); + "%s", lp_servicename(SNUM(handle->conn))); /* The bitmaps will be disconnected when the private data is deleted. */ @@ -865,13 +856,13 @@ static void smb_full_audit_disconnect(vfs_handle_struct *handle, } static SMB_BIG_UINT smb_full_audit_disk_free(vfs_handle_struct *handle, - connection_struct *conn, const char *path, + const char *path, BOOL small_query, SMB_BIG_UINT *bsize, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize) { SMB_BIG_UINT result; - result = SMB_VFS_NEXT_DISK_FREE(handle, conn, path, small_query, bsize, + result = SMB_VFS_NEXT_DISK_FREE(handle, path, small_query, bsize, dfree, dsize); /* Don't have a reasonable notion of failure here */ @@ -882,13 +873,12 @@ static SMB_BIG_UINT smb_full_audit_disk_free(vfs_handle_struct *handle, } static int smb_full_audit_get_quota(struct vfs_handle_struct *handle, - struct connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt) { int result; - result = SMB_VFS_NEXT_GET_QUOTA(handle, conn, qtype, id, qt); + result = SMB_VFS_NEXT_GET_QUOTA(handle, qtype, id, qt); do_log(SMB_VFS_OP_GET_QUOTA, (result >= 0), handle, ""); @@ -897,13 +887,12 @@ static int smb_full_audit_get_quota(struct vfs_handle_struct *handle, static int smb_full_audit_set_quota(struct vfs_handle_struct *handle, - struct connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt) { int result; - result = SMB_VFS_NEXT_SET_QUOTA(handle, conn, qtype, id, qt); + result = SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, qt); do_log(SMB_VFS_OP_SET_QUOTA, (result >= 0), handle, ""); @@ -924,25 +913,24 @@ static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle, } static int smb_full_audit_statvfs(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, struct vfs_statvfs_struct *statbuf) { int result; - result = SMB_VFS_NEXT_STATVFS(handle, conn, path, statbuf); + result = SMB_VFS_NEXT_STATVFS(handle, path, statbuf); do_log(SMB_VFS_OP_STATVFS, (result >= 0), handle, ""); return result; } -static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle, connection_struct *conn, +static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr) { SMB_STRUCT_DIR *result; - result = SMB_VFS_NEXT_OPENDIR(handle, conn, fname, mask, attr); + result = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr); do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname); @@ -950,11 +938,11 @@ static SMB_STRUCT_DIR *smb_full_audit_opendir(vfs_handle_struct *handle, connect } static SMB_STRUCT_DIRENT *smb_full_audit_readdir(vfs_handle_struct *handle, - connection_struct *conn, SMB_STRUCT_DIR *dirp) + SMB_STRUCT_DIR *dirp) { SMB_STRUCT_DIRENT *result; - result = SMB_VFS_NEXT_READDIR(handle, conn, dirp); + result = SMB_VFS_NEXT_READDIR(handle, dirp); /* This operation has no reasonable error condition * (End of dir is also failure), so always succeed. @@ -964,78 +952,78 @@ static SMB_STRUCT_DIRENT *smb_full_audit_readdir(vfs_handle_struct *handle, return result; } -static void smb_full_audit_seekdir(vfs_handle_struct *handle, connection_struct *conn, +static void smb_full_audit_seekdir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp, long offset) { - SMB_VFS_NEXT_SEEKDIR(handle, conn, dirp, offset); + SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset); do_log(SMB_VFS_OP_SEEKDIR, True, handle, ""); return; } -static long smb_full_audit_telldir(vfs_handle_struct *handle, connection_struct *conn, +static long smb_full_audit_telldir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp) { long result; - result = SMB_VFS_NEXT_TELLDIR(handle, conn, dirp); + result = SMB_VFS_NEXT_TELLDIR(handle, dirp); do_log(SMB_VFS_OP_TELLDIR, True, handle, ""); return result; } -static void smb_full_audit_rewinddir(vfs_handle_struct *handle, connection_struct *conn, +static void smb_full_audit_rewinddir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp) { - SMB_VFS_NEXT_REWINDDIR(handle, conn, dirp); + SMB_VFS_NEXT_REWINDDIR(handle, dirp); do_log(SMB_VFS_OP_REWINDDIR, True, handle, ""); return; } -static int smb_full_audit_mkdir(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode) { int result; - result = SMB_VFS_NEXT_MKDIR(handle, conn, path, mode); + result = SMB_VFS_NEXT_MKDIR(handle, path, mode); do_log(SMB_VFS_OP_MKDIR, (result >= 0), handle, "%s", path); return result; } -static int smb_full_audit_rmdir(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_rmdir(vfs_handle_struct *handle, const char *path) { int result; - result = SMB_VFS_NEXT_RMDIR(handle, conn, path); + result = SMB_VFS_NEXT_RMDIR(handle, path); do_log(SMB_VFS_OP_RMDIR, (result >= 0), handle, "%s", path); return result; } -static int smb_full_audit_closedir(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_closedir(vfs_handle_struct *handle, SMB_STRUCT_DIR *dirp) { int result; - result = SMB_VFS_NEXT_CLOSEDIR(handle, conn, dirp); + result = SMB_VFS_NEXT_CLOSEDIR(handle, dirp); do_log(SMB_VFS_OP_CLOSEDIR, (result >= 0), handle, ""); return result; } -static int smb_full_audit_open(vfs_handle_struct *handle, connection_struct *conn, - const char *fname, int flags, mode_t mode) +static int smb_full_audit_open(vfs_handle_struct *handle, + const char *fname, files_struct *fsp, int flags, mode_t mode) { int result; - result = SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode); + result = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode); do_log(SMB_VFS_OP_OPEN, (result >= 0), handle, "%s|%s", ((flags & O_WRONLY) || (flags & O_RDWR))?"w":"r", @@ -1133,12 +1121,12 @@ static ssize_t smb_full_audit_sendfile(vfs_handle_struct *handle, int tofd, return result; } -static int smb_full_audit_rename(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_rename(vfs_handle_struct *handle, const char *oldname, const char *newname) { int result; - result = SMB_VFS_NEXT_RENAME(handle, conn, oldname, newname); + result = SMB_VFS_NEXT_RENAME(handle, oldname, newname); do_log(SMB_VFS_OP_RENAME, (result >= 0), handle, "%s|%s", oldname, newname); @@ -1156,12 +1144,12 @@ static int smb_full_audit_fsync(vfs_handle_struct *handle, files_struct *fsp, in return result; } -static int smb_full_audit_stat(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_stat(vfs_handle_struct *handle, const char *fname, SMB_STRUCT_STAT *sbuf) { int result; - result = SMB_VFS_NEXT_STAT(handle, conn, fname, sbuf); + result = SMB_VFS_NEXT_STAT(handle, fname, sbuf); do_log(SMB_VFS_OP_STAT, (result >= 0), handle, "%s", fname); @@ -1180,36 +1168,36 @@ static int smb_full_audit_fstat(vfs_handle_struct *handle, files_struct *fsp, in return result; } -static int smb_full_audit_lstat(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_lstat(vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf) { int result; - result = SMB_VFS_NEXT_LSTAT(handle, conn, path, sbuf); + result = SMB_VFS_NEXT_LSTAT(handle, path, sbuf); do_log(SMB_VFS_OP_LSTAT, (result >= 0), handle, "%s", path); return result; } -static int smb_full_audit_unlink(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_unlink(vfs_handle_struct *handle, const char *path) { int result; - result = SMB_VFS_NEXT_UNLINK(handle, conn, path); + result = SMB_VFS_NEXT_UNLINK(handle, path); do_log(SMB_VFS_OP_UNLINK, (result >= 0), handle, "%s", path); return result; } -static int smb_full_audit_chmod(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_chmod(vfs_handle_struct *handle, const char *path, mode_t mode) { int result; - result = SMB_VFS_NEXT_CHMOD(handle, conn, path, mode); + result = SMB_VFS_NEXT_CHMOD(handle, path, mode); do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode); @@ -1229,12 +1217,12 @@ static int smb_full_audit_fchmod(vfs_handle_struct *handle, files_struct *fsp, i return result; } -static int smb_full_audit_chown(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_chown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid) { int result; - result = SMB_VFS_NEXT_CHOWN(handle, conn, path, uid, gid); + result = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid); do_log(SMB_VFS_OP_CHOWN, (result >= 0), handle, "%s|%ld|%ld", path, (long int)uid, (long int)gid); @@ -1255,36 +1243,36 @@ static int smb_full_audit_fchown(vfs_handle_struct *handle, files_struct *fsp, i return result; } -static int smb_full_audit_chdir(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_chdir(vfs_handle_struct *handle, const char *path) { int result; - result = SMB_VFS_NEXT_CHDIR(handle, conn, path); + result = SMB_VFS_NEXT_CHDIR(handle, path); do_log(SMB_VFS_OP_CHDIR, (result >= 0), handle, "chdir|%s", path); return result; } -static char *smb_full_audit_getwd(vfs_handle_struct *handle, connection_struct *conn, +static char *smb_full_audit_getwd(vfs_handle_struct *handle, char *path) { char *result; - result = SMB_VFS_NEXT_GETWD(handle, conn, path); + result = SMB_VFS_NEXT_GETWD(handle, path); do_log(SMB_VFS_OP_GETWD, (result != NULL), handle, "%s", path); return result; } -static int smb_full_audit_utime(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_utime(vfs_handle_struct *handle, const char *path, struct utimbuf *times) { int result; - result = SMB_VFS_NEXT_UTIME(handle, conn, path, times); + result = SMB_VFS_NEXT_UTIME(handle, path, times); do_log(SMB_VFS_OP_UTIME, (result >= 0), handle, "%s", path); @@ -1316,6 +1304,33 @@ static BOOL smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp, in return result; } +static int smb_full_audit_kernel_flock(struct vfs_handle_struct *handle, + struct files_struct *fsp, int fd, + uint32 share_mode) +{ + int result; + + result = SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, fd, share_mode); + + do_log(SMB_VFS_OP_KERNEL_FLOCK, (result >= 0), handle, "%s", + fsp->fsp_name); + + return result; +} + +static int smb_full_audit_linux_setlease(vfs_handle_struct *handle, files_struct *fsp, + int fd, int leasetype) +{ + int result; + + result = SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, fd, leasetype); + + do_log(SMB_VFS_OP_LINUX_SETLEASE, (result >= 0), handle, "%s", + fsp->fsp_name); + + return result; +} + static BOOL smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid) { @@ -1328,12 +1343,12 @@ static BOOL smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp, return result; } -static int smb_full_audit_symlink(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_symlink(vfs_handle_struct *handle, const char *oldpath, const char *newpath) { int result; - result = SMB_VFS_NEXT_SYMLINK(handle, conn, oldpath, newpath); + result = SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath); do_log(SMB_VFS_OP_SYMLINK, (result >= 0), handle, "%s|%s", oldpath, newpath); @@ -1341,24 +1356,24 @@ static int smb_full_audit_symlink(vfs_handle_struct *handle, connection_struct * return result; } -static int smb_full_audit_readlink(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_readlink(vfs_handle_struct *handle, const char *path, char *buf, size_t bufsiz) { int result; - result = SMB_VFS_NEXT_READLINK(handle, conn, path, buf, bufsiz); + result = SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz); do_log(SMB_VFS_OP_READLINK, (result >= 0), handle, "%s", path); return result; } -static int smb_full_audit_link(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_link(vfs_handle_struct *handle, const char *oldpath, const char *newpath) { int result; - result = SMB_VFS_NEXT_LINK(handle, conn, oldpath, newpath); + result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath); do_log(SMB_VFS_OP_LINK, (result >= 0), handle, "%s|%s", oldpath, newpath); @@ -1366,24 +1381,24 @@ static int smb_full_audit_link(vfs_handle_struct *handle, connection_struct *con return result; } -static int smb_full_audit_mknod(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_mknod(vfs_handle_struct *handle, const char *pathname, mode_t mode, SMB_DEV_T dev) { int result; - result = SMB_VFS_NEXT_MKNOD(handle, conn, pathname, mode, dev); + result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev); do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname); return result; } -static char *smb_full_audit_realpath(vfs_handle_struct *handle, connection_struct *conn, +static char *smb_full_audit_realpath(vfs_handle_struct *handle, const char *path, char *resolved_path) { char *result; - result = SMB_VFS_NEXT_REALPATH(handle, conn, path, resolved_path); + result = SMB_VFS_NEXT_REALPATH(handle, path, resolved_path); do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path); @@ -1448,12 +1463,12 @@ static BOOL smb_full_audit_set_nt_acl(vfs_handle_struct *handle, files_struct *f return result; } -static int smb_full_audit_chmod_acl(vfs_handle_struct *handle, connection_struct *conn, +static int smb_full_audit_chmod_acl(vfs_handle_struct *handle, const char *path, mode_t mode) { int result; - result = SMB_VFS_NEXT_CHMOD_ACL(handle, conn, path, mode); + result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode); do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle, "%s|%o", path, mode); @@ -1475,13 +1490,13 @@ static int smb_full_audit_fchmod_acl(vfs_handle_struct *handle, files_struct *fs } static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle, - connection_struct *conn, + SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p) { int result; - result = SMB_VFS_NEXT_SYS_ACL_GET_ENTRY(handle, conn, theacl, entry_id, + result = SMB_VFS_NEXT_SYS_ACL_GET_ENTRY(handle, theacl, entry_id, entry_p); do_log(SMB_VFS_OP_SYS_ACL_GET_ENTRY, (result >= 0), handle, @@ -1491,13 +1506,13 @@ static int smb_full_audit_sys_acl_get_entry(vfs_handle_struct *handle, } static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle, - connection_struct *conn, + SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) { int result; - result = SMB_VFS_NEXT_SYS_ACL_GET_TAG_TYPE(handle, conn, entry_d, + result = SMB_VFS_NEXT_SYS_ACL_GET_TAG_TYPE(handle, entry_d, tag_type_p); do_log(SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE, (result >= 0), handle, @@ -1507,13 +1522,13 @@ static int smb_full_audit_sys_acl_get_tag_type(vfs_handle_struct *handle, } static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle, - connection_struct *conn, + SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p) { int result; - result = SMB_VFS_NEXT_SYS_ACL_GET_PERMSET(handle, conn, entry_d, + result = SMB_VFS_NEXT_SYS_ACL_GET_PERMSET(handle, entry_d, permset_p); do_log(SMB_VFS_OP_SYS_ACL_GET_PERMSET, (result >= 0), handle, @@ -1523,12 +1538,12 @@ static int smb_full_audit_sys_acl_get_permset(vfs_handle_struct *handle, } static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle, - connection_struct *conn, + SMB_ACL_ENTRY_T entry_d) { void *result; - result = SMB_VFS_NEXT_SYS_ACL_GET_QUALIFIER(handle, conn, entry_d); + result = SMB_VFS_NEXT_SYS_ACL_GET_QUALIFIER(handle, entry_d); do_log(SMB_VFS_OP_SYS_ACL_GET_QUALIFIER, (result != NULL), handle, ""); @@ -1537,13 +1552,12 @@ static void * smb_full_audit_sys_acl_get_qualifier(vfs_handle_struct *handle, } static SMB_ACL_T smb_full_audit_sys_acl_get_file(vfs_handle_struct *handle, - connection_struct *conn, const char *path_p, SMB_ACL_TYPE_T type) { SMB_ACL_T result; - result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, conn, path_p, type); + result = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type); do_log(SMB_VFS_OP_SYS_ACL_GET_FILE, (result != NULL), handle, "%s", path_p); @@ -1565,12 +1579,12 @@ static SMB_ACL_T smb_full_audit_sys_acl_get_fd(vfs_handle_struct *handle, } static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle, - connection_struct *conn, + SMB_ACL_PERMSET_T permset) { int result; - result = SMB_VFS_NEXT_SYS_ACL_CLEAR_PERMS(handle, conn, permset); + result = SMB_VFS_NEXT_SYS_ACL_CLEAR_PERMS(handle, permset); do_log(SMB_VFS_OP_SYS_ACL_CLEAR_PERMS, (result >= 0), handle, ""); @@ -1579,13 +1593,13 @@ static int smb_full_audit_sys_acl_clear_perms(vfs_handle_struct *handle, } static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle, - connection_struct *conn, + SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) { int result; - result = SMB_VFS_NEXT_SYS_ACL_ADD_PERM(handle, conn, permset, perm); + result = SMB_VFS_NEXT_SYS_ACL_ADD_PERM(handle, permset, perm); do_log(SMB_VFS_OP_SYS_ACL_ADD_PERM, (result >= 0), handle, ""); @@ -1594,12 +1608,12 @@ static int smb_full_audit_sys_acl_add_perm(vfs_handle_struct *handle, } static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle, - connection_struct *conn, SMB_ACL_T theacl, + SMB_ACL_T theacl, ssize_t *plen) { char * result; - result = SMB_VFS_NEXT_SYS_ACL_TO_TEXT(handle, conn, theacl, plen); + result = SMB_VFS_NEXT_SYS_ACL_TO_TEXT(handle, theacl, plen); do_log(SMB_VFS_OP_SYS_ACL_TO_TEXT, (result != NULL), handle, ""); @@ -1608,12 +1622,12 @@ static char * smb_full_audit_sys_acl_to_text(vfs_handle_struct *handle, } static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle, - connection_struct *conn, + int count) { SMB_ACL_T result; - result = SMB_VFS_NEXT_SYS_ACL_INIT(handle, conn, count); + result = SMB_VFS_NEXT_SYS_ACL_INIT(handle, count); do_log(SMB_VFS_OP_SYS_ACL_INIT, (result != NULL), handle, ""); @@ -1622,12 +1636,12 @@ static SMB_ACL_T smb_full_audit_sys_acl_init(vfs_handle_struct *handle, } static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle, - connection_struct *conn, SMB_ACL_T *pacl, + SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) { int result; - result = SMB_VFS_NEXT_SYS_ACL_CREATE_ENTRY(handle, conn, pacl, pentry); + result = SMB_VFS_NEXT_SYS_ACL_CREATE_ENTRY(handle, pacl, pentry); do_log(SMB_VFS_OP_SYS_ACL_CREATE_ENTRY, (result >= 0), handle, ""); @@ -1636,13 +1650,13 @@ static int smb_full_audit_sys_acl_create_entry(vfs_handle_struct *handle, } static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle, - connection_struct *conn, + SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) { int result; - result = SMB_VFS_NEXT_SYS_ACL_SET_TAG_TYPE(handle, conn, entry, + result = SMB_VFS_NEXT_SYS_ACL_SET_TAG_TYPE(handle, entry, tagtype); do_log(SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE, (result >= 0), handle, @@ -1652,13 +1666,13 @@ static int smb_full_audit_sys_acl_set_tag_type(vfs_handle_struct *handle, } static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle, - connection_struct *conn, + SMB_ACL_ENTRY_T entry, void *qual) { int result; - result = SMB_VFS_NEXT_SYS_ACL_SET_QUALIFIER(handle, conn, entry, qual); + result = SMB_VFS_NEXT_SYS_ACL_SET_QUALIFIER(handle, entry, qual); do_log(SMB_VFS_OP_SYS_ACL_SET_QUALIFIER, (result >= 0), handle, ""); @@ -1667,13 +1681,13 @@ static int smb_full_audit_sys_acl_set_qualifier(vfs_handle_struct *handle, } static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle, - connection_struct *conn, + SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) { int result; - result = SMB_VFS_NEXT_SYS_ACL_SET_PERMSET(handle, conn, entry, permset); + result = SMB_VFS_NEXT_SYS_ACL_SET_PERMSET(handle, entry, permset); do_log(SMB_VFS_OP_SYS_ACL_SET_PERMSET, (result >= 0), handle, ""); @@ -1682,12 +1696,12 @@ static int smb_full_audit_sys_acl_set_permset(vfs_handle_struct *handle, } static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle, - connection_struct *conn, + SMB_ACL_T theacl ) { int result; - result = SMB_VFS_NEXT_SYS_ACL_VALID(handle, conn, theacl); + result = SMB_VFS_NEXT_SYS_ACL_VALID(handle, theacl); do_log(SMB_VFS_OP_SYS_ACL_VALID, (result >= 0), handle, ""); @@ -1696,13 +1710,13 @@ static int smb_full_audit_sys_acl_valid(vfs_handle_struct *handle, } static int smb_full_audit_sys_acl_set_file(vfs_handle_struct *handle, - connection_struct *conn, + const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) { int result; - result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, conn, name, acltype, + result = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype, theacl); do_log(SMB_VFS_OP_SYS_ACL_SET_FILE, (result >= 0), handle, @@ -1725,12 +1739,12 @@ static int smb_full_audit_sys_acl_set_fd(vfs_handle_struct *handle, files_struct } static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle, - connection_struct *conn, + const char *path) { int result; - result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, conn, path); + result = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path); do_log(SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, (result >= 0), handle, "%s", path); @@ -1739,13 +1753,13 @@ static int smb_full_audit_sys_acl_delete_def_file(vfs_handle_struct *handle, } static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle, - connection_struct *conn, + SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) { int result; - result = SMB_VFS_NEXT_SYS_ACL_GET_PERM(handle, conn, permset, perm); + result = SMB_VFS_NEXT_SYS_ACL_GET_PERM(handle, permset, perm); do_log(SMB_VFS_OP_SYS_ACL_GET_PERM, (result >= 0), handle, ""); @@ -1754,12 +1768,12 @@ static int smb_full_audit_sys_acl_get_perm(vfs_handle_struct *handle, } static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle, - connection_struct *conn, + char *text) { int result; - result = SMB_VFS_NEXT_SYS_ACL_FREE_TEXT(handle, conn, text); + result = SMB_VFS_NEXT_SYS_ACL_FREE_TEXT(handle, text); do_log(SMB_VFS_OP_SYS_ACL_FREE_TEXT, (result >= 0), handle, ""); @@ -1768,12 +1782,12 @@ static int smb_full_audit_sys_acl_free_text(vfs_handle_struct *handle, } static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle, - connection_struct *conn, + SMB_ACL_T posix_acl) { int result; - result = SMB_VFS_NEXT_SYS_ACL_FREE_ACL(handle, conn, posix_acl); + result = SMB_VFS_NEXT_SYS_ACL_FREE_ACL(handle, posix_acl); do_log(SMB_VFS_OP_SYS_ACL_FREE_ACL, (result >= 0), handle, ""); @@ -1782,13 +1796,12 @@ static int smb_full_audit_sys_acl_free_acl(vfs_handle_struct *handle, } static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle, - connection_struct *conn, void *qualifier, SMB_ACL_TAG_T tagtype) { int result; - result = SMB_VFS_NEXT_SYS_ACL_FREE_QUALIFIER(handle, conn, qualifier, + result = SMB_VFS_NEXT_SYS_ACL_FREE_QUALIFIER(handle, qualifier, tagtype); do_log(SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER, (result >= 0), handle, @@ -1798,12 +1811,12 @@ static int smb_full_audit_sys_acl_free_qualifier(vfs_handle_struct *handle, } static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, + const char *path, const char *name, void *value, size_t size) { ssize_t result; - result = SMB_VFS_NEXT_GETXATTR(handle, conn, path, name, value, size); + result = SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size); do_log(SMB_VFS_OP_GETXATTR, (result >= 0), handle, "%s|%s", path, name); @@ -1812,13 +1825,12 @@ static ssize_t smb_full_audit_getxattr(struct vfs_handle_struct *handle, } static ssize_t smb_full_audit_lgetxattr(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, const char *name, void *value, size_t size) { ssize_t result; - result = SMB_VFS_NEXT_LGETXATTR(handle, conn, path, name, value, size); + result = SMB_VFS_NEXT_LGETXATTR(handle, path, name, value, size); do_log(SMB_VFS_OP_LGETXATTR, (result >= 0), handle, "%s|%s", path, name); @@ -1841,12 +1853,11 @@ static ssize_t smb_full_audit_fgetxattr(struct vfs_handle_struct *handle, } static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, char *list, size_t size) { ssize_t result; - result = SMB_VFS_NEXT_LISTXATTR(handle, conn, path, list, size); + result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size); do_log(SMB_VFS_OP_LISTXATTR, (result >= 0), handle, "%s", path); @@ -1854,12 +1865,11 @@ static ssize_t smb_full_audit_listxattr(struct vfs_handle_struct *handle, } static ssize_t smb_full_audit_llistxattr(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, char *list, size_t size) { ssize_t result; - result = SMB_VFS_NEXT_LLISTXATTR(handle, conn, path, list, size); + result = SMB_VFS_NEXT_LLISTXATTR(handle, path, list, size); do_log(SMB_VFS_OP_LLISTXATTR, (result >= 0), handle, "%s", path); @@ -1881,12 +1891,12 @@ static ssize_t smb_full_audit_flistxattr(struct vfs_handle_struct *handle, } static int smb_full_audit_removexattr(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, + const char *path, const char *name) { int result; - result = SMB_VFS_NEXT_REMOVEXATTR(handle, conn, path, name); + result = SMB_VFS_NEXT_REMOVEXATTR(handle, path, name); do_log(SMB_VFS_OP_REMOVEXATTR, (result >= 0), handle, "%s|%s", path, name); @@ -1895,12 +1905,12 @@ static int smb_full_audit_removexattr(struct vfs_handle_struct *handle, } static int smb_full_audit_lremovexattr(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, + const char *path, const char *name) { int result; - result = SMB_VFS_NEXT_LREMOVEXATTR(handle, conn, path, name); + result = SMB_VFS_NEXT_LREMOVEXATTR(handle, path, name); do_log(SMB_VFS_OP_LREMOVEXATTR, (result >= 0), handle, "%s|%s", path, name); @@ -1923,13 +1933,13 @@ static int smb_full_audit_fremovexattr(struct vfs_handle_struct *handle, } static int smb_full_audit_setxattr(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, + const char *path, const char *name, const void *value, size_t size, int flags) { int result; - result = SMB_VFS_NEXT_SETXATTR(handle, conn, path, name, value, size, + result = SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size, flags); do_log(SMB_VFS_OP_SETXATTR, (result >= 0), handle, @@ -1939,13 +1949,13 @@ static int smb_full_audit_setxattr(struct vfs_handle_struct *handle, } static int smb_full_audit_lsetxattr(struct vfs_handle_struct *handle, - struct connection_struct *conn, const char *path, + const char *path, const char *name, const void *value, size_t size, int flags) { int result; - result = SMB_VFS_NEXT_LSETXATTR(handle, conn, path, name, value, size, + result = SMB_VFS_NEXT_LSETXATTR(handle, path, name, value, size, flags); do_log(SMB_VFS_OP_LSETXATTR, (result >= 0), handle, @@ -2047,6 +2057,7 @@ static int smb_full_audit_aio_suspend(struct vfs_handle_struct *handle, struct f } +NTSTATUS vfs_full_audit_init(void); NTSTATUS vfs_full_audit_init(void) { NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, diff --git a/source/modules/vfs_gpfs.c b/source/modules/vfs_gpfs.c new file mode 100644 index 00000000000..20c9f56a170 --- /dev/null +++ b/source/modules/vfs_gpfs.c @@ -0,0 +1,674 @@ +/* + Unix SMB/CIFS implementation. + Wrap gpfs calls in vfs functions. + + Copyright (C) Christian Ambach <cambach1@de.ibm.com> 2006 + + Major code contributions by Chetan Shringarpure <chetan.sh@in.ibm.com> + and Gomati Mohanan <gomati.mohanan@in.ibm.com> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +*/ + +#include "includes.h" + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_VFS + +#include <gpfs_gpl.h> +#include "nfs4_acls.h" + + +static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp, + int fd, uint32 share_mode) +{ + + START_PROFILE(syscall_kernel_flock); + + kernel_flock(fsp->fh->fd, share_mode); + + if (!set_gpfs_sharemode(fsp, fsp->access_mask, fsp->share_access)) { + + return -1; + + } + + END_PROFILE(syscall_kernel_flock); + + return 0; +} + +static int vfs_gpfs_setlease(vfs_handle_struct *handle, files_struct *fsp, + int fd, int leasetype) +{ + int ret; + + START_PROFILE(syscall_linux_setlease); + + if ( linux_set_lease_sighandler(fd) == -1) + return -1; + + ret = set_gpfs_lease(fd,leasetype); + + if ( ret < 0 ) { + /* This must have come from GPFS not being available */ + /* or some other error, hence call the default */ + ret = linux_setlease(fd, leasetype); + } + + END_PROFILE(syscall_linux_setlease); + + return ret; +} + + + +static void gpfs_dumpacl(int level, struct gpfs_acl *gacl) +{ + int i; + if (gacl==NULL) + { + DEBUG(0, ("gpfs acl is NULL\n")); + return; + } + + DEBUG(level, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n", + gacl->acl_nace, gacl->acl_type, gacl->acl_version, gacl->acl_level, gacl->acl_len)); + for(i=0; i<gacl->acl_nace; i++) + { + struct gpfs_ace_v4 *gace = gacl->ace_v4 + i; + DEBUG(level, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n", + i, gace->aceType, gace->aceFlags, gace->aceMask, + gace->aceIFlags, gace->aceWho)); + } +} + +static struct gpfs_acl *gpfs_getacl_alloc(const char *fname, gpfs_aclType_t type) +{ + struct gpfs_acl *acl; + size_t len = 200; + int ret; + TALLOC_CTX *mem_ctx = main_loop_talloc_get(); + + acl = (struct gpfs_acl *)talloc_size(mem_ctx, len); + if (acl == NULL) { + errno = ENOMEM; + return NULL; + } + + acl->acl_len = len; + acl->acl_level = 0; + acl->acl_version = 0; + acl->acl_type = type; + + ret = smbd_gpfs_getacl((char *)fname, GPFS_GETACL_STRUCT | GPFS_ACL_SAMBA, acl); + if ((ret != 0) && (errno == ENOSPC)) { + struct gpfs_acl *new_acl = (struct gpfs_acl *)talloc_size( + mem_ctx, acl->acl_len + sizeof(struct gpfs_acl)); + if (new_acl == NULL) { + errno = ENOMEM; + return NULL; + } + + new_acl->acl_len = acl->acl_len; + new_acl->acl_level = acl->acl_level; + new_acl->acl_version = acl->acl_version; + new_acl->acl_type = acl->acl_type; + acl = new_acl; + + ret = smbd_gpfs_getacl((char *)fname, GPFS_GETACL_STRUCT | GPFS_ACL_SAMBA, acl); + } + if (ret != 0) + { + DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno))); + return NULL; + } + + return acl; +} + +static BOOL gpfs_get_nfs4_acl(struct files_struct *fsp, SMB4ACL_T **ppacl, BOOL *pretryPosix) +{ + TALLOC_CTX *mem_ctx; + int i; + struct gpfs_acl *gacl = NULL; + + mem_ctx = main_loop_talloc_get(); + + DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fsp->fsp_name)); + + /* First get the real acl length */ + gacl = gpfs_getacl_alloc(fsp->fsp_name, GPFS_ACL_TYPE_NFS4); + if (gacl == NULL) { + DEBUG(9, ("gpfs_getacl failed for %s with %s\n", + fsp->fsp_name, strerror(errno))); + return False; + } + + if (gacl->acl_type != GPFS_ACL_TYPE_NFS4) { + DEBUG(10, ("Got non-nfsv4 acl\n")); + *pretryPosix = True; + return False; + } + + *ppacl = smb_create_smb4acl(); + + DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n", + gacl->acl_len, gacl->acl_level, gacl->acl_version, + gacl->acl_nace)); + + for (i=0; i<gacl->acl_nace; i++) { + struct gpfs_ace_v4 *gace = &gacl->ace_v4[i]; + SMB_ACE4PROP_T smbace; + memset(&smbace, 0, sizeof(SMB4ACE_T)); + + DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, " + "who: %d\n", gace->aceType, gace->aceIFlags, + gace->aceFlags, gace->aceMask, gace->aceWho)); + + if (gace->aceIFlags & ACE4_IFLAG_SPECIAL_ID) { + smbace.flags |= SMB_ACE4_ID_SPECIAL; + switch (gace->aceWho) { + case ACE4_SPECIAL_OWNER: + smbace.who.special_id = SMB_ACE4_WHO_OWNER; + break; + case ACE4_SPECIAL_GROUP: + smbace.who.special_id = SMB_ACE4_WHO_GROUP; + break; + case ACE4_SPECIAL_EVERYONE: + smbace.who.special_id = SMB_ACE4_WHO_EVERYONE; + break; + default: + DEBUG(8, ("invalid special gpfs id %d " + "ignored\n", gace->aceWho)); + continue; /* don't add it */ + } + } else { + if (gace->aceFlags & ACE4_FLAG_GROUP_ID) + smbace.who.gid = gace->aceWho; + else + smbace.who.uid = gace->aceWho; + } + + smbace.aceType = gace->aceType; + smbace.aceFlags = gace->aceFlags; + smbace.aceMask = gace->aceMask; + smbace.flags = (gace->aceIFlags&ACE4_IFLAG_SPECIAL_ID) ? SMB_ACE4_ID_SPECIAL : 0; + + smb_add_ace4(*ppacl, &smbace); + } + + return True; +} + +static size_t gpfsacl_get_nt_acl_common(files_struct *fsp, + uint32 security_info, SEC_DESC **ppdesc) +{ + SMB4ACL_T *pacl = NULL; + BOOL result; + BOOL retryPosix = False; + + *ppdesc = NULL; + result = gpfs_get_nfs4_acl(fsp, &pacl, &retryPosix); + if (retryPosix) + { + DEBUG(10, ("retrying with posix acl...\n")); + return get_nt_acl(fsp, security_info, ppdesc); + } + if (result==False) + return 0; + + return smb_get_nt_acl_nfs4(fsp, security_info, ppdesc, pacl); +} + +size_t gpfsacl_fget_nt_acl(vfs_handle_struct *handle, + files_struct *fsp, int fd, uint32 security_info, + SEC_DESC **ppdesc) +{ + return gpfsacl_get_nt_acl_common(fsp, security_info, ppdesc); +} + +size_t gpfsacl_get_nt_acl(vfs_handle_struct *handle, + files_struct *fsp, const char *name, + uint32 security_info, SEC_DESC **ppdesc) +{ + return gpfsacl_get_nt_acl_common(fsp, security_info, ppdesc); +} + +static BOOL gpfsacl_process_smbacl(files_struct *fsp, SMB4ACL_T *smbacl) +{ + int ret; + gpfs_aclLen_t gacl_len; + SMB4ACE_T *smbace; + struct gpfs_acl *gacl; + TALLOC_CTX *mem_ctx = main_loop_talloc_get(); + + gacl_len = sizeof(struct gpfs_acl) + + (smb_get_naces(smbacl)-1)*sizeof(gpfs_ace_v4_t); + + gacl = talloc_size(mem_ctx, gacl_len); + if (gacl == NULL) { + DEBUG(0, ("talloc failed\n")); + errno = ENOMEM; + return False; + } + + gacl->acl_len = gacl_len; + gacl->acl_level = 0; + gacl->acl_version = GPFS_ACL_VERSION_NFS4; + gacl->acl_type = GPFS_ACL_TYPE_NFS4; + gacl->acl_nace = 0; /* change later... */ + + for (smbace=smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) { + struct gpfs_ace_v4 *gace = &gacl->ace_v4[gacl->acl_nace]; + SMB_ACE4PROP_T *aceprop = smb_get_ace4(smbace); + + gace->aceType = aceprop->aceType; + gace->aceFlags = aceprop->aceFlags; + gace->aceMask = aceprop->aceMask; + gace->aceIFlags = (aceprop->flags&SMB_ACE4_ID_SPECIAL) ? ACE4_IFLAG_SPECIAL_ID : 0; + + if (aceprop->flags&SMB_ACE4_ID_SPECIAL) + { + switch(aceprop->who.special_id) + { + case SMB_ACE4_WHO_EVERYONE: + gace->aceWho = ACE4_SPECIAL_EVERYONE; + break; + case SMB_ACE4_WHO_OWNER: + gace->aceWho = ACE4_SPECIAL_OWNER; + break; + case SMB_ACE4_WHO_GROUP: + gace->aceWho = ACE4_SPECIAL_GROUP; + break; + default: + DEBUG(8, ("unsupported special_id %d\n", aceprop->who.special_id)); + continue; /* don't add it !!! */ + } + } else { + /* just only for the type safety... */ + if (aceprop->aceFlags&SMB_ACE4_IDENTIFIER_GROUP) + gace->aceWho = aceprop->who.gid; + else + gace->aceWho = aceprop->who.uid; + } + + gacl->acl_nace++; + } + + ret = smbd_gpfs_putacl(fsp->fsp_name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl); + if (ret != 0) { + DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno))); + gpfs_dumpacl(8, gacl); + return False; + } + + DEBUG(10, ("gpfs_putacl succeeded\n")); + return True; +} + +static BOOL gpfsacl_set_nt_acl_internal(files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd) +{ + struct gpfs_acl *acl; + BOOL result = False; + + acl = gpfs_getacl_alloc(fsp->fsp_name, GPFS_ACL_TYPE_ACCESS); + if (acl == NULL) + return False; + + if (acl->acl_version&GPFS_ACL_VERSION_NFS4) + { + result = smb_set_nt_acl_nfs4( + fsp, security_info_sent, psd, + gpfsacl_process_smbacl); + } else { /* assume POSIX ACL - by default... */ + result = set_nt_acl(fsp, security_info_sent, psd); + } + + return result; +} + +static BOOL gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, int fd, uint32 security_info_sent, SEC_DESC *psd) +{ + return gpfsacl_set_nt_acl_internal(fsp, security_info_sent, psd); +} + +static BOOL gpfsacl_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, char *name, uint32 security_info_sent, SEC_DESC *psd) +{ + return gpfsacl_set_nt_acl_internal(fsp, security_info_sent, psd); +} + +static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl) +{ + SMB_ACL_T result; + int i; + + result = sys_acl_init(pacl->acl_nace); + if (result == NULL) { + errno = ENOMEM; + return NULL; + } + + result->count = pacl->acl_nace; + + for (i=0; i<pacl->acl_nace; i++) { + struct smb_acl_entry *ace = &result->acl[i]; + const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i]; + + DEBUG(10, ("Converting type %d id %lu perm %x\n", + (int)g_ace->ace_type, (unsigned long)g_ace->ace_who, + (int)g_ace->ace_perm)); + + switch (g_ace->ace_type) { + case GPFS_ACL_USER: + ace->a_type = SMB_ACL_USER; + ace->uid = (uid_t)g_ace->ace_who; + break; + case GPFS_ACL_USER_OBJ: + ace->a_type = SMB_ACL_USER_OBJ; + break; + case GPFS_ACL_GROUP: + ace->a_type = SMB_ACL_GROUP; + ace->gid = (gid_t)g_ace->ace_who; + break; + case GPFS_ACL_GROUP_OBJ: + ace->a_type = SMB_ACL_GROUP_OBJ; + break; + case GPFS_ACL_OTHER: + ace->a_type = SMB_ACL_OTHER; + break; + case GPFS_ACL_MASK: + ace->a_type = SMB_ACL_MASK; + break; + default: + DEBUG(10, ("Got invalid ace_type: %d\n", + g_ace->ace_type)); + errno = EINVAL; + SAFE_FREE(result); + return NULL; + } + + ace->a_perm = 0; + ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ? + SMB_ACL_READ : 0; + ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ? + SMB_ACL_WRITE : 0; + ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ? + SMB_ACL_EXECUTE : 0; + + DEBUGADD(10, ("Converted to %d perm %x\n", + ace->a_type, ace->a_perm)); + } + + return result; +} + +static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type) +{ + struct gpfs_acl *pacl; + SMB_ACL_T result = NULL; + + pacl = gpfs_getacl_alloc(path, type); + + if (pacl == NULL) { + DEBUG(10, ("gpfs_getacl failed for %s with %s\n", + path, strerror(errno))); + if (errno == 0) { + errno = EINVAL; + } + goto done; + } + + if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) { + DEBUG(10, ("Got acl version %d, expected %d\n", + pacl->acl_version, GPFS_ACL_VERSION_POSIX)); + errno = EINVAL; + goto done; + } + + DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n", + pacl->acl_len, pacl->acl_level, pacl->acl_version, + pacl->acl_nace)); + + result = gpfs2smb_acl(pacl); + if (result == NULL) { + goto done; + } + + done: + + if (errno != 0) { + SAFE_FREE(result); + } + return result; +} + +SMB_ACL_T gpfsacl_sys_acl_get_file(vfs_handle_struct *handle, + + const char *path_p, + SMB_ACL_TYPE_T type) +{ + gpfs_aclType_t gpfs_type; + + switch(type) { + case SMB_ACL_TYPE_ACCESS: + gpfs_type = GPFS_ACL_TYPE_ACCESS; + break; + case SMB_ACL_TYPE_DEFAULT: + gpfs_type = GPFS_ACL_TYPE_DEFAULT; + break; + default: + DEBUG(0, ("Got invalid type: %d\n", type)); + smb_panic("exiting"); + } + + return gpfsacl_get_posix_acl(path_p, gpfs_type); +} + +SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle, + files_struct *fsp, + int fd) +{ + return gpfsacl_get_posix_acl(fsp->fsp_name, GPFS_ACL_TYPE_ACCESS); +} + +static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl, + SMB_ACL_TYPE_T type) +{ + gpfs_aclLen_t len; + struct gpfs_acl *result; + int i; + union gpfs_ace_union + { + gpfs_ace_v1_t ace_v1[1]; /* when GPFS_ACL_VERSION_POSIX */ + gpfs_ace_v4_t ace_v4[1]; /* when GPFS_ACL_VERSION_NFS4 */ + }; + + DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count)); + + len = sizeof(struct gpfs_acl) - sizeof(union gpfs_ace_union) + + (pacl->count)*sizeof(gpfs_ace_v1_t); + + result = SMB_MALLOC(len); + if (result == NULL) { + errno = ENOMEM; + return result; + } + + result->acl_len = len; + result->acl_level = 0; + result->acl_version = GPFS_ACL_VERSION_POSIX; + result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ? + GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS; + result->acl_nace = pacl->count; + + for (i=0; i<pacl->count; i++) { + const struct smb_acl_entry *ace = &pacl->acl[i]; + struct gpfs_ace_v1 *g_ace = &result->ace_v1[i]; + + DEBUG(10, ("Converting type %d perm %x\n", + (int)ace->a_type, (int)ace->a_perm)); + + g_ace->ace_perm = 0; + + switch(ace->a_type) { + case SMB_ACL_USER: + g_ace->ace_type = GPFS_ACL_USER; + g_ace->ace_who = (gpfs_uid_t)ace->uid; + break; + case SMB_ACL_USER_OBJ: + g_ace->ace_type = GPFS_ACL_USER_OBJ; + g_ace->ace_perm |= ACL_PERM_CONTROL; + g_ace->ace_who = 0; + break; + case SMB_ACL_GROUP: + g_ace->ace_type = GPFS_ACL_GROUP; + g_ace->ace_who = (gpfs_uid_t)ace->gid; + break; + case SMB_ACL_GROUP_OBJ: + g_ace->ace_type = GPFS_ACL_GROUP_OBJ; + g_ace->ace_who = 0; + break; + case SMB_ACL_MASK: + g_ace->ace_type = GPFS_ACL_MASK; + g_ace->ace_perm = 0x8f; + g_ace->ace_who = 0; + break; + case SMB_ACL_OTHER: + g_ace->ace_type = GPFS_ACL_OTHER; + g_ace->ace_who = 0; + break; + default: + DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type)); + errno = EINVAL; + SAFE_FREE(result); + return NULL; + } + + g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ? + ACL_PERM_READ : 0; + g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ? + ACL_PERM_WRITE : 0; + g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ? + ACL_PERM_EXECUTE : 0; + + DEBUGADD(10, ("Converted to %d id %d perm %x\n", + g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm)); + } + + return result; +} + +int gpfsacl_sys_acl_set_file(vfs_handle_struct *handle, + + const char *name, + SMB_ACL_TYPE_T type, + SMB_ACL_T theacl) +{ + struct gpfs_acl *gpfs_acl; + int result; + + gpfs_acl = smb2gpfs_acl(theacl, type); + if (gpfs_acl == NULL) { + return -1; + } + + result = smbd_gpfs_putacl((char *)name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gpfs_acl); + + SAFE_FREE(gpfs_acl); + return result; +} + +int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle, + files_struct *fsp, + int fd, SMB_ACL_T theacl) +{ + errno = ENOTSUP; + return -1; +} + +int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct *handle, + + const char *path) +{ + errno = ENOTSUP; + return -1; +} + +/* VFS operations structure */ + +static vfs_op_tuple gpfs_op_tuples[] = { + + {SMB_VFS_OP(vfs_gpfs_kernel_flock), + SMB_VFS_OP_KERNEL_FLOCK, + SMB_VFS_LAYER_OPAQUE}, + + {SMB_VFS_OP(vfs_gpfs_setlease), + SMB_VFS_OP_LINUX_SETLEASE, + SMB_VFS_LAYER_OPAQUE}, + + {SMB_VFS_OP(gpfsacl_fget_nt_acl), + SMB_VFS_OP_FGET_NT_ACL, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(gpfsacl_get_nt_acl), + SMB_VFS_OP_GET_NT_ACL, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(gpfsacl_fset_nt_acl), + SMB_VFS_OP_FSET_NT_ACL, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(gpfsacl_set_nt_acl), + SMB_VFS_OP_SET_NT_ACL, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(gpfsacl_sys_acl_get_file), + SMB_VFS_OP_SYS_ACL_GET_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(gpfsacl_sys_acl_get_fd), + SMB_VFS_OP_SYS_ACL_GET_FD, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(gpfsacl_sys_acl_set_file), + SMB_VFS_OP_SYS_ACL_SET_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(gpfsacl_sys_acl_set_fd), + SMB_VFS_OP_SYS_ACL_SET_FD, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(gpfsacl_sys_acl_delete_def_file), + SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(NULL), + SMB_VFS_OP_NOOP, + SMB_VFS_LAYER_NOOP} + +}; + + +NTSTATUS vfs_gpfs_init(void); +NTSTATUS vfs_gpfs_init(void) +{ + init_gpfs(); + + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs", + gpfs_op_tuples); +} diff --git a/source/modules/vfs_hpuxacl.c b/source/modules/vfs_hpuxacl.c new file mode 100644 index 00000000000..aeb078c32dc --- /dev/null +++ b/source/modules/vfs_hpuxacl.c @@ -0,0 +1,105 @@ +/* + Unix SMB/Netbios implementation. + VFS module to get and set hpux acls + Copyright (C) Michael Adam 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/* prototypes for private functions first - for clarity */ + +/* public functions - the api */ + +SMB_ACL_T hpuxacl_sys_acl_get_file(vfs_handle_struct *handle, + const char *path_p, + SMB_ACL_TYPE_T type) +{ + errno = ENOTSUP; + return NULL; +} + +SMB_ACL_T hpuxacl_sys_acl_get_fd(vfs_handle_struct *handle, + files_struct *fsp, + int fd) +{ + errno = ENOTSUP; + return NULL; +} + +int hpuxacl_sys_acl_set_file(vfs_handle_struct *handle, + const char *name, + SMB_ACL_TYPE_T type, + SMB_ACL_T theacl) +{ + errno = ENOTSUP; + return -1; +} + +int hpuxacl_sys_acl_set_fd(vfs_handle_struct *handle, + files_struct *fsp, + int fd, SMB_ACL_T theacl) +{ + errno = ENOTSUP; + return -1; +} + +int hpuxacl_sys_acl_delete_def_file(vfs_handle_struct *handle, + const char *path) +{ + errno = ENOTSUP; + return -1; +} + +/* private functions */ + +/* VFS operations structure */ + +static vfs_op_tuple hpuxacl_op_tuples[] = { + /* Disk operations */ + {SMB_VFS_OP(hpuxacl_sys_acl_get_file), + SMB_VFS_OP_SYS_ACL_GET_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(hpuxacl_sys_acl_get_fd), + SMB_VFS_OP_SYS_ACL_GET_FD, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(hpuxacl_sys_acl_set_file), + SMB_VFS_OP_SYS_ACL_SET_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(hpuxacl_sys_acl_set_fd), + SMB_VFS_OP_SYS_ACL_SET_FD, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(hpuxacl_sys_acl_delete_def_file), + SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(NULL), + SMB_VFS_OP_NOOP, + SMB_VFS_LAYER_NOOP} +}; + +NTSTATUS vfs_hpuxacl_init(void); +NTSTATUS vfs_hpuxacl_init(void) +{ + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "hpuxacl", + hpuxacl_op_tuples); +} + +/* ENTE */ diff --git a/source/modules/vfs_irixacl.c b/source/modules/vfs_irixacl.c new file mode 100644 index 00000000000..d80b34b24b1 --- /dev/null +++ b/source/modules/vfs_irixacl.c @@ -0,0 +1,105 @@ +/* + Unix SMB/Netbios implementation. + VFS module to get and set irix acls + Copyright (C) Michael Adam 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/* prototypes for private functions first - for clarity */ + +/* public functions - the api */ + +SMB_ACL_T irixacl_sys_acl_get_file(vfs_handle_struct *handle, + const char *path_p, + SMB_ACL_TYPE_T type) +{ + errno = ENOTSUP; + return NULL; +} + +SMB_ACL_T irixacl_sys_acl_get_fd(vfs_handle_struct *handle, + files_struct *fsp, + int fd) +{ + errno = ENOTSUP; + return NULL; +} + +int irixacl_sys_acl_set_file(vfs_handle_struct *handle, + const char *name, + SMB_ACL_TYPE_T type, + SMB_ACL_T theacl) +{ + errno = ENOTSUP; + return -1; +} + +int irixacl_sys_acl_set_fd(vfs_handle_struct *handle, + files_struct *fsp, + int fd, SMB_ACL_T theacl) +{ + errno = ENOTSUP; + return -1; +} + +int irixacl_sys_acl_delete_def_file(vfs_handle_struct *handle, + const char *path) +{ + errno = ENOTSUP; + return -1; +} + +/* private functions */ + +/* VFS operations structure */ + +static vfs_op_tuple irixacl_op_tuples[] = { + /* Disk operations */ + {SMB_VFS_OP(irixacl_sys_acl_get_file), + SMB_VFS_OP_SYS_ACL_GET_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(irixacl_sys_acl_get_fd), + SMB_VFS_OP_SYS_ACL_GET_FD, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(irixacl_sys_acl_set_file), + SMB_VFS_OP_SYS_ACL_SET_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(irixacl_sys_acl_set_fd), + SMB_VFS_OP_SYS_ACL_SET_FD, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(irixacl_sys_acl_delete_def_file), + SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(NULL), + SMB_VFS_OP_NOOP, + SMB_VFS_LAYER_NOOP} +}; + +NTSTATUS vfs_irixacl_init(void); +NTSTATUS vfs_irixacl_init(void) +{ + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "irixacl", + irixacl_op_tuples); +} + +/* ENTE */ diff --git a/source/modules/vfs_netatalk.c b/source/modules/vfs_netatalk.c index e9d4360cd80..7176919a7dc 100644 --- a/source/modules/vfs_netatalk.c +++ b/source/modules/vfs_netatalk.c @@ -172,11 +172,11 @@ static void atalk_rrmdir(TALLOC_CTX *ctx, char *path) /* Directory operations */ -SMB_STRUCT_DIR *atalk_opendir(struct vfs_handle_struct *handle, struct connection_struct *conn, const char *fname, const char *mask, uint32 attr) +static SMB_STRUCT_DIR *atalk_opendir(struct vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr) { SMB_STRUCT_DIR *ret = 0; - ret = SMB_VFS_NEXT_OPENDIR(handle, conn, fname, mask, attr); + ret = SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr); /* * when we try to perform delete operation upon file which has fork @@ -187,19 +187,19 @@ SMB_STRUCT_DIR *atalk_opendir(struct vfs_handle_struct *handle, struct connectio * list then it would be nice to add one. */ - atalk_add_to_list(&conn->hide_list); - atalk_add_to_list(&conn->veto_list); + atalk_add_to_list(&handle->conn->hide_list); + atalk_add_to_list(&handle->conn->veto_list); return ret; } -static int atalk_rmdir(struct vfs_handle_struct *handle, struct connection_struct *conn, const char *path) +static int atalk_rmdir(struct vfs_handle_struct *handle, const char *path) { BOOL add = False; TALLOC_CTX *ctx = 0; char *dpath; - if (!conn || !conn->origpath || !path) goto exit_rmdir; + if (!handle->conn->origpath || !path) goto exit_rmdir; /* due to there is no way to change bDeleteVetoFiles variable * from this module, gotta use talloc stuff.. @@ -211,19 +211,19 @@ static int atalk_rmdir(struct vfs_handle_struct *handle, struct connection_struc goto exit_rmdir; if (!(dpath = talloc_asprintf(ctx, "%s/%s%s", - conn->origpath, path, add ? "/"APPLEDOUBLE : ""))) + handle->conn->origpath, path, add ? "/"APPLEDOUBLE : ""))) goto exit_rmdir; atalk_rrmdir(ctx, dpath); exit_rmdir: talloc_destroy(ctx); - return SMB_VFS_NEXT_RMDIR(handle, conn, path); + return SMB_VFS_NEXT_RMDIR(handle, path); } /* File operations */ -static int atalk_rename(struct vfs_handle_struct *handle, struct connection_struct *conn, const char *oldname, const char *newname) +static int atalk_rename(struct vfs_handle_struct *handle, const char *oldname, const char *newname) { int ret = 0; char *adbl_path = 0; @@ -232,14 +232,14 @@ static int atalk_rename(struct vfs_handle_struct *handle, struct connection_stru SMB_STRUCT_STAT orig_info; TALLOC_CTX *ctx; - ret = SMB_VFS_NEXT_RENAME(handle, conn, oldname, newname); + ret = SMB_VFS_NEXT_RENAME(handle, oldname, newname); - if (!conn || !oldname) return ret; + if (!oldname) return ret; if (!(ctx = talloc_init("rename_file"))) return ret; - if (atalk_build_paths(ctx, conn->origpath, oldname, &adbl_path, &orig_path, + if (atalk_build_paths(ctx, handle->conn->origpath, oldname, &adbl_path, &orig_path, &adbl_info, &orig_info) != 0) return ret; @@ -255,7 +255,7 @@ exit_rename: return ret; } -static int atalk_unlink(struct vfs_handle_struct *handle, struct connection_struct *conn, const char *path) +static int atalk_unlink(struct vfs_handle_struct *handle, const char *path) { int ret = 0, i; char *adbl_path = 0; @@ -264,25 +264,25 @@ static int atalk_unlink(struct vfs_handle_struct *handle, struct connection_stru SMB_STRUCT_STAT orig_info; TALLOC_CTX *ctx; - ret = SMB_VFS_NEXT_UNLINK(handle, conn, path); + ret = SMB_VFS_NEXT_UNLINK(handle, path); - if (!conn || !path) return ret; + if (!path) return ret; /* no .AppleDouble sync if veto or hide list is empty, * otherwise "Cannot find the specified file" error will be caused */ - if (!conn->veto_list) return ret; - if (!conn->hide_list) return ret; + if (!handle->conn->veto_list) return ret; + if (!handle->conn->hide_list) return ret; - for (i = 0; conn->veto_list[i].name; i ++) { - if (strstr(conn->veto_list[i].name, APPLEDOUBLE)) + for (i = 0; handle->conn->veto_list[i].name; i ++) { + if (strstr(handle->conn->veto_list[i].name, APPLEDOUBLE)) break; } - if (!conn->veto_list[i].name) { - for (i = 0; conn->hide_list[i].name; i ++) { - if (strstr(conn->hide_list[i].name, APPLEDOUBLE)) + if (!handle->conn->veto_list[i].name) { + for (i = 0; handle->conn->hide_list[i].name; i ++) { + if (strstr(handle->conn->hide_list[i].name, APPLEDOUBLE)) break; else { DEBUG(3, ("ATALK: %s is not hidden, skipped..\n", @@ -295,7 +295,7 @@ static int atalk_unlink(struct vfs_handle_struct *handle, struct connection_stru if (!(ctx = talloc_init("unlink_file"))) return ret; - if (atalk_build_paths(ctx, conn->origpath, path, &adbl_path, &orig_path, + if (atalk_build_paths(ctx, handle->conn->origpath, path, &adbl_path, &orig_path, &adbl_info, &orig_info) != 0) return ret; @@ -311,7 +311,7 @@ exit_unlink: return ret; } -static int atalk_chmod(struct vfs_handle_struct *handle, struct connection_struct *conn, const char *path, mode_t mode) +static int atalk_chmod(struct vfs_handle_struct *handle, const char *path, mode_t mode) { int ret = 0; char *adbl_path = 0; @@ -320,14 +320,14 @@ static int atalk_chmod(struct vfs_handle_struct *handle, struct connection_struc SMB_STRUCT_STAT orig_info; TALLOC_CTX *ctx; - ret = SMB_VFS_NEXT_CHMOD(handle, conn, path, mode); + ret = SMB_VFS_NEXT_CHMOD(handle, path, mode); - if (!conn || !path) return ret; + if (!path) return ret; if (!(ctx = talloc_init("chmod_file"))) return ret; - if (atalk_build_paths(ctx, conn->origpath, path, &adbl_path, &orig_path, + if (atalk_build_paths(ctx, handle->conn->origpath, path, &adbl_path, &orig_path, &adbl_info, &orig_info) != 0) return ret; @@ -343,7 +343,7 @@ exit_chmod: return ret; } -static int atalk_chown(struct vfs_handle_struct *handle, struct connection_struct *conn, const char *path, uid_t uid, gid_t gid) +static int atalk_chown(struct vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid) { int ret = 0; char *adbl_path = 0; @@ -352,14 +352,14 @@ static int atalk_chown(struct vfs_handle_struct *handle, struct connection_struc SMB_STRUCT_STAT orig_info; TALLOC_CTX *ctx; - ret = SMB_VFS_NEXT_CHOWN(handle, conn, path, uid, gid); + ret = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid); - if (!conn || !path) return ret; + if (!path) return ret; if (!(ctx = talloc_init("chown_file"))) return ret; - if (atalk_build_paths(ctx, conn->origpath, path, &adbl_path, &orig_path, + if (atalk_build_paths(ctx, handle->conn->origpath, path, &adbl_path, &orig_path, &adbl_info, &orig_info) != 0) return ret; @@ -394,6 +394,7 @@ static vfs_op_tuple atalk_ops[] = { {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} }; +NTSTATUS vfs_netatalk_init(void); NTSTATUS vfs_netatalk_init(void) { return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "netatalk", atalk_ops); diff --git a/source/modules/vfs_notify_fam.c b/source/modules/vfs_notify_fam.c new file mode 100644 index 00000000000..b76046b3789 --- /dev/null +++ b/source/modules/vfs_notify_fam.c @@ -0,0 +1,302 @@ +/* + * FAM file notification support. + * + * Copyright (c) James Peach 2005 + * Copyright (c) Volker Lendecke 2007 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "includes.h" + +#include <fam.h> + +#if !defined(HAVE_FAM_H_FAMCODES_TYPEDEF) +/* Gamin provides this typedef which means we can't use 'enum FAMCodes' as per + * every other FAM implementation. Phooey. + */ +typedef enum FAMCodes FAMCodes; +#endif + +/* NOTE: There are multiple versions of FAM floating around the net, each with + * slight differences from the original SGI FAM implementation. In this file, + * we rely only on the SGI features and do not assume any extensions. For + * example, we do not look at FAMErrno, because it is not set by the original + * implementation. + * + * Random FAM links: + * http://oss.sgi.com/projects/fam/ + * http://savannah.nongnu.org/projects/fam/ + * http://sourceforge.net/projects/bsdfam/ + */ + +/* ------------------------------------------------------------------------- */ + +struct fam_watch_context { + struct fam_watch_context *prev, *next; + FAMConnection *fam_connection; + struct FAMRequest fr; + struct sys_notify_context *sys_ctx; + void (*callback)(struct sys_notify_context *ctx, + void *private_data, + struct notify_event *ev); + void *private_data; + uint32_t mask; /* the inotify mask */ + uint32_t filter; /* the windows completion filter */ + const char *path; +}; + + +/* + * We want one FAM connection per smbd, not one per tcon. + */ +static FAMConnection fam_connection; +static BOOL fam_connection_initialized = False; + +static struct fam_watch_context *fam_notify_list; +static void fam_handler(struct event_context *event_ctx, + struct fd_event *fd_event, + uint16 flags, + void *private_data); + +static NTSTATUS fam_open_connection(FAMConnection *fam_conn, + struct event_context *event_ctx) +{ + int res; + char *name; + + ZERO_STRUCTP(fam_conn); + FAMCONNECTION_GETFD(fam_conn) = -1; + + if (asprintf(&name, "smbd (%lu)", (unsigned long)sys_getpid()) == -1) { + DEBUG(0, ("No memory\n")); + return NT_STATUS_NO_MEMORY; + } + + res = FAMOpen2(fam_conn, name); + SAFE_FREE(name); + + if (res < 0) { + DEBUG(10, ("FAM file change notifications not available\n")); + /* + * No idea how to get NT_STATUS from a FAM result + */ + FAMCONNECTION_GETFD(fam_conn) = -1; + return NT_STATUS_UNEXPECTED_IO_ERROR; + } + + if (event_add_fd(event_ctx, event_ctx, + FAMCONNECTION_GETFD(fam_conn), + EVENT_FD_READ, fam_handler, + (void *)fam_conn) == NULL) { + DEBUG(0, ("event_add_fd failed\n")); + FAMClose(fam_conn); + FAMCONNECTION_GETFD(fam_conn) = -1; + return NT_STATUS_NO_MEMORY; + } + + return NT_STATUS_OK; +} + +static void fam_reopen(FAMConnection *fam_conn, + struct event_context *event_ctx, + struct fam_watch_context *notify_list) +{ + struct fam_watch_context *ctx; + + DEBUG(5, ("Re-opening FAM connection\n")); + + FAMClose(fam_conn); + + if (!NT_STATUS_IS_OK(fam_open_connection(fam_conn, event_ctx))) { + DEBUG(5, ("Re-opening fam connection failed\n")); + return; + } + + for (ctx = notify_list; ctx; ctx = ctx->next) { + FAMMonitorDirectory(fam_conn, ctx->path, &ctx->fr, NULL); + } +} + +static void fam_handler(struct event_context *event_ctx, + struct fd_event *fd_event, + uint16 flags, + void *private_data) +{ + FAMConnection *fam_conn = (FAMConnection *)private_data; + FAMEvent fam_event; + struct fam_watch_context *ctx; + struct notify_event ne; + + if (FAMPending(fam_conn) == 0) { + DEBUG(10, ("fam_handler called but nothing pending\n")); + return; + } + + if (FAMNextEvent(fam_conn, &fam_event) != 1) { + DEBUG(5, ("FAMNextEvent returned an error\n")); + TALLOC_FREE(fd_event); + fam_reopen(fam_conn, event_ctx, fam_notify_list); + return; + } + + DEBUG(10, ("Got FAMCode %d for %s\n", fam_event.code, + fam_event.filename)); + + switch (fam_event.code) { + case FAMCreated: + ne.action = NOTIFY_ACTION_ADDED; + break; + case FAMDeleted: + ne.action = NOTIFY_ACTION_REMOVED; + break; + default: + DEBUG(10, ("Ignoring code FAMCode %d for file %s\n", + (int)fam_event.code, fam_event.filename)); + return; + } + + for (ctx = fam_notify_list; ctx; ctx = ctx->next) { + if (memcmp(&fam_event.fr, &ctx->fr, sizeof(FAMRequest)) == 0) { + break; + } + } + + if (ctx == NULL) { + DEBUG(5, ("Discarding event for file %s\n", + fam_event.filename)); + return; + } + + if ((ne.path = strrchr_m(fam_event.filename, '\\')) == NULL) { + ne.path = fam_event.filename; + } + + ctx->callback(ctx->sys_ctx, ctx->private_data, &ne); +} + +static int fam_watch_context_destructor(struct fam_watch_context *ctx) +{ + if (FAMCONNECTION_GETFD(ctx->fam_connection) != -1) { + FAMCancelMonitor(&fam_connection, &ctx->fr); + } + DLIST_REMOVE(fam_notify_list, ctx); + return 0; +} + +/* + add a watch. The watch is removed when the caller calls + talloc_free() on *handle +*/ +static NTSTATUS fam_watch(vfs_handle_struct *vfs_handle, + struct sys_notify_context *ctx, + struct notify_entry *e, + void (*callback)(struct sys_notify_context *ctx, + void *private_data, + struct notify_event *ev), + void *private_data, + void *handle_p) +{ + const uint32 fam_mask = (FILE_NOTIFY_CHANGE_FILE_NAME| + FILE_NOTIFY_CHANGE_DIR_NAME); + struct fam_watch_context *watch; + void **handle = (void **)handle_p; + + if ((e->filter & fam_mask) == 0) { + DEBUG(10, ("filter = %u, ignoring in FAM\n", e->filter)); + return NT_STATUS_OK; + } + + if (!fam_connection_initialized) { + if (!NT_STATUS_IS_OK(fam_open_connection(&fam_connection, + ctx->ev))) { + /* + * Just let smbd do all the work itself + */ + return NT_STATUS_OK; + } + fam_connection_initialized = True; + } + + if (!(watch = TALLOC_P(ctx, struct fam_watch_context))) { + return NT_STATUS_NO_MEMORY; + } + + watch->fam_connection = &fam_connection; + + watch->callback = callback; + watch->private_data = private_data; + watch->sys_ctx = ctx; + + if (!(watch->path = talloc_strdup(watch, e->path))) { + DEBUG(0, ("talloc_asprintf failed\n")); + TALLOC_FREE(watch); + return NT_STATUS_NO_MEMORY; + } + + /* + * The FAM module in this early state will only take care of + * FAMCreated and FAMDeleted events, Leave the rest to + * notify_internal.c + */ + + watch->filter = fam_mask; + e->filter &= ~fam_mask; + + DLIST_ADD(fam_notify_list, watch); + talloc_set_destructor(watch, fam_watch_context_destructor); + + /* + * Only directories monitored so far + */ + + if (FAMCONNECTION_GETFD(watch->fam_connection) != -1) { + FAMMonitorDirectory(watch->fam_connection, watch->path, + &watch->fr, NULL); + } + else { + /* + * If the re-open is successful, this will establish the + * FAMMonitor from the list + */ + fam_reopen(watch->fam_connection, ctx->ev, fam_notify_list); + } + + *handle = (void *)watch; + + return NT_STATUS_OK; +} + +/* VFS operations structure */ + +static vfs_op_tuple notify_fam_op_tuples[] = { + + {SMB_VFS_OP(fam_watch), + SMB_VFS_OP_NOTIFY_WATCH, + SMB_VFS_LAYER_OPAQUE}, + + {SMB_VFS_OP(NULL), + SMB_VFS_OP_NOOP, + SMB_VFS_LAYER_NOOP} + +}; + + +NTSTATUS vfs_notify_fam_init(void); +NTSTATUS vfs_notify_fam_init(void) +{ + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "notify_fam", + notify_fam_op_tuples); +} diff --git a/source/modules/vfs_posixacl.c b/source/modules/vfs_posixacl.c new file mode 100644 index 00000000000..191c4a7cb0e --- /dev/null +++ b/source/modules/vfs_posixacl.c @@ -0,0 +1,392 @@ +/* + Unix SMB/Netbios implementation. + VFS module to get and set posix acls + Copyright (C) Volker Lendecke 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + + +/* prototypes for static functions first - for clarity */ + +static BOOL smb_ace_to_internal(acl_entry_t posix_ace, + struct smb_acl_entry *ace); +static struct smb_acl_t *smb_acl_to_internal(acl_t acl); +static int smb_acl_set_mode(acl_entry_t entry, SMB_ACL_PERM_T perm); +static acl_t smb_acl_to_posix(const struct smb_acl_t *acl); + + +/* public functions - the api */ + +SMB_ACL_T posixacl_sys_acl_get_file(vfs_handle_struct *handle, + const char *path_p, + SMB_ACL_TYPE_T type) +{ + struct smb_acl_t *result; + acl_type_t acl_type; + acl_t acl; + + switch(type) { + case SMB_ACL_TYPE_ACCESS: + acl_type = ACL_TYPE_ACCESS; + break; + case SMB_ACL_TYPE_DEFAULT: + acl_type = ACL_TYPE_DEFAULT; + break; + default: + errno = EINVAL; + return NULL; + } + + acl = acl_get_file(path_p, acl_type); + + if (acl == NULL) { + return NULL; + } + + result = smb_acl_to_internal(acl); + acl_free(acl); + return result; +} + +SMB_ACL_T posixacl_sys_acl_get_fd(vfs_handle_struct *handle, + files_struct *fsp, + int fd) +{ + struct smb_acl_t *result; + acl_t acl = acl_get_fd(fd); + + if (acl == NULL) { + return NULL; + } + + result = smb_acl_to_internal(acl); + acl_free(acl); + return result; +} + +int posixacl_sys_acl_set_file(vfs_handle_struct *handle, + const char *name, + SMB_ACL_TYPE_T type, + SMB_ACL_T theacl) +{ + int res; + acl_type_t acl_type; + acl_t acl; + + DEBUG(10, ("Calling acl_set_file: %s, %d\n", name, type)); + + switch(type) { + case SMB_ACL_TYPE_ACCESS: + acl_type = ACL_TYPE_ACCESS; + break; + case SMB_ACL_TYPE_DEFAULT: + acl_type = ACL_TYPE_DEFAULT; + break; + default: + errno = EINVAL; + return -1; + } + + if ((acl = smb_acl_to_posix(theacl)) == NULL) { + return -1; + } + res = acl_set_file(name, acl_type, acl); + if (res != 0) { + DEBUG(10, ("acl_set_file failed: %s\n", strerror(errno))); + } + acl_free(acl); + return res; +} + +int posixacl_sys_acl_set_fd(vfs_handle_struct *handle, + files_struct *fsp, + int fd, SMB_ACL_T theacl) +{ + int res; + acl_t acl = smb_acl_to_posix(theacl); + if (acl == NULL) { + return -1; + } + res = acl_set_fd(fd, acl); + acl_free(acl); + return res; +} + +int posixacl_sys_acl_delete_def_file(vfs_handle_struct *handle, + const char *path) +{ + return acl_delete_def_file(path); +} + + +/* private functions */ + +static BOOL smb_ace_to_internal(acl_entry_t posix_ace, + struct smb_acl_entry *ace) +{ + acl_tag_t tag; + acl_permset_t permset; + + if (acl_get_tag_type(posix_ace, &tag) != 0) { + DEBUG(0, ("smb_acl_get_tag_type failed\n")); + return False; + } + + switch(tag) { + case ACL_USER: + ace->a_type = SMB_ACL_USER; + break; + case ACL_USER_OBJ: + ace->a_type = SMB_ACL_USER_OBJ; + break; + case ACL_GROUP: + ace->a_type = SMB_ACL_GROUP; + break; + case ACL_GROUP_OBJ: + ace->a_type = SMB_ACL_GROUP_OBJ; + break; + case ACL_OTHER: + ace->a_type = SMB_ACL_OTHER; + break; + case ACL_MASK: + ace->a_type = SMB_ACL_MASK; + break; + default: + DEBUG(0, ("unknown tag type %d\n", (unsigned int)tag)); + return False; + } + switch(ace->a_type) { + case SMB_ACL_USER: { + uid_t *puid = (uid_t *)acl_get_qualifier(posix_ace); + if (puid == NULL) { + DEBUG(0, ("smb_acl_get_qualifier failed\n")); + return False; + } + ace->uid = *puid; + acl_free(puid); + break; + } + + case SMB_ACL_GROUP: { + gid_t *pgid = (uid_t *)acl_get_qualifier(posix_ace); + if (pgid == NULL) { + DEBUG(0, ("smb_acl_get_qualifier failed\n")); + return False; + } + ace->gid = *pgid; + acl_free(pgid); + break; + } + default: + break; + } + if (acl_get_permset(posix_ace, &permset) != 0) { + DEBUG(0, ("smb_acl_get_mode failed\n")); + return False; + } + ace->a_perm = 0; + ace->a_perm |= (acl_get_perm(permset, ACL_READ) ? SMB_ACL_READ : 0); + ace->a_perm |= (acl_get_perm(permset, ACL_WRITE) ? SMB_ACL_WRITE : 0); + ace->a_perm |= (acl_get_perm(permset, ACL_EXECUTE) ? SMB_ACL_EXECUTE : 0); + return True; +} + +static struct smb_acl_t *smb_acl_to_internal(acl_t acl) +{ + struct smb_acl_t *result = SMB_MALLOC_P(struct smb_acl_t); + int entry_id = ACL_FIRST_ENTRY; + acl_entry_t e; + if (result == NULL) { + return NULL; + } + ZERO_STRUCTP(result); + while (acl_get_entry(acl, entry_id, &e) == 1) { + + entry_id = ACL_NEXT_ENTRY; + + result = (struct smb_acl_t *)SMB_REALLOC( + result, sizeof(struct smb_acl_t) + + (sizeof(struct smb_acl_entry) * (result->count+1))); + if (result == NULL) { + DEBUG(0, ("SMB_REALLOC failed\n")); + errno = ENOMEM; + return NULL; + } + + if (!smb_ace_to_internal(e, &result->acl[result->count])) { + SAFE_FREE(result); + return NULL; + } + + result->count += 1; + } + return result; +} + +static int smb_acl_set_mode(acl_entry_t entry, SMB_ACL_PERM_T perm) +{ + int ret; + acl_permset_t permset; + + if ((ret = acl_get_permset(entry, &permset)) != 0) { + return ret; + } + if ((ret = acl_clear_perms(permset)) != 0) { + return ret; + } + if ((perm & SMB_ACL_READ) && + ((ret = acl_add_perm(permset, ACL_READ)) != 0)) { + return ret; + } + if ((perm & SMB_ACL_WRITE) && + ((ret = acl_add_perm(permset, ACL_WRITE)) != 0)) { + return ret; + } + if ((perm & SMB_ACL_EXECUTE) && + ((ret = acl_add_perm(permset, ACL_EXECUTE)) != 0)) { + return ret; + } + return acl_set_permset(entry, permset); +} + +static acl_t smb_acl_to_posix(const struct smb_acl_t *acl) +{ + acl_t result; + int i; + + result = acl_init(acl->count); + if (result == NULL) { + DEBUG(10, ("acl_init failed\n")); + return NULL; + } + + for (i=0; i<acl->count; i++) { + const struct smb_acl_entry *entry = &acl->acl[i]; + acl_entry_t e; + acl_tag_t tag; + + if (acl_create_entry(&result, &e) != 0) { + DEBUG(1, ("acl_create_entry failed: %s\n", + strerror(errno))); + goto fail; + } + + switch (entry->a_type) { + case SMB_ACL_USER: + tag = ACL_USER; + break; + case SMB_ACL_USER_OBJ: + tag = ACL_USER_OBJ; + break; + case SMB_ACL_GROUP: + tag = ACL_GROUP; + break; + case SMB_ACL_GROUP_OBJ: + tag = ACL_GROUP_OBJ; + break; + case SMB_ACL_OTHER: + tag = ACL_OTHER; + break; + case SMB_ACL_MASK: + tag = ACL_MASK; + break; + default: + DEBUG(1, ("Unknown tag value %d\n", entry->a_type)); + goto fail; + } + + if (acl_set_tag_type(e, tag) != 0) { + DEBUG(10, ("acl_set_tag_type(%d) failed: %s\n", + tag, strerror(errno))); + goto fail; + } + + switch (entry->a_type) { + case SMB_ACL_USER: + if (acl_set_qualifier(e, &entry->uid) != 0) { + DEBUG(1, ("acl_set_qualifiier failed: %s\n", + strerror(errno))); + goto fail; + } + break; + case SMB_ACL_GROUP: + if (acl_set_qualifier(e, &entry->gid) != 0) { + DEBUG(1, ("acl_set_qualifiier failed: %s\n", + strerror(errno))); + goto fail; + } + break; + default: /* Shut up, compiler! :-) */ + break; + } + + if (smb_acl_set_mode(e, entry->a_perm) != 0) { + goto fail; + } + } + + if (acl_valid(result) != 0) { + DEBUG(0, ("smb_acl_to_posix: ACL is invalid for set (%s)\n", + strerror(errno))); + goto fail; + } + + return result; + + fail: + if (result != NULL) { + acl_free(result); + } + return NULL; +} + +/* VFS operations structure */ + +static vfs_op_tuple posixacl_op_tuples[] = { + /* Disk operations */ + {SMB_VFS_OP(posixacl_sys_acl_get_file), + SMB_VFS_OP_SYS_ACL_GET_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(posixacl_sys_acl_get_fd), + SMB_VFS_OP_SYS_ACL_GET_FD, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(posixacl_sys_acl_set_file), + SMB_VFS_OP_SYS_ACL_SET_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(posixacl_sys_acl_set_fd), + SMB_VFS_OP_SYS_ACL_SET_FD, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(posixacl_sys_acl_delete_def_file), + SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(NULL), + SMB_VFS_OP_NOOP, + SMB_VFS_LAYER_NOOP} +}; + +NTSTATUS vfs_posixacl_init(void); +NTSTATUS vfs_posixacl_init(void) +{ + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "posixacl", + posixacl_op_tuples); +} diff --git a/source/modules/vfs_prealloc.c b/source/modules/vfs_prealloc.c new file mode 100644 index 00000000000..2e0b8b18b49 --- /dev/null +++ b/source/modules/vfs_prealloc.c @@ -0,0 +1,215 @@ +/* + * XFS preallocation support module. + * + * Copyright (c) James Peach 2006 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" + +/* Extent preallocation module. + * + * The purpose of this module is to preallocate space on the filesystem when + * we have a good idea of how large files are supposed to be. This lets writes + * proceed without having to allocate new extents and results in better file + * layouts on disk. + * + * Currently only implemented for XFS. This module is based on an original idea + * and implementation by Sebastian Brings. + * + * Tunables. + * + * prealloc: <ext> Number of bytes to preallocate for a file with + * the matching extension. + * prealloc:debug Debug level at which to emit messages. + * + * Example. + * + * prealloc:mpeg = 500M # Preallocate *.mpeg to 500 MiB. + */ + +#ifdef HAVE_XFS_LIBXFS_H +#include <xfs/libxfs.h> +#define lock_type xfs_flock64_t +#else +#define lock_type struct flock64 +#endif + +#define MODULE "prealloc" +static int module_debug; + +static int preallocate_space(int fd, SMB_OFF_T size) +{ + lock_type fl = {0}; + int err; + + if (size <= 0) { + return 0; + } + + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = size; + + /* IMPORTANT: We use RESVSP because we want the extents to be + * allocated, but we don't want the allocation to show up in + * st_size or persist after the close(2). + */ + +#if defined(XFS_IOC_RESVSP64) + /* On Linux this comes in via libxfs.h. */ + err = xfsctl(NULL, fd, XFS_IOC_RESVSP64, &fl); +#elif defined(F_RESVSP64) + /* On IRIX, this comes from fcntl.h. */ + err = fcntl(fd, F_RESVSP64, &fl); +#else + err = -1; + errno = ENOSYS; +#endif + + if (err) { + DEBUG(module_debug, + ("%s: preallocate failed on fd=%d size=%lld: %s\n", + MODULE, fd, (long long)size, strerror(errno))); + } + + return err; +} + +static int prealloc_connect( + struct vfs_handle_struct * handle, + const char * service, + const char * user) +{ + module_debug = lp_parm_int(SNUM(handle->conn), + MODULE, "debug", 100); + + return SMB_VFS_NEXT_CONNECT(handle, service, user); +} + +static int prealloc_open(vfs_handle_struct* handle, + const char * fname, + files_struct * fsp, + int flags, + mode_t mode) +{ + int fd; + off64_t size = 0; + + const char * dot; + char fext[10]; + + if (!(flags & (O_CREAT|O_TRUNC))) { + /* Caller is not intending to rewrite the file. Let's not mess + * with the allocation in this case. + */ + goto normal_open; + } + + *fext = '\0'; + dot = strrchr(fname, '.'); + if (dot && *++dot) { + if (strlen(dot) < sizeof(fext)) { + strncpy(fext, dot, sizeof(fext)); + strnorm(fext, CASE_LOWER); + } + } + + if (*fext == '\0') { + goto normal_open; + } + + /* Syntax for specifying preallocation size is: + * MODULE: <extension> = <size> + * where + * <extension> is the file extension in lower case + * <size> is a size like 10, 10K, 10M + */ + size = conv_str_size(lp_parm_const_string(SNUM(handle->conn), MODULE, + fext, NULL)); + if (size <= 0) { + /* No need to preallocate this file. */ + goto normal_open; + } + + fd = SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode); + if (fd < 0) { + return fd; + } + + /* Prellocate only if the file is being created or replaced. Note that + * Samba won't ever pass down O_TRUNC, which is why we have to handle + * truncate calls specially. + */ + if ((flags & O_CREAT) || (flags & O_TRUNC)) { + SMB_OFF_T * psize; + + psize = VFS_ADD_FSP_EXTENSION(handle, fsp, SMB_OFF_T); + if (psize == NULL || *psize == -1) { + return fd; + } + + DEBUG(module_debug, + ("%s: preallocating %s (fd=%d) to %lld bytes\n", + MODULE, fname, fd, (long long)size)); + + *psize = size; + if (preallocate_space(fd, *psize) < 0) { + VFS_REMOVE_FSP_EXTENSION(handle, fsp); + } + } + + return fd; + +normal_open: + /* We are not creating or replacing a file. Skip the + * preallocation. + */ + DEBUG(module_debug, ("%s: skipping preallocation for %s\n", + MODULE, fname)); + return SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode); +} + +static int prealloc_ftruncate(vfs_handle_struct * handle, + files_struct * fsp, + int fd, + SMB_OFF_T offset) +{ + SMB_OFF_T *psize; + int ret = SMB_VFS_NEXT_FTRUNCATE(handle, fsp, fd, offset); + + /* Maintain the allocated space even in the face of truncates. */ + if ((psize = VFS_FETCH_FSP_EXTENSION(handle, fsp))) { + preallocate_space(fd, *psize); + } + + return ret; +} + +static vfs_op_tuple prealloc_op_tuples[] = { + {SMB_VFS_OP(prealloc_open), SMB_VFS_OP_OPEN, SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(prealloc_ftruncate), SMB_VFS_OP_FTRUNCATE, SMB_VFS_LAYER_TRANSPARENT}, + {SMB_VFS_OP(prealloc_connect), SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_TRANSPARENT}, + {NULL, SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} +}; + +NTSTATUS vfs_prealloc_init(void); +NTSTATUS vfs_prealloc_init(void) +{ + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, + MODULE, prealloc_op_tuples); +} + diff --git a/source/modules/vfs_readonly.c b/source/modules/vfs_readonly.c index ee9e40c2fca..721e59430c2 100644 --- a/source/modules/vfs_readonly.c +++ b/source/modules/vfs_readonly.c @@ -55,7 +55,6 @@ #define MODULE_NAME "readonly" static int readonly_connect(vfs_handle_struct *handle, - connection_struct *conn, const char *service, const char *user) { @@ -71,10 +70,10 @@ static int readonly_connect(vfs_handle_struct *handle, time_t end_period = get_date(period[1], ¤t_time); if ((current_time >= begin_period) && (current_time <= end_period)) { - conn->read_only = True; + handle->conn->read_only = True; } - return SMB_VFS_NEXT_CONNECT(handle, conn, service, user); + return SMB_VFS_NEXT_CONNECT(handle, service, user); } else { @@ -92,6 +91,7 @@ static vfs_op_tuple readonly_op_tuples[] = { {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} }; +NTSTATUS vfs_readonly_init(void); NTSTATUS vfs_readonly_init(void) { return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, MODULE_NAME, readonly_op_tuples); diff --git a/source/modules/vfs_recycle.c b/source/modules/vfs_recycle.c index 42f2f51416e..121454315fb 100644 --- a/source/modules/vfs_recycle.c +++ b/source/modules/vfs_recycle.c @@ -32,9 +32,9 @@ static int vfs_recycle_debug_level = DBGC_VFS; #undef DBGC_CLASS #define DBGC_CLASS vfs_recycle_debug_level -static int recycle_connect(vfs_handle_struct *handle, connection_struct *conn, const char *service, const char *user); -static void recycle_disconnect(vfs_handle_struct *handle, connection_struct *conn); -static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, const char *name); +static int recycle_connect(vfs_handle_struct *handle, const char *service, const char *user); +static void recycle_disconnect(vfs_handle_struct *handle); +static int recycle_unlink(vfs_handle_struct *handle, const char *name); static vfs_op_tuple recycle_ops[] = { @@ -48,20 +48,20 @@ static vfs_op_tuple recycle_ops[] = { {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} }; -static int recycle_connect(vfs_handle_struct *handle, connection_struct *conn, const char *service, const char *user) +static int recycle_connect(vfs_handle_struct *handle, const char *service, const char *user) { DEBUG(10,("recycle_connect() connect to service[%s] as user[%s].\n", service,user)); - return SMB_VFS_NEXT_CONNECT(handle, conn, service, user); + return SMB_VFS_NEXT_CONNECT(handle, service, user); } -static void recycle_disconnect(vfs_handle_struct *handle, connection_struct *conn) +static void recycle_disconnect(vfs_handle_struct *handle) { DEBUG(10,("recycle_disconnect() connect to service[%s].\n", - lp_servicename(SNUM(conn)))); + lp_servicename(SNUM(handle->conn)))); - SMB_VFS_NEXT_DISCONNECT(handle, conn); + SMB_VFS_NEXT_DISCONNECT(handle); } static const char *recycle_repository(vfs_handle_struct *handle) @@ -202,7 +202,7 @@ static BOOL recycle_directory_exist(vfs_handle_struct *handle, const char *dname { SMB_STRUCT_STAT st; - if (SMB_VFS_NEXT_STAT(handle, handle->conn, dname, &st) == 0) { + if (SMB_VFS_NEXT_STAT(handle, dname, &st) == 0) { if (S_ISDIR(st.st_mode)) { return True; } @@ -215,7 +215,7 @@ static BOOL recycle_file_exist(vfs_handle_struct *handle, const char *fname) { SMB_STRUCT_STAT st; - if (SMB_VFS_NEXT_STAT(handle, handle->conn, fname, &st) == 0) { + if (SMB_VFS_NEXT_STAT(handle, fname, &st) == 0) { if (S_ISREG(st.st_mode)) { return True; } @@ -234,7 +234,7 @@ static SMB_OFF_T recycle_get_file_size(vfs_handle_struct *handle, const char *fn { SMB_STRUCT_STAT st; - if (SMB_VFS_NEXT_STAT(handle, handle->conn, fname, &st) != 0) { + if (SMB_VFS_NEXT_STAT(handle, fname, &st) != 0) { DEBUG(0,("recycle: stat for %s returned %s\n", fname, strerror(errno))); return (SMB_OFF_T)0; } @@ -280,7 +280,7 @@ static BOOL recycle_create_dir(vfs_handle_struct *handle, const char *dname) DEBUG(10, ("recycle: dir %s already exists\n", new_dir)); else { DEBUG(5, ("recycle: creating new dir %s\n", new_dir)); - if (SMB_VFS_NEXT_MKDIR(handle, handle->conn, new_dir, mode) != 0) { + if (SMB_VFS_NEXT_MKDIR(handle, new_dir, mode) != 0) { DEBUG(1,("recycle: mkdir failed for %s with error: %s\n", new_dir, strerror(errno))); ret = False; goto done; @@ -354,7 +354,7 @@ static void recycle_do_touch(vfs_handle_struct *handle, const char *fname, BOOL struct utimbuf tb; time_t currtime; - if (SMB_VFS_NEXT_STAT(handle, handle->conn, fname, &st) != 0) { + if (SMB_VFS_NEXT_STAT(handle, fname, &st) != 0) { DEBUG(0,("recycle: stat for %s returned %s\n", fname, strerror(errno))); return; } @@ -362,16 +362,19 @@ static void recycle_do_touch(vfs_handle_struct *handle, const char *fname, BOOL tb.actime = currtime; tb.modtime = touch_mtime ? currtime : st.st_mtime; - if (SMB_VFS_NEXT_UTIME(handle, handle->conn, fname, &tb) == -1 ) { + if (SMB_VFS_NEXT_UTIME(handle, fname, &tb) == -1 ) { DEBUG(0, ("recycle: touching %s failed, reason = %s\n", fname, strerror(errno))); } } +extern userdom_struct current_user_info; + /** * Check if file should be recycled **/ -static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, const char *file_name) +static int recycle_unlink(vfs_handle_struct *handle, const char *file_name) { + connection_struct *conn = handle->conn; char *path_name = NULL; char *temp_name = NULL; char *final_name = NULL; @@ -383,7 +386,12 @@ static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, co BOOL exist; int rc = -1; - repository = alloc_sub_conn(conn, recycle_repository(handle)); + repository = talloc_sub_advanced(NULL, lp_servicename(SNUM(conn)), + conn->user, + conn->connectpath, conn->gid, + get_current_username(), + current_user_info.domain, + recycle_repository(handle)); ALLOC_CHECK(repository, done); /* shouldn't we allow absolute path names here? --metze */ /* Yes :-). JRA. */ @@ -391,14 +399,14 @@ static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, co if(!repository || *(repository) == '\0') { DEBUG(3, ("recycle: repository path not set, purging %s...\n", file_name)); - rc = SMB_VFS_NEXT_UNLINK(handle, conn, file_name); + rc = SMB_VFS_NEXT_UNLINK(handle, file_name); goto done; } /* we don't recycle the recycle bin... */ if (strncmp(file_name, repository, strlen(repository)) == 0) { DEBUG(3, ("recycle: File is within recycling bin, unlinking ...\n")); - rc = SMB_VFS_NEXT_UNLINK(handle, conn, file_name); + rc = SMB_VFS_NEXT_UNLINK(handle, file_name); goto done; } @@ -408,7 +416,7 @@ static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, co * if(fsize == 0) { DEBUG(3, ("recycle: File %s is empty, purging...\n", file_name)); - rc = SMB_VFS_NEXT_UNLINK(handle,conn,file_name); + rc = SMB_VFS_NEXT_UNLINK(handle,file_name); goto done; } */ @@ -420,18 +428,18 @@ static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, co maxsize = recycle_maxsize(handle); if(maxsize > 0 && file_size > maxsize) { DEBUG(3, ("recycle: File %s exceeds maximum recycle size, purging... \n", file_name)); - rc = SMB_VFS_NEXT_UNLINK(handle, conn, file_name); + rc = SMB_VFS_NEXT_UNLINK(handle, file_name); goto done; } /* FIXME: this is wrong: moving files with rename does not change the disk space * allocation * - space_avail = SMB_VFS_NEXT_DISK_FREE(handle, conn, ".", True, &bsize, &dfree, &dsize) * 1024L; + space_avail = SMB_VFS_NEXT_DISK_FREE(handle, ".", True, &bsize, &dfree, &dsize) * 1024L; DEBUG(5, ("space_avail = %Lu, file_size = %Lu\n", space_avail, file_size)); if(space_avail < file_size) { DEBUG(3, ("recycle: Not enough diskspace, purging file %s\n", file_name)); - rc = SMB_VFS_NEXT_UNLINK(handle, conn, file_name); + rc = SMB_VFS_NEXT_UNLINK(handle, file_name); goto done; } */ @@ -456,7 +464,7 @@ static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, co if (matchparam(recycle_exclude(handle), base)) { DEBUG(3, ("recycle: file %s is excluded \n", base)); - rc = SMB_VFS_NEXT_UNLINK(handle, conn, file_name); + rc = SMB_VFS_NEXT_UNLINK(handle, file_name); goto done; } @@ -466,7 +474,7 @@ static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, co */ if (checkparam(recycle_exclude_dir(handle), path_name)) { DEBUG(3, ("recycle: directory %s is excluded \n", path_name)); - rc = SMB_VFS_NEXT_UNLINK(handle, conn, file_name); + rc = SMB_VFS_NEXT_UNLINK(handle, file_name); goto done; } @@ -484,7 +492,7 @@ static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, co DEBUG(10, ("recycle: Creating directory %s\n", temp_name)); if (recycle_create_dir(handle, temp_name) == False) { DEBUG(3, ("recycle: Could not create directory, purging %s...\n", file_name)); - rc = SMB_VFS_NEXT_UNLINK(handle, conn, file_name); + rc = SMB_VFS_NEXT_UNLINK(handle, file_name); goto done; } } @@ -497,7 +505,7 @@ static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, co if (recycle_file_exist(handle, final_name)) { if (recycle_versions(handle) == False || matchparam(recycle_noversions(handle), base) == True) { DEBUG(3, ("recycle: Removing old file %s from recycle bin\n", final_name)); - if (SMB_VFS_NEXT_UNLINK(handle, conn, final_name) != 0) { + if (SMB_VFS_NEXT_UNLINK(handle, final_name) != 0) { DEBUG(1, ("recycle: Error deleting old file: %s\n", strerror(errno))); } } @@ -511,10 +519,10 @@ static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, co } DEBUG(10, ("recycle: Moving %s to %s\n", file_name, final_name)); - rc = SMB_VFS_NEXT_RENAME(handle, conn, file_name, final_name); + rc = SMB_VFS_NEXT_RENAME(handle, file_name, final_name); if (rc != 0) { DEBUG(3, ("recycle: Move error %d (%s), purging file %s (%s)\n", errno, strerror(errno), file_name, final_name)); - rc = SMB_VFS_NEXT_UNLINK(handle, conn, file_name); + rc = SMB_VFS_NEXT_UNLINK(handle, file_name); goto done; } @@ -526,10 +534,11 @@ done: SAFE_FREE(path_name); SAFE_FREE(temp_name); SAFE_FREE(final_name); - SAFE_FREE(repository); + TALLOC_FREE(repository); return rc; } +NTSTATUS vfs_recycle_init(void); NTSTATUS vfs_recycle_init(void) { NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "recycle", recycle_ops); diff --git a/source/modules/vfs_shadow_copy.c b/source/modules/vfs_shadow_copy.c index db1c8d007dc..f9a76ec72d2 100644 --- a/source/modules/vfs_shadow_copy.c +++ b/source/modules/vfs_shadow_copy.c @@ -72,10 +72,10 @@ static BOOL shadow_copy_match_name(const char *name) return False; } -static SMB_STRUCT_DIR *shadow_copy_opendir(vfs_handle_struct *handle, connection_struct *conn, const char *fname, const char *mask, uint32 attr) +static SMB_STRUCT_DIR *shadow_copy_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr) { shadow_copy_Dir *dirp; - SMB_STRUCT_DIR *p = SMB_VFS_NEXT_OPENDIR(handle,conn,fname,mask,attr); + SMB_STRUCT_DIR *p = SMB_VFS_NEXT_OPENDIR(handle,fname,mask,attr); if (!p) { DEBUG(0,("shadow_copy_opendir: SMB_VFS_NEXT_OPENDIR() failed for [%s]\n",fname)); @@ -85,7 +85,7 @@ static SMB_STRUCT_DIR *shadow_copy_opendir(vfs_handle_struct *handle, connection dirp = SMB_MALLOC_P(shadow_copy_Dir); if (!dirp) { DEBUG(0,("shadow_copy_opendir: Out of memory\n")); - SMB_VFS_NEXT_CLOSEDIR(handle,conn,p); + SMB_VFS_NEXT_CLOSEDIR(handle,p); return NULL; } @@ -94,7 +94,7 @@ static SMB_STRUCT_DIR *shadow_copy_opendir(vfs_handle_struct *handle, connection while (True) { SMB_STRUCT_DIRENT *d; - d = SMB_VFS_NEXT_READDIR(handle, conn, p); + d = SMB_VFS_NEXT_READDIR(handle, p); if (d == NULL) { break; } @@ -115,11 +115,11 @@ static SMB_STRUCT_DIR *shadow_copy_opendir(vfs_handle_struct *handle, connection dirp->dirs[dirp->num++] = *d; } - SMB_VFS_NEXT_CLOSEDIR(handle,conn,p); + SMB_VFS_NEXT_CLOSEDIR(handle,p); return((SMB_STRUCT_DIR *)dirp); } -SMB_STRUCT_DIRENT *shadow_copy_readdir(vfs_handle_struct *handle, connection_struct *conn, SMB_STRUCT_DIR *_dirp) +static SMB_STRUCT_DIRENT *shadow_copy_readdir(vfs_handle_struct *handle, SMB_STRUCT_DIR *_dirp) { shadow_copy_Dir *dirp = (shadow_copy_Dir *)_dirp; @@ -130,7 +130,7 @@ SMB_STRUCT_DIRENT *shadow_copy_readdir(vfs_handle_struct *handle, connection_str return NULL; } -static void shadow_copy_seekdir(struct vfs_handle_struct *handle, struct connection_struct *conn, SMB_STRUCT_DIR *_dirp, long offset) +static void shadow_copy_seekdir(struct vfs_handle_struct *handle, SMB_STRUCT_DIR *_dirp, long offset) { shadow_copy_Dir *dirp = (shadow_copy_Dir *)_dirp; @@ -139,19 +139,19 @@ static void shadow_copy_seekdir(struct vfs_handle_struct *handle, struct connect } } -static long shadow_copy_telldir(struct vfs_handle_struct *handle, struct connection_struct *conn, SMB_STRUCT_DIR *_dirp) +static long shadow_copy_telldir(struct vfs_handle_struct *handle, SMB_STRUCT_DIR *_dirp) { shadow_copy_Dir *dirp = (shadow_copy_Dir *)_dirp; return( dirp->pos ) ; } -static void shadow_copy_rewinddir(struct vfs_handle_struct *handle, struct connection_struct *conn, SMB_STRUCT_DIR *_dirp) +static void shadow_copy_rewinddir(struct vfs_handle_struct *handle, SMB_STRUCT_DIR *_dirp) { shadow_copy_Dir *dirp = (shadow_copy_Dir *)_dirp; dirp->pos = 0 ; } -int shadow_copy_closedir(vfs_handle_struct *handle, connection_struct *conn, SMB_STRUCT_DIR *_dirp) +static int shadow_copy_closedir(vfs_handle_struct *handle, SMB_STRUCT_DIR *_dirp) { shadow_copy_Dir *dirp = (shadow_copy_Dir *)_dirp; @@ -163,7 +163,7 @@ int shadow_copy_closedir(vfs_handle_struct *handle, connection_struct *conn, SMB static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle, files_struct *fsp, SHADOW_COPY_DATA *shadow_copy_data, BOOL labels) { - SMB_STRUCT_DIR *p = SMB_VFS_NEXT_OPENDIR(handle,fsp->conn,fsp->conn->connectpath,NULL,0); + SMB_STRUCT_DIR *p = SMB_VFS_NEXT_OPENDIR(handle,fsp->conn->connectpath,NULL,0); shadow_copy_data->num_volumes = 0; shadow_copy_data->labels = NULL; @@ -177,7 +177,7 @@ static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle, files_str SHADOW_COPY_LABEL *tlabels; SMB_STRUCT_DIRENT *d; - d = SMB_VFS_NEXT_READDIR(handle, fsp->conn, p); + d = SMB_VFS_NEXT_READDIR(handle, p); if (d == NULL) { break; } @@ -200,7 +200,7 @@ static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle, files_str (shadow_copy_data->num_volumes+1)*sizeof(SHADOW_COPY_LABEL)); if (tlabels == NULL) { DEBUG(0,("shadow_copy_get_shadow_copy_data: Out of memory\n")); - SMB_VFS_NEXT_CLOSEDIR(handle,fsp->conn,p); + SMB_VFS_NEXT_CLOSEDIR(handle,p); return -1; } @@ -209,7 +209,7 @@ static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle, files_str shadow_copy_data->labels = tlabels; } - SMB_VFS_NEXT_CLOSEDIR(handle,fsp->conn,p); + SMB_VFS_NEXT_CLOSEDIR(handle,p); return 0; } @@ -228,6 +228,7 @@ static vfs_op_tuple shadow_copy_ops[] = { {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} }; +NTSTATUS vfs_shadow_copy_init(void); NTSTATUS vfs_shadow_copy_init(void) { NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "shadow_copy", shadow_copy_ops); diff --git a/source/modules/vfs_solarisacl.c b/source/modules/vfs_solarisacl.c new file mode 100644 index 00000000000..3ec01b2a391 --- /dev/null +++ b/source/modules/vfs_solarisacl.c @@ -0,0 +1,789 @@ +/* + Unix SMB/Netbios implementation. + VFS module to get and set Solaris ACLs + Copyright (C) Michael Adam 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + + +#include "includes.h" + + +/* typedef struct acl SOLARIS_ACE_T; */ +typedef aclent_t SOLARIS_ACE_T; +typedef aclent_t *SOLARIS_ACL_T; +typedef int SOLARIS_ACL_TAG_T; /* the type of an ACL entry */ +typedef o_mode_t SOLARIS_PERM_T; + +/* for convenience: check if solaris acl entry is a default entry? */ +#define _IS_DEFAULT(ace) ((ace).a_type & ACL_DEFAULT) +#define _IS_OF_TYPE(ace, type) ( \ + (((type) == SMB_ACL_TYPE_ACCESS) && !_IS_DEFAULT(ace)) \ + || \ + (((type) == SMB_ACL_TYPE_DEFAULT) && _IS_DEFAULT(ace)) \ +) + + +/* prototypes for private functions */ + +static SOLARIS_ACL_T solaris_acl_init(int count); +static BOOL smb_acl_to_solaris_acl(SMB_ACL_T smb_acl, + SOLARIS_ACL_T *solariacl, int *count, + SMB_ACL_TYPE_T type); +static SMB_ACL_T solaris_acl_to_smb_acl(SOLARIS_ACL_T solarisacl, int count, + SMB_ACL_TYPE_T type); +static SOLARIS_ACL_TAG_T smb_tag_to_solaris_tag(SMB_ACL_TAG_T smb_tag); +static SMB_ACL_TAG_T solaris_tag_to_smb_tag(SOLARIS_ACL_TAG_T solaris_tag); +static BOOL solaris_add_to_acl(SOLARIS_ACL_T *solaris_acl, int *count, + SOLARIS_ACL_T add_acl, int add_count, SMB_ACL_TYPE_T type); +static BOOL solaris_acl_get_file(const char *name, SOLARIS_ACL_T *solarisacl, + int *count); +static BOOL solaris_acl_get_fd(int fd, SOLARIS_ACL_T *solarisacl, int *count); +static BOOL solaris_acl_sort(SOLARIS_ACL_T acl, int count); +static SMB_ACL_PERM_T solaris_perm_to_smb_perm(const SOLARIS_PERM_T perm); +static SOLARIS_PERM_T smb_perm_to_solaris_perm(const SMB_ACL_PERM_T perm); +static BOOL solaris_acl_check(SOLARIS_ACL_T solaris_acl, int count); + + +/* public functions - the api */ + +SMB_ACL_T solarisacl_sys_acl_get_file(vfs_handle_struct *handle, + const char *path_p, + SMB_ACL_TYPE_T type) +{ + SMB_ACL_T result = NULL; + int count; + SOLARIS_ACL_T solaris_acl; + + DEBUG(10, ("solarisacl_sys_acl_get_file called for file '%s'.\n", + path_p)); + + if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) { + DEBUG(10, ("invalid SMB_ACL_TYPE given (%d)\n", type)); + errno = EINVAL; + goto done; + } + + DEBUGADD(10, ("getting %s acl\n", + ((type == SMB_ACL_TYPE_ACCESS) ? "access" : "default"))); + + if (!solaris_acl_get_file(path_p, &solaris_acl, &count)) { + goto done; + } + result = solaris_acl_to_smb_acl(solaris_acl, count, type); + if (result == NULL) { + DEBUG(10, ("conversion solaris_acl -> smb_acl failed (%s).\n", + strerror(errno))); + } + + done: + DEBUG(10, ("solarisacl_sys_acl_get_file %s.\n", + ((result == NULL) ? "failed" : "succeeded" ))); + SAFE_FREE(solaris_acl); + return result; +} + + +/* + * get the access ACL of a file referred to by a fd + */ +SMB_ACL_T solarisacl_sys_acl_get_fd(vfs_handle_struct *handle, + files_struct *fsp, + int fd) +{ + SMB_ACL_T result = NULL; + int count; + SOLARIS_ACL_T solaris_acl; + + DEBUG(10, ("entering solarisacl_sys_acl_get_fd.\n")); + + if (!solaris_acl_get_fd(fd, &solaris_acl, &count)) { + goto done; + } + /* + * The facl call returns both ACCESS and DEFAULT acls (as present). + * The posix acl_get_fd function returns only the + * access acl. So we need to filter this out here. + */ + result = solaris_acl_to_smb_acl(solaris_acl, count, + SMB_ACL_TYPE_ACCESS); + if (result == NULL) { + DEBUG(10, ("conversion solaris_acl -> smb_acl failed (%s).\n", + strerror(errno))); + } + + done: + DEBUG(10, ("solarisacl_sys_acl_get_fd %s.\n", + ((result == NULL) ? "failed" : "succeeded"))); + SAFE_FREE(solaris_acl); + return NULL; +} + +int solarisacl_sys_acl_set_file(vfs_handle_struct *handle, + const char *name, + SMB_ACL_TYPE_T type, + SMB_ACL_T theacl) +{ + int ret = -1; + struct stat s; + SOLARIS_ACL_T solaris_acl; + int count; + + DEBUG(10, ("solarisacl_sys_acl_set_file called for file '%s'\n", + name)); + + if ((type != SMB_ACL_TYPE_ACCESS) && (type != SMB_ACL_TYPE_DEFAULT)) { + errno = EINVAL; + DEBUG(10, ("invalid smb acl type given (%d).\n", type)); + goto done; + } + DEBUGADD(10, ("setting %s acl\n", + ((type == SMB_ACL_TYPE_ACCESS) ? "access" : "default"))); + + if(!smb_acl_to_solaris_acl(theacl, &solaris_acl, &count, type)) { + DEBUG(10, ("conversion smb_acl -> solaris_acl failed (%s).\n", + strerror(errno))); + goto done; + } + + /* + * if the file is a directory, there is extra work to do: + * since the solaris acl call stores both the access acl and + * the default acl as provided, we have to get the acl part + * that has not been specified in "type" from the file first + * and concatenate it with the acl provided. + */ + if (SMB_VFS_STAT(handle->conn, name, &s) != 0) { + DEBUG(10, ("Error in stat call: %s\n", strerror(errno))); + goto done; + } + if (S_ISDIR(s.st_mode)) { + SOLARIS_ACL_T other_acl; + int other_count; + SMB_ACL_TYPE_T other_type; + + other_type = (type == SMB_ACL_TYPE_ACCESS) + ? SMB_ACL_TYPE_DEFAULT + : SMB_ACL_TYPE_ACCESS; + DEBUGADD(10, ("getting acl from filesystem\n")); + if (!solaris_acl_get_file(name, &other_acl, &other_count)) { + DEBUG(10, ("error getting acl from directory\n")); + goto done; + } + DEBUG(10, ("adding %s part of fs acl to given acl\n", + ((other_type == SMB_ACL_TYPE_ACCESS) + ? "access" + : "default"))); + if (!solaris_add_to_acl(&solaris_acl, &count, other_acl, + other_count, other_type)) + { + DEBUG(10, ("error adding other acl.\n")); + SAFE_FREE(other_acl); + goto done; + } + SAFE_FREE(other_acl); + } + else if (type != SMB_ACL_TYPE_ACCESS) { + errno = EINVAL; + goto done; + } + + if (!solaris_acl_sort(solaris_acl, count)) { + DEBUG(10, ("resulting acl is not valid!\n")); + goto done; + } + + ret = acl(name, SETACL, count, solaris_acl); + + done: + DEBUG(10, ("solarisacl_sys_acl_set_file %s.\n", + ((ret != 0) ? "failed" : "succeeded"))); + SAFE_FREE(solaris_acl); + return ret; +} + +/* + * set the access ACL on the file referred to by a fd + */ +int solarisacl_sys_acl_set_fd(vfs_handle_struct *handle, + files_struct *fsp, + int fd, SMB_ACL_T theacl) +{ + SOLARIS_ACL_T solaris_acl; + SOLARIS_ACL_T default_acl; + int count, default_count; + int ret = -1; + + DEBUG(10, ("entering solarisacl_sys_acl_set_fd\n")); + + /* + * the posix acl_set_fd call sets the access acl of the + * file referred to by fd. the solaris facl-SETACL call + * sets the access and default acl as provided, so we + * have to retrieve the default acl of the file and + * concatenate it with the access acl provided. + */ + if (!smb_acl_to_solaris_acl(theacl, &solaris_acl, &count, + SMB_ACL_TYPE_ACCESS)) + { + DEBUG(10, ("conversion smb_acl -> solaris_acl failed (%s).\n", + strerror(errno))); + goto done; + } + if (!solaris_acl_get_fd(fd, &default_acl, &default_count)) { + DEBUG(10, ("error getting (default) acl from fd\n")); + goto done; + } + if (!solaris_add_to_acl(&solaris_acl, &count, + default_acl, default_count, + SMB_ACL_TYPE_DEFAULT)) + { + DEBUG(10, ("error adding default acl to solaris acl\n")); + goto done; + } + if (!solaris_acl_sort(solaris_acl, count)) { + DEBUG(10, ("resulting acl is not valid!\n")); + goto done; + } + + ret = facl(fd, SETACL, count, solaris_acl); + if (ret != 0) { + DEBUG(10, ("call of facl failed (%s).\n", strerror(errno))); + } + + done: + DEBUG(10, ("solarisacl_sys_acl_st_fd %s.\n", + ((ret == 0) ? "succeded" : "failed" ))); + SAFE_FREE(solaris_acl); + SAFE_FREE(default_acl); + return ret; +} + +/* + * delete the default ACL of a directory + * + * This is achieved by fetching the access ACL and rewriting it + * directly, via the solaris system call: the SETACL call on + * directories writes both the access and the default ACL as provided. + * + * XXX: posix acl_delete_def_file returns an error if + * the file referred to by path is not a directory. + * this function does not complain but the actions + * have no effect on a file other than a directory. + * But sys_acl_delete_default_file is only called in + * smbd/posixacls.c after having checked that the file + * is a directory, anyways. So implementing the extra + * check is considered unnecessary. --- Agreed? XXX + */ +int solarisacl_sys_acl_delete_def_file(vfs_handle_struct *handle, + const char *path) +{ + SMB_ACL_T smb_acl; + int ret = -1; + SOLARIS_ACL_T solaris_acl; + int count; + + DEBUG(10, ("entering solarisacl_sys_acl_delete_def_file.\n")); + + smb_acl = solarisacl_sys_acl_get_file(handle, path, + SMB_ACL_TYPE_ACCESS); + if (smb_acl == NULL) { + DEBUG(10, ("getting file acl failed!\n")); + goto done; + } + if (!smb_acl_to_solaris_acl(smb_acl, &solaris_acl, &count, + SMB_ACL_TYPE_ACCESS)) + { + DEBUG(10, ("conversion smb_acl -> solaris_acl failed.\n")); + goto done; + } + if (!solaris_acl_sort(solaris_acl, count)) { + DEBUG(10, ("resulting acl is not valid!\n")); + goto done; + } + ret = acl(path, SETACL, count, solaris_acl); + if (ret != 0) { + DEBUG(10, ("settinge file acl failed!\n")); + } + + done: + DEBUG(10, ("solarisacl_sys_acl_delete_def_file %s.\n", + ((ret != 0) ? "failed" : "succeeded" ))); + SAFE_FREE(smb_acl); + return ret; +} + + +/* private functions */ + +static SOLARIS_ACL_T solaris_acl_init(int count) +{ + SOLARIS_ACL_T solaris_acl = + (SOLARIS_ACL_T)SMB_MALLOC(sizeof(aclent_t) * count); + if (solaris_acl == NULL) { + errno = ENOMEM; + } + return solaris_acl; +} + +/* + * Convert the SMB acl to the ACCESS or DEFAULT part of a + * solaris ACL, as desired. + */ +static BOOL smb_acl_to_solaris_acl(SMB_ACL_T smb_acl, + SOLARIS_ACL_T *solaris_acl, int *count, + SMB_ACL_TYPE_T type) +{ + BOOL ret = False; + int i; + int check_which, check_rc; + + DEBUG(10, ("entering smb_acl_to_solaris_acl\n")); + + *solaris_acl = NULL; + *count = 0; + + for (i = 0; i < smb_acl->count; i++) { + const struct smb_acl_entry *smb_entry = &(smb_acl->acl[i]); + SOLARIS_ACE_T solaris_entry; + + ZERO_STRUCT(solaris_entry); + + solaris_entry.a_type = smb_tag_to_solaris_tag(smb_entry->a_type); + if (solaris_entry.a_type == 0) { + DEBUG(10, ("smb_tag to solaris_tag failed\n")); + goto fail; + } + switch(solaris_entry.a_type) { + case USER: + DEBUG(10, ("got tag type USER with uid %d\n", + smb_entry->uid)); + solaris_entry.a_id = (uid_t)smb_entry->uid; + break; + case GROUP: + DEBUG(10, ("got tag type GROUP with gid %d\n", + smb_entry->gid)); + solaris_entry.a_id = (uid_t)smb_entry->gid; + break; + default: + break; + } + if (type == SMB_ACL_TYPE_DEFAULT) { + DEBUG(10, ("adding default bit to solaris ace\n")); + solaris_entry.a_type |= ACL_DEFAULT; + } + + solaris_entry.a_perm = + smb_perm_to_solaris_perm(smb_entry->a_perm); + DEBUG(10, ("assembled the following solaris ace:\n")); + DEBUGADD(10, (" - type: 0x%04x\n", solaris_entry.a_type)); + DEBUGADD(10, (" - id: %d\n", solaris_entry.a_id)); + DEBUGADD(10, (" - perm: o%o\n", solaris_entry.a_perm)); + if (!solaris_add_to_acl(solaris_acl, count, &solaris_entry, + 1, type)) + { + DEBUG(10, ("error adding acl entry\n")); + goto fail; + } + DEBUG(10, ("count after adding: %d (i: %d)\n", *count, i)); + DEBUG(10, ("test, if entry has been copied into acl:\n")); + DEBUGADD(10, (" - type: 0x%04x\n", + (*solaris_acl)[(*count)-1].a_type)); + DEBUGADD(10, (" - id: %d\n", + (*solaris_acl)[(*count)-1].a_id)); + DEBUGADD(10, (" - perm: o%o\n", + (*solaris_acl)[(*count)-1].a_perm)); + } + + ret = True; + goto done; + + fail: + SAFE_FREE(*solaris_acl); + done: + DEBUG(10, ("smb_acl_to_solaris_acl %s\n", + ((ret == True) ? "succeeded" : "failed"))); + return ret; +} + +/* + * convert either the access or the default part of a + * soaris acl to the SMB_ACL format. + */ +static SMB_ACL_T solaris_acl_to_smb_acl(SOLARIS_ACL_T solaris_acl, int count, + SMB_ACL_TYPE_T type) +{ + SMB_ACL_T result; + int i; + + if ((result = sys_acl_init(0)) == NULL) { + DEBUG(10, ("error allocating memory for SMB_ACL\n")); + goto fail; + } + for (i = 0; i < count; i++) { + SMB_ACL_ENTRY_T smb_entry; + SMB_ACL_PERM_T smb_perm; + + if (!_IS_OF_TYPE(solaris_acl[i], type)) { + continue; + } + result = SMB_REALLOC(result, + sizeof(struct smb_acl_t) + + (sizeof(struct smb_acl_entry) * + (result->count + 1))); + if (result == NULL) { + DEBUG(10, ("error reallocating memory for SMB_ACL\n")); + goto fail; + } + smb_entry = &result->acl[result->count]; + if (sys_acl_set_tag_type(smb_entry, + solaris_tag_to_smb_tag(solaris_acl[i].a_type)) != 0) + { + DEBUG(10, ("invalid tag type given: 0x%04x\n", + solaris_acl[i].a_type)); + goto fail; + } + /* intentionally not checking return code here: */ + sys_acl_set_qualifier(smb_entry, (void *)&solaris_acl[i].a_id); + smb_perm = solaris_perm_to_smb_perm(solaris_acl[i].a_perm); + if (sys_acl_set_permset(smb_entry, &smb_perm) != 0) { + DEBUG(10, ("invalid permset given: %d\n", + solaris_acl[i].a_perm)); + goto fail; + } + result->count += 1; + } + goto done; + + fail: + SAFE_FREE(result); + done: + DEBUG(10, ("solaris_acl_to_smb_acl %s\n", + ((result == NULL) ? "failed" : "succeeded"))); + return result; +} + + + +static SOLARIS_ACL_TAG_T smb_tag_to_solaris_tag(SMB_ACL_TAG_T smb_tag) +{ + SOLARIS_ACL_TAG_T solaris_tag = 0; + + DEBUG(10, ("smb_tag_to_solaris_tag\n")); + DEBUGADD(10, (" --> got smb tag 0x%04x\n", smb_tag)); + + switch (smb_tag) { + case SMB_ACL_USER: + solaris_tag = USER; + break; + case SMB_ACL_USER_OBJ: + solaris_tag = USER_OBJ; + break; + case SMB_ACL_GROUP: + solaris_tag = GROUP; + break; + case SMB_ACL_GROUP_OBJ: + solaris_tag = GROUP_OBJ; + break; + case SMB_ACL_OTHER: + solaris_tag = OTHER_OBJ; + break; + case SMB_ACL_MASK: + solaris_tag = CLASS_OBJ; + break; + default: + DEBUGADD(10, (" !!! unknown smb tag type 0x%04x\n", smb_tag)); + break; + } + + DEBUGADD(10, (" --> determined solaris tag 0x%04x\n", solaris_tag)); + + return solaris_tag; +} + +static SMB_ACL_TAG_T solaris_tag_to_smb_tag(SOLARIS_ACL_TAG_T solaris_tag) +{ + SMB_ACL_TAG_T smb_tag = 0; + + DEBUG(10, ("solaris_tag_to_smb_tag:\n")); + DEBUGADD(10, (" --> got solaris tag 0x%04x\n", solaris_tag)); + + solaris_tag &= ~ACL_DEFAULT; + + switch (solaris_tag) { + case USER: + smb_tag = SMB_ACL_USER; + break; + case USER_OBJ: + smb_tag = SMB_ACL_USER_OBJ; + break; + case GROUP: + smb_tag = SMB_ACL_GROUP; + break; + case GROUP_OBJ: + smb_tag = SMB_ACL_GROUP_OBJ; + break; + case OTHER_OBJ: + smb_tag = SMB_ACL_OTHER; + break; + case CLASS_OBJ: + smb_tag = SMB_ACL_MASK; + break; + default: + DEBUGADD(10, (" !!! unknown solaris tag type: 0x%04x\n", + solaris_tag)); + break; + } + + DEBUGADD(10, (" --> determined smb tag 0x%04x\n", smb_tag)); + + return smb_tag; +} + + +static SMB_ACL_PERM_T solaris_perm_to_smb_perm(const SOLARIS_PERM_T perm) +{ + SMB_ACL_PERM_T smb_perm = 0; + smb_perm |= ((perm & SMB_ACL_READ) ? SMB_ACL_READ : 0); + smb_perm |= ((perm & SMB_ACL_WRITE) ? SMB_ACL_WRITE : 0); + smb_perm |= ((perm & SMB_ACL_EXECUTE) ? SMB_ACL_EXECUTE : 0); + return smb_perm; +} + + +static SOLARIS_PERM_T smb_perm_to_solaris_perm(const SMB_ACL_PERM_T perm) +{ + SOLARIS_PERM_T solaris_perm = 0; + solaris_perm |= ((perm & SMB_ACL_READ) ? SMB_ACL_READ : 0); + solaris_perm |= ((perm & SMB_ACL_WRITE) ? SMB_ACL_WRITE : 0); + solaris_perm |= ((perm & SMB_ACL_EXECUTE) ? SMB_ACL_EXECUTE : 0); + return solaris_perm; +} + + +static BOOL solaris_acl_get_file(const char *name, SOLARIS_ACL_T *solaris_acl, + int *count) +{ + BOOL result = False; + + DEBUG(10, ("solaris_acl_get_file called for file '%s'\n", name)); + + /* + * The original code tries some INITIAL_ACL_SIZE + * and only did the GETACLCNT call upon failure + * (for performance reasons). + * For the sake of simplicity, I skip this for now. + */ + *count = acl(name, GETACLCNT, 0, NULL); + if (*count < 0) { + DEBUG(10, ("acl GETACLCNT failed: %s\n", strerror(errno))); + goto done; + } + *solaris_acl = solaris_acl_init(*count); + if (*solaris_acl == NULL) { + DEBUG(10, ("error allocating memory for solaris acl...\n")); + goto done; + } + *count = acl(name, GETACL, *count, *solaris_acl); + if (*count < 0) { + DEBUG(10, ("acl GETACL failed: %s\n", strerror(errno))); + goto done; + } + result = True; + + done: + DEBUG(10, ("solaris_acl_get_file %s.\n", + ((result == True) ? "succeeded" : "failed" ))); + return result; +} + + +static BOOL solaris_acl_get_fd(int fd, SOLARIS_ACL_T *solaris_acl, int *count) +{ + BOOL ret = False; + + DEBUG(10, ("entering solaris_acl_get_fd\n")); + + /* + * see solaris_acl_get_file for comment about omission + * of INITIAL_ACL_SIZE... + */ + *count = facl(fd, GETACLCNT, 0, NULL); + if (*count < 0) { + DEBUG(10, ("facl GETACLCNT failed: %s\n", strerror(errno))); + goto done; + } + *solaris_acl = solaris_acl_init(*count); + if (*solaris_acl == NULL) { + DEBUG(10, ("error allocating memory for solaris acl...\n")); + goto done; + } + *count = facl(fd, GETACL, *count, *solaris_acl); + if (*count < 0) { + DEBUG(10, ("facl GETACL failed: %s\n", strerror(errno))); + goto done; + } + ret = True; + + done: + DEBUG(10, ("solaris_acl_get_fd %s\n", + ((ret == True) ? "succeeded" : "failed"))); + return ret; +} + + + +/* + * Add entries to a solaris ACL. + * + * Entries are directly added to the solarisacl parameter. + * if memory allocation fails, this may result in solarisacl + * being NULL. if the resulting acl is to be checked and is + * not valid, it is kept in solarisacl but False is returned. + * + * The type of ACEs (access/default) to be added to the ACL can + * be selected via the type parameter. + * I use the SMB_ACL_TYPE_T type here. Since SMB_ACL_TYPE_ACCESS + * is defined as "0", this means that one can only add either + * access or default ACEs, not both at the same time. If it + * should become necessary to add all of an ACL, one would have + * to replace this parameter by another type. + */ +static BOOL solaris_add_to_acl(SOLARIS_ACL_T *solaris_acl, int *count, + SOLARIS_ACL_T add_acl, int add_count, + SMB_ACL_TYPE_T type) +{ + int i; + + if ((type != SMB_ACL_TYPE_ACCESS) && (type != SMB_ACL_TYPE_DEFAULT)) + { + DEBUG(10, ("invalid acl type given: %d\n", type)); + errno = EINVAL; + return False; + } + for (i = 0; i < add_count; i++) { + if (!_IS_OF_TYPE(add_acl[i], type)) { + continue; + } + ADD_TO_ARRAY(NULL, SOLARIS_ACE_T, add_acl[i], + solaris_acl, count); + if (solaris_acl == NULL) { + DEBUG(10, ("error enlarging acl.\n")); + errno = ENOMEM; + return False; + } + } + return True; +} + + +/* + * sort the ACL and check it for validity + * + * [original comment from lib/sysacls.c:] + * + * if it's a minimal ACL with only 4 entries then we + * need to recalculate the mask permissions to make + * sure that they are the same as the GROUP_OBJ + * permissions as required by the UnixWare acl() system call. + * + * (note: since POSIX allows minimal ACLs which only contain + * 3 entries - ie there is no mask entry - we should, in theory, + * check for this and add a mask entry if necessary - however + * we "know" that the caller of this interface always specifies + * a mask, so in practice "this never happens" (tm) - if it *does* + * happen aclsort() will fail and return an error and someone will + * have to fix it...) + */ +static BOOL solaris_acl_sort(SOLARIS_ACL_T solaris_acl, int count) +{ + int fixmask = (count <= 4); + + if (aclsort(count, fixmask, solaris_acl) != 0) { + errno = EINVAL; + return False; + } + return True; +} + +/* + * acl check function: + * unused at the moment but could be used to get more + * concrete error messages for debugging... + * (acl sort just says that the acl is invalid...) + */ +static BOOL solaris_acl_check(SOLARIS_ACL_T solaris_acl, int count) +{ + int check_rc; + int check_which; + + check_rc = aclcheck(solaris_acl, count, &check_which); + if (check_rc != 0) { + DEBUG(10, ("acl is not valid:\n")); + DEBUGADD(10, (" - return code: %d\n", check_rc)); + DEBUGADD(10, (" - which: %d\n", check_which)); + if (check_which != -1) { + DEBUGADD(10, (" - invalid entry:\n")); + DEBUGADD(10, (" * type: %d:\n", + solaris_acl[check_which].a_type)); + DEBUGADD(10, (" * id: %d\n", + solaris_acl[check_which].a_id)); + DEBUGADD(10, (" * perm: 0o%o\n", + solaris_acl[check_which].a_perm)); + } + return False; + } + return True; +} + + +/* VFS operations structure */ + +static vfs_op_tuple solarisacl_op_tuples[] = { + /* Disk operations */ + {SMB_VFS_OP(solarisacl_sys_acl_get_file), + SMB_VFS_OP_SYS_ACL_GET_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(solarisacl_sys_acl_get_fd), + SMB_VFS_OP_SYS_ACL_GET_FD, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(solarisacl_sys_acl_set_file), + SMB_VFS_OP_SYS_ACL_SET_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(solarisacl_sys_acl_set_fd), + SMB_VFS_OP_SYS_ACL_SET_FD, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(solarisacl_sys_acl_delete_def_file), + SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(NULL), + SMB_VFS_OP_NOOP, + SMB_VFS_LAYER_NOOP} +}; + +NTSTATUS vfs_solarisacl_init(void); +NTSTATUS vfs_solarisacl_init(void) +{ + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "solarisacl", + solarisacl_op_tuples); +} + +/* ENTE */ diff --git a/source/modules/vfs_tru64acl.c b/source/modules/vfs_tru64acl.c new file mode 100644 index 00000000000..6aa9557c28c --- /dev/null +++ b/source/modules/vfs_tru64acl.c @@ -0,0 +1,505 @@ +/* + Unix SMB/Netbios implementation. + VFS module to get and set Tru64 acls + Copyright (C) Michael Adam 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/* prototypes for private functions first - for clarity */ + +static struct smb_acl_t *tru64_acl_to_smb_acl(const struct acl *tru64_acl); +static BOOL tru64_ace_to_smb_ace(acl_entry_t tru64_ace, + struct smb_acl_entry *smb_ace); +static acl_t smb_acl_to_tru64_acl(const SMB_ACL_T smb_acl); +static acl_tag_t smb_tag_to_tru64(SMB_ACL_TAG_T smb_tag); +static SMB_ACL_TAG_T tru64_tag_to_smb(acl_tag_t tru64_tag); +static acl_perm_t smb_permset_to_tru64(smb_acl_permset_t smb_permset); +static smb_acl_permset_t tru64_permset_to_smb(const acl_perm_t tru64_permset); + + +/* public functions - the api */ + +SMB_ACL_T tru64acl_sys_acl_get_file(vfs_handle_struct *handle, + const char *path_p, + SMB_ACL_TYPE_T type) +{ + struct smb_acl_t *result; + acl_type_t the_acl_type; + acl_t tru64_acl; + + DEBUG(10, ("Hi! This is tru64acl_sys_acl_get_file.\n")); + + switch(type) { + case SMB_ACL_TYPE_ACCESS: + the_acl_type = ACL_TYPE_ACCESS; + break; + case SMB_ACL_TYPE_DEFAULT: + the_acl_type = ACL_TYPE_DEFAULT; + break; + default: + errno = EINVAL; + return NULL; + } + + tru64_acl = acl_get_file((char *)path_p, the_acl_type); + + if (tru64_acl == NULL) { + return NULL; + } + + result = tru64_acl_to_smb_acl(tru64_acl); + acl_free(tru64_acl); + return result; +} + +SMB_ACL_T tru64acl_sys_acl_get_fd(vfs_handle_struct *handle, + files_struct *fsp, + int fd) +{ + struct smb_acl_t *result; + acl_t tru64_acl = acl_get_fd(fd, ACL_TYPE_ACCESS); + + if (tru64_acl == NULL) { + return NULL; + } + + result = tru64_acl_to_smb_acl(tru64_acl); + acl_free(tru64_acl); + return result; +} + +int tru64acl_sys_acl_set_file(vfs_handle_struct *handle, + const char *name, + SMB_ACL_TYPE_T type, + SMB_ACL_T theacl) +{ + int res; + acl_type_t the_acl_type; + acl_t tru64_acl; + + DEBUG(10, ("tru64acl_sys_acl_set_file called with name %s, type %d\n", + name, type)); + + switch(type) { + case SMB_ACL_TYPE_ACCESS: + DEBUGADD(10, ("got acl type ACL_TYPE_ACCESS\n")); + the_acl_type = ACL_TYPE_ACCESS; + break; + case SMB_ACL_TYPE_DEFAULT: + DEBUGADD(10, ("got acl type ACL_TYPE_DEFAULT\n")); + the_acl_type = ACL_TYPE_DEFAULT; + break; + default: + DEBUGADD(10, ("invalid acl type\n")); + errno = EINVAL; + goto fail; + } + + tru64_acl = smb_acl_to_tru64_acl(theacl); + if (tru64_acl == NULL) { + DEBUG(10, ("smb_acl_to_tru64_acl failed!\n")); + goto fail; + } + DEBUG(10, ("got tru64 acl...\n")); + res = acl_set_file((char *)name, the_acl_type, tru64_acl); + acl_free(tru64_acl); + if (res != 0) { + DEBUG(10, ("acl_set_file failed: %s\n", strerror(errno))); + goto fail; + } + return res; +fail: + DEBUG(1, ("tru64acl_sys_acl_set_file failed!\n")); + return -1; +} + +int tru64acl_sys_acl_set_fd(vfs_handle_struct *handle, + files_struct *fsp, + int fd, SMB_ACL_T theacl) +{ + int res; + acl_t tru64_acl = smb_acl_to_tru64_acl(theacl); + if (tru64_acl == NULL) { + return -1; + } + res = acl_set_fd(fd, ACL_TYPE_ACCESS, tru64_acl); + acl_free(tru64_acl); + return res; + +} + +int tru64acl_sys_acl_delete_def_file(vfs_handle_struct *handle, + const char *path) +{ + return acl_delete_def_file((char *)path); +} + + +/* private functions */ + +static struct smb_acl_t *tru64_acl_to_smb_acl(const struct acl *tru64_acl) +{ + struct smb_acl_t *result; + acl_entry_t entry; + + DEBUG(10, ("Hi! This is tru64_acl_to_smb_acl.\n")); + + if ((result = SMB_MALLOC_P(struct smb_acl_t)) == NULL) { + DEBUG(0, ("SMB_MALLOC_P failed in tru64_acl_to_smb_acl\n")); + errno = ENOMEM; + goto fail; + } + ZERO_STRUCTP(result); + if (acl_first_entry((struct acl *)tru64_acl) != 0) { + DEBUG(10, ("acl_first_entry failed: %s\n", strerror(errno))); + goto fail; + } + while ((entry = acl_get_entry((struct acl *)tru64_acl)) != NULL) { + result = SMB_REALLOC(result, sizeof(struct smb_acl_t) + + (sizeof(struct smb_acl_entry) * + (result->count + 1))); + if (result == NULL) { + DEBUG(0, ("SMB_REALLOC failed in tru64_acl_to_smb_acl\n")); + errno = ENOMEM; + goto fail; + } + /* XYZ */ + if (!tru64_ace_to_smb_ace(entry, &result->acl[result->count])) { + SAFE_FREE(result); + goto fail; + } + result->count += 1; + } + return result; + +fail: + if (result != NULL) { + SAFE_FREE(result); + } + DEBUG(1, ("tru64_acl_to_smb_acl failed!\n")); + return NULL; +} + +static BOOL tru64_ace_to_smb_ace(acl_entry_t tru64_ace, + struct smb_acl_entry *smb_ace) +{ + acl_tag_t tru64_tag; + acl_permset_t permset; + SMB_ACL_TAG_T smb_tag_type; + smb_acl_permset_t smb_permset; + void *qualifier; + + if (acl_get_tag_type(tru64_ace, &tru64_tag) != 0) { + DEBUG(0, ("acl_get_tag_type failed: %s\n", strerror(errno))); + return False; + } + + /* On could set the tag type directly to save a function call, + * but I like this better... */ + smb_tag_type = tru64_tag_to_smb(tru64_tag); + if (smb_tag_type == 0) { + DEBUG(3, ("invalid tag type given: %d\n", tru64_tag)); + return False; + } + if (sys_acl_set_tag_type(smb_ace, smb_tag_type) != 0) { + DEBUG(3, ("sys_acl_set_tag_type failed: %s\n", + strerror(errno))); + return False; + } + qualifier = acl_get_qualifier(tru64_ace); + if (qualifier != NULL) { + if (sys_acl_set_qualifier(smb_ace, qualifier) != 0) { + DEBUG(3, ("sys_acl_set_qualifier failed\n")); + return False; + } + } + if (acl_get_permset(tru64_ace, &permset) != 0) { + DEBUG(3, ("acl_get_permset failed: %s\n", strerror(errno))); + return False; + } + smb_permset = tru64_permset_to_smb(*permset); + if (sys_acl_set_permset(smb_ace, &smb_permset) != 0) { + DEBUG(3, ("sys_acl_set_permset failed: %s\n", strerror(errno))); + return False; + } + return True; +} + +static acl_t smb_acl_to_tru64_acl(const SMB_ACL_T smb_acl) +{ + acl_t result; + acl_entry_t tru64_entry; + int i; + char *acl_text; + ssize_t acl_text_len; + + /* The tru64 acl_init function takes a size_t value + * instead of a count of entries (as with posix). + * the size parameter "Specifies the size of the working + * storage in bytes" (according to the man page). + * But it is unclear to me, how this size is to be + * calculated. + * + * It should not matter, since acl_create_entry enlarges + * the working storage at need. ... */ + + DEBUG(10, ("Hi! This is smb_acl_to_tru64_acl.\n")); + + result = acl_init(1); + + if (result == NULL) { + DEBUG(3, ("acl_init failed!\n")); + goto fail; + } + + DEBUGADD(10, ("parsing acl entries...\n")); + for (i = 0; i < smb_acl->count; i++) { + /* XYZ - maybe eliminate this direct access? */ + const struct smb_acl_entry *smb_entry = &smb_acl->acl[i]; + acl_tag_t tru64_tag; + acl_perm_t tru64_permset; + + tru64_tag = smb_tag_to_tru64(smb_entry->a_type); + if (tru64_tag == -1) { + DEBUG(3, ("smb_tag_to_tru64 failed!\n")); + goto fail; + } + + if (tru64_tag == ACL_MASK) { + DEBUGADD(10, (" - acl type ACL_MASK: not implemented on Tru64 ==> skipping\n")); + continue; + } + + tru64_entry = acl_create_entry(&result); + if (tru64_entry == NULL) { + DEBUG(3, ("acl_create_entry failed: %s\n", + strerror(errno))); + goto fail; + } + + if (acl_set_tag_type(tru64_entry, tru64_tag) != 0) { + DEBUG(3, ("acl_set_tag_type(%d) failed: %s\n", + strerror(errno))); + goto fail; + } + + switch (smb_entry->a_type) { + case SMB_ACL_USER: + if (acl_set_qualifier(tru64_entry, + (int *)&smb_entry->uid) != 0) + { + DEBUG(3, ("acl_set_qualifier failed: %s\n", + strerror(errno))); + goto fail; + } + DEBUGADD(10, (" - setting uid to %d\n", smb_entry->uid)); + break; + case SMB_ACL_GROUP: + if (acl_set_qualifier(tru64_entry, + (int *)&smb_entry->gid) != 0) + { + DEBUG(3, ("acl_set_qualifier failed: %s\n", + strerror(errno))); + goto fail; + } + DEBUGADD(10, (" - setting gid to %d\n", smb_entry->gid)); + break; + default: + break; + } + + tru64_permset = smb_permset_to_tru64(smb_entry->a_perm); + if (tru64_permset == -1) { + DEBUG(3, ("smb_permset_to_tru64 failed!\n")); + goto fail; + } + DEBUGADD(10, (" - setting perms to %0d\n", tru64_permset)); + if (acl_set_permset(tru64_entry, &tru64_permset) != 0) + { + DEBUG(3, ("acl_set_permset failed: %s\n", strerror(errno))); + goto fail; + } + } /* for */ + DEBUGADD(10, ("done parsing acl entries\n")); + + tru64_entry = NULL; + if (acl_valid(result, &tru64_entry) != 0) { + DEBUG(1, ("smb_acl_to_tru64_acl: ACL is invalid (%s)\n", + strerror(errno))); + if (tru64_entry != NULL) { + DEBUGADD(1, ("the acl contains duplicate entries\n")); + } + goto fail; + } + DEBUGADD(10, ("acl is valid\n")); + + acl_text = acl_to_text(result, &acl_text_len); + if (acl_text == NULL) { + DEBUG(3, ("acl_to_text failed: %s\n", strerror(errno))); + goto fail; + } + DEBUG(1, ("acl_text: %s\n", acl_text)); + free(acl_text); + + return result; + +fail: + if (result != NULL) { + acl_free(result); + } + DEBUG(1, ("smb_acl_to_tru64_acl failed!\n")); + return NULL; +} + +static acl_tag_t smb_tag_to_tru64(SMB_ACL_TAG_T smb_tag) +{ + acl_tag_t result; + switch (smb_tag) { + case SMB_ACL_USER: + result = ACL_USER; + DEBUGADD(10, ("got acl type ACL_USER\n")); + break; + case SMB_ACL_USER_OBJ: + result = ACL_USER_OBJ; + DEBUGADD(10, ("got acl type ACL_USER_OBJ\n")); + break; + case SMB_ACL_GROUP: + result = ACL_GROUP; + DEBUGADD(10, ("got acl type ACL_GROUP\n")); + break; + case SMB_ACL_GROUP_OBJ: + result = ACL_GROUP_OBJ; + DEBUGADD(10, ("got acl type ACL_GROUP_OBJ\n")); + break; + case SMB_ACL_OTHER: + result = ACL_OTHER; + DEBUGADD(10, ("got acl type ACL_OTHER\n")); + break; + case SMB_ACL_MASK: + result = ACL_MASK; + DEBUGADD(10, ("got acl type ACL_MASK\n")); + break; + default: + DEBUG(1, ("Unknown tag type %d\n", smb_tag)); + result = -1; + } + return result; +} + + +static SMB_ACL_TAG_T tru64_tag_to_smb(acl_tag_t tru64_tag) +{ + SMB_ACL_TAG_T smb_tag_type; + switch(tru64_tag) { + case ACL_USER: + smb_tag_type = SMB_ACL_USER; + DEBUGADD(10, ("got smb acl tag type SMB_ACL_USER\n")); + break; + case ACL_USER_OBJ: + smb_tag_type = SMB_ACL_USER_OBJ; + DEBUGADD(10, ("got smb acl tag type SMB_ACL_USER_OBJ\n")); + break; + case ACL_GROUP: + smb_tag_type = SMB_ACL_GROUP; + DEBUGADD(10, ("got smb acl tag type SMB_ACL_GROUP\n")); + break; + case ACL_GROUP_OBJ: + smb_tag_type = SMB_ACL_GROUP_OBJ; + DEBUGADD(10, ("got smb acl tag type SMB_ACL_GROUP_OBJ\n")); + break; + case ACL_OTHER: + smb_tag_type = SMB_ACL_OTHER; + DEBUGADD(10, ("got smb acl tag type SMB_ACL_OTHER\n")); + break; + case ACL_MASK: + smb_tag_type = SMB_ACL_MASK; + DEBUGADD(10, ("got smb acl tag type SMB_ACL_MASK\n")); + break; + default: + DEBUG(0, ("Unknown tag type %d\n", (unsigned int)tru64_tag)); + smb_tag_type = 0; + } + return smb_tag_type; +} + +static acl_perm_t smb_permset_to_tru64(smb_acl_permset_t smb_permset) +{ + /* originally, I thought that acl_clear_perm was the + * proper way to reset the permset to 0. but without + * initializing it to 0, acl_clear_perm fails. + * so probably, acl_clear_perm is not necessary here... ?! */ + acl_perm_t tru64_permset = 0; + if (acl_clear_perm(&tru64_permset) != 0) { + DEBUG(5, ("acl_clear_perm failed: %s\n", strerror(errno))); + return -1; + } + /* according to original lib/sysacls.c, acl_add_perm is + * broken on tru64 ... */ + tru64_permset |= ((smb_permset & SMB_ACL_READ) ? ACL_READ : 0); + tru64_permset |= ((smb_permset & SMB_ACL_WRITE) ? ACL_WRITE : 0); + tru64_permset |= ((smb_permset & SMB_ACL_EXECUTE) ? ACL_EXECUTE : 0); + return tru64_permset; +} + +static smb_acl_permset_t tru64_permset_to_smb(const acl_perm_t tru64_permset) +{ + smb_acl_permset_t smb_permset = 0; + smb_permset |= ((tru64_permset & ACL_READ) ? SMB_ACL_READ : 0); + smb_permset |= ((tru64_permset & ACL_WRITE) ? SMB_ACL_WRITE : 0); + smb_permset |= ((tru64_permset & ACL_EXECUTE) ? SMB_ACL_EXECUTE : 0); + return smb_permset; +} + + +/* VFS operations structure */ + +static vfs_op_tuple tru64acl_op_tuples[] = { + /* Disk operations */ + {SMB_VFS_OP(tru64acl_sys_acl_get_file), + SMB_VFS_OP_SYS_ACL_GET_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(tru64acl_sys_acl_get_fd), + SMB_VFS_OP_SYS_ACL_GET_FD, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(tru64acl_sys_acl_set_file), + SMB_VFS_OP_SYS_ACL_SET_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(tru64acl_sys_acl_set_fd), + SMB_VFS_OP_SYS_ACL_SET_FD, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(tru64acl_sys_acl_delete_def_file), + SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE, + SMB_VFS_LAYER_TRANSPARENT}, + + {SMB_VFS_OP(NULL), + SMB_VFS_OP_NOOP, + SMB_VFS_LAYER_NOOP} +}; + +NTSTATUS vfs_tru64acl_init(void); +NTSTATUS vfs_tru64acl_init(void) +{ + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "tru64acl", + tru64acl_op_tuples); +} + +/* ENTE */ diff --git a/source/modules/weird.c b/source/modules/weird.c index ccee9d71edd..12a535cbb75 100644 --- a/source/modules/weird.c +++ b/source/modules/weird.c @@ -125,6 +125,7 @@ static size_t weird_push(void *cd, const char **inbuf, size_t *inbytesleft, struct charset_functions weird_functions = {"WEIRD", weird_pull, weird_push}; +NTSTATUS charset_weird_init(void); NTSTATUS charset_weird_init(void) { return smb_register_charset(&weird_functions); |