bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: $(LIB_ACL_TRIVIAL)


From: Paul Eggert
Subject: Re: $(LIB_ACL_TRIVIAL)
Date: Mon, 03 Dec 2007 15:34:56 -0800
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

Bruno Haible <address@hidden> writes:

> But how come that some programs use the 'acl' module and nevertheless don't
> need $(LIB_ACL_TRIVIAL) ? Possibly the 'acl' module is the combination of
> two different functionalities, and should better be split into two different
> modules - one which relies on $(LIB_ACL_TRIVIAL) $(LIB_ACL) and one which
> relies only on $(LIB_ACL) ?

For the code that exists there now, that would be the right fix.  But
a better fix is to add support for Solaris 10 ACLs.  One we do that,
the justification for LIB_ACL_TRIVIAL will largely melt away, as we'll
need Solaris's -lsec for every program that uses ACLs.

On my list of things to do is to add relatively efficient support for
Solaris ACLs.  But that's nontrivial.  In the mean time, slow support
is better than no support at all, so I installed the following:

2007-12-03  Paul Eggert  <address@hidden>

        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.

diff --git a/lib/acl.c b/lib/acl.c
index 5214c51..b40e43a 100644
--- 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
 }

diff --git a/m4/acl.m4 b/m4/acl.m4
index 6e6bd08..b5a9aad 100644
--- 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)
diff --git a/modules/acl b/modules/acl
index e95d249..03a2217 100644
--- a/modules/acl
+++ b/modules/acl
@@ -16,7 +16,7 @@ quote
 sys_stat

 configure.ac:
-AC_FUNC_ACL
+gl_FUNC_ACL

 Makefile.am:





reply via email to

[Prev in Thread] Current Thread [Next in Thread]