From 0a9d9877fef46e7bc0a3eff16081d37016569981 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 3 Dec 2007 15:30:36 -0800 Subject: [PATCH] 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 . * 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 | 12 +++++++++ lib/acl.c | 66 +++++++++++++++++++++++++++++++++++++++++++++- m4/acl.m4 | 76 ++++++++++++++++++++++++++++------------------------- modules/acl | 2 +- 4 files changed, 118 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index d9d80e9a4a..06e0ee8daf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-12-03 Paul Eggert + + 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 + . + * 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 * doc/regexprops-generic.texi: change "an close-group" to "a diff --git a/lib/acl.c b/lib/acl.c index 5214c51c75..b40e43a174 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 6e6bd086b6..b5a9aad515 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 e95d249520..03a2217998 100644 --- a/modules/acl +++ b/modules/acl @@ -16,7 +16,7 @@ quote sys_stat configure.ac: -AC_FUNC_ACL +gl_FUNC_ACL Makefile.am: -- 2.30.2