selftest/Samba4: make use of get_cmd_env_vars() to setup all relevant env variables
[samba.git] / source3 / modules / vfs_aixacl_util.c
index fd7481af3ef02daac85d0e24a97962a3c829f973..38b53eb3f535a8911c669626f4c91efa7185468a 100644 (file)
@@ -5,7 +5,7 @@
 
    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 "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;
 
-
-       
-       DEBUG(10,("acl_entry is %d\n",acl_entry));
-       DEBUG(10,("acl_last(file_acl) id %d\n",acl_last(file_acl)));
+       DEBUG(10,("acl_entry is %p\n",(void *)acl_entry));
+       DEBUG(10,("acl_last(file_acl) id %p\n",(void *)acl_last(file_acl)));
 
        /* Check if the extended acl bit is on.   *
         * If it isn't, do not show the           *
@@ -61,33 +60,30 @@ 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;
                        }
-                       
 
                        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->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;
                        }
@@ -115,19 +111,19 @@ 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);
                        }
-               
+
                        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,("acl_entry = %p\n",(void *)acl_entry));
                        DEBUG(10,("The ace_type is %d\n",acl_entry->ace_type));
+
                        acl_entry = acl_nxt(acl_entry);
                }
        } /* end of if enabled */
@@ -139,22 +135,21 @@ 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:
                        ace->a_perm = file_acl->g_access << 6;
@@ -165,12 +160,12 @@ SMB_ACL_T aixacl_to_smbacl(struct acl *file_acl)
                        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);
 
@@ -178,17 +173,14 @@ SMB_ACL_T aixacl_to_smbacl(struct acl *file_acl)
                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)
@@ -210,11 +202,10 @@ struct acl *aixacl_smb_to_aixacl(SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
        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;
+       unsigned int id_type;
+       unsigned int acl_length;
        int     i;
+
        DEBUG(10,("Entering aixacl_smb_to_aixacl\n"));
        /* AIX has no default ACL */
        if(acltype == SMB_ACL_TYPE_DEFAULT)
@@ -229,7 +220,7 @@ struct acl *aixacl_smb_to_aixacl(SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
        }
 
        memset(file_acl,0,BUFSIZ);
+
        file_acl->acl_len = ACL_SIZ;
        file_acl->acl_mode = S_IXACL;
 
@@ -290,7 +281,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;