lib: modules: Change XXX_init interface from XXX_init(void) to XXX_init(TALLOC_CTX *)
[sfrench/samba-autobuild/.git] / source3 / modules / vfs_tru64acl.c
index 60c08fdd574ce88611b6972a8bbd4ebd1a676bc6..83edc15205edef8681254d0a5fd177be4ca55833 100644 (file)
@@ -1,7 +1,7 @@
 /*
    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
 */
 
 #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,7 +39,8 @@ static SMB_ACL_PERM_T tru64_permset_to_smb(const acl_perm_t tru64_permset);
 
 SMB_ACL_T tru64acl_sys_acl_get_file(vfs_handle_struct *handle,
                                    const char *path_p,
-                                   SMB_ACL_TYPE_T type)
+                                   SMB_ACL_TYPE_T type,
+                                   TALLOC_CTX *mem_ctx)
 {
         struct smb_acl_t *result;
         acl_type_t the_acl_type;
@@ -61,23 +66,23 @@ SMB_ACL_T tru64acl_sys_acl_get_file(vfs_handle_struct *handle,
                 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;
 }
@@ -129,14 +134,14 @@ 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;
 
@@ -151,35 +156,35 @@ int tru64acl_sys_acl_delete_def_file(vfs_handle_struct *handle,
 
 /* 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;
@@ -187,14 +192,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;
@@ -300,23 +303,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;
@@ -467,38 +470,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 */