s3:modules/non_posix_acls: only stat if we do not have it cached
[samba.git] / source3 / modules / vfs_aixacl_util.c
index 2d84f03bfb085dc6f4bda9699c5b1c7d33fdfa3f..1194d27df22b48aeb57a632550aeeb4173e89b3d 100644 (file)
 */
 
 #include "includes.h"
+#include "system/filesys.h"
+#include "smbd/smbd.h"
+#include "vfs_aixacl_util.h"
 
-SMB_ACL_T aixacl_to_smbacl(struct acl *file_acl)
+SMB_ACL_T aixacl_to_smbacl(struct acl *file_acl, TALLOC_CTX *mem_ctx)
 {
        struct acl_entry *acl_entry;
        struct ace_id *idp;
        
-       struct smb_acl_t *result = SMB_MALLOC_P(struct smb_acl_t);
+       struct smb_acl_t *result = sys_acl_init(mem_ctx);
        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;
@@ -61,11 +63,9 @@ SMB_ACL_T aixacl_to_smbacl(struct acl *file_acl)
                        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)));
+                       result->acl = talloc_realloc(result, result->acl, struct smb_acl_entry, result->count+1);
                        if (result == NULL) {
-                               DEBUG(0, ("SMB_REALLOC failed\n"));
+                               DEBUG(0, ("talloc_realloc failed\n"));
                                errno = ENOMEM;
                                return NULL;
                        }
@@ -78,15 +78,15 @@ SMB_ACL_T aixacl_to_smbacl(struct acl *file_acl)
                                                        
                        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->info.user.uid = idp->id_data[0];
+                       DEBUG(10,("case ACEID_USER ace->info.user.uid is %d\n",ace->info.user.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->info.group.gid = idp->id_data[0];
+                       DEBUG(10,("case ACEID_GROUP ace->info.group.gid is %d\n",ace->info.group.gid));
                        ace->a_type = SMB_ACL_GROUP;
                        break;
                        }
@@ -114,7 +114,7 @@ SMB_ACL_T aixacl_to_smbacl(struct acl *file_acl)
                                break;
                        default:
                                DEBUG(0, ("unknown ace->type\n"));
-                               SAFE_FREE(result);
+                               TALLOC_FREE(result);
                                return(0);
                        }
                
@@ -138,21 +138,20 @@ SMB_ACL_T aixacl_to_smbacl(struct acl *file_acl)
        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;
-                       }
+               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\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));
+               ace->info.user.uid = 0;
+               ace->info.group.gid = 0;
+               DEBUG(10,("ace->info.user.uid = %d\n",ace->info.user.uid));
                
                switch(i) {
                case 2:
@@ -288,7 +287,7 @@ struct acl *aixacl_smb_to_aixacl(SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
                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;
+               ace_id->id_data[0] = (smb_entry->a_type==SMB_ACL_GROUP) ? smb_entry->info.group.gid : smb_entry->info.user.uid;
        }
 
        return file_acl;