Date: Sat, 27 Dec 2008 15:17:46 -0900 From: Mel <fbsd.questions@rachie.is-a-geek.net> To: freebsd-questions@freebsd.org Cc: Mitar <mmitar@gmail.com> Subject: Re: Open with O_APPEND fails Message-ID: <200812271517.46409.fbsd.questions@rachie.is-a-geek.net> In-Reply-To: <f63c4b2d0812271246u18a881e6j87e0054c24f4661a@mail.gmail.com> References: <f63c4b2d0812271246u18a881e6j87e0054c24f4661a@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Saturday 27 December 2008 11:46:03 Mitar wrote: > Hi! > > I discovered that open syscall with only O_APPEND fails with > "permission denied" if an user does not have rights to write to a file > (what is normal) even if it is root (what is a surprise). For example, > if I have a file owned by www:www and with 644 permissions root cannot > do open("testfile", O_APPEND) call. If I change ownership of I change > permission to for example 666, call succeedes. > > This works on Linux (Debian). So this is a feature? Or a bug? > > (I discovered that because htpasswd failed to add new > username/password pair (ran as root) to a file owner by www.) > > Checked on FreeBSD 7.0-STABLE. Can't reproduce: $ ls -al test.txt -rw-r--r-- 1 www www 33 Dec 27 15:12 test.txt $ sudo ./open test.txt opened as fd 3 $ cat test.txt this file cannot be appended to $ cat -n open.c 1 #include <sys/types.h> 2 #include <sys/uio.h> 3 #include <unistd.h> 4 #include <stdio.h> 5 #include <fcntl.h> 6 #include <err.h> 7 #include <sysexits.h> 8 9 int main(void) 10 { 11 const char fname[] = "test.txt"; 12 const char txt[] = "cannot be appended to\n"; 13 int fd; 14 15 fd = open(fname, O_WRONLY|O_APPEND); 16 if( fd < 0 ) 17 err(EX_NOINPUT, "Failed to open %s", fname); 18 19 printf("%s opened as fd %i\n", fname, fd); 20 if( write(fd, txt, sizeof(txt)) < 0 ) 21 err(EX_DATAERR, "write()"); 22 close(fd); 23 return EX_OK; 24 } -- Mel Problem with today's modular software: they start with the modules and never get to the software part.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200812271517.46409.fbsd.questions>