(root)/
acl-2.3.1/
libacl/
acl_calc_mask.c
       1  /*
       2    File: acl_calc_mask.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  
      26  /* 23.4.2 */
      27  int
      28  acl_calc_mask(acl_t *acl_p)
      29  {
      30  	acl_obj *acl_obj_p;
      31  	acl_entry_obj *entry_obj_p, *mask_obj_p = NULL;
      32  	permset_t perm = ACL_PERM_NONE;
      33  	if (!acl_p) {
      34  		errno = EINVAL;
      35  		return -1;
      36  	}
      37  	acl_obj_p = ext2int(acl, *acl_p);
      38  	if (!acl_obj_p)
      39  		return -1;
      40  	FOREACH_ACL_ENTRY(entry_obj_p, acl_obj_p) {
      41  		switch(entry_obj_p->etag) {
      42  			case ACL_USER_OBJ:
      43  			case ACL_OTHER:
      44  				break;
      45  			case ACL_MASK:
      46  				mask_obj_p = entry_obj_p;
      47  				break;
      48  			case ACL_USER:
      49  			case ACL_GROUP_OBJ:
      50  			case ACL_GROUP:
      51  				perm |= entry_obj_p->eperm.sperm;
      52  				break;
      53  			default:
      54  				errno = EINVAL;
      55  				return -1;
      56  		}
      57  	}
      58  	if (mask_obj_p == NULL) {
      59  		mask_obj_p = __acl_create_entry_obj(acl_obj_p);
      60  		if (mask_obj_p == NULL)
      61  			return -1;
      62  		mask_obj_p->etag = ACL_MASK;
      63  		__acl_reorder_entry_obj_p(mask_obj_p);
      64  	}
      65  	mask_obj_p->eperm.sperm = perm;
      66  	return 0;
      67  }
      68