diff options
author | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1996-03-21 00:16:44 +0000 |
---|---|---|
committer | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1996-03-21 00:16:44 +0000 |
commit | 05e8dd7eaf3b1fb4e2b46d3071635564a32b3a65 (patch) | |
tree | 2a786cff8909848ba40e0bfcc14d5609c5004dc9 | |
parent | 20811e65105f4845cc07c8c25d9248c312b95cd1 (diff) |
From NetBSD: Merge of 960317
29 files changed, 1932 insertions, 460 deletions
diff --git a/sbin/Makefile b/sbin/Makefile index a4bf43886ce..c99bfdc7ab4 100644 --- a/sbin/Makefile +++ b/sbin/Makefile @@ -1,4 +1,5 @@ -# $NetBSD: Makefile,v 1.25 1995/10/10 21:42:00 gwr Exp $ +# $OpenBSD: Makefile,v 1.3 1996/03/21 00:15:18 niklas Exp $ +# $NetBSD: Makefile,v 1.26 1996/03/16 10:29:36 leo Exp $ # @(#)Makefile 8.5 (Berkeley) 3/31/94 # Not ported: XNSrouted enpload scsiformat startslip @@ -6,8 +7,15 @@ SUBDIR= badsect disklabel ccdconfig dmesg fastboot ifconfig init ipf \ ipfstat mknod modload modunload mount mountd nfsd nfsiod nologin \ - ping quotacheck reboot route routed savecore shutdown slattach \ - swapon ttyflags umount + ping quotacheck reboot route routed shutdown slattach swapon \ + ttyflags umount + +# XXX Temporarely until all ports are able to use savecore (leo) +.if (${MACHINE} == "atari") +SUBDIR+= savecore +.else +SUBDIR+= savecore.old +.endif # support for various file systems SUBDIR+= mount_ados diff --git a/sbin/ccdconfig/ccdconfig.8 b/sbin/ccdconfig/ccdconfig.8 index c59b9f2b179..d3bf184dd84 100644 --- a/sbin/ccdconfig/ccdconfig.8 +++ b/sbin/ccdconfig/ccdconfig.8 @@ -1,8 +1,12 @@ -.\" $NetBSD: ccdconfig.8,v 1.1.2.1 1995/11/11 02:43:33 thorpej Exp $ +.\" $OpenBSD: ccdconfig.8,v 1.3 1996/03/21 00:15:23 niklas Exp $ +.\" $NetBSD: ccdconfig.8,v 1.4 1996/02/28 01:01:17 thorpej Exp $ .\" -.\" Copyright (c) 1995 Jason R. Thorpe. +.\" Copyright (c) 1996 The NetBSD Foundation, Inc. .\" All rights reserved. .\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Jason R. Thorpe. +.\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: @@ -13,22 +17,23 @@ .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: -.\" This product includes software developed for the NetBSD Project -.\" by Jason R. Thorpe. -.\" 4. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. +.\" This product includes software developed by the NetBSD +.\" Foundation, Inc. and its contributors. +.\" 4. Neither the name of The NetBSD Foundation nor the names of its +.\" contributors may be used to endorse or promote products derived +.\" from this software without specific prior written permission. .\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 REGENTS 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. .\" .Dd July 17, 1995 .Dt CCDCONFIG 8 @@ -117,6 +122,7 @@ The flags are as follows: .Bd -unfilled -offset indent CCDF_SWAP 0x01 Interleave should be dmmax CCDF_UNIFORM 0x02 Use uniform interleave +CCDF_MIRROR 0x04 Enable data mirroring .Ed .Pp The format in the diff --git a/sbin/ccdconfig/ccdconfig.c b/sbin/ccdconfig/ccdconfig.c index 35f27f7b9df..3c6fe5415e8 100644 --- a/sbin/ccdconfig/ccdconfig.c +++ b/sbin/ccdconfig/ccdconfig.c @@ -1,9 +1,13 @@ -/* $NetBSD: ccdconfig.c,v 1.2.2.1 1995/11/11 02:43:35 thorpej Exp $ */ +/* $OpenBSD: ccdconfig.c,v 1.3 1996/03/21 00:15:24 niklas Exp $ */ +/* $NetBSD: ccdconfig.c,v 1.5 1996/02/28 01:01:18 thorpej Exp $ */ -/* - * Copyright (c) 1995 Jason R. Thorpe. +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. * All rights reserved. * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -14,22 +18,23 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed for the NetBSD Project - * by Jason R. Thorpe. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 REGENTS 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. */ #include <sys/param.h> @@ -70,6 +75,7 @@ struct flagval { } flagvaltab[] = { { "CCDF_SWAP", CCDF_SWAP }, { "CCDF_UNIFORM", CCDF_UNIFORM }, + { "CCDF_MIRROR", CCDF_MIRROR }, { NULL, 0 }, }; diff --git a/sbin/ccdconfig/pathnames.h b/sbin/ccdconfig/pathnames.h index f8da9e08e7c..c1519b96fac 100644 --- a/sbin/ccdconfig/pathnames.h +++ b/sbin/ccdconfig/pathnames.h @@ -1,9 +1,13 @@ -/* $NetBSD: pathnames.h,v 1.1 1995/08/17 16:37:20 thorpej Exp $ */ +/* $OpenBSD: pathnames.h,v 1.2 1996/03/21 00:15:27 niklas Exp $ */ +/* $NetBSD: pathnames.h,v 1.2 1996/02/28 01:01:20 thorpej Exp $ */ -/* - * Copyright (c) 1995 Jason R. Thorpe. +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. * All rights reserved. * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -14,22 +18,23 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed for the NetBSD Project - * by Jason R. Thorpe. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 REGENTS 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. */ #define _PATH_CCDCONF "/etc/ccd.conf" diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c index 98845511b14..8fa18e54317 100644 --- a/sbin/disklabel/disklabel.c +++ b/sbin/disklabel/disklabel.c @@ -1,4 +1,5 @@ -/* $NetBSD: disklabel.c,v 1.29 1995/06/26 23:17:26 jtc Exp $ */ +/* $OpenBSD: disklabel.c,v 1.3 1996/03/21 00:15:31 niklas Exp $ */ +/* $NetBSD: disklabel.c,v 1.30 1996/03/14 19:49:24 ghudson Exp $ */ /* * Copyright (c) 1987, 1993 @@ -47,7 +48,7 @@ static char copyright[] = /* from static char sccsid[] = "@(#)disklabel.c 1.2 (Symmetric) 11/28/85"; */ static char sccsid[] = "@(#)disklabel.c 8.2 (Berkeley) 1/7/94"; #else -static char rcsid[] = "$NetBSD: disklabel.c,v 1.29 1995/06/26 23:17:26 jtc Exp $"; +static char rcsid[] = "$NetBSD: disklabel.c,v 1.30 1996/03/14 19:49:24 ghudson Exp $"; #endif #endif /* not lint */ @@ -781,17 +782,20 @@ display(f, lp) if (lp->d_flags & D_BADSECT) fprintf(f, " badsect"); fprintf(f, "\n"); - fprintf(f, "bytes/sector: %d\n", lp->d_secsize); - fprintf(f, "sectors/track: %d\n", lp->d_nsectors); - fprintf(f, "tracks/cylinder: %d\n", lp->d_ntracks); - fprintf(f, "sectors/cylinder: %d\n", lp->d_secpercyl); - fprintf(f, "cylinders: %d\n", lp->d_ncylinders); - fprintf(f, "rpm: %d\n", lp->d_rpm); - fprintf(f, "interleave: %d\n", lp->d_interleave); - fprintf(f, "trackskew: %d\n", lp->d_trackskew); - fprintf(f, "cylinderskew: %d\n", lp->d_cylskew); - fprintf(f, "headswitch: %d\t\t# milliseconds\n", lp->d_headswitch); - fprintf(f, "track-to-track seek: %d\t# milliseconds\n", lp->d_trkseek); + fprintf(f, "bytes/sector: %ld\n", (long) lp->d_secsize); + fprintf(f, "sectors/track: %ld\n", (long) lp->d_nsectors); + fprintf(f, "tracks/cylinder: %ld\n", (long) lp->d_ntracks); + fprintf(f, "sectors/cylinder: %ld\n", (long) lp->d_secpercyl); + fprintf(f, "cylinders: %ld\n", (long) lp->d_ncylinders); + fprintf(f, "total sectors: %ld\n", (long) lp->d_secperunit); + fprintf(f, "rpm: %ld\n", (long) lp->d_rpm); + fprintf(f, "interleave: %ld\n", (long) lp->d_interleave); + fprintf(f, "trackskew: %ld\n", (long) lp->d_trackskew); + fprintf(f, "cylinderskew: %ld\n", (long) lp->d_cylskew); + fprintf(f, "headswitch: %ld\t\t# milliseconds\n", + (long) lp->d_headswitch); + fprintf(f, "track-to-track seek: %ld\t# milliseconds\n", + (long) lp->d_trkseek); fprintf(f, "drivedata: "); for (i = NDDATA - 1; i >= 0; i--) if (lp->d_drivedata[i]) @@ -1098,6 +1102,15 @@ getasciilabel(f, lp) lp->d_ncylinders = v; continue; } + if (!strcmp(cp, "total sectors")) { + v = atoi(tp); + if (v <= 0) { + warnx("line %d: bad %s: %s", lineno, cp, tp); + errors++; + } else + lp->d_secperunit = v; + continue; + } if (!strcmp(cp, "rpm")) { v = atoi(tp); if (v <= 0) { diff --git a/sbin/dump/dumprmt.c b/sbin/dump/dumprmt.c index 75841fe584f..ce03a2ca4f7 100644 --- a/sbin/dump/dumprmt.c +++ b/sbin/dump/dumprmt.c @@ -1,4 +1,5 @@ -/* $NetBSD: dumprmt.c,v 1.9 1995/03/18 14:54:59 cgd Exp $ */ +/* $OpenBSD: dumprmt.c,v 1.2 1996/03/21 00:15:35 niklas Exp $ */ +/* $NetBSD: dumprmt.c,v 1.10 1996/03/15 22:39:26 scottr Exp $ */ /*- * Copyright (c) 1980, 1993 @@ -37,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)dumprmt.c 8.1 (Berkeley) 6/5/93"; #else -static char rcsid[] = "$NetBSD: dumprmt.c,v 1.9 1995/03/18 14:54:59 cgd Exp $"; +static char rcsid[] = "$NetBSD: dumprmt.c,v 1.10 1996/03/15 22:39:26 scottr Exp $"; #endif #endif /* not lint */ @@ -90,6 +91,8 @@ static void rmtgets __P((char *, int)); static int rmtreply __P((char *)); extern int ntrec; /* blocking factor on tape */ +extern uid_t uid; /* real uid */ +extern uid_t euid; /* effective uid */ int rmthost(host) @@ -144,8 +147,12 @@ rmtgetconn() rmtpeer = ++cp; } else tuser = pwd->pw_name; + + (void) seteuid(euid); rmtape = rcmd(&rmtpeer, (u_short)sp->s_port, pwd->pw_name, tuser, _PATH_RMT, (int *)0); + (void) setuid(uid); /* Just to be Really Really safe */ + size = ntrec * TP_BSIZE; if (size > 60 * 1024) /* XXX */ size = 60 * 1024; diff --git a/sbin/dump/main.c b/sbin/dump/main.c index b11970ca3f4..ce517570476 100644 --- a/sbin/dump/main.c +++ b/sbin/dump/main.c @@ -1,4 +1,5 @@ -/* $NetBSD: main.c,v 1.7 1996/02/05 23:59:40 mrg Exp $ */ +/* $OpenBSD: main.c,v 1.4 1996/03/21 00:15:37 niklas Exp $ */ +/* $NetBSD: main.c,v 1.8 1996/03/15 22:39:32 scottr Exp $ */ /*- * Copyright (c) 1980, 1991, 1993, 1994 @@ -43,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 4/15/94"; #else -static char rcsid[] = "$NetBSD: main.c,v 1.7 1996/02/05 23:59:40 mrg Exp $"; +static char rcsid[] = "$NetBSD: main.c,v 1.8 1996/03/15 22:39:32 scottr Exp $"; #endif #endif /* not lint */ @@ -88,6 +89,8 @@ int cartridge = 0; /* Assume non-cartridge tape */ long dev_bsize = 1; /* recalculated below */ long blocksperfile; /* output blocks per file */ char *host = NULL; /* remote host (if any) */ +uid_t uid; /* real uid */ +uid_t euid; /* effective uid */ static long numarg __P((char *, long, long)); static void obsolete __P((int *, char **[])); @@ -107,6 +110,10 @@ main(argc, argv) int i, anydirskipped, bflag = 0, Tflag = 0, honorlevel = 1; ino_t maxino; + uid = getuid(); + euid = geteuid(); + (void) seteuid(uid); + spcl.c_date = 0; (void)time((time_t *)&spcl.c_date); @@ -244,7 +251,7 @@ main(argc, argv) exit(X_ABORT); #endif } - (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */ + (void) setuid(uid); /* rmthost() is the only reason to be setuid */ if (signal(SIGHUP, SIG_IGN) != SIG_IGN) signal(SIGHUP, sig); diff --git a/sbin/fsdb/fsdb.8 b/sbin/fsdb/fsdb.8 index 87470cc7f0f..454d9e8cfaf 100644 --- a/sbin/fsdb/fsdb.8 +++ b/sbin/fsdb/fsdb.8 @@ -1,8 +1,12 @@ -.\" $NetBSD: fsdb.8,v 1.3 1996/02/06 02:25:04 jtc Exp $ +.\" $OpenBSD: fsdb.8,v 1.3 1996/03/21 00:15:42 niklas Exp $ +.\" $NetBSD: fsdb.8,v 1.4 1996/02/27 22:28:09 jtc Exp $ .\" -.\" Copyright (c) 1995 John T. Kohl +.\" Copyright (c) 1996 The NetBSD Foundation, Inc. .\" All rights reserved. .\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by John T. Kohl. +.\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: @@ -11,19 +15,24 @@ .\" 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. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the NetBSD +.\" Foundation, Inc. and its contributors. +.\" 4. Neither the name of The NetBSD Foundation nor the names of its +.\" contributors may be used to endorse or promote products derived +.\" from this software without specific prior written permission. .\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR `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 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 +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 REGENTS 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. .\" .Dd September 14, 1995 diff --git a/sbin/fsdb/fsdb.c b/sbin/fsdb/fsdb.c index 8a5ad7b3ddc..9c10c8ccfb3 100644 --- a/sbin/fsdb/fsdb.c +++ b/sbin/fsdb/fsdb.c @@ -1,35 +1,44 @@ -/* $NetBSD: fsdb.c,v 1.2 1995/10/08 23:18:10 thorpej Exp $ */ +/* $OpenBSD: fsdb.c,v 1.2 1996/03/21 00:15:46 niklas Exp $ */ +/* $NetBSD: fsdb.c,v 1.3 1996/02/27 22:28:12 jtc Exp $ */ -/* - * Copyright (c) 1995 John T. Kohl - * 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `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 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 +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by John T. Kohl. + * + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 REGENTS 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 char rcsid[] = "$NetBSD: fsdb.c,v 1.2 1995/10/08 23:18:10 thorpej Exp $"; +static char rcsid[] = "$NetBSD: fsdb.c,v 1.3 1996/02/27 22:28:12 jtc Exp $"; #endif /* not lint */ #include <sys/types.h> diff --git a/sbin/fsdb/fsdb.h b/sbin/fsdb/fsdb.h index af51907e352..16c0b762be2 100644 --- a/sbin/fsdb/fsdb.h +++ b/sbin/fsdb/fsdb.h @@ -1,30 +1,39 @@ -/* $NetBSD: fsdb.h,v 1.2 1995/10/08 23:18:11 thorpej Exp $ */ +/* $OpenBSD: fsdb.h,v 1.2 1996/03/21 00:15:48 niklas Exp $ */ +/* $NetBSD: fsdb.h,v 1.3 1996/02/27 22:28:13 jtc Exp $ */ -/* - * Copyright (c) 1995 John T. Kohl - * 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `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 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 +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by John T. Kohl. + * + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 REGENTS 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. */ diff --git a/sbin/fsdb/fsdbutil.c b/sbin/fsdb/fsdbutil.c index d71e25f1f7e..82e73562bd3 100644 --- a/sbin/fsdb/fsdbutil.c +++ b/sbin/fsdb/fsdbutil.c @@ -1,35 +1,44 @@ -/* $NetBSD: fsdbutil.c,v 1.3 1995/12/14 22:30:45 thorpej Exp $ */ +/* $OpenBSD: fsdbutil.c,v 1.4 1996/03/21 00:15:50 niklas Exp $ */ +/* $NetBSD: fsdbutil.c,v 1.4 1996/02/27 22:28:16 jtc Exp $ */ -/* - * Copyright (c) 1995 John T. Kohl - * 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `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 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 +/*- + * Copyright (c) 1996 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by John T. Kohl. + * + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 REGENTS 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 char rcsid[] = "$NetBSD: fsdbutil.c,v 1.3 1995/12/14 22:30:45 thorpej Exp $"; +static char rcsid[] = "$NetBSD: fsdbutil.c,v 1.4 1996/02/27 22:28:16 jtc Exp $"; #endif /* not lint */ #include <sys/types.h> diff --git a/sbin/mount_nfs/Makefile b/sbin/mount_nfs/Makefile index 9d78b197d97..ba0017f8e65 100644 --- a/sbin/mount_nfs/Makefile +++ b/sbin/mount_nfs/Makefile @@ -1,18 +1,22 @@ -# $NetBSD: Makefile,v 1.4 1995/03/18 14:57:40 cgd Exp $ +# $OpenBSD: Makefile,v 1.3 1996/03/21 00:15:56 niklas Exp $ +# $NetBSD: Makefile,v 1.5 1996/02/18 11:59:09 fvdl Exp $ # @(#)Makefile 8.2 (Berkeley) 3/27/94 PROG= mount_nfs SRCS= mount_nfs.c getmntopts.c MAN= mount_nfs.8 -MOUNT= ${.CURDIR}/../mount -CFLAGS+= -DNFS -I${MOUNT} -.PATH: ${MOUNT} +# Temporarily removed to use own getmntops.c - fvdl +# +#MOUNT= ${.CURDIR}/../mount +#CFLAGS+= -DNFS -I${MOUNT} +#.PATH: ${MOUNT} +CFLAGS+=-DNFS .include <bsd.own.mk> # For KERBEROS .if defined(KERBEROS) -CFLAGS+=-DKERBEROS +CFLAGS+=-DNFSKERB DPADD+= ${LIBKRB} ${LIBDES} LDADD+= -lkrb -ldes .endif diff --git a/sbin/mount_nfs/getmntopts.c b/sbin/mount_nfs/getmntopts.c new file mode 100644 index 00000000000..13d05634c43 --- /dev/null +++ b/sbin/mount_nfs/getmntopts.c @@ -0,0 +1,103 @@ +/* $OpenBSD: getmntopts.c,v 1.1 1996/03/21 00:15:58 niklas Exp $ */ + +/*- + * Copyright (c) 1994 + * The Regents of the University of California. 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 char sccsid[] = "@(#)getmntopts.c 8.3 (Berkeley) 3/29/95"; +#endif /* not lint */ + +#include <sys/param.h> +#include <sys/mount.h> + +#include <err.h> +#include <errno.h> +#include <fstab.h> +#include <stdlib.h> +#include <string.h> + +#include "mntopts.h" + +int getmnt_silent = 0; + +void +getmntopts(options, m0, flagp, altflagp) + const char *options; + const struct mntopt *m0; + int *flagp; + int *altflagp; +{ + const struct mntopt *m; + int negative; + char *opt, *optbuf, *p; + int *thisflagp; + + /* Copy option string, since it is about to be torn asunder... */ + if ((optbuf = strdup(options)) == NULL) + err(1, NULL); + + for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) { + /* Check for "no" prefix. */ + if (opt[0] == 'n' && opt[1] == 'o') { + negative = 1; + opt += 2; + } else + negative = 0; + + /* + * for options with assignments in them (ie. quotas) + * ignore the assignment as it's handled elsewhere + */ + p = strchr(opt, '='); + if (p) + *p = '\0'; + + /* Scan option table. */ + for (m = m0; m->m_option != NULL; ++m) + if (strcasecmp(opt, m->m_option) == 0) + break; + + /* Save flag, or fail if option is not recognised. */ + if (m->m_option) { + thisflagp = m->m_altloc ? altflagp : flagp; + if (negative == m->m_inverse) + *thisflagp |= m->m_flag; + else + *thisflagp &= ~m->m_flag; + } else if (!getmnt_silent) { + errx(1, "-o %s: option not supported", opt); + } + } + + free(optbuf); +} diff --git a/sbin/mount_nfs/mntopts.h b/sbin/mount_nfs/mntopts.h new file mode 100644 index 00000000000..8b98770c42a --- /dev/null +++ b/sbin/mount_nfs/mntopts.h @@ -0,0 +1,82 @@ +/* $OpenBSD: mntopts.h,v 1.1 1996/03/21 00:16:00 niklas Exp $ */ + +/*- + * Copyright (c) 1994 + * The Regents of the University of California. 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + * + * @(#)mntopts.h 8.7 (Berkeley) 3/29/95 + */ + +struct mntopt { + const char *m_option; /* option name */ + int m_inverse; /* if a negative option, eg "dev" */ + int m_flag; /* bit to set, eg. MNT_RDONLY */ + int m_altloc; /* 1 => set bit in altflags */ +}; + +/* User-visible MNT_ flags. */ +#define MOPT_ASYNC { "async", 0, MNT_ASYNC, 0 } +#define MOPT_NODEV { "dev", 1, MNT_NODEV, 0 } +#define MOPT_NOEXEC { "exec", 1, MNT_NOEXEC, 0 } +#define MOPT_NOSUID { "suid", 1, MNT_NOSUID, 0 } +#define MOPT_RDONLY { "rdonly", 0, MNT_RDONLY, 0 } +#define MOPT_SYNC { "sync", 0, MNT_SYNCHRONOUS, 0 } +#define MOPT_UNION { "union", 0, MNT_UNION, 0 } +#define MOPT_USERQUOTA { "userquota", 0, 0, 0 } +#define MOPT_GROUPQUOTA { "groupquota", 0, 0, 0 } + +/* Control flags. */ +#define MOPT_FORCE { "force", 0, MNT_FORCE, 0 } +#define MOPT_UPDATE { "update", 0, MNT_UPDATE, 0 } +#define MOPT_RO { "ro", 0, MNT_RDONLY, 0 } +#define MOPT_RW { "rw", 1, MNT_RDONLY, 0 } + +/* This is parsed by mount(8), but is ignored by specific mount_*(8)s. */ +#define MOPT_AUTO { "auto", 0, 0, 0 } + +#define MOPT_FSTAB_COMPAT \ + MOPT_RO, \ + MOPT_RW, \ + MOPT_AUTO + +/* Standard options which all mounts can understand. */ +#define MOPT_STDOPTS \ + MOPT_USERQUOTA, \ + MOPT_GROUPQUOTA, \ + MOPT_FSTAB_COMPAT, \ + MOPT_NODEV, \ + MOPT_NOEXEC, \ + MOPT_NOSUID, \ + MOPT_RDONLY, \ + MOPT_UNION + +void getmntopts __P((const char *, const struct mntopt *, int *, int *)); +extern int getmnt_silent; diff --git a/sbin/mount_nfs/mount_nfs.8 b/sbin/mount_nfs/mount_nfs.8 index b8429b97696..e32c026ace5 100644 --- a/sbin/mount_nfs/mount_nfs.8 +++ b/sbin/mount_nfs/mount_nfs.8 @@ -1,6 +1,7 @@ -.\" $NetBSD: mount_nfs.8,v 1.2 1995/03/18 14:57:41 cgd Exp $ +.\" $OpenBSD: mount_nfs.8,v 1.2 1996/03/21 00:16:02 niklas Exp $ +.\" $NetBSD: mount_nfs.8,v 1.3 1996/02/18 11:59:10 fvdl Exp $ .\" -.\" Copyright (c) 1992, 1993, 1994 +.\" Copyright (c) 1992, 1993, 1994, 1995 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -31,9 +32,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)mount_nfs.8 8.2 (Berkeley) 3/27/94 +.\" @(#)mount_nfs.8 8.3 (Berkeley) 3/29/95 .\" -.Dd March 27, 1994 +.Dd March 29, 1995 .Dt MOUNT_NFS 8 .Os BSD 4.4 .Sh NAME @@ -41,8 +42,9 @@ .Nd mount nfs file systems .Sh SYNOPSIS .Nm mount_nfs -.Op Fl KMPTbcdiklqs +.Op Fl 23KPTUbcdilqs .Op Fl D Ar deadthresh +.Op Fl I Ar readdirsize .Op Fl L Ar leaseterm .Op Fl R Ar retrycnt .Op Fl a Ar maxreadahead @@ -65,10 +67,17 @@ on to the file system tree at the point .Ar node. This command is normally executed by .Xr mount 8 . -It implements the mount protocol as described in RFC 1094, Appendix A. +It implements the mount protocol as described in RFC 1094, Appendix A and +.%T "NFS: Network File System Version 3 Protocol Specification" , +Appendix I. .Pp The options are: .Bl -tag -width indent +.It Fl 2 +Use the NFS Version 2 protocol. +.It Fl 3 +Use the NFS Version 3 protocol. The default is to try version 3 first, and +fall back to version 2 if the mount fails. .It Fl D Used with NQNFS to set the .Dq "dead server threshold" @@ -82,23 +91,27 @@ Values may be set in the range of 1 - 9, with 9 referring to an (i.e. never assume cached data still valid). This option is not generally recommended and is really an experimental feature. +.It Fl I +Set the readdir read size to the specified value. The value should normally +be a multiple of DIRBLKSIZ that is <= the read size for the mount. .It Fl K Pass Kerberos authenticators to the server for client-to-server user-credential mapping. -This may only be used over TCP mounts between 4.4BSD clients and servers. +This requires that the kernel be built with the NFSKERB option. +(Refer to the INTERNET-DRAFT titled +.%T "Authentication Mechanisms for ONC RPC" , +for more information.) .It Fl L Used with NQNFS to set the lease term to the specified number of seconds. Only use this argument for mounts with a large round trip delay. Values are normally in the 10-30 second range. -.It Fl M -Assume that other clients are not writing a file concurrently with this client. -This implements a slightly less strict consistency criteria than 4.3BSD-Reno -did, that is more in line with most commercial client implementations. -This is recommended for servers that do not support leasing. .It Fl P Use a reserved socket port number. This is useful for mounting servers that require clients to use a -reserved port number. +reserved port number on the mistaken belief that this makes NFS +more secure. (For the rare case where the client has a trusted root account +but untrusworthy users and the network cables are in secure areas this does +help, but for normal desktop clients this does not apply.) .It Fl R Set the retry count for doing the mount to the specified value. .It Fl T @@ -106,11 +119,15 @@ Use TCP transport instead of UDP. This is recommended for servers that are not on the same LAN cable as the client. (NB: This is NOT supported by most non-BSD servers.) +.It Fl U +Force the mount protocol to use UDP transport, even for TCP NFS mounts. +(Necessary for some old BSD servers.) .It Fl a Set the read-ahead count to the specified value. This may be in the range of 0 - 4, and determines how many blocks will be read ahead when a large file is being read sequentially. -This is recommended for mounts with a large bandwidth * delay product. +Trying a value greater than 1 for this is suggested for +mounts with a large bandwidth * delay product. .It Fl b If an initial attempt to contact the server fails, fork off a child to keep trying the mount in the background. @@ -121,10 +138,12 @@ where the filesystem mount is not critical to multiuser operation. For UDP mount points, do not do a .Xr connect 2 . This must be used for servers that do not reply to requests from the -standard port number. +standard NFS port number 2049. .It Fl d -Do not estimate retransmit timeout dynamically. -This may be useful for UDP mounts that exhibit high retry rates. +Turn off the dynamic retransmit timeout estimator. +This may be useful for UDP mounts that exhibit high retry rates, +since it is possible that the dynamically estimated timeout interval is too +short. .It Fl g Set the maximum size of the group list for the credentials to the specified value. @@ -136,20 +155,15 @@ point. Make the mount interruptible, which implies that file system calls that are delayed due to an unresponsive server will fail with EINTR when a termination signal is posted for the process. -.It Fl k -Used with NQNFS to specify -.Dq get a lease -for the file name being looked up. -This is recommended unless the server is complaining about excessive -lease load. .It Fl l -Used with NQNFS to specify that the \fBReaddir_and_Lookup\fR RPC should +Used with NQNFS and NFSV3 to specify that the \fBReaddirPlus\fR RPC should be used. This option reduces RPC traffic for cases such as .Dq "ls -l" , -but increases the lease load on the server. -This is recommended unless the server is complaining about excessive -lease load. +but tends to flood the attribute and name caches with prefetched entries. +Try this option and see whether performance improves or degrades. Probably +most useful for client to server network interconnects with a large bandwidth +times delay product. .It Fl m Set the Kerberos realm to the string argument. Used with the @@ -163,12 +177,18 @@ See the .Xr mount 8 man page for possible options and their meanings. .It Fl q -Use the leasing extensions to the protocol to maintain cache consistency. -This protocol, referred to as Not Quite Nfs (NQNFS), -is only supported by 4.4BSD servers. +Use the leasing extensions to the NFS Version 3 protocol +to maintain cache consistency. +This protocol version 2 revision to Not Quite Nfs (NQNFS) +is only supported by this updated release of NFS code. +It is not backwards compatible with the version 1 NQNFS protocol +that was part of the first release of 4.4BSD-Lite. +To interoperate with a first release 4.4BSD-Lite NFS system you will have to +avoid this option until you have had an oppurtunity to upgrade the NFS code +to release 2 of 4.4BSD-Lite on all your systems. .It Fl r Set the read data size to the specified value. -It should be a power of 2 greater than or equal to 1024. +It should normally be a power of 2 greater than or equal to 1024. This should be used for UDP mounts when the .Dq "fragments dropped due to timeout" value is getting large while actively using a mount point. @@ -193,6 +213,9 @@ Try increasing the interval if .Xr nfsstat 1 shows high retransmit rates while the file system is active or reducing the value if there is a low retransmit rate but long response delay observed. +(Normally, the -d option should be specified when using this option to manually +tune the timeout +interval.) .It Fl w Set the write data size to the specified value. Ditto the comments w.r.t. the diff --git a/sbin/mount_nfs/mount_nfs.c b/sbin/mount_nfs/mount_nfs.c index 6652bf84af2..34fb23cb7b3 100644 --- a/sbin/mount_nfs/mount_nfs.c +++ b/sbin/mount_nfs/mount_nfs.c @@ -1,4 +1,5 @@ -/* $NetBSD: mount_nfs.c,v 1.10 1995/05/21 15:17:13 mycroft Exp $ */ +/* $OpenBSD: mount_nfs.c,v 1.3 1996/03/21 00:16:03 niklas Exp $ */ +/* $NetBSD: mount_nfs.c,v 1.11 1996/02/18 11:59:11 fvdl Exp $ */ /* * Copyright (c) 1992, 1993, 1994 @@ -44,9 +45,9 @@ static char copyright[] = #ifndef lint #if 0 -static char sccsid[] = "@(#)mount_nfs.c 8.3 (Berkeley) 3/27/94"; +static char sccsid[] = "@(#)mount_nfs.c 8.11 (Berkeley) 5/4/95"; #else -static char rcsid[] = "$NetBSD: mount_nfs.c,v 1.10 1995/05/21 15:17:13 mycroft Exp $"; +static char rcsid[] = "$NetBSD: mount_nfs.c,v 1.11 1996/02/18 11:59:11 fvdl Exp $"; #endif #endif /* not lint */ @@ -65,13 +66,13 @@ static char rcsid[] = "$NetBSD: mount_nfs.c,v 1.10 1995/05/21 15:17:13 mycroft E #include <netiso/iso.h> #endif -#ifdef KERBEROS +#ifdef NFSKERB #include <kerberosIV/des.h> #include <kerberosIV/krb.h> #endif #include <nfs/rpcv2.h> -#include <nfs/nfsv2.h> +#include <nfs/nfsproto.h> #define _KERNEL #include <nfs/nfs.h> #undef _KERNEL @@ -92,23 +93,57 @@ static char rcsid[] = "$NetBSD: mount_nfs.c,v 1.10 1995/05/21 15:17:13 mycroft E #include "mntopts.h" +#define ALTF_BG 0x1 +#define ALTF_NOCONN 0x2 +#define ALTF_DUMBTIMR 0x4 +#define ALTF_INTR 0x8 +#define ALTF_KERB 0x10 +#define ALTF_NFSV3 0x20 +#define ALTF_RDIRPLUS 0x40 +#define ALTF_MNTUDP 0x80 +#define ALTF_RESVPORT 0x100 +#define ALTF_SEQPACKET 0x200 +#define ALTF_NQNFS 0x400 +#define ALTF_SOFT 0x800 +#define ALTF_TCP 0x1000 + struct mntopt mopts[] = { MOPT_STDOPTS, MOPT_FORCE, MOPT_UPDATE, + { "bg", 0, ALTF_BG, 1 }, + { "conn", 1, ALTF_NOCONN, 1 }, + { "dumbtimer", 0, ALTF_DUMBTIMR, 1 }, + { "intr", 0, ALTF_INTR, 1 }, +#ifdef NFSKERB + { "kerb", 0, ALTF_KERB, 1 }, +#endif + { "nfsv3", 0, ALTF_NFSV3, 1 }, + { "rdirplus", 0, ALTF_RDIRPLUS, 1 }, + { "mntudp", 0, ALTF_MNTUDP, 1 }, + { "resvport", 0, ALTF_RESVPORT, 1 }, +#ifdef ISO + { "seqpacket", 0, ALTF_SEQPACKET, 1 }, +#endif + { "nqnfs", 0, ALTF_NQNFS, 1 }, + { "soft", 0, ALTF_SOFT, 1 }, + { "tcp", 0, ALTF_TCP, 1 }, { NULL } }; struct nfs_args nfsdefargs = { + NFS_ARGSVERSION, (struct sockaddr *)0, sizeof (struct sockaddr_in), SOCK_DGRAM, 0, - (nfsv2fh_t *)0, + (u_char *)0, 0, + NFSMNT_NFSV3, NFS_WSIZE, NFS_RSIZE, - NFS_TIMEO, + NFS_READDIRSIZE, + 10, NFS_RETRANS, NFS_MAXGRPS, NFS_DEFRAHEAD, @@ -118,19 +153,35 @@ struct nfs_args nfsdefargs = { }; struct nfhret { - u_long stat; - nfsv2fh_t nfh; + u_long stat; + long vers; + long auth; + long fhsize; + u_char nfh[NFSX_V3FHMAX]; }; #define DEF_RETRY 10000 #define BGRND 1 #define ISBGRND 2 -int retrycnt = DEF_RETRY; +int retrycnt; int opflags = 0; +int nfsproto = IPPROTO_UDP; +int mnttcp_ok = 1; +int force2 = 0; +int force3 = 0; -#ifdef KERBEROS +#ifdef NFSKERB char inst[INST_SZ]; char realm[REALM_SZ]; -KTEXT_ST kt; +struct { + u_long kind; + KTEXT_ST kt; +} ktick; +struct nfsrpc_nickverf kverf; +struct nfsrpc_fullblock kin, kout; +NFSKERBKEY_T kivec; +CREDENTIALS kcr; +struct timeval ktv; +NFSKERBKEYSCHED_T kerb_keysched; #endif int getnfsargs __P((char *, struct nfs_args *)); @@ -151,26 +202,44 @@ main(argc, argv) register struct nfs_args *nfsargsp; struct nfs_args nfsargs; struct nfsd_cargs ncd; - int mntflags, i, nfssvc_flag, num; + int mntflags, altflags, i, nfssvc_flag, num; char *name, *p, *spec; int error = 0; -#ifdef KERBEROS +#ifdef NFSKERB uid_t last_ruid; #endif -#ifdef KERBEROS +#ifdef NFSKERB last_ruid = -1; if (krb_get_lrealm(realm, 0) != KSUCCESS) (void)strcpy(realm, "[not set]"); + if (sizeof (struct nfsrpc_nickverf) != RPCX_NICKVERF || + sizeof (struct nfsrpc_fullblock) != RPCX_FULLBLOCK || + ((char *)&ktick.kt) - ((char *)&ktick) != NFSX_UNSIGNED || + ((char *)ktick.kt.dat) - ((char *)&ktick) != 2 * NFSX_UNSIGNED) + fprintf(stderr, "Yikes! NFSKERB structs not packed!!\n"); + #endif retrycnt = DEF_RETRY; mntflags = 0; + altflags = 0; nfsargs = nfsdefargs; nfsargsp = &nfsargs; while ((c = getopt(argc, argv, - "a:bcdD:g:iKklL:Mm:o:PpqR:r:sTt:w:x:")) != EOF) + "23a:bcdD:g:I:iKL:lm:o:PpqR:r:sTt:w:x:U")) != EOF) switch (c) { + case '3': + if (force2) + errx(1, "-2 and -3 are mutually exclusive"); + force3 = 1; + break; + case '2': + if (force3) + errx(1, "-2 and -3 are mutually exclusive"); + force2 = 1; + nfsargsp->flags &= ~NFSMNT_NFSV3; + break; case 'a': num = strtol(optarg, &p, 10); if (*p || num < 0) @@ -204,17 +273,21 @@ main(argc, argv) nfsargsp->flags |= NFSMNT_MAXGRPS; break; #endif + case 'I': + num = strtol(optarg, &p, 10); + if (*p || num <= 0) + errx(1, "illegal -I value -- %s", optarg); + nfsargsp->readdirsize = num; + nfsargsp->flags |= NFSMNT_READDIRSIZE; + break; case 'i': nfsargsp->flags |= NFSMNT_INT; break; -#ifdef KERBEROS +#ifdef NFSKERB case 'K': nfsargsp->flags |= NFSMNT_KERB; break; #endif - case 'k': - nfsargsp->flags |= NFSMNT_NQLOOKLEASE; - break; case 'L': num = strtol(optarg, &p, 10); if (*p || num < 2) @@ -223,19 +296,49 @@ main(argc, argv) nfsargsp->flags |= NFSMNT_LEASETERM; break; case 'l': - nfsargsp->flags |= NFSMNT_RDIRALOOK; + nfsargsp->flags |= NFSMNT_RDIRPLUS; break; - case 'M': - nfsargsp->flags |= NFSMNT_MYWRITE; - break; -#ifdef KERBEROS +#ifdef NFSKERB case 'm': (void)strncpy(realm, optarg, REALM_SZ - 1); realm[REALM_SZ - 1] = '\0'; break; #endif case 'o': - getmntopts(optarg, mopts, &mntflags); + getmntopts(optarg, mopts, &mntflags, &altflags); + if(altflags & ALTF_BG) + opflags |= BGRND; + if(altflags & ALTF_NOCONN) + nfsargsp->flags |= NFSMNT_NOCONN; + if(altflags & ALTF_DUMBTIMR) + nfsargsp->flags |= NFSMNT_DUMBTIMR; + if(altflags & ALTF_INTR) + nfsargsp->flags |= NFSMNT_INT; +#ifdef NFSKERB + if(altflags & ALTF_KERB) + nfsargsp->flags |= NFSMNT_KERB; +#endif + if(altflags & ALTF_NFSV3) + nfsargsp->flags |= NFSMNT_NFSV3; + if(altflags & ALTF_RDIRPLUS) + nfsargsp->flags |= NFSMNT_RDIRPLUS; + if(altflags & ALTF_MNTUDP) + mnttcp_ok = 0; + if(altflags & ALTF_RESVPORT) + nfsargsp->flags |= NFSMNT_RESVPORT; +#ifdef ISO + if(altflags & ALTF_SEQPACKET) + nfsargsp->sotype = SOCK_SEQPACKET; +#endif + if(altflags & ALTF_NQNFS) + nfsargsp->flags |= (NFSMNT_NQNFS|NFSMNT_NFSV3); + if(altflags & ALTF_SOFT) + nfsargsp->flags |= NFSMNT_SOFT; + if(altflags & ALTF_TCP) { + nfsargsp->sotype = SOCK_STREAM; + nfsproto = IPPROTO_TCP; + } + altflags = 0; break; case 'P': nfsargsp->flags |= NFSMNT_RESVPORT; @@ -246,7 +349,7 @@ main(argc, argv) break; #endif case 'q': - nfsargsp->flags |= NFSMNT_NQNFS; + nfsargsp->flags |= (NFSMNT_NQNFS | NFSMNT_NFSV3); break; case 'R': num = strtol(optarg, &p, 10); @@ -266,6 +369,7 @@ main(argc, argv) break; case 'T': nfsargsp->sotype = SOCK_STREAM; + nfsproto = IPPROTO_TCP; break; case 't': num = strtol(optarg, &p, 10); @@ -288,6 +392,9 @@ main(argc, argv) nfsargsp->retrans = num; nfsargsp->flags |= NFSMNT_RETRANS; break; + case 'U': + mnttcp_ok = 0; + break; default: usage(); break; @@ -328,29 +435,79 @@ main(argc, argv) } nfssvc_flag = NFSSVC_MNTD | NFSSVC_GOTAUTH | NFSSVC_AUTHINFAIL; -#ifdef KERBEROS +#ifdef NFSKERB /* * Set up as ncd_authuid for the kerberos call. * Must set ruid to ncd_authuid and reset the * ticket name iff ncd_authuid is not the same * as last time, so that the right ticket file * is found. + * Get the Kerberos credential structure so that + * we have the seesion key and get a ticket for + * this uid. + * For more info see the IETF Draft "Authentication + * in ONC RPC". */ if (ncd.ncd_authuid != last_ruid) { krb_set_tkt_string(""); last_ruid = ncd.ncd_authuid; } setreuid(ncd.ncd_authuid, 0); - if (krb_mk_req(&kt, "rcmd", inst, realm, 0) == - KSUCCESS && - kt.length <= (RPCAUTH_MAXSIZ - 2 * NFSX_UNSIGNED)) { - ncd.ncd_authtype = RPCAUTH_NQNFS; - ncd.ncd_authlen = kt.length; - ncd.ncd_authstr = (char *)kt.dat; - nfssvc_flag = NFSSVC_MNTD | NFSSVC_GOTAUTH; + kret = krb_get_cred(NFS_KERBSRV, inst, realm, &kcr); + if (kret == RET_NOTKT) { + kret = get_ad_tkt(NFS_KERBSRV, inst, realm, + DEFAULT_TKT_LIFE); + if (kret == KSUCCESS) + kret = krb_get_cred(NFS_KERBSRV, inst, realm, + &kcr); + } + if (kret == KSUCCESS) + kret = krb_mk_req(&ktick.kt, NFS_KERBSRV, inst, + realm, 0); + + /* + * Fill in the AKN_FULLNAME authenticator and verfier. + * Along with the Kerberos ticket, we need to build + * the timestamp verifier and encrypt it in CBC mode. + */ + if (kret == KSUCCESS && + ktick.kt.length <= (RPCAUTH_MAXSIZ-3*NFSX_UNSIGNED) + && gettimeofday(&ktv, (struct timezone *)0) == 0) { + ncd.ncd_authtype = RPCAUTH_KERB4; + ncd.ncd_authstr = (u_char *)&ktick; + ncd.ncd_authlen = nfsm_rndup(ktick.kt.length) + + 3 * NFSX_UNSIGNED; + ncd.ncd_verfstr = (u_char *)&kverf; + ncd.ncd_verflen = sizeof (kverf); + memmove(ncd.ncd_key, kcr.session, + sizeof (kcr.session)); + kin.t1 = htonl(ktv.tv_sec); + kin.t2 = htonl(ktv.tv_usec); + kin.w1 = htonl(NFS_KERBTTL); + kin.w2 = htonl(NFS_KERBTTL - 1); + bzero((caddr_t)kivec, sizeof (kivec)); + + /* + * Encrypt kin in CBC mode using the session + * key in kcr. + */ + XXX + + /* + * Finally, fill the timestamp verifier into the + * authenticator and verifier. + */ + ktick.kind = htonl(RPCAKN_FULLNAME); + kverf.kind = htonl(RPCAKN_FULLNAME); + NFS_KERBW1(ktick.kt) = kout.w1; + ktick.kt.length = htonl(ktick.kt.length); + kverf.verf.t1 = kout.t1; + kverf.verf.t2 = kout.t2; + kverf.verf.w2 = kout.w2; + nfssvc_flag = NFSSVC_MNTD | NFSSVC_GOTAUTH; } setreuid(0, 0); -#endif /* KERBEROS */ +#endif /* NFSKERB */ } } exit(0); @@ -371,9 +528,9 @@ getnfsargs(spec, nfsargsp) #endif struct timeval pertry, try; enum clnt_stat clnt_stat; - int so = RPC_ANYSOCK, i; + int so = RPC_ANYSOCK, i, nfsvers, mntvers, orgcnt; char *hostp, *delimp; -#ifdef KERBEROS +#ifdef NFSKERB char *cp; #endif u_short tport; @@ -442,21 +599,30 @@ getnfsargs(spec, nfsargsp) } memcpy(&saddr.sin_addr, hp->h_addr, hp->h_length); } -#ifdef KERBEROS +#ifdef NFSKERB if (nfsargsp->flags & NFSMNT_KERB) { strncpy(inst, hp->h_name, INST_SZ); inst[INST_SZ - 1] = '\0'; if (cp = strchr(inst, '.')) *cp = '\0'; } -#endif /* KERBEROS */ +#endif /* NFSKERB */ + if (force2) { + nfsvers = NFS_VER2; + mntvers = RPCMNT_VER1; + } else { + nfsvers = NFS_VER3; + mntvers = RPCMNT_VER3; + } + orgcnt = retrycnt; +tryagain: nfhret.stat = EACCES; /* Mark not yet successful */ while (retrycnt > 0) { saddr.sin_family = AF_INET; saddr.sin_port = htons(PMAPPORT); if ((tport = pmap_getport(&saddr, RPCPROG_NFS, - NFS_VER2, nfsargsp->sotype == SOCK_STREAM ? IPPROTO_TCP : + nfsvers, nfsargsp->sotype == SOCK_STREAM ? IPPROTO_TCP : IPPROTO_UDP)) == 0) { if ((opflags & ISBGRND) == 0) clnt_pcreateerror("NFS Portmap"); @@ -464,20 +630,42 @@ getnfsargs(spec, nfsargsp) saddr.sin_port = 0; pertry.tv_sec = 10; pertry.tv_usec = 0; - if ((clp = (nfsargsp->sotype == SOCK_STREAM ? - clnttcp_create(&saddr, RPCPROG_MNT, RPCMNT_VER1, - &so, 0, 0) : - clntudp_create(&saddr, RPCPROG_MNT, RPCMNT_VER1, - pertry, &so))) == NULL) { + if (mnttcp_ok && nfsargsp->sotype == SOCK_STREAM) + clp = clnttcp_create(&saddr, RPCPROG_MNT, mntvers, + &so, 0, 0); + else + clp = clntudp_create(&saddr, RPCPROG_MNT, mntvers, + pertry, &so); + if (clp == NULL) { if ((opflags & ISBGRND) == 0) clnt_pcreateerror("Cannot MNT PRC"); } else { clp->cl_auth = authunix_create_default(); try.tv_sec = 10; try.tv_usec = 0; + if (nfsargsp->flags & NFSMNT_KERB) + nfhret.auth = RPCAUTH_KERB4; + else + nfhret.auth = RPCAUTH_UNIX; + nfhret.vers = mntvers; clnt_stat = clnt_call(clp, RPCMNT_MOUNT, xdr_dir, spec, xdr_fh, &nfhret, try); if (clnt_stat != RPC_SUCCESS) { + if (clnt_stat == RPC_PROGVERSMISMATCH) { + if (nfsvers == NFS_VER3 && + !force3) { + retrycnt = orgcnt; + nfsvers = NFS_VER2; + mntvers = RPCMNT_VER1; + nfsargsp->flags &= + ~NFSMNT_NFSV3; + goto tryagain; + } else { + errx(1, "%s", + clnt_sperror(clp, + "MNT RPC")); + } + } if ((opflags & ISBGRND) == 0) warnx("%s", clnt_sperror(clp, "bad MNT RPC")); @@ -510,7 +698,7 @@ getnfsargs(spec, nfsargsp) if (opflags & ISBGRND) exit(1); errno = nfhret.stat; - warn("can't access %s", spec); + warnx("can't access %s: %s", spec, strerror(nfhret.stat)); return (0); } saddr.sin_port = htons(tport); @@ -524,7 +712,8 @@ getnfsargs(spec, nfsargsp) nfsargsp->addr = (struct sockaddr *) &saddr; nfsargsp->addrlen = sizeof (saddr); } - nfsargsp->fh = &nfhret.nfh; + nfsargsp->fh = nfhret.nfh; + nfsargsp->fhsize = nfhret.fhsize; nfsargsp->hostname = nam; return (1); } @@ -543,13 +732,43 @@ xdr_dir(xdrsp, dirp) int xdr_fh(xdrsp, np) XDR *xdrsp; - struct nfhret *np; + register struct nfhret *np; { - if (!xdr_u_long(xdrsp, &(np->stat))) + register int i; + long auth, authcnt, authfnd = 0; + + if (!xdr_u_long(xdrsp, &np->stat)) return (0); if (np->stat) return (1); - return (xdr_opaque(xdrsp, (caddr_t)&(np->nfh), NFSX_FH)); + switch (np->vers) { + case 1: + np->fhsize = NFSX_V2FH; + return (xdr_opaque(xdrsp, (caddr_t)np->nfh, NFSX_V2FH)); + case 3: + if (!xdr_long(xdrsp, &np->fhsize)) + return (0); + if (np->fhsize <= 0 || np->fhsize > NFSX_V3FHMAX) + return (0); + if (!xdr_opaque(xdrsp, (caddr_t)np->nfh, np->fhsize)) + return (0); + if (!xdr_long(xdrsp, &authcnt)) + return (0); + for (i = 0; i < authcnt; i++) { + if (!xdr_long(xdrsp, &auth)) + return (0); + if (auth == np->auth) + authfnd++; + } + /* + * Some servers, such as DEC's OSF/1 return a nil authenticator + * list to indicate RPCAUTH_UNIX. + */ + if (!authfnd && (authcnt > 0 || np->auth != RPCAUTH_UNIX)) + np->stat = EAUTH; + return (1); + }; + return (0); } __dead void diff --git a/sbin/mount_umap/mount_umap.8 b/sbin/mount_umap/mount_umap.8 index d7a5bd94cda..095ee35fe0b 100644 --- a/sbin/mount_umap/mount_umap.8 +++ b/sbin/mount_umap/mount_umap.8 @@ -1,4 +1,5 @@ -.\" $NetBSD: mount_umap.8,v 1.2 1995/03/18 14:58:16 cgd Exp $ +.\" $OpenBSD: mount_umap.8,v 1.3 1996/03/21 00:16:06 niklas Exp $ +.\" $NetBSD: mount_umap.8,v 1.4 1996/03/05 02:36:42 thorpej Exp $ .\" .\" Copyright (c) 1992, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -46,10 +47,12 @@ .Sh SYNOPSIS .Nm mount_umap .Op Fl o Ar options -.Ar target -.Ar mount-point +-u .Ar uid-mapfile +-g .Ar gid-mapfile +.Ar target +.Ar mount-point .Sh DESCRIPTION The .Nm mount_umap diff --git a/sbin/mountd/exports.5 b/sbin/mountd/exports.5 index 936f669a64d..c921143cbe1 100644 --- a/sbin/mountd/exports.5 +++ b/sbin/mountd/exports.5 @@ -1,4 +1,5 @@ -.\" $NetBSD: exports.5,v 1.8 1995/03/18 14:58:28 cgd Exp $ +.\" $OpenBSD: exports.5,v 1.2 1996/03/21 00:16:10 niklas Exp $ +.\" $NetBSD: exports.5,v 1.9 1996/02/18 11:57:50 fvdl Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -31,9 +32,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)exports.5 8.2 (Berkeley) 1/28/94 +.\" @(#)exports.5 8.3 (Berkeley) 3/29/95 .\" -.Dd January 28, 1994 +.Dd March 29, 1995 .Dt EXPORTS 5 .Os .Sh NAME @@ -51,7 +52,9 @@ file specifies remote mount points for the mount protocol per the .Tn NFS server specification; see -.%T "Network File System Protocol Specification \\*(tNRFC\\*(sP 1094, Appendix A" . +.%T "Network File System Protocol Specification \\*(tNRFC\\*(sP 1094, Appendix A" +and +.%T "NFS: Network File System Version 3 Specification, Appendix I" . .Pp Each line in the file (other than comment lines that begin with a #) @@ -73,7 +76,10 @@ The second is to specify the pathname of the root of the filesystem followed by the .Fl alldirs flag; -this form allows the host(s) to mount any directory within the filesystem. +this form allows the host(s) to mount at any point within the filesystem, +including regular files if the +.Fl r +option is used on mountd. The pathnames must not have any symbolic links in them and should not have any "." or ".." components. Mount points for a filesystem may appear on multiple lines each with @@ -142,8 +148,7 @@ The .Fl kerb option specifies that the Kerberos authentication server should be used to authenticate and map client credentials. -(Note that this is NOT Sun NFS compatible and -is supported for TCP transport only.) +This option requires that the kernel be built with the NFSKERB option. .Pp The .Fl ro diff --git a/sbin/mountd/mountd.8 b/sbin/mountd/mountd.8 index 1ed6cb47af8..cd0ffd5440c 100644 --- a/sbin/mountd/mountd.8 +++ b/sbin/mountd/mountd.8 @@ -1,4 +1,5 @@ -.\" $NetBSD: mountd.8,v 1.10 1995/11/06 07:00:14 thorpej Exp $ +.\" $OpenBSD: mountd.8,v 1.3 1996/03/21 00:16:12 niklas Exp $ +.\" $NetBSD: mountd.8,v 1.11 1996/02/18 11:57:51 fvdl Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -31,9 +32,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)mountd.8 8.1 (Berkeley) 6/9/93 +.\" @(#)mountd.8 8.4 (Berkeley) 4/28/95 .\" -.Dd June 9, 1993 +.Dd April 28, 1995 .Dt MOUNTD 8 .Os .Sh NAME @@ -55,7 +56,9 @@ listens for service requests at the port indicated in the .Tn NFS server specification; see .%T "Network File System Protocol Specification" , -RFC1094. +RFC1094, Appendix A and +.%T "NFS: Network File System Version 3 Protocol Specification" , +Appendix I. .Pp Options and operands available for .Nm mountd : diff --git a/sbin/mountd/mountd.c b/sbin/mountd/mountd.c index ef86ed32101..29e8181c0dd 100644 --- a/sbin/mountd/mountd.c +++ b/sbin/mountd/mountd.c @@ -1,4 +1,5 @@ -/* $NetBSD: mountd.c,v 1.30 1995/11/28 05:25:47 jtc Exp $ */ +/* $OpenBSD: mountd.c,v 1.6 1996/03/21 00:16:16 niklas Exp $ */ +/* $NetBSD: mountd.c,v 1.31 1996/02/18 11:57:53 fvdl Exp $ */ /* * Copyright (c) 1989, 1993 @@ -44,9 +45,9 @@ static char copyright[] = #ifndef lint #if 0 -static char sccsid[] = "@(#)mountd.c 8.8 (Berkeley) 2/20/94"; +static char sccsid[] = "@(#)mountd.c 8.15 (Berkeley) 5/1/95"; #else -static char rcsid[] = "$NetBSD: mountd.c,v 1.30 1995/11/28 05:25:47 jtc Exp $"; +static char rcsid[] = "$NetBSD: mountd.c,v 1.31 1996/02/18 11:57:53 fvdl Exp $"; #endif #endif /* not lint */ @@ -66,7 +67,7 @@ static char rcsid[] = "$NetBSD: mountd.c,v 1.30 1995/11/28 05:25:47 jtc Exp $"; #include <netiso/iso.h> #endif #include <nfs/rpcv2.h> -#include <nfs/nfsv2.h> +#include <nfs/nfsproto.h> #include <arpa/inet.h> @@ -102,6 +103,8 @@ struct dirlist { }; /* dp_flag bits */ #define DP_DEFSET 0x1 +#define DP_HOSTSET 0x2 +#define DP_KERB 0x4 struct exportlist { struct exportlist *ex_next; @@ -140,22 +143,29 @@ struct grouplist { #define GT_ISO 0x4 struct hostlist { + int ht_flag; /* Uses DP_xx bits */ struct grouplist *ht_grp; struct hostlist *ht_next; }; +struct fhreturn { + int fhr_flag; + int fhr_vers; + nfsfh_t fhr_fh; +}; + /* Global defs */ char *add_expdir __P((struct dirlist **, char *, int)); void add_dlist __P((struct dirlist **, struct dirlist *, - struct grouplist *)); + struct grouplist *, int)); void add_mlist __P((char *, char *)); int check_dirpath __P((char *)); int check_options __P((struct dirlist *)); -int chk_host __P((struct dirlist *, u_long, int *)); +int chk_host __P((struct dirlist *, u_long, int *, int *)); void del_mlist __P((char *, char *)); struct dirlist *dirp_search __P((struct dirlist *, char *)); int do_mount __P((struct exportlist *, struct grouplist *, int, - struct ucred *, char *, int, struct statfs *)); + struct ucred *, char *, int, struct statfs *)); int do_opt __P((char **, char **, struct exportlist *, struct grouplist *, int *, int *, struct ucred *)); struct exportlist *ex_search __P((fsid_t *)); @@ -166,6 +176,7 @@ void free_grp __P((struct grouplist *)); void free_host __P((struct hostlist *)); void get_exportlist __P((void)); int get_host __P((char *, struct grouplist *)); +int get_num __P((char *)); struct hostlist *get_ht __P((void)); int get_line __P((void)); void get_mountlist __P((void)); @@ -184,7 +195,7 @@ void send_umntall __P((void)); int umntall_each __P((caddr_t, struct sockaddr_in *)); int xdr_dir __P((XDR *, char *)); int xdr_explist __P((XDR *, caddr_t)); -int xdr_fhs __P((XDR *, nfsv2fh_t *)); +int xdr_fhs __P((XDR *, caddr_t)); int xdr_mlist __P((XDR *, caddr_t)); /* C library */ @@ -237,7 +248,7 @@ main(argc, argv) SVCXPRT *udptransp, *tcptransp; int c; - while ((c = getopt(argc, argv, "dn")) != EOF) + while ((c = getopt(argc, argv, "dnr")) != EOF) switch (c) { case 'd': debug = 1; @@ -245,6 +256,9 @@ main(argc, argv) case 'n': resvport_only = 0; break; + case 'r': + /* Compatibility */ + break; default: fprintf(stderr, "Usage: mountd [-dn] [export_file]\n"); exit(1); @@ -287,10 +301,15 @@ main(argc, argv) exit(1); } pmap_unset(RPCPROG_MNT, RPCMNT_VER1); + pmap_unset(RPCPROG_MNT, RPCMNT_VER3); if (!svc_register(udptransp, RPCPROG_MNT, RPCMNT_VER1, mntsrv, - IPPROTO_UDP) || + IPPROTO_UDP) || + !svc_register(udptransp, RPCPROG_MNT, RPCMNT_VER3, mntsrv, + IPPROTO_UDP) || !svc_register(tcptransp, RPCPROG_MNT, RPCMNT_VER1, mntsrv, - IPPROTO_TCP)) { + IPPROTO_TCP) || + !svc_register(tcptransp, RPCPROG_MNT, RPCMNT_VER3, mntsrv, + IPPROTO_TCP)) { syslog(LOG_ERR, "Can't register mount"); exit(1); } @@ -309,16 +328,18 @@ mntsrv(rqstp, transp) { struct exportlist *ep; struct dirlist *dp; - nfsv2fh_t nfh; + struct fhreturn fhr; struct stat stb; struct statfs fsb; struct hostent *hp; u_long saddr; u_short sport; char rpcpath[RPCMNT_PATHLEN+1], dirpath[MAXPATHLEN]; - int bad = ENOENT, defset; - sigset_t sigset, osigset; + int bad = ENOENT, defset, hostset; + sigset_t sighup_mask; + sigemptyset(&sighup_mask); + sigaddset(&sighup_mask, SIGHUP); saddr = transp->xp_raddr.sin_addr.s_addr; sport = ntohs(transp->xp_raddr.sin_port); hp = (struct hostent *)NULL; @@ -354,28 +375,31 @@ mntsrv(rqstp, transp) } /* Check in the exports list */ - sigemptyset(&sigset); - sigaddset(&sigset, SIGHUP); - sigprocmask(SIG_BLOCK, &sigset, &osigset); + sigprocmask(SIG_BLOCK, &sighup_mask, NULL); ep = ex_search(&fsb.f_fsid); - defset = 0; - if (ep && (chk_host(ep->ex_defdir, saddr, &defset) || + hostset = defset = 0; + if (ep && (chk_host(ep->ex_defdir, saddr, &defset, &hostset) || ((dp = dirp_search(ep->ex_dirl, dirpath)) && - chk_host(dp, saddr, &defset)) || + chk_host(dp, saddr, &defset, &hostset)) || (defset && scan_tree(ep->ex_defdir, saddr) == 0 && scan_tree(ep->ex_dirl, saddr) == 0))) { + if (hostset & DP_HOSTSET) + fhr.fhr_flag = hostset; + else + fhr.fhr_flag = defset; + fhr.fhr_vers = rqstp->rq_vers; /* Get the file handle */ - memset(&nfh, 0, sizeof(nfh)); - if (getfh(dirpath, (fhandle_t *)&nfh) < 0) { + memset(&fhr.fhr_fh, 0, sizeof(nfsfh_t)); + if (getfh(dirpath, (fhandle_t *)&fhr.fhr_fh) < 0) { bad = errno; syslog(LOG_ERR, "Can't get fh for %s", dirpath); if (!svc_sendreply(transp, xdr_long, (caddr_t)&bad)) syslog(LOG_ERR, "Can't send reply"); - sigprocmask(SIG_SETMASK, &osigset, NULL); + sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL); return; } - if (!svc_sendreply(transp, xdr_fhs, (caddr_t)&nfh)) + if (!svc_sendreply(transp, xdr_fhs, (caddr_t)&fhr)) syslog(LOG_ERR, "Can't send reply"); if (hp == NULL) hp = gethostbyaddr((caddr_t)&saddr, @@ -392,7 +416,7 @@ mntsrv(rqstp, transp) if (!svc_sendreply(transp, xdr_long, (caddr_t)&bad)) syslog(LOG_ERR, "Can't send reply"); } - sigprocmask(SIG_SETMASK, &osigset, NULL); + sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL); return; case RPCMNT_DUMP: if (!svc_sendreply(transp, xdr_mlist, (caddr_t)NULL)) @@ -448,18 +472,37 @@ xdr_dir(xdrsp, dirp) } /* - * Xdr routine to generate fhstatus + * Xdr routine to generate file handle reply */ int -xdr_fhs(xdrsp, nfh) +xdr_fhs(xdrsp, cp) XDR *xdrsp; - nfsv2fh_t *nfh; + caddr_t cp; { - long ok = 0; + register struct fhreturn *fhrp = (struct fhreturn *)cp; + long ok = 0, len, auth; if (!xdr_long(xdrsp, &ok)) return (0); - return (xdr_opaque(xdrsp, (caddr_t)nfh, NFSX_FH)); + switch (fhrp->fhr_vers) { + case 1: + return (xdr_opaque(xdrsp, (caddr_t)&fhrp->fhr_fh, NFSX_V2FH)); + case 3: + len = NFSX_V3FH; + if (!xdr_long(xdrsp, &len)) + return (0); + if (!xdr_opaque(xdrsp, (caddr_t)&fhrp->fhr_fh, len)) + return (0); + if (fhrp->fhr_flag & DP_KERB) + auth = RPCAUTH_KERB4; + else + auth = RPCAUTH_UNIX; + len = 1; + if (!xdr_long(xdrsp, &len)) + return (0); + return (xdr_long(xdrsp, &auth)); + }; + return (0); } int @@ -500,11 +543,11 @@ xdr_explist(xdrsp, cp) struct exportlist *ep; int false = 0; int putdef; - sigset_t sigset, osigset; + sigset_t sighup_mask; - sigemptyset(&sigset); - sigaddset(&sigset, SIGHUP); - sigprocmask(SIG_BLOCK, &sigset, &osigset); + sigemptyset(&sighup_mask); + sigaddset(&sighup_mask, SIGHUP); + sigprocmask(SIG_BLOCK, &sighup_mask, NULL); ep = exphead; while (ep) { putdef = 0; @@ -516,12 +559,12 @@ xdr_explist(xdrsp, cp) goto errout; ep = ep->ex_next; } - sigprocmask(SIG_SETMASK, &osigset, NULL); + sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL); if (!xdr_bool(xdrsp, &false)) return (0); return (1); errout: - sigprocmask(SIG_SETMASK, &osigset, NULL); + sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL); return (0); } @@ -789,6 +832,7 @@ get_exportlist() if (get_host(hst, grp)) { syslog(LOG_ERR, "Bad netgroup %s", cp); getexp_err(ep, tgrp); + endnetgrent(); goto nextline; } } else if (get_host(cp, grp)) { @@ -849,12 +893,12 @@ get_exportlist() * Success. Update the data structures. */ if (has_host) { - hang_dirp(dirhead, tgrp, ep, (opt_flags & OP_ALLDIRS)); + hang_dirp(dirhead, tgrp, ep, opt_flags); grp->gr_next = grphead; grphead = tgrp; } else { hang_dirp(dirhead, (struct grouplist *)NULL, ep, - (opt_flags & OP_ALLDIRS)); + opt_flags); free_grp(grp); } dirhead = (struct dirlist *)NULL; @@ -978,24 +1022,28 @@ add_expdir(dpp, cp, len) * and update the entry for host. */ void -hang_dirp(dp, grp, ep, alldirs) +hang_dirp(dp, grp, ep, flags) struct dirlist *dp; struct grouplist *grp; struct exportlist *ep; - int alldirs; + int flags; { struct hostlist *hp; struct dirlist *dp2; - if (alldirs) { + if (flags & OP_ALLDIRS) { if (ep->ex_defdir) free((caddr_t)dp); else ep->ex_defdir = dp; - if (grp == (struct grouplist *)NULL) + if (grp == (struct grouplist *)NULL) { ep->ex_defdir->dp_flag |= DP_DEFSET; - else while (grp) { + if (flags & OP_KERB) + ep->ex_defdir->dp_flag |= DP_KERB; + } else while (grp) { hp = get_ht(); + if (flags & OP_KERB) + hp->ht_flag |= DP_KERB; hp->ht_grp = grp; hp->ht_next = ep->ex_defdir->dp_hosts; ep->ex_defdir->dp_hosts = hp; @@ -1008,7 +1056,7 @@ hang_dirp(dp, grp, ep, alldirs) */ while (dp) { dp2 = dp->dp_left; - add_dlist(&ep->ex_dirl, dp, grp); + add_dlist(&ep->ex_dirl, dp, grp, flags); dp = dp2; } } @@ -1019,10 +1067,11 @@ hang_dirp(dp, grp, ep, alldirs) * for the new directory or adding the new node. */ void -add_dlist(dpp, newdp, grp) +add_dlist(dpp, newdp, grp, flags) struct dirlist **dpp; struct dirlist *newdp; struct grouplist *grp; + int flags; { struct dirlist *dp; struct hostlist *hp; @@ -1032,10 +1081,10 @@ add_dlist(dpp, newdp, grp) if (dp) { cmp = strcmp(dp->dp_dirp, newdp->dp_dirp); if (cmp > 0) { - add_dlist(&dp->dp_left, newdp, grp); + add_dlist(&dp->dp_left, newdp, grp, flags); return; } else if (cmp < 0) { - add_dlist(&dp->dp_right, newdp, grp); + add_dlist(&dp->dp_right, newdp, grp, flags); return; } else free((caddr_t)newdp); @@ -1051,13 +1100,18 @@ add_dlist(dpp, newdp, grp) */ do { hp = get_ht(); + if (flags & OP_KERB) + hp->ht_flag |= DP_KERB; hp->ht_grp = grp; hp->ht_next = dp->dp_hosts; dp->dp_hosts = hp; grp = grp->gr_next; } while (grp); - } else + } else { dp->dp_flag |= DP_DEFSET; + if (flags & OP_KERB) + dp->dp_flag |= DP_KERB; + } } /* @@ -1086,10 +1140,11 @@ dirp_search(dp, dirpath) * Scan for a host match in a directory tree. */ int -chk_host(dp, saddr, defsetp) +chk_host(dp, saddr, defsetp, hostsetp) struct dirlist *dp; u_long saddr; int *defsetp; + int *hostsetp; { struct hostlist *hp; struct grouplist *grp; @@ -1097,7 +1152,7 @@ chk_host(dp, saddr, defsetp) if (dp) { if (dp->dp_flag & DP_DEFSET) - *defsetp = 1; + *defsetp = dp->dp_flag; hp = dp->dp_hosts; while (hp) { grp = hp->ht_grp; @@ -1106,15 +1161,19 @@ chk_host(dp, saddr, defsetp) addrp = (u_long **) grp->gr_ptr.gt_hostent->h_addr_list; while (*addrp) { - if (**addrp == saddr) + if (**addrp == saddr) { + *hostsetp = (hp->ht_flag | DP_HOSTSET); return (1); + } addrp++; } break; case GT_NET: if ((saddr & grp->gr_ptr.gt_net.nt_mask) == - grp->gr_ptr.gt_net.nt_net) + grp->gr_ptr.gt_net.nt_net) { + *hostsetp = (hp->ht_flag | DP_HOSTSET); return (1); + } break; }; hp = hp->ht_next; @@ -1131,12 +1190,12 @@ scan_tree(dp, saddr) struct dirlist *dp; u_long saddr; { - int defset; + int defset, hostset; if (dp) { if (scan_tree(dp->dp_left, saddr)) return (1); - if (chk_host(dp, saddr, &defset)) + if (chk_host(dp, saddr, &defset, &hostset)) return (1); if (scan_tree(dp->dp_right, saddr)) return (1); @@ -1390,6 +1449,7 @@ get_ht() if (hp == (struct hostlist *)NULL) out_of_mem(); hp->ht_next = (struct hostlist *)NULL; + hp->ht_flag = 0; return (hp); } @@ -1552,7 +1612,8 @@ do_mount(ep, grp, exflags, anoncrp, dirp, dirplen, fsb) return (1); } if (opt_flags & OP_ALLDIRS) { - syslog(LOG_ERR, "Not root dir"); + syslog(LOG_ERR, "Could not remount %s: %m", + dirp); return (1); } /* back up over the last component */ diff --git a/sbin/nfsd/nfsd.8 b/sbin/nfsd/nfsd.8 index 4b30b85a540..ccb2cb8e974 100644 --- a/sbin/nfsd/nfsd.8 +++ b/sbin/nfsd/nfsd.8 @@ -1,4 +1,5 @@ -.\" $NetBSD: nfsd.8,v 1.6 1995/03/18 14:58:59 cgd Exp $ +.\" $OpenBSD: nfsd.8,v 1.2 1996/03/21 00:16:20 niklas Exp $ +.\" $NetBSD: nfsd.8,v 1.7 1996/02/18 11:58:24 fvdl Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -31,9 +32,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)nfsd.8 8.3 (Berkeley) 2/22/94 +.\" @(#)nfsd.8 8.4 (Berkeley) 3/29/95 .\" -.Dd February 22, 1994 +.Dd March 29, 1995 .Dt NFSD 8 .Os .Sh NAME @@ -100,7 +101,8 @@ listens for service requests at the port indicated in the .Tn NFS server specification; see .%T "Network File System Protocol Specification" , -RFC1094. +RFC1094 and +.%T "NFS: Network File System Version 3 Protocol Specification" . .Pp The .Nm nfsd diff --git a/sbin/nfsd/nfsd.c b/sbin/nfsd/nfsd.c index e55a7d171a9..eaedfdf30b8 100644 --- a/sbin/nfsd/nfsd.c +++ b/sbin/nfsd/nfsd.c @@ -1,4 +1,5 @@ -/* $NetBSD: nfsd.c,v 1.17 1995/05/28 05:31:45 jtc Exp $ */ +/* $OpenBSD: nfsd.c,v 1.2 1996/03/21 00:16:22 niklas Exp $ */ +/* $NetBSD: nfsd.c,v 1.19 1996/02/18 23:18:56 mycroft Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -44,14 +45,13 @@ static char copyright[] = #ifndef lint #if 0 -static char sccsid[] = "@(#)nfsd.c 8.7 (Berkeley) 2/22/94"; +static char sccsid[] = "@(#)nfsd.c 8.9 (Berkeley) 3/29/95"; #else -static char rcsid[] = "$NetBSD: nfsd.c,v 1.17 1995/05/28 05:31:45 jtc Exp $"; +static char rcsid[] = "$NetBSD: nfsd.c,v 1.19 1996/02/18 23:18:56 mycroft Exp $"; #endif -#endif not lint +#endif /* not lint */ #include <sys/param.h> -#include <syslog.h> #include <sys/ioctl.h> #include <sys/stat.h> #include <sys/wait.h> @@ -69,10 +69,10 @@ static char rcsid[] = "$NetBSD: nfsd.c,v 1.17 1995/05/28 05:31:45 jtc Exp $"; #include <netiso/iso.h> #endif #include <nfs/rpcv2.h> -#include <nfs/nfsv2.h> +#include <nfs/nfsproto.h> #include <nfs/nfs.h> -#ifdef KERBEROS +#ifdef NFSKERB #include <kerberosIV/des.h> #include <kerberosIV/krb.h> #endif @@ -86,6 +86,7 @@ static char rcsid[] = "$NetBSD: nfsd.c,v 1.17 1995/05/28 05:31:45 jtc Exp $"; #include <stdio.h> #include <stdlib.h> #include <strings.h> +#include <syslog.h> #include <unistd.h> /* Global defs */ @@ -98,11 +99,16 @@ int debug = 0; struct nfsd_srvargs nsd; -#ifdef KERBEROS +#ifdef NFSKERB char lnam[ANAME_SZ]; KTEXT_ST kt; -AUTH_DAT auth; +AUTH_DAT kauth; char inst[INST_SZ]; +struct nfsrpc_fullblock kin, kout; +struct nfsrpc_fullverf kverf; +NFSKERBKEY_T kivec; +struct timeval ktv; +NFSKERBKEYSCHED_T kerb_keysched; #endif void nonfs __P((int)); @@ -142,6 +148,7 @@ main(argc, argv, envp) #ifdef ISO struct sockaddr_iso isoaddr, isopeer; #endif + struct timeval ktv; fd_set ready, sockbits; int ch, cltpflag, connect_type_cnt, i, len, maxsock, msgsock; int nfsdcnt, nfssvc_flag, on, reregister, sock, tcpflag, tcpsock; @@ -224,10 +231,12 @@ main(argc, argv, envp) if (reregister) { if (udpflag && - !pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_UDP, NFS_PORT)) + (!pmap_set(RPCPROG_NFS, 2, IPPROTO_UDP, NFS_PORT) || + !pmap_set(RPCPROG_NFS, 3, IPPROTO_UDP, NFS_PORT))) err(1, "can't register with portmap for UDP."); if (tcpflag && - !pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_TCP, NFS_PORT)) + (!pmap_set(RPCPROG_NFS, 2, IPPROTO_TCP, NFS_PORT) || + !pmap_set(RPCPROG_NFS, 3, IPPROTO_TCP, NFS_PORT))) err(1, "can't register with portmap for TCP."); exit(0); } @@ -247,8 +256,14 @@ main(argc, argv, envp) setproctitle("server"); nfssvc_flag = NFSSVC_NFSD; nsd.nsd_nfsd = NULL; -#ifdef KERBEROS - nsd.nsd_authstr = (char *)kt.dat; +#ifdef NFSKERB + if (sizeof (struct nfsrpc_fullverf) != RPCX_FULLVERF || + sizeof (struct nfsrpc_fullblock) != RPCX_FULLBLOCK) + syslog(LOG_ERR, "Yikes NFSKERB structs not packed!"); + nsd.nsd_authstr = (u_char *)&kt; + nsd.nsd_authlen = sizeof (kt); + nsd.nsd_verfstr = (u_char *)&kverf; + nsd.nsd_verflen = sizeof (kverf); #endif while (nfssvc(nfssvc_flag, &nsd) < 0) { if (errno != ENEEDAUTH) { @@ -256,14 +271,27 @@ main(argc, argv, envp) exit(1); } nfssvc_flag = NFSSVC_NFSD | NFSSVC_AUTHINFAIL; -#ifdef KERBEROS - kt.length = nsd.nsd_authlen; - kt.mbz = 0; - (void)strcpy(inst, "*"); - if (krb_rd_req(&kt, "rcmd", - inst, nsd.nsd_haddr, &auth, "") == RD_AP_OK && - krb_kntoln(&auth, lnam) == KSUCCESS && - (pwd = getpwnam(lnam)) != NULL) { +#ifdef NFSKERB + /* + * Get the Kerberos ticket out of the authenticator + * verify it and convert the principal name to a user + * name. The user name is then converted to a set of + * user credentials via the password and group file. + * Finally, decrypt the timestamp and validate it. + * For more info see the IETF Draft "Authentication + * in ONC RPC". + */ + kt.length = ntohl(kt.length); + if (gettimeofday(&ktv, (struct timezone *)0) == 0 && + kt.length > 0 && kt.length <= + (RPCAUTH_MAXSIZ - 3 * NFSX_UNSIGNED)) { + kin.w1 = NFS_KERBW1(kt); + kt.mbz = 0; + (void)strcpy(inst, "*"); + if (krb_rd_req(&kt, NFS_KERBSRV, + inst, nsd.nsd_haddr, &kauth, "") == RD_AP_OK && + krb_kntoln(&kauth, lnam) == KSUCCESS && + (pwd = getpwnam(lnam)) != NULL) { cr = &nsd.nsd_cr; cr->cr_uid = pwd->pw_uid; cr->cr_groups[0] = pwd->pw_gid; @@ -284,9 +312,34 @@ main(argc, argv, envp) break; } endgrent(); - nfssvc_flag = NFSSVC_NFSD | NFSSVC_AUTHIN; + + /* + * Get the timestamp verifier out of the + * authenticator and verifier strings. + */ + kin.t1 = kverf.t1; + kin.t2 = kverf.t2; + kin.w2 = kverf.w2; + bzero((caddr_t)kivec, sizeof (kivec)); + bcopy((caddr_t)kauth.session, + (caddr_t)nsd.nsd_key,sizeof(kauth.session)); + + /* + * Decrypt the timestamp verifier in CBC mode. + */ + XXX + + /* + * Validate the timestamp verifier, to + * check that the session key is ok. + */ + nsd.nsd_timestamp.tv_sec = ntohl(kout.t1); + nsd.nsd_timestamp.tv_usec = ntohl(kout.t2); + nsd.nsd_ttl = ntohl(kout.w1); + if ((nsd.nsd_ttl - 1) == ntohl(kout.w2)) + nfssvc_flag = NFSSVC_NFSD | NFSSVC_AUTHIN; } -#endif /* KERBEROS */ +#endif /* NFSKERB */ } exit(0); } @@ -306,7 +359,8 @@ main(argc, argv, envp) syslog(LOG_ERR, "can't bind udp addr"); exit(1); } - if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_UDP, NFS_PORT)) { + if (!pmap_set(RPCPROG_NFS, 2, IPPROTO_UDP, NFS_PORT) || + !pmap_set(RPCPROG_NFS, 3, IPPROTO_UDP, NFS_PORT)) { syslog(LOG_ERR, "can't register with udp portmap"); exit(1); } @@ -386,7 +440,8 @@ main(argc, argv, envp) syslog(LOG_ERR, "listen failed"); exit(1); } - if (!pmap_set(RPCPROG_NFS, NFS_VER2, IPPROTO_TCP, NFS_PORT)) { + if (!pmap_set(RPCPROG_NFS, 2, IPPROTO_TCP, NFS_PORT) || + !pmap_set(RPCPROG_NFS, 3, IPPROTO_TCP, NFS_PORT)) { syslog(LOG_ERR, "can't register tcp with portmap"); exit(1); } @@ -549,7 +604,6 @@ main(argc, argv, envp) void usage() { - (void)fprintf(stderr, "usage: nfsd %s\n", USAGE); exit(1); } @@ -567,5 +621,5 @@ reapchild(signo) int signo; { - while (wait3((int *)0, WNOHANG, (struct rusage *)0) > 0); + while (wait3(NULL, WNOHANG, NULL) > 0); } diff --git a/sbin/nfsiod/nfsiod.c b/sbin/nfsiod/nfsiod.c index 0f6414f07c9..71efc694294 100644 --- a/sbin/nfsiod/nfsiod.c +++ b/sbin/nfsiod/nfsiod.c @@ -1,4 +1,5 @@ -/* $NetBSD: nfsiod.c,v 1.10 1995/09/30 11:39:53 pk Exp $ */ +/* $OpenBSD: nfsiod.c,v 1.2 1996/03/21 00:16:26 niklas Exp $ */ +/* $NetBSD: nfsiod.c,v 1.12 1996/02/20 16:06:55 fvdl Exp $ */ /* * Copyright (c) 1989, 1993 @@ -44,19 +45,21 @@ static char copyright[] = #ifndef lint #if 0 -static char sccsid[] = "@(#)nfsiod.c 8.3 (Berkeley) 2/22/94"; +static char sccsid[] = "@(#)nfsiod.c 8.4 (Berkeley) 5/3/95" #else -static char rcsid[] = "$NetBSD: nfsiod.c,v 1.10 1995/09/30 11:39:53 pk Exp $"; +static char rcsid[] = "$NetBSD: nfsiod.c,v 1.12 1996/02/20 16:06:55 fvdl Exp $"; #endif #endif not lint #include <sys/param.h> #include <sys/ioctl.h> -#include <syslog.h> #include <sys/ucred.h> #include <sys/wait.h> +#include <sys/time.h> +#include <sys/mount.h> -#include <nfs/nfsv2.h> +#include <nfs/rpcv2.h> +#include <nfs/nfsproto.h> #include <nfs/nfs.h> #include <err.h> @@ -65,6 +68,7 @@ static char rcsid[] = "$NetBSD: nfsiod.c,v 1.10 1995/09/30 11:39:53 pk Exp $"; #include <signal.h> #include <stdio.h> #include <stdlib.h> +#include <syslog.h> #include <unistd.h> /* Global defs */ diff --git a/sbin/restore/main.c b/sbin/restore/main.c index 74e36284f56..363f1e3fba9 100644 --- a/sbin/restore/main.c +++ b/sbin/restore/main.c @@ -1,4 +1,5 @@ -/* $NetBSD: main.c,v 1.10 1996/02/06 00:00:22 mrg Exp $ */ +/* $OpenBSD: main.c,v 1.3 1996/03/21 00:16:29 niklas Exp $ */ +/* $NetBSD: main.c,v 1.11 1996/03/15 22:39:39 scottr Exp $ */ /* * Copyright (c) 1983, 1993 @@ -43,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 9/13/94"; #else -static char rcsid[] = "$NetBSD: main.c,v 1.10 1996/02/06 00:00:22 mrg Exp $"; +static char rcsid[] = "$NetBSD: main.c,v 1.11 1996/03/15 22:39:39 scottr Exp $"; #endif #endif /* not lint */ @@ -77,6 +78,8 @@ ino_t maxino; time_t dumptime; time_t dumpdate; FILE *terminal; +uid_t uid; /* real uid */ +uid_t euid; /* effective uid */ static void obsolete __P((int *, char **[])); static void usage __P((void)); @@ -92,6 +95,10 @@ main(argc, argv) char *symtbl = "./restoresymtable"; char *p, name[MAXPATHLEN]; + uid = getuid(); + euid = geteuid(); + (void) seteuid(uid); + if (argc < 2) usage(); diff --git a/sbin/restore/tape.c b/sbin/restore/tape.c index 9ecc3cdf92c..6ca315c651a 100644 --- a/sbin/restore/tape.c +++ b/sbin/restore/tape.c @@ -1,4 +1,5 @@ -/* $NetBSD: tape.c,v 1.19 1995/06/19 00:20:32 cgd Exp $ */ +/* $OpenBSD: tape.c,v 1.2 1996/03/21 00:16:32 niklas Exp $ */ +/* $NetBSD: tape.c,v 1.20 1996/03/15 22:39:41 scottr Exp $ */ /* * Copyright (c) 1983, 1993 @@ -42,7 +43,7 @@ #if 0 static char sccsid[] = "@(#)tape.c 8.6 (Berkeley) 9/13/94"; #else -static char rcsid[] = "$NetBSD: tape.c,v 1.19 1995/06/19 00:20:32 cgd Exp $"; +static char rcsid[] = "$NetBSD: tape.c,v 1.20 1996/03/15 22:39:41 scottr Exp $"; #endif #endif /* not lint */ @@ -90,6 +91,9 @@ int oldinofmt; /* old inode format conversion required */ int Bcvt; /* Swap Bytes (for CCI or sun) */ static int Qcvt; /* Swap quads (for sun) */ +extern uid_t uid; /* real uid */ +extern uid_t euid; /* effective uid */ + #define FLUSHTAPEBUF() blkcnt = ntrec + 1 static void accthdr __P((struct s_spcl *)); @@ -151,7 +155,7 @@ setinput(source) } pipein++; } - setuid(getuid()); /* no longer need or want root privileges */ + (void) setuid(uid); /* rmthost() is the only reason to be setuid */ (void) strcpy(magtape, source); } diff --git a/sbin/savecore.old/Makefile b/sbin/savecore.old/Makefile new file mode 100644 index 00000000000..71b014cb6cd --- /dev/null +++ b/sbin/savecore.old/Makefile @@ -0,0 +1,10 @@ +# $OpenBSD: Makefile,v 1.1 1996/03/21 00:16:39 niklas Exp $ +# $NetBSD: Makefile,v 1.1.1.1 1996/03/16 10:25:12 leo Exp $ +# @(#)Makefile 8.2 (Berkeley) 4/17/94 + +PROG= savecore +SRCS= savecore.c zopen.c +MAN= savecore.8 +.PATH: ${.CURDIR}/../../usr.bin/compress + +.include <bsd.prog.mk> diff --git a/sbin/savecore.old/savecore.8 b/sbin/savecore.old/savecore.8 new file mode 100644 index 00000000000..5cf34d9e296 --- /dev/null +++ b/sbin/savecore.old/savecore.8 @@ -0,0 +1,133 @@ +.\" $OpenBSD: savecore.8,v 1.1 1996/03/21 00:16:41 niklas Exp $ +.\" $NetBSD: savecore.8,v 1.1.1.1 1996/03/16 10:25:12 leo Exp $ +.\" +.\" Copyright (c) 1980, 1991, 1993 +.\" The Regents of the University of California. 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. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. +.\" +.\" @(#)savecore.8 8.1 (Berkeley) 6/5/93 +.\" +.Dd June 5, 1993 +.Dt SAVECORE 8 +.Os BSD 4 +.Sh NAME +.Nm savecore +.Nd "save a core dump of the operating system" +.Sh SYNOPSIS +.Nm savecore +.Fl c +.Nm savecore +.Op Fl fvz +.Op Fl N Ar system +.Ar directory +.Sh DESCRIPTION +.Nm Savecore +copies the currently running kernel and its associated core dump into +.Fa directory , +and enters a reboot message and information about the core dump into +the system log. +.Pp +The options are as follows: +.Bl -tag -width directory +.It Fl c +Clears the dump, so that future invocations of +.Nm savecore +will ignore it. +.It Fl f +Forces a dump to be taken even if the dump doesn't appear correct or there +is insufficient disk space. +.It Fl N +Use +.Ar system +as the kernel instead of the default ``/netbsd''. +.It Fl v +Prints out some additional debugging information. +.It Fl z +Compresses the core dump and kernel (see +.Xr compress 1 ). +.El +.Pp +.Nm Savecore +checks the core dump in various ways to make sure that it is current and +that it corresponds to the currently running system. +If it passes these checks, it saves the core image in +.Ar directory Ns Pa /netbsd.#.core +and the system in +.Ar directory Ns Pa /netbsd.# +(or in +.Ar directory Ns Pa /netbsd.#.Z.core +and +.Ar directory Ns Pa /netbsd.#.Z , +respectively, if the +.Fl z +option is used). +The ``#'' is the number from the first line of the file +.Ar directory Ns Pa /bounds , +and it is incremented and stored back into the file each time +.Nm savecore +successfully runs. +.Pp +.Nm Savecore +also checks the available disk space before attempting to make the copies. +If there is insufficient disk space in the filesystem containing +.Ar directory , +or if the file +.Ar directory Ns Pa /minfree +exists and the number of free kilobytes (for non-superusers) in the +filesystem after the copies were made would be less than the number +in the first line of this file, the copies are not attempted. +.Pp +If +.Nm savecore +successfully copies the kernel and the core dump, the core dump is cleared +so that future invocations of +.Nm savecore +will ignore it. +.Pp +.Nm Savecore +is meant to be called near the end of the initialization file +.Pa /etc/rc +(see +.Xr rc 8 ) . +.Sh FILES +.Bl -tag -width /netbsdxx -compact +.It Pa /netbsd +current kernel +.El +.Sh BUGS +The minfree code does not consider the effect of compression. +.Sh SEE ALSO +.Xr compress 1 , +.Xr syslogd 8 +.Sh HISTORY +The +.Nm +command appeared in +.Bx 4.1 . diff --git a/sbin/savecore.old/savecore.c b/sbin/savecore.old/savecore.c new file mode 100644 index 00000000000..dbb9ef18a49 --- /dev/null +++ b/sbin/savecore.old/savecore.c @@ -0,0 +1,663 @@ +/* $OpenBSD: savecore.c,v 1.1 1996/03/21 00:16:43 niklas Exp $ */ +/* $NetBSD: savecore.c,v 1.1.1.1 1996/03/16 10:25:11 leo Exp $ */ + +/*- + * Copyright (c) 1986, 1992, 1993 + * The Regents of the University of California. 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 char copyright[] = +"@(#) Copyright (c) 1986, 1992, 1993\n\ + The Regents of the University of California. All rights reserved.\n"; +#endif /* not lint */ + +#ifndef lint +#if 0 +static char sccsid[] = "@(#)savecore.c 8.3 (Berkeley) 1/2/94"; +#else +static char rcsid[] = "$NetBSD: savecore.c,v 1.1.1.1 1996/03/16 10:25:11 leo Exp $"; +#endif +#endif /* not lint */ + +#include <sys/param.h> +#include <sys/stat.h> +#include <sys/mount.h> +#include <sys/syslog.h> +#include <sys/time.h> + +#include <dirent.h> +#include <errno.h> +#include <fcntl.h> +#include <nlist.h> +#include <paths.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <tzfile.h> +#include <unistd.h> + +extern FILE *zopen __P((const char *fname, const char *mode, int bits)); + +#define ok(number) ((number) - KERNBASE) + +struct nlist current_nl[] = { /* Namelist for currently running system. */ +#define X_DUMPDEV 0 + { "_dumpdev" }, +#define X_DUMPLO 1 + { "_dumplo" }, +#define X_TIME 2 + { "_time" }, +#define X_DUMPSIZE 3 + { "_dumpsize" }, +#define X_VERSION 4 + { "_version" }, +#define X_PANICSTR 5 + { "_panicstr" }, +#define X_DUMPMAG 6 + { "_dumpmag" }, + { "" }, +}; +int cursyms[] = { X_DUMPDEV, X_DUMPLO, X_VERSION, X_DUMPMAG, -1 }; +int dumpsyms[] = { X_TIME, X_DUMPSIZE, X_VERSION, X_PANICSTR, X_DUMPMAG, -1 }; + +struct nlist dump_nl[] = { /* Name list for dumped system. */ + { "_dumpdev" }, /* Entries MUST be the same as */ + { "_dumplo" }, /* those in current_nl[]. */ + { "_time" }, + { "_dumpsize" }, + { "_version" }, + { "_panicstr" }, + { "_dumpmag" }, + { "" }, +}; + +/* Types match kernel declarations. */ +long dumplo; /* where dump starts on dumpdev */ +int dumpmag; /* magic number in dump */ +int dumpsize; /* amount of memory dumped */ + +char *kernel; +char *dirname; /* directory to save dumps in */ +char *ddname; /* name of dump device */ +dev_t dumpdev; /* dump device */ +int dumpfd; /* read/write descriptor on block dev */ +time_t now; /* current date */ +char panic_mesg[1024]; +int panicstr; +char vers[1024]; + +int clear, compress, force, verbose; /* flags */ + +void check_kmem __P((void)); +int check_space __P((void)); +void clear_dump __P((void)); +int Create __P((char *, int)); +int dump_exists __P((void)); +char *find_dev __P((dev_t, int)); +int get_crashtime __P((void)); +void kmem_setup __P((void)); +void log __P((int, char *, ...)); +void Lseek __P((int, off_t, int)); +int Open __P((char *, int rw)); +int Read __P((int, void *, int)); +char *rawname __P((char *s)); +void save_core __P((void)); +void usage __P((void)); +void Write __P((int, void *, int)); + +int +main(argc, argv) + int argc; + char *argv[]; +{ + int ch; + + openlog("savecore", LOG_PERROR, LOG_DAEMON); + + while ((ch = getopt(argc, argv, "cdfN:vz")) != -1) + switch(ch) { + case 'c': + clear = 1; + break; + case 'd': /* Not documented. */ + case 'v': + verbose = 1; + break; + case 'f': + force = 1; + break; + case 'N': + kernel = optarg; + break; + case 'z': + compress = 1; + break; + case '?': + default: + usage(); + } + argc -= optind; + argv += optind; + + if (!clear) { + if (argc != 1 && argc != 2) + usage(); + dirname = argv[0]; + } + if (argc == 2) + kernel = argv[1]; + + (void)time(&now); + kmem_setup(); + + if (clear) { + clear_dump(); + exit(0); + } + + if (!dump_exists() && !force) + exit(1); + + check_kmem(); + + if (panicstr) + syslog(LOG_ALERT, "reboot after panic: %s", panic_mesg); + else + syslog(LOG_ALERT, "reboot"); + + if ((!get_crashtime() || !check_space()) && !force) + exit(1); + + save_core(); + + clear_dump(); + exit(0); +} + +void +kmem_setup() +{ + FILE *fp; + int kmem, i; + char *dump_sys; + + /* + * Some names we need for the currently running system, others for + * the system that was running when the dump was made. The values + * obtained from the current system are used to look for things in + * /dev/kmem that cannot be found in the dump_sys namelist, but are + * presumed to be the same (since the disk partitions are probably + * the same!) + */ + if ((nlist(_PATH_UNIX, current_nl)) == -1) + syslog(LOG_ERR, "%s: nlist: %s", _PATH_UNIX, strerror(errno)); + for (i = 0; cursyms[i] != -1; i++) + if (current_nl[cursyms[i]].n_value == 0) { + syslog(LOG_ERR, "%s: %s not in namelist", + _PATH_UNIX, current_nl[cursyms[i]].n_name); + exit(1); + } + + dump_sys = kernel ? kernel : _PATH_UNIX; + if ((nlist(dump_sys, dump_nl)) == -1) + syslog(LOG_ERR, "%s: nlist: %s", dump_sys, strerror(errno)); + for (i = 0; dumpsyms[i] != -1; i++) + if (dump_nl[dumpsyms[i]].n_value == 0) { + syslog(LOG_ERR, "%s: %s not in namelist", + dump_sys, dump_nl[dumpsyms[i]].n_name); + exit(1); + } + + kmem = Open(_PATH_KMEM, O_RDONLY); + Lseek(kmem, (off_t)current_nl[X_DUMPDEV].n_value, L_SET); + (void)Read(kmem, &dumpdev, sizeof(dumpdev)); + if (dumpdev == NODEV) { + syslog(LOG_WARNING, "no core dump (no dumpdev)"); + exit(1); + } + Lseek(kmem, (off_t)current_nl[X_DUMPLO].n_value, L_SET); + (void)Read(kmem, &dumplo, sizeof(dumplo)); + dumplo *= DEV_BSIZE; + if (verbose) + (void)printf("dumplo = %d (%d * %d)\n", + dumplo, dumplo / DEV_BSIZE, DEV_BSIZE); + Lseek(kmem, (off_t)current_nl[X_DUMPMAG].n_value, L_SET); + (void)Read(kmem, &dumpmag, sizeof(dumpmag)); + ddname = find_dev(dumpdev, S_IFBLK); + dumpfd = Open(ddname, O_RDWR); + fp = fdopen(kmem, "r"); + if (fp == NULL) { + syslog(LOG_ERR, "%s: fdopen: %m", _PATH_KMEM); + exit(1); + } + if (kernel) + return; + (void)fseek(fp, (off_t)current_nl[X_VERSION].n_value, L_SET); + (void)fgets(vers, sizeof(vers), fp); + + /* Don't fclose(fp), we use dumpfd later. */ +} + +void +check_kmem() +{ + register char *cp; + FILE *fp; + char core_vers[1024]; + + fp = fdopen(dumpfd, "r"); + if (fp == NULL) { + syslog(LOG_ERR, "%s: fdopen: %m", ddname); + exit(1); + } + fseek(fp, (off_t)(dumplo + ok(dump_nl[X_VERSION].n_value)), L_SET); + fgets(core_vers, sizeof(core_vers), fp); + if (strcmp(vers, core_vers) && kernel == 0) + syslog(LOG_WARNING, + "warning: %s version mismatch:\n\t%s\nand\t%s\n", + _PATH_UNIX, vers, core_vers); + (void)fseek(fp, + (off_t)(dumplo + ok(dump_nl[X_PANICSTR].n_value)), L_SET); + (void)fread(&panicstr, sizeof(panicstr), 1, fp); + if (panicstr) { + (void)fseek(fp, dumplo + ok(panicstr), L_SET); + cp = panic_mesg; + do + *cp = getc(fp); + while (*cp++ && cp < &panic_mesg[sizeof(panic_mesg)]); + } + /* Don't fclose(fp), we use dumpfd later. */ +} + +void +clear_dump() +{ + long newdumplo; + + newdumplo = 0; + Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_DUMPMAG].n_value)), L_SET); + Write(dumpfd, &newdumplo, sizeof(newdumplo)); +} + +int +dump_exists() +{ + int newdumpmag; + + Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_DUMPMAG].n_value)), L_SET); + (void)Read(dumpfd, &newdumpmag, sizeof(newdumpmag)); + + /* Read the dump size. */ + Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_DUMPSIZE].n_value)), L_SET); + (void)Read(dumpfd, &dumpsize, sizeof(dumpsize)); + dumpsize *= getpagesize(); + + /* + * Return zero if core dump doesn't seem to be there, and note + * it for syslog. This check and return happens after the dump size + * is read, so dumpsize is whether or not the core is valid (for -f). + */ + if (newdumpmag != dumpmag) { + if (verbose) + syslog(LOG_WARNING, "magic number mismatch (%x != %x)", + newdumpmag, dumpmag); + syslog(LOG_WARNING, "no core dump"); + return (0); + } + return (1); +} + +char buf[1024 * 1024]; + +void +save_core() +{ + register FILE *fp; + register int bounds, ifd, nr, nw, ofd; + char *rawp, path[MAXPATHLEN]; + + /* + * Get the current number and update the bounds file. Do the update + * now, because may fail later and don't want to overwrite anything. + */ + (void)snprintf(path, sizeof(path), "%s/bounds", dirname); + if ((fp = fopen(path, "r")) == NULL) + goto err1; + if (fgets(buf, sizeof(buf), fp) == NULL) { + if (ferror(fp)) +err1: syslog(LOG_WARNING, "%s: %s", path, strerror(errno)); + bounds = 0; + } else + bounds = atoi(buf); + if (fp != NULL) + (void)fclose(fp); + if ((fp = fopen(path, "w")) == NULL) + syslog(LOG_ERR, "%s: %m", path); + else { + (void)fprintf(fp, "%d\n", bounds + 1); + (void)fclose(fp); + } + (void)fclose(fp); + + /* Create the core file. */ + (void)snprintf(path, sizeof(path), "%s/netbsd.%d.core%s", + dirname, bounds, compress ? ".Z" : ""); + if (compress) { + if ((fp = zopen(path, "w", 0)) == NULL) { + syslog(LOG_ERR, "%s: %s", path, strerror(errno)); + exit(1); + } + } else + ofd = Create(path, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + + /* Open the raw device. */ + rawp = rawname(ddname); + if ((ifd = open(rawp, O_RDONLY)) == -1) { + syslog(LOG_WARNING, "%s: %m; using block device", rawp); + ifd = dumpfd; + } + + /* Seek to the start of the core. */ + Lseek(ifd, (off_t)dumplo, L_SET); + + /* Copy the core file. */ + syslog(LOG_NOTICE, "writing %score to %s", + compress ? "compressed " : "", path); + for (; dumpsize > 0; dumpsize -= nr) { + (void)printf("%6dK\r", dumpsize / 1024); + (void)fflush(stdout); + nr = read(ifd, buf, MIN(dumpsize, sizeof(buf))); + if (nr <= 0) { + if (nr == 0) + syslog(LOG_WARNING, + "WARNING: EOF on dump device"); + else + syslog(LOG_ERR, "%s: %m", rawp); + goto err2; + } + if (compress) + nw = fwrite(buf, 1, nr, fp); + else + nw = write(ofd, buf, nr); + if (nw != nr) { + syslog(LOG_ERR, "%s: %s", + path, strerror(nw == 0 ? EIO : errno)); +err2: syslog(LOG_WARNING, + "WARNING: core may be incomplete"); + (void)printf("\n"); + exit(1); + } + } + (void)close(ifd); + if (compress) + (void)fclose(fp); + else + (void)close(ofd); + + /* Copy the kernel. */ + ifd = Open(kernel ? kernel : _PATH_UNIX, O_RDONLY); + (void)snprintf(path, sizeof(path), "%s/netbsd.%d%s", + dirname, bounds, compress ? ".Z" : ""); + if (compress) { + if ((fp = zopen(path, "w", 0)) == NULL) { + syslog(LOG_ERR, "%s: %s", path, strerror(errno)); + exit(1); + } + } else + ofd = Create(path, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + syslog(LOG_NOTICE, "writing %skernel to %s", + compress ? "compressed " : "", path); + while ((nr = read(ifd, buf, sizeof(buf))) > 0) { + if (compress) + nw = fwrite(buf, 1, nr, fp); + else + nw = write(ofd, buf, nr); + if (nw != nr) { + syslog(LOG_ERR, "%s: %s", + path, strerror(nw == 0 ? EIO : errno)); + syslog(LOG_WARNING, + "WARNING: kernel may be incomplete"); + exit(1); + } + } + if (nr < 0) { + syslog(LOG_ERR, "%s: %s", + kernel ? kernel : _PATH_UNIX, strerror(errno)); + syslog(LOG_WARNING, + "WARNING: kernel may be incomplete"); + exit(1); + } + if (compress) + (void)fclose(fp); + else + (void)close(ofd); +} + +char * +find_dev(dev, type) + register dev_t dev; + register int type; +{ + register DIR *dfd; + struct dirent *dir; + struct stat sb; + char *dp, devname[MAXPATHLEN + 1]; + + if ((dfd = opendir(_PATH_DEV)) == NULL) { + syslog(LOG_ERR, "%s: %s", _PATH_DEV, strerror(errno)); + exit(1); + } + (void)strcpy(devname, _PATH_DEV); + while ((dir = readdir(dfd))) { + (void)strcpy(devname + sizeof(_PATH_DEV) - 1, dir->d_name); + if (lstat(devname, &sb)) { + syslog(LOG_ERR, "%s: %s", devname, strerror(errno)); + continue; + } + if ((sb.st_mode & S_IFMT) != type) + continue; + if (dev == sb.st_rdev) { + closedir(dfd); + if ((dp = strdup(devname)) == NULL) { + syslog(LOG_ERR, "%s", strerror(errno)); + exit(1); + } + return (dp); + } + } + closedir(dfd); + syslog(LOG_ERR, "can't find device %d/%d", major(dev), minor(dev)); + exit(1); +} + +char * +rawname(s) + char *s; +{ + char *sl, name[MAXPATHLEN]; + + if ((sl = strrchr(s, '/')) == NULL || sl[1] == '0') { + syslog(LOG_ERR, + "can't make raw dump device name from %s", s); + return (s); + } + (void)snprintf(name, sizeof(name), "%.*s/r%s", sl - s, s, sl + 1); + if ((sl = strdup(name)) == NULL) { + syslog(LOG_ERR, "%s", strerror(errno)); + exit(1); + } + return (sl); +} + +int +get_crashtime() +{ + time_t dumptime; /* Time the dump was taken. */ + + Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_TIME].n_value)), L_SET); + (void)Read(dumpfd, &dumptime, sizeof(dumptime)); + if (dumptime == 0) { + if (verbose) + syslog(LOG_ERR, "dump time is zero"); + return (0); + } + (void)printf("savecore: system went down at %s", ctime(&dumptime)); +#define LEEWAY (7 * SECSPERDAY) + if (dumptime < now - LEEWAY || dumptime > now + LEEWAY) { + (void)printf("dump time is unreasonable\n"); + return (0); + } + return (1); +} + +int +check_space() +{ + register FILE *fp; + char *tkernel; + off_t minfree, spacefree, kernelsize, needed; + struct stat st; + struct statfs fsbuf; + char buf[100], path[MAXPATHLEN]; + + tkernel = kernel ? kernel : _PATH_UNIX; + if (stat(tkernel, &st) < 0) { + syslog(LOG_ERR, "%s: %m", tkernel); + exit(1); + } + kernelsize = st.st_blocks * S_BLKSIZE; + if (statfs(dirname, &fsbuf) < 0) { + syslog(LOG_ERR, "%s: %m", dirname); + exit(1); + } + spacefree = (fsbuf.f_bavail * fsbuf.f_bsize) / 1024; + + (void)snprintf(path, sizeof(path), "%s/minfree", dirname); + if ((fp = fopen(path, "r")) == NULL) + minfree = 0; + else { + if (fgets(buf, sizeof(buf), fp) == NULL) + minfree = 0; + else + minfree = atoi(buf); + (void)fclose(fp); + } + + needed = (dumpsize + kernelsize) / 1024; + if (minfree > 0 && spacefree - needed < minfree) { + syslog(LOG_WARNING, + "no dump, not enough free space on device"); + return (0); + } + if (spacefree - needed < minfree) + syslog(LOG_WARNING, + "dump performed, but free space threshold crossed"); + return (1); +} + +int +Open(name, rw) + char *name; + int rw; +{ + int fd; + + if ((fd = open(name, rw, 0)) < 0) { + syslog(LOG_ERR, "%s: %m", name); + exit(1); + } + return (fd); +} + +int +Read(fd, bp, size) + int fd, size; + void *bp; +{ + int nr; + + nr = read(fd, bp, size); + if (nr != size) { + syslog(LOG_ERR, "read: %m"); + exit(1); + } + return (nr); +} + +void +Lseek(fd, off, flag) + int fd, flag; + off_t off; +{ + off_t ret; + + ret = lseek(fd, off, flag); + if (ret == -1) { + syslog(LOG_ERR, "lseek: %m"); + exit(1); + } +} + +int +Create(file, mode) + char *file; + int mode; +{ + register int fd; + + fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, mode); + if (fd < 0) { + syslog(LOG_ERR, "%s: %m", file); + exit(1); + } + return (fd); +} + +void +Write(fd, bp, size) + int fd, size; + void *bp; +{ + int n; + + if ((n = write(fd, bp, size)) < size) { + syslog(LOG_ERR, "write: %s", strerror(n == -1 ? errno : EIO)); + exit(1); + } +} + +void +usage() +{ + (void)syslog(LOG_ERR, "usage: savecore [-cfvz] [-N system] directory"); + exit(1); +} diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c index d77f1251568..fe65684c0e5 100644 --- a/sbin/savecore/savecore.c +++ b/sbin/savecore/savecore.c @@ -1,4 +1,5 @@ -/* $NetBSD: savecore.c,v 1.23 1995/07/24 20:35:02 cgd Exp $ */ +/* $OpenBSD: savecore.c,v 1.3 1996/03/21 00:16:36 niklas Exp $ */ +/* $NetBSD: savecore.c,v 1.25 1996/03/16 10:29:46 leo Exp $ */ /*- * Copyright (c) 1986, 1992, 1993 @@ -43,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)savecore.c 8.3 (Berkeley) 1/2/94"; #else -static char rcsid[] = "$NetBSD: savecore.c,v 1.23 1995/07/24 20:35:02 cgd Exp $"; +static char rcsid[] = "$NetBSD: savecore.c,v 1.25 1996/03/16 10:29:46 leo Exp $"; #endif #endif /* not lint */ @@ -63,10 +64,13 @@ static char rcsid[] = "$NetBSD: savecore.c,v 1.23 1995/07/24 20:35:02 cgd Exp $" #include <string.h> #include <tzfile.h> #include <unistd.h> +#include <limits.h> +#include <kvm.h> extern FILE *zopen __P((const char *fname, const char *mode, int bits)); -#define ok(number) ((number) - KERNBASE) +#define KREAD(kd, addr, p)\ + (kvm_read(kd, addr, (char *)(p), sizeof(*(p))) != sizeof(*(p))) struct nlist current_nl[] = { /* Namelist for currently running system. */ #define X_DUMPDEV 0 @@ -83,7 +87,7 @@ struct nlist current_nl[] = { /* Namelist for currently running system. */ { "_panicstr" }, #define X_DUMPMAG 6 { "_dumpmag" }, - { "" }, + { NULL }, }; int cursyms[] = { X_DUMPDEV, X_DUMPLO, X_VERSION, X_DUMPMAG, -1 }; int dumpsyms[] = { X_TIME, X_DUMPSIZE, X_VERSION, X_PANICSTR, X_DUMPMAG, -1 }; @@ -96,7 +100,7 @@ struct nlist dump_nl[] = { /* Name list for dumped system. */ { "_version" }, { "_panicstr" }, { "_dumpmag" }, - { "" }, + { NULL }, }; /* Types match kernel declarations. */ @@ -109,6 +113,7 @@ char *dirname; /* directory to save dumps in */ char *ddname; /* name of dump device */ dev_t dumpdev; /* dump device */ int dumpfd; /* read/write descriptor on block dev */ +kvm_t *kd_dump; /* kvm descriptor on block dev */ time_t now; /* current date */ char panic_mesg[1024]; int panicstr; @@ -127,7 +132,6 @@ void kmem_setup __P((void)); void log __P((int, char *, ...)); void Lseek __P((int, off_t, int)); int Open __P((char *, int rw)); -int Read __P((int, void *, int)); char *rawname __P((char *s)); void save_core __P((void)); void usage __P((void)); @@ -205,9 +209,10 @@ main(argc, argv) void kmem_setup() { - FILE *fp; - int kmem, i; - char *dump_sys; + kvm_t *kd_kern; + char errbuf[_POSIX2_LINE_MAX]; + int i, hdrsz; + char *dump_sys; /* * Some names we need for the currently running system, others for @@ -217,8 +222,15 @@ kmem_setup() * presumed to be the same (since the disk partitions are probably * the same!) */ - if ((nlist(_PATH_UNIX, current_nl)) == -1) - syslog(LOG_ERR, "%s: nlist: %s", _PATH_UNIX, strerror(errno)); + kd_kern = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); + if (kd_kern == NULL) { + syslog(LOG_ERR, "%s: kvm_openfiles: %s", _PATH_UNIX, errbuf); + exit(1); + } + if (kvm_nlist(kd_kern, current_nl) == -1) + syslog(LOG_ERR, "%s: kvm_nlist: %s", _PATH_UNIX, + kvm_geterr(kd_kern)); + for (i = 0; cursyms[i] != -1; i++) if (current_nl[cursyms[i]].n_value == 0) { syslog(LOG_ERR, "%s: %s not in namelist", @@ -226,85 +238,80 @@ kmem_setup() exit(1); } - dump_sys = kernel ? kernel : _PATH_UNIX; - if ((nlist(dump_sys, dump_nl)) == -1) - syslog(LOG_ERR, "%s: nlist: %s", dump_sys, strerror(errno)); - for (i = 0; dumpsyms[i] != -1; i++) - if (dump_nl[dumpsyms[i]].n_value == 0) { - syslog(LOG_ERR, "%s: %s not in namelist", - dump_sys, dump_nl[dumpsyms[i]].n_name); - exit(1); - } - - kmem = Open(_PATH_KMEM, O_RDONLY); - Lseek(kmem, (off_t)current_nl[X_DUMPDEV].n_value, L_SET); - (void)Read(kmem, &dumpdev, sizeof(dumpdev)); + KREAD(kd_kern, current_nl[X_DUMPDEV].n_value, &dumpdev); if (dumpdev == NODEV) { syslog(LOG_WARNING, "no core dump (no dumpdev)"); exit(1); } - Lseek(kmem, (off_t)current_nl[X_DUMPLO].n_value, L_SET); - (void)Read(kmem, &dumplo, sizeof(dumplo)); + KREAD(kd_kern, current_nl[X_DUMPLO].n_value, &dumplo); dumplo *= DEV_BSIZE; if (verbose) (void)printf("dumplo = %d (%d * %d)\n", dumplo, dumplo / DEV_BSIZE, DEV_BSIZE); - Lseek(kmem, (off_t)current_nl[X_DUMPMAG].n_value, L_SET); - (void)Read(kmem, &dumpmag, sizeof(dumpmag)); + KREAD(kd_kern, current_nl[X_DUMPMAG].n_value, &dumpmag); + + if (kernel == NULL) { + (void)kvm_read(kd_kern, current_nl[X_VERSION].n_value, + vers, sizeof(vers)); + vers[sizeof(vers) - 1] = '\0'; + } + ddname = find_dev(dumpdev, S_IFBLK); dumpfd = Open(ddname, O_RDWR); - fp = fdopen(kmem, "r"); - if (fp == NULL) { - syslog(LOG_ERR, "%s: fdopen: %m", _PATH_KMEM); + + dump_sys = kernel ? kernel : _PATH_UNIX; + + kd_dump = kvm_openfiles(dump_sys, ddname, NULL, O_RDWR, errbuf); + if (kd_dump == NULL) { + syslog(LOG_ERR, "%s: kvm_openfiles: %s", dump_sys, errbuf); exit(1); } - if (kernel) - return; - (void)fseek(fp, (off_t)current_nl[X_VERSION].n_value, L_SET); - (void)fgets(vers, sizeof(vers), fp); - /* Don't fclose(fp), we use dumpfd later. */ + if (kvm_nlist(kd_dump, dump_nl) == -1) + syslog(LOG_ERR, "%s: kvm_nlist: %s", dump_sys, + kvm_geterr(kd_dump)); + + for (i = 0; dumpsyms[i] != -1; i++) + if (dump_nl[dumpsyms[i]].n_value == 0) { + syslog(LOG_ERR, "%s: %s not in namelist", + dump_sys, dump_nl[dumpsyms[i]].n_name); + exit(1); + } + hdrsz = kvm_dump_mkheader(kd_kern, kd_dump, (off_t)dumplo); + if (hdrsz == -1) { + syslog(LOG_ERR, "%s: kvm_dump_mkheader: %s", dump_sys, + kvm_geterr(kd_kern)); + exit(1); + } + dumplo += hdrsz; + kvm_close(kd_kern); } void check_kmem() { - register char *cp; - FILE *fp; + register char *cp; + register int panicloc; char core_vers[1024]; - fp = fdopen(dumpfd, "r"); - if (fp == NULL) { - syslog(LOG_ERR, "%s: fdopen: %m", ddname); - exit(1); - } - fseek(fp, (off_t)(dumplo + ok(dump_nl[X_VERSION].n_value)), L_SET); - fgets(core_vers, sizeof(core_vers), fp); + (void)kvm_read(kd_dump, dump_nl[X_VERSION].n_value, core_vers, + sizeof(core_vers)); + core_vers[sizeof(core_vers) - 1] = '\0'; + if (strcmp(vers, core_vers) && kernel == 0) syslog(LOG_WARNING, "warning: %s version mismatch:\n\t%s\nand\t%s\n", _PATH_UNIX, vers, core_vers); - (void)fseek(fp, - (off_t)(dumplo + ok(dump_nl[X_PANICSTR].n_value)), L_SET); - (void)fread(&panicstr, sizeof(panicstr), 1, fp); + + KREAD(kd_dump, dump_nl[X_PANICSTR].n_value, &panicstr); if (panicstr) { - (void)fseek(fp, dumplo + ok(panicstr), L_SET); - cp = panic_mesg; - do - *cp = getc(fp); - while (*cp++ && cp < &panic_mesg[sizeof(panic_mesg)]); + cp = panic_mesg; + panicloc = panicstr; + do { + KREAD(kd_dump, panicloc, cp); + panicloc++; + } while (*cp++ && cp < &panic_mesg[sizeof(panic_mesg)]); } - /* Don't fclose(fp), we use dumpfd later. */ -} - -void -clear_dump() -{ - long newdumplo; - - newdumplo = 0; - Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_DUMPMAG].n_value)), L_SET); - Write(dumpfd, &newdumplo, sizeof(newdumplo)); } int @@ -312,12 +319,10 @@ dump_exists() { int newdumpmag; - Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_DUMPMAG].n_value)), L_SET); - (void)Read(dumpfd, &newdumpmag, sizeof(newdumpmag)); + KREAD(kd_dump, dump_nl[X_DUMPMAG].n_value, &newdumpmag); /* Read the dump size. */ - Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_DUMPSIZE].n_value)), L_SET); - (void)Read(dumpfd, &dumpsize, sizeof(dumpsize)); + KREAD(kd_dump, dump_nl[X_DUMPSIZE].n_value, &dumpsize); dumpsize *= getpagesize(); /* @@ -335,6 +340,15 @@ dump_exists() return (1); } +void +clear_dump() +{ + if (kvm_dump_inval(kd_dump) == -1) + syslog(LOG_ERR, "%s: kvm_clear_dump: %s", ddname, + kvm_geterr(kd_dump)); + +} + char buf[1024 * 1024]; void @@ -368,15 +382,21 @@ err1: syslog(LOG_WARNING, "%s: %s", path, strerror(errno)); (void)fclose(fp); /* Create the core file. */ - (void)snprintf(path, sizeof(path), "%s/bsd.%d%s.core", + (void)snprintf(path, sizeof(path), "%s/bsd.%d.core%s", dirname, bounds, compress ? ".Z" : ""); if (compress) { if ((fp = zopen(path, "w", 0)) == NULL) { syslog(LOG_ERR, "%s: %s", path, strerror(errno)); exit(1); } - } else + } else { ofd = Create(path, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + fp = fdopen(ofd, "w"); + if (fp == NULL) { + syslog(LOG_ERR, "%s: fdopen: %s", path); + exit(1); + } + } /* Open the raw device. */ rawp = rawname(ddname); @@ -388,6 +408,12 @@ err1: syslog(LOG_WARNING, "%s: %s", path, strerror(errno)); /* Seek to the start of the core. */ Lseek(ifd, (off_t)dumplo, L_SET); + if (kvm_dump_wrtheader(kd_dump, fp, dumpsize) == -1) { + syslog(LOG_ERR, "kvm_dump_wrtheader: %s : %s", path, + kvm_geterr(kd_dump)); + exit(1); + } + /* Copy the core file. */ syslog(LOG_NOTICE, "writing %score to %s", compress ? "compressed " : "", path); @@ -403,10 +429,7 @@ err1: syslog(LOG_WARNING, "%s: %s", path, strerror(errno)); syslog(LOG_ERR, "%s: %m", rawp); goto err2; } - if (compress) - nw = fwrite(buf, 1, nr, fp); - else - nw = write(ofd, buf, nr); + nw = fwrite(buf, 1, nr, fp); if (nw != nr) { syslog(LOG_ERR, "%s: %s", path, strerror(nw == 0 ? EIO : errno)); @@ -417,10 +440,7 @@ err2: syslog(LOG_WARNING, } } (void)close(ifd); - if (compress) - (void)fclose(fp); - else - (void)close(ofd); + (void)fclose(fp); /* Copy the kernel. */ ifd = Open(kernel ? kernel : _PATH_UNIX, O_RDONLY); @@ -522,8 +542,7 @@ get_crashtime() { time_t dumptime; /* Time the dump was taken. */ - Lseek(dumpfd, (off_t)(dumplo + ok(dump_nl[X_TIME].n_value)), L_SET); - (void)Read(dumpfd, &dumptime, sizeof(dumptime)); + KREAD(kd_dump, dump_nl[X_TIME].n_value, &dumptime); if (dumptime == 0) { if (verbose) syslog(LOG_ERR, "dump time is zero"); @@ -597,21 +616,6 @@ Open(name, rw) return (fd); } -int -Read(fd, bp, size) - int fd, size; - void *bp; -{ - int nr; - - nr = read(fd, bp, size); - if (nr != size) { - syslog(LOG_ERR, "read: %m"); - exit(1); - } - return (nr); -} - void Lseek(fd, off, flag) int fd, flag; |