s3-vfs: Use the system. namespace for fake ACLs
[kai/samba.git] / source3 / modules / vfs_hpuxacl.c
index 1df3fbbf5a5b808bd71948f2771524fbb30d72b7..f8661b1134ca00c441752a46371e0d224f78d320 100644 (file)
 
 
 #include "includes.h"
+#include "system/filesys.h"
 #include "smbd/smbd.h"
+#include "modules/vfs_hpuxacl.h"
+
 
 /* 
  * including standard header <sys/aclv.h> 
@@ -142,7 +145,7 @@ SMB_ACL_T hpuxacl_sys_acl_get_file(vfs_handle_struct *handle,
        SMB_ACL_T result = NULL;
        int count;
        HPUX_ACL_T hpux_acl = NULL;
-       
+
        DEBUG(10, ("hpuxacl_sys_acl_get_file called for file '%s'.\n", 
                   path_p));
 
@@ -170,7 +173,7 @@ SMB_ACL_T hpuxacl_sys_acl_get_file(vfs_handle_struct *handle,
                DEBUG(10, ("conversion hpux_acl -> smb_acl failed (%s).\n",
                           strerror(errno)));
        }
-       
+
  done:
        DEBUG(10, ("hpuxacl_sys_acl_get_file %s.\n",
                   ((result == NULL) ? "failed" : "succeeded" )));
@@ -188,14 +191,6 @@ SMB_ACL_T hpuxacl_sys_acl_get_fd(vfs_handle_struct *handle,
         /* 
         * HPUX doesn't have the facl call. Fake it using the path.... JRA. 
         */
-       /* For all I see, the info should already be in the fsp
-        * parameter, but get it again to be safe --- necessary? */
-        files_struct *file_struct_p = file_find_fd(fsp->conn->sconn,
-                                                  fsp->fh->fd);
-        if (file_struct_p == NULL) {
-                errno = EBADF;
-                return NULL;
-        }
         /*
          * We know we're in the same conn context. So we
          * can use the relative path.
@@ -204,7 +199,7 @@ SMB_ACL_T hpuxacl_sys_acl_get_fd(vfs_handle_struct *handle,
                "hpuxacl_sys_acl_get_file (no facl syscall on HPUX).\n"));
 
         return hpuxacl_sys_acl_get_file(handle,
-                                       file_struct_p->fsp_name->base_name,
+                                       fsp->fsp_name->base_name,
                                        SMB_ACL_TYPE_ACCESS);
 }
 
@@ -219,7 +214,7 @@ int hpuxacl_sys_acl_set_file(vfs_handle_struct *handle,
        int count;
        struct smb_filename *smb_fname = NULL;
        NTSTATUS status;
-       
+
        DEBUG(10, ("hpuxacl_sys_acl_set_file called for file '%s'\n",
                   name));
 
@@ -304,12 +299,12 @@ int hpuxacl_sys_acl_set_file(vfs_handle_struct *handle,
        }
        DEBUG(10, ("resulting acl is valid.\n"));
 
-       ret = acl(CONST_DISCARD(char *, smb_fname->base_name), ACL_SET, count,
+       ret = acl(discard_const_p(char, smb_fname->base_name), ACL_SET, count,
                  hpux_acl);
        if (ret != 0) {
                DEBUG(0, ("ERROR calling acl: %s\n", strerror(errno)));
        }
-       
+
  done:
        DEBUG(10, ("hpuxacl_sys_acl_set_file %s.\n",
                   ((ret != 0) ? "failed" : "succeeded")));
@@ -328,14 +323,6 @@ int hpuxacl_sys_acl_set_fd(vfs_handle_struct *handle,
         /*
          * HPUX doesn't have the facl call. Fake it using the path.... JRA.
          */
