Add support for Solaris 10 ACLs. Also, ACLs are Gnulib, not Autoconf.
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 3 Dec 2007 23:30:36 +0000 (15:30 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 3 Dec 2007 23:30:36 +0000 (15:30 -0800)
* modules/acl (configure.ac): Rename AC_FUNC_ACL to gl_FUNC_ACL.
* m4/acl.m4 (gl_FUNC_ACL): Renamed from AC_FUNC_ACL.  On Solaris,
put -lsec in even for programs other than 'ls'.  This fixes a problem
for gettext reported by Bruno Haible in
<http://lists.gnu.org/archive/html/bug-gnulib/2007-12/msg00007.html>.
* lib/acl.c (copy_acl, qset_acl) [USE_ACL && defined ACL_NO_TRIVIAL]:
Add support for Solaris 10.  This isn't efficient, but should get the
job done for now.

ChangeLog
lib/acl.c
m4/acl.m4
modules/acl

index d9d80e9a4aea5aba40dbab6aa146c94f78bac799..06e0ee8dafaa93b702cb1eab4f0cd2282e7fd2df 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2007-12-03  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Add support for Solaris 10 ACLs.  Also, ACLs are Gnulib, not Autoconf.
+       * modules/acl (configure.ac): Rename AC_FUNC_ACL to gl_FUNC_ACL.
+       * m4/acl.m4 (gl_FUNC_ACL): Renamed from AC_FUNC_ACL.  On Solaris,
+       put -lsec in even for programs other than 'ls'.  This fixes a problem
+       for gettext reported by Bruno Haible in
+       <http://lists.gnu.org/archive/html/bug-gnulib/2007-12/msg00007.html>.
+       * lib/acl.c (copy_acl, qset_acl) [USE_ACL && defined ACL_NO_TRIVIAL]:
+       Add support for Solaris 10.  This isn't efficient, but should get the
+       job done for now.
+
 2007-12-03  James Youngman  <jay@gnu.org>
 
        * doc/regexprops-generic.texi: change "an close-group" to "a
index 5214c51c7568ab17c1e9a1cf1ac2565a22a2fc80..b40e43a174c7f3c6b046a5b0feb2db8f4eca2303 100644 (file)
--- a/lib/acl.c
+++ b/lib/acl.c
@@ -144,10 +144,38 @@ copy_acl (const char *src_name, int source_desc, const char *dst_name,
         acl_free (acl);
     }
   return 0;
+
 #else
-  ret = chmod_or_fchmod (dst_name, dest_desc, mode);
+
+# if 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)
+    {
+      error (0, errno, "%s", quote (src_name));
+      return ret;
+    }
+# endif
+
+  ret = qset_acl (dst_name, dest_desc, mode);
   if (ret != 0)
     error (0, errno, _("preserving permissions for %s"), quote (dst_name));
+
+# if USE_ACL && defined ACL_NO_TRIVIAL
+  if (ret == 0 && aclp)
+    {
+      ret = (dest_desc < 0
+            ? acl_set (dst_name, aclp)
+            : facl_set (dest_desc, aclp));
+      if (ret != 0)
+       error (0, errno, _("preserving permissions for %s"), quote (dst_name));
+      acl_free (aclp);
+    }
+# endif
+
   return ret;
 #endif
 }
@@ -240,7 +268,43 @@ qset_acl (char const *name, int desc, mode_t mode)
     }
   return 0;
 #else
+
+# if USE_ACL && 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;
+       }
+    }
+# endif
+
   return chmod_or_fchmod (name, desc, mode);
+
 #endif
 }
 
index 6e6bd086b61ffc657eccbb027af72d1b8a77f908..b5a9aad5150c19d3cab4b88204f59895e1f16c0a 100644 (file)
--- a/m4/acl.m4
+++ b/m4/acl.m4
@@ -7,50 +7,54 @@
 
 # Written by Paul Eggert and Jim Meyering.
 
