From owner-freebsd-questions Wed Nov 10 10:57:43 1999 Delivered-To: freebsd-questions@freebsd.org Received: from timingpdc.timing.com (timingpdc.timing.com [206.168.13.194]) by hub.freebsd.org (Postfix) with ESMTP id 2625E14E16 for ; Wed, 10 Nov 1999 10:57:33 -0800 (PST) (envelope-from jhein@timing.com) Received: from taz.timing.com ([206.168.13.210]) by timingpdc.timing.com (Post.Office MTA v3.1.2 release (PO205-101c) ID# 103-49575U100L2S100) with ESMTP id AAA444; Wed, 10 Nov 1999 11:58:21 -0700 Received: (from jhein@localhost) by taz.timing.com (8.8.7/8.8.7) id LAA11467; Wed, 10 Nov 1999 11:57:24 -0700 X-Authentication-Warning: taz.timing.com: jhein set sender to jhein@taz.timing.com using -f MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <14377.49172.154829.498969@taz.timing.com> Date: Wed, 10 Nov 1999 11:57:24 -0700 (MST) From: "John E. Hein" To: Michael Kennett Cc: keith@mail.telestream.com, freebsd-questions@freebsd.org Subject: Re: Testing file permissions In-Reply-To: <199911101849.CAA12198@laurasia.com.au> References: <199911101849.CAA12198@laurasia.com.au> X-Mailer: VM 6.75 under Emacs 20.4.1 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Michael Kennett wrote at 02:49 +0800 on Nov 11: > > You can just test the file attributes... > > > > -d file exists and is a directory > > -e file exists > > -f file exists and is a regular file > > -r you have read permissions on the file > > -s file exists and is not empy > > -w You have write permisions on the file > > -x You have execute permissions on the file > > -O You own the file > > -G Files group IS matches yours > ^^^^^ (Note these!) > > That is not quite what I want to do. These tests (and their results) apply > to the user/group id of the process conducting the test. > > What I'd like to determine is the user/group that owns the file, and what > the three different levels of access (world/group/user) are. In other > words, rather than finding out if the *current* process can access the > file, I'd like to know (in the script) what the full mode of the access > to the file is. How's your perl? ... see perlfunc(1) man page, and look for the stat function. Or use stat(2) in a small C program and call it from your script. It sounds like the former would be best for your purpose. Here's a sample snippet . . # get permissions ($dev,$ino,$mode) = stat($filename); # user execute bit set? printf "mode & 0100: 0%o\n", $mode & 0100; . . To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message