From nobody@FreeBSD.ORG  Fri Jan 28 08:04:30 2000
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id 28D8615CA5; Fri, 28 Jan 2000 08:04:30 -0800 (PST)
Message-Id: <20000128160430.28D8615CA5@hub.freebsd.org>
Date: Fri, 28 Jan 2000 08:04:30 -0800 (PST)
From: ichimura@shimada.nuee.nagoya-u.ac.jp
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@FreeBSD.org
Subject: newfs always make root's / directory
X-Send-Pr-Version: www-1.0

>Number:         16422
>Category:       bin
>Synopsis:       [patch] [request] newfs(8) always make root's / directory
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 28 08:10:04 PST 2000
>Closed-Date:    
>Last-Modified:  Mon Sep 13 14:54:49 UTC 2010
>Originator:     Ichimura Kazuhito
>Release:        3.3-Release
>Organization:
Nagoya University
>Environment:
FreeBSD cados20 3.3-RELEASE FreeBSD 3.3-RELEASE #2: Mon Jan 24 01:33:14 JST 2000     ichimura@cados20:/usr/src/sys/compile/cados20  i386

>Description:
I want to use removable disk. And root mount it using "amd" command.
So I run "newfs" command.

But created / directry's owner is not me but root(uid 0).
group is wheel(gid 0), too.
And permition is always 755.
So I couldn't write my disk...

Is this FreeBSD's policy or Bug?
>How-To-Repeat:
root# chmod 666 /dev/SOMEDISK*
root# su foo
foo%  newfs /dev/SOMEDISK
foo%  exit
root# mount /dev/SOMEDISK /SOMEWHERE
root# ls -ld /SOMEWHERE
drwxr-xr-x  2 root  wheel  512 Jan 29 00:45 /SOMEWHERE/
>Fix:
Is is patch for /usr/src/sbin/newfs/mkfs.c
It is very short.

*** mkfs.c.orig	Mon Aug 30 00:14:52 1999
--- mkfs.c	Sat Jan 29 00:55:41 2000
***************
*** 981,987 ****
  	if (mfs)
  		node.di_mode = IFDIR | 01777;
  	else
! 		node.di_mode = IFDIR | UMASK;
  	node.di_nlink = PREDEFDIR;
  	if (Oflag)
  		node.di_size = makedir((struct direct *)oroot_dir, PREDEFDIR);
--- 981,994 ----
  	if (mfs)
  		node.di_mode = IFDIR | 01777;
  	else
! 	{
! 		mode_t mask;
! 		mask = umask( UMASK );
! 		umask( mask );
! 		node.di_mode = IFDIR | (0777&~mask);
! 	}
! 	node.di_uid = getuid();
! 	node.di_gid = getgid();
  	node.di_nlink = PREDEFDIR;
  	if (Oflag)
  		node.di_size = makedir((struct direct *)oroot_dir, PREDEFDIR);


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: dd 
State-Changed-When: Sat Jun 16 20:07:53 PDT 2001 
State-Changed-Why:  
newfs shouldn't leave artifacts of the current environment lying around. 
Besides, you can always use chown after newfs/mount.  E-mail questions@ 
if you're not sure how to do that. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=16422 

From: Adrian Filipi-Martin <adrian@ubergeeks.com>
To: freebsd-gnats-submit@FreeBSD.org,
	<ichimura@shimada.nuee.nagoya-u.ac.jp>
