From fd33bfb7f2a74c2ddd9aea91bb08026696cc083c Mon Sep 17 00:00:00 2001 From: mlelstv Date: Sun, 26 Jul 2020 08:20:22 +0000 Subject: [PATCH] Refactor remaining mount_* commands to use the common pathadj() function for resolving paths. Make pathadj() no longer warn about symlinks. Symlinks in /dev are regularly used in several places like LVM . The warning was also only visible when calling a mount_* command directly as mount(8) itself would resolve the path witout warning before passing it to a mount_* command. --- sbin/mount/pathadj.c | 11 +++++++---- sbin/mount_ados/Makefile | 4 ++-- sbin/mount_ados/mount_ados.c | 22 ++++++---------------- sbin/mount_autofs/Makefile | 8 ++++++-- sbin/mount_autofs/mount_autofs.c | 12 ++++-------- sbin/mount_fdesc/Makefile | 8 ++++++-- sbin/mount_fdesc/mount_fdesc.c | 12 ++++-------- sbin/mount_filecore/Makefile | 4 ++-- sbin/mount_filecore/mount_filecore.c | 23 +++++------------------ sbin/mount_kernfs/Makefile | 8 ++++++-- sbin/mount_kernfs/mount_kernfs.c | 12 ++++-------- sbin/mount_null/Makefile | 8 +++++--- sbin/mount_null/mount_null.c | 21 ++++++--------------- sbin/mount_overlay/Makefile | 8 +++++--- sbin/mount_overlay/mount_overlay.c | 21 ++++++--------------- sbin/mount_procfs/Makefile | 8 ++++++-- sbin/mount_procfs/mount_procfs.c | 13 +++++-------- sbin/mount_ptyfs/Makefile | 8 ++++++-- sbin/mount_ptyfs/mount_ptyfs.c | 13 +++++-------- sbin/mount_umap/Makefile | 8 +++++--- sbin/mount_umap/mount_umap.c | 21 ++++++--------------- sbin/mount_union/Makefile | 8 +++++--- sbin/mount_union/mount_union.c | 21 ++++++--------------- 23 files changed, 118 insertions(+), 164 deletions(-) diff --git a/sbin/mount/pathadj.c b/sbin/mount/pathadj.c index f8f6e499f3a3..649773ea61e0 100644 --- a/sbin/mount/pathadj.c +++ b/sbin/mount/pathadj.c @@ -1,4 +1,4 @@ -/* $NetBSD: pathadj.c,v 1.2 2011/02/17 16:57:46 pooka Exp $ */ +/* $NetBSD: pathadj.c,v 1.3 2020/07/26 08:20:22 mlelstv Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation. All Rights Reserved. @@ -37,10 +37,13 @@ void pathadj(const char *input, char *adjusted) { - if (realpath(input, adjusted) == NULL) + if (realpath(input, adjusted) == NULL) { warn("Warning: realpath %s", input); - if (strncmp(input, adjusted, MAXPATHLEN)) { - warnx("\"%s\" is a non-resolved or relative path.", input); + return; + } + + if (input[0] != '/') { + warnx("\"%s\" is a relative path.", input); warnx("using \"%s\" instead.", adjusted); } } diff --git a/sbin/mount_ados/Makefile b/sbin/mount_ados/Makefile index e53d47ebea45..5b06de012f82 100644 --- a/sbin/mount_ados/Makefile +++ b/sbin/mount_ados/Makefile @@ -1,9 +1,9 @@ -# $NetBSD: Makefile,v 1.13 2005/06/27 01:00:05 christos Exp $ +# $NetBSD: Makefile,v 1.14 2020/07/26 08:20:22 mlelstv Exp $ .include PROG= mount_ados -SRCS= mount_ados.c fattr.c +SRCS= mount_ados.c fattr.c pathadj.c MAN= mount_ados.8 MOUNT= ${NETBSDSRCDIR}/sbin/mount diff --git a/sbin/mount_ados/mount_ados.c b/sbin/mount_ados/mount_ados.c index bc15f3e83916..29ada86d6edf 100644 --- a/sbin/mount_ados/mount_ados.c +++ b/sbin/mount_ados/mount_ados.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_ados.c,v 1.29 2011/08/29 14:35:00 joerg Exp $ */ +/* $NetBSD: mount_ados.c,v 1.30 2020/07/26 08:20:22 mlelstv Exp $ */ /* * Copyright (c) 1994 Christopher G. Demetriou @@ -36,7 +36,7 @@ #include #ifndef lint -__RCSID("$NetBSD: mount_ados.c,v 1.29 2011/08/29 14:35:00 joerg Exp $"); +__RCSID("$NetBSD: mount_ados.c,v 1.30 2020/07/26 08:20:22 mlelstv Exp $"); #endif /* not lint */ #include @@ -120,21 +120,11 @@ mount_ados(int argc, char **argv) dev = argv[optind]; dir = argv[optind + 1]; - if (realpath(dev, canon_dev) == NULL) /* Check device path */ - err(1, "realpath %s", dev); - if (strncmp(dev, canon_dev, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", dev); - dev = canon_dev; - warnx("using \"%s\" instead.", dev); - } + pathadj(dev, canon_dev); + dev = canon_dev; - if (realpath(dir, canon_dir) == NULL) /* Check mounton path */ - err(1, "realpath %s", dir); - if (strncmp(dir, canon_dir, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", dir); - dir = canon_dir; - warnx("using \"%s\" instead.", dir); - } + pathadj(dir, canon_dir); + dir = canon_dir; args.fspec = dev; if (!set_gid || !set_uid || !set_mask) { diff --git a/sbin/mount_autofs/Makefile b/sbin/mount_autofs/Makefile index cad1aec42d12..043cf0cde5f6 100644 --- a/sbin/mount_autofs/Makefile +++ b/sbin/mount_autofs/Makefile @@ -1,12 +1,16 @@ -# $NetBSD: Makefile,v 1.2 2018/01/22 09:45:32 kamil Exp $ +# $NetBSD: Makefile,v 1.3 2020/07/26 08:20:22 mlelstv Exp $ # @(#)Makefile 8.2 (Berkeley) 3/27/94 .include PROG= mount_autofs -SRCS= mount_autofs.c +SRCS= mount_autofs.c pathadj.c MAN= mount_autofs.8 +MOUNT= ${NETBSDSRCDIR}/sbin/mount +CPPFLAGS+= -I${NETBSDSRCDIR}/sys -I${MOUNT} +.PATH: ${MOUNT} + DPADD+=${LIBUTIL} LDADD+=-lutil diff --git a/sbin/mount_autofs/mount_autofs.c b/sbin/mount_autofs/mount_autofs.c index e985eb7baff3..375aa7d521b9 100644 --- a/sbin/mount_autofs/mount_autofs.c +++ b/sbin/mount_autofs/mount_autofs.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_autofs.c,v 1.4 2019/11/20 17:18:35 tkusumi Exp $ */ +/* $NetBSD: mount_autofs.c,v 1.5 2020/07/26 08:20:22 mlelstv Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include #ifndef lint -__RCSID("$NetBSD: mount_autofs.c,v 1.4 2019/11/20 17:18:35 tkusumi Exp $"); +__RCSID("$NetBSD: mount_autofs.c,v 1.5 2020/07/26 08:20:22 mlelstv Exp $"); #endif /* not lint */ #include @@ -46,6 +46,7 @@ __RCSID("$NetBSD: mount_autofs.c,v 1.4 2019/11/20 17:18:35 tkusumi Exp $"); #include +#include "mountprog.h" #include "mount_autofs.h" static const struct mntopt mopts[] = { @@ -102,12 +103,7 @@ mount_autofs_parseargs(int argc, char *argv[], void *v, int *mntflags, usage(); strlcpy(canon_dev, argv[0], MAXPATHLEN); - if (realpath(argv[1], canon_dir) == NULL) /* Check mounton path */ - err(EXIT_FAILURE, "realpath %s", canon_dir); - if (strncmp(argv[1], canon_dir, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", argv[1]); - warnx("using \"%s\" instead.", canon_dir); - } + pathadj(argv[1], canon_dir); } int diff --git a/sbin/mount_fdesc/Makefile b/sbin/mount_fdesc/Makefile index 73a5943375d9..e14c4b02757d 100644 --- a/sbin/mount_fdesc/Makefile +++ b/sbin/mount_fdesc/Makefile @@ -1,12 +1,16 @@ -# $NetBSD: Makefile,v 1.13 2005/06/27 01:00:05 christos Exp $ +# $NetBSD: Makefile,v 1.14 2020/07/26 08:20:22 mlelstv Exp $ # @(#)Makefile 8.2 (Berkeley) 3/27/94 .include PROG= mount_fdesc -SRCS= mount_fdesc.c +SRCS= mount_fdesc.c pathadj.c MAN= mount_fdesc.8 +MOUNT= ${NETBSDSRCDIR}/sbin/mount +CPPFLAGS+= -I${NETBSDSRCDIR}/sys -I${MOUNT} +.PATH: ${MOUNT} + DPADD+=${LIBUTIL} LDADD+=-lutil diff --git a/sbin/mount_fdesc/mount_fdesc.c b/sbin/mount_fdesc/mount_fdesc.c index 1249c8401c84..c60336fb57dd 100644 --- a/sbin/mount_fdesc/mount_fdesc.c +++ b/sbin/mount_fdesc/mount_fdesc.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_fdesc.c,v 1.26 2011/08/29 14:35:00 joerg Exp $ */ +/* $NetBSD: mount_fdesc.c,v 1.27 2020/07/26 08:20:22 mlelstv Exp $ */ /* * Copyright (c) 1992, 1993, 1994 @@ -77,7 +77,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\ #if 0 static char sccsid[] = "@(#)mount_fdesc.c 8.3 (Berkeley) 4/26/95"; #else -__RCSID("$NetBSD: mount_fdesc.c,v 1.26 2011/08/29 14:35:00 joerg Exp $"); +__RCSID("$NetBSD: mount_fdesc.c,v 1.27 2020/07/26 08:20:22 mlelstv Exp $"); #endif #endif /* not lint */ @@ -92,6 +92,7 @@ __RCSID("$NetBSD: mount_fdesc.c,v 1.26 2011/08/29 14:35:00 joerg Exp $"); #include +#include "mountprog.h" #include "mount_fdesc.h" static const struct mntopt mopts[] = { @@ -142,12 +143,7 @@ mount_fdesc_parseargs(int argc, char *argv[], void *dummy, int *mntflags, exit(0); strlcpy(canon_dev, argv[0], MAXPATHLEN); - if (realpath(argv[1], canon_dir) == NULL) /* Check mounton path */ - err(1, "realpath %s", argv[1]); - if (strncmp(argv[1], canon_dir, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", argv[1]); - warnx("using \"%s\" instead.", canon_dir); - } + pathadj(argv[1], canon_dir); } int diff --git a/sbin/mount_filecore/Makefile b/sbin/mount_filecore/Makefile index 93681883e403..91c90ee7c17f 100644 --- a/sbin/mount_filecore/Makefile +++ b/sbin/mount_filecore/Makefile @@ -1,11 +1,11 @@ -# $NetBSD: Makefile,v 1.8 2005/06/27 01:00:05 christos Exp $ +# $NetBSD: Makefile,v 1.9 2020/07/26 08:20:22 mlelstv Exp $ # # Makefile 1.0 1998/6/26 .include PROG= mount_filecore -SRCS= mount_filecore.c fattr.c +SRCS= mount_filecore.c fattr.c pathadj.c MAN= mount_filecore.8 MOUNT= ${NETBSDSRCDIR}/sbin/mount diff --git a/sbin/mount_filecore/mount_filecore.c b/sbin/mount_filecore/mount_filecore.c index 0fcd0cf84984..d60f8526d1de 100644 --- a/sbin/mount_filecore/mount_filecore.c +++ b/sbin/mount_filecore/mount_filecore.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_filecore.c,v 1.20 2011/08/29 14:35:01 joerg Exp $ */ +/* $NetBSD: mount_filecore.c,v 1.21 2020/07/26 08:20:22 mlelstv Exp $ */ /* * Copyright (c) 1992, 1993, 1994 The Regents of the University of California. @@ -165,24 +165,11 @@ mount_filecore(int argc, char **argv) if (argc != 2) usage(); - dev = argv[0]; - dir = argv[1]; + pathadj(argv[0], canon_dev); + dev = canon_dev; - if (realpath(dev, canon_dev) == NULL) /* Check device path */ - err(1, "realpath %s", dev); - if (strncmp(dev, canon_dev, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", dev); - dev = canon_dev; - warnx("using \"%s\" instead.", dev); - } - - if (realpath(dir, canon_dir) == NULL) /* Check mounton path */ - err(1, "realpath %s", dir); - if (strncmp(dir, canon_dir, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", dir); - dir = canon_dir; - warnx("using \"%s\" instead.", dir); - } + pathadj(argv[0], canon_dir); + dir = canon_dir; #define DEFAULT_ROOTUID -2 /* diff --git a/sbin/mount_kernfs/Makefile b/sbin/mount_kernfs/Makefile index 538bbe957a4b..eff165aaeee6 100644 --- a/sbin/mount_kernfs/Makefile +++ b/sbin/mount_kernfs/Makefile @@ -1,12 +1,16 @@ -# $NetBSD: Makefile,v 1.13 2005/06/27 01:00:06 christos Exp $ +# $NetBSD: Makefile,v 1.14 2020/07/26 08:20:22 mlelstv Exp $ # @(#)Makefile 8.2 (Berkeley) 3/27/94 .include PROG= mount_kernfs -SRCS= mount_kernfs.c +SRCS= mount_kernfs.c pathadj.c MAN= mount_kernfs.8 +MOUNT= ${NETBSDSRCDIR}/sbin/mount +CPPFLAGS+= -I${NETBSDSRCDIR}/sys -I${MOUNT} +.PATH: ${MOUNT} + DPADD+=${LIBUTIL} LDADD+=-lutil diff --git a/sbin/mount_kernfs/mount_kernfs.c b/sbin/mount_kernfs/mount_kernfs.c index af66098686fd..da922221d1e6 100644 --- a/sbin/mount_kernfs/mount_kernfs.c +++ b/sbin/mount_kernfs/mount_kernfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_kernfs.c,v 1.25 2011/08/29 14:35:01 joerg Exp $ */ +/* $NetBSD: mount_kernfs.c,v 1.26 2020/07/26 08:20:22 mlelstv Exp $ */ /* * Copyright (c) 1992, 1993, 1994 @@ -77,7 +77,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\ #if 0 static char sccsid[] = "@(#)mount_kernfs.c 8.3 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: mount_kernfs.c,v 1.25 2011/08/29 14:35:01 joerg Exp $"); +__RCSID("$NetBSD: mount_kernfs.c,v 1.26 2020/07/26 08:20:22 mlelstv Exp $"); #endif #endif /* not lint */ @@ -92,6 +92,7 @@ __RCSID("$NetBSD: mount_kernfs.c,v 1.25 2011/08/29 14:35:01 joerg Exp $"); #include +#include "mountprog.h" #include "mount_kernfs.h" static const struct mntopt mopts[] = { @@ -142,12 +143,7 @@ mount_kernfs_parseargs(int argc, char *argv[], void *dummy, int *mntflags, exit(0); strlcpy(canon_dev, argv[0], MAXPATHLEN); - if (realpath(argv[1], canon_dir) == NULL) /* Check mounton path */ - err(1, "realpath %s", argv[1]); - if (strncmp(argv[1], canon_dir, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", argv[1]); - warnx("using \"%s\" instead.", canon_dir); - } + pathadj(argv[1], canon_dir); } int diff --git a/sbin/mount_null/Makefile b/sbin/mount_null/Makefile index 5f797d9e64cb..42118e5199b1 100644 --- a/sbin/mount_null/Makefile +++ b/sbin/mount_null/Makefile @@ -1,13 +1,15 @@ -# $NetBSD: Makefile,v 1.12 2005/06/27 01:00:06 christos Exp $ +# $NetBSD: Makefile,v 1.13 2020/07/26 08:20:22 mlelstv Exp $ # @(#)Makefile 8.3 (Berkeley) 3/27/94 .include PROG= mount_null -SRCS= mount_null.c +SRCS= mount_null.c pathadj.c MAN= mount_null.8 -CPPFLAGS+= -I${NETBSDSRCDIR}/sys +MOUNT= ${NETBSDSRCDIR}/sbin/mount +CPPFLAGS+= -I${NETBSDSRCDIR}/sys -I${MOUNT} +.PATH: ${MOUNT} DPADD+=${LIBUTIL} LDADD+=-lutil diff --git a/sbin/mount_null/mount_null.c b/sbin/mount_null/mount_null.c index 864d36acb5bc..3d851a4efd5b 100644 --- a/sbin/mount_null/mount_null.c +++ b/sbin/mount_null/mount_null.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_null.c,v 1.20 2016/07/25 04:40:51 erh Exp $ */ +/* $NetBSD: mount_null.c,v 1.21 2020/07/26 08:20:22 mlelstv Exp $ */ /* * Copyright (c) 1992, 1993, 1994 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\ #if 0 static char sccsid[] = "@(#)mount_null.c 8.6 (Berkeley) 4/26/95"; #else -__RCSID("$NetBSD: mount_null.c,v 1.20 2016/07/25 04:40:51 erh Exp $"); +__RCSID("$NetBSD: mount_null.c,v 1.21 2020/07/26 08:20:22 mlelstv Exp $"); #endif #endif /* not lint */ @@ -58,6 +58,8 @@ __RCSID("$NetBSD: mount_null.c,v 1.20 2016/07/25 04:40:51 erh Exp $"); #include +#include "mountprog.h" + static const struct mntopt mopts[] = { MOPT_STDOPTS, MOPT_GETARGS, @@ -102,19 +104,8 @@ mount_null(int argc, char *argv[]) if (argc != 2) usage(); - if (realpath(argv[0], target) == NULL) /* Check device path */ - err(1, "realpath %s", argv[0]); - if (strncmp(argv[0], target, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", argv[0]); - warnx("using \"%s\" instead.", target); - } - - if (realpath(argv[1], canon_dir) == NULL) /* Check mounton path */ - err(1, "realpath %s", argv[1]); - if (strncmp(argv[1], canon_dir, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", argv[1]); - warnx("using \"%s\" instead.", canon_dir); - } + pathadj(argv[0], target); + pathadj(argv[1], canon_dir); if (strcmp(target, canon_dir) == 0) errx(1, "%s (%s) and %s (%s) are identical paths", diff --git a/sbin/mount_overlay/Makefile b/sbin/mount_overlay/Makefile index 69774fdc4695..5cf951c2c507 100644 --- a/sbin/mount_overlay/Makefile +++ b/sbin/mount_overlay/Makefile @@ -1,13 +1,15 @@ -# $NetBSD: Makefile,v 1.5 2005/06/27 01:00:06 christos Exp $ +# $NetBSD: Makefile,v 1.6 2020/07/26 08:20:22 mlelstv Exp $ # @(#)Makefile 8.3 (Berkeley) 3/27/94 .include PROG= mount_overlay -SRCS= mount_overlay.c +SRCS= mount_overlay.c pathadj.c MAN= mount_overlay.8 -CPPFLAGS+= -I${NETBSDSRCDIR}/sys +MOUNT= ${NETBSDSRCDIR}/sbin/mount +CPPFLAGS+= -I${NETBSDSRCDIR}/sys -I${MOUNT} +.PATH: ${MOUNT} DPADD+=${LIBUTIL} LDADD+=-lutil diff --git a/sbin/mount_overlay/mount_overlay.c b/sbin/mount_overlay/mount_overlay.c index a32f915e8d64..6d708af85193 100644 --- a/sbin/mount_overlay/mount_overlay.c +++ b/sbin/mount_overlay/mount_overlay.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_overlay.c,v 1.13 2011/08/29 14:35:02 joerg Exp $ */ +/* $NetBSD: mount_overlay.c,v 1.14 2020/07/26 08:20:22 mlelstv Exp $ */ /* * Copyright (c) 1992, 1993, 1994 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\ #if 0 static char sccsid[] = "@(#)mount_null.c 8.6 (Berkeley) 4/26/95"; #else -__RCSID("$NetBSD: mount_overlay.c,v 1.13 2011/08/29 14:35:02 joerg Exp $"); +__RCSID("$NetBSD: mount_overlay.c,v 1.14 2020/07/26 08:20:22 mlelstv Exp $"); #endif #endif /* not lint */ @@ -58,6 +58,8 @@ __RCSID("$NetBSD: mount_overlay.c,v 1.13 2011/08/29 14:35:02 joerg Exp $"); #include +#include "mountprog.h" + static const struct mntopt mopts[] = { MOPT_STDOPTS, MOPT_GETARGS, @@ -102,19 +104,8 @@ mount_overlay(int argc, char *argv[]) if (argc != 2) usage(); - if (realpath(argv[0], target) == NULL) /* Check device path */ - err(1, "realpath %s", argv[0]); - if (strncmp(argv[0], target, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", argv[0]); - warnx("using \"%s\" instead.", target); - } - - if (realpath(argv[1], canon_dir) == NULL) /* Check mounton path */ - err(1, "realpath %s", argv[1]); - if (strncmp(argv[1], canon_dir, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", argv[1]); - warnx("using \"%s\" instead.", canon_dir); - } + pathadj(argv[0], target); + pathadj(argv[1], canon_dir); args.la.target = target; diff --git a/sbin/mount_procfs/Makefile b/sbin/mount_procfs/Makefile index 692df90bb0db..42462f2c425a 100644 --- a/sbin/mount_procfs/Makefile +++ b/sbin/mount_procfs/Makefile @@ -1,12 +1,16 @@ -# $NetBSD: Makefile,v 1.14 2005/06/27 01:00:06 christos Exp $ +# $NetBSD: Makefile,v 1.15 2020/07/26 08:20:23 mlelstv Exp $ # @(#)Makefile 8.4 (Berkeley) 3/27/94 .include PROG= mount_procfs -SRCS= mount_procfs.c +SRCS= mount_procfs.c pathadj.c MAN= mount_procfs.8 +MOUNT= ${NETBSDSRCDIR}/sbin/mount +CPPFLAGS+= -I${NETBSDSRCDIR}/sys -I${MOUNT} +.PATH: ${MOUNT} + DPADD+=${LIBUTIL} LDADD+=-lutil diff --git a/sbin/mount_procfs/mount_procfs.c b/sbin/mount_procfs/mount_procfs.c index 5e8f56e1f8db..c227d658a12a 100644 --- a/sbin/mount_procfs/mount_procfs.c +++ b/sbin/mount_procfs/mount_procfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_procfs.c,v 1.24 2011/08/29 14:35:02 joerg Exp $ */ +/* $NetBSD: mount_procfs.c,v 1.25 2020/07/26 08:20:23 mlelstv Exp $ */ /* * Copyright (c) 1992, 1993, 1994 @@ -77,7 +77,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\ #if 0 static char sccsid[] = "@(#)mount_procfs.c 8.4 (Berkeley) 4/26/95"; #else -__RCSID("$NetBSD: mount_procfs.c,v 1.24 2011/08/29 14:35:02 joerg Exp $"); +__RCSID("$NetBSD: mount_procfs.c,v 1.25 2020/07/26 08:20:23 mlelstv Exp $"); #endif #endif /* not lint */ @@ -95,6 +95,8 @@ __RCSID("$NetBSD: mount_procfs.c,v 1.24 2011/08/29 14:35:02 joerg Exp $"); #include +#include "mountprog.h" + static const struct mntopt mopts[] = { MOPT_STDOPTS, MOPT_GETARGS, @@ -141,12 +143,7 @@ mount_procfs(int argc, char *argv[]) if (argc != 2) usage(); - if (realpath(argv[1], canon_dir) == NULL) /* Check mounton path */ - err(1, "realpath %s", argv[1]); - if (strncmp(argv[1], canon_dir, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", argv[1]); - warnx("using \"%s\" instead.", canon_dir); - } + pathadj(argv[1], canon_dir); args.version = PROCFS_ARGSVERSION; args.flags = altflags; diff --git a/sbin/mount_ptyfs/Makefile b/sbin/mount_ptyfs/Makefile index 76248ee0c235..eb1c0ec746d9 100644 --- a/sbin/mount_ptyfs/Makefile +++ b/sbin/mount_ptyfs/Makefile @@ -1,12 +1,16 @@ -# $NetBSD: Makefile,v 1.5 2010/06/14 14:42:49 pooka Exp $ +# $NetBSD: Makefile,v 1.6 2020/07/26 08:20:23 mlelstv Exp $ # @(#)Makefile 8.2 (Berkeley) 3/27/94 .include PROG= mount_ptyfs -SRCS= mount_ptyfs.c +SRCS= mount_ptyfs.c pathadj.c MAN= mount_ptyfs.8 +MOUNT= ${NETBSDSRCDIR}/sbin/mount +CPPFLAGS+= -I${NETBSDSRCDIR}/sys -I${MOUNT} +.PATH: ${MOUNT} + DPADD+=${LIBUTIL} LDADD+=-lutil diff --git a/sbin/mount_ptyfs/mount_ptyfs.c b/sbin/mount_ptyfs/mount_ptyfs.c index d504367631db..7dfa3844b0f9 100644 --- a/sbin/mount_ptyfs/mount_ptyfs.c +++ b/sbin/mount_ptyfs/mount_ptyfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_ptyfs.c,v 1.17 2016/09/05 01:09:57 sevan Exp $ */ +/* $NetBSD: mount_ptyfs.c,v 1.18 2020/07/26 08:20:23 mlelstv Exp $ */ /* * Copyright (c) 1992, 1993, 1994 @@ -77,7 +77,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\ #if 0 static char sccsid[] = "@(#)mount_ptyfs.c 8.3 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: mount_ptyfs.c,v 1.17 2016/09/05 01:09:57 sevan Exp $"); +__RCSID("$NetBSD: mount_ptyfs.c,v 1.18 2020/07/26 08:20:23 mlelstv Exp $"); #endif #endif /* not lint */ @@ -98,6 +98,8 @@ __RCSID("$NetBSD: mount_ptyfs.c,v 1.17 2016/09/05 01:09:57 sevan Exp $"); #include +#include "mountprog.h" + #define ALTF_GROUP 0x1 #define ALTF_MODE 0x2 #define ALTF_CHROOT 0x4 /* compat */ @@ -202,12 +204,7 @@ mount_ptyfs(int argc, char *argv[]) if (argc != 2) usage(); - if (realpath(argv[1], canon_dir) == NULL) /* Check mounton path */ - err(1, "realpath %s", argv[1]); - if (strncmp(argv[1], canon_dir, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", argv[1]); - warnx("using \"%s\" instead.", canon_dir); - } + pathadj(argv[1], canon_dir); if (mount(MOUNT_PTYFS, canon_dir, mntflags, &args, sizeof args) == -1) err(1, "ptyfs on %s", canon_dir); diff --git a/sbin/mount_umap/Makefile b/sbin/mount_umap/Makefile index f9c97907ea42..624399a1c3e4 100644 --- a/sbin/mount_umap/Makefile +++ b/sbin/mount_umap/Makefile @@ -1,13 +1,15 @@ -# $NetBSD: Makefile,v 1.11 2005/06/27 01:00:06 christos Exp $ +# $NetBSD: Makefile,v 1.12 2020/07/26 08:20:23 mlelstv Exp $ # @(#)Makefile 8.3 (Berkeley) 3/27/94 .include PROG= mount_umap -SRCS= mount_umap.c +SRCS= mount_umap.c pathadj.c MAN= mount_umap.8 -CPPFLAGS+= -I${NETBSDSRCDIR}/sys +MOUNT= ${NETBSDSRCDIR}/sbin/mount +CPPFLAGS+= -I${NETBSDSRCDIR}/sys -I${MOUNT} +.PATH: ${MOUNT} DPADD+=${LIBUTIL} LDADD+=-lutil diff --git a/sbin/mount_umap/mount_umap.c b/sbin/mount_umap/mount_umap.c index d576c01075f9..767073f2afb4 100644 --- a/sbin/mount_umap/mount_umap.c +++ b/sbin/mount_umap/mount_umap.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_umap.c,v 1.26 2019/08/20 21:18:10 perseant Exp $ */ +/* $NetBSD: mount_umap.c,v 1.27 2020/07/26 08:20:23 mlelstv Exp $ */ /* * Copyright (c) 1992, 1993, 1994 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\ #if 0 static char sccsid[] = "@(#)mount_umap.c 8.5 (Berkeley) 4/26/95"; #else -__RCSID("$NetBSD: mount_umap.c,v 1.26 2019/08/20 21:18:10 perseant Exp $"); +__RCSID("$NetBSD: mount_umap.c,v 1.27 2020/07/26 08:20:23 mlelstv Exp $"); #endif #endif /* not lint */ @@ -60,6 +60,8 @@ __RCSID("$NetBSD: mount_umap.c,v 1.26 2019/08/20 21:18:10 perseant Exp $"); #include +#include "mountprog.h" + #define ROOTUSER 0 /* * This define controls whether any user but the superuser can own and @@ -139,19 +141,8 @@ mount_umap(int argc, char *argv[]) if (argc != 2 || mapfile == NULL || gmapfile == NULL) usage(); - if (realpath(argv[0], source) == NULL) /* Check source path */ - err(1, "realpath %s", argv[0]); - if (strncmp(argv[0], source, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", argv[0]); - warnx("using \"%s\" instead.", source); - } - - if (realpath(argv[1], target) == NULL) /* Check mounton path */ - err(1, "realpath %s", argv[1]); - if (strncmp(argv[1], target, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", argv[1]); - warnx("using \"%s\" instead.", target); - } + pathadj(argv[0], source); + pathadj(argv[1], target); /* Read in uid mapping data. */ if ((fp = fopen(mapfile, "r")) == NULL) diff --git a/sbin/mount_union/Makefile b/sbin/mount_union/Makefile index 80a7853f5c68..c9d051974832 100644 --- a/sbin/mount_union/Makefile +++ b/sbin/mount_union/Makefile @@ -1,13 +1,15 @@ -# $NetBSD: Makefile,v 1.14 2005/06/27 01:00:06 christos Exp $ +# $NetBSD: Makefile,v 1.15 2020/07/26 08:20:23 mlelstv Exp $ # @(#)Makefile 8.4 (Berkeley) 7/13/94 .include PROG= mount_union -SRCS= mount_union.c +SRCS= mount_union.c pathadj.c MAN= mount_union.8 -CPPFLAGS+= -I${NETBSDSRCDIR}/sys +MOUNT= ${NETBSDSRCDIR}/sbin/mount +CPPFLAGS+= -I${NETBSDSRCDIR}/sys -I${MOUNT} +.PATH: ${MOUNT} DPADD+=${LIBUTIL} LDADD+=-lutil diff --git a/sbin/mount_union/mount_union.c b/sbin/mount_union/mount_union.c index 3e02c4eac714..6eab35779679 100644 --- a/sbin/mount_union/mount_union.c +++ b/sbin/mount_union/mount_union.c @@ -1,4 +1,4 @@ -/* $NetBSD: mount_union.c,v 1.22 2011/08/29 14:35:03 joerg Exp $ */ +/* $NetBSD: mount_union.c,v 1.23 2020/07/26 08:20:23 mlelstv Exp $ */ /* * Copyright (c) 1992, 1993, 1994 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\ #if 0 static char sccsid[] = "@(#)mount_union.c 8.6 (Berkeley) 4/26/95"; #else -__RCSID("$NetBSD: mount_union.c,v 1.22 2011/08/29 14:35:03 joerg Exp $"); +__RCSID("$NetBSD: mount_union.c,v 1.23 2020/07/26 08:20:23 mlelstv Exp $"); #endif #endif /* not lint */ @@ -60,6 +60,8 @@ __RCSID("$NetBSD: mount_union.c,v 1.22 2011/08/29 14:35:03 joerg Exp $"); #include +#include "mountprog.h" + static const struct mntopt mopts[] = { MOPT_STDOPTS, MOPT_GETARGS, @@ -112,19 +114,8 @@ mount_union(int argc, char *argv[]) if (argc != 2) usage(); - if (realpath(argv[0], target) == NULL) /* Check device path */ - err(1, "realpath %s", argv[0]); - if (strncmp(argv[0], target, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", argv[0]); - warnx("using \"%s\" instead.", target); - } - - if (realpath(argv[1], canon_dir) == NULL) /* Check mounton path */ - err(1, "realpath %s", argv[1]); - if (strncmp(argv[1], canon_dir, MAXPATHLEN)) { - warnx("\"%s\" is a relative path.", argv[1]); - warnx("using \"%s\" instead.", canon_dir); - } + pathadj(argv[0], target); + pathadj(argv[1], canon_dir); if (subdir(target, canon_dir) || subdir(canon_dir, target)) errx(1, "%s (%s) and %s are not distinct paths",