(root)/
acl-2.3.1/
libacl/
__apply_mask_to_mode.c
       1  /*
       2    File: __apply_mask_to_mode.c
       3    (Linux Access Control List Management)
       4  
       5    Copyright (C) 1999-2002
       6    Andreas Gruenbacher, <andreas.gruenbacher@gmail.com>
       7   	
       8    This program is free software; you can redistribute it and/or
       9    modify it under the terms of the GNU Lesser General Public
      10    License as published by the Free Software Foundation; either
      11    version 2.1 of the License, or (at your option) any later version.
      12  
      13    This program is distributed in the hope that it will be useful,
      14    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      16    Lesser General Public License for more details.
      17  
      18    You should have received a copy of the GNU Lesser General Public
      19    License along with this library; if not, write to the Free Software
      20    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
      21  */
      22  
      23  #include "config.h"
      24  #include <sys/stat.h>
      25  #include "libacl.h"
      26  
      27  #if defined(HAVE_ACL_ENTRIES) && \
      28      defined (HAVE_ACL_GET_ENTRY) && defined(HAVE_ACL_GET_TAG_TYPE) && \
      29      defined (HAVE_ACL_GET_PERMSET) && defined(HAVE_ACL_GET_PERM)
      30  int
      31  __apply_mask_to_mode(mode_t *mode, acl_t acl)
      32  {
      33  	acl_entry_t entry;
      34  	int entry_id=ACL_FIRST_ENTRY;
      35  
      36  	/* A mimimal ACL which has three entries has no mask entry; the
      37  	   group file mode permission bits are exact. */
      38  	if (acl_entries(acl) == 3)
      39  		return 0;
      40  
      41  	while (acl_get_entry(acl, entry_id, &entry) == 1) {
      42  		acl_tag_t tag_type;
      43  
      44  		acl_get_tag_type(entry, &tag_type);
      45  		if (tag_type == ACL_MASK) {
      46  			acl_permset_t permset;
      47  
      48  			acl_get_permset(entry, &permset);
      49  			if (acl_get_perm(permset, ACL_READ) != 1)
      50  				*mode &= ~S_IRGRP;
      51  			if (acl_get_perm(permset, ACL_WRITE) != 1)
      52  				*mode &= ~S_IWGRP;
      53  			if (acl_get_perm(permset, ACL_EXECUTE) != 1)
      54  				*mode &= ~S_IXGRP;
      55  
      56  			return 0;
      57  		}
      58  		entry_id = ACL_NEXT_ENTRY;
      59  	}
      60  
      61  	/* This is unexpected; if the ACL didn't include a mask entry
      62  	   we should have exited before the loop! */
      63  	*mode &= ~S_IRWXG;
      64  	return 1;
      65  }
      66  #endif
      67  
      68