view lib/acl-internal.h @ 16935:498a2211d839

Write "Mac OS X" instead of "MacOS X". * README: Write "Mac OS X" instead of "MacOS X". * build-aux/bootstrap: Likewise. * build-aux/install-reloc: Likewise. * lib/acl-internal.h: Likewise. * lib/acl_entries.c: Likewise. * lib/argp-ba.c: Likewise. * lib/argp-pv.c: Likewise. * lib/config.charset: Likewise. * lib/copy-acl.c: Likewise. * lib/csharpexec.c: Likewise. * lib/euidaccess.c: Likewise. * lib/fbufmode.c: Likewise. * lib/fflush.c: Likewise. * lib/file-has-acl.c: Likewise. * lib/filemode.h: Likewise. * lib/fpurge.c: Likewise. * lib/freadable.c: Likewise. * lib/freadahead.c: Likewise. * lib/freading.c: Likewise. * lib/freadptr.c: Likewise. * lib/freadseek.c: Likewise. * lib/fseeko.c: Likewise. * lib/fseterr.c: Likewise. * lib/fsusage.c: Likewise. * lib/fwritable.c: Likewise. * lib/fwriting.c: Likewise. * lib/get-rusage-as.c: Likewise. * lib/get-rusage-data.c: Likewise. * lib/getdomainname.c: Likewise. * lib/idpriv-drop.c: Likewise. * lib/idpriv-droptemp.c: Likewise. * lib/localcharset.c: Likewise. * lib/locale.in.h: Likewise. * lib/localename.c: Likewise. * lib/mbsrtowcs-state.c: Likewise. * lib/nproc.c: Likewise. * lib/passfd.c: Likewise. * lib/posix_openpt.c: Likewise. * lib/printf-parse.c: Likewise. * lib/progreloc.c: Likewise. * lib/safe-read.h: Likewise. * lib/safe-write.h: Likewise. * lib/sched.in.h: Likewise. * lib/set-mode-acl.c: Likewise. * lib/signal.in.h: Likewise. * lib/stdint.in.h: Likewise. * lib/stdio-impl.h: Likewise. * lib/stdlib.in.h: Likewise. * lib/strtod.c: Likewise. * lib/sys_select.in.h: Likewise. * lib/tcgetsid.c: Likewise. * lib/unistd.in.h: Likewise. * lib/unlockpt.c: Likewise. * lib/vasnprintf.c: Likewise. * lib/vma-iter.c: Likewise. * lib/wcsrtombs-state.c: Likewise. * m4/acl.m4: Likewise. * m4/acosl.m4: Likewise. * m4/asinl.m4: Likewise. * m4/atanl.m4: Likewise. * m4/c-stack.m4: Likewise. * m4/cosl.m4: Likewise. * m4/expl.m4: Likewise. * m4/extensions.m4: Likewise. * m4/fdatasync.m4: Likewise. * m4/fmal.m4: Likewise. * m4/frexp.m4: Likewise. * m4/frexpf.m4: Likewise. * m4/frexpl.m4: Likewise. * m4/fsusage.m4: Likewise. * m4/getdomainname.m4: Likewise. * m4/getloadavg.m4: Likewise. * m4/getopt.m4: Likewise. * m4/gettext.m4: Likewise. * m4/gnulib-common.m4: Likewise. * m4/intdiv0.m4: Likewise. * m4/intlmacosx.m4: Likewise. * m4/largefile.m4: Likewise. * m4/ldexpl.m4: Likewise. * m4/link-follow.m4: Likewise. * m4/locale-ar.m4: Likewise. * m4/locale-fr.m4: Likewise. * m4/locale-ja.m4: Likewise. * m4/locale-tr.m4: Likewise. * m4/locale-zh.m4: Likewise. * m4/locale_h.m4: Likewise. * m4/lock.m4: Likewise. * m4/logl.m4: Likewise. * m4/mathfunc.m4: Likewise. * m4/minus-zero.m4: Likewise. * m4/mktime.m4: Likewise. * m4/mmap-anon.m4: Likewise. * m4/multiarch.m4: Likewise. * m4/nanosleep.m4: Likewise. * m4/nocrash.m4: Likewise. * m4/poll.m4: Likewise. * m4/printf-frexpl.m4: Likewise. * m4/printf.m4: Likewise. * m4/signbit.m4: Likewise. * m4/sinl.m4: Likewise. * m4/sqrtl.m4: Likewise. * m4/strerror_r.m4: Likewise. * m4/tanl.m4: Likewise. * m4/threadlib.m4: Likewise. * m4/ttyname_r.m4: Likewise. * m4/unlink.m4: Likewise. * m4/visibility.m4: Likewise. * m4/wcwidth.m4: Likewise. * tests/minus-zero.h: Likewise. * tests/test-alloca-opt.c: Likewise. * tests/test-copy-acl.sh: Likewise. * tests/test-copy-file.sh: Likewise. * tests/test-fdatasync.c: Likewise. * tests/test-file-has-acl.sh: Likewise. * tests/test-flock.c: Likewise. * tests/test-fsync.c: Likewise. * tests/test-localename.c: Likewise. * tests/test-malloca.c: Likewise. * tests/test-nonblocking-pipe.h: Likewise. * tests/test-nonblocking-socket.h: Likewise. * tests/test-openpty.c: Likewise. * tests/test-posix_openpt.c: Likewise. * tests/test-ptsname.c: Likewise. * tests/test-ptsname_r.c: Likewise. * tests/test-sameacls.c: Likewise. * tests/test-select.h: Likewise. * tests/test-set-mode-acl.sh: Likewise. * tests/test-snprintf-posix.h: Likewise. * tests/test-sprintf-posix.h: Likewise. * tests/test-strtod.c: Likewise. * tests/test-time.c: Likewise. * tests/test-vasnprintf-posix.c: Likewise. * tests/test-vasprintf-posix.c: Likewise. * doc/acl-resources.txt: Likewise. * doc/**/*.texi: Likewise. Reported by Max Horn <max@quendi.de>.
author Bruno Haible <bruno@clisp.org>
date Fri, 22 Jun 2012 13:26:07 +0200
parents cc05dad27529
children 16d02df1b46e
line wrap: on
line source

