diff options
author | Jim Meyering <jim@meyering.net> | 2006-12-24 17:08:04 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2006-12-24 17:08:04 +0000 |
commit | 242003f6553e03889f917462948dbb1a9fd83342 (patch) | |
tree | 9b7bafcc02ff9cd6f4fcae9d51d9b28834bbaaf6 /lib/fchownat.c | |
parent | 69689592b0dc73378f568297d86bd1cb139b6553 (diff) | |
download | gnulib-242003f6553e03889f917462948dbb1a9fd83342.tar.gz |
Work around an fchownat bug in glibc-2.4:
http://lists.ubuntu.com/archives/ubuntu-users/2006-September/093218.html
This bug would cause "chown -RP ... DIR" to follow symlinks in DIR,
in spite of the -P option.
* m4/openat.m4 (gl_FUNC_FCHOWNAT, gl_FUNC_FCHOWNAT_DEREF_BUG):
New macros.
(gl_PREREQ_OPENAT): Require gl_FUNC_FCHOWNAT.
* modules/openat (Files): Add lib/fchownat.c.
* lib/openat.c (fchownat): Don't define here. Move to...
* lib/fchownat.c: ...this new file.
Diffstat (limited to 'lib/fchownat.c')
-rw-r--r-- | lib/fchownat.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/fchownat.c b/lib/fchownat.c new file mode 100644 index 0000000000..382ed7bc14 --- /dev/null +++ b/lib/fchownat.c @@ -0,0 +1,49 @@ +/* This function serves as replacement for a missing fchownat function, + as well as a work around for the fchownat bug in glibc-2.4: + <http://lists.ubuntu.com/archives/ubuntu-users/2006-September/093218.html> + when the buggy fchownat-with-AT_SYMLINK_NOFOLLOW operates on a symlink, it + mistakenly affects the symlink referent, rather than the symlink itself. + + Copyright (C) 2006 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 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* written by Jim Meyering */ + +#include <config.h> + +#include "openat.h" + +#include <unistd.h> + +#include "dirname.h" /* solely for definition of IS_ABSOLUTE_FILE_NAME */ +#include "save-cwd.h" +#include "openat-priv.h" + +/* Replacement for Solaris' function by the same name. + Invoke chown or lchown on file, FILE, using OWNER and GROUP, in the + directory open on descriptor FD. If FLAG is AT_SYMLINK_NOFOLLOW, then + use lchown, otherwise, use chown. 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. */ + +#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_POST_FILE_PARAM_DECLS , uid_t owner, gid_t group, int flag +#define AT_FUNC_POST_FILE_ARGS , owner, group +#include "at-func.c" |