| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: umount.c,v 1.52 2016/06/26 04:01:30 dholland Exp $ */ | | 1 | /* $NetBSD: umount.c,v 1.53 2020/04/23 04:21:13 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1980, 1989, 1993 | | 4 | * Copyright (c) 1980, 1989, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -29,77 +29,79 @@ | | | @@ -29,77 +29,79 @@ |
29 | * SUCH DAMAGE. | | 29 | * SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | #ifndef lint | | 33 | #ifndef lint |
34 | __COPYRIGHT("@(#) Copyright (c) 1980, 1989, 1993\ | | 34 | __COPYRIGHT("@(#) Copyright (c) 1980, 1989, 1993\ |
35 | The Regents of the University of California. All rights reserved."); | | 35 | The Regents of the University of California. All rights reserved."); |
36 | #endif /* not lint */ | | 36 | #endif /* not lint */ |
37 | | | 37 | |
38 | #ifndef lint | | 38 | #ifndef lint |
39 | #if 0 | | 39 | #if 0 |
40 | static char sccsid[] = "@(#)umount.c 8.8 (Berkeley) 5/8/95"; | | 40 | static char sccsid[] = "@(#)umount.c 8.8 (Berkeley) 5/8/95"; |
41 | #else | | 41 | #else |
42 | __RCSID("$NetBSD: umount.c,v 1.52 2016/06/26 04:01:30 dholland Exp $"); | | 42 | __RCSID("$NetBSD: umount.c,v 1.53 2020/04/23 04:21:13 christos Exp $"); |
43 | #endif | | 43 | #endif |
44 | #endif /* not lint */ | | 44 | #endif /* not lint */ |
45 | | | 45 | |
46 | #include <sys/param.h> | | 46 | #include <sys/param.h> |
47 | #include <sys/stat.h> | | 47 | #include <sys/stat.h> |
48 | #include <sys/mount.h> | | 48 | #include <sys/mount.h> |
49 | #include <sys/time.h> | | 49 | #include <sys/time.h> |
50 | #ifndef SMALL | | 50 | #ifndef SMALL |
51 | #include <sys/socket.h> | | 51 | #include <sys/socket.h> |
52 | | | 52 | |
53 | #include <netdb.h> | | 53 | #include <netdb.h> |
54 | #include <rpc/rpc.h> | | 54 | #include <rpc/rpc.h> |
55 | #include <rpc/pmap_clnt.h> | | 55 | #include <rpc/pmap_clnt.h> |
56 | #include <rpc/pmap_prot.h> | | 56 | #include <rpc/pmap_prot.h> |
57 | #include <nfs/rpcv2.h> | | 57 | #include <nfs/rpcv2.h> |
58 | #include <nfs/nfsmount.h> | | 58 | #include <nfs/nfsmount.h> |
59 | #endif /* !SMALL */ | | 59 | #endif /* !SMALL */ |
60 | | | 60 | |
61 | #include <err.h> | | 61 | #include <err.h> |
62 | #include <errno.h> | | 62 | #include <errno.h> |
63 | #include <fstab.h> | | 63 | #include <fstab.h> |
64 | #include <stdio.h> | | 64 | #include <stdio.h> |
65 | #include <stdlib.h> | | 65 | #include <stdlib.h> |
66 | #include <string.h> | | 66 | #include <string.h> |
67 | #include <unistd.h> | | 67 | #include <unistd.h> |
| | | 68 | #include <util.h> |
68 | | | 69 | |
69 | typedef enum { MNTANY, MNTON, MNTFROM } mntwhat; | | 70 | typedef enum { MNTANY, MNTON, MNTFROM } mntwhat; |
70 | | | 71 | |
71 | #ifndef SMALL | | 72 | #ifndef SMALL |
72 | #include "mountprog.h" | | 73 | #include "mountprog.h" |
73 | | | 74 | |
74 | static int fake, verbose; | | 75 | static int fake, verbose; |
75 | static char *nfshost; | | 76 | static char *nfshost; |
76 | static struct addrinfo *nfshost_ai = NULL; | | 77 | static struct addrinfo *nfshost_ai = NULL; |
77 | | | 78 | |
78 | static int namematch(const struct addrinfo *); | | 79 | static int namematch(const struct addrinfo *); |
79 | static int sacmp(const struct sockaddr *, const struct sockaddr *); | | 80 | static int sacmp(const struct sockaddr *, const struct sockaddr *); |
80 | static int xdr_dir(XDR *, char *); | | 81 | static int xdr_dir(XDR *, char *); |
81 | static const char *getmntproto(const char *); | | 82 | static const char *getmntproto(const char *); |
82 | #endif /* !SMALL */ | | 83 | #endif /* !SMALL */ |
83 | | | 84 | |
84 | static int fflag; | | 85 | static int fflag; |
85 | static char *getmntname(const char *, mntwhat, char **); | | 86 | static char *getmntname(const char *, mntwhat, char **); |
86 | static int umountfs(const char *, const char **, int); | | 87 | static int umountfs(const char *, const char **, int); |
87 | static void usage(void) __dead; | | 88 | static void usage(void) __dead; |
88 | | | 89 | |
89 | int | | 90 | int |
90 | main(int argc, char *argv[]) | | 91 | main(int argc, char *argv[]) |
91 | { | | 92 | { |
92 | int ch, errs, all = 0, raw = 0; | | 93 | int ch, errs, all = 0, raw = 0; |
| | | 94 | char mntfromname[MAXPATHLEN]; |
93 | #ifndef SMALL | | 95 | #ifndef SMALL |
94 | int mnts; | | 96 | int mnts; |
95 | struct statvfs *mntbuf; | | 97 | struct statvfs *mntbuf; |
96 | struct addrinfo hints; | | 98 | struct addrinfo hints; |
97 | #endif /* SMALL */ | | 99 | #endif /* SMALL */ |
98 | const char **typelist = NULL; | | 100 | const char **typelist = NULL; |
99 | | | 101 | |
100 | #ifdef SMALL | | 102 | #ifdef SMALL |
101 | #define OPTS "fR" | | 103 | #define OPTS "fR" |
102 | #else | | 104 | #else |
103 | #define OPTS "AaFfh:Rt:v" | | 105 | #define OPTS "AaFfh:Rt:v" |
104 | #endif | | 106 | #endif |
105 | while ((ch = getopt(argc, argv, OPTS)) != -1) | | 107 | while ((ch = getopt(argc, argv, OPTS)) != -1) |
| @@ -158,29 +160,33 @@ main(int argc, char *argv[]) | | | @@ -158,29 +160,33 @@ main(int argc, char *argv[]) |
158 | if ((mnts = getmntinfo(&mntbuf, ST_NOWAIT)) == 0) { | | 160 | if ((mnts = getmntinfo(&mntbuf, ST_NOWAIT)) == 0) { |
159 | warn("getmntinfo"); | | 161 | warn("getmntinfo"); |
160 | errs = 1; | | 162 | errs = 1; |
161 | } | | 163 | } |
162 | for (errs = 0, mnts--; mnts > 0; mnts--) { | | 164 | for (errs = 0, mnts--; mnts > 0; mnts--) { |
163 | if (checkvfsname(mntbuf[mnts].f_fstypename, typelist)) | | 165 | if (checkvfsname(mntbuf[mnts].f_fstypename, typelist)) |
164 | continue; | | 166 | continue; |
165 | if (umountfs(mntbuf[mnts].f_mntonname, typelist, | | 167 | if (umountfs(mntbuf[mnts].f_mntonname, typelist, |
166 | 1) != 0) | | 168 | 1) != 0) |
167 | errs = 1; | | 169 | errs = 1; |
168 | } | | 170 | } |
169 | } else | | 171 | } else |
170 | #endif /* !SMALL */ | | 172 | #endif /* !SMALL */ |
171 | for (errs = 0; *argv != NULL; ++argv) | | 173 | for (errs = 0; *argv != NULL; ++argv) { |
172 | if (umountfs(*argv, typelist, raw) != 0) | | 174 | if (getfsspecname(mntfromname, sizeof(mntfromname), |
| | | 175 | *argv) == NULL) |
| | | 176 | err(EXIT_FAILURE, "%s", mntfromname); |
| | | 177 | if (umountfs(mntfromname, typelist, raw) != 0) |
173 | errs = 1; | | 178 | errs = 1; |
| | | 179 | } |
174 | return errs; | | 180 | return errs; |
175 | } | | 181 | } |
176 | | | 182 | |
177 | static int | | 183 | static int |
178 | umountfs(const char *name, const char **typelist, int raw) | | 184 | umountfs(const char *name, const char **typelist, int raw) |
179 | { | | 185 | { |
180 | #ifndef SMALL | | 186 | #ifndef SMALL |
181 | enum clnt_stat clnt_stat; | | 187 | enum clnt_stat clnt_stat; |
182 | struct timeval try; | | 188 | struct timeval try; |
183 | CLIENT *clp; | | 189 | CLIENT *clp; |
184 | char *hostp = NULL; | | 190 | char *hostp = NULL; |
185 | struct addrinfo *ai = NULL, hints; | | 191 | struct addrinfo *ai = NULL, hints; |
186 | const char *proto = NULL; | | 192 | const char *proto = NULL; |
| @@ -329,43 +335,47 @@ umountfs(const char *name, const char ** | | | @@ -329,43 +335,47 @@ umountfs(const char *name, const char ** |
329 | } | | 335 | } |
330 | auth_destroy(clp->cl_auth); | | 336 | auth_destroy(clp->cl_auth); |
331 | clnt_destroy(clp); | | 337 | clnt_destroy(clp); |
332 | } | | 338 | } |
333 | #endif /* ! SMALL */ | | 339 | #endif /* ! SMALL */ |
334 | return 0; | | 340 | return 0; |
335 | } | | 341 | } |
336 | | | 342 | |
337 | static char * | | 343 | static char * |
338 | getmntname(const char *name, mntwhat what, char **type) | | 344 | getmntname(const char *name, mntwhat what, char **type) |
339 | { | | 345 | { |
340 | static struct statvfs *mntbuf; | | 346 | static struct statvfs *mntbuf; |
341 | static int mntsize; | | 347 | static int mntsize; |
| | | 348 | static char mntfromname[MAXPATHLEN]; |
342 | int i; | | 349 | int i; |
343 | | | 350 | |
344 | if (mntbuf == NULL && | | 351 | if (mntbuf == NULL && |
345 | (mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) { | | 352 | (mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) { |
346 | warn("getmntinfo"); | | 353 | warn("getmntinfo"); |
347 | return (NULL); | | 354 | return (NULL); |
348 | } | | 355 | } |
349 | for (i = mntsize - 1; i >= 0; i--) { | | 356 | for (i = mntsize - 1; i >= 0; i--) { |
350 | if ((what == MNTON) && !strcmp(mntbuf[i].f_mntfromname, name)) { | | 357 | if ((what == MNTON) && !strcmp(mntbuf[i].f_mntfromname, name)) { |
351 | if (type) | | 358 | if (type) |
352 | *type = mntbuf[i].f_fstypename; | | 359 | *type = mntbuf[i].f_fstypename; |
353 | return (mntbuf[i].f_mntonname); | | 360 | return (mntbuf[i].f_mntonname); |
354 | } | | 361 | } |
355 | if ((what == MNTFROM) && !strcmp(mntbuf[i].f_mntonname, name)) { | | 362 | if ((what == MNTFROM) && !strcmp(mntbuf[i].f_mntonname, name)) { |
356 | if (type) | | 363 | if (type) |
357 | *type = mntbuf[i].f_fstypename; | | 364 | *type = mntbuf[i].f_fstypename; |
358 | return (mntbuf[i].f_mntfromname); | | 365 | if (getfsspecname(mntfromname, sizeof(mntfromname), |
| | | 366 | mntbuf[i].f_mntfromname) == NULL) |
| | | 367 | err(EXIT_FAILURE, "%s", mntfromname); |
| | | 368 | return mntfromname; |
359 | } | | 369 | } |
360 | } | | 370 | } |
361 | return (NULL); | | 371 | return (NULL); |
362 | } | | 372 | } |
363 | | | 373 | |
364 | #ifndef SMALL | | 374 | #ifndef SMALL |
365 | static int | | 375 | static int |
366 | sacmp(const struct sockaddr *sa1, const struct sockaddr *sa2) | | 376 | sacmp(const struct sockaddr *sa1, const struct sockaddr *sa2) |
367 | { | | 377 | { |
368 | const void *p1, *p2; | | 378 | const void *p1, *p2; |
369 | size_t len; | | 379 | size_t len; |
370 | | | 380 | |
371 | if (sa1->sa_family != sa2->sa_family) | | 381 | if (sa1->sa_family != sa2->sa_family) |