Mercurial > hg > octave-kai > gnulib-hg
annotate lib/copy-acl.c @ 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 | 531aa00a1e80 |
children | e542fd46ad6f |
rev | line source |
---|---|
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* copy-acl.c - copy access control list from one file to another file |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
2 |
16201
8250f2777afc
maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents:
15575
diff
changeset
|
3 Copyright (C) 2002-2003, 2005-2012 Free Software Foundation, Inc. |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 it under the terms of the GNU General Public License as published by |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 (at your option) any later version. |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 This program is distributed in the hope that it will be useful, |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 GNU General Public License for more details. |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU General Public License |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>. |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 |
10184 | 18 Written by Paul Eggert, Andreas Grünbacher, and Bruno Haible. */ |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 #include <config.h> |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 #include "acl.h" |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 #include "acl-internal.h" |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 |
10198
5056e8a13405
Include gettext.h only in those files that need it.
Bruno Haible <bruno@clisp.org>
parents:
10184
diff
changeset
|
26 #include "gettext.h" |
5056e8a13405
Include gettext.h only in those files that need it.
Bruno Haible <bruno@clisp.org>
parents:
10184
diff
changeset
|
27 #define _(msgid) gettext (msgid) |
5056e8a13405
Include gettext.h only in those files that need it.
Bruno Haible <bruno@clisp.org>
parents:
10184
diff
changeset
|
28 |
10147
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
29 |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 /* Copy access control lists from one file to another. If SOURCE_DESC is |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
31 a valid file descriptor, use file descriptor operations, else use |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
32 filename based operations on SRC_NAME. Likewise for DEST_DESC and |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 DST_NAME. |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 If access control lists are not available, fchmod the target file to |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 MODE. Also sets the non-permission bits of the destination file |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 (S_ISUID, S_ISGID, S_ISVTX) to those from MODE if any are set. |
10147
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
37 Return 0 if successful. |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
38 Return -2 and set errno for an error relating to the source file. |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
39 Return -1 and set errno for an error relating to the destination file. */ |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 |
16270 | 41 int |
10147
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
42 qcopy_acl (const char *src_name, int source_desc, const char *dst_name, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
43 int dest_desc, mode_t mode) |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 { |
10155
3df501903792
Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents:
10152
diff
changeset
|
45 #if USE_ACL && HAVE_ACL_GET_FILE |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 /* POSIX 1003.1e (draft 17 -- abandoned) specific version. */ |
16935
498a2211d839
Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents:
16383
diff
changeset
|
47 /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */ |
15575
3e19c8849877
acl: Fix a test failure on IRIX 6.5 with NFS.
Bruno Haible <bruno@clisp.org>
parents:
15572
diff
changeset
|
48 # if !HAVE_ACL_TYPE_EXTENDED |
10172
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
49 /* Linux, FreeBSD, IRIX, Tru64 */ |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 acl_t acl; |
10168
d688b8e59f31
Trivial stylistic improvements.
Bruno Haible <bruno@clisp.org>
parents:
10163
diff
changeset
|
52 int ret; |
d688b8e59f31
Trivial stylistic improvements.
Bruno Haible <bruno@clisp.org>
parents:
10163
diff
changeset
|
53 |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 if (HAVE_ACL_GET_FD && source_desc != -1) |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 acl = acl_get_fd (source_desc); |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 else |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 acl = acl_get_file (src_name, ACL_TYPE_ACCESS); |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 if (acl == NULL) |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 { |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 if (ACL_NOT_WELL_SUPPORTED (errno)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
61 return qset_acl (dst_name, dest_desc, mode); |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
62 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
63 return -2; |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 } |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 if (HAVE_ACL_SET_FD && dest_desc != -1) |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 ret = acl_set_fd (dest_desc, acl); |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 else |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 ret = acl_set_file (dst_name, ACL_TYPE_ACCESS, acl); |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 if (ret != 0) |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 { |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
72 int saved_errno = errno; |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
73 |
10169
7215efd0ff4f
Trivial code simplifications.
Bruno Haible <bruno@clisp.org>
parents:
10168
diff
changeset
|
74 if (ACL_NOT_WELL_SUPPORTED (errno) && !acl_access_nontrivial (acl)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
75 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
76 acl_free (acl); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
77 return chmod_or_fchmod (dst_name, dest_desc, mode); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
78 } |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
79 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
80 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
81 acl_free (acl); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
82 chmod_or_fchmod (dst_name, dest_desc, mode); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
83 errno = saved_errno; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
84 return -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
85 } |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
86 } |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
87 else |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
88 acl_free (acl); |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
89 |
15575
3e19c8849877
acl: Fix a test failure on IRIX 6.5 with NFS.
Bruno Haible <bruno@clisp.org>
parents:
15572
diff
changeset
|
90 if (!MODE_INSIDE_ACL || (mode & (S_ISUID | S_ISGID | S_ISVTX))) |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
91 { |
10114
51164d97e89b
Make copy_acl work on MacOS X 10.5.
Bruno Haible <bruno@clisp.org>
parents:
10108
diff
changeset
|
92 /* We did not call chmod so far, and either the mode and the ACL are |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
93 separate or special bits are to be set which don't fit into ACLs. */ |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
94 |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
95 if (chmod_or_fchmod (dst_name, dest_desc, mode) != 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
96 return -1; |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
97 } |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
98 |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
99 if (S_ISDIR (mode)) |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
100 { |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
101 acl = acl_get_file (src_name, ACL_TYPE_DEFAULT); |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
102 if (acl == NULL) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
103 return -2; |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
104 |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
105 if (acl_set_file (dst_name, ACL_TYPE_DEFAULT, acl)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
106 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
107 int saved_errno = errno; |
10147
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
108 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
109 acl_free (acl); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
110 errno = saved_errno; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
111 return -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
112 } |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
113 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
114 acl_free (acl); |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
115 } |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
116 return 0; |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
117 |
15575
3e19c8849877
acl: Fix a test failure on IRIX 6.5 with NFS.
Bruno Haible <bruno@clisp.org>
parents:
15572
diff
changeset
|
118 # else /* HAVE_ACL_TYPE_EXTENDED */ |
16935
498a2211d839
Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents:
16383
diff
changeset
|
119 /* Mac OS X */ |
10172
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
120 |
16935
498a2211d839
Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents:
16383
diff
changeset
|
121 /* On Mac OS X, acl_get_file (name, ACL_TYPE_ACCESS) |
498a2211d839
Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents:
16383
diff
changeset
|
122 and acl_get_file (name, ACL_TYPE_DEFAULT) |
10172
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
123 always return NULL / EINVAL. You have to use |
16935
498a2211d839
Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents:
16383
diff
changeset
|
124 acl_get_file (name, ACL_TYPE_EXTENDED) |
498a2211d839
Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents:
16383
diff
changeset
|
125 or acl_get_fd (open (name, ...)) |
10172
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
126 to retrieve an ACL. |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
127 On the other hand, |
16935
498a2211d839
Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents:
16383
diff
changeset
|
128 acl_set_file (name, ACL_TYPE_ACCESS, acl) |
498a2211d839
Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents:
16383
diff
changeset
|
129 and acl_set_file (name, ACL_TYPE_DEFAULT, acl) |
10172
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
130 have the same effect as |
16935
498a2211d839
Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents:
16383
diff
changeset
|
131 acl_set_file (name, ACL_TYPE_EXTENDED, acl): |
10172
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
132 Each of these calls sets the file's ACL. */ |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
133 |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
134 acl_t acl; |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
135 int ret; |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
136 |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
137 if (HAVE_ACL_GET_FD && source_desc != -1) |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
138 acl = acl_get_fd (source_desc); |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
139 else |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
140 acl = acl_get_file (src_name, ACL_TYPE_EXTENDED); |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
141 if (acl == NULL) |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
142 { |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
143 if (ACL_NOT_WELL_SUPPORTED (errno)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
144 return qset_acl (dst_name, dest_desc, mode); |
10172
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
145 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
146 return -2; |
10172
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
147 } |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
148 |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
149 if (HAVE_ACL_SET_FD && dest_desc != -1) |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
150 ret = acl_set_fd (dest_desc, acl); |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
151 else |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
152 ret = acl_set_file (dst_name, ACL_TYPE_EXTENDED, acl); |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
153 if (ret != 0) |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
154 { |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
155 int saved_errno = errno; |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
156 |
10177
caed32fb1892
New function acl_extended_nontrivial (MacOS X only).
Bruno Haible <bruno@clisp.org>
parents:
10172
diff
changeset
|
157 if (ACL_NOT_WELL_SUPPORTED (errno) && !acl_extended_nontrivial (acl)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
158 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
159 acl_free (acl); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
160 return chmod_or_fchmod (dst_name, dest_desc, mode); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
161 } |
10172
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
162 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
163 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
164 acl_free (acl); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
165 chmod_or_fchmod (dst_name, dest_desc, mode); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
166 errno = saved_errno; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
167 return -1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
168 } |
10172
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
169 } |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
170 else |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
171 acl_free (acl); |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
172 |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
173 /* Since !MODE_INSIDE_ACL, we have to call chmod explicitly. */ |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
174 return chmod_or_fchmod (dst_name, dest_desc, mode); |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
175 |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
176 # endif |
50e666f281ef
Add support for MacOS X ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10169
diff
changeset
|
177 |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
178 #elif USE_ACL && defined GETACL /* Solaris, Cygwin, not HP-UX */ |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
179 |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
180 /* Solaris 2.5 through Solaris 10, Cygwin, and contemporaneous versions |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
181 of Unixware. The acl() call returns the access and default ACL both |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
182 at once. */ |
15572
dd7c06a51643
acl: Clean up Solaris code.
Bruno Haible <bruno@clisp.org>
parents:
15570
diff
changeset
|
183 # ifdef ACE_GETACL |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
184 int ace_count; |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
185 ace_t *ace_entries; |
15572
dd7c06a51643
acl: Clean up Solaris code.
Bruno Haible <bruno@clisp.org>
parents:
15570
diff
changeset
|
186 # endif |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
187 int count; |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
188 aclent_t *entries; |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
189 int did_chmod; |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
190 int saved_errno; |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
191 int ret; |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
192 |
15572
dd7c06a51643
acl: Clean up Solaris code.
Bruno Haible <bruno@clisp.org>
parents:
15570
diff
changeset
|
193 # ifdef ACE_GETACL |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
194 /* Solaris also has a different variant of ACLs, used in ZFS and NFSv4 |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
195 file systems (whereas the other ones are used in UFS file systems). |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
196 There is an API |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
197 pathconf (name, _PC_ACL_ENABLED) |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
198 fpathconf (desc, _PC_ACL_ENABLED) |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
199 that allows to determine which of the two kinds of ACLs is supported |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
200 for the given file. But some file systems may implement this call |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
201 incorrectly, so better not use it. |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
202 When fetching the source ACL, we simply fetch both ACL types. |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
203 When setting the destination ACL, we try either ACL types, assuming |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
204 that the kernel will translate the ACL from one form to the other. |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
205 (See in <http://docs.sun.com/app/docs/doc/819-2241/6n4huc7ia?l=en&a=view> |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
206 the description of ENOTSUP.) */ |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
207 for (;;) |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
208 { |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
209 ace_count = (source_desc != -1 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
210 ? facl (source_desc, ACE_GETACLCNT, 0, NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
211 : acl (src_name, ACE_GETACLCNT, 0, NULL)); |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
212 |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
213 if (ace_count < 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
214 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
215 if (errno == ENOSYS || errno == EINVAL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
216 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
217 ace_count = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
218 ace_entries = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
219 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
220 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
221 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
222 return -2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
223 } |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
224 |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
225 if (ace_count == 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
226 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
227 ace_entries = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
228 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
229 } |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
230 |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
231 ace_entries = (ace_t *) malloc (ace_count * sizeof (ace_t)); |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
232 if (ace_entries == NULL) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
233 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
234 errno = ENOMEM; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
235 return -2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
236 } |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
237 |
16381
fc5c37ccbece
acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents:
16270
diff
changeset
|
238 ret = (source_desc != -1 |
fc5c37ccbece
acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents:
16270
diff
changeset
|
239 ? facl (source_desc, ACE_GETACL, ace_count, ace_entries) |
fc5c37ccbece
acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents:
16270
diff
changeset
|
240 : acl (src_name, ACE_GETACL, ace_count, ace_entries)); |
fc5c37ccbece
acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents:
16270
diff
changeset
|
241 if (ret < 0) |
fc5c37ccbece
acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents:
16270
diff
changeset
|
242 { |
fc5c37ccbece
acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents:
16270
diff
changeset
|
243 free (ace_entries); |
fc5c37ccbece
acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents:
16270
diff
changeset
|
244 if (errno == ENOSYS || errno == EINVAL) |
fc5c37ccbece
acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents:
16270
diff
changeset
|
245 { |
fc5c37ccbece
acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents:
16270
diff
changeset
|
246 ace_count = 0; |
fc5c37ccbece
acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents:
16270
diff
changeset
|
247 ace_entries = NULL; |
fc5c37ccbece
acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents:
16270
diff
changeset
|
248 break; |
fc5c37ccbece
acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents:
16270
diff
changeset
|
249 } |
fc5c37ccbece
acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents:
16270
diff
changeset
|
250 else |
fc5c37ccbece
acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents:
16270
diff
changeset
|
251 return -2; |
fc5c37ccbece
acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents:
16270
diff
changeset
|
252 } |
fc5c37ccbece
acl: Fix endless loop on Solaris with vxfs.
Bruno Haible <bruno@clisp.org>
parents:
16270
diff
changeset
|
253 if (ret == ace_count) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
254 break; |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
255 /* Huh? The number of ACL entries changed since the last call. |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
256 Repeat. */ |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
257 } |
15572
dd7c06a51643
acl: Clean up Solaris code.
Bruno Haible <bruno@clisp.org>
parents:
15570
diff
changeset
|
258 # endif |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
259 |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
260 for (;;) |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
261 { |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
262 count = (source_desc != -1 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
263 ? facl (source_desc, GETACLCNT, 0, NULL) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
264 : acl (src_name, GETACLCNT, 0, NULL)); |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
265 |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
266 if (count < 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
267 { |
12906
05cf771f8b65
copy-acl: enhance Solaris ACL error handling
Ben Walton <bwalton@artsci.utoronto.ca>
parents:
12559
diff
changeset
|
268 if (errno == ENOSYS || errno == ENOTSUP || errno == EOPNOTSUPP) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
269 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
270 count = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
271 entries = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
272 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
273 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
274 else |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
275 return -2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
276 } |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
277 |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
278 if (count == 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
279 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
280 entries = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
281 break; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
282 } |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
283 |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
284 entries = (aclent_t *) malloc (count * sizeof (aclent_t)); |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
285 if (entries == NULL) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
286 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
287 errno = ENOMEM; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
288 return -2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
289 } |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
290 |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
291 if ((source_desc != -1 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
292 ? facl (source_desc, GETACL, count, entries) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
293 : acl (src_name, GETACL, count, entries)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
294 == count) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
295 break; |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
296 /* Huh? The number of ACL entries changed since the last call. |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
297 Repeat. */ |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
298 } |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
299 |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
300 /* Is there an ACL of either kind? */ |
15572
dd7c06a51643
acl: Clean up Solaris code.
Bruno Haible <bruno@clisp.org>
parents:
15570
diff
changeset
|
301 # ifdef ACE_GETACL |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
302 if (ace_count == 0) |
15572
dd7c06a51643
acl: Clean up Solaris code.
Bruno Haible <bruno@clisp.org>
parents:
15570
diff
changeset
|
303 # endif |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
304 if (count == 0) |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
305 return qset_acl (dst_name, dest_desc, mode); |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
306 |
10181
5282ccc922b9
Add support for Cygwin ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10179
diff
changeset
|
307 did_chmod = 0; /* set to 1 once the mode bits in 0777 have been set */ |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
308 saved_errno = 0; /* the first non-ignorable error code */ |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
309 |
10620
43de0aaeccb6
Fix test failure on Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10198
diff
changeset
|
310 if (!MODE_INSIDE_ACL) |
43de0aaeccb6
Fix test failure on Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10198
diff
changeset
|
311 { |
43de0aaeccb6
Fix test failure on Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10198
diff
changeset
|
312 /* On Cygwin, it is necessary to call chmod before acl, because |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
313 chmod can change the contents of the ACL (in ways that don't |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
314 change the allowed accesses, but still visible). */ |
10620
43de0aaeccb6
Fix test failure on Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10198
diff
changeset
|
315 if (chmod_or_fchmod (dst_name, dest_desc, mode) != 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
316 saved_errno = errno; |
10620
43de0aaeccb6
Fix test failure on Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10198
diff
changeset
|
317 did_chmod = 1; |
43de0aaeccb6
Fix test failure on Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10198
diff
changeset
|
318 } |
43de0aaeccb6
Fix test failure on Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10198
diff
changeset
|
319 |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
320 /* If both ace_entries and entries are available, try SETACL before |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
321 ACE_SETACL, because SETACL cannot fail with ENOTSUP whereas ACE_SETACL |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
322 can. */ |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
323 |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
324 if (count > 0) |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
325 { |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
326 ret = (dest_desc != -1 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
327 ? facl (dest_desc, SETACL, count, entries) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
328 : acl (dst_name, SETACL, count, entries)); |
10620
43de0aaeccb6
Fix test failure on Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10198
diff
changeset
|
329 if (ret < 0 && saved_errno == 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
330 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
331 saved_errno = errno; |
13937
e7b74d54a791
acl: port to Solaris 8 when copying from tmpfs to ufs
Paul Eggert <eggert@cs.ucla.edu>
parents:
13757
diff
changeset
|
332 if ((errno == ENOSYS || errno == EOPNOTSUPP || errno == EINVAL) |
12906
05cf771f8b65
copy-acl: enhance Solaris ACL error handling
Ben Walton <bwalton@artsci.utoronto.ca>
parents:
12559
diff
changeset
|
333 && !acl_nontrivial (count, entries)) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
334 saved_errno = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
335 } |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
336 else |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
337 did_chmod = 1; |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
338 } |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
339 free (entries); |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
340 |
15572
dd7c06a51643
acl: Clean up Solaris code.
Bruno Haible <bruno@clisp.org>
parents:
15570
diff
changeset
|
341 # ifdef ACE_GETACL |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
342 if (ace_count > 0) |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
343 { |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
344 ret = (dest_desc != -1 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
345 ? facl (dest_desc, ACE_SETACL, ace_count, ace_entries) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
346 : acl (dst_name, ACE_SETACL, ace_count, ace_entries)); |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
347 if (ret < 0 && saved_errno == 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
348 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
349 saved_errno = errno; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
350 if ((errno == ENOSYS || errno == EINVAL || errno == ENOTSUP) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
351 && !acl_ace_nontrivial (ace_count, ace_entries)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
352 saved_errno = 0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
353 } |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
354 } |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
355 free (ace_entries); |
15572
dd7c06a51643
acl: Clean up Solaris code.
Bruno Haible <bruno@clisp.org>
parents:
15570
diff
changeset
|
356 # endif |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
357 |
10620
43de0aaeccb6
Fix test failure on Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10198
diff
changeset
|
358 if (MODE_INSIDE_ACL |
43de0aaeccb6
Fix test failure on Cygwin.
Bruno Haible <bruno@clisp.org>
parents:
10198
diff
changeset
|
359 && did_chmod <= ((mode & (S_ISUID | S_ISGID | S_ISVTX)) ? 1 : 0)) |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
360 { |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
361 /* We did not call chmod so far, and either the mode and the ACL are |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
362 separate or special bits are to be set which don't fit into ACLs. */ |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
363 |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
364 if (chmod_or_fchmod (dst_name, dest_desc, mode) != 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
365 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
366 if (saved_errno == 0) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
367 saved_errno = errno; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
368 } |
10179
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
369 } |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
370 |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
371 if (saved_errno) |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
372 { |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
373 errno = saved_errno; |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
374 return -1; |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
375 } |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
376 return 0; |
90f51b86b088
Add support for Solaris 7..10 ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10177
diff
changeset
|
377 |
10182
4a177f4b083f
Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10181
diff
changeset
|
378 #elif USE_ACL && HAVE_GETACL /* HP-UX */ |
4a177f4b083f
Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10181
diff
changeset
|
379 |
16383
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
380 struct acl_entry entries[NACLENTRIES]; |
10182
4a177f4b083f
Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10181
diff
changeset
|
381 int count; |
14905
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
382 # if HAVE_ACLV_H |
16383
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
383 struct acl aclv_entries[NACLVENTRIES]; |
14905
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
384 int aclv_count; |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
385 # endif |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
386 int did_chmod; |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
387 int saved_errno; |
10182
4a177f4b083f
Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10181
diff
changeset
|
388 int ret; |
4a177f4b083f
Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10181
diff
changeset
|
389 |
16383
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
390 count = (source_desc != -1 |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
391 ? fgetacl (source_desc, NACLENTRIES, entries) |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
392 : getacl (src_name, NACLENTRIES, entries)); |
10182
4a177f4b083f
Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10181
diff
changeset
|
393 |
16383
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
394 if (count < 0) |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
395 { |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
396 if (errno == ENOSYS || errno == EOPNOTSUPP || errno == ENOTSUP) |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
397 count = 0; |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
398 else |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
399 return -2; |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
400 } |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
401 else if (count > 0) |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
402 { |
10182
4a177f4b083f
Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10181
diff
changeset
|
403 if (count > NACLENTRIES) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
404 /* If NACLENTRIES cannot be trusted, use dynamic memory allocation. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
405 abort (); |
10182
4a177f4b083f
Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10181
diff
changeset
|
406 } |
4a177f4b083f
Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10181
diff
changeset
|
407 |
14905
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
408 # if HAVE_ACLV_H |
16383
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
409 aclv_count = acl ((char *) src_name, ACL_GET, NACLVENTRIES, aclv_entries); |
10182
4a177f4b083f
Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10181
diff
changeset
|
410 |
16383
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
411 if (aclv_count < 0) |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
412 { |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
413 if (errno == ENOSYS || errno == EOPNOTSUPP || errno == EINVAL) |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
414 count = 0; |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
415 else |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
416 return -2; |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
417 } |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
418 else if (aclv_count > 0) |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
419 { |
14905
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
420 if (aclv_count > NACLVENTRIES) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
421 /* If NACLVENTRIES cannot be trusted, use dynamic memory allocation. */ |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
422 abort (); |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
423 } |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
424 # endif |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
425 |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
426 if (count == 0) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
427 # if HAVE_ACLV_H |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
428 if (aclv_count == 0) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
429 # endif |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
430 return qset_acl (dst_name, dest_desc, mode); |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
431 |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
432 did_chmod = 0; /* set to 1 once the mode bits in 0777 have been set */ |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
433 saved_errno = 0; /* the first non-ignorable error code */ |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
434 |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
435 if (count > 0) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
436 { |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
437 ret = (dest_desc != -1 |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
438 ? fsetacl (dest_desc, count, entries) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
439 : setacl (dst_name, count, entries)); |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
440 if (ret < 0 && saved_errno == 0) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
441 { |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
442 saved_errno = errno; |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
443 if (errno == ENOSYS || errno == EOPNOTSUPP || errno == ENOTSUP) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
444 { |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
445 struct stat source_statbuf; |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
446 |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
447 if ((source_desc != -1 |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
448 ? fstat (source_desc, &source_statbuf) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
449 : stat (src_name, &source_statbuf)) == 0) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
450 { |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
451 if (!acl_nontrivial (count, entries, &source_statbuf)) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
452 saved_errno = 0; |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
453 } |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
454 else |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
455 saved_errno = errno; |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
456 } |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
457 } |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
458 else |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
459 did_chmod = 1; |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
460 } |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
461 |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
462 # if HAVE_ACLV_H |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
463 if (aclv_count > 0) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
464 { |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
465 ret = acl ((char *) dst_name, ACL_SET, aclv_count, aclv_entries); |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
466 if (ret < 0 && saved_errno == 0) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
467 { |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
468 saved_errno = errno; |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
469 if (errno == ENOSYS || errno == EOPNOTSUPP || errno == EINVAL) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
470 { |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
471 if (!aclv_nontrivial (aclv_count, aclv_entries)) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
472 saved_errno = 0; |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
473 } |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
474 } |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
475 else |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
476 did_chmod = 1; |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
477 } |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
478 # endif |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
479 |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
480 if (did_chmod <= ((mode & (S_ISUID | S_ISGID | S_ISVTX)) ? 1 : 0)) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
481 { |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
482 /* We did not call chmod so far, and special bits are to be set which |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
483 don't fit into ACLs. */ |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
484 |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
485 if (chmod_or_fchmod (dst_name, dest_desc, mode) != 0) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
486 { |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
487 if (saved_errno == 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
488 saved_errno = errno; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
489 } |
14905
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
490 } |
10182
4a177f4b083f
Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10181
diff
changeset
|
491 |
14905
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
492 if (saved_errno) |
a9b67d6b93df
acl: Add support for HP-UX >= 11.11 JFS ACLs.
Bruno Haible <bruno@clisp.org>
parents:
14904
diff
changeset
|
493 { |
10182
4a177f4b083f
Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10181
diff
changeset
|
494 errno = saved_errno; |
4a177f4b083f
Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10181
diff
changeset
|
495 return -1; |
4a177f4b083f
Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10181
diff
changeset
|
496 } |
4a177f4b083f
Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10181
diff
changeset
|
497 return 0; |
4a177f4b083f
Add support for HP-UX ACLs.
Bruno Haible <bruno@clisp.org>
parents:
10181
diff
changeset
|
498 |
10183 | 499 #elif USE_ACL && HAVE_ACLX_GET && 0 /* AIX */ |
500 | |
501 /* TODO */ | |
502 | |
503 #elif USE_ACL && HAVE_STATACL /* older AIX */ | |
504 | |
505 union { struct acl a; char room[4096]; } u; | |
506 int ret; | |
507 | |
508 if ((source_desc != -1 | |
509 ? fstatacl (source_desc, STX_NORMAL, &u.a, sizeof (u)) | |
510 : statacl (src_name, STX_NORMAL, &u.a, sizeof (u))) | |
511 < 0) | |
512 return -2; | |
513 | |
514 ret = (dest_desc != -1 | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
515 ? fchacl (dest_desc, &u.a, u.a.acl_len) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
516 : chacl (dst_name, &u.a, u.a.acl_len)); |
10183 | 517 if (ret < 0) |
518 { | |
519 int saved_errno = errno; | |
520 | |
521 chmod_or_fchmod (dst_name, dest_desc, mode); | |
522 errno = saved_errno; | |
523 return -1; | |
524 } | |
525 | |
526 /* No need to call chmod_or_fchmod at this point, since the mode bits | |
527 S_ISUID, S_ISGID, S_ISVTX are also stored in the ACL. */ | |
528 | |
529 return 0; | |
530 | |
13757
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
531 #elif USE_ACL && HAVE_ACLSORT /* NonStop Kernel */ |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
532 |
16383
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
533 struct acl entries[NACLENTRIES]; |
13757
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
534 int count; |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
535 int ret; |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
536 |
16383
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
537 count = acl ((char *) src_name, ACL_GET, NACLENTRIES, entries); |
13757
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
538 |
16383
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
539 if (count < 0) |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
540 { |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
541 if (0) |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
542 count = 0; |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
543 else |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
544 return -2; |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
545 } |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
546 else if (count > 0) |
531aa00a1e80
acl: Don't use ACL_CNT and similar ops, since they are unreliable.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16381
diff
changeset
|
547 { |
13757
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
548 if (count > NACLENTRIES) |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
549 /* If NACLENTRIES cannot be trusted, use dynamic memory allocation. */ |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
550 abort (); |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
551 } |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
552 |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
553 if (count == 0) |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
554 return qset_acl (dst_name, dest_desc, mode); |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
555 |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
556 ret = acl ((char *) dst_name, ACL_SET, count, entries); |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
557 if (ret < 0) |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
558 { |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
559 int saved_errno = errno; |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
560 |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
561 if (0) |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
562 { |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
563 if (!acl_nontrivial (count, entries)) |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
564 return chmod_or_fchmod (dst_name, dest_desc, mode); |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
565 } |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
566 |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
567 chmod_or_fchmod (dst_name, dest_desc, mode); |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
568 errno = saved_errno; |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
569 return -1; |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
570 } |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
571 |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
572 if (mode & (S_ISUID | S_ISGID | S_ISVTX)) |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
573 { |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
574 /* We did not call chmod so far, and either the mode and the ACL are |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
575 separate or special bits are to be set which don't fit into ACLs. */ |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
576 |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
577 return chmod_or_fchmod (dst_name, dest_desc, mode); |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
578 } |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
579 return 0; |
87aaf9340686
acl: Add support for ACLs on NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
13544
diff
changeset
|
580 |
10155
3df501903792
Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents:
10152
diff
changeset
|
581 #else |
3df501903792
Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents:
10152
diff
changeset
|
582 |
10168
d688b8e59f31
Trivial stylistic improvements.
Bruno Haible <bruno@clisp.org>
parents:
10163
diff
changeset
|
583 return qset_acl (dst_name, dest_desc, mode); |
10155
3df501903792
Simplify #ifs. Put Solaris code after POSIX-like code.
Bruno Haible <bruno@clisp.org>
parents:
10152
diff
changeset
|
584 |
10108
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
585 #endif |
bf329a08180c
Split off copy_acl function to separate file.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
586 } |
10147
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
587 |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
588 |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
589 /* Copy access control lists from one file to another. If SOURCE_DESC is |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
590 a valid file descriptor, use file descriptor operations, else use |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
591 filename based operations on SRC_NAME. Likewise for DEST_DESC and |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
592 DST_NAME. |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
593 If access control lists are not available, fchmod the target file to |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
594 MODE. Also sets the non-permission bits of the destination file |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
595 (S_ISUID, S_ISGID, S_ISVTX) to those from MODE if any are set. |
16268
dad15f0cd2ff
acl: Align return values of copy_acl and qcopy_acl.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
596 Return 0 if successful, otherwise output a diagnostic and return a |
dad15f0cd2ff
acl: Align return values of copy_acl and qcopy_acl.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
597 negative error code. */ |
10147
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
598 |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
599 int |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
600 copy_acl (const char *src_name, int source_desc, const char *dst_name, |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10620
diff
changeset
|
601 int dest_desc, mode_t mode) |
10147
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
602 { |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
603 int ret = qcopy_acl (src_name, source_desc, dst_name, dest_desc, mode); |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
604 switch (ret) |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
605 { |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
606 case -2: |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
607 error (0, errno, "%s", quote (src_name)); |
16268
dad15f0cd2ff
acl: Align return values of copy_acl and qcopy_acl.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
608 break; |
10147
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
609 |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
610 case -1: |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
611 error (0, errno, _("preserving permissions for %s"), quote (dst_name)); |
16268
dad15f0cd2ff
acl: Align return values of copy_acl and qcopy_acl.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
612 break; |
10147
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
613 |
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
614 default: |
16268
dad15f0cd2ff
acl: Align return values of copy_acl and qcopy_acl.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
615 break; |
10147
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
616 } |
16268
dad15f0cd2ff
acl: Align return values of copy_acl and qcopy_acl.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
617 return ret; |
10147
b6cf6bba0c9d
Separate the error handling into a different function.
Bruno Haible <bruno@clisp.org>
parents:
10114
diff
changeset
|
618 } |