Cc:  
Subject: Re: bin/16422: newfs always make root's / directory
Date: Wed, 16 Jan 2002 20:18:44 -0500 (EST)

 Hi folks,
 
 	I know this PR is closed, but the fundamental need is real.
 Having newfs always produce a root:wheel owned directory is contrary to
 user mounts (sysctl vfs.usermount=1) facility.
 
 	We use user mounts to provide desktop users access to the local
 devices (floppy and cd-rom).  The users presently either need root
 privileges to chown a newfs'd floppy or then need to get one of our admins
 to do it.  This need is required by the default ownership of the filesystem
 root after newfs fnishes.
 
 	The attached diffs make newfs's behavior more compatible with user
 mounts.  To defeat this new behavior, the -R flag is provided.  If people
 do not like this being the default, I'd still like to see the -R flag, but
 with its logic reversed to enable the behavior.
 
 	Adrian
 --
 [ adrian@ubergeeks.com ]
 
 
 --- mkfs.c.orig	Fri Dec 21 23:33:36 2001
 +++ mkfs.c	Wed Jan 16 19:16:01 2002
 @@ -95,6 +95,7 @@
  extern struct stat mfs_mtstat;	/* stat prior to mount          */
  extern int	Nflag;		/* run mkfs without writing file system */
  extern int	Oflag;		/* format as an 4.3BSD file system */
 +extern int	Rflag;		/* Always set the root directory root:wheel */
  extern int	Uflag;		/* enable soft updates for file system */
  extern int	fssize;		/* file system size */
  extern int	ntracks;	/* # tracks/cylinder */
 @@ -1010,8 +1011,17 @@
  	 */
  	if (mfs)
  		node.di_mode = IFDIR | 01777;
 -	else
 -		node.di_mode = IFDIR | UMASK;
 +	else {
 +		if (Rflag || (getuid() == 0) ) {
 +			node.di_mode = IFDIR | UMASK;
 +		} else {
 +			mode_t mask = umask(0);
 +			umask(mask);
 +			node.di_mode = IFDIR | (0777 & ~mask);
 +			node.di_uid = getuid();
 +			node.di_gid = getgid();
 +		}
 +	}
  	node.di_nlink = PREDEFDIR;
  	if (Oflag)
  		node.di_size = makedir((struct direct *)oroot_dir, PREDEFDIR);
 --- newfs.8.orig	Fri Dec 21 23:33:36 2001
 +++ newfs.8	Wed Jan 16 20:00:04 2002
 @@ -41,7 +41,7 @@
  .Nd construct a new file system
  .Sh SYNOPSIS
  .Nm
 -.Op Fl NOU
 +.Op Fl NORU
  .Op Fl S Ar sector-size
  .Op Fl T Ar disktype
  .Op Fl a Ar maxcontig
 @@ -101,7 +101,16 @@
  In fact, it need not even be special.)
  Typically the defaults are reasonable, however
  .Nm
 -has numerous options to allow the defaults to be selectively overridden.
 +has numerous options to allow the defaults to be selectively
 +overridden.  The default owner and group of the root directory of
 +the formatted device is the same as that of the user issuing the
 +.Nm newfs
 +command, and the default mode is modified by the user's umask
 +setting, unless
 +.Nm newfs
 +is run by root, in which case
 +.Fl R
 +flag is assumed.
  .Pp
  .Nm Mount_mfs
  is used to build a file system in virtual memory and then mount it
 @@ -148,6 +157,12 @@
  format filesystem.
  This options is primarily used to build root filesystems
  that can be understood by older boot ROMs.
 +.It Fl R
 +Use the traditional behavior when setting the owner, group and mode
 +for the root directory on the newly formated device.  i.e. Set it
 +to root and wheel with the mode u=rwx,go=rx, rather than using the
 +current user's UID, GID and umask, if not running as root.  This
 +option is enabled implicitly if the user is root.
  .It Fl T
  Use information for the specified disk from
  .Pa /etc/disktab
 --- newfs.c.orig	Fri Dec 21 23:33:36 2001
 +++ newfs.c	Wed Jan 16 18:35:46 2002
 @@ -170,6 +170,7 @@
  struct stat mfs_mtstat;		/* stat prior to mount		*/
  int	Nflag;			/* run without writing file system */
  int	Oflag;			/* format as an 4.3BSD file system */
 +int	Rflag;			/* Always set the root directory root:wheel */
  int	Uflag;			/* enable soft updates for file system */
  int	fssize;			/* file system size */
  int	ntracks = NTRACKS;	/* # tracks/cylinder */
 @@ -250,7 +251,7 @@
 
  	opstring = mfs ?
  	    "NF:T:Ua:b:c:d:e:f:g:h:i:m:o:s:" :
 -	    "NOS:T:Ua:b:c:d:e:f:g:h:i:k:l:m:n:o:p:r:s:t:u:vx:";
 +	    "NORS:T:Ua:b:c:d:e:f:g:h:i:k:l:m:n:o:p:r:s:t:u:vx:";
  	while ((ch = getopt(argc, argv, opstring)) != -1)
  		switch (ch) {
  		case 'N':
 @@ -258,6 +259,9 @@
  			break;
  		case 'O':
  			Oflag = 1;
 +			break;
 +		case 'R':
 +			Rflag = 1;
  			break;
  		case 'S':
  			if ((sectorsize = atoi(optarg)) <= 0)
 
State-Changed-From-To: closed->open 
State-Changed-By: arundel 
State-Changed-When: Mon Sep 13 14:53:21 UTC 2010 
State-Changed-Why:  
It's time to re-evaluate this request imo. 

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