(root)/
acl-2.3.1/
libacl/
acl_equiv_mode.c
       1  /*
       2    File: acl_equiv_mode.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 <stdio.h>
      24  #include <errno.h>
      25  #include <sys/stat.h>
      26  #include "libacl.h"
      27  
      28  
      29  int
      30  acl_equiv_mode(acl_t acl, mode_t *mode_p)
      31  {
      32  	acl_obj *acl_obj_p = ext2int(acl, acl);
      33  	acl_entry_obj *entry_obj_p, *mask_obj_p = NULL;
      34  	int not_equiv = 0;
      35  	mode_t mode = 0;
      36  	if (!acl_obj_p)
      37  		return -1;
      38  	FOREACH_ACL_ENTRY(entry_obj_p, acl_obj_p) {
      39  		switch(entry_obj_p->etag) {
      40  			case ACL_USER_OBJ:
      41  				mode |= (entry_obj_p->eperm.sperm
      42  				         & S_IRWXO) << 6;
      43  				break;
      44  			case ACL_GROUP_OBJ:
      45  				mode |= (entry_obj_p->eperm.sperm &
      46  				         S_IRWXO) << 3;
      47  				break;
      48  			case ACL_OTHER:
      49  				mode |= (entry_obj_p->eperm.sperm &
      50  				         S_IRWXO);
      51  				break;
      52  			case ACL_MASK:
      53  				mask_obj_p = entry_obj_p;
      54  				/* fall through */
      55  			case ACL_USER:
      56  			case ACL_GROUP:
      57  				not_equiv = 1;
      58  				break;
      59  			default:
      60  				errno = EINVAL;
      61  				return -1;
      62  		}
      63  	}
      64  	if (mode_p) {
      65  		if (mask_obj_p)
      66  			mode = (mode & ~S_IRWXG) |
      67  			       ((mask_obj_p->eperm.sperm & S_IRWXO) << 3);
      68  		*mode_p = mode;
      69  	}
      70  	return not_equiv;
      71  }
      72