/* Return 1 if the given ACL is non-trivial. Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ int acl_nontrivial (struct acl *a) { /* The normal way to iterate through an ACL is like this: struct acl_entry *ace; for (ace = a->acl_ext; ace != acl_last (a); ace = acl_nxt (ace)) { struct ace_id *aei; switch (ace->ace_type) { case ACC_PERMIT: case ACC_DENY: case ACC_SPECIFY: ...; } for (aei = ace->ace_id; aei != id_last (ace); aei = id_nxt (aei)) ... } */ return (acl_last (a) != a->acl_ext ? 1 : 0); }
SMB_ACL_T aixacl_to_smbacl(struct acl *file_acl) { struct acl_entry *acl_entry; struct ace_id *idp; struct smb_acl_t *result = SMB_MALLOC_P(struct smb_acl_t); 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 %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 * * contents of the acl since AIX intends * * the extended info to remain unused */ if(file_acl->acl_mode & S_IXACL){ /* while we are not pointing to the very end */ while(acl_entry < acl_last(file_acl)) { /* before we malloc anything, make sure this is */ /* a valid acl entry and one that we want to map */ idp = id_nxt(acl_entry->ace_id); if((acl_entry->ace_type == ACC_SPECIFY || (acl_entry->ace_type == ACC_PERMIT)) && (idp != id_last(acl_entry))) { acl_entry = acl_nxt(acl_entry); continue; } 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))); if (result == NULL) { DEBUG(0, ("SMB_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->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->a_type = SMB_ACL_GROUP; break; } default: break; } /* The access in the acl entries must be left shifted by * * three bites, because they will ultimately be compared * * to S_IRUSR, S_IWUSR, and S_IXUSR. */ switch(acl_entry->ace_type){ case ACC_PERMIT: case ACC_SPECIFY: ace->a_perm = acl_entry->ace_access; ace->a_perm <<= 6; DEBUG(10,("ace->a_perm is %d\n",ace->a_perm)); break; case ACC_DENY: /* Since there is no way to return a DENY acl entry * * change to PERMIT and then shift. */ DEBUG(10,("acl_entry->ace_access is %d\n",acl_entry->ace_access)); ace->a_perm = ~acl_entry->ace_access & 7; DEBUG(10,("ace->a_perm is %d\n",ace->a_perm)); ace->a_perm <<= 6; break; default: DEBUG(0, ("unknown ace->type\n")); SAFE_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 = %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 */ /* Since owner, group, other acl entries are not * * part of the acl entries in an acl, they must * * be dummied up to become part of the list. */ 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; } ace = &result->acl[result->count]; ace->uid = 0; ace->gid = 0; DEBUG(10,("ace->uid = %d\n",ace->uid)); switch(i) { case 2: ace->a_perm = file_acl->g_access << 6; ace->a_type = SMB_ACL_GROUP_OBJ; break; case 3: 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); } 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; }