bug-gnulib
[Top][All Lists]
Advanced

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

Re: make openat declarations consistent


From: Eric Blake
Subject: Re: make openat declarations consistent
Date: Thu, 3 Sep 2009 20:01:34 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Eric Blake <ebb9 <at> byu.net> writes:

> > That brings up the lack of an faccessat replacement in gnulib.
> 
> I'll post a module for this shortly.

It is feasible for a system to have faccessat but not euidaccess (if they are 
complying strictly with POSIX 2008), so we might as well add that to our 
euidaccess arsenal.

With regards to the cygwin 1.7 faccessat bug, it would be a separate patch to 
add a check for whether faccessat works, and if not, use the stat() fallback 
path of euidaccess as well as create rpl_faccessat.  But cygwin's faccessat 
DOES support AT_SYMLINK_NOFOLLOW to check the access bits of symlinks (not that 
it is ever useful in practice), just like Linux, which means we would have to 
consider an leuidaccess wrapper that acts like euidaccess except using lstat 
instead of stat.


>From c71f2501a518d8a22db671a14ebd533aecc12463 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 3 Sep 2009 11:38:53 -0600
Subject: [PATCH 1/3] openat: make template easier to use

* lib/at-func.c (CALL_FUNC): Allow AT_FUNC_USE_F1_COND and
AT_FUNC_F2 to be undefined.
(VALIDATE_FLAG): New macro; use it to reject bad flags.
(AT_FUNC_USE_F1_COND): Change sense to just flag bit.
* lib/fchmodat.c (AT_FUNC_USE_F1_COND): Adjust.
* lib/fchownat.c (AT_FUNC_USE_F1_COND): Likewise.
* lib/openat.c (AT_FUNC_USE_F1_COND) [fstatat, unlinkat]:
Likewise.
* lib/mkdirat.c (AT_FUNC_F2, AT_FUNC_USE_F1_COND): Delete.
* lib/selinux-at.c (AT_FUNC_F2, AT_FUNC_USE_F1_COND)
[getfileconat, lgetfileconat, setfileconat, lsetfileconat]:
Likewise.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog        |   14 ++++++++++++++
 lib/at-func.c    |   27 +++++++++++++++++++++------
 lib/fchmodat.c   |    2 +-
 lib/fchownat.c   |    2 +-
 lib/mkdirat.c    |    2 --
 lib/openat.c     |    4 ++--
 lib/selinux-at.c |   16 ----------------
 7 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a73cad1..288440e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2009-09-03  Eric Blake  <address@hidden>

+       openat: make template easier to use
+       * lib/at-func.c (CALL_FUNC): Allow AT_FUNC_USE_F1_COND and
+       AT_FUNC_F2 to be undefined.
+       (VALIDATE_FLAG): New macro; use it to reject bad flags.
+       (AT_FUNC_USE_F1_COND): Change sense to just flag bit.
+       * lib/fchmodat.c (AT_FUNC_USE_F1_COND): Adjust.
+       * lib/fchownat.c (AT_FUNC_USE_F1_COND): Likewise.
+       * lib/openat.c (AT_FUNC_USE_F1_COND) [fstatat, unlinkat]:
+       Likewise.
+       * lib/mkdirat.c (AT_FUNC_F2, AT_FUNC_USE_F1_COND): Delete.
+       * lib/selinux-at.c (AT_FUNC_F2, AT_FUNC_USE_F1_COND)
+       [getfileconat, lgetfileconat, setfileconat, lsetfileconat]:
+       Likewise.
+
        openat: declare in POSIX headers
        * NEWS: Mention this.
        * modules/openat (configure.ac): Declare witnesses.
diff --git a/lib/at-func.c b/lib/at-func.c
index c7963fe..620fdaf 100644
--- a/lib/at-func.c
+++ b/lib/at-func.c
@@ -1,5 +1,5 @@
 /* Define an at-style functions like fstatat, unlinkat, fchownat, etc.
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2009 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
@@ -16,14 +16,27 @@

 /* written by Jim Meyering */

