(root)/
acl-2.3.1/
libacl/
__acl_from_xattr.c
       1  /*
       2    File: __acl_from_xattr.c
       3  
       4    Copyright (C) 1999, 2000
       5    Andreas Gruenbacher, <andreas.gruenbacher@gmail.com>
       6  
       7    This program is free software; you can redistribute it and/or
       8    modify it under the terms of the GNU Lesser General Public
       9    License as published by the Free Software Foundation; either
      10    version 2.1 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    Lesser General Public License for more details.
      16  
      17    You should have received a copy of the GNU Lesser 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 "config.h"
      23  #include "libacl.h"
      24  
      25  #include "byteorder.h"
      26  #include "acl_ea.h"
      27  
      28  
      29  acl_t
      30  __acl_from_xattr(const char *ext_acl_p, size_t size)
      31  {
      32  	acl_ea_header *ext_header_p = (acl_ea_header *)ext_acl_p;
      33  	acl_ea_entry *ext_entry_p = (acl_ea_entry *)(ext_header_p+1);
      34  	acl_ea_entry *ext_end_p;
      35  	acl_obj *acl_obj_p;
      36  	acl_entry_obj *entry_obj_p;
      37  	int entries;
      38  
      39  	if (size < sizeof(acl_ea_header)) {
      40  		errno = EINVAL;
      41  		return NULL;
      42  	}
      43  	if (ext_header_p->a_version != cpu_to_le32(ACL_EA_VERSION)) {
      44  		errno = EINVAL;
      45  		return NULL;
      46  	}
      47  	size -= sizeof(acl_ea_header);
      48  	if (size % sizeof(acl_ea_entry)) {
      49  		errno = EINVAL;
      50  		return NULL;
      51  	}
      52  	entries = size / sizeof(acl_ea_entry);
      53  	ext_end_p = ext_entry_p + entries;
      54  
      55  	acl_obj_p = __acl_init_obj(entries);
      56  	if (acl_obj_p == NULL)
      57  		return NULL;
      58  	while (ext_end_p != ext_entry_p) {
      59  		entry_obj_p = __acl_create_entry_obj(acl_obj_p);
      60  		if (!entry_obj_p)
      61  			goto fail;
      62  
      63  		entry_obj_p->etag        = le16_to_cpu(ext_entry_p->e_tag);
      64  		entry_obj_p->eperm.sperm = le16_to_cpu(ext_entry_p->e_perm);
      65  
      66  		switch(entry_obj_p->etag) {
      67  			case ACL_USER_OBJ:
      68  			case ACL_GROUP_OBJ:
      69  			case ACL_MASK:
      70  			case ACL_OTHER:
      71  				entry_obj_p->eid.qid = ACL_UNDEFINED_ID;
      72  				break;
      73  
      74  			case ACL_USER:
      75  			case ACL_GROUP:
      76  				entry_obj_p->eid.qid =
      77  					le32_to_cpu(ext_entry_p->e_id);
      78  				break;
      79  
      80  			default:
      81  				errno = EINVAL;
      82  				goto fail;
      83  		}
      84  		ext_entry_p++;
      85  	}
      86  	if (__acl_reorder_obj_p(acl_obj_p))
      87  		goto fail;
      88  	return int2ext(acl_obj_p);
      89  
      90  fail:
      91  	__acl_free_acl_obj(acl_obj_p);
      92  	return NULL;
      93  }
      94