From owner-freebsd-questions@FreeBSD.ORG Thu May 12 14:05:08 2005 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 418B416A4CE for ; Thu, 12 May 2005 14:05:08 +0000 (GMT) Received: from fri.itea.ntnu.no (fri.itea.ntnu.no [129.241.7.60]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4D78643D6B for ; Thu, 12 May 2005 14:05:07 +0000 (GMT) (envelope-from svein-freebsd-questions@theloosingend.net) Received: from localhost (localhost [127.0.0.1]) by fri.itea.ntnu.no (Postfix) with ESMTP id 317B97E9C for ; Thu, 12 May 2005 16:05:06 +0200 (CEST) Received: from maren.thelosingend.net (maren.math.ntnu.no [129.241.211.48]) by fri.itea.ntnu.no (Postfix) with SMTP for ; Thu, 12 May 2005 16:05:05 +0200 (CEST) Received: (qmail 84712 invoked by uid 1001); 12 May 2005 14:05:05 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 12 May 2005 14:05:05 -0000 Date: Thu, 12 May 2005 16:05:05 +0200 (CEST) From: Svein Halvor Halvorsen X-X-Sender: sveinhal@maren.thelosingend.net To: Chuck Swiger In-Reply-To: <42824FFA.4080603@mac.com> Message-ID: <20050512155122.U82794@maren.thelosingend.net> References: <20050511165506.GC10213@asu.edu> <428242D7.6040103@mac.com> <20050511174702.GA23222@noisy.compsoc.man.ac.uk> <42824FFA.4080603@mac.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Content-Scanned: with sophos and spamassassin at mailgw.ntnu.no. cc: Lewis Thompson cc: David.Bear@asu.edu cc: questions@freebsd.org Subject: Re: user owned groups X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: questions@freebsd.org List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 May 2005 14:05:08 -0000 * Chuck Swiger [2005-05-11 14:33 -0400] > Otherwise, you only have one default umask. I'm not sure there is a sane way > of changing it depending on which directory you are currently in, but you > might try setting up an alias ("cd77", "cd22"?) which combines setting the > umask and cd'ing. On my system, I keep .umask files lying around which has a umask number in it. Then in the systemwide bashrc file, I have [1; see below]. I have a /.umask file with a 0022 in it, and a 0077 in /home/.umask The function below will traverse the directory tree and try to find a .umask file in any directory in "this" or any higher level. Then it will read the value from the file and apply it to the umask command. If the umask is changing as a result of this, it will print a message stating the current umask, as well as which file was used to decide the current umask. If the umask is either group- or world-writable, a warning is issued. For non-bash users, I have not made an equivalent, and the umask is just set to 0077. I don't think I have any such users though (it's basically just me and my closest family who has access to my server). I think this will work in old style Bourne shells as well, though. [1] DEFUMASK=`umask` cd(){ builtin cd "$@" oldumask=$(printf "%04.0f" `umask`) dir=$PWD found=false while [[ "$dir" != "/" ]] && [[ "$found" != "true" ]] ; do if [ -f "$dir/.umask" ]; then umask `cat $dir/.umask 2>/dev/null` found=true else dir=`dirname "$dir"` fi done [[ "$found" != "true" ]] && umask $DEFUMASK newumask=$(printf "%04.0f" `umask`) if [ "$PS1" != "" ]; then if [[ "$oldumask" -ne "$newumask" ]]; then [[ "$found" == "true" ]] && echo "Using .umask from $dir" echo "umask is `umask` (`umask -S`)" fi [[ "`echo $newumask|cut -c3`" -lt "2" ]] && echo "WARNING: Insecure umask (group-writeable)" [[ "`echo $newumask|cut -c4`" -lt "2" ]] && echo "WARNING: Insecure umask (world-writeable)" fi unset oldumask newumask dir found } pushd(){ builtin pushd "$@" cd "$PWD" } popd(){ builtin popd "$@" cd "$PWD" } cd "$PWD" >/dev/null 2>&1