Module Name: src
Committed By: christos
Date: Fri Feb 2 20:27:26 UTC 2024
Modified Files:
src/sbin/mount_cd9660: Makefile mount_cd9660.8 mount_cd9660.c
src/sys/fs/cd9660: cd9660_extern.h cd9660_mount.h cd9660_vfsops.c
cd9660_vnops.c
Log Message:
PR/57897: Ricardo Branco: Add support for mount options mask,dirmask,uid,gid
To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sbin/mount_cd9660/Makefile
cvs rdiff -u -r1.31 -r1.32 src/sbin/mount_cd9660/mount_cd9660.8
cvs rdiff -u -r1.33 -r1.34 src/sbin/mount_cd9660/mount_cd9660.c
cvs rdiff -u -r1.27 -r1.28 src/sys/fs/cd9660/cd9660_extern.h
cvs rdiff -u -r1.6 -r1.7 src/sys/fs/cd9660/cd9660_mount.h
cvs rdiff -u -r1.97 -r1.98 src/sys/fs/cd9660/cd9660_vfsops.c
cvs rdiff -u -r1.62 -r1.63 src/sys/fs/cd9660/cd9660_vnops.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sbin/mount_cd9660/Makefile
diff -u src/sbin/mount_cd9660/Makefile:1.12 src/sbin/mount_cd9660/Makefile:1.13
--- src/sbin/mount_cd9660/Makefile:1.12 Tue Aug 5 16:57:45 2008
+++ src/sbin/mount_cd9660/Makefile Fri Feb 2 15:27:26 2024
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.12 2008/08/05 20:57:45 pooka Exp $
+# $NetBSD: Makefile,v 1.13 2024/02/02 20:27:26 christos Exp $
# @(#)Makefile 8.3 (Berkeley) 3/27/94
.include <bsd.own.mk>
PROG= mount_cd9660
-SRCS= mount_cd9660.c pathadj.c
+SRCS= mount_cd9660.c fattr.c pathadj.c
MAN= mount_cd9660.8
MOUNT= ${NETBSDSRCDIR}/sbin/mount
Index: src/sbin/mount_cd9660/mount_cd9660.8
diff -u src/sbin/mount_cd9660/mount_cd9660.8:1.31 src/sbin/mount_cd9660/mount_cd9660.8:1.32
--- src/sbin/mount_cd9660/mount_cd9660.8:1.31 Sat Jun 30 05:27:41 2018
+++ src/sbin/mount_cd9660/mount_cd9660.8 Fri Feb 2 15:27:26 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: mount_cd9660.8,v 1.31 2018/06/30 09:27:41 sevan Exp $
+.\" $NetBSD: mount_cd9660.8,v 1.32 2024/02/02 20:27:26 christos Exp $
.\"
.\" Copyright (c) 2004 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -57,7 +57,7 @@
.\"
.\" @(#)mount_cd9660.8 8.3 (Berkeley) 3/27/94
.\"
-.Dd June 30, 2018
+.Dd February 1, 2024
.Dt MOUNT_CD9660 8
.Os
.Sh NAME
@@ -65,6 +65,10 @@
.Nd mount an ISO-9660 file system
.Sh SYNOPSIS
.Nm
+.Op Fl G Ar gid
+.Op Fl m Ar mask
+.Op Fl M Ar mask
+.Op Fl U Ar uid
.Op Fl o Ar options
.Ar special node
.Sh DESCRIPTION
@@ -82,6 +86,37 @@ are converted to absolute paths before u
.Pp
The options are as follows:
.Bl -tag -width indent
+.It Fl G Ar group
+Set the group of the files in the file system to
+.Ar group .
+The default gid on non-Rockridge volumes is zero.
+.It Fl U Ar user
+Set the owner of the files in the file system to
+.Ar user .
+The default uid on non-Rockridge volumes is zero.
+.It Fl m Ar mask
+Specify the maximum file permissions for files
+in the file system.
+(For example, a
+.Ar mask
+of
+.Li 755
+specifies that, by default, the owner should have
+read, write, and execute permissions for files, but
+others should only have read and execute permissions).
+See
+.Xr chmod 1
+for more information about octal file modes.
+Only the nine low-order bits of
+.Ar mask
+are used.
+The default
+.Ar mask
+on non-Rockridge volumes is 755.
+.It Fl M Ar mask
+Specify the maximum file permissions for directories
+in the file system.
+See the previous option's description for details.
.It Fl o
Options are specified with a
.Fl o
Index: src/sbin/mount_cd9660/mount_cd9660.c
diff -u src/sbin/mount_cd9660/mount_cd9660.c:1.33 src/sbin/mount_cd9660/mount_cd9660.c:1.34
--- src/sbin/mount_cd9660/mount_cd9660.c:1.33 Sun Oct 16 12:26:35 2022
+++ src/sbin/mount_cd9660/mount_cd9660.c Fri Feb 2 15:27:26 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: mount_cd9660.c,v 1.33 2022/10/16 16:26:35 rillig Exp $ */
+/* $NetBSD: mount_cd9660.c,v 1.34 2024/02/02 20:27:26 christos Exp $ */
/*
* Copyright (c) 1992, 1993, 1994
@@ -46,7 +46,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 19
#if 0
static char sccsid[] = "@(#)mount_cd9660.c 8.7 (Berkeley) 5/1/95";
#else
-__RCSID("$NetBSD: mount_cd9660.c,v 1.33 2022/10/16 16:26:35 rillig Exp $");
+__RCSID("$NetBSD: mount_cd9660.c,v 1.34 2024/02/02 20:27:26 christos Exp $");
#endif
#endif /* not lint */
@@ -99,14 +99,15 @@ mount_cd9660_parseargs(int argc, char **
struct iso_args *args, int *mntflags,
char *canon_dev, char *canon_dir)
{
- int ch, opts;
+ struct stat sb;
+ int ch, opts, set_gid, set_uid, set_mask, set_dirmask;
mntoptparse_t mp;
char *dev, *dir;
memset(args, 0, sizeof(*args));
- *mntflags = opts = 0;
+ *mntflags = opts = set_gid = set_uid = set_mask = set_dirmask = 0;
optind = optreset = 1;
- while ((ch = getopt(argc, argv, "egjo:r")) != -1)
+ while ((ch = getopt(argc, argv, "egG:jM:m:o:rU:")) != -1)
switch (ch) {
case 'e':
/* obsolete, retained for compatibility only, use
@@ -118,6 +119,19 @@ mount_cd9660_parseargs(int argc, char **
* -o gens */
opts |= ISOFSMNT_GENS;
break;
+ case 'G':
+ opts |= ISOFSMNT_GID;
+ args->gid = a_gid(optarg);
+ set_gid = 1;
+ break;
+ case 'm':
+ args->fmask = a_mask(optarg);
+ set_mask = 1;
+ break;
+ case 'M':
+ args->dmask = a_mask(optarg);
+ set_dirmask = 1;
+ break;
case 'j':
/* obsolete, retained fo compatibility only, use
* -o nojoliet */
@@ -134,6 +148,11 @@ mount_cd9660_parseargs(int argc, char **
* -o norrip */
opts |= ISOFSMNT_NORRIP;
break;
+ case 'U':
+ opts |= ISOFSMNT_UID;
+ args->uid = a_uid(optarg);
+ set_uid = 1;
+ break;
case '?':
default:
usage();
@@ -145,6 +164,14 @@ mount_cd9660_parseargs(int argc, char **
if (argc != 2)
usage();
+ if (set_mask && !set_dirmask) {
+ args->dmask = args->fmask;
+ set_dirmask = 1;
+ } else if (set_dirmask && !set_mask) {
+ args->fmask = args->dmask;
+ set_mask = 1;
+ }
+
dev = argv[0];
dir = argv[1];
@@ -159,6 +186,20 @@ mount_cd9660_parseargs(int argc, char **
*mntflags |= MNT_RDONLY;
args->fspec = canon_dev;
args->flags = opts;
+
+ if (!set_gid || !set_uid || !set_mask) {
+ if (stat(dir, &sb) == -1)
+ err(1, "stat %s", dir);
+
+ if (!set_uid)
+ args->uid = sb.st_uid;
+ if (!set_gid)
+ args->gid = sb.st_gid;
+ if (!set_mask) {
+ args->fmask = args->dmask =
+ sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
+ }
+ }
}
int
Index: src/sys/fs/cd9660/cd9660_extern.h
diff -u src/sys/fs/cd9660/cd9660_extern.h:1.27 src/sys/fs/cd9660/cd9660_extern.h:1.28
--- src/sys/fs/cd9660/cd9660_extern.h:1.27 Tue Aug 21 21:05:23 2018
+++ src/sys/fs/cd9660/cd9660_extern.h Fri Feb 2 15:27:26 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: cd9660_extern.h,v 1.27 2018/08/22 01:05:23 msaitoh Exp $ */
+/* $NetBSD: cd9660_extern.h,v 1.28 2024/02/02 20:27:26 christos Exp $ */
/*-
* Copyright (c) 1994
@@ -62,6 +62,11 @@ struct iso_mnt {
dev_t im_dev;
struct vnode *im_devvp;
+ uid_t im_uid;
+ gid_t im_gid;
+ mode_t im_fmask;
+ mode_t im_dmask;
+
int logical_block_size;
int im_bshift;
int im_bmask;
Index: src/sys/fs/cd9660/cd9660_mount.h
diff -u src/sys/fs/cd9660/cd9660_mount.h:1.6 src/sys/fs/cd9660/cd9660_mount.h:1.7
--- src/sys/fs/cd9660/cd9660_mount.h:1.6 Sat Dec 3 12:34:43 2005
+++ src/sys/fs/cd9660/cd9660_mount.h Fri Feb 2 15:27:26 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: cd9660_mount.h,v 1.6 2005/12/03 17:34:43 christos Exp $ */
+/* $NetBSD: cd9660_mount.h,v 1.7 2024/02/02 20:27:26 christos Exp $ */
/*
* Copyright (c) 1995
* The Regents of the University of California. All rights reserved.
@@ -45,6 +45,10 @@ struct iso_args {
const char *fspec; /* block special device to mount */
struct export_args30 _pad1; /* compat with old userland tools */
int flags; /* mounting flags, see below */
+ uid_t uid; /* uid that owns ISO-9660 files */
+ gid_t gid; /* gid that owns ISO-9660 files */
+ mode_t fmask; /* file mask to be applied for files */
+ mode_t dmask; /* file mask to be applied for directories */
};
#define ISOFSMNT_NORRIP 0x00000001 /* disable Rock Ridge Ext.*/
#define ISOFSMNT_GENS 0x00000002 /* enable generation numbers */
@@ -52,6 +56,8 @@ struct iso_args {
#define ISOFSMNT_NOJOLIET 0x00000008 /* disable Joliet extensions */
#define ISOFSMNT_NOCASETRANS 0x00000010 /* do not make names lower case */
#define ISOFSMNT_RRCASEINS 0x00000020 /* case insensitive Rock Ridge */
+#define ISOFSMNT_UID 0x00000100 /* override uid */
+#define ISOFSMNT_GID 0x00000200 /* override gid */
#define ISOFSMNT_BITS "\177\20" \
"b\00norrip\0b\01gens\0b\02extatt\0b\03nojoliet\0" \
Index: src/sys/fs/cd9660/cd9660_vfsops.c
diff -u src/sys/fs/cd9660/cd9660_vfsops.c:1.97 src/sys/fs/cd9660/cd9660_vfsops.c:1.98
--- src/sys/fs/cd9660/cd9660_vfsops.c:1.97 Tue May 3 03:33:07 2022
+++ src/sys/fs/cd9660/cd9660_vfsops.c Fri Feb 2 15:27:26 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: cd9660_vfsops.c,v 1.97 2022/05/03 07:33:07 hannken Exp $ */
+/* $NetBSD: cd9660_vfsops.c,v 1.98 2024/02/02 20:27:26 christos Exp $ */
/*-
* Copyright (c) 1994
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.97 2022/05/03 07:33:07 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.98 2024/02/02 20:27:26 christos Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@@ -456,6 +456,13 @@ iso_mountfs(struct vnode *devvp, struct
isomp->im_dev = dev;
isomp->im_devvp = devvp;
+ if (argp->flags & ISOFSMNT_UID)
+ isomp->im_uid = argp->uid;
+ if (argp->flags & ISOFSMNT_GID)
+ isomp->im_gid = argp->gid;
+ isomp->im_fmask = argp->fmask & ACCESSPERMS;
+ isomp->im_dmask = argp->dmask & ACCESSPERMS;
+
/* Check the Rock Ridge Extension support */
if (!(argp->flags & ISOFSMNT_NORRIP)) {
struct iso_directory_record *rootp;
@@ -483,7 +490,8 @@ iso_mountfs(struct vnode *devvp, struct
bp = NULL;
}
isomp->im_flags = argp->flags & (ISOFSMNT_NORRIP | ISOFSMNT_GENS |
- ISOFSMNT_EXTATT | ISOFSMNT_NOJOLIET | ISOFSMNT_RRCASEINS);
+ ISOFSMNT_EXTATT | ISOFSMNT_NOJOLIET | ISOFSMNT_RRCASEINS |
+ ISOFSMNT_UID | ISOFSMNT_GID);
if (isomp->im_flags & ISOFSMNT_GENS)
isomp->iso_ftype = ISO_FTYPE_9660;
Index: src/sys/fs/cd9660/cd9660_vnops.c
diff -u src/sys/fs/cd9660/cd9660_vnops.c:1.62 src/sys/fs/cd9660/cd9660_vnops.c:1.63
--- src/sys/fs/cd9660/cd9660_vnops.c:1.62 Sun Mar 27 13:10:55 2022
+++ src/sys/fs/cd9660/cd9660_vnops.c Fri Feb 2 15:27:26 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: cd9660_vnops.c,v 1.62 2022/03/27 17:10:55 christos Exp $ */
+/* $NetBSD: cd9660_vnops.c,v 1.63 2024/02/02 20:27:26 christos Exp $ */
/*-
* Copyright (c) 1994
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cd9660_vnops.c,v 1.62 2022/03/27 17:10:55 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd9660_vnops.c,v 1.63 2024/02/02 20:27:26 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -61,6 +61,7 @@ __KERNEL_RCSID(0, "$NetBSD: cd9660_vnops
#include <fs/cd9660/iso.h>
#include <fs/cd9660/cd9660_extern.h>
#include <fs/cd9660/cd9660_node.h>
+#include <fs/cd9660/cd9660_mount.h>
#include <fs/cd9660/iso_rrip.h>
#include <fs/cd9660/cd9660_mount.h>
@@ -116,11 +117,22 @@ static int
cd9660_check_permitted(struct vnode *vp, struct iso_node *ip, accmode_t accmode,
kauth_cred_t cred)
{
+ accmode_t file_mode;
+ uid_t uid;
+ gid_t gid;
+
+ file_mode = ip->inode.iso_mode & ALLPERMS;
+ file_mode &= (vp->v_type == VDIR) ? ip->i_mnt->im_dmask : ip->i_mnt->im_fmask;
+
+ uid = (ip->i_mnt->im_flags & ISOFSMNT_UID) ?
+ ip->i_mnt->im_uid : ip->inode.iso_uid;
+ gid = (ip->i_mnt->im_flags & ISOFSMNT_GID) ?
+ ip->i_mnt->im_gid : ip->inode.iso_gid;
return kauth_authorize_vnode(cred, KAUTH_ACCESS_ACTION(accmode,
- vp->v_type, ip->inode.iso_mode & ALLPERMS), vp, NULL,
- genfs_can_access(vp, cred, ip->inode.iso_uid, ip->inode.iso_gid,
- ip->inode.iso_mode & ALLPERMS, NULL, accmode));
+ vp->v_type, file_mode), vp, NULL,
+ genfs_can_access(vp, cred, uid, gid,
+ file_mode, NULL, accmode));
}
int
@@ -160,9 +172,12 @@ cd9660_getattr(void *v)
vap->va_fileid = ip->i_number;
vap->va_mode = ip->inode.iso_mode & ALLPERMS;
+ vap->va_mode &= (vp->v_type == VDIR) ? ip->i_mnt->im_dmask : ip->i_mnt->im_fmask;
vap->va_nlink = ip->inode.iso_links;
- vap->va_uid = ip->inode.iso_uid;
- vap->va_gid = ip->inode.iso_gid;
+ vap->va_uid = (ip->i_mnt->im_flags & ISOFSMNT_UID) ?
+ ip->i_mnt->im_uid : ip->inode.iso_uid;
+ vap->va_gid = (ip->i_mnt->im_flags & ISOFSMNT_GID) ?
+ ip->i_mnt->im_gid : ip->inode.iso_gid;
vap->va_atime = ip->inode.iso_atime;
vap->va_mtime = ip->inode.iso_mtime;
vap->va_ctime = ip->inode.iso_ctime;