From nobody@FreeBSD.org  Mon Jan  1 04:00:54 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 2C89037B400
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  1 Jan 2001 04:00:54 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.1/8.11.1) id f01C0sX92024;
	Mon, 1 Jan 2001 04:00:54 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200101011200.f01C0sX92024@freefall.freebsd.org>
Date: Mon, 1 Jan 2001 04:00:54 -0800 (PST)
From: jau@iki.fi
Sender: nobody@FreeBSD.org
To: freebsd-gnats-submit@FreeBSD.org
Subject: access(2) system call reports an immutable file as writable
X-Send-Pr-Version: www-1.0

>Number:         23990
>Category:       kern
>Synopsis:       access(2) system call reports an immutable file as writable
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan 01 04:10:01 PST 2001
>Closed-Date:    Fri Mar 23 15:25:52 PST 2001
>Last-Modified:  Fri Mar 23 15:36:01 PST 2001
>Originator:     Jukka A. Ukkonen
>Release:        3.5.1
>Organization:
Finnish UNIX Users' Group
>Environment:
FreeBSD mjolnir.thunderbolt.fi 3.5.1-RELEASE FreeBSD 3.5.1-RELEASE #2: Mon Oct 16 13:00:59 EET DST 2000     jau@mjolnir.thunderbolt.fi:/usr/src/sys/compile/Mjolnir  i386

>Description:
The access(2) system call reports an immutable file as writable
though the reasonable approach would be to report "not writable".

This is a problem for programs that rely on accept(2) providing
them correct information about the accessibilty of files.
Especially when someone wants to quickly review one's files'
accessibility with a program like access(1) the current behaviour
produces misleading results and is logically in contradiction with
reporting files on read-only mounted file systems as "not writable".

Currently the only way to really know whether writing is OK or not
is by trying to open the file for writing.

>How-To-Repeat:
# touch testfile
# chflags uchg testfile
# access -w testfile


>Fix:
Should be relatively straight forward by adding
a VOP_GETATTR(vp, &va, p->p_ucred, p) call and
(va.va_flags & IMMUTABLE) test to access(2).


>Release-Note:
>Audit-Trail:

From: Daniel Hagan <dhagan@colltech.com>
To: freebsd-gnats-submit@FreeBSD.org, jau@iki.fi
Cc:  
Subject: Re: kern/23990: access(2) system call reports an immutable file as 
 writable
Date: Wed, 03 Jan 2001 16:36:02 -0500

 temp.c ----
 #include <unistd.h>
 main() {
   printf("%d\n", access("blah", W_OK));
 }
 -----> compiled into a.out
 
 % touch blah
 % chflags uchg blah
 % ls -lo
 -rw-------  1 dhagan  dhagan  uchg    0 Jan  3 16:30 blah
 % ./a.out 
 -1
 % chflags nouchg blah
 % ./a.out
 0
 
 Seems to work ok to me.  Maybe this was a problem in 3.5.1.  I'd try
 upgrading to the 4.x branch.
 
 Daniel
 
State-Changed-From-To: open->closed 
State-Changed-By: mpp 
State-Changed-When: Fri Mar 23 15:25:52 PST 2001 
State-Changed-Why:  
I've verified that the access(2) system call returns the correct value 
when testing if immutable files can be written.  I tested on 4.0,  
4.2-stable, and 5.0-current.   

I think you may not have been confused about how the "access" command  
was working (the one I've got on my system was installed as part of the  
teTeX port).  It appears to just be a very stripped down version of 
the "test" command.  Here is output from a session: 

Script started on Fri Mar 23 17:19:33 2001 
acme 1%	touch testfile 
acme 2%	access -w testfile 
acme 3%	echo $status 
0 
acme 4%	chflags uchg testfile 
acme 5%	access -w testfile 
acme 6%	echo $status 
1 
acme 7%	exit 
exit 

Script done on Fri Mar 23 17:20:04 2001 

Note that the command doesn't output any messages if access to the 
file is not allowed. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=23990 
>Unformatted:
