From: Bruno Haible Date: Tue, 3 Jun 2008 22:00:28 +0000 (+0200) Subject: Simplify #ifs. Put Solaris code after POSIX-like code. X-Git-Tag: v0.1~7315 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=fb3917caac20bdcf09b53c1f8d43d0676e5db8b2;p=gnulib.git Simplify #ifs. Put Solaris code after POSIX-like code. --- diff --git a/ChangeLog b/ChangeLog index d52bae051..19792e695 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-06-03 Bruno Haible + + * lib/file-has-acl.c (file_has_acl): Put Solaris 10 code after POSIX- + draft code. Simplify #ifs. + * lib/set-mode-acl.c (qset_acl): Don't test for symlink if !USE_ACL. + Put Solaris code after POSIX-draft code. Fix comments regarding + Solaris 10, HP-UX. Mention Cygwin. + * lib/copy-acl.c (qcopy_acl): Simplify #ifs. + 2008-06-03 Eric Blake Provide fallback for older kernels. diff --git a/lib/copy-acl.c b/lib/copy-acl.c index 2a32f7d0d..eefbff768 100644 --- a/lib/copy-acl.c +++ b/lib/copy-acl.c @@ -41,7 +41,7 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, { int ret; -#if USE_ACL && HAVE_ACL_GET_FILE && HAVE_ACL_SET_FILE && HAVE_ACL_FREE +#if USE_ACL && HAVE_ACL_GET_FILE /* POSIX 1003.1e (draft 17 -- abandoned) specific version. */ /* Linux, FreeBSD, MacOS X, IRIX, Tru64 */ @@ -125,23 +125,20 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, } return 0; -#else - -# if USE_ACL && defined ACL_NO_TRIVIAL +#elif USE_ACL && defined ACL_NO_TRIVIAL /* Solaris 10 NFSv4 ACLs. */ + acl_t *aclp = NULL; ret = (source_desc < 0 ? acl_get (src_name, ACL_NO_TRIVIAL, &aclp) : facl_get (source_desc, ACL_NO_TRIVIAL, &aclp)); if (ret != 0 && errno != ENOSYS) return -2; -# endif ret = qset_acl (dst_name, dest_desc, mode); if (ret != 0) return -1; -# if USE_ACL && defined ACL_NO_TRIVIAL if (aclp) { ret = (dest_desc < 0 @@ -157,9 +154,13 @@ qcopy_acl (const char *src_name, int source_desc, const char *dst_name, } acl_free (aclp); } -# endif return 0; + +#else + + return qset_acl (dst_name, dest_desc, mode); + #endif } diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c index c69d012aa..977708963 100644 --- a/lib/file-has-acl.c +++ b/lib/file-has-acl.c @@ -30,21 +30,10 @@ int file_has_acl (char const *name, struct stat const *sb) { +#if USE_ACL if (! S_ISLNK (sb->st_mode)) { -#if USE_ACL && HAVE_ACL_TRIVIAL - - /* Solaris 10, which also has NFSv4 and ZFS style ACLs. */ - return acl_trivial (name); - -#elif USE_ACL && HAVE_ACL && defined GETACLCNT - - /* Solaris 2.5 through Solaris 9, and contemporaneous versions of - HP-UX and Unixware. */ - int n = acl (name, GETACLCNT, 0, NULL); - return n < 0 ? (errno == ENOSYS ? 0 : -1) : (MIN_ACL_ENTRIES < n); - -#elif USE_ACL && HAVE_ACL_GET_FILE && HAVE_ACL_FREE +# if HAVE_ACL_GET_FILE /* POSIX 1003.1e (draft 17 -- abandoned) specific version. */ /* Linux, FreeBSD, MacOS X, IRIX, Tru64 */ @@ -77,8 +66,27 @@ file_has_acl (char const *name, struct stat const *sb) if (ret < 0) return ACL_NOT_WELL_SUPPORTED (errno) ? 0 : -1; return ret; -#endif + +# elif HAVE_ACL && defined GETACLCNT /* Solaris, Cygwin, not HP-UX */ + +# if HAVE_ACL_TRIVIAL + + /* Solaris 10, which also has NFSv4 and ZFS style ACLs. */ + return acl_trivial (name); + +# else /* Solaris, Cygwin, general case */ + + /* Solaris 2.5 through Solaris 10, Cygwin, and contemporaneous versions + of Unixware. The acl() call returns the access and default ACL both + at once. */ + int n = acl (name, GETACLCNT, 0, NULL); + return n < 0 ? (errno == ENOSYS ? 0 : -1) : (MIN_ACL_ENTRIES < n); + +# endif + +# endif } +#endif /* FIXME: Add support for AIX, Irix, and Tru64. Please see Samba's source/lib/sysacls.c file for fix-related ideas. */ diff --git a/lib/set-mode-acl.c b/lib/set-mode-acl.c index 79d3c5708..4d59c0732 100644 --- a/lib/set-mode-acl.c +++ b/lib/set-mode-acl.c @@ -49,9 +49,10 @@ int qset_acl (char const *name, int desc, mode_t mode) { #if USE_ACL -# if MODE_INSIDE_ACL -# if HAVE_ACL_SET_FILE && HAVE_ACL_FREE +# if HAVE_ACL_GET_FILE /* POSIX 1003.1e draft 17 (abandoned) specific version. */ + /* Linux, FreeBSD, MacOS X, IRIX, Tru64 */ +# if MODE_INSIDE_ACL /* Linux, FreeBSD, IRIX, Tru64 */ /* We must also have acl_from_text and acl_delete_def_file. @@ -138,46 +139,7 @@ qset_acl (char const *name, int desc, mode_t mode) } return 0; -# elif defined ACL_NO_TRIVIAL - /* Solaris 10, with NFSv4 ACLs. */ - acl_t *aclp; - char acl_text[] = "user::---,group::---,mask:---,other:---"; - - if (mode & S_IRUSR) acl_text[ 6] = 'r'; - if (mode & S_IWUSR) acl_text[ 7] = 'w'; - if (mode & S_IXUSR) acl_text[ 8] = 'x'; - if (mode & S_IRGRP) acl_text[17] = acl_text[26] = 'r'; - if (mode & S_IWGRP) acl_text[18] = acl_text[27] = 'w'; - if (mode & S_IXGRP) acl_text[19] = acl_text[28] = 'x'; - if (mode & S_IROTH) acl_text[36] = 'r'; - if (mode & S_IWOTH) acl_text[37] = 'w'; - if (mode & S_IXOTH) acl_text[38] = 'x'; - - if (acl_fromtext (acl_text, &aclp) != 0) - { - errno = ENOMEM; - return -1; - } - else - { - int acl_result = (desc < 0 ? acl_set (name, aclp) : facl_set (desc, aclp)); - int acl_errno = errno; - acl_free (aclp); - if (acl_result == 0 || acl_errno != ENOSYS) - { - errno = acl_errno; - return acl_result; - } - } - - return chmod_or_fchmod (name, desc, mode); - -# else /* Unknown flavor of ACLs */ - return chmod_or_fchmod (name, desc, mode); -# endif -# else /* !MODE_INSIDE_ACL */ -# if HAVE_ACL_SET_FILE && HAVE_ACL_FREE - /* POSIX 1003.1e draft 17 (abandoned) specific version. */ +# else /* !MODE_INSIDE_ACL */ /* MacOS X */ acl_t acl; @@ -223,9 +185,44 @@ qset_acl (char const *name, int desc, mode_t mode) } return chmod_or_fchmod (name, desc, mode); -# else /* Unknown flavor of ACLs */ - return chmod_or_fchmod (name, desc, mode); # endif + +# elif defined ACL_NO_TRIVIAL + /* Solaris 10, with NFSv4 ACLs. */ + acl_t *aclp; + char acl_text[] = "user::---,group::---,mask:---,other:---"; + + if (mode & S_IRUSR) acl_text[ 6] = 'r'; + if (mode & S_IWUSR) acl_text[ 7] = 'w'; + if (mode & S_IXUSR) acl_text[ 8] = 'x'; + if (mode & S_IRGRP) acl_text[17] = acl_text[26] = 'r'; + if (mode & S_IWGRP) acl_text[18] = acl_text[27] = 'w'; + if (mode & S_IXGRP) acl_text[19] = acl_text[28] = 'x'; + if (mode & S_IROTH) acl_text[36] = 'r'; + if (mode & S_IWOTH) acl_text[37] = 'w'; + if (mode & S_IXOTH) acl_text[38] = 'x'; + + if (acl_fromtext (acl_text, &aclp) != 0) + { + errno = ENOMEM; + return -1; + } + else + { + int acl_result = (desc < 0 ? acl_set (name, aclp) : facl_set (desc, aclp)); + int acl_errno = errno; + acl_free (aclp); + if (acl_result == 0 || acl_errno != ENOSYS) + { + errno = acl_errno; + return acl_result; + } + } + + return chmod_or_fchmod (name, desc, mode); + +# else /* Unknown flavor of ACLs */ + return chmod_or_fchmod (name, desc, mode); # endif #else /* !USE_ACL */ return chmod_or_fchmod (name, desc, mode);