-#define CALL_FUNC(F)                           \
-  (AT_FUNC_USE_F1_COND                         \
+#ifdef AT_FUNC_USE_F1_COND
+# define CALL_FUNC(F)                          \
+  (flag == AT_FUNC_USE_F1_COND                 \
     ? AT_FUNC_F1 (F AT_FUNC_POST_FILE_ARGS)    \
     : AT_FUNC_F2 (F AT_FUNC_POST_FILE_ARGS))
+# define VALIDATE_FLAG(F)                      \
+  if (flag & ~AT_FUNC_USE_F1_COND)             \
+    {                                          \
+      errno = EINVAL;                          \
+      return -1;                               \
+    }
+#else
+# define CALL_FUNC(F) (AT_FUNC_F1 (F AT_FUNC_POST_FILE_ARGS))
+# define VALIDATE_FLAG(F) /* empty */
+#endif

-/* Call AT_FUNC_F1 or AT_FUNC_F2 (testing AT_FUNC_USE_F1_COND to
-   determine which) to operate on FILE, which is in the directory
-   open on descriptor FD.  If possible, do it without changing the
+/* Call AT_FUNC_F1 to operate on FILE, which is in the directory
+   open on descriptor FD.  If AT_FUNC_USE_F1_COND is defined to a value,
+   AT_FUNC_POST_FILE_PARAM_DECLS must inlude a parameter named flag;
+   call AT_FUNC_F2 if FLAG is 0 or fail if FLAG contains more bits than
+   AT_FUNC_USE_F1_COND.  If possible, do it without changing the
    working directory.  Otherwise, resort to using save_cwd/fchdir,
    then AT_FUNC_F?/restore_cwd.  If either the save_cwd or the restore_cwd
    fails, then give a diagnostic and exit nonzero.  */
@@ -34,6 +47,8 @@ AT_FUNC_NAME (int fd, char const *file 
AT_FUNC_POST_FILE_PARAM_DECLS)
   int saved_errno;
   int err;

+  VALIDATE_FLAG (flag);
+
   if (fd == AT_FDCWD || IS_ABSOLUTE_FILE_NAME (file))
     return CALL_FUNC (file);

diff --git a/lib/fchmodat.c b/lib/fchmodat.c
index 23eee64..cc2776e 100644
--- a/lib/fchmodat.c
+++ b/lib/fchmodat.c
@@ -45,7 +45,7 @@ static int lchmod (char const *f, mode_t m) { errno = ENOSYS; 
return -1; }
 #define AT_FUNC_NAME fchmodat
 #define AT_FUNC_F1 lchmod
 #define AT_FUNC_F2 chmod
-#define AT_FUNC_USE_F1_COND flag == AT_SYMLINK_NOFOLLOW
+#define AT_FUNC_USE_F1_COND AT_SYMLINK_NOFOLLOW
 #define AT_FUNC_POST_FILE_PARAM_DECLS , mode_t mode, int flag
 #define AT_FUNC_POST_FILE_ARGS        , mode
 #include "at-func.c"
diff --git a/lib/fchownat.c b/lib/fchownat.c
index c217b52..ba5d86b 100644
--- a/lib/fchownat.c
+++ b/lib/fchownat.c
@@ -41,7 +41,7 @@
 #define AT_FUNC_NAME fchownat
 #define AT_FUNC_F1 lchown
 #define AT_FUNC_F2 chown
-#define AT_FUNC_USE_F1_COND flag == AT_SYMLINK_NOFOLLOW
+#define AT_FUNC_USE_F1_COND AT_SYMLINK_NOFOLLOW
 #define AT_FUNC_POST_FILE_PARAM_DECLS , uid_t owner, gid_t group, int flag
 #define AT_FUNC_POST_FILE_ARGS        , owner, group
 #include "at-func.c"
diff --git a/lib/mkdirat.c b/lib/mkdirat.c
index d4b3317..33ece9c 100644
--- a/lib/mkdirat.c
+++ b/lib/mkdirat.c
@@ -34,8 +34,6 @@

 #define AT_FUNC_NAME mkdirat
 #define AT_FUNC_F1 mkdir
-#define AT_FUNC_F2 mkdir
-#define AT_FUNC_USE_F1_COND 1
 #define AT_FUNC_POST_FILE_PARAM_DECLS , mode_t mode
 #define AT_FUNC_POST_FILE_ARGS        , mode
 #include "at-func.c"
diff --git a/lib/openat.c b/lib/openat.c
index 0e2c27b..e1471b8 100644
--- a/lib/openat.c
+++ b/lib/openat.c
@@ -169,7 +169,7 @@ openat_needs_fchdir (void)
 #define AT_FUNC_NAME fstatat
 #define AT_FUNC_F1 lstat
 #define AT_FUNC_F2 stat
-#define AT_FUNC_USE_F1_COND flag == AT_SYMLINK_NOFOLLOW
+#define AT_FUNC_USE_F1_COND AT_SYMLINK_NOFOLLOW
 #define AT_FUNC_POST_FILE_PARAM_DECLS , struct stat *st, int flag
 #define AT_FUNC_POST_FILE_ARGS        , st
 #include "at-func.c"
@@ -191,7 +191,7 @@ openat_needs_fchdir (void)
 #define AT_FUNC_NAME unlinkat
 #define AT_FUNC_F1 rmdir
 #define AT_FUNC_F2 unlink
-#define AT_FUNC_USE_F1_COND flag == AT_REMOVEDIR
+#define AT_FUNC_USE_F1_COND AT_REMOVEDIR
 #define AT_FUNC_POST_FILE_PARAM_DECLS , int flag
 #define AT_FUNC_POST_FILE_ARGS        /* empty */
 #include "at-func.c"
diff --git a/lib/selinux-at.c b/lib/selinux-at.c
index 18e6b0f..65f938b 100644
--- a/lib/selinux-at.c
+++ b/lib/selinux-at.c
@@ -33,56 +33,40 @@

 #define AT_FUNC_NAME getfileconat
 #define AT_FUNC_F1 getfilecon
-#define AT_FUNC_F2 getfilecon
-#define AT_FUNC_USE_F1_COND 1
 #define AT_FUNC_POST_FILE_PARAM_DECLS , security_context_t *con
 #define AT_FUNC_POST_FILE_ARGS        , con
 #include "at-func.c"
 #undef AT_FUNC_NAME
 #undef AT_FUNC_F1
-#undef AT_FUNC_F2
-#undef AT_FUNC_USE_F1_COND
 #undef AT_FUNC_POST_FILE_PARAM_DECLS
 #undef AT_FUNC_POST_FILE_ARGS

 #define AT_FUNC_NAME lgetfileconat
 #define AT_FUNC_F1 lgetfilecon
-#define AT_FUNC_F2 lgetfilecon
-#define AT_FUNC_USE_F1_COND 1
 #define AT_FUNC_POST_FILE_PARAM_DECLS , security_context_t *con
 #define AT_FUNC_POST_FILE_ARGS        , con
 #include "at-func.c"
 #undef AT_FUNC_NAME
 #undef AT_FUNC_F1
-#undef AT_FUNC_F2
-#undef AT_FUNC_USE_F1_COND
 #undef AT_FUNC_POST_FILE_PARAM_DECLS
 #undef AT_FUNC_POST_FILE_ARGS

 #define AT_FUNC_NAME setfileconat
 #define AT_FUNC_F1 setfilecon
-#define AT_FUNC_F2 setfilecon
-#define AT_FUNC_USE_F1_COND 1
 #define AT_FUNC_POST_FILE_PARAM_DECLS , security_context_t con
 #define AT_FUNC_POST_FILE_ARGS        , con
 #include "at-func.c"
 #undef AT_FUNC_NAME
 #undef AT_FUNC_F1
-#undef AT_FUNC_F2
-#undef AT_FUNC_USE_F1_COND
 #undef AT_FUNC_POST_FILE_PARAM_DECLS
 #undef AT_FUNC_POST_FILE_ARGS

 #define AT_FUNC_NAME lsetfileconat
 #define AT_FUNC_F1 lsetfilecon
-#define AT_FUNC_F2 lsetfilecon
-#define AT_FUNC_USE_F1_COND 1
 #define AT_FUNC_POST_FILE_PARAM_DECLS , security_context_t con
 #define AT_FUNC_POST_FILE_ARGS        , con
 #include "at-func.c"
 #undef AT_FUNC_NAME
 #undef AT_FUNC_F1
-#undef AT_FUNC_F2
-#undef AT_FUNC_USE_F1_COND
 #undef AT_FUNC_POST_FILE_PARAM_DECLS
 #undef AT_FUNC_POST_FILE_ARGS
-- 
1.6.3.2


>From a372b521763eb072ad4272d65def718dc8763f7f Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 3 Sep 2009 13:43:12 -0600
Subject: [PATCH 2/3] euidaccess: prefer POSIX over non-standard implemenation

* m4/euidaccess.m4 (gl_PREREQ_EUIDACCESS): Check for faccessat.
* lib/euidaccess.c (euidaccess): Use it if available.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog        |    4 ++++
 lib/euidaccess.c |    8 +++++---
 m4/euidaccess.m4 |    5 ++++-
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 288440e..c9ca634 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2009-09-03  Eric Blake  <address@hidden>

+       euidaccess: prefer POSIX over non-standard implemenation
+       * m4/euidaccess.m4 (gl_PREREQ_EUIDACCESS): Check for faccessat.
+       * lib/euidaccess.c (euidaccess): Use it if available.
+
        openat: make template easier to use
        * lib/at-func.c (CALL_FUNC): Allow AT_FUNC_USE_F1_COND and
        AT_FUNC_F2 to be undefined.
diff --git a/lib/euidaccess.c b/lib/euidaccess.c
index 17eb724..5ba59b0 100644
--- a/lib/euidaccess.c
+++ b/lib/euidaccess.c
@@ -1,7 +1,7 @@
 /* euidaccess -- check if effective user id can access file

-   Copyright (C) 1990, 1991, 1995, 1998, 2000, 2003, 2004, 2005, 2006, 2008
-   Free Software Foundation, Inc.
+   Copyright (C) 1990, 1991, 1995, 1998, 2000, 2003, 2004, 2005, 2006,
+   2008, 2009 Free Software Foundation, Inc.

    This file is part of the GNU C Library.

@@ -77,7 +77,9 @@
 int
 euidaccess (const char *file, int mode)
 {
-#if defined EFF_ONLY_OK
+#if HAVE_FACCESSAT
+  return faccessat (AT_FDCWD, file, mode, AT_EACCESS);
+#elif defined EFF_ONLY_OK
   return access (file, mode | EFF_ONLY_OK);
 #elif defined ACC_SELF
   return accessx (file, mode, ACC_SELF);
diff --git a/m4/euidaccess.m4 b/m4/euidaccess.m4
index 5882f58..f1a175c 100644
--- a/m4/euidaccess.m4
+++ b/m4/euidaccess.m4
@@ -1,4 +1,4 @@
-# euidaccess.m4 serial 10
+# euidaccess.m4 serial 11
 dnl Copyright (C) 2002-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -31,6 +31,9 @@ AC_DEFUN([gl_FUNC_EUIDACCESS],

 # Prerequisites of lib/euidaccess.c.
 AC_DEFUN([gl_PREREQ_EUIDACCESS], [
+  dnl Prefer POSIX faccessat over non-standard euidaccess.
+  AC_CHECK_FUNCS_ONCE([faccessat])
+  dnl Try various other non-standard fallbacks.
   AC_CHECK_HEADERS_ONCE([libgen.h])
   AC_CHECK_DECLS_ONCE([setregid])
   AC_REQUIRE([AC_FUNC_GETGROUPS])
-- 
1.6.3.2


>From 7b69561dc6656fb4b873d44ddaacfc46a787ffb5 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Thu, 3 Sep 2009 13:41:18 -0600
Subject: [PATCH 3/3] faccessat: new module

* modules/faccessat: New file.
* lib/faccessat.m4: Likewise.
* m4/faccessat.m4 (gl_FUNC_FACCESSAT): Likewise.
* m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add witness.
* modules/unistd (Makefile.am): Use it.
* lib/unistd.in.h (faccessat): Declare it.
(F_OK, X_OK, W_OK, R_OK): Provide definitions.
* lib/fcntl.in.h (AT_SYMLINK_FOLLOW, AT_EACCESS): Likewise.
* MODULES.html.sh (File system functions): Mention it.
* doc/posix-functions/faccessat.texi (faccessat): Likewise.
* doc/posix-headers/fcntl.texi (fcntl.h): Likewise.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog                          |   13 +++++++++
 MODULES.html.sh                    |    1 +
 doc/posix-functions/faccessat.texi |   14 +++++++---
 doc/posix-headers/fcntl.texi       |    6 +---
 lib/faccessat.c                    |   49 ++++++++++++++++++++++++++++++++++++
 lib/fcntl.in.h                     |    9 ++++++
 lib/unistd.in.h                    |   22 ++++++++++++++++
 m4/faccessat.m4                    |   21 +++++++++++++++
 m4/unistd_h.m4                     |    2 +
 modules/faccessat                  |   32 +++++++++++++++++++++++
 modules/unistd                     |    2 +
 11 files changed, 163 insertions(+), 8 deletions(-)
 create mode 100644 lib/faccessat.c
 create mode 100644 m4/faccessat.m4
 create mode 100644 modules/faccessat

diff --git a/ChangeLog b/ChangeLog
index c9ca634..a51697c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2009-09-03  Eric Blake  <address@hidden>

+       faccessat: new module
+       * modules/faccessat: New file.
+       * lib/faccessat.m4: Likewise.
+       * m4/faccessat.m4 (gl_FUNC_FACCESSAT): Likewise.
+       * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add witness.
+       * modules/unistd (Makefile.am): Use it.
+       * lib/unistd.in.h (faccessat): Declare it.
+       (F_OK, X_OK, W_OK, R_OK): Provide definitions.
+       * lib/fcntl.in.h (AT_SYMLINK_FOLLOW, AT_EACCESS): Likewise.
+       * MODULES.html.sh (File system functions): Mention it.
+       * doc/posix-functions/faccessat.texi (faccessat): Likewise.
+       * doc/posix-headers/fcntl.texi (fcntl.h): Likewise.
+
        euidaccess: prefer POSIX over non-standard implemenation
        * m4/euidaccess.m4 (gl_PREREQ_EUIDACCESS): Check for faccessat.
        * lib/euidaccess.c (euidaccess): Use it if available.
diff --git a/MODULES.html.sh b/MODULES.html.sh
index bcecc55..b60ef61 100755
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -2452,6 +2452,7 @@ func_all_modules ()
   func_module dirfd
   func_module double-slash-root
   func_module euidaccess
+  func_module faccessat
   func_module fdopendir
   func_module file-type
   func_module fileblocks
diff --git a/doc/posix-functions/faccessat.texi b/doc/posix-
functions/faccessat.texi
index bf3335d..835a5d8 100644
--- a/doc/posix-functions/faccessat.texi
+++ b/doc/posix-functions/faccessat.texi
@@ -4,16 +4,22 @@ faccessat

 POSIX specification: @url
{http://www.opengroup.org/onlinepubs/9699919799/functions/faccessat.html}

-Gnulib module: ---
+Gnulib module: faccessat

 Portability problems fixed by Gnulib:
 @itemize
address@hidden
+This function is missing on some platforms:
+glibc 2.3.6, MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX
+5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x, mingw,
+Interix 3.5, BeOS.
+However, the replacement does not always take into account ACLs.
 @end itemize

 Portability problems not fixed by Gnulib:
 @itemize
 @item
-This function is missing on some platforms:
-glibc 2.3.6, MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX
-5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x, mingw, Interix 
3.5, BeOS.
+There is an inherent race between calling this function and performing
+some action based on the results; you should think twice before
+trusting this function in a set-uid or set-gid program.
 @end itemize
diff --git a/doc/posix-headers/fcntl.texi b/doc/posix-headers/fcntl.texi
index 020586c..5cf86ee 100644
--- a/doc/posix-headers/fcntl.texi
+++ b/doc/posix-headers/fcntl.texi
@@ -32,7 +32,8 @@ fcntl.h
 Solaris 10

 @item
address@hidden, @samp{AT_SYMLINK_NOFOLLOW}, and @samp{AT_REMOVEDIR}
address@hidden, @samp{AT_EACCESS}, @samp{AT_SYMLINK_NOFOLLOW},
address@hidden, and @samp{AT_REMOVEDIR}
 are missing on some platforms.
 @end itemize

@@ -61,7 +62,4 @@ fcntl.h
 @samp{POSIX_FADV_NORMAL}, @samp{POSIX_FADV_RANDOM},
 @samp{POSIX_FADV_SEQUENTIAL}, and @samp{POSIX_FADV_WILLNEED} are not
 defined on some platforms.
-
address@hidden
address@hidden and @samp{AT_SYMLINK_FOLLOW} are missing on some platforms.
 @end itemize
diff --git a/lib/faccessat.c b/lib/faccessat.c
new file mode 100644
index 0000000..a449b02
--- /dev/null
+++ b/lib/faccessat.c
@@ -0,0 +1,49 @@
+/* Check the access rights of a file relative to an open directory.
+   Copyright (C) 2009 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 Eric Blake */
+
+#include <config.h>
+
+#include <unistd.h>
+
+#include "dirname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */
+#include "openat.h"
+#include "openat-priv.h"
+#include "save-cwd.h"
+
+#ifndef HAVE_ACCESS
+/* Mingw lacks access, but it also lacks real vs. effective ids, so
+   the gnulib euidaccess module is good enough.  */
+# undef access
+# define access euidaccess
+#endif
+
+/* Invoke access or euidaccess on file, FILE, using mode MODE, in the directory
+   open on descriptor FD.  If possible, do it without changing the
+   working directory.  Otherwise, resort to using save_cwd/fchdir,
+   then mkdir/restore_cwd.  If either the save_cwd or the restore_cwd
+   fails, then give a diagnostic and exit nonzero.
+   Note that this implementation only supports AT_EACCESS, although some
+   native versions also support AT_SYMLINK_NOFOLLOW.  */
+
+#define AT_FUNC_NAME faccessat
+#define AT_FUNC_F1 euidaccess
+#define AT_FUNC_F2 access
+#define AT_FUNC_USE_F1_COND AT_EACCESS
+#define AT_FUNC_POST_FILE_PARAM_DECLS , int mode, int flag
+#define AT_FUNC_POST_FILE_ARGS        , mode
+#include "at-func.c"
diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h
index 6c88b47..cadb6a1 100644
--- a/lib/fcntl.in.h
+++ b/lib/fcntl.in.h
@@ -192,6 +192,15 @@ int openat (int fd, char const *file, int flags, /* mode_t 
mode */ ...);
 # define AT_REMOVEDIR 1
 #endif

+/* Solaris 9 lacks these two, so just pick unique values.  */
+#ifndef AT_SYMLINK_FOLLOW
+# define AT_SYMLINK_FOLLOW 2
+#endif
+
+#ifndef AT_EACCESS
+# define AT_EACCESS 4
+#endif
+

 #endif /* _GL_FCNTL_H */
 #endif /* _GL_FCNTL_H */
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index e6db70b..d635e79 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -106,6 +106,15 @@
 # define STDERR_FILENO 2
 #endif

+/* Ensure *_OK functions exist.  */
+#ifndef F_OK
+# define F_OK 0
+# define X_OK 1
+# define W_OK 2
+# define R_OK 4
+#endif
+
+
 /* Declare overridden functions.  */

 #ifdef __cplusplus
@@ -163,6 +172,19 @@ int unlinkat (int fd, char const *file, int flag);
 #endif /* @GNULIB_OPENAT@ */


+#if @GNULIB_FACCESSAT@
+# if address@hidden@
+int faccessat (int fd, char const *file, int mode, int flag);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef faccessat
+# define faccessat(d,n,m,f)                        \
+    (GL_LINK_WARNING ("faccessat is not portable - " \
+                      "use gnulib module faccessat for portability"), \
+     fchownat (d, n, m, f))
+#endif
+
+
 #if @GNULIB_CLOSE@
 # if @REPLACE_CLOSE@
 /* Automatically included by modules that need a replacement for close.  */
diff --git a/m4/faccessat.m4 b/m4/faccessat.m4
new file mode 100644
index 0000000..f21dc13
--- /dev/null
+++ b/m4/faccessat.m4
@@ -0,0 +1,21 @@
+# serial 1
+# See if we need to provide faccessat replacement.
+
+dnl Copyright (C) 2009 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# Written by Eric Blake.
+
+AC_DEFUN([gl_FUNC_FACCESSAT],
+[
+  AC_REQUIRE([gl_FUNC_OPENAT])
+  AC_REQUIRE([gl_FUNC_EUIDACCESS])
+  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+  AC_CHECK_FUNCS_ONCE([access])
+  AC_CHECK_FUNCS_ONCE([faccessat])
+  if test $ac_cv_func_faccessat = no; then
+    HAVE_FACCESSAT=0
+  fi
+])
diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4
index c8e93da..928f5bc 100644
--- a/m4/unistd_h.m4
+++ b/m4/unistd_h.m4
@@ -39,6 +39,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   GNULIB_DUP3=0;             AC_SUBST([GNULIB_DUP3])
   GNULIB_ENVIRON=0;          AC_SUBST([GNULIB_ENVIRON])
   GNULIB_EUIDACCESS=0;       AC_SUBST([GNULIB_EUIDACCESS])
+  GNULIB_FACCESSAT=0;        AC_SUBST([GNULIB_FACCESSAT])
   GNULIB_FCHDIR=0;           AC_SUBST([GNULIB_FCHDIR])
   GNULIB_FSYNC=0;            AC_SUBST([GNULIB_FSYNC])
   GNULIB_FTRUNCATE=0;        AC_SUBST([GNULIB_FTRUNCATE])
@@ -62,6 +63,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   HAVE_DUP2=1;            AC_SUBST([HAVE_DUP2])
   HAVE_DUP3=1;            AC_SUBST([HAVE_DUP3])
   HAVE_EUIDACCESS=1;      AC_SUBST([HAVE_EUIDACCESS])
+  HAVE_FACCESSAT=1;       AC_SUBST([HAVE_FACCESSAT])
   HAVE_FSYNC=1;           AC_SUBST([HAVE_FSYNC])
   HAVE_FTRUNCATE=1;       AC_SUBST([HAVE_FTRUNCATE])
   HAVE_GETDOMAINNAME=1;   AC_SUBST([HAVE_GETDOMAINNAME])
diff --git a/modules/faccessat b/modules/faccessat
new file mode 100644
index 0000000..d7737ba
--- /dev/null
+++ b/modules/faccessat
@@ -0,0 +1,32 @@
+Description:
+faccessat() function: check user's permissions for a file.
+
+Files:
+lib/faccessat.c
+m4/faccessat.m4
+
+Depends-on:
+euidaccess
+extensions
+fcntl-h
+openat
+unistd
+
+configure.ac:
+gl_FUNC_FACCESSAT
+gl_UNISTD_MODULE_INDICATOR([faccessat])
+
+Makefile.am:
+
+Include:
+<fcntl.h>
+<unistd.h>
+
+Link:
+$(LIB_EACCESS)
+
+License:
+GPL
+
+Maintainer:
+Jim Meyering, Eric Blake
diff --git a/modules/unistd b/modules/unistd
index 4c5add7..b48b4b9 100644
--- a/modules/unistd
+++ b/modules/unistd
@@ -32,6 +32,7 @@ unistd.h: unistd.in.h
              -e 's|@''GNULIB_DUP3''@|$(GNULIB_DUP3)|g' \
              -e 's|@''GNULIB_ENVIRON''@|$(GNULIB_ENVIRON)|g' \
              -e 's|@''GNULIB_EUIDACCESS''@|$(GNULIB_EUIDACCESS)|g' \
+             -e 's|@''GNULIB_FACCESSAT''@|$(GNULIB_FACCESSAT)|g' \
              -e 's|@''GNULIB_FCHDIR''@|$(GNULIB_FCHDIR)|g' \
              -e 's|@''GNULIB_FSYNC''@|$(GNULIB_FSYNC)|g' \
              -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \
@@ -55,6 +56,7 @@ unistd.h: unistd.in.h
              -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \
              -e 's|@''HAVE_DUP3''@|$(HAVE_DUP3)|g' \
              -e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \
+             -e 's|@''HAVE_FACCESSAT''@|$(HAVE_FACCESSAT)|g' \
              -e 's|@''HAVE_FCHOWNAT''@|$(HAVE_FCHOWNAT)|g' \
              -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \
              -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
-- 
1.6.3.2








reply via email to

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