diff options
| author | Paul Eggert | 2013-05-07 14:34:03 -0700 |
|---|---|---|
| committer | Paul Eggert | 2013-05-07 14:34:03 -0700 |
| commit | ffdc270a762ee93261f133632a9f82ea6ace9424 (patch) | |
| tree | c1eacab0759fb3725a6fc99a089cc8f3f78644ac /lib/acl-internal.h | |
| parent | ad64371062c05222227d7d573075c81b1f046630 (diff) | |
| download | emacs-ffdc270a762ee93261f133632a9f82ea6ace9424.tar.gz emacs-ffdc270a762ee93261f133632a9f82ea6ace9424.zip | |
Use Gnulib ACL implementation, for benefit of Solaris etc.
* configure.ac: Remove -with-acl option, since Gnulib does that for
us now.
(LIBACL_LIBS): Remove; no longer needed.
* lib/Makefile.am (CLEANFILES, SUFFIXES): New (empty) macros,
for the benefit of the new ACL implementation.
* lib/makefile.w32-in (GNULIBOBJS): Add $(BLD)/acl-errno-valid.$(O).
($(BLD)/acl-errno-valid.$(O)): New rule.
* lib/acl-errno-valid.c, lib/acl-internal.h, lib/acl.h:
* lib/acl_entries.c, lib/errno.in.h, lib/file-has-acl.c:
* lib/qcopy-acl.c, lib/qset-acl.c, m4/acl.m4, m4/errno_h.m4:
New files, taken from gnulib.
* lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
* admin/merge-gnulib (GNULIB_MODULES): Add qacl.
(GNULIB_TOOL_FLAGS): Do not avoid errno.
* etc/NEWS: Emacs is no longer limited to POSIX ACLs. --disable-acl,
not --without-acl, since we're now using Gnulib's implementation.
* nt/config.nt (HAVE_ACL_SET_FILE): Rename from HAVE_POSIX_ACL.
* nt/inc/ms-w32.h (EOPNOTSUPP): New macro.
* src/Makefile.in (LIB_ACL): New macro.
(LIBACL_LIBS): Remove.
(LIBES): Use LIB_ACL, not LIBACL_LIBS.
* src/fileio.c: Include <acl.h>.
Use HAVE_ACL_SET_FILE rather than HAVE_POSIX_ACL.
(ACL_NOT_WELL_SUPPORTED): Remove. All uses replaced by
!acl_errno_valid.
(Fcopy_file) [!WINDOWSNT]: Use qcopy_acl instead of rolling
it ourselves.
Fixes: debbugs:14295
Diffstat (limited to 'lib/acl-internal.h')
| -rw-r--r-- | lib/acl-internal.h | 250 |
1 files changed, 250 insertions, 0 deletions
diff --git a/lib/acl-internal.h b/lib/acl-internal.h new file mode 100644 index 00000000000..7e6d77a5fd4 --- /dev/null +++ b/lib/acl-internal.h | |||
| @@ -0,0 +1,250 @@ | |||
| 1 | /* Internal implementation of access control lists. | ||
| 2 | |||
| 3 | Copyright (C) 2002-2003, 2005-2013 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | This program is free software: you can redistribute it and/or modify | ||
| 6 | it under the terms of the GNU General Public License as published by | ||
| 7 | the Free Software Foundation; either version 3 of the License, or | ||
| 8 | (at your option) any later version. | ||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, | ||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | GNU General Public License for more details. | ||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License | ||
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 17 | |||
| 18 | Written by Paul Eggert, Andreas Grünbacher, and Bruno Haible. */ | ||
| 19 | |||
| 20 | #include "acl.h" | ||
| 21 | |||
| 22 | #include <stdbool.h> | ||
| 23 | #include <stdlib.h> | ||
| 24 | |||
| 25 | /* All systems define the ACL related API in <sys/acl.h>. */ | ||
| 26 | #if HAVE_SYS_ACL_H | ||
| 27 | # include <sys/acl.h> | ||
| 28 | #endif | ||
| 29 | #if defined HAVE_FACL && ! defined GETACLCNT && defined ACL_CNT | ||
| 30 | # define GETACLCNT ACL_CNT | ||
| 31 | #endif | ||
| 32 | |||
| 33 | /* On Linux, additional ACL related API is available in <acl/libacl.h>. */ | ||
| 34 | #ifdef HAVE_ACL_LIBACL_H | ||
| 35 | # include <acl/libacl.h> | ||
| 36 | #endif | ||
| 37 | |||
| 38 | /* On HP-UX >= 11.11, additional ACL API is available in <aclv.h>. */ | ||
| 39 | #if HAVE_ACLV_H | ||
| 40 | # include <sys/types.h> | ||
| 41 | # include <aclv.h> | ||
| 42 | /* HP-UX 11.11 lacks these declarations. */ | ||
| 43 | extern int acl (char *, int, int, struct acl *); | ||
| 44 | extern int aclsort (int, int, struct acl *); | ||
| 45 | #endif | ||
| 46 | |||
| 47 | #include <errno.h> | ||
| 48 | |||
| 49 | #include <limits.h> | ||
| 50 | #ifndef MIN | ||
| 51 | # define MIN(a,b) ((a) < (b) ? (a) : (b)) | ||
| 52 | #endif | ||
| 53 | |||
| 54 | #ifndef SIZE_MAX | ||
| 55 | # define SIZE_MAX ((size_t) -1) | ||
| 56 | #endif | ||
| 57 | |||
| 58 | #ifndef HAVE_FCHMOD | ||
| 59 | # define HAVE_FCHMOD false | ||
| 60 | # define fchmod(fd, mode) (-1) | ||
| 61 | #endif | ||
| 62 | |||
| 63 | _GL_INLINE_HEADER_BEGIN | ||
| 64 | #ifndef ACL_INTERNAL_INLINE | ||
| 65 | # define ACL_INTERNAL_INLINE _GL_INLINE | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #if USE_ACL | ||
| 69 | |||
| 70 | # if HAVE_ACL_GET_FILE | ||
| 71 | /* POSIX 1003.1e (draft 17 -- abandoned) specific version. */ | ||
| 72 | /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */ | ||
| 73 | |||
| 74 | # ifndef MIN_ACL_ENTRIES | ||
| 75 | # define MIN_ACL_ENTRIES 4 | ||
| 76 | # endif | ||
| 77 | |||
| 78 | /* POSIX 1003.1e (draft 17) */ | ||
| 79 | # ifdef HAVE_ACL_GET_FD | ||
| 80 | /* Most platforms have a 1-argument acl_get_fd, only OSF/1 has a 2-argument | ||
| 81 | macro(!). */ | ||
| 82 | # if HAVE_ACL_FREE_TEXT /* OSF/1 */ | ||
| 83 | ACL_INTERNAL_INLINE acl_t | ||
| 84 | rpl_acl_get_fd (int fd) | ||
| 85 | { | ||
| 86 | return acl_get_fd (fd, ACL_TYPE_ACCESS); | ||
| 87 | } | ||
| 88 | # undef acl_get_fd | ||
| 89 | # define acl_get_fd rpl_acl_get_fd | ||
| 90 | # endif | ||
| 91 | # else | ||
| 92 | # define HAVE_ACL_GET_FD false | ||
| 93 | # undef acl_get_fd | ||
| 94 | # define acl_get_fd(fd) (NULL) | ||
| 95 | # endif | ||
| 96 | |||
| 97 | /* POSIX 1003.1e (draft 17) */ | ||
| 98 | # ifdef HAVE_ACL_SET_FD | ||
| 99 | /* Most platforms have a 2-argument acl_set_fd, only OSF/1 has a 3-argument | ||
| 100 | macro(!). */ | ||
| 101 | # if HAVE_ACL_FREE_TEXT /* OSF/1 */ | ||
| 102 | ACL_INTERNAL_INLINE int | ||
| 103 | rpl_acl_set_fd (int fd, acl_t acl) | ||
| 104 | { | ||
| 105 | return acl_set_fd (fd, ACL_TYPE_ACCESS, acl); | ||
| 106 | } | ||
| 107 | # undef acl_set_fd | ||
| 108 | # define acl_set_fd rpl_acl_set_fd | ||
| 109 | # endif | ||
| 110 | # else | ||
| 111 | # define HAVE_ACL_SET_FD false | ||
| 112 | # undef acl_set_fd | ||
| 113 | # define acl_set_fd(fd, acl) (-1) | ||
| 114 | # endif | ||
| 115 | |||
| 116 | /* POSIX 1003.1e (draft 13) */ | ||
| 117 | # if ! HAVE_ACL_FREE_TEXT | ||
| 118 | # define acl_free_text(buf) acl_free (buf) | ||
| 119 | # endif | ||
| 120 | |||
| 121 | /* Linux-specific */ | ||
| 122 | # ifndef HAVE_ACL_EXTENDED_FILE | ||
| 123 | # define HAVE_ACL_EXTENDED_FILE false | ||
| 124 | # define acl_extended_file(name) (-1) | ||
| 125 | # endif | ||
| 126 | |||
| 127 | /* Linux-specific */ | ||
| 128 | # ifndef HAVE_ACL_FROM_MODE | ||
| 129 | # define HAVE_ACL_FROM_MODE false | ||
| 130 | # define acl_from_mode(mode) (NULL) | ||
| 131 | # endif | ||
| 132 | |||
| 133 | /* Set to 1 if a file's mode is implicit by the ACL. | ||
| 134 | Set to 0 if a file's mode is stored independently from the ACL. */ | ||
| 135 | # if (HAVE_ACL_COPY_EXT_NATIVE && HAVE_ACL_CREATE_ENTRY_NP) || defined __sgi /* Mac OS X, IRIX */ | ||
| 136 | # define MODE_INSIDE_ACL 0 | ||
| 137 | # else | ||
| 138 | # define MODE_INSIDE_ACL 1 | ||
| 139 | # endif | ||
| 140 | |||
| 141 | /* Return the number of entries in ACL. | ||
| 142 | Return -1 and set errno upon failure to determine it. */ | ||
| 143 | /* Define a replacement for acl_entries if needed. (Only Linux has it.) */ | ||
| 144 | # if !HAVE_ACL_ENTRIES | ||
| 145 | # define acl_entries rpl_acl_entries | ||
| 146 | extern int acl_entries (acl_t); | ||
| 147 | # endif | ||
| 148 | |||
| 149 | # if HAVE_ACL_TYPE_EXTENDED /* Mac OS X */ | ||
| 150 | /* ACL is an ACL, from a file, stored as type ACL_TYPE_EXTENDED. | ||
| 151 | Return 1 if the given ACL is non-trivial. | ||
| 152 | Return 0 if it is trivial. */ | ||
| 153 | extern int acl_extended_nontrivial (acl_t); | ||
| 154 | # else | ||
| 155 | /* ACL is an ACL, from a file, stored as type ACL_TYPE_ACCESS. | ||
| 156 | Return 1 if the given ACL is non-trivial. | ||
| 157 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. | ||
| 158 | Return -1 and set errno upon failure to determine it. */ | ||
| 159 | extern int acl_access_nontrivial (acl_t); | ||
| 160 | # endif | ||
| 161 | |||
| 162 | # elif HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */ | ||
| 163 | |||
| 164 | /* Set to 1 if a file's mode is implicit by the ACL. | ||
| 165 | Set to 0 if a file's mode is stored independently from the ACL. */ | ||
| 166 | # if defined __CYGWIN__ /* Cygwin */ | ||
| 167 | # define MODE_INSIDE_ACL 0 | ||
| 168 | # else /* Solaris */ | ||
| 169 | # define MODE_INSIDE_ACL 1 | ||
| 170 | # endif | ||
| 171 | |||
| 172 | /* Return 1 if the given ACL is non-trivial. | ||
| 173 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 174 | extern int acl_nontrivial (int count, aclent_t *entries); | ||
| 175 | |||
| 176 | # ifdef ACE_GETACL /* Solaris 10 */ | ||
| 177 | |||
| 178 | /* Test an ACL retrieved with ACE_GETACL. | ||
| 179 | Return 1 if the given ACL, consisting of COUNT entries, is non-trivial. | ||
| 180 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 181 | extern int acl_ace_nontrivial (int count, ace_t *entries); | ||
| 182 | |||
| 183 | /* Definitions for when the built executable is executed on Solaris 10 | ||
| 184 | (newer version) or Solaris 11. */ | ||
| 185 | /* For a_type. */ | ||
| 186 | # define OLD_ALLOW 0 | ||
| 187 | # define OLD_DENY 1 | ||
| 188 | # define NEW_ACE_ACCESS_ALLOWED_ACE_TYPE 0 /* replaces ALLOW */ | ||
| 189 | # define NEW_ACE_ACCESS_DENIED_ACE_TYPE 1 /* replaces DENY */ | ||
| 190 | /* For a_flags. */ | ||
| 191 | # define OLD_ACE_OWNER 0x0100 | ||
| 192 | # define OLD_ACE_GROUP 0x0200 | ||
| 193 | # define OLD_ACE_OTHER 0x0400 | ||
| 194 | # define NEW_ACE_OWNER 0x1000 | ||
| 195 | # define NEW_ACE_GROUP 0x2000 | ||
| 196 | # define NEW_ACE_IDENTIFIER_GROUP 0x0040 | ||
| 197 | # define NEW_ACE_EVERYONE 0x4000 | ||
| 198 | /* For a_access_mask. */ | ||
| 199 | # define NEW_ACE_READ_DATA 0x001 /* corresponds to 'r' */ | ||
| 200 | # define NEW_ACE_WRITE_DATA 0x002 /* corresponds to 'w' */ | ||
| 201 | # define NEW_ACE_APPEND_DATA 0x004 | ||
| 202 | # define NEW_ACE_READ_NAMED_ATTRS 0x008 | ||
| 203 | # define NEW_ACE_WRITE_NAMED_ATTRS 0x010 | ||
| 204 | # define NEW_ACE_EXECUTE 0x020 | ||
| 205 | # define NEW_ACE_DELETE_CHILD 0x040 | ||
| 206 | # define NEW_ACE_READ_ATTRIBUTES 0x080 | ||
| 207 | # define NEW_ACE_WRITE_ATTRIBUTES 0x100 | ||
| 208 | # define NEW_ACE_DELETE 0x10000 | ||
| 209 | # define NEW_ACE_READ_ACL 0x20000 | ||
| 210 | # define NEW_ACE_WRITE_ACL 0x40000 | ||
| 211 | # define NEW_ACE_WRITE_OWNER 0x80000 | ||
| 212 | # define NEW_ACE_SYNCHRONIZE 0x100000 | ||
| 213 | |||
| 214 | # endif | ||
| 215 | |||
| 216 | # elif HAVE_GETACL /* HP-UX */ | ||
| 217 | |||
| 218 | /* Return 1 if the given ACL is non-trivial. | ||
| 219 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 220 | extern int acl_nontrivial (int count, struct acl_entry *entries, struct stat *sb); | ||
| 221 | |||
| 222 | # if HAVE_ACLV_H /* HP-UX >= 11.11 */ | ||
| 223 | |||
| 224 | /* Return 1 if the given ACL is non-trivial. | ||
| 225 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 226 | extern int aclv_nontrivial (int count, struct acl *entries); | ||
| 227 | |||
| 228 | # endif | ||
| 229 | |||
| 230 | # elif HAVE_ACLX_GET && 0 /* AIX */ | ||
| 231 | |||
| 232 | /* TODO */ | ||
| 233 | |||
| 234 | # elif HAVE_STATACL /* older AIX */ | ||
| 235 | |||
| 236 | /* Return 1 if the given ACL is non-trivial. | ||
| 237 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 238 | extern int acl_nontrivial (struct acl *a); | ||
| 239 | |||
| 240 | # elif HAVE_ACLSORT /* NonStop Kernel */ | ||
| 241 | |||
| 242 | /* Return 1 if the given ACL is non-trivial. | ||
| 243 | Return 0 if it is trivial, i.e. equivalent to a simple stat() mode. */ | ||
| 244 | extern int acl_nontrivial (int count, struct acl *entries); | ||
| 245 | |||
| 246 | # endif | ||
| 247 | |||
| 248 | #endif | ||
| 249 | |||
| 250 | _GL_INLINE_HEADER_END | ||