-       /* For all I see, the info should already be in the fsp
-        * parameter, but get it again to be safe --- necessary? */
-        files_struct *file_struct_p = file_find_fd(fsp->conn->sconn,
-                                                  fsp->fh->fd);
-        if (file_struct_p == NULL) {
-                errno = EBADF;
-                return -1;
-        }
         /*
          * We know we're in the same conn context. So we
          * can use the relative path.
@@ -344,7 +331,7 @@ int hpuxacl_sys_acl_set_fd(vfs_handle_struct *handle,
                "hpuxacl_sys_acl_set_file (no facl syscall on HPUX)\n"));
 
         return hpuxacl_sys_acl_set_file(handle,
-                                       file_struct_p->fsp_name->base_name,
+                                       fsp->fsp_name->base_name,
                                        SMB_ACL_TYPE_ACCESS, theacl);
 }
 
@@ -374,7 +361,7 @@ int hpuxacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
        int count;
 
        DEBUG(10, ("entering hpuxacl_sys_acl_delete_def_file.\n"));
-       
+
        smb_acl = hpuxacl_sys_acl_get_file(handle, path, 
                                           SMB_ACL_TYPE_ACCESS);
        if (smb_acl == NULL) {
@@ -391,15 +378,15 @@ int hpuxacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
                DEBUG(10, ("resulting acl is not valid!\n"));
                goto done;
        }
-       ret = acl(CONST_DISCARD(char *, path), ACL_SET, count, hpux_acl);
+       ret = acl(discard_const_p(char, path), ACL_SET, count, hpux_acl);
        if (ret != 0) {
                DEBUG(10, ("settinge file acl failed!\n"));
        }
-       
+
  done:
        DEBUG(10, ("hpuxacl_sys_acl_delete_def_file %s.\n",
                   ((ret != 0) ? "failed" : "succeeded" )));
-       SAFE_FREE(smb_acl);
+       TALLOC_FREE(smb_acl);
        return ret;
 }
 
@@ -431,7 +418,7 @@ static bool smb_acl_to_hpux_acl(SMB_ACL_T smb_acl,
        int check_which, check_rc;
 
        DEBUG(10, ("entering smb_acl_to_hpux_acl\n"));
-       
+
        *hpux_acl = NULL;
        *count = 0;
 
@@ -464,7 +451,7 @@ static bool smb_acl_to_hpux_acl(SMB_ACL_T smb_acl,
                        DEBUG(10, ("adding default bit to hpux ace\n"));
                        hpux_entry.a_type |= ACL_DEFAULT;
                }
-               
+
                hpux_entry.a_perm = 
                        smb_perm_to_hpux_perm(smb_entry->a_perm);
                DEBUG(10, ("assembled the following hpux ace:\n"));
@@ -489,7 +476,7 @@ static bool smb_acl_to_hpux_acl(SMB_ACL_T smb_acl,
 
        ret = True;
        goto done;
-       
+
  fail:
        SAFE_FREE(*hpux_acl);
  done:
@@ -515,15 +502,12 @@ static SMB_ACL_T hpux_acl_to_smb_acl(HPUX_ACL_T hpux_acl, int count,
        for (i = 0; i < count; i++) {
                SMB_ACL_ENTRY_T smb_entry;
                SMB_ACL_PERM_T smb_perm;
-               
+
                if (!_IS_OF_TYPE(hpux_acl[i], type)) {
                        continue;
                }
-               result = SMB_REALLOC(result, 
-                                    sizeof(struct smb_acl_t) +
-                                    (sizeof(struct smb_acl_entry) *
-                                     (result->count + 1)));
-               if (result == NULL) {
+               result->acl = talloc_realloc(result, result->acl, struct smb_acl_entry, result->count + 1);
+               if (result->acl == NULL) {
                        DEBUG(10, ("error reallocating memory for SMB_ACL\n"));
                        goto fail;
                }
@@ -546,9 +530,8 @@ static SMB_ACL_T hpux_acl_to_smb_acl(HPUX_ACL_T hpux_acl, int count,
                result->count += 1;
        }
        goto done;
-       
  fail:
-       SAFE_FREE(result);
+       TALLOC_FREE(result);
  done:
        DEBUG(10, ("hpux_acl_to_smb_acl %s\n",
                   ((result == NULL) ? "failed" : "succeeded")));
@@ -563,7 +546,7 @@ static HPUX_ACL_TAG_T smb_tag_to_hpux_tag(SMB_ACL_TAG_T smb_tag)
 
        DEBUG(10, ("smb_tag_to_hpux_tag\n"));
        DEBUGADD(10, (" --> got smb tag 0x%04x\n", smb_tag));
-       
+
        switch (smb_tag) {
        case SMB_ACL_USER:
                hpux_tag = USER;
@@ -587,7 +570,7 @@ static HPUX_ACL_TAG_T smb_tag_to_hpux_tag(SMB_ACL_TAG_T smb_tag)
                DEBUGADD(10, (" !!! unknown smb tag type 0x%04x\n", smb_tag));
                break;
        }
-       
+
        DEBUGADD(10, (" --> determined hpux tag 0x%04x\n", hpux_tag));
 
        return hpux_tag;
@@ -599,7 +582,7 @@ static SMB_ACL_TAG_T hpux_tag_to_smb_tag(HPUX_ACL_TAG_T hpux_tag)
 
        DEBUG(10, ("hpux_tag_to_smb_tag:\n"));
        DEBUGADD(10, (" --> got hpux tag 0x%04x\n", hpux_tag)); 
-       
+
        hpux_tag &= ~ACL_DEFAULT; 
 
        switch (hpux_tag) {
@@ -628,7 +611,7 @@ static SMB_ACL_TAG_T hpux_tag_to_smb_tag(HPUX_ACL_TAG_T hpux_tag)
        }
 
        DEBUGADD(10, (" --> determined smb tag 0x%04x\n", smb_tag));
-       
+
        return smb_tag;
 }
 
@@ -665,7 +648,7 @@ static bool hpux_acl_get_file(const char *name, HPUX_ACL_T *hpux_acl,
        static HPUX_ACE_T dummy_ace;
 
        DEBUG(10, ("hpux_acl_get_file called for file '%s'\n", name));
-       
+
        /* 
         * The original code tries some INITIAL_ACL_SIZE
         * and only did the ACL_CNT call upon failure
@@ -679,7 +662,7 @@ static bool hpux_acl_get_file(const char *name, HPUX_ACL_T *hpux_acl,
         * instantiated or malloced each time this function is
         * called). Btw: the count parameter does not seem to matter...
         */
-       *count = acl(CONST_DISCARD(char *, name), ACL_CNT, 0, &dummy_ace);
+       *count = acl(discard_const_p(char, name), ACL_CNT, 0, &dummy_ace);
        if (*count < 0) {
                DEBUG(10, ("acl ACL_CNT failed: %s\n", strerror(errno)));
                goto done;
@@ -689,7 +672,7 @@ static bool hpux_acl_get_file(const char *name, HPUX_ACL_T *hpux_acl,
                DEBUG(10, ("error allocating memory for hpux acl...\n"));
                goto done;
        }
-       *count = acl(CONST_DISCARD(char *, name), ACL_GET, *count, *hpux_acl);
+       *count = acl(discard_const_p(char, name), ACL_GET, *count, *hpux_acl);
        if (*count < 0) {
                DEBUG(10, ("acl ACL_GET failed: %s\n", strerror(errno)));
                goto done;
@@ -726,7 +709,7 @@ static bool hpux_add_to_acl(HPUX_ACL_T *hpux_acl, int *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));
@@ -960,7 +943,7 @@ static int hpux_internal_aclsort(int acl_count, int calclass, HPUX_ACL_T aclp)
        struct hpux_acl_types acl_obj_count;
        int n_class_obj_perm = 0;
        int i, j;
+
        DEBUG(10,("Entering hpux_internal_aclsort. (calclass = %d)\n", calclass));
 
        if (hpux_aclsort_call_present()) {
@@ -1144,7 +1127,7 @@ static bool hpux_acl_check(HPUX_ACL_T hpux_acl, int count)
 {
        int check_rc;
        int check_which;
-       
+
        check_rc = aclcheck(hpux_acl, count, &check_which);
        if (check_rc != 0) {
                DEBUG(10, ("acl is not valid:\n"));
@@ -1168,11 +1151,11 @@ static bool hpux_acl_check(HPUX_ACL_T hpux_acl, int count)
 /* VFS operations structure */
 
 static struct vfs_fn_pointers hpuxacl_fns = {
-       .sys_acl_get_file = hpuxacl_sys_acl_get_file,
-       .sys_acl_get_fd = hpuxacl_sys_acl_get_fd,
-       .sys_acl_set_file = hpuxacl_sys_acl_set_file,
-       .sys_acl_set_fd = hpuxacl_sys_acl_set_fd,
-       .sys_acl_delete_def_file = hpuxacl_sys_acl_delete_def_file,
+       .sys_acl_get_file_fn = hpuxacl_sys_acl_get_file,
+       .sys_acl_get_fd_fn = hpuxacl_sys_acl_get_fd,
+       .sys_acl_set_file_fn = hpuxacl_sys_acl_set_file,
+       .sys_acl_set_fd_fn = hpuxacl_sys_acl_set_fd,
+       .sys_acl_delete_def_file_fn = hpuxacl_sys_acl_delete_def_file,
 };
 
 NTSTATUS vfs_hpuxacl_init(void)