mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-14 01:00:07 +00:00
* io/sys/stat.h [__USE_GNU]: Declare fchmodat.
* io/fchmodat.c: New file. * io/Makefile (routines): Add fchmodat. * io/Versions (libc: GLIBC_2.4): Likewise. * sysdeps/unix/sysv/linux/fchmodat.c: New file. * io/tst-fchmodat.c: New file. * io/Makefile (tests): Add it.
This commit is contained in:
parent
06dc5bf35a
commit
c90c5d4106
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
2006-01-05 Roland McGrath <roland@redhat.com>
|
||||||
|
|
||||||
|
* io/sys/stat.h [__USE_GNU]: Declare fchmodat.
|
||||||
|
* io/fchmodat.c: New file.
|
||||||
|
* io/Makefile (routines): Add fchmodat.
|
||||||
|
* io/Versions (libc: GLIBC_2.4): Likewise.
|
||||||
|
* sysdeps/unix/sysv/linux/fchmodat.c: New file.
|
||||||
|
* io/tst-fchmodat.c: New file.
|
||||||
|
* io/Makefile (tests): Add it.
|
||||||
|
|
||||||
2006-01-03 Steven Munroe <sjmunroe@us.ibm.com>
|
2006-01-03 Steven Munroe <sjmunroe@us.ibm.com>
|
||||||
|
|
||||||
* sysdeps/powerpc/powerpc32/sysdep.h (ENTRY, EALIGN): Add cfi_startproc
|
* sysdeps/powerpc/powerpc32/sysdep.h (ENTRY, EALIGN): Add cfi_startproc
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright (C) 1992-2002, 2003, 2005 Free Software Foundation, Inc.
|
# Copyright (C) 1992-2002,2003,2005,2006 Free Software Foundation, Inc.
|
||||||
# This file is part of the GNU C Library.
|
# This file is part of the GNU C Library.
|
||||||
|
|
||||||
# The GNU C Library is free software; you can redistribute it and/or
|
# The GNU C Library is free software; you can redistribute it and/or
|
||||||
@ -35,7 +35,8 @@ routines := \
|
|||||||
fxstatat fxstatat64 \
|
fxstatat fxstatat64 \
|
||||||
statfs fstatfs statfs64 fstatfs64 \
|
statfs fstatfs statfs64 fstatfs64 \
|
||||||
statvfs fstatvfs statvfs64 fstatvfs64 \
|
statvfs fstatvfs statvfs64 fstatvfs64 \
|
||||||
umask chmod fchmod lchmod mkdir mkdirat \
|
umask chmod fchmod lchmod fchmodat \
|
||||||
|
mkdir mkdirat \
|
||||||
open open64 openat openat64 close \
|
open open64 openat openat64 close \
|
||||||
read write lseek lseek64 access euidaccess \
|
read write lseek lseek64 access euidaccess \
|
||||||
fcntl flock lockf lockf64 \
|
fcntl flock lockf lockf64 \
|
||||||
@ -63,7 +64,7 @@ test-srcs := ftwtest
|
|||||||
tests := test-utime test-stat test-stat2 test-lfs tst-getcwd \
|
tests := test-utime test-stat test-stat2 test-lfs tst-getcwd \
|
||||||
tst-fcntl bug-ftw1 bug-ftw2 bug-ftw3 bug-ftw4 tst-statvfs \
|
tst-fcntl bug-ftw1 bug-ftw2 bug-ftw3 bug-ftw4 tst-statvfs \
|
||||||
tst-openat tst-unlinkat tst-fstatat tst-futimesat \
|
tst-openat tst-unlinkat tst-fstatat tst-futimesat \
|
||||||
tst-renameat tst-fchownat
|
tst-renameat tst-fchownat tst-fchmodat
|
||||||
|
|
||||||
distribute := ftwtest-sh
|
distribute := ftwtest-sh
|
||||||
|
|
||||||
|
@ -98,6 +98,7 @@ libc {
|
|||||||
nftw; nftw64;
|
nftw; nftw64;
|
||||||
}
|
}
|
||||||
GLIBC_2.4 {
|
GLIBC_2.4 {
|
||||||
|
fchmodat;
|
||||||
fchownat;
|
fchownat;
|
||||||
__fxstatat; __fxstatat64;
|
__fxstatat; __fxstatat64;
|
||||||
linkat;
|
linkat;
|
||||||
|
50
io/fchmodat.c
Normal file
50
io/fchmodat.c
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/* Change the protections of file relative to open directory. Stub version.
|
||||||
|
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library 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
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
fchmodat (fd, file, mode, flag)
|
||||||
|
int fd;
|
||||||
|
const char *file;
|
||||||
|
mode_t mode;
|
||||||
|
int flag;
|
||||||
|
{
|
||||||
|
if (file == NULL || (flag & ~AT_SYMLINK_NOFOLLOW) != 0)
|
||||||
|
{
|
||||||
|
__set_errno (EINVAL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fd < 0 && fd != AT_FDCWD)
|
||||||
|
{
|
||||||
|
__set_errno (EBADF);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
__set_errno (ENOSYS);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
stub_warning (fchownat)
|
||||||
|
|
||||||
|
#include <stub-tag.h>
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 1991,1992,1995-2004,2005 Free Software Foundation, Inc.
|
/* Copyright (C) 1991,1992,1995-2004,2005,2006 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
The GNU C Library is free software; you can redistribute it and/or
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
@ -293,6 +293,14 @@ extern int lchmod (__const char *__file, __mode_t __mode)
|
|||||||
extern int fchmod (int __fd, __mode_t __mode) __THROW;
|
extern int fchmod (int __fd, __mode_t __mode) __THROW;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __USE_GNU
|
||||||
|
/* Set file access permissions of FILE relative to
|
||||||
|
the directory FD is open on. */
|
||||||
|
extern int fchmodat (int __fd, __const char *__file, __mode_t mode, int __flag)
|
||||||
|
__THROW __nonnull ((2)) __wur;
|
||||||
|
#endif /* Use GNU. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Set the file creation mask of the current process to MASK,
|
/* Set the file creation mask of the current process to MASK,
|
||||||
and return the old creation mask. */
|
and return the old creation mask. */
|
||||||
|
146
io/tst-fchmodat.c
Normal file
146
io/tst-fchmodat.c
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
/* Test for fchmodat function. */
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
|
static void prepare (void);
|
||||||
|
#define PREPARE(argc, argv) prepare ()
|
||||||
|
|
||||||
|
static int do_test (void);
|
||||||
|
#define TEST_FUNCTION do_test ()
|
||||||
|
|
||||||
|
#include "../test-skeleton.c"
|
||||||
|
|
||||||
|
static int dir_fd;
|
||||||
|
|
||||||
|
static void
|
||||||
|
prepare (void)
|
||||||
|
{
|
||||||
|
size_t test_dir_len = strlen (test_dir);
|
||||||
|
static const char dir_name[] = "/tst-fchmodat.XXXXXX";
|
||||||
|
|
||||||
|
size_t dirbuflen = test_dir_len + sizeof (dir_name);
|
||||||
|
char *dirbuf = malloc (dirbuflen);
|
||||||
|
if (dirbuf == NULL)
|
||||||
|
{
|
||||||
|
puts ("out of memory");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf (dirbuf, dirbuflen, "%s%s", test_dir, dir_name);
|
||||||
|
if (mkdtemp (dirbuf) == NULL)
|
||||||
|
{
|
||||||
|
puts ("cannot create temporary directory");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
add_temp_file (dirbuf);
|
||||||
|
|
||||||
|
dir_fd = open (dirbuf, O_RDONLY | O_DIRECTORY);
|
||||||
|
if (dir_fd == -1)
|
||||||
|
{
|
||||||
|
puts ("cannot open directory");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
do_test (void)
|
||||||
|
{
|
||||||
|
/* fdopendir takes over the descriptor, make a copy. */
|
||||||
|
int dupfd = dup (dir_fd);
|
||||||
|
if (dupfd == -1)
|
||||||
|
{
|
||||||
|
puts ("dup failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (lseek (dupfd, 0, SEEK_SET) != 0)
|
||||||
|
{
|
||||||
|
puts ("1st lseek failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The directory should be empty save the . and .. files. */
|
||||||
|
DIR *dir = fdopendir (dupfd);
|
||||||
|
if (dir == NULL)
|
||||||
|
{
|
||||||
|
puts ("fdopendir failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
struct dirent64 *d;
|
||||||
|
while ((d = readdir64 (dir)) != NULL)
|
||||||
|
if (strcmp (d->d_name, ".") != 0 && strcmp (d->d_name, "..") != 0)
|
||||||
|
{
|
||||||
|
printf ("temp directory contains file \"%s\"\n", d->d_name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
closedir (dir);
|
||||||
|
|
||||||
|
umask (022);
|
||||||
|
|
||||||
|
/* Try to create a file. */
|
||||||
|
int fd = openat (dir_fd, "some-file", O_CREAT|O_RDWR|O_EXCL, 0666);
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
if (errno == ENOSYS)
|
||||||
|
{
|
||||||
|
puts ("*at functions not supported");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
puts ("file creation failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
write (fd, "hello", 5);
|
||||||
|
puts ("file created");
|
||||||
|
|
||||||
|
struct stat64 st1;
|
||||||
|
if (fstat64 (fd, &st1) != 0)
|
||||||
|
{
|
||||||
|
puts ("fstat64 failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
close (fd);
|
||||||
|
|
||||||
|
if ((st1.st_mode & 0777) != 0644)
|
||||||
|
{
|
||||||
|
printf ("openat created mode %04o, not 0644\n", (st1.st_mode & 0777));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fchmodat (dir_fd, "some-file", 0400, 0) != 0)
|
||||||
|
{
|
||||||
|
puts ("fchownat failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct stat64 st2;
|
||||||
|
if (fstatat64 (dir_fd, "some-file", &st2, 0) != 0)
|
||||||
|
{
|
||||||
|
puts ("fstatat64 failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((st2.st_mode & 0777) != 0400)
|
||||||
|
{
|
||||||
|
puts ("mode change failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unlinkat (dir_fd, "some-file", 0) != 0)
|
||||||
|
{
|
||||||
|
puts ("unlinkat failed");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
close (dir_fd);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
87
sysdeps/unix/sysv/linux/fchmodat.c
Normal file
87
sysdeps/unix/sysv/linux/fchmodat.c
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/* Change the protections of file relative to open directory. Linux version.
|
||||||
|
Copyright (C) 2006 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library 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
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <alloca.h>
|
||||||
|
#include <sysdep.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
fchmodat (fd, file, mode, flag)
|
||||||
|
int fd;
|
||||||
|
const char *file;
|
||||||
|
mode_t mode;
|
||||||
|
int flag;
|
||||||
|
{
|
||||||
|
if (flag & ~AT_SYMLINK_NOFOLLOW)
|
||||||
|
{
|
||||||
|
__set_errno (EINVAL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#ifndef __NR_lchmod /* Linux so far has no lchmod syscall. */
|
||||||
|
if (flag & AT_SYMLINK_NOFOLLOW)
|
||||||
|
{
|
||||||
|
__set_errno (ENOTSUP);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char *buf = NULL;
|
||||||
|
|
||||||
|
if (fd != AT_FDCWD && file[0] != '/')
|
||||||
|
{
|
||||||
|
size_t filelen = strlen (file);
|
||||||
|
static const char procfd[] = "/proc/self/fd/%d/%s";
|
||||||
|
/* Buffer for the path name we are going to use. It consists of
|
||||||
|
- the string /proc/self/fd/
|
||||||
|
- the file descriptor number
|
||||||
|
- the file name provided.
|
||||||
|
The final NUL is included in the sizeof. A bit of overhead
|
||||||
|
due to the format elements compensates for possible negative
|
||||||
|
numbers. */
|
||||||
|
size_t buflen = sizeof (procfd) + sizeof (int) * 3 + filelen;
|
||||||
|
buf = alloca (buflen);
|
||||||
|
|
||||||
|
__snprintf (buf, buflen, procfd, fd, file);
|
||||||
|
file = buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
int result;
|
||||||
|
INTERNAL_SYSCALL_DECL (err);
|
||||||
|
|
||||||
|
#ifdef __NR_lchmod
|
||||||
|
if (flag & AT_SYMLINK_NOFOLLOW)
|
||||||
|
result = INTERNAL_SYSCALL (lchmod, err, 2, file, mode);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
result = INTERNAL_SYSCALL (chmod, err, 2, file, mode);
|
||||||
|
|
||||||
|
if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 0))
|
||||||
|
{
|
||||||
|
__atfct_seterrno (INTERNAL_SYSCALL_ERRNO (result, err), fd, buf);
|
||||||
|
result = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user