s3: VFS: Change SMB_VFS_SYS_ACL_SET_FILE to use const struct smb_filename * instead...
[samba.git] / source3 / modules / vfs_tru64acl.c
index 0c2de36911f2c32f2cd2b581ab47779489fd203e..d44e56a0df9f0a18cf6b8047357f1135dd19c28b 100644 (file)
@@ -1,11 +1,11 @@
 /*
    Unix SMB/Netbios implementation.
    VFS module to get and set Tru64 acls
-   Copyright (C) Michael Adam 2006
+   Copyright (C) Michael Adam 2006,2008
 
    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
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    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.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
+#include "system/filesys.h"
+#include "smbd/smbd.h"
+#include "modules/vfs_tru64acl.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, 
+static struct smb_acl_t *tru64_acl_to_smb_acl(const struct acl *tru64_acl,
+                                             TALLOC_CTX *mem_ctx);
+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);
@@ -35,8 +38,9 @@ static SMB_ACL_PERM_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)
+                               const struct smb_filename *smb_fname,
+                               SMB_ACL_TYPE_T type,
+                               TALLOC_CTX *mem_ctx)
 {
         struct smb_acl_t *result;
         acl_type_t the_acl_type;
@@ -56,35 +60,35 @@ SMB_ACL_T tru64acl_sys_acl_get_file(vfs_handle_struct *handle,
                 return NULL;
         }
 
-        tru64_acl = acl_get_file((char *)path_p, the_acl_type);
+        tru64_acl = acl_get_file((char *)smb_fname->base_name, the_acl_type);
 
         if (tru64_acl == NULL) {
                 return NULL;
         }
 
-        result = tru64_acl_to_smb_acl(tru64_acl);
+        result = tru64_acl_to_smb_acl(tru64_acl, mem_ctx);
         acl_free(tru64_acl);
         return result;
 }
 
 SMB_ACL_T tru64acl_sys_acl_get_fd(vfs_handle_struct *handle,
                                  files_struct *fsp,
-                                 int fd)
+                                 TALLOC_CTX *mem_ctx)
 {
        struct smb_acl_t *result;
-       acl_t tru64_acl = acl_get_fd(fd, ACL_TYPE_ACCESS);
+       acl_t tru64_acl = acl_get_fd(fsp->fh->fd, ACL_TYPE_ACCESS);
 
        if (tru64_acl == NULL) {
                return NULL;
        }
        
-       result = tru64_acl_to_smb_acl(tru64_acl);
+       result = tru64_acl_to_smb_acl(tru64_acl, mem_ctx);
        acl_free(tru64_acl);
        return result;
 }
 
 int tru64acl_sys_acl_set_file(vfs_handle_struct *handle,
-                             const char *name,
+                             const struct smb_filename *smb_fname,
                              SMB_ACL_TYPE_T type,
                              SMB_ACL_T theacl)
 {
@@ -93,7 +97,7 @@ int tru64acl_sys_acl_set_file(vfs_handle_struct *handle,
         acl_t tru64_acl;
 
         DEBUG(10, ("tru64acl_sys_acl_set_file called with name %s, type %d\n", 
-                       name, type));
+                       smb_fname->base_name, type));
 
         switch(type) {
         case SMB_ACL_TYPE_ACCESS:
@@ -116,7 +120,8 @@ int tru64acl_sys_acl_set_file(vfs_handle_struct *handle,
                 goto fail;
         }
        DEBUG(10, ("got tru64 acl...\n"));
-        res = acl_set_file((char *)name, the_acl_type, tru64_acl);
+        res = acl_set_file((char *)smb_fname->base_name,
+                               the_acl_type, tru64_acl);
         acl_free(tru64_acl);
         if (res != 0) {
                 DEBUG(10, ("acl_set_file failed: %s\n", strerror(errno)));
@@ -130,57 +135,57 @@ fail:
 
 int tru64acl_sys_acl_set_fd(vfs_handle_struct *handle,
                            files_struct *fsp,
-                           int fd, SMB_ACL_T theacl)
+                           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);
+        res =  acl_set_fd(fsp->fh->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)
+                               const struct smb_filename *smb_fname)
 {
-       return acl_delete_def_file((char *)path);
+       return acl_delete_def_file((char *)smb_fname->base_name);
 }
 
 
 /* private functions */
 
