From owner-freebsd-questions@FreeBSD.ORG Sun Dec 28 00:17:47 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B5E851065674 for ; Sun, 28 Dec 2008 00:17:47 +0000 (UTC) (envelope-from fbsd.questions@rachie.is-a-geek.net) Received: from mail.rachie.is-a-geek.net (rachie.is-a-geek.net [66.230.99.27]) by mx1.freebsd.org (Postfix) with ESMTP id 7B9068FC17 for ; Sun, 28 Dec 2008 00:17:47 +0000 (UTC) (envelope-from fbsd.questions@rachie.is-a-geek.net) Received: from localhost (mail.rachie.is-a-geek.net [192.168.2.101]) by mail.rachie.is-a-geek.net (Postfix) with ESMTP id A292BAFC201; Sat, 27 Dec 2008 15:17:46 -0900 (AKST) From: Mel To: freebsd-questions@freebsd.org Date: Sat, 27 Dec 2008 15:17:46 -0900 User-Agent: KMail/1.9.10 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200812271517.46409.fbsd.questions@rachie.is-a-geek.net> Cc: Mitar Subject: Re: Open with O_APPEND fails X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Dec 2008 00:17:47 -0000 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 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 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.