/* Internal implementation of access control lists.

   Copyright (C) 2002-2003, 2005-2012 Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

   Written by Paul Eggert, Andreas Grünbacher, and Bruno Haible.  */

#include "acl.h"

#include <stdbool.h>
#include <stdlib.h>

/* All systems define the ACL related API in <sys/acl.h>.  */
#if HAVE_SYS_ACL_H
# include <sys/acl.h>
#endif
#if defined HAVE_FACL && ! defined GETACLCNT && defined ACL_CNT
# define GETACLCNT ACL_CNT
#endif

/* On Linux, additional ACL related API is available in <acl/libacl.h>.  */
#ifdef HAVE_ACL_LIBACL_H
# include <acl/libacl.h>
#endif

/* On HP-UX >= 11.11, additional ACL API is available in <aclv.h>.  */
#if HAVE_ACLV_H
# include <sys/types.h>
# include <aclv.h>
/* HP-UX 11.11 lacks these declarations.  */
extern int acl (char *, int, int, struct acl *);
extern int aclsort (int, int, struct acl *);
#endif

#include "error.h"
#include "quote.h"

#include <errno.h>
#ifndef ENOSYS
# define ENOSYS (-1)
#endif
#ifndef ENOTSUP
# define ENOTSUP (-1)
#endif

#include <limits.h>
#ifndef MIN
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif

#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#endif

#ifndef HAVE_FCHMOD
# define HAVE_FCHMOD false
# define fchmod(fd, mode) (-1)
#endif

/* Recognize some common errors such as from an NFS mount that does
   not support ACLs, even when local drives do.  */
#if defined __APPLE__ && defined __MACH__ /* Mac OS X */
# define ACL_NOT_WELL_SUPPORTED(Err) \
     ((Err) == ENOTSUP || (Err) == ENOSYS || (Err) == EINVAL || (Err) == EBUSY || (Err) == ENOENT)
#elif defined EOPNOTSUPP /* Tru64 NFS */
# define ACL_NOT_WELL_SUPPORTED(Err) \
     ((Err) == ENOTSUP || (Err) == ENOSYS || (Err) == EINVAL || (Err) == EBUSY || (Err) == EOPNOTSUPP)
#else
# define ACL_NOT_WELL_SUPPORTED(Err) \
     ((Err) == ENOTSUP || (Err) == ENOSYS || (Err) == EINVAL || (Err) == EBUSY)
#endif

#if USE_ACL

# if HAVE_ACL_GET_FILE
/* POSIX 1003.1e (draft 17 -- abandoned) specific version.  */
/* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */

#  ifndef MIN_ACL_ENTRIES
#   define MIN_ACL_ENTRIES 4
#  endif

/* POSIX 1003.1e (draft 17) */
#  ifdef HAVE_ACL_GET_FD
/* Most platforms have a 1-argument acl_get_fd, only OSF/1 has a 2-argument
   macro(!).  */
#   if HAVE_ACL_FREE_TEXT /* OSF/1 */
static inline acl_t
rpl_acl_get_fd (int fd)
{
  return acl_get_fd (fd, ACL_TYPE_ACCESS);
}
#    undef acl_get_fd
#    define acl_get_fd rpl_acl_get_fd
#   endif
#  else
#   define HAVE_ACL_GET_FD false
#   undef acl_get_fd
#   define acl_get_fd(fd) (NULL)
#  endif

/* POSIX 1003.1e (draft 17) */
#  ifdef HAVE_ACL_SET_FD
/* Most platforms have a 2-argument acl_set_fd, only OSF/1 has a 3-argument
   macro(!).  */
#   if HAVE_ACL_FREE_TEXT /* OSF/1 */
static inline int
rpl_acl_set_fd (int fd, acl_t acl)
{
  return acl_set_fd (fd, ACL_TYPE_ACCESS, acl);
}
#    undef acl_set_fd
#    define acl_set_fd rpl_acl_set_fd
#   endif
#  else
#   define HAVE_ACL_SET_FD false
#   undef acl_set_fd
#   define acl_set_fd(fd, acl) (-1)
#  endif

/* POSIX 1003.1e (draft 13) */
#  if ! HAVE_ACL_FREE_TEXT
#   define acl_free_text(buf) acl_free (buf)
#  endif

/* Linux-specific */
#  ifndef HAVE_ACL_EXTENDED_FILE
#   define HAVE_ACL_EXTENDED_FILE false
#   define acl_extended_file(name) (-1)
#  endif

/* Linux-specific */
#  ifndef HAVE_ACL_FROM_MODE
#   define HAVE_ACL_FROM_MODE false
#   define acl_from_mode(mode) (NULL)
#  endif

/* Set to 1 if a file's mode is implicit by the ACL.
   Set to 0 if a file's mode is stored independently from the ACL.  */
#  if (HAVE_ACL_COPY_EXT_NATIVE && HAVE_ACL_CREATE_ENTRY_NP) || defined __sgi /* Mac OS X, IRIX */
#   define MODE_INSIDE_ACL 0
#  else
#   define MODE_INSIDE_ACL 1
#  endif

/* Return the number of entries in ACL.
   Return -1 and set errno upon failure to determine it.  */
/* Define a replacement for acl_entries if needed. (Only Linux has it.)  */
#  if !HAVE_ACL_ENTRIES
#   define acl_entries rpl_acl_entries
extern int acl_entries (acl_t);
#  endif

