2017-11-27 15:37:16 +00:00
|
|
|
/*-
|
2023-05-10 15:40:58 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2017-11-27 15:37:16 +00:00
|
|
|
*
|
1999-11-21 08:06:00 +00:00
|
|
|
* Copyright (c) 1999 Martin Blapp
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] =
|
|
|
|
"$FreeBSD$";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ucred.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
|
|
|
|
#include <rpc/rpc.h>
|
2009-06-24 18:42:21 +00:00
|
|
|
#include <rpcsvc/mount.h>
|
1999-11-21 08:06:00 +00:00
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "mounttab.h"
|
|
|
|
|
|
|
|
int verbose;
|
|
|
|
|
|
|
|
static int do_umount (char *, char *);
|
|
|
|
static int do_umntall (char *);
|
|
|
|
static int is_mounted (char *, char *);
|
|
|
|
static void usage (void);
|
|
|
|
int xdr_dir (XDR *, char *);
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv) {
|
|
|
|
int ch, keep, success, pathlen;
|
2001-07-22 01:25:25 +00:00
|
|
|
time_t expire, now;
|
1999-11-21 08:06:00 +00:00
|
|
|
char *host, *path;
|
|
|
|
struct mtablist *mtab;
|
|
|
|
|
|
|
|
expire = 0;
|
2001-07-22 01:25:25 +00:00
|
|
|
host = path = NULL;
|
1999-11-21 08:06:00 +00:00
|
|
|
success = keep = verbose = 0;
|
|
|
|
while ((ch = getopt(argc, argv, "h:kp:ve:")) != -1)
|
|
|
|
switch (ch) {
|
|
|
|
case 'h':
|
|
|
|
host = optarg;
|
|
|
|
break;
|
|
|
|
case 'e':
|
2001-06-16 07:15:48 +00:00
|
|
|
expire = atoi(optarg);
|
1999-11-21 08:06:00 +00:00
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
keep = 1;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
path = optarg;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose = 1;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
usage();
|
|
|
|
default:
|
2003-04-27 07:09:33 +00:00
|
|
|
break;
|
1999-11-21 08:06:00 +00:00
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2000-01-15 14:28:14 +00:00
|
|
|
/* Default expiretime is one day */
|
1999-11-21 08:06:00 +00:00
|
|
|
if (expire == 0)
|
2000-01-15 14:28:14 +00:00
|
|
|
expire = 86400;
|
2001-07-22 01:25:25 +00:00
|
|
|
time(&now);
|
|
|
|
|
|
|
|
/* Read PATH_MOUNTTAB. */
|
2001-07-22 12:17:51 +00:00
|
|
|
if (!read_mtab()) {
|
2001-07-22 01:25:25 +00:00
|
|
|
if (verbose)
|
|
|
|
warnx("no mounttab entries (%s does not exist)",
|
|
|
|
PATH_MOUNTTAB);
|
|
|
|
mtabhead = NULL;
|
|
|
|
}
|
|
|
|
|
1999-11-21 08:06:00 +00:00
|
|
|
if (host == NULL && path == NULL) {
|
2001-07-22 01:25:25 +00:00
|
|
|
/* Check each entry and do any necessary unmount RPCs. */
|
1999-11-21 08:06:00 +00:00
|
|
|
for (mtab = mtabhead; mtab != NULL; mtab = mtab->mtab_next) {
|
2001-07-22 01:25:25 +00:00
|
|
|
if (*mtab->mtab_host == '\0')
|
|
|
|
continue;
|
|
|
|
if (mtab->mtab_time + expire < now) {
|
|
|
|
/* Clear expired entry. */
|
|
|
|
if (verbose)
|
|
|
|
warnx("remove expired entry %s:%s",
|
|
|
|
mtab->mtab_host, mtab->mtab_dirp);
|
|
|
|
bzero(mtab->mtab_host,
|
|
|
|
sizeof(mtab->mtab_host));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (keep && is_mounted(mtab->mtab_host,
|
|
|
|
mtab->mtab_dirp)) {
|
|
|
|
if (verbose)
|
|
|
|
warnx("skip entry %s:%s",
|
|
|
|
mtab->mtab_host, mtab->mtab_dirp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (do_umount(mtab->mtab_host, mtab->mtab_dirp)) {
|
|
|
|
if (verbose)
|
|
|
|
warnx("umount RPC for %s:%s succeeded",
|
|
|
|
mtab->mtab_host, mtab->mtab_dirp);
|
|
|
|
/* Remove all entries for this host + path. */
|
2001-07-22 12:17:51 +00:00
|
|
|
clean_mtab(mtab->mtab_host, mtab->mtab_dirp,
|
|
|
|
verbose);
|
1999-11-21 08:06:00 +00:00
|
|
|
}
|
|
|
|
}
|
2001-07-22 01:25:25 +00:00
|
|
|
success = 1;
|
|
|
|
} else {
|
|
|
|
if (host == NULL && path != NULL)
|
|
|
|
/* Missing hostname. */
|
|
|
|
usage();
|
|
|
|
if (path == NULL) {
|
|
|
|
/* Do a RPC UMNTALL for this specific host */
|
|
|
|
success = do_umntall(host);
|
|
|
|
if (verbose && success)
|
|
|
|
warnx("umntall RPC for %s succeeded", host);
|
|
|
|
} else {
|
|
|
|
/* Do a RPC UMNTALL for this specific mount */
|
|
|
|
for (pathlen = strlen(path);
|
|
|
|
pathlen > 1 && path[pathlen - 1] == '/'; pathlen--)
|
|
|
|
path[pathlen - 1] = '\0';
|
|
|
|
success = do_umount(host, path);
|
|
|
|
if (verbose && success)
|
|
|
|
warnx("umount RPC for %s:%s succeeded", host,
|
|
|
|
path);
|
1999-11-21 08:06:00 +00:00
|
|
|
}
|
2001-07-22 01:25:25 +00:00
|
|
|
/* If successful, remove any corresponding mounttab entries. */
|
|
|
|
if (success)
|
2001-07-22 12:17:51 +00:00
|
|
|
clean_mtab(host, path, verbose);
|
1999-11-21 08:06:00 +00:00
|
|
|
}
|
2001-07-22 01:25:25 +00:00
|
|
|
/* Write and unlink PATH_MOUNTTAB if necessary */
|
|
|
|
if (success)
|
2001-07-22 12:17:51 +00:00
|
|
|
success = write_mtab(verbose);
|
1999-11-21 08:06:00 +00:00
|
|
|
free_mtab();
|
2001-07-22 01:25:25 +00:00
|
|
|
exit (success ? 0 : 1);
|
1999-11-21 08:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a RPC_MNT UMNTALL request to hostname.
|
1999-12-08 22:29:30 +00:00
|
|
|
* XXX This works for all mountd implementations,
|
|
|
|
* but produces a RPC IOERR on non FreeBSD systems.
|
1999-11-21 08:06:00 +00:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
do_umntall(char *hostname) {
|
|
|
|
enum clnt_stat clnt_stat;
|
Bring in a hybrid of SunSoft's transport-independent RPC (TI-RPC) and
associated changes that had to happen to make this possible as well as
bugs fixed along the way.
Bring in required TLI library routines to support this.
Since we don't support TLI we've essentially copied what NetBSD
has done, adding a thin layer to emulate direct the TLI calls
into BSD socket calls.
This is mostly from Sun's tirpc release that was made in 1994,
however some fixes were backported from the 1999 release (supposedly
only made available after this porting effort was underway).
The submitter has agreed to continue on and bring us up to the
1999 release.
Several key features are introduced with this update:
Client calls are thread safe. (1999 code has server side thread
safe)
Updated, a more modern interface.
Many userland updates were done to bring the code up to par with
the recent RPC API.
There is an update to the pthreads library, a function
pthread_main_np() was added to emulate a function of Sun's threads
library.
While we're at it, bring in NetBSD's lockd, it's been far too
long of a wait.
New rpcbind(8) replaces portmap(8) (supporting communication over
an authenticated Unix-domain socket, and by default only allowing
set and unset requests over that channel). It's much more secure
than the old portmapper.
Umount(8), mountd(8), mount_nfs(8), nfsd(8) have also been upgraded
to support TI-RPC and to support IPV6.
Umount(8) is also fixed to unmount pathnames longer than 80 chars,
which are currently truncated by the Kernel statfs structure.
Submitted by: Martin Blapp <mb@imp.ch>
Manpage review: ru
Secure RPC implemented by: wpaul
2001-03-19 12:50:13 +00:00
|
|
|
struct timeval try;
|
1999-11-21 08:06:00 +00:00
|
|
|
CLIENT *clp;
|
|
|
|
|
2005-05-27 00:05:16 +00:00
|
|
|
try.tv_sec = 3;
|
|
|
|
try.tv_usec = 0;
|
2009-06-24 18:42:21 +00:00
|
|
|
clp = clnt_create_timed(hostname, MOUNTPROG, MOUNTVERS, "udp",
|
2005-05-27 00:05:16 +00:00
|
|
|
&try);
|
2001-07-22 01:25:25 +00:00
|
|
|
if (clp == NULL) {
|
2009-06-24 18:42:21 +00:00
|
|
|
warnx("%s: %s", hostname, clnt_spcreateerror("MOUNTPROG"));
|
2001-08-02 21:46:21 +00:00
|
|
|
return (0);
|
1999-11-21 08:06:00 +00:00
|
|
|
}
|
|
|
|
clp->cl_auth = authunix_create_default();
|
2009-06-24 18:42:21 +00:00
|
|
|
clnt_stat = clnt_call(clp, MOUNTPROC_UMNTALL,
|
2003-10-26 06:14:10 +00:00
|
|
|
(xdrproc_t)xdr_void, (caddr_t)0,
|
|
|
|
(xdrproc_t)xdr_void, (caddr_t)0, try);
|
2001-08-02 21:46:21 +00:00
|
|
|
if (clnt_stat != RPC_SUCCESS)
|
2009-06-24 18:42:21 +00:00
|
|
|
warnx("%s: %s", hostname, clnt_sperror(clp, "MOUNTPROC_UMNTALL"));
|
2001-08-02 21:46:21 +00:00
|
|
|
auth_destroy(clp->cl_auth);
|
|
|
|
clnt_destroy(clp);
|
|
|
|
return (clnt_stat == RPC_SUCCESS);
|
1999-11-21 08:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a RPC_MNT UMOUNT request for dirp to hostname.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
do_umount(char *hostname, char *dirp) {
|
|
|
|
enum clnt_stat clnt_stat;
|
Bring in a hybrid of SunSoft's transport-independent RPC (TI-RPC) and
associated changes that had to happen to make this possible as well as
bugs fixed along the way.
Bring in required TLI library routines to support this.
Since we don't support TLI we've essentially copied what NetBSD
has done, adding a thin layer to emulate direct the TLI calls
into BSD socket calls.
This is mostly from Sun's tirpc release that was made in 1994,
however some fixes were backported from the 1999 release (supposedly
only made available after this porting effort was underway).
The submitter has agreed to continue on and bring us up to the
1999 release.
Several key features are introduced with this update:
Client calls are thread safe. (1999 code has server side thread
safe)
Updated, a more modern interface.
Many userland updates were done to bring the code up to par with
the recent RPC API.
There is an update to the pthreads library, a function
pthread_main_np() was added to emulate a function of Sun's threads
library.
While we're at it, bring in NetBSD's lockd, it's been far too
long of a wait.
New rpcbind(8) replaces portmap(8) (supporting communication over
an authenticated Unix-domain socket, and by default only allowing
set and unset requests over that channel). It's much more secure
than the old portmapper.
Umount(8), mountd(8), mount_nfs(8), nfsd(8) have also been upgraded
to support TI-RPC and to support IPV6.
Umount(8) is also fixed to unmount pathnames longer than 80 chars,
which are currently truncated by the Kernel statfs structure.
Submitted by: Martin Blapp <mb@imp.ch>
Manpage review: ru
Secure RPC implemented by: wpaul
2001-03-19 12:50:13 +00:00
|
|
|
struct timeval try;
|
1999-11-21 08:06:00 +00:00
|
|
|
CLIENT *clp;
|
Bring in a hybrid of SunSoft's transport-independent RPC (TI-RPC) and
associated changes that had to happen to make this possible as well as
bugs fixed along the way.
Bring in required TLI library routines to support this.
Since we don't support TLI we've essentially copied what NetBSD
has done, adding a thin layer to emulate direct the TLI calls
into BSD socket calls.
This is mostly from Sun's tirpc release that was made in 1994,
however some fixes were backported from the 1999 release (supposedly
only made available after this porting effort was underway).
The submitter has agreed to continue on and bring us up to the
1999 release.
Several key features are introduced with this update:
Client calls are thread safe. (1999 code has server side thread
safe)
Updated, a more modern interface.
Many userland updates were done to bring the code up to par with
the recent RPC API.
There is an update to the pthreads library, a function
pthread_main_np() was added to emulate a function of Sun's threads
library.
While we're at it, bring in NetBSD's lockd, it's been far too
long of a wait.
New rpcbind(8) replaces portmap(8) (supporting communication over
an authenticated Unix-domain socket, and by default only allowing
set and unset requests over that channel). It's much more secure
than the old portmapper.
Umount(8), mountd(8), mount_nfs(8), nfsd(8) have also been upgraded
to support TI-RPC and to support IPV6.
Umount(8) is also fixed to unmount pathnames longer than 80 chars,
which are currently truncated by the Kernel statfs structure.
Submitted by: Martin Blapp <mb@imp.ch>
Manpage review: ru
Secure RPC implemented by: wpaul
2001-03-19 12:50:13 +00:00
|
|
|
|
2005-05-27 00:05:16 +00:00
|
|
|
try.tv_sec = 3;
|
|
|
|
try.tv_usec = 0;
|
2009-06-24 18:42:21 +00:00
|
|
|
clp = clnt_create_timed(hostname, MOUNTPROG, MOUNTVERS, "udp",
|
2005-05-27 00:05:16 +00:00
|
|
|
&try);
|
Bring in a hybrid of SunSoft's transport-independent RPC (TI-RPC) and
associated changes that had to happen to make this possible as well as
bugs fixed along the way.
Bring in required TLI library routines to support this.
Since we don't support TLI we've essentially copied what NetBSD
has done, adding a thin layer to emulate direct the TLI calls
into BSD socket calls.
This is mostly from Sun's tirpc release that was made in 1994,
however some fixes were backported from the 1999 release (supposedly
only made available after this porting effort was underway).
The submitter has agreed to continue on and bring us up to the
1999 release.
Several key features are introduced with this update:
Client calls are thread safe. (1999 code has server side thread
safe)
Updated, a more modern interface.
Many userland updates were done to bring the code up to par with
the recent RPC API.
There is an update to the pthreads library, a function
pthread_main_np() was added to emulate a function of Sun's threads
library.
While we're at it, bring in NetBSD's lockd, it's been far too
long of a wait.
New rpcbind(8) replaces portmap(8) (supporting communication over
an authenticated Unix-domain socket, and by default only allowing
set and unset requests over that channel). It's much more secure
than the old portmapper.
Umount(8), mountd(8), mount_nfs(8), nfsd(8) have also been upgraded
to support TI-RPC and to support IPV6.
Umount(8) is also fixed to unmount pathnames longer than 80 chars,
which are currently truncated by the Kernel statfs structure.
Submitted by: Martin Blapp <mb@imp.ch>
Manpage review: ru
Secure RPC implemented by: wpaul
2001-03-19 12:50:13 +00:00
|
|
|
if (clp == NULL) {
|
2009-06-24 18:42:21 +00:00
|
|
|
warnx("%s: %s", hostname, clnt_spcreateerror("MOUNTPROG"));
|
2001-08-02 21:46:21 +00:00
|
|
|
return (0);
|
1999-11-21 08:06:00 +00:00
|
|
|
}
|
Bring in a hybrid of SunSoft's transport-independent RPC (TI-RPC) and
associated changes that had to happen to make this possible as well as
bugs fixed along the way.
Bring in required TLI library routines to support this.
Since we don't support TLI we've essentially copied what NetBSD
has done, adding a thin layer to emulate direct the TLI calls
into BSD socket calls.
This is mostly from Sun's tirpc release that was made in 1994,
however some fixes were backported from the 1999 release (supposedly
only made available after this porting effort was underway).
The submitter has agreed to continue on and bring us up to the
1999 release.
Several key features are introduced with this update:
Client calls are thread safe. (1999 code has server side thread
safe)
Updated, a more modern interface.
Many userland updates were done to bring the code up to par with
the recent RPC API.
There is an update to the pthreads library, a function
pthread_main_np() was added to emulate a function of Sun's threads
library.
While we're at it, bring in NetBSD's lockd, it's been far too
long of a wait.
New rpcbind(8) replaces portmap(8) (supporting communication over
an authenticated Unix-domain socket, and by default only allowing
set and unset requests over that channel). It's much more secure
than the old portmapper.
Umount(8), mountd(8), mount_nfs(8), nfsd(8) have also been upgraded
to support TI-RPC and to support IPV6.
Umount(8) is also fixed to unmount pathnames longer than 80 chars,
which are currently truncated by the Kernel statfs structure.
Submitted by: Martin Blapp <mb@imp.ch>
Manpage review: ru
Secure RPC implemented by: wpaul
2001-03-19 12:50:13 +00:00
|
|
|
clp->cl_auth = authsys_create_default();
|
2009-06-24 18:42:21 +00:00
|
|
|
clnt_stat = clnt_call(clp, MOUNTPROC_UMNT, (xdrproc_t)xdr_dir, dirp,
|
2003-10-26 06:14:10 +00:00
|
|
|
(xdrproc_t)xdr_void, (caddr_t)0, try);
|
2001-08-02 21:46:21 +00:00
|
|
|
if (clnt_stat != RPC_SUCCESS)
|
2009-06-24 18:42:21 +00:00
|
|
|
warnx("%s: %s", hostname, clnt_sperror(clp, "MOUNTPROC_UMNT"));
|
2001-08-02 21:46:21 +00:00
|
|
|
auth_destroy(clp->cl_auth);
|
|
|
|
clnt_destroy(clp);
|
|
|
|
return (clnt_stat == RPC_SUCCESS);
|
1999-11-21 08:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the entry is still/already mounted.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
is_mounted(char *hostname, char *dirp) {
|
|
|
|
struct statfs *mntbuf;
|
|
|
|
char name[MNAMELEN + 1];
|
2001-07-22 01:25:25 +00:00
|
|
|
size_t bufsize;
|
1999-11-21 08:06:00 +00:00
|
|
|
int mntsize, i;
|
|
|
|
|
2001-07-22 01:25:25 +00:00
|
|
|
if (strlen(hostname) + strlen(dirp) >= MNAMELEN)
|
1999-11-21 08:06:00 +00:00
|
|
|
return (0);
|
2001-07-22 01:25:25 +00:00
|
|
|
snprintf(name, sizeof(name), "%s:%s", hostname, dirp);
|
1999-11-21 08:06:00 +00:00
|
|
|
mntsize = getfsstat(NULL, 0, MNT_NOWAIT);
|
|
|
|
if (mntsize <= 0)
|
|
|
|
return (0);
|
|
|
|
bufsize = (mntsize + 1) * sizeof(struct statfs);
|
|
|
|
if ((mntbuf = malloc(bufsize)) == NULL)
|
|
|
|
err(1, "malloc");
|
|
|
|
mntsize = getfsstat(mntbuf, (long)bufsize, MNT_NOWAIT);
|
|
|
|
for (i = mntsize - 1; i >= 0; i--) {
|
|
|
|
if (strcmp(mntbuf[i].f_mntfromname, name) == 0) {
|
|
|
|
free(mntbuf);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(mntbuf);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* xdr routines for mount rpc's
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xdr_dir(XDR *xdrsp, char *dirp) {
|
2009-06-24 18:42:21 +00:00
|
|
|
return (xdr_string(xdrsp, &dirp, MNTPATHLEN));
|
1999-11-21 08:06:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-04-24 15:53:49 +00:00
|
|
|
usage(void)
|
|
|
|
{
|
1999-11-21 08:06:00 +00:00
|
|
|
(void)fprintf(stderr, "%s\n",
|
2001-07-22 01:25:25 +00:00
|
|
|
"usage: rpc.umntall [-kv] [-e expire] [-h host] [-p path]");
|
1999-11-21 08:06:00 +00:00
|
|
|
exit(1);
|
|
|
|
}
|