1/* 2 File: __acl_to_xattr.c 3 4 Copyright (C) 1999, 2000 5 Andreas Gruenbacher, <a.gruenbacher@computer.org> 6 7 This program is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Library General Public 9 License as published by the Free Software Foundation; either 10 version 2 of the License, or (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Library General Public License for more details. 16 17 You should have received a copy of the GNU Library General Public 18 License along with this library; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20*/ 21 22#include <errno.h> 23#include <sys/acl.h> 24#include "libacl.h" 25 26#include "byteorder.h" 27#include "acl_ea.h" 28 29 30char * 31__acl_to_xattr(const acl_obj *acl_obj_p, size_t *size) 32{ 33 const acl_entry_obj *entry_obj_p; 34 acl_ea_header *ext_header_p; 35 acl_ea_entry *ext_ent_p; 36 37 *size = sizeof(acl_ea_header) + acl_obj_p->aused * sizeof(acl_ea_entry); 38 ext_header_p = (acl_ea_header *)malloc(*size); 39 if (!ext_header_p) 40 return NULL; 41 42 ext_header_p->a_version = cpu_to_le32(ACL_EA_VERSION); 43 ext_ent_p = (acl_ea_entry *)(ext_header_p+1); 44 FOREACH_ACL_ENTRY(entry_obj_p, acl_obj_p) { 45 ext_ent_p->e_tag = cpu_to_le16(entry_obj_p->etag); 46 ext_ent_p->e_perm = cpu_to_le16(entry_obj_p->eperm.sperm); 47 48 switch(entry_obj_p->etag) { 49 case ACL_USER: 50 case ACL_GROUP: 51 ext_ent_p->e_id = 52 cpu_to_le32(entry_obj_p->eid.qid); 53 break; 54 55 default: 56 ext_ent_p->e_id = ACL_UNDEFINED_ID; 57 break; 58 } 59 ext_ent_p++; 60 } 61 return (char *)ext_header_p; 62} 63 64