-static struct smb_acl_t *tru64_acl_to_smb_acl(const struct acl *tru64_acl) 
+static struct smb_acl_t *tru64_acl_to_smb_acl(const struct acl *tru64_acl,
+                                             TALLOC_CTX *mem_ctx)
 {
        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"));
+       if ((result = sys_acl_init(mem_ctx)) == NULL) {
+               DEBUG(0, ("sys_acl_init() 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"));
+               result->acl = talloc_realloc(result, result->acl, struct smb_acl_entry, 
+                                            result->count + 1);
+               if (result->acl == NULL) {
+                       TALLOC_FREE(result);
+                       DEBUG(0, ("talloc_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);
+                       TALLOC_FREE(result);
                        goto fail;
                }
                result->count += 1;
@@ -188,14 +193,12 @@ static struct smb_acl_t *tru64_acl_to_smb_acl(const struct acl *tru64_acl)
        return result;
 
 fail:
-       if (result != NULL) {
-               SAFE_FREE(result);
-       }
+       TALLOC_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, 
+static bool tru64_ace_to_smb_ace(acl_entry_t tru64_ace, 
                                struct smb_acl_entry *smb_ace) 
 {
        acl_tag_t tru64_tag;
@@ -301,23 +304,23 @@ static acl_t smb_acl_to_tru64_acl(const SMB_ACL_T smb_acl)
                switch (smb_entry->a_type) {
                case SMB_ACL_USER:
                        if (acl_set_qualifier(tru64_entry, 
-                                               (int *)&smb_entry->uid) != 0) 
+                                               (int *)&smb_entry->info.user.uid) != 0) 
                        {
                                DEBUG(3, ("acl_set_qualifier failed: %s\n",
                                        strerror(errno)));
                                goto fail;
                        }
-                       DEBUGADD(10, (" - setting uid to %d\n", smb_entry->uid));
+                       DEBUGADD(10, (" - setting uid to %d\n", smb_entry->info.user.uid));
                        break;
                case SMB_ACL_GROUP:
                        if (acl_set_qualifier(tru64_entry, 
-                                               (int *)&smb_entry->gid) != 0)
+                                               (int *)&smb_entry->info.group.gid) != 0)
                        {
                                DEBUG(3, ("acl_set_qualifier failed: %s\n",
                                        strerror(errno)));
                                goto fail;
                        }
-                       DEBUGADD(10, (" - setting gid to %d\n", smb_entry->gid));
+                       DEBUGADD(10, (" - setting gid to %d\n", smb_entry->info.group.gid));
                        break;
                default:
                        break;
@@ -468,38 +471,21 @@ static SMB_ACL_PERM_T tru64_permset_to_smb(const acl_perm_t tru64_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}
+static struct vfs_fn_pointers tru64acl_fns = {
+       .sys_acl_get_file_fn = tru64acl_sys_acl_get_file,
+       .sys_acl_get_fd_fn = tru64acl_sys_acl_get_fd,
+       .sys_acl_blob_get_file_fn = posix_sys_acl_blob_get_file,
+       .sys_acl_blob_get_fd_fn = posix_sys_acl_blob_get_fd,
+       .sys_acl_set_file_fn = tru64acl_sys_acl_set_file,
+       .sys_acl_set_fd_fn = tru64acl_sys_acl_set_fd,
+       .sys_acl_delete_def_file_fn = tru64acl_sys_acl_delete_def_file,
 };
 
-NTSTATUS vfs_tru64acl_init(void);
-NTSTATUS vfs_tru64acl_init(void)
+NTSTATUS vfs_tru64acl_init(TALLOC_CTX *);
+NTSTATUS vfs_tru64acl_init(TALLOC_CTX *ctx)
 {
        return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "tru64acl",
-                               tru64acl_op_tuples);
+                               &tru64acl_fns);
 }
 
 /* ENTE */