#  if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */
/* ACL is an ACL, from a file, stored as type ACL_TYPE_EXTENDED.
   Return 1 if the given ACL is non-trivial.
   Return 0 if it is trivial.  */
extern int acl_extended_nontrivial (acl_t);
#  else
/* ACL is an ACL, from a file, stored as type ACL_TYPE_ACCESS.
   Return 1 if the given ACL is non-trivial.
   Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.
   Return -1 and set errno upon failure to determine it.  */
extern int acl_access_nontrivial (acl_t);
#  endif

# elif HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */

/* Set to 1 if a file's mode is implicit by the ACL.
   Set to 0 if a file's mode is stored independently from the ACL.  */
#  if defined __CYGWIN__ /* Cygwin */
#   define MODE_INSIDE_ACL 0
#  else /* Solaris */
#   define MODE_INSIDE_ACL 1
#  endif

/* Return 1 if the given ACL is non-trivial.
   Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
extern int acl_nontrivial (int count, aclent_t *entries);

#  ifdef ACE_GETACL /* Solaris 10 */

/* Test an ACL retrieved with ACE_GETACL.
   Return 1 if the given ACL, consisting of COUNT entries, is non-trivial.
   Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
extern int acl_ace_nontrivial (int count, ace_t *entries);

/* Definitions for when the built executable is executed on Solaris 10
   (newer version) or Solaris 11.  */
/* For a_type.  */
#   define OLD_ALLOW 0
#   define OLD_DENY  1
#   define NEW_ACE_ACCESS_ALLOWED_ACE_TYPE 0 /* replaces ALLOW */
#   define NEW_ACE_ACCESS_DENIED_ACE_TYPE  1 /* replaces DENY */
/* For a_flags.  */
#   define OLD_ACE_OWNER            0x0100
#   define OLD_ACE_GROUP            0x0200
#   define OLD_ACE_OTHER            0x0400
#   define NEW_ACE_OWNER            0x1000
#   define NEW_ACE_GROUP            0x2000
#   define NEW_ACE_IDENTIFIER_GROUP 0x0040
#   define NEW_ACE_EVERYONE         0x4000
/* For a_access_mask.  */
#   define NEW_ACE_READ_DATA         0x001 /* corresponds to 'r' */
#   define NEW_ACE_WRITE_DATA        0x002 /* corresponds to 'w' */
#   define NEW_ACE_APPEND_DATA       0x004
#   define NEW_ACE_READ_NAMED_ATTRS  0x008
#   define NEW_ACE_WRITE_NAMED_ATTRS 0x010
#   define NEW_ACE_EXECUTE           0x020
#   define NEW_ACE_DELETE_CHILD      0x040
#   define NEW_ACE_READ_ATTRIBUTES   0x080
#   define NEW_ACE_WRITE_ATTRIBUTES  0x100
#   define NEW_ACE_DELETE          0x10000
#   define NEW_ACE_READ_ACL        0x20000
#   define NEW_ACE_WRITE_ACL       0x40000
#   define NEW_ACE_WRITE_OWNER     0x80000
#   define NEW_ACE_SYNCHRONIZE    0x100000

#  endif

# elif HAVE_GETACL /* HP-UX */

/* Return 1 if the given ACL is non-trivial.
   Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
extern int acl_nontrivial (int count, struct acl_entry *entries, struct stat *sb);

#  if HAVE_ACLV_H /* HP-UX >= 11.11 */

/* Return 1 if the given ACL is non-trivial.
   Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
extern int aclv_nontrivial (int count, struct acl *entries);

#  endif

# elif HAVE_ACLX_GET && 0 /* AIX */

/* TODO */

# elif HAVE_STATACL /* older AIX */

/* Return 1 if the given ACL is non-trivial.
   Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
extern int acl_nontrivial (struct acl *a);

# elif HAVE_ACLSORT /* NonStop Kernel */

/* Return 1 if the given ACL is non-trivial.
   Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
extern int acl_nontrivial (int count, struct acl *entries);

# endif

#endif