Dear Jean-Pierre,
I found this while trying to build the current release of coreutils
on an NTFS partition created with mkntfs v1.13.1 mounted with 1.2216SC.2,
as NTFS 3.1 (but also with an old NTFS 1.2 partition):
: Version 1.2216SC.2 integrated FUSE 27
: Mounted /md1-ntfs/ntfs-new.img (Read-Write, label "", NTFS 3.1)
: Cmdline options: dev,suid
: Mount options:
dev,suid,silent,allow_other,nonempty,relatime,noatime,fsname=/md1-ntfs/ntfs-new.img
: User mapping built
Step 1:
su some-non-root-user-which-is-in-UserMapping
Step 2:
$ wget http://ftp.gnu.org/gnu/coreutils/coreutils-6.10.tar.gz
$ LC_ALL=C strace -efile tar xvfz coreutils-6.10.tar.gz coreutils-6.10/man/ls.1
Result:
execve("/bin/tar", ["tar", "xvfz", "coreutils-6.10.tar.gz",
"coreutils-6.10/man/ls.1"], [/* 64 vars */]) = 0
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
open("/lib64/librt.so.1", O_RDONLY) = 3
open("/lib64/libc.so.6", O_RDONLY) = 3
open("/lib64/libpthread.so.0", O_RDONLY) = 3
coreutils-6.10/man/ls.1
open("coreutils-6.10/man/ls.1", O_WRONLY|O_CREAT|O_EXCL, 0444) = -1 EEXIST
(File exists)
unlink("coreutils-6.10/man/ls.1") = 0
open("coreutils-6.10/man/ls.1", O_WRONLY|O_CREAT|O_EXCL, 0444) = -1 EACCES
(Permission denied)
tar: coreutils-6.10/man/ls.1: Cannot open: Permission denied
ls -l coreutils-6.10/man/ls.1
-r--r--r-- 1 abuild 99 0 2008-03-08 23:06 coreutils-6.10/man/ls.1
tar --version
tar (GNU tar) 1.15.1
Normally, an failed open() should not create an empty file.
On ext3, the command works as expected and the whole archive can be extracted.
The what minium flags which trigger the issue are:
open(".create444.test", O_WRONLY|O_CREAT, 0444);
O_CREAT is neccesary to create the file (it may not extist to thrigger the
issue)
O_WRONLY seems to conflict with 0444 (no write permissions) in the current code.
I guess that the operation is executed in two steps:
1st: Create the file with mode 444 (this succeeds, the file is created with 444)
2nd: Open the the file with O_WRONLY (fails as it need require write permission)
But, as this syscall creates the file and opens the newly created file aa-same-
time, it should be able to create it with any permission it wants and still be
able to write to it.
I verified by compiling the latest version of GNU tar and it works the same:
http://ftp.gnu.org/gnu/tar/tar-1.19.tar.bz2
I attached a testcase which does a few other tests as well so we can use
it for debugging and testing, current output as mapped user is:
/tmp/create444
1 Expected: Success, got: Permission denied
2 Expected: Success, got: File exists
2 errors
Bernhard#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
main() {
int fd, errors = 0;
unlink(".create444.test");
if (errno && errno != ENOENT) {
perror("unlinking failed");
return 5;
}
umask(0022);
// Create the file with WRITE-only but mode 444:
fd = open(".create444.test", O_WRONLY|O_CREAT, 0444);
if (fd < 0) {
perror("1 Expected: Success, got");
errors++;
} else
unlink(".create444.test");
// At this point, the test file should not be present
// This is just a test wether an error on the last open
// created the file nonetheless...:
fd = open(".create444.test", O_CREAT|O_EXCL, 0444);
if (fd < 0) {
perror("2 Expected: Success, got");
errors++;
}
// Now that we don't delete it, expect EEXIST here:
errno = 0;
fd = open(".create444.test", O_WRONLY|O_CREAT, 0444);
//fd = open(".create444.test", O_CREAT|O_EXCL, 0444);
if (errno =! EEXIST) {
perror("3 Expected: File exists, got");
errors++;
}
// We expect to be able to read:
fd = open(".create444.test", O_RDONLY);
if (fd < 0) {
perror("4 Expected: Success, got");
errors++;
}
// We expect to be not able to write:
errno = 0;
fd = open(".create444.test", O_WRONLY);
if (errno != EACCES) {
perror("5 Expected: Permission denied, got");
errors++;
}
unlink(".create444.test");
printf("%d errors\n", errors);
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
ntfs-3g-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ntfs-3g-devel