From owner-freebsd-arch Sat Jan 19 19:38:43 2002 Delivered-To: freebsd-arch@freebsd.org Received: from D00015.dialonly.kemerovo.su (www2.svzserv.kemerovo.su [213.184.65.86]) by hub.freebsd.org (Postfix) with ESMTP id C98F537B402 for ; Sat, 19 Jan 2002 19:38:25 -0800 (PST) Received: (from eugen@localhost) by D00015.dialonly.kemerovo.su (8.11.6/8.11.6) id g0K3PLj00479 for arch@freebsd.org; Sun, 20 Jan 2002 10:25:21 +0700 (KRAT) (envelope-from eugen) Date: Sun, 20 Jan 2002 10:25:21 +0700 From: Eugene Grosbein To: arch@freebsd.org Subject: [PATCH] msdosfs: differrent masks for directories and other files Message-ID: <20020120102521.A450@grosbein.pp.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi! There is very frequently asked (at least, in Russian newsgroups) question: is it possible to make Midnight Commander enter to archives on msdosfs and stop his attempts to execute files there? The only way is to use '-m 644', but then you can enter directories as root only. Finally I got tired of these questions and patched kernel, mount_msdosfs and its man page to accept new option '-M mask'. This mask is used for directories only, if supplied. If -M is used and -m is not then supplied mask is used for all objects. I do not run CURRENT so this patch is for 4.5RC1 That is my first 6K kernel patch so please review. It works at least for me :-) Index: sbin/mount_msdos/mount_msdos.8 =================================================================== RCS file: /home/ncvs/src/sbin/mount_msdos/Attic/mount_msdos.8,v retrieving revision 1.19.2.1 diff -u -r1.19.2.1 mount_msdos.8 --- sbin/mount_msdos/mount_msdos.8 8 Dec 2000 14:03:59 -0000 1.19.2.1 +++ sbin/mount_msdos/mount_msdos.8 19 Jan 2002 05:55:22 -0000 @@ -42,6 +42,7 @@ .Op Fl u Ar uid .Op Fl g Ar gid .Op Fl m Ar mask +.Op Fl M Ar mask .Op Fl s .Op Fl l .Op Fl 9 @@ -105,11 +106,22 @@ for more information about octal file modes.) Only the nine low-order bits of .Ar mask -are used. +are used. The value of +.Ar -M +is used if it is supplied and +.Ar -m +is omitted. The default .Ar mask is taken from the directory on which the file system is being mounted. +.It Fl M Ar mask +Specify the maximum file permissions for directories +in the file system. The value of +.Ar -m +is used if it is supplied and +.Ar -M +is omitted. See description of previous option for details. .It Fl s Force behaviour to ignore and not generate Win'95 long filenames. Index: sbin/mount_msdos/mount_msdos.c =================================================================== RCS file: /home/ncvs/src/sbin/mount_msdos/Attic/mount_msdos.c,v retrieving revision 1.19.2.1 diff -u -r1.19.2.1 mount_msdos.c --- sbin/mount_msdos/mount_msdos.c 20 Jul 2000 10:35:13 -0000 1.19.2.1 +++ sbin/mount_msdos/mount_msdos.c 19 Jan 2002 04:30:27 -0000 @@ -88,15 +88,15 @@ { struct msdosfs_args args; struct stat sb; - int c, error, mntflags, set_gid, set_uid, set_mask; + int c, error, mntflags, set_gid, set_uid, set_mask, set_dirmask; char *dev, *dir, mntpath[MAXPATHLEN]; struct vfsconf vfc; - mntflags = set_gid = set_uid = set_mask = 0; + mntflags = set_gid = set_uid = set_mask = set_dirmask = 0; (void)memset(&args, '\0', sizeof(args)); args.magic = MSDOSFS_ARGSMAGIC; - while ((c = getopt(argc, argv, "sl9u:g:m:o:L:W:")) != -1) { + while ((c = getopt(argc, argv, "sl9u:g:m:M:o:L:W:")) != -1) { switch (c) { #ifdef MSDOSFSMNT_GEMDOSFS case 'G': @@ -124,6 +124,10 @@ args.mask = a_mask(optarg); set_mask = 1; break; + case 'M': + args.dirmask = a_mask(optarg); + set_dirmask = 1; + break; case 'L': load_ultable(&args, optarg); args.flags |= MSDOSFSMNT_ULTABLE; @@ -144,7 +148,16 @@ if (optind + 2 != argc) usage(); - + + if (set_mask && !set_dirmask) { + args.dirmask = args.mask; + set_dirmask = 1; + } + else if (set_dirmask && !set_mask) { + args.mask = args.dirmask; + set_mask = 1; + } + dev = argv[optind]; dir = argv[optind + 1]; @@ -170,7 +183,8 @@ if (!set_gid) args.gid = sb.st_gid; if (!set_mask) - args.mask = sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); + args.mask = args.dirmask = + sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); } error = getvfsbyname("msdos", &vfc); Index: sys/msdosfs/msdosfs_vfsops.c =================================================================== RCS file: /home/ncvs/src/sys/msdosfs/Attic/msdosfs_vfsops.c,v retrieving revision 1.60.2.5 diff -u -r1.60.2.5 msdosfs_vfsops.c --- sys/msdosfs/msdosfs_vfsops.c 4 Nov 2001 18:57:51 -0000 1.60.2.5 +++ sys/msdosfs/msdosfs_vfsops.c 19 Jan 2002 04:47:43 -0000 @@ -113,6 +113,7 @@ pmp->pm_gid = argp->gid; pmp->pm_uid = argp->uid; pmp->pm_mask = argp->mask & ALLPERMS; + pmp->pm_dirmask = argp->dirmask & ALLPERMS; pmp->pm_flags |= argp->flags & MSDOSFSMNT_MNTOPT; if (pmp->pm_flags & MSDOSFSMNT_U2WTABLE) { bcopy(argp->u2w, pmp->pm_u2w, sizeof(pmp->pm_u2w)); @@ -184,7 +185,7 @@ args.flags = 0; args.uid = 0; args.gid = 0; - args.mask = 0777; + args.mask = args.dirmask = 0777; if ((error = mountmsdosfs(rootvp, mp, p, &args)) != 0) { free(mp, M_MOUNT); Index: sys/msdosfs/msdosfs_vnops.c =================================================================== RCS file: /home/ncvs/src/sys/msdosfs/Attic/msdosfs_vnops.c,v retrieving revision 1.95.2.1 diff -u -r1.95.2.1 msdosfs_vnops.c --- sys/msdosfs/msdosfs_vnops.c 18 Jul 2000 13:19:13 -0000 1.95.2.1 +++ sys/msdosfs/msdosfs_vnops.c 19 Jan 2002 05:36:00 -0000 @@ -259,7 +259,7 @@ file_mode = (S_IXUSR|S_IXGRP|S_IXOTH) | (S_IRUSR|S_IRGRP|S_IROTH) | ((dep->de_Attributes & ATTR_READONLY) ? 0 : (S_IWUSR|S_IWGRP|S_IWOTH)); - file_mode &= pmp->pm_mask; + file_mode &= (vp->v_type == VDIR ? pmp->pm_dirmask : pmp->pm_mask); /* * Disallow write attempts on read-only file systems; @@ -358,7 +358,8 @@ mode = S_IRWXU|S_IRWXG|S_IRWXO; else mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; - vap->va_mode = mode & pmp->pm_mask; + vap->va_mode = mode & + (ap->a_vp->v_type == VDIR ? pmp->pm_dirmask : pmp->pm_mask); vap->va_uid = pmp->pm_uid; vap->va_gid = pmp->pm_gid; vap->va_nlink = 1; Index: sys/msdosfs/msdosfsmount.h =================================================================== RCS file: /home/ncvs/src/sys/msdosfs/Attic/msdosfsmount.h,v retrieving revision 1.20.2.2 diff -u -r1.20.2.2 msdosfsmount.h --- sys/msdosfs/msdosfsmount.h 27 Oct 2000 09:45:07 -0000 1.20.2.2 +++ sys/msdosfs/msdosfsmount.h 19 Jan 2002 04:42:41 -0000 @@ -65,7 +65,10 @@ dev_t pm_dev; /* block special device mounted */ uid_t pm_uid; /* uid to set as owner of the files */ gid_t pm_gid; /* gid to set as owner of the files */ - mode_t pm_mask; /* mask to and with file protection bits */ + mode_t pm_mask; /* mask to and with file protection bits + for files */ + mode_t pm_dirmask; /* mask to and with file protection bits + for directories */ struct vnode *pm_devvp; /* vnode for block device mntd */ struct bpb50 pm_bpb; /* BIOS parameter blk for this fs */ u_long pm_BlkPerSec; /* How many DEV_BSIZE blocks fit inside a physical sector */ @@ -211,7 +214,8 @@ struct export_args export; /* network export information */ uid_t uid; /* uid that owns msdosfs files */ gid_t gid; /* gid that owns msdosfs files */ - mode_t mask; /* mask to be applied for msdosfs perms */ + mode_t mask; /* file mask to be applied for msdosfs perms */ + mode_t dirmask; /* dir mask to be applied for msdosfs perms */ int flags; /* see below */ int magic; /* version number */ u_int16_t u2w[128]; /* Local->Unicode table */ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message