Commit b20b7b0b authored by Paul Eggert's avatar Paul Eggert

qacl: new module, broken out from the acl module

This is for GNU Emacs, which wants the acl functions but does
not want 'error' invoked when they fail.
* lib/acl-internal.h: Do not include error.h, quote.h.
(ENOSYS, ENOTSUP): Remove; no longer needed.
(ACL_NOT_WELL_SUPPORTED): Remove; replaced by acl_errno_valid.
* lib/acl.h: Include <stdbool.h>.
(acl_errno_valid): New function.
* lib/copy-acl.c, lib/set-acl.c: Include errno,h, not acl-internal.h.
* lib/copy-acl.c (qcopy_acl): Move to lib/qcopy-acl.c.
* lib/set-acl.c: Rename from lib/set-mode-acl.c.
(chmod_or_fchmod, qset_acl): Move to lib/qset-acl.c.
(ACL_INTERNAL_INLINE): Remove; no longer needed.
* lib/file-has-acl.c (file_has_acl):
* lib/qcopy-acl.c (qcopy_acl):
* lib/qset-acl.c (qset_acl):
Use acl_errno_valid instead of ACL_NOT_WELL_SUPPORTED.
* modules/acl (Files): Move lib/acl.h, lib/acl-internal.h,
lib/acl_entries.c, lib/set-mode-acl.c (renamed to lib/set-acl.c),
lib/file-has-acl.c, m4/acl.m4 to qacl module.
Add lib/set-acl.c.
(Depends-on): Move extern-inline, fstat, sys_stat to qacl module.
Add qacl.
(configure.ac): Move gl_FUNC_ACL to qacl module.
(lib_SOURCES): Remove file-has-acl.c (moved to qacl module).
Rename set-mode-acl.c to set-acl.c.
* lib/acl-errno-valid.c: New file.
* lib/qcopy-acl.c: New file, moved from the old lib/copy-acl.c; the
copy_acl function remains in copy-acl.c.
* lib/qcopy-acl.c, lib/qset-acl.c: Do not include gettext.h.
(_): Remove; not needed.
* lib/qset-acl.c: New file, moved from the old lib/set-mode-acl.c; the
set_acl function remains in set-acl.c (renamed from set-mode-acl.c).
* modules/qacl: New file, moved from the old modules/acl.
(Files, lib_SOURCES): Add acl-errno-valid.c, qcopy-acl.c, qset-acl.c.
Remove set-mode-acl.c, copy-acl.c.
(Depends-on): Remove error, gettext-h, quote.  Add stdbool.
parent 0488b6e8
2013-04-27 Paul Eggert <eggert@cs.ucla.edu>
qacl: new module, broken out from the acl module
This is for GNU Emacs, which wants the acl functions but does
not want 'error' invoked when they fail.
* lib/acl-internal.h: Do not include error.h, quote.h.
(ENOSYS, ENOTSUP): Remove; no longer needed.
(ACL_NOT_WELL_SUPPORTED): Remove; replaced by acl_errno_valid.
* lib/acl.h: Include <stdbool.h>.
(acl_errno_valid): New function.
* lib/copy-acl.c, lib/set-acl.c: Include errno,h, not acl-internal.h.
* lib/copy-acl.c (qcopy_acl): Move to lib/qcopy-acl.c.
* lib/set-acl.c: Rename from lib/set-mode-acl.c.
(chmod_or_fchmod, qset_acl): Move to lib/qset-acl.c.
(ACL_INTERNAL_INLINE): Remove; no longer needed.
* lib/file-has-acl.c (file_has_acl):
* lib/qcopy-acl.c (qcopy_acl):
* lib/qset-acl.c (qset_acl):
Use acl_errno_valid instead of ACL_NOT_WELL_SUPPORTED.
* modules/acl (Files): Move lib/acl.h, lib/acl-internal.h,
lib/acl_entries.c, lib/set-mode-acl.c (renamed to lib/set-acl.c),
lib/file-has-acl.c, m4/acl.m4 to qacl module.
Add lib/set-acl.c.
(Depends-on): Move extern-inline, fstat, sys_stat to qacl module.
Add qacl.
(configure.ac): Move gl_FUNC_ACL to qacl module.
(lib_SOURCES): Remove file-has-acl.c (moved to qacl module).
Rename set-mode-acl.c to set-acl.c.
* lib/acl-errno-valid.c: New file.
* lib/qcopy-acl.c: New file, moved from the old lib/copy-acl.c; the
copy_acl function remains in copy-acl.c.
* lib/qcopy-acl.c, lib/qset-acl.c: Do not include gettext.h.
(_): Remove; not needed.
* lib/qset-acl.c: New file, moved from the old lib/set-mode-acl.c; the
set_acl function remains in set-acl.c (renamed from set-mode-acl.c).
* modules/qacl: New file, moved from the old modules/acl.
(Files, lib_SOURCES): Add acl-errno-valid.c, qcopy-acl.c, qset-acl.c.
Remove set-mode-acl.c, copy-acl.c.
(Depends-on): Remove error, gettext-h, quote. Add stdbool.
alignof, intprops, malloca: port better to IBM's C compiler
* lib/alignof.h (alignof_type) [__IBM_ALIGNOF__]: Use __alignof__.
* lib/intprops.h (_GL_HAVE___TYPEOF__) [__IBM_TYPEOF__]: Now 1.
/* Test whether ACLs are well supported on this system.
Copyright 2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Written by Paul Eggert. */
#include <config.h>
#include <acl.h>
#include <errno.h>
/* Return true if errno value ERRNUM indicates that ACLs are well
supported on this system. ERRNUM should be an errno value obtained
after an ACL-related system call fails. */
bool
acl_errno_valid (int errnum)
{
/* Recognize some common errors such as from an NFS mount that does
not support ACLs, even when local drives do. */
switch (errnum)
{
case EBUSY: return false;
case EINVAL: return false;
#if defined __APPLE__ && defined __MACH__
case ENOENT: return false;
#endif
case ENOSYS: return false;
#if defined ENOTSUP && ENOTSUP != EOPNOTSUPP
case ENOTSUP: return false;
#endif
case EOPNOTSUPP: return false;
default: return true;
}
}
......@@ -44,16 +44,7 @@ extern int acl (char *, int, int, struct acl *);
extern int aclsort (int, int, struct acl *);
#endif
#include "error.h"
#include "quote.h"
#include <errno.h>
#ifndef ENOSYS
# define ENOSYS (-1)
#endif
#ifndef ENOTSUP
# define ENOTSUP (-1)
#endif
#include <limits.h>
#ifndef MIN
......@@ -69,19 +60,6 @@ extern int aclsort (int, int, struct acl *);
# define fchmod(fd, mode) (-1)
#endif
/* Recognize some common errors such as from an NFS mount that does
not support ACLs, even when local drives do. */
#if defined __APPLE__ && defined __MACH__ /* Mac OS X */
# define ACL_NOT_WELL_SUPPORTED(Err) \
((Err) == ENOTSUP || (Err) == ENOSYS || (Err) == EINVAL || (Err) == EBUSY || (Err) == ENOENT)
#elif defined EOPNOTSUPP /* Tru64 NFS */
# define ACL_NOT_WELL_SUPPORTED(Err) \
((Err) == ENOTSUP || (Err) == ENOSYS || (Err) == EINVAL || (Err) == EBUSY || (Err) == EOPNOTSUPP)
#else
# define ACL_NOT_WELL_SUPPORTED(Err) \
((Err) == ENOTSUP || (Err) == ENOSYS || (Err) == EINVAL || (Err) == EBUSY)
#endif
_GL_INLINE_HEADER_BEGIN
#ifndef ACL_INTERNAL_INLINE
# define ACL_INTERNAL_INLINE _GL_INLINE
......
......@@ -17,9 +17,11 @@
Written by Paul Eggert. */
#include <stdbool.h>
#include <sys/types.h>
#include <sys/stat.h>
bool acl_errno_valid (int) _GL_ATTRIBUTE_CONST;
int file_has_acl (char const *, struct stat const *);
int qset_acl (char const *, int, mode_t);
int set_acl (char const *, int, mode_t);
......
This diff is collapsed.
......@@ -553,7 +553,7 @@ file_has_acl (char const *name, struct stat const *sb)
# endif
}
if (ret < 0)
return ACL_NOT_WELL_SUPPORTED (errno) ? 0 : -1;
return - acl_errno_valid (errno);
return ret;
# elif HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */
......
This diff is collapsed.
/* set-mode-acl.c - set access control list equivalent to a mode
/* qset-acl.c - set access control list equivalent to a mode
Copyright (C) 2002-2003, 2005-2013 Free Software Foundation, Inc.
......@@ -25,13 +25,10 @@
#include "acl-internal.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
/* If DESC is a valid file descriptor use fchmod to change the
file's mode to MODE on systems that have fchown. On systems
that don't have fchown and if DESC is invalid, use chown on
file's mode to MODE on systems that have fchmod. On systems
that don't have fchmod and if DESC is invalid, use chmod on
NAME instead.
Return 0 if successful. Return -1 and set errno upon failure. */
......@@ -119,14 +116,10 @@ qset_acl (char const *name, int desc, mode_t mode)
{
int saved_errno = errno;
acl_free (acl);
if (ACL_NOT_WELL_SUPPORTED (errno))
if (! acl_errno_valid (errno))
return chmod_or_fchmod (name, desc, mode);
else
{
errno = saved_errno;
return -1;
}
errno = saved_errno;
return -1;
}
else
acl_free (acl);
......@@ -180,16 +173,11 @@ qset_acl (char const *name, int desc, mode_t mode)
if (ret != 0)
{
int saved_errno = errno;
acl_free (acl);
if (ACL_NOT_WELL_SUPPORTED (saved_errno))
if (! acl_errno_valid (saved_errno))
return chmod_or_fchmod (name, desc, mode);
else
{
errno = saved_errno;
return -1;
}
errno = saved_errno;
return -1;
}
acl_free (acl);
}
......@@ -686,14 +674,3 @@ qset_acl (char const *name, int desc, mode_t mode)
return chmod_or_fchmod (name, desc, mode);
#endif
}
/* As with qset_acl, but also output a diagnostic on failure. */
int
set_acl (char const *name, int desc, mode_t mode)
{
int ret = qset_acl (name, desc, mode);
if (ret != 0)
error (0, errno, _("setting permissions for %s"), quote (name));
return ret;
}
/* set-acl.c - set access control list equivalent to a mode
Copyright (C) 2002-2003, 2005-2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Written by Paul Eggert and Andreas Gruenbacher, and Bruno Haible. */
#include <config.h>
#include "acl.h"
#include "error.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
/* Set the access control lists of a file. If DESC is a valid file
descriptor, use file descriptor operations where available, else use
filename based operations on NAME. If access control lists are not
available, fchmod the target file to MODE. Also sets the
non-permission bits of the destination file (S_ISUID, S_ISGID, S_ISVTX)
to those from MODE if any are set.
Return 0 if successful. On failure, output a diagnostic, set errno and
return -1. */
int
set_acl (char const *name, int desc, mode_t mode)
{
int ret = qset_acl (name, desc, mode);
if (ret != 0)
error (0, errno, _("setting permissions for %s"), quote (name));
return ret;
}
Description:
Access control lists of files. (Unportable.)
Access control lists of files, with diagnostics. (Unportable.)
Files:
lib/acl.h
lib/acl-internal.h
lib/acl_entries.c
lib/set-mode-acl.c
lib/copy-acl.c
lib/file-has-acl.c
m4/acl.m4
lib/set-acl.c
Depends-on:
error
extern-inline
fstat
gettext-h
qacl
quote
sys_stat
configure.ac:
gl_FUNC_ACL
Makefile.am:
lib_SOURCES += set-mode-acl.c copy-acl.c file-has-acl.c
lib_SOURCES += copy-acl.c set-acl.c
Include:
"acl.h"
......
Description:
Access control lists of files. (Unportable.)
Files:
lib/acl.h
lib/acl-internal.h
lib/acl-errno-valid.c
lib/acl_entries.c
lib/file-has-acl.c
lib/qcopy-acl.c
lib/qset-acl.c
m4/acl.m4
Depends-on:
extern-inline
fstat
stdbool
sys_stat
configure.ac:
gl_FUNC_ACL
Makefile.am:
lib_SOURCES += acl-errno-valid.c file-has-acl.c qcopy-acl.c qset-acl.c
Include:
"acl.h"
Link:
$(LIB_ACL)
License:
GPL
Maintainer:
Paul Eggert, Jim Meyering, Bruno Haible
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment