From sttng359@alzatex.com  Tue Jun  7 11:50:44 2005
Return-Path: <sttng359@alzatex.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id D8BD216A41C
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  7 Jun 2005 11:50:44 +0000 (GMT)
	(envelope-from sttng359@alzatex.com)
Received: from hosea.tallye.com (joel.tallye.com [216.99.199.78])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 6C3CD43D4C
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  7 Jun 2005 11:50:44 +0000 (GMT)
	(envelope-from sttng359@alzatex.com)
Received: from fbsd.ddns.alzatex.cc (fbsd.ddns.alzatex.cc [192.168.1.37])
	by hosea.tallye.com (8.12.8/8.12.10) with ESMTP id j57BohDV014139
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 7 Jun 2005 04:50:43 -0700
Received: from fbsd.ddns.alzatex.cc (localhost [127.0.0.1])
	by fbsd.ddns.alzatex.cc (8.13.3/8.13.3) with ESMTP id j57Bsc60001527
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 7 Jun 2005 04:54:38 -0700 (PDT)
	(envelope-from sttng359@fbsd.ddns.alzatex.cc)
Received: (from sttng359@localhost)
	by fbsd.ddns.alzatex.cc (8.13.3/8.13.3/Submit) id j57BscEW001526;
	Tue, 7 Jun 2005 04:54:38 -0700 (PDT)
	(envelope-from sttng359)
Message-Id: <200506071154.j57BscEW001526@fbsd.ddns.alzatex.cc>
Date: Tue, 7 Jun 2005 04:54:38 -0700 (PDT)
From: "Loren M. Lang" <lorenl@alzatex.com>
Reply-To: "Loren M. Lang" <lorenl@alzatex.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] mount_msdosfs When a mask, but no dirmask specified, add X bits to dirmask.
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         81989
>Category:       bin
>Synopsis:       [patch] mount_msdosfs(8): when a mask, but no dirmask specified, add X bits to dirmask.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jun 07 12:00:57 GMT 2005
>Closed-Date:    Sat Jan 27 18:36:53 GMT 2007
>Last-Modified:  Sat Jan 27 18:36:53 GMT 2007
>Originator:     Loren M. Lang
>Release:        FreeBSD 5.4-RELEASE-p1 i386
>Organization:
Alzatex, Inc.
>Environment:
System: FreeBSD fbsd.ddns.alzatex.cc 5.4-RELEASE-p1 FreeBSD 5.4-RELEASE-p1 #6: Tue Jun 7 04:04:28 PDT 2005 root@:/usr/obj/usr/src/sys/IPSEC-NG i386


	
>Description:
	Currently, when a file mask is set, but no directory mask, it sets
the directory mask to the file mask.  Or when no mask it set at all, it uses
the permissions on the mount point for both the directory and file mask.
This patch causes mount_msdosfs to enable the access(X) bit for the directory
mask everywhere either a read or write permission is set.  This allows me
to set a file mask with -m 644 or by changing the permissions on the mount
point to 644 and have directories work correctly with the corresponding 755
permissions.

	This behavior mimics how mount_smbfs currently responds for smb
network mounts.

>How-To-Repeat:
	The following two commands would get a permission error:

	mount_msdosfs -m 644 /dev/fd0 /mnt/floppy
	ls /mnt/floppy

>Fix:

	

--- mount_msdosfs.patch begins here ---
--- sbin/mount_msdosfs/mount_msdosfs.c.orig	Sat Jun  4 02:49:28 2005
+++ sbin/mount_msdosfs/mount_msdosfs.c	Tue Jun  7 03:48:53 2005
@@ -81,6 +81,7 @@
 static mode_t	a_mask(char *);
 static void	usage(void) __dead2;
 static int	set_charset(struct msdosfs_args *);
+static mode_t	set_dirxbit(mode_t);
 
 int
 main(int argc, char **argv)
@@ -186,7 +187,7 @@
 		usage();
 
 	if (set_mask && !set_dirmask) {
-		args.dirmask = args.mask;
+		args.dirmask = set_dirxbit(args.mask);
 		set_dirmask = 1;
 	}
 	else if (set_dirmask && !set_mask) {
@@ -231,15 +232,30 @@
 			args.uid = sb.st_uid;
 		if (!set_gid)
 			args.gid = sb.st_gid;
-		if (!set_mask)
-			args.mask = args.dirmask =
-				sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
+		if (!set_mask) {
+			args.mask = sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
+			args.dirmask = set_dirxbit(args.mask);
+		}
 	}
 
 	if (mount("msdosfs", mntpath, mntflags, &args) < 0)
 		err(EX_OSERR, "%s", dev);
 
 	exit (0);
+}
+
+static mode_t
+set_dirxbit(m)
+	mode_t m;
+{
+	if(m & (S_IRUSR|S_IWUSR))
+		m |= S_IXUSR;
+	if(m & (S_IRGRP|S_IWGRP))
+		m |= S_IXGRP;
+	if(m & (S_IROTH|S_IWOTH))
+		m |= S_IXOTH;
+
+	return m;
 }
 
 gid_t
--- mount_msdosfs.patch ends here ---


>Release-Note:
>Audit-Trail:
Adding to audit trail from misfiled PR bin/82126:

Date: Sat, 11 Jun 2005 01:37:03 +0800
From: Eugene Grosbein <eugen@kuzbass.ru>

 > Currently, when a file mask is set, but no directory mask, it sets
 > the directory mask to the file mask.  Or when no mask it set at all, it uses
 > the permissions on the mount point for both the directory and file mask.
 
 This was done intentionaly to satisfy POLA when '-M' option was introduced
 because it worked exactly this way before.
 
 > This patch causes mount_msdosfs to enable the access(X) bit for the directory
 > mask everywhere either a read or write permission is set.  This allows me
 > to set a file mask with -m 644 or by changing the permissions on the mount
 > point to 644 and have directories work correctly with the corresponding 755
 > permissions.
 
 Just use -m 644 -M 755 options together.
 
 Eugene Grosbein
State-Changed-From-To: open->closed 
State-Changed-By: rodrigc 
State-Changed-When: Sat Jan 27 18:36:03 UTC 2007 
State-Changed-Why:  
As Eugene Grosbein pointed out, the -M option to mount_msdosfs can 
be used to do what you need. 

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