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.
thorpej-futex
mlelstv 2020-07-26 08:20:22 +00:00
parent 1b968d3ccf
commit fd33bfb7f2
23 changed files with 118 additions and 164 deletions

View File

@ -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);
}
}

View File

@ -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 <bsd.own.mk>
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

View File

@ -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 <sys/cdefs.h>
#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 <sys/param.h>
@ -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) {

View File

@ -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 <bsd.own.mk>
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

View File

@ -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 <sys/cdefs.h>
#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 <sys/param.h>
@ -46,6 +46,7 @@ __RCSID("$NetBSD: mount_autofs.c,v 1.4 2019/11/20 17:18:35 tkusumi Exp $");
#include <fs/autofs/autofs_mount.h>
#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

View File

@ -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 <bsd.own.mk>
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

View File

@ -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 <mntopts.h>
#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

View File

@ -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 <bsd.own.mk>
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

View File

@ -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
/*

View File

@ -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 <bsd.own.mk>
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

View File

@ -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 <mntopts.h>
#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

View File

@ -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 <bsd.own.mk>
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

View File

@ -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 <mntopts.h>
#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",

View File

@ -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 <bsd.own.mk>
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

View File

@ -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 <mntopts.h>
#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;

View File

@ -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 <bsd.own.mk>
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

View File

@ -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 <mntopts.h>
#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;

View File

@ -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 <bsd.own.mk>
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

View File

@ -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 <mntopts.h>
#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);

View File

@ -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 <bsd.own.mk>
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

View File

@ -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 <mntopts.h>
#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)

View File

@ -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 <bsd.own.mk>
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

View File

@ -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 <mntopts.h>
#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",