-AC_DEFUN([AC_FUNC_ACL],
+AC_DEFUN([gl_FUNC_ACL],
 [
   AC_LIBOBJ([acl])
   AC_LIBOBJ([file-has-acl])
 
   dnl Prerequisites of lib/acl.c.
+  LIB_ACL=
+  use_acl=0
   AC_CHECK_HEADERS(sys/acl.h)
-  AC_CHECK_FUNCS(acl)
-  ac_save_LIBS="$LIBS"
-    AC_SEARCH_LIBS(acl_get_file, acl,
-                  [test "$ac_cv_search_acl_get_file" = "none required" ||
-                   LIB_ACL=$ac_cv_search_acl_get_file])
-    AC_SUBST(LIB_ACL)
-    AC_CHECK_HEADERS(acl/libacl.h)
-    AC_CHECK_FUNCS(acl_get_file acl_get_fd acl_set_file acl_set_fd \
-                  acl_free acl_from_mode acl_from_text \
-                  acl_delete_def_file acl_extended_file)
-    if test $ac_cv_header_sys_acl_h = yes; then
-      use_acl=1
-      if test $ac_cv_func_acl_get_file = yes; then
-       # If we detect the acl_get_file bug, disable ACL support altogether.
-       gl_ACL_GET_FILE( , [use_acl=0])
-      fi
-    else
-      use_acl=0
-    fi
-    if test $use_acl = 1 &&
-       test $ac_cv_func_acl_get_file = yes &&
-       test $ac_cv_func_acl_free = yes; then
-      AC_REPLACE_FUNCS([acl_entries])
-    fi
-  LIBS="$ac_save_LIBS"
-  if test $use_acl = 1; then
-    ac_save_LIBS="$LIBS"
+  if test $ac_cv_header_sys_acl_h = yes; then
+    ac_save_LIBS=$LIBS
+    AC_CHECK_FUNCS([acl])
+    use_acl=1
     AC_SEARCH_LIBS([acl_trivial], [sec],
-      [AC_DEFINE([HAVE_ACL_TRIVIAL], 1,
-        [Define to 1 if you have the `acl_trivial' function.])
-       test "$ac_cv_search_acl_trivial" = "none required" ||
-       LIB_ACL_TRIVIAL="$ac_cv_search_acl_trivial"])
-    AC_SUBST([LIB_ACL_TRIVIAL])
-    LIBS="$ac_save_LIBS"
+      [test "$ac_cv_search_acl_trivial" = "none required" ||
+       LIB_ACL=$ac_cv_search_acl_trivial
+       AC_CHECK_FUNCS([acl_trivial])],
+      [if test $ac_cv_func_acl_trivial != yes; then
+        AC_SEARCH_LIBS([acl_get_file], [acl],
+          [test "$ac_cv_search_acl_get_file" = "none required" ||
+           LIB_ACL=$ac_cv_search_acl_get_file
+           AC_CHECK_FUNCS(
+             [acl_get_file acl_get_fd acl_set_file acl_set_fd \
+              acl_free acl_from_mode acl_from_text \
+              acl_delete_def_file acl_extended_file])
+           if test $ac_cv_func_acl_get_file = yes; then
+             # If the acl_get_file bug is detected, disable all ACL support.
+             gl_ACL_GET_FILE( , [use_acl=0])
+           fi
+           if test $use_acl = 1; then
+             AC_CHECK_HEADERS([acl/libacl.h])
+             if test $ac_cv_func_acl_get_file = yes &&
+                test $ac_cv_func_acl_free = yes; then
+               AC_REPLACE_FUNCS([acl_entries])
+             fi
+           else
+             LIB_ACL=
+           fi])
+       fi])
+    LIBS=$ac_save_LIBS
   fi
-  AC_DEFINE_UNQUOTED(USE_ACL, $use_acl,
-                    [Define if you want access control list support.])
+  AC_SUBST([LIB_ACL])
+  AC_DEFINE_UNQUOTED([USE_ACL], [$use_acl],
+    [Define to nonzero if you want access control list support.])
+
+  # This is for backwards compatibility; remove this by the end of 2007.
+  LIB_ACL_TRIVIAL=
+  AC_SUBST([LIB_ACL_TRIVIAL])
 ])
 
 # gl_ACL_GET_FILE(IF-WORKS, IF-NOT)
index e95d24952038477653cef5e63ba56ebf60aaa8d7..03a221799833afaa7a82bbc35b82d80c687e2da6 100644 (file)
@@ -16,7 +16,7 @@ quote
 sys_stat
 
 configure.ac:
-AC_FUNC_ACL
+gl_FUNC_ACL
 
 Makefile.am: