summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>1996-05-22 11:34:43 +0000
committerderaadt <deraadt@openbsd.org>1996-05-22 11:34:43 +0000
commit4b826ba8ef7118cfb0442afaa8b454015556f1ee (patch)
tree4ee6d433b487f8be05483a9299c0c2291d4782e6
parentnew vi (diff)
downloadwireguard-openbsd-4b826ba8ef7118cfb0442afaa8b454015556f1ee.tar.xz
wireguard-openbsd-4b826ba8ef7118cfb0442afaa8b454015556f1ee.zip
libutil
-rw-r--r--include/Makefile19
-rw-r--r--include/pwd.h3
-rw-r--r--include/util.h67
-rw-r--r--lib/libutil/Makefile22
-rw-r--r--lib/libutil/getmaxpartitions.358
-rw-r--r--lib/libutil/getmaxpartitions.c60
-rw-r--r--lib/libutil/getrawpartition.369
-rw-r--r--lib/libutil/getrawpartition.c60
-rw-r--r--lib/libutil/login.3107
-rw-r--r--lib/libutil/login.c5
-rw-r--r--lib/libutil/login_tty.c5
-rw-r--r--lib/libutil/logout.c8
-rw-r--r--lib/libutil/logwtmp.c7
-rw-r--r--lib/libutil/openpty.3153
-rw-r--r--lib/libutil/passwd.c347
-rw-r--r--lib/libutil/pty.c14
-rw-r--r--lib/libutil/pw_init.3174
-rw-r--r--lib/libutil/pw_lock.3100
-rw-r--r--lib/libutil/shlib_version2
-rw-r--r--libexec/rpc.yppasswdd/Makefile9
-rw-r--r--libexec/rpc.yppasswdd/yppasswdd_mkpw.c5
-rw-r--r--sbin/ccdconfig/Makefile6
-rw-r--r--sbin/ccdconfig/ccdconfig.c37
-rw-r--r--sbin/init/init.c12
-rw-r--r--sbin/newfs/Makefile5
-rw-r--r--sbin/newfs/newfs.c22
-rw-r--r--sbin/newlfs/Makefile5
-rw-r--r--sbin/newlfs/newfs.c21
-rw-r--r--usr.bin/chpass/Makefile12
-rw-r--r--usr.bin/chpass/chpass.18
-rw-r--r--usr.bin/chpass/chpass.c66
-rw-r--r--usr.bin/chpass/chpass.h8
-rw-r--r--usr.bin/chpass/edit.c24
-rw-r--r--usr.bin/chpass/pw_copy.c113
-rw-r--r--usr.bin/chpass/pw_copy.h38
-rw-r--r--usr.bin/login/login.c5
-rw-r--r--usr.bin/passwd/Makefile17
-rw-r--r--usr.bin/passwd/local_passwd.c16
-rw-r--r--usr.bin/systat/Makefile17
-rw-r--r--usr.bin/systat/cmds.c10
-rw-r--r--usr.bin/systat/disks.c108
-rw-r--r--usr.bin/systat/extern.h4
-rw-r--r--usr.bin/systat/iostat.c154
-rw-r--r--usr.bin/systat/main.c62
-rw-r--r--usr.bin/systat/swap.c6
-rw-r--r--usr.bin/systat/systat.150
-rw-r--r--usr.bin/systat/vmstat.c77
-rw-r--r--usr.bin/vmstat/Makefile8
-rw-r--r--usr.bin/vmstat/dkstats.c8
-rw-r--r--usr.bin/vmstat/dkstats.h5
-rw-r--r--usr.bin/vmstat/vmstat.84
-rw-r--r--usr.bin/vmstat/vmstat.c128
-rw-r--r--usr.sbin/iostat/Makefile12
-rw-r--r--usr.sbin/iostat/iostat.84
-rw-r--r--usr.sbin/iostat/iostat.c12
-rw-r--r--usr.sbin/pwd_mkdb/Makefile6
-rw-r--r--usr.sbin/pwd_mkdb/pw_scan.c137
-rw-r--r--usr.sbin/pwd_mkdb/pw_scan.h36
-rw-r--r--usr.sbin/pwd_mkdb/pwd_mkdb.c5
-rw-r--r--usr.sbin/vipw/Makefile6
-rw-r--r--usr.sbin/vipw/pw_util.c222
-rw-r--r--usr.sbin/vipw/pw_util.h44
-rw-r--r--usr.sbin/vipw/vipw.c30
63 files changed, 1619 insertions, 1245 deletions
diff --git a/include/Makefile b/include/Makefile
index 548bbbff26f..f1670e8fb0c 100644
--- a/include/Makefile
+++ b/include/Makefile
@@ -1,23 +1,26 @@
-# $OpenBSD: Makefile,v 1.7 1996/05/06 21:44:19 deraadt Exp $
-# $NetBSD: Makefile,v 1.57 1996/04/25 00:55:44 jtc Exp $
+# $OpenBSD: Makefile,v 1.8 1996/05/22 11:34:45 deraadt Exp $
+# $NetBSD: Makefile,v 1.59 1996/05/15 21:36:43 jtc Exp $
# @(#)Makefile 5.45.1.1 (Berkeley) 5/6/91
-# Doing a make install builds /usr/include
-#
# The ``rm -rf''s used below are safe because rm doesn't follow symbolic
# links.
# Missing: mp.h
FILES= a.out.h ar.h assert.h bitstring.h bm.h cpio.h ctype.h db.h dirent.h \
- disktab.h dlfcn.h elf_abi.h err.h fnmatch.h fstab.h fts.h glob.h \
- grp.h ieeefp.h iso646.h kvm.h langinfo.h limits.h link.h locale.h \
+ disktab.h elf_abi.h err.h fnmatch.h fstab.h fts.h glob.h \
+ grp.h ieeefp.h iso646.h kvm.h langinfo.h limits.h locale.h \
malloc.h math.h memory.h mpool.h ndbm.h netdb.h netgroup.h nlist.h \
- nl_types.h paths.h pwd.h ranlib.h re_comp.h regex.h regexp.h resolv.h \
+ nl_types.h paths.h poll.h pwd.h ranlib.h re_comp.h regex.h regexp.h \
+ resolv.h \
search.h setjmp.h sgtty.h signal.h stab.h stddef.h stdio.h stdlib.h \
string.h strings.h struct.h sysexits.h tar.h time.h ttyent.h tzfile.h \
- unistd.h utime.h utmp.h vis.h
+ unistd.h util.h utime.h utmp.h vis.h
+
+.if (${MACHINE_ARCH} != "alpha")
+FILES+= dlfcn.h link.h
+.endif
MFILES= float.h frame.h stdarg.h varargs.h
LFILES= errno.h fcntl.h syslog.h termios.h
diff --git a/include/pwd.h b/include/pwd.h
index 767ae19d3e5..7493ee92dc5 100644
--- a/include/pwd.h
+++ b/include/pwd.h
@@ -1,4 +1,4 @@
-/* $NetBSD: pwd.h,v 1.8 1995/07/28 05:30:52 phil Exp $ */
+/* $NetBSD: pwd.h,v 1.9 1996/05/15 21:36:45 jtc Exp $ */
/*-
* Copyright (c) 1989, 1993
@@ -49,6 +49,7 @@
#ifndef _POSIX_SOURCE
#define _PATH_PASSWD "/etc/passwd"
#define _PATH_MASTERPASSWD "/etc/master.passwd"
+#define _PATH_MASTERPASSWD_LOCK "/etc/ptmp"
#define _PATH_MP_DB "/etc/pwd.db"
#define _PATH_SMP_DB "/etc/spwd.db"
diff --git a/include/util.h b/include/util.h
new file mode 100644
index 00000000000..96202ae2545
--- /dev/null
+++ b/include/util.h
@@ -0,0 +1,67 @@
+/* $NetBSD: util.h,v 1.2 1996/05/16 07:00:22 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 1995
+ * 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 _UTIL_H_
+#define _UTIL_H_
+
+#include <pwd.h>
+#include <utmp.h>
+#include <termios.h>
+#include <sys/ttycom.h>
+#include <sys/types.h>
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+void login __P((struct utmp *));
+int login_tty __P((int));
+int logout __P((const char *));
+void logwtmp __P((const char *, const char *, const char *));
+int pw_lock __P((int retries));
+int pw_mkdb __P((void));
+int pw_abort __P((void));
+void pw_init __P((void));
+void pw_edit __P((int notsetuid, const char *filename));
+void pw_prompt __P((void));
+void pw_copy __P((int ffd, int tfd, struct passwd *pw));
+int pw_scan __P((char *bp, struct passwd *pw, int *flags));
+void pw_error __P((const char *name, int err, int eval));
+int openpty __P((int *, int *, char *, struct termios *,
+ struct winsize *));
+pid_t forkpty __P((int *, char *, struct termios *, struct winsize *));
+int getmaxpartitions __P((void));
+int getrawpartition __P((void));
+__END_DECLS
+
+#endif /* !_UTIL_H_ */
diff --git a/lib/libutil/Makefile b/lib/libutil/Makefile
index 7c1299b0237..0e629329d6a 100644
--- a/lib/libutil/Makefile
+++ b/lib/libutil/Makefile
@@ -1,8 +1,24 @@
-# from: @(#)Makefile 8.1 (Berkeley) 6/4/93
-# $Id: Makefile,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $
+# $OpenBSD: Makefile,v 1.2 1996/05/22 11:34:58 deraadt Exp $
+# $NetBSD: Makefile,v 1.8 1996/05/16 07:03:28 thorpej Exp $
LIB= util
CFLAGS+=-DLIBC_SCCS
-SRCS= login.c login_tty.c logout.c logwtmp.c pty.c
+SRCS= getmaxpartitions.c getrawpartition.c login.c login_tty.c logout.c \
+ logwtmp.c passwd.c pty.c
+
+MAN= getmaxpartitions.3 getrawpartition.3 login.3 openpty.3 pw_init.3 \
+ pw_lock.3
+
+MLINKS+=login.3 logout.3
+MLINKS+=login.3 logwtmp.3
+MLINKS+=openpty.3 login_tty.3
+MLINKS+=openpty.3 forkpty.3
+MLINKS+=pw_init.3 pw_edit.3
+MLINKS+=pw_init.3 pw_prompt.3
+MLINKS+=pw_init.3 pw_copy.3
+MLINKS+=pw_init.3 pw_scan.3
+MLINKS+=pw_init.3 pw_error.3
+MLINKS+=pw_lock.3 pw_mkdb.3
+MLINKS+=pw_lock.3 pw_abort.3
.include <bsd.lib.mk>
diff --git a/lib/libutil/getmaxpartitions.3 b/lib/libutil/getmaxpartitions.3
new file mode 100644
index 00000000000..426c53e0928
--- /dev/null
+++ b/lib/libutil/getmaxpartitions.3
@@ -0,0 +1,58 @@
+.\" $NetBSD: getmaxpartitions.3,v 1.1 1996/05/16 07:03:30 thorpej Exp $
+.\"
+.\" 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:
+.\" 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.
+.\"
+.Dd May 15, 1996
+.Dt GETMAXPARTITIONS 3
+.Os NetBSD
+.Sh NAME
+.Nm getmaxpartitions
+.Nd get the maximum number of partitions allowed per disk
+.Sh SYNOPSIS
+.Fd #include <util.h>
+.Ft int
+.Fn getmaxpartitions void
+.Sh DESCRIPTION
+.Fn Getmaxpartitions
+returns the number of partitions that are allowed per disk on the
+system.
+.Sh SEE ALSO
+.Xr getrawpartition 3 ,
+.Xr sysctl 3
+.Sh HISTORY
+The
+.Nm
+function call appeared in
+.Nx 1.2 .
diff --git a/lib/libutil/getmaxpartitions.c b/lib/libutil/getmaxpartitions.c
new file mode 100644
index 00000000000..493c885bc25
--- /dev/null
+++ b/lib/libutil/getmaxpartitions.c
@@ -0,0 +1,60 @@
+/* $NetBSD: getmaxpartitions.c,v 1.1 1996/05/16 07:03:31 thorpej Exp $ */
+
+/*-
+ * 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:
+ * 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$NetBSD: getmaxpartitions.c,v 1.1 1996/05/16 07:03:31 thorpej Exp $";
+#endif
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <util.h>
+
+int
+getmaxpartitions()
+{
+ int maxpart, mib[2];
+ size_t varlen;
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_MAXPARTITIONS;
+ varlen = sizeof(maxpart);
+ if (sysctl(mib, 2, &maxpart, &varlen, NULL, 0) < 0)
+ return (-1);
+
+ return (maxpart);
+}
diff --git a/lib/libutil/getrawpartition.3 b/lib/libutil/getrawpartition.3
new file mode 100644
index 00000000000..290d4a34f87
--- /dev/null
+++ b/lib/libutil/getrawpartition.3
@@ -0,0 +1,69 @@
+.\" $NetBSD: getrawpartition.3,v 1.1 1996/05/16 07:03:32 thorpej Exp $
+.\"
+.\" 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:
+.\" 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.
+.\"
+.Dd May 15, 1996
+.Dt GETRAWPARTITION 3
+.Os NetBSD
+.Sh NAME
+.Nm getrawpartition
+.Nd get the system
+.Dq raw
+partition
+.Sh SYNOPSIS
+.Fd #include <util.h>
+.Ft int
+.Fn getrawpartition void
+.Sh DESCRIPTION
+.Fn Getrawpartition
+returns the partition number (
+.Sq a
+== 0,
+.Sq b
+== 1, ...) of the
+.Dq raw
+partition of the system's disks.
+The
+.Dq raw
+partition is defined as the partition which provides access to the entire
+disk, regardless of the disk's partition map.
+.Sh SEE ALSO
+.Xr getmaxpartitions 3 ,
+.Xr sysctl 3
+.Sh HISTORY
+The
+.Nm
+function call appeared in
+.Nx 1.2 .
diff --git a/lib/libutil/getrawpartition.c b/lib/libutil/getrawpartition.c
new file mode 100644
index 00000000000..239a030f84b
--- /dev/null
+++ b/lib/libutil/getrawpartition.c
@@ -0,0 +1,60 @@
+/* $NetBSD: getrawpartition.c,v 1.1 1996/05/16 07:03:33 thorpej Exp $ */
+
+/*-
+ * 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:
+ * 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$NetBSD: getrawpartition.c,v 1.1 1996/05/16 07:03:33 thorpej Exp $";
+#endif
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <util.h>
+
+int
+getrawpartition()
+{
+ int rawpart, mib[2];
+ size_t varlen;
+
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_RAWPARTITION;
+ varlen = sizeof(rawpart);
+ if (sysctl(mib, 2, &rawpart, &varlen, NULL, 0) < 0)
+ return (-1);
+
+ return (rawpart);
+}
diff --git a/lib/libutil/login.3 b/lib/libutil/login.3
new file mode 100644
index 00000000000..eae46302e21
--- /dev/null
+++ b/lib/libutil/login.3
@@ -0,0 +1,107 @@
+.\" Copyright (c) 1995
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software developed by the Computer Systems
+.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
+.\" BG 91-66 and contributed to Berkeley.
+.\"
+.\" 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.
+.\"
+.Dd December 14, 1995
+.Dt LOGIN 3
+.Os
+.Sh NAME
+.Nm login ,
+.Nm logout ,
+.Nm logwtmp
+.Nd login utility functions
+.Sh SYNOPSIS
+.Fd #include <util.h>
+.Ft void
+.Fn login "struct utmp *ut"
+.Ft int
+.Fn logout "const char *line"
+.Ft void
+.Fn logwtmp "const char *line" "const char *name" "const char *host"
+.Sh DESCRIPTION
+The
+.Fn login ,
+.Fn logout ,
+and
+.Fn logwtmp
+functions operate on the database of current users in
+.Pa /var/run/utmp
+and on the logfile
+.Pa /var/log/wtmp
+of logins and logouts.
+.Pp
+The
+.Fn login
+function updates the
+.Pa /var/run/utmp
+and
+.Pa /var/log/wtmp
+files with user information contained in
+.Fa ut .
+.Pp
+The
+.Fn logout
+function removes the entry from
+.Pa /var/run/utmp
+corresponding to the device
+.Fa line .
+.Pp
+The
+.Fn logwtmp
+function adds an entry to
+.Pa /var/log/wtmp .
+Since
+.Fn login
+will add the appropriate entry for
+.Pa /var/log/wtmp
+during a login,
+.Fn logwtmp
+is usually used for logouts.
+.Sh RETURN VALUES
+.Fn logout
+returns non-zero if it was able to find and delete an entry for
+.Fa line ,
+and zero if there is no entry for
+.Fa line
+in
+.Pa /var/run/utmp .
+.Sh FILES
+.Bl -tag -width /var/run/wtmp -compact
+.It Pa /dev/\(**
+.It Pa /etc/ttys
+.It Pa /var/run/utmp
+.It Pa /var/log/wtmp
+.El
+.Sh SEE ALSO
+.Xr utmp 5
diff --git a/lib/libutil/login.c b/lib/libutil/login.c
index 5cdbd3d654c..2398f001313 100644
--- a/lib/libutil/login.c
+++ b/lib/libutil/login.c
@@ -33,7 +33,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
/* from: static char sccsid[] = "@(#)login.c 8.1 (Berkeley) 6/4/93"; */
-static char *rcsid = "$Id: login.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $";
+static char *rcsid = "$Id: login.c,v 1.2 1996/05/22 11:35:05 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -43,8 +43,7 @@ static char *rcsid = "$Id: login.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $";
#include <stdlib.h>
#include <utmp.h>
#include <stdio.h>
-
-void login __P((struct utmp *));
+#include <util.h>
void
login(ut)
diff --git a/lib/libutil/login_tty.c b/lib/libutil/login_tty.c
index fe2cc4e1326..a72a9f457a2 100644
--- a/lib/libutil/login_tty.c
+++ b/lib/libutil/login_tty.c
@@ -33,14 +33,13 @@
#if defined(LIBC_SCCS) && !defined(lint)
/* from: static char sccsid[] = "@(#)login_tty.c 8.1 (Berkeley) 6/4/93"; */
-static char *rcsid = "$Id: login_tty.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $";
+static char *rcsid = "$Id: login_tty.c,v 1.2 1996/05/22 11:35:06 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
#include <sys/ioctl.h>
#include <unistd.h>
-
-int login_tty __P((int));
+#include <util.h>
int
login_tty(fd)
diff --git a/lib/libutil/logout.c b/lib/libutil/logout.c
index 02c847d3e2b..a3e34793c01 100644
--- a/lib/libutil/logout.c
+++ b/lib/libutil/logout.c
@@ -33,7 +33,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
/* from: static char sccsid[] = "@(#)logout.c 8.1 (Berkeley) 6/4/93"; */
-static char *rcsid = "$Id: logout.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $";
+static char *rcsid = "$Id: logout.c,v 1.2 1996/05/22 11:35:07 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -44,16 +44,16 @@ static char *rcsid = "$Id: logout.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $"
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
+#include <util.h>
typedef struct utmp UTMP;
int
logout(line)
- register char *line;
+ const char *line;
{
- register int fd;
+ int fd, rval;
UTMP ut;
- int rval;
if ((fd = open(_PATH_UTMP, O_RDWR, 0)) < 0)
return(0);
diff --git a/lib/libutil/logwtmp.c b/lib/libutil/logwtmp.c
index e1fb193cc20..9cfcf2d61da 100644
--- a/lib/libutil/logwtmp.c
+++ b/lib/libutil/logwtmp.c
@@ -33,7 +33,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
/* from: static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93"; */
-static char *rcsid = "$Id: logwtmp.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $";
+static char *rcsid = "$Id: logwtmp.c,v 1.2 1996/05/22 11:35:08 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -44,12 +44,11 @@ static char *rcsid = "$Id: logwtmp.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $
#include <string.h>
#include <unistd.h>
#include <utmp.h>
-
-void logwtmp __P((char *, char *, char *));
+#include <util.h>
void
logwtmp(line, name, host)
- char *line, *name, *host;
+ const char *line, *name, *host;
{
struct utmp ut;
struct stat buf;
diff --git a/lib/libutil/openpty.3 b/lib/libutil/openpty.3
new file mode 100644
index 00000000000..0e553261247
--- /dev/null
+++ b/lib/libutil/openpty.3
@@ -0,0 +1,153 @@
+.\" Copyright (c) 1995
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software developed by the Computer Systems
+.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
+.\" BG 91-66 and contributed to Berkeley.
+.\"
+.\" 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.
+.\"
+.Dd December 14, 1995
+.Dt OPENPTY 3
+.Os
+.Sh NAME
+.Nm openpty ,
+.Nm login_tty ,
+.Nm forkpty
+.Nd tty utility functions
+.Sh SYNOPSIS
+.Fd #include <util.h>
+.Ft void
+.Fn openpty "int *amaster" "int *aslave" "char *name" "struct termios *termp" "struct winsize *winp"
+.Ft int
+.Fn login_tty "int fd"
+.Ft pid_t
+.Fn forkpty "int *amaster" "char *name" "struct termios *termp" "struct winsize *winp"
+.Sh DESCRIPTION
+The
+.Fn openpty ,
+.Fn login_tty ,
+and
+.Fn login_tty
+functions perform manipulations on ttys and pseudo-ttys.
+.Pp
+The
+.Fn openpty
+function finds an available pseudo-tty and returns file descriptors
+for the master and slave in
+.Fa amaster
+and
+.Fa aslave .
+If
+.Fa name
+is non-null, the filename of the slave is returned in
+.Fa name .
+If
+.Fa termp
+is non-null, the terminal parameters of the slave will be set to the
+values in
+.Fa termp .
+If
+.Fa winp
+is non-null, the window size of the slave will be set to the values in
+.Fa winp .
+.Pp
+The
+.Fn login_tty
+function prepares for a login on the tty
+.Fa fd
+(which may be a real tty device, or the slave of a pseudo-tty as
+returned by
+.Fn openpty )
+by creating a new session, making
+.Fa fd
+the controlling terminal for the current process, setting
+.Fa fd
+to be the standard input, output, and error streams of the current
+process, and closing
+.Fa fd .
+.Pp
+The
+.Fn forkpty
+function combines
+.Fn openpty ,
+.Fn fork ,
+and
+.Fn login_tty
+to creates a new process operating in a pseudo-tty. The file
+descriptor of the master side of the pseudo-tty is returned in
+.Fa amaster ,
+and the filename of the slave in
+.Fa name
+if it is non-null. The
+.Fa termp
+and
+.Fa winp
+parameters, if non-null, will determine the terminal attributes and
+window size of the slave side of the pseudo-tty.
+.Sh RETURN VALUES
+If a call to
+.Fn openpty ,
+.Fn login_tty ,
+or
+.fn forkpty
+is not successful, -1 is returned and
+.Va errno
+is set to indicate the error. Otherwise, they return 0.
+.Sh ERRORS
+.Fn openpty
+will fail if:
+.Bl -tag -width Er
+.It Bq Er ENOENT
+There are no available ttys.
+.El
+.Pp
+.Fn login_tty
+will fail if
+.Fn ioctl
+fails to set
+.Fa fd
+to the controlling terminal of the current process.
+.Fn forkpty
+will fail if either
+.Fn openpty
+or
+.Fn fork
+fails.
+.Sh FILES
+.Bl -tag -width /dev/[pt]ty[pqrstuwxyzPQRST][0123456789abcdef] -compact
+.It Pa /dev/[pt]ty[pqrstuwxyzPQRST][0123456789abcdef]
+.El
+.Sh BUGS
+The names of the virtual consoles for the i386 PCVT console driver
+conflict with what would be the seventh group of pseudo-ttys, so
+.Fn openpty
+skips
+.Pa /dev/[pt]tyv[0123456789abcdef]
+while looking for pseudo-ttys.
diff --git a/lib/libutil/passwd.c b/lib/libutil/passwd.c
new file mode 100644
index 00000000000..c473eca72dc
--- /dev/null
+++ b/lib/libutil/passwd.c
@@ -0,0 +1,347 @@
+/*
+ * Copyright (c) 1987, 1993, 1994, 1995
+ * 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$NetBSD: passwd.c,v 1.1 1996/05/15 21:42:31 jtc Exp $";
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <pwd.h>
+#include <errno.h>
+#include <paths.h>
+#include <signal.h>
+#include <limits.h>
+#include <util.h>
+
+static void pw_cont __P((int sig));
+
+int
+pw_lock(retries)
+ int retries;
+{
+ int i, fd;
+ mode_t old_mode;
+
+ /* Acquire the lock file. */
+ old_mode = umask(0);
+ fd = open(_PATH_MASTERPASSWD_LOCK, O_WRONLY|O_CREAT|O_EXCL, 0600);
+ for (i = 0; i < retries && fd < 0 && errno == EEXIST; i++) {
+ sleep(1);
+ fd = open(_PATH_MASTERPASSWD_LOCK, O_WRONLY|O_CREAT|O_EXCL,
+ 0600);
+ }
+ umask(old_mode);
+ return(fd);
+}
+
+int
+pw_mkdb()
+{
+ int pstat;
+ pid_t pid;
+
+ pid = vfork();
+ if (pid == 0) {
+ execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p",
+ _PATH_MASTERPASSWD_LOCK, NULL);
+ exit(1);
+ }
+ pid = waitpid(pid, &pstat, 0);
+ if (pid == -1 || !WIFEXITED(pstat) || WEXITSTATUS(pstat) != 0) {
+ unlink(_PATH_MASTERPASSWD_LOCK);
+ return(-1);
+ }
+ return(0);
+}
+
+int
+pw_abort()
+{
+ return(unlink(_PATH_MASTERPASSWD_LOCK));
+}
+
+/* Everything below this point is intended for the convenience of programs
+ * which allow a user to interactively edit the passwd file. Errors in the
+ * routines below will cause the process to abort. */
+
+static pid_t editpid = -1;
+
+static void
+pw_cont(sig)
+ int sig;
+{
+
+ if (editpid != -1)
+ kill(editpid, sig);
+}
+
+void
+pw_init()
+{
+ struct rlimit rlim;
+
+ /* Unlimited resource limits. */
+ rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY;
+ (void)setrlimit(RLIMIT_CPU, &rlim);
+ (void)setrlimit(RLIMIT_FSIZE, &rlim);
+ (void)setrlimit(RLIMIT_STACK, &rlim);
+ (void)setrlimit(RLIMIT_DATA, &rlim);
+ (void)setrlimit(RLIMIT_RSS, &rlim);
+
+ /* Don't drop core (not really necessary, but GP's). */
+ rlim.rlim_cur = rlim.rlim_max = 0;
+ (void)setrlimit(RLIMIT_CORE, &rlim);
+
+ /* Turn off signals. */
+ (void)signal(SIGALRM, SIG_IGN);
+ (void)signal(SIGHUP, SIG_IGN);
+ (void)signal(SIGINT, SIG_IGN);
+ (void)signal(SIGPIPE, SIG_IGN);
+ (void)signal(SIGQUIT, SIG_IGN);
+ (void)signal(SIGTERM, SIG_IGN);
+ (void)signal(SIGCONT, pw_cont);
+}
+
+void
+pw_edit(notsetuid, filename)
+ int notsetuid;
+ const char *filename;
+{
+ int pstat;
+ char *p, *editor;
+
+ if (!filename)
+ filename = _PATH_MASTERPASSWD_LOCK;
+ if (!(editor = getenv("EDITOR")))
+ editor = _PATH_VI;
+ if (p = strrchr(editor, '/'))
+ ++p;
+ else
+ p = editor;
+
+ if (!(editpid = vfork())) {
+ if (notsetuid) {
+ setgid(getgid());
+ setuid(getuid());
+ }
+ execlp(editor, p, filename, NULL);
+ _exit(1);
+ }
+ for (;;) {
+ editpid = waitpid(editpid, (int *)&pstat, WUNTRACED);
+ if (editpid == -1)
+ pw_error(editor, 1, 1);
+ else if (WIFSTOPPED(pstat))
+ raise(WSTOPSIG(pstat));
+ else if (WIFEXITED(pstat) && WEXITSTATUS(pstat) == 0)
+ break;
+ else
+ pw_error(editor, 1, 1);
+ }
+ editpid = -1;
+}
+
+void
+pw_prompt()
+{
+ int c;
+
+ (void)printf("re-edit the password file? [y]: ");
+ (void)fflush(stdout);
+ c = getchar();
+ if (c != EOF && c != '\n')
+ while (getchar() != '\n');
+ if (c == 'n')
+ pw_error(NULL, 0, 0);
+}
+
+void
+pw_copy(ffd, tfd, pw)
+ int ffd, tfd;
+ struct passwd *pw;
+{
+ FILE *from, *to;
+ int done;
+ char *p, buf[8192];
+
+ if (!(from = fdopen(ffd, "r")))
+ pw_error(_PATH_MASTERPASSWD, 1, 1);
+ if (!(to = fdopen(tfd, "w")))
+ pw_error(_PATH_MASTERPASSWD_LOCK, 1, 1);
+
+ for (done = 0; fgets(buf, sizeof(buf), from);) {
+ if (!strchr(buf, '\n')) {
+ warnx("%s: line too long", _PATH_MASTERPASSWD);
+ pw_error(NULL, 0, 1);
+ }
+ if (done) {
+ (void)fprintf(to, "%s", buf);
+ if (ferror(to))
+ goto err;
+ continue;
+ }
+ if (!(p = strchr(buf, ':'))) {
+ warnx("%s: corrupted entry", _PATH_MASTERPASSWD);
+ pw_error(NULL, 0, 1);
+ }
+ *p = '\0';
+ if (strcmp(buf, pw->pw_name)) {
+ *p = ':';
+ (void)fprintf(to, "%s", buf);
+ if (ferror(to))
+ goto err;
+ continue;
+ }
+ (void)fprintf(to, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
+ pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid,
+ pw->pw_class, pw->pw_change, pw->pw_expire, pw->pw_gecos,
+ pw->pw_dir, pw->pw_shell);
+ done = 1;
+ if (ferror(to))
+ goto err;
+ }
+ if (!done)
+ (void)fprintf(to, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
+ pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid,
+ pw->pw_class, pw->pw_change, pw->pw_expire, pw->pw_gecos,
+ pw->pw_dir, pw->pw_shell);
+
+ if (ferror(to))
+err: pw_error(NULL, 1, 1);
+ (void)fclose(to);
+}
+
+int
+pw_scan(bp, pw, flags)
+ char *bp;
+ struct passwd *pw;
+ int *flags;
+{
+ long id;
+ int root;
+ char *p, *sh;
+
+ if (flags != (int *)NULL)
+ *flags = 0;
+
+ if (!(pw->pw_name = strsep(&bp, ":"))) /* login */
+ goto fmt;
+ root = !strcmp(pw->pw_name, "root");
+
+ if (!(pw->pw_passwd = strsep(&bp, ":"))) /* passwd */
+ goto fmt;
+
+ if (!(p = strsep(&bp, ":"))) /* uid */
+ goto fmt;
+ id = atol(p);
+ if (root && id) {
+ warnx("root uid should be 0");
+ return (0);
+ }
+ if (id > USHRT_MAX) {
+ warnx("%s > max uid value (%d)", p, USHRT_MAX);
+ return (0);
+ }
+ pw->pw_uid = id;
+ if ((*p == '\0') && (flags != (int *)NULL))
+ *flags |= _PASSWORD_NOUID;
+
+ if (!(p = strsep(&bp, ":"))) /* gid */
+ goto fmt;
+ id = atol(p);
+ if (id > USHRT_MAX) {
+ warnx("%s > max gid value (%d)", p, USHRT_MAX);
+ return (0);
+ }
+ pw->pw_gid = id;
+ if ((*p == '\0') && (flags != (int *)NULL))
+ *flags |= _PASSWORD_NOGID;
+
+ pw->pw_class = strsep(&bp, ":"); /* class */
+ if (!(p = strsep(&bp, ":"))) /* change */
+ goto fmt;
+ pw->pw_change = atol(p);
+ if ((*p == '\0') && (flags != (int *)NULL))
+ *flags |= _PASSWORD_NOCHG;
+ if (!(p = strsep(&bp, ":"))) /* expire */
+ goto fmt;
+ pw->pw_expire = atol(p);
+ if ((*p == '\0') && (flags != (int *)NULL))
+ *flags |= _PASSWORD_NOEXP;
+ pw->pw_gecos = strsep(&bp, ":"); /* gecos */
+ pw->pw_dir = strsep(&bp, ":"); /* directory */
+ if (!(pw->pw_shell = strsep(&bp, ":"))) /* shell */
+ goto fmt;
+
+ p = pw->pw_shell;
+ if (root && *p) /* empty == /bin/sh */
+ for (setusershell();;) {
+ if (!(sh = getusershell())) {
+ warnx("warning, unknown root shell");
+ break;
+ }
+ if (!strcmp(p, sh))
+ break;
+ }
+
+ if (p = strsep(&bp, ":")) { /* too many */
+fmt: warnx("corrupted entry");
+ return (0);
+ }
+
+ return (1);
+}
+
+void
+pw_error(name, err, eval)
+ const char *name;
+ int err, eval;
+{
+ if (err)
+ warn(name);
+
+ warnx("%s: unchanged", _PATH_MASTERPASSWD);
+ pw_abort();
+ exit(eval);
+}
+
diff --git a/lib/libutil/pty.c b/lib/libutil/pty.c
index 6119ed6be83..1319ae122f4 100644
--- a/lib/libutil/pty.c
+++ b/lib/libutil/pty.c
@@ -33,7 +33,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
/* from: static char sccsid[] = "@(#)pty.c 8.1 (Berkeley) 6/4/93"; */
-static char *rcsid = "$Id: pty.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $";
+static char *rcsid = "$Id: pty.c,v 1.2 1996/05/22 11:35:11 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
@@ -47,10 +47,14 @@ static char *rcsid = "$Id: pty.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $";
#include <stdio.h>
#include <string.h>
#include <grp.h>
+#include <util.h>
-int login_tty __P((int));
-int openpty __P((int *, int *, char *, struct termios *, struct winsize *));
-pid_t forkpty __P((int *, char *, struct termios *, struct winsize *));
+#ifdef i386
+/* PCVT conflicts with ttyv*. */
+#define TTY_LETTERS "pqrstuwxyzPQRST"
+#else
+#define TTY_LETTERS "pqrstuvwxyzPQRST"
+#endif
int
openpty(amaster, aslave, name, termp, winp)
@@ -69,7 +73,7 @@ openpty(amaster, aslave, name, termp, winp)
else
ttygid = -1;
- for (cp1 = "pqrstuvwxyzPQRST"; *cp1; cp1++) {
+ for (cp1 = TTY_LETTERS; *cp1; cp1++) {
line[8] = *cp1;
for (cp2 = "0123456789abcdef"; *cp2; cp2++) {
line[9] = *cp2;
diff --git a/lib/libutil/pw_init.3 b/lib/libutil/pw_init.3
new file mode 100644
index 00000000000..0de0b1a16c2
--- /dev/null
+++ b/lib/libutil/pw_init.3
@@ -0,0 +1,174 @@
+.\" Copyright (c) 1995
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software developed by the Computer Systems
+.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
+.\" BG 91-66 and contributed to Berkeley.
+.\"
+.\" 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.
+.\"
+.Dd December 15, 1995
+.Dt PW_INIT 3
+.Os
+.Sh NAME
+.Nm pw_init ,
+.Nm pw_edit ,
+.Nm pw_prompt ,
+.Nm pw_copy ,
+.Nm pw_scan ,
+.Nm pw_error
+.Nd utility functions for interactive passwd file updates
+.Sh SYNOPSIS
+.Fd #indlude <pwd.h>
+.Fd #include <util.h>
+.Ft void
+.Fn pw_init
+.Ft void
+.Fn pw_edit "int notsetuid" "const char *filename"
+.Ft void
+.Fn pw_prompt
+.Ft void
+.Fn pw_copy "int ffd" "int tfd" "struct passwd *pw"
+.Ft int
+.Fn pw_scan "char *bp" "struct passwd *pw" "int *flags"
+.Ft void
+.Fn pw_error "const char *name" "int err" "int eval"
+.Sh DESCRIPTION
+These functions are designed as conveniences for interactive programs
+which update the passwd file and do nothing else. They generally
+handle errors by printing out a message to the standard error stream
+and possibly aborting the process.
+.Pp
+The
+.Fn pw_init
+function prepares for a passwd update by unlimiting all resource
+constraints, disabling core dumps (thus preventing dumping the
+contents of the passwd database into a world-readable file), and
+disabling most signals.
+.Pp
+The
+.Fn pw_edit
+function runs an editor (named by the environment variable EDITOR, or
+.Pa /usr/bin/vi
+if EDITOR is not set) on the file
+.Fa filename
+(or
+.Pa /etc/ptmp
+if
+.Fa filename
+is NULL). If
+.Fa notsetuid
+is nonzero,
+.Fn pw_edit
+will set the effective user and group ID to the real user and group ID
+before running the editor.
+.Pp
+The
+.Fn pw_prompt
+function asks the user whether he or she wants to re-edit the password
+file; if the answer is no,
+.Fn pw_prompt
+deletes the lock file and exits the process.
+.Pp
+The
+.Fn pw_copy
+function reads a passwd file from
+.Fa ffd
+and writes it to
+.Fa tfd ,
+updating the entry corresponding to pw->pw_name with the information
+in
+.Fa pw .
+.Pp
+The
+.Fn pw_scan
+function accepts in
+.Fa bp
+a passwd entry as it would be represented in
+.Pa /etc/master.passwd
+and fills in
+.Fa pw
+with corresponding values; string fields in
+.Fa pw
+will be pointers into
+.Fa bp .
+Some characters in
+.Fa bp
+will be overwritten with 0s in order to terminate the strings pointed
+to by
+.Fa pw .
+If
+.Fa flags
+is non-null, it is filled in with the following flags:
+.Bl -tag -width _PASSWORD_NOGIDxxx
+.It Dv _PASSWORD_NOUID
+The uid field of
+.Fa bp
+is empty.
+.It Dv _PASSWORD_NOGID
+The gid field of
+.Fa bp
+is empty.
+.It Dv _PASSWD_NOCHG
+The change field of
+.Fa bp
+is empty.
+.It Dv _PASSWD_NOEXP
+The expire field of
+.Fa bp
+is empty.
+.El
+.Pp
+The
+.Fn pw_error
+function displays an error message, aborts the current passwd update,
+and exits the current process. If
+.Fa err
+is non-zero, a warning message beginning with
+.Fa name
+is printed for the current value of
+.Va errno .
+The process exits with status
+.Fa eval .
+.Sh RETURN VALUES
+The
+.Fn pw_scan
+function prints a warning message and returns 0 if the string in the
+.Fa bp
+argument is not a valid passwd string. Otherwise,
+.Fn pw_scan
+returns 1.
+.Sh FILES
+.Bl -tag -width /etc/master.passwd -compact
+.It Pa /etc/master.passwd
+.It Pa /etc/ptmp
+.El
+.Sh SEE ALSO
+.Xr pw_lock 3 ,
+.Xr passwd 5
diff --git a/lib/libutil/pw_lock.3 b/lib/libutil/pw_lock.3
new file mode 100644
index 00000000000..f768f6970c9
--- /dev/null
+++ b/lib/libutil/pw_lock.3
@@ -0,0 +1,100 @@
+.\" Copyright (c) 1995
+.\" The Regents of the University of California. All rights reserved.
+.\"
+.\" This code is derived from software developed by the Computer Systems
+.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
+.\" BG 91-66 and contributed to Berkeley.
+.\"
+.\" 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.
+.\"
+.Dd December 15, 1995
+.Dt PW_LOCK 3
+.Os
+.Sh NAME
+.Nm pw_lock ,
+.Nm pw_mkdb ,
+.Nm pw_abort
+.Nd passwd file update functions
+.Sh SYNOPSIS
+.Fd #include <util.h>
+.Ft int
+.Fn pw_lock "int retries"
+.Ft int
+.Fn pw_mkdb
+.Ft void
+.Fn pw_abort
+.Sh DESCRIPTION
+The
+.Fn pw_lock ,
+.Fn pw_mkdb ,
+and
+.Fn pw_abort
+functions allow a program to update the system passwd database.
+.Pp
+The
+.Fn pw_lock
+function attempts to lock the passwd database by creating the file
+.Pa /etc/ptmp ,
+and returns the file descriptor of that file. If
+.Fa retries
+is greater than zero,
+.Fn pw_lock
+will try multiple times to open
+.Pa /etc/ptmp ,
+waiting one second between tries. In addition to being a lock file,
+.Pa /etc/ptmp
+will also hold the contents of the new passwd file.
+.Pp
+The
+.Fn pw_mkdb
+function updates the passwd file from the contents of
+.Pa /etc/ptmp .
+You should finish writing to and close the file descriptor returned by
+.Fn pw_lock
+before calling
+.Fn pw_mkdb .
+.Pp
+The
+.Fn pw_abort
+function aborts a passwd file update by deleting
+.Pa /etc/ptmp .
+The passwd database remains unchanged.
+.Sh RETURN VALUES
+The
+.Fn pw_lock
+and
+.Fn pw_mkdb
+functions return -1 if they are unable to complete properly.
+.Sh FILES
+.Bl -tag -width /etc/master.passwd -compact
+.It Pa /etc/master.passwd
+.It Pa /etc/ptmp
+.El
+.Sh SEE ALSO
+.Xr pw_init 3
diff --git a/lib/libutil/shlib_version b/lib/libutil/shlib_version
index 3f0196ebf4a..83a67c373cc 100644
--- a/lib/libutil/shlib_version
+++ b/lib/libutil/shlib_version
@@ -1,2 +1,2 @@
major=3
-minor=1
+minor=2
diff --git a/libexec/rpc.yppasswdd/Makefile b/libexec/rpc.yppasswdd/Makefile
index 6019fbdda3a..f9335647186 100644
--- a/libexec/rpc.yppasswdd/Makefile
+++ b/libexec/rpc.yppasswdd/Makefile
@@ -1,5 +1,5 @@
# from: @(#)Makefile 5.8 (Berkeley) 7/28/90
-# $Id: Makefile,v 1.3 1996/02/15 03:50:47 etheisen Exp $
+# $Id: Makefile,v 1.4 1996/05/22 11:36:00 deraadt Exp $
PROG= rpc.yppasswdd
SRCS= rpc.yppasswdd.c yppasswdd_xdr.c yppasswdd_proc.c yppasswdd_mkpw.c \
@@ -11,9 +11,8 @@ BINDIR=/usr/sbin
MLINKS= rpc.yppasswdd.8 yppasswdd.8
.PATH: ${.CURDIR}/../../usr.sbin/vipw ${.CURDIR}/../../usr.bin/chpass \
${.CURDIR/../../ypserv
-#DPADD+= ${LIBCRYPT}
-#LDADD+= -lcrypt
-CFLAGS+=-I${.CURDIR}/../../usr.sbin/ypserv -I${.CURDIR}/../../usr.sbin/vipw \
- -I${.CURDIR}/../../usr.bin/chpass
+DPADD+= ${LIBUTIL}
+LDADD+= -lutil
+CFLAGS+=-I${.CURDIR}/../../usr.sbin/vipw -I${.CURDIR}/../../usr.bin/chpass
.include <bsd.prog.mk>
diff --git a/libexec/rpc.yppasswdd/yppasswdd_mkpw.c b/libexec/rpc.yppasswdd/yppasswdd_mkpw.c
index 331d5db5842..188d519fbf1 100644
--- a/libexec/rpc.yppasswdd/yppasswdd_mkpw.c
+++ b/libexec/rpc.yppasswdd/yppasswdd_mkpw.c
@@ -28,7 +28,7 @@
*/
#ifndef LINT
-static char rcsid[] = "$Id: yppasswdd_mkpw.c,v 1.2 1995/11/01 17:40:35 deraadt Exp $";
+static char rcsid[] = "$Id: yppasswdd_mkpw.c,v 1.3 1996/05/22 11:36:01 deraadt Exp $";
#endif
#include <sys/types.h>
@@ -64,8 +64,7 @@ make_passwd(argp)
return (1);
pw_init();
- pfd = pw_lock();
- tfd = pw_tmp();
+ tfd = pw_lock(0);
/*
* Get the new password. Reset passwd change time to zero; when
diff --git a/sbin/ccdconfig/Makefile b/sbin/ccdconfig/Makefile
index ab042b3283e..13f6e1f9d63 100644
--- a/sbin/ccdconfig/Makefile
+++ b/sbin/ccdconfig/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 1995/08/17 16:37:17 thorpej Exp $
+# $NetBSD: Makefile,v 1.2 1996/05/16 07:11:17 thorpej Exp $
PROG= ccdconfig
MAN= ccdconfig.8
@@ -6,7 +6,7 @@ MAN= ccdconfig.8
BINGRP= kmem
BINMODE=2555
-DPADD= ${LIBKVM}
-LDADD= -lkvm
+DPADD= ${LIBKVM} ${LIBUTIL}
+LDADD= -lkvm -lutil
.include <bsd.prog.mk>
diff --git a/sbin/ccdconfig/ccdconfig.c b/sbin/ccdconfig/ccdconfig.c
index 3c6fe5415e8..1fbc6b79150 100644
--- a/sbin/ccdconfig/ccdconfig.c
+++ b/sbin/ccdconfig/ccdconfig.c
@@ -1,5 +1,5 @@
-/* $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 $ */
+/* $OpenBSD: ccdconfig.c,v 1.4 1996/05/22 11:34:48 deraadt Exp $ */
+/* $NetBSD: ccdconfig.c,v 1.6 1996/05/16 07:11:18 thorpej Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -55,6 +55,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <util.h>
#include <dev/ccdvar.h>
@@ -98,8 +99,6 @@ static int do_io __P((char *, u_long, struct ccd_ioctl *));
static int do_single __P((int, char **, int));
static int do_all __P((int));
static int dump_ccd __P((int, char **));
-static int getmaxpartitions __P((void));
-static int getrawpartition __P((void));
static int flags_to_val __P((char *));
static int pathtodevt __P((char *, dev_t *));
static void print_ccd_info __P((struct ccd_softc *, kvm_t *));
@@ -626,36 +625,6 @@ print_ccd_info(cs, kd)
}
static int
-getmaxpartitions()
-{
- int maxpart, mib[2];
- size_t varlen;
-
- mib[0] = CTL_KERN;
- mib[1] = KERN_MAXPARTITIONS;
- varlen = sizeof(maxpart);
- if (sysctl(mib, 2, &maxpart, &varlen, NULL, 0) < 0)
- return (-1);
-
- return (maxpart);
-}
-
-static int
-getrawpartition()
-{
- int rawpart, mib[2];
- size_t varlen;
-
- mib[0] = CTL_KERN;
- mib[1] = KERN_RAWPARTITION;
- varlen = sizeof(rawpart);
- if (sysctl(mib, 2, &rawpart, &varlen, NULL, 0) < 0)
- return (-1);
-
- return (rawpart);
-}
-
-static int
flags_to_val(flags)
char *flags;
{
diff --git a/sbin/init/init.c b/sbin/init/init.c
index d0788c6826e..96b3bc1caa2 100644
--- a/sbin/init/init.c
+++ b/sbin/init/init.c
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.21 1995/10/05 06:11:24 mycroft Exp $ */
+/* $NetBSD: init.c,v 1.22 1996/05/15 23:29:33 jtc Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -46,7 +46,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)init.c 8.1 (Berkeley) 7/15/93";
#else
-static char rcsid[] = "$NetBSD: init.c,v 1.21 1995/10/05 06:11:24 mycroft Exp $";
+static char rcsid[] = "$NetBSD: init.c,v 1.22 1996/05/15 23:29:33 jtc Exp $";
#endif
#endif /* not lint */
@@ -65,6 +65,7 @@ static char rcsid[] = "$NetBSD: init.c,v 1.21 1995/10/05 06:11:24 mycroft Exp $"
#include <time.h>
#include <ttyent.h>
#include <unistd.h>
+#include <util.h>
#ifdef __STDC__
#include <stdarg.h>
@@ -79,13 +80,6 @@ static char rcsid[] = "$NetBSD: init.c,v 1.21 1995/10/05 06:11:24 mycroft Exp $"
#include "pathnames.h"
/*
- * Until the mythical util.h arrives...
- */
-extern int login_tty __P((int));
-extern int logout __P((const char *));
-extern void logwtmp __P((const char *, const char *, const char *));
-
-/*
* Sleep times; used to prevent thrashing.
*/
#define GETTY_SPACING 5 /* N secs minimum getty spacing */
diff --git a/sbin/newfs/Makefile b/sbin/newfs/Makefile
index 8f987dc77cb..bf7d243f8a1 100644
--- a/sbin/newfs/Makefile
+++ b/sbin/newfs/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.9 1995/03/18 14:58:37 cgd Exp $
+# $NetBSD: Makefile,v 1.10 1996/05/16 07:13:01 thorpej Exp $
# @(#)Makefile 8.2 (Berkeley) 3/27/94
PROG= newfs
@@ -9,6 +9,9 @@ MOUNT= ${.CURDIR}/../mount
CFLAGS+=-DMFS -I${MOUNT}
.PATH: ${MOUNT} ${.CURDIR}/../disklabel
+DPADD= ${LIBUTIL}
+LDADD= -lutil
+
LINKS= ${BINDIR}/newfs ${BINDIR}/mount_mfs
MLINKS= newfs.8 mount_mfs.8 newfs.8 mfs.8
diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c
index 6fdaf7d90a9..9f6cef21b1c 100644
--- a/sbin/newfs/newfs.c
+++ b/sbin/newfs/newfs.c
@@ -1,4 +1,4 @@
-/* $NetBSD: newfs.c,v 1.19 1995/06/28 02:21:02 thorpej Exp $ */
+/* $NetBSD: newfs.c,v 1.20 1996/05/16 07:13:03 thorpej Exp $ */
/*
* Copyright (c) 1983, 1989, 1993, 1994
@@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)newfs.c 8.8 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$NetBSD: newfs.c,v 1.19 1995/06/28 02:21:02 thorpej Exp $";
+static char rcsid[] = "$NetBSD: newfs.c,v 1.20 1996/05/16 07:13:03 thorpej Exp $";
#endif
#endif /* not lint */
@@ -69,6 +69,7 @@ static char rcsid[] = "$NetBSD: newfs.c,v 1.19 1995/06/28 02:21:02 thorpej Exp $
#include <string.h>
#include <syslog.h>
#include <unistd.h>
+#include <util.h>
#if __STDC__
#include <stdarg.h>
@@ -90,8 +91,6 @@ void fatal(const char *fmt, ...);
void fatal();
#endif
-int getmaxpartitions __P((void));
-
#define COMPAT /* allow non-labeled disks */
/*
@@ -681,21 +680,6 @@ fatal(fmt, va_alist)
/*NOTREACHED*/
}
-int
-getmaxpartitions()
-{
- int maxpart, mib[2];
- size_t varlen;
-
- mib[0] = CTL_KERN;
- mib[1] = KERN_MAXPARTITIONS;
- varlen = sizeof(maxpart);
- if (sysctl(mib, 2, &maxpart, &varlen, NULL, 0) < 0)
- fatal("getmaxpartitions: %s", strerror(errno));
-
- return (maxpart);
-}
-
usage()
{
if (mfs) {
diff --git a/sbin/newlfs/Makefile b/sbin/newlfs/Makefile
index ccf83c7436e..929101505c5 100644
--- a/sbin/newlfs/Makefile
+++ b/sbin/newlfs/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.5 1995/03/18 14:58:45 cgd Exp $
+# $NetBSD: Makefile,v 1.6 1996/05/16 07:17:49 thorpej Exp $
# @(#)Makefile 8.1 (Berkeley) 6/18/93
PROG= newlfs
@@ -6,4 +6,7 @@ SRCS= dkcksum.c lfs.c lfs_cksum.c misc.c newfs.c
MAN= newlfs.8
.PATH: ${.CURDIR}/../../sys/ufs/lfs ${.CURDIR}/../disklabel
+DPADD= ${LIBUTIL}
+LDADD= -lutil
+
.include <bsd.prog.mk>
diff --git a/sbin/newlfs/newfs.c b/sbin/newlfs/newfs.c
index ef7d9be96ec..2668ff6cab0 100644
--- a/sbin/newlfs/newfs.c
+++ b/sbin/newlfs/newfs.c
@@ -1,4 +1,4 @@
-/* $NetBSD: newfs.c,v 1.4 1995/06/28 02:21:32 thorpej Exp $ */
+/* $NetBSD: newfs.c,v 1.5 1996/05/16 07:17:50 thorpej Exp $ */
/*-
* Copyright (c) 1989, 1992, 1993
@@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)newfs.c 8.3 (Berkeley) 4/22/94";
#else
-static char rcsid[] = "$NetBSD: newfs.c,v 1.4 1995/06/28 02:21:32 thorpej Exp $";
+static char rcsid[] = "$NetBSD: newfs.c,v 1.5 1996/05/16 07:17:50 thorpej Exp $";
#endif
#endif /* not lint */
@@ -69,6 +69,7 @@ static char rcsid[] = "$NetBSD: newfs.c,v 1.4 1995/06/28 02:21:32 thorpej Exp $"
#include <ctype.h>
#include <string.h>
#include <paths.h>
+#include <util.h>
#include "config.h"
#include "extern.h"
@@ -119,7 +120,6 @@ char *progname, *special;
static struct disklabel *getdisklabel __P((char *, int));
static struct disklabel *debug_readlabel __P((int));
static void rewritelabel __P((char *, int, struct disklabel *));
-static int getmaxpartitions __P((void));
static void usage __P((void));
int
@@ -432,21 +432,6 @@ rewritelabel(s, fd, lp)
#endif
}
-static int
-getmaxpartitions()
-{
- int maxpart, mib[2];
- size_t varlen;
-
- mib[0] = CTL_KERN;
- mib[1] = KERN_MAXPARTITIONS;
- varlen = sizeof(maxpart);
- if (sysctl(mib, 2, &maxpart, &varlen, NULL, 0) < 0)
- fatal("getmaxpartitions: %s", strerror(errno));
-
- return (maxpart);
-}
-
void
usage()
{
diff --git a/usr.bin/chpass/Makefile b/usr.bin/chpass/Makefile
index 752792ba265..f6f19c838f6 100644
--- a/usr.bin/chpass/Makefile
+++ b/usr.bin/chpass/Makefile
@@ -1,18 +1,16 @@
-# $NetBSD: Makefile,v 1.5 1995/03/26 04:55:22 glass Exp $
+# $NetBSD: Makefile,v 1.6 1996/05/15 21:50:39 jtc Exp $
# @(#)Makefile 8.2 (Berkeley) 4/2/94
PROG= chpass
-SRCS= chpass.c edit.c field.c pw_copy.c pw_scan.c pw_util.c pw_yp.c table.c util.c getpwent.c
+SRCS= chpass.c edit.c field.c pw_yp.c table.c util.c getpwent.c
BINOWN= root
BINMODE=4555
-.PATH: ${.CURDIR}/../../usr.sbin/pwd_mkdb ${.CURDIR}/../../usr.sbin/vipw \
- ${.CURDIR}/../../lib/libc/gen
-CFLAGS+=-I${.CURDIR}/../../usr.sbin/pwd_mkdb -I${.CURDIR}/../../usr.sbin/vipw
+.PATH: ${.CURDIR}/../../lib/libc/gen
LINKS= ${BINDIR}/chpass ${BINDIR}/chfn ${BINDIR}/chpass ${BINDIR}/chsh
MLINKS= chpass.1 chfn.1 chpass.1 chsh.1
CFLAGS+=-DYP
-DPADD+= ${LIBRPCSVC}
-LDADD+= -lrpcsvc
+DPADD+= ${LIBRPCSVC} ${LIBUTIL}
+LDADD+= -lrpcsvc -lutil
.include <bsd.prog.mk>
diff --git a/usr.bin/chpass/chpass.1 b/usr.bin/chpass/chpass.1
index f077510addb..1a66a07f49b 100644
--- a/usr.bin/chpass/chpass.1
+++ b/usr.bin/chpass/chpass.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: chpass.1,v 1.6 1995/09/14 06:10:53 jtc Exp $
+.\" $NetBSD: chpass.1,v 1.7 1996/05/15 21:50:40 jtc Exp $
.\"
.\" Copyright (c) 1988, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -205,8 +205,10 @@ with the user.
The user database
.It Pa /etc/passwd
A Version 7 format password file
-.It Pa /etc/chpass.XXXXXX
-Temporary copy of the password file
+.It Pa /etc/ptmp
+Lock file for the passwd database
+.It Pa /etc/pw.XXXXXX
+Temporary copy of the user passwd information
.It Pa /etc/shells
The list of approved shells
.El
diff --git a/usr.bin/chpass/chpass.c b/usr.bin/chpass/chpass.c
index ba5a7efdade..a959b2fda5d 100644
--- a/usr.bin/chpass/chpass.c
+++ b/usr.bin/chpass/chpass.c
@@ -1,4 +1,4 @@
-/* $NetBSD: chpass.c,v 1.7 1995/07/28 07:01:32 phil Exp $ */
+/* $NetBSD: chpass.c,v 1.8 1996/05/15 21:50:43 jtc Exp $ */
/*-
* Copyright (c) 1988, 1993, 1994
@@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)chpass.c 8.4 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$NetBSD: chpass.c,v 1.7 1995/07/28 07:01:32 phil Exp $";
+static char rcsid[] = "$NetBSD: chpass.c,v 1.8 1996/05/15 21:50:43 jtc Exp $";
#endif
#endif /* not lint */
@@ -61,10 +61,7 @@ static char rcsid[] = "$NetBSD: chpass.c,v 1.7 1995/07/28 07:01:32 phil Exp $";
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-
-#include <pw_scan.h>
-#include <pw_util.h>
-#include "pw_copy.h"
+#include <util.h>
#include "chpass.h"
#include "pathnames.h"
@@ -89,8 +86,8 @@ main(argc, argv)
{
enum { NEWSH, LOADENTRY, EDITENTRY } op;
struct passwd *pw, lpw;
- int ch, pfd, tfd;
- char *arg;
+ int ch, pfd, tfd, dfd;
+ char *arg, tempname[] = "/etc/pw.XXXXXX";
#ifdef YP
use_yp = _yp_check(NULL);
@@ -178,45 +175,27 @@ main(argc, argv)
exit(1);
}
- /*
- * The temporary file/file descriptor usage is a little tricky here.
- * 1: We start off with two fd's, one for the master password
- * file (used to lock everything), and one for a temporary file.
- * 2: Display() gets an fp for the temporary file, and copies the
- * user's information into it. It then gives the temporary file
- * to the user and closes the fp, closing the underlying fd.
- * 3: The user edits the temporary file some number of times.
- * 4: Verify() gets an fp for the temporary file, and verifies the
- * contents. It can't use an fp derived from the step #2 fd,
- * because the user's editor may have created a new instance of
- * the file. Once the file is verified, its contents are stored
- * in a password structure. The verify routine closes the fp,
- * closing the underlying fd.
- * 5: Delete the temporary file.
- * 6: Get a new temporary file/fd. Pw_copy() gets an fp for it
- * file and copies the master password file into it, replacing
- * the user record with a new one. We can't use the first
- * temporary file for this because it was owned by the user.
- * Pw_copy() closes its fp, flushing the data and closing the
- * underlying file descriptor. We can't close the master
- * password fp, or we'd lose the lock.
- * 7: Call pw_mkdb() (which renames the temporary file) and exit.
- * The exit closes the master passwd fp/fd.
- */
+ /* Get the passwd lock file and open the passwd file for reading. */
pw_init();
- pfd = pw_lock();
- tfd = pw_tmp();
-
+ tfd = pw_lock(0);
+ if (tfd < 0)
+ errx(1, "the passwd file is busy.");
+ pfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0);
+ if (pfd < 0)
+ pw_error(_PATH_MASTERPASSWD, 1, 1);
+
+ /* Edit the user passwd information if requested. */
if (op == EDITENTRY) {
- display(tfd, pw);
- edit(pw);
+ dfd = mkstemp(tempname);
+ if (dfd < 0)
+ pw_error(tempname, 1, 1);
+ display(tempname, dfd, pw);
+ edit(tempname, pw);
(void)unlink(tempname);
- tfd = pw_tmp();
}
-
+
#ifdef YP
if (use_yp) {
- (void)unlink(tempname);
if (pw_yp(pw, uid))
pw_error((char *)NULL, 0, 1);
else
@@ -224,9 +203,12 @@ main(argc, argv)
}
else
#endif /* YP */
+
+ /* Copy the passwd file to the lock file, updating pw. */
pw_copy(pfd, tfd, pw);
- if (!pw_mkdb())
+ /* Now finish the passwd file update. */
+ if (pw_mkdb() < 0)
pw_error((char *)NULL, 0, 1);
exit(0);
diff --git a/usr.bin/chpass/chpass.h b/usr.bin/chpass/chpass.h
index 52997da455c..087556f4131 100644
--- a/usr.bin/chpass/chpass.h
+++ b/usr.bin/chpass/chpass.h
@@ -1,4 +1,4 @@
-/* $NetBSD: chpass.h,v 1.3 1995/03/26 04:55:26 glass Exp $ */
+/* $NetBSD: chpass.h,v 1.4 1996/05/15 21:50:44 jtc Exp $ */
/*
* Copyright (c) 1988, 1993, 1994
@@ -54,8 +54,8 @@ extern ENTRY list[];
extern uid_t uid;
int atot __P((char *, time_t *));
-void display __P((int, struct passwd *));
-void edit __P((struct passwd *));
+void display __P((char *, int, struct passwd *));
+void edit __P((char *, struct passwd *));
char *ok_shell __P((char *));
int p_change __P((char *, struct passwd *, ENTRY *));
int p_class __P((char *, struct passwd *, ENTRY *));
@@ -69,4 +69,4 @@ int p_passwd __P((char *, struct passwd *, ENTRY *));
int p_shell __P((char *, struct passwd *, ENTRY *));
int p_uid __P((char *, struct passwd *, ENTRY *));
char *ttoa __P((time_t));
-int verify __P((struct passwd *));
+int verify __P((char *, struct passwd *));
diff --git a/usr.bin/chpass/edit.c b/usr.bin/chpass/edit.c
index 10c82bb5722..afd0d7f862e 100644
--- a/usr.bin/chpass/edit.c
+++ b/usr.bin/chpass/edit.c
@@ -1,4 +1,4 @@
-/* $NetBSD: edit.c,v 1.5 1995/07/28 07:03:41 phil Exp $ */
+/* $NetBSD: edit.c,v 1.6 1996/05/15 21:50:45 jtc Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)edit.c 8.3 (Berkeley) 4/2/94";
#else
-static char rcsid[] = "$NetBSD: edit.c,v 1.5 1995/07/28 07:03:41 phil Exp $";
+static char rcsid[] = "$NetBSD: edit.c,v 1.6 1996/05/15 21:50:45 jtc Exp $";
#endif
#endif /* not lint */
@@ -53,16 +53,13 @@ static char rcsid[] = "$NetBSD: edit.c,v 1.5 1995/07/28 07:03:41 phil Exp $";
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-
-#include <pw_scan.h>
-#include <pw_util.h>
+#include <util.h>
#include "chpass.h"
-extern char *tempname;
-
void
-edit(pw)
+edit(tempname, pw)
+ char *tempname;
struct passwd *pw;
{
struct stat begin, end;
@@ -70,14 +67,15 @@ edit(pw)
for (;;) {
if (stat(tempname, &begin))
pw_error(tempname, 1, 1);
- pw_edit(1);
+ pw_edit(1, tempname);
if (stat(tempname, &end))
pw_error(tempname, 1, 1);
if (begin.st_mtime == end.st_mtime) {
warnx("no changes made");
+ unlink(tempname);
pw_error(NULL, 0, 0);
}
- if (verify(pw))
+ if (verify(tempname, pw))
break;
pw_prompt();
}
@@ -89,7 +87,8 @@ edit(pw)
* set conditional flag if the user gets to edit the shell.
*/
void
-display(fd, pw)
+display(tempname, fd, pw)
+ char *tempname;
int fd;
struct passwd *pw;
{
@@ -140,7 +139,8 @@ display(fd, pw)
}
int
-verify(pw)
+verify(tempname, pw)
+ char *tempname;
struct passwd *pw;
{
ENTRY *ep;
diff --git a/usr.bin/chpass/pw_copy.c b/usr.bin/chpass/pw_copy.c
index fc1dc24083e..e69de29bb2d 100644
--- a/usr.bin/chpass/pw_copy.c
+++ b/usr.bin/chpass/pw_copy.c
@@ -1,113 +0,0 @@
-/* $NetBSD: pw_copy.c,v 1.3 1995/03/26 04:55:30 glass Exp $ */
-
-/*-
- * Copyright (c) 1990, 1993, 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
-#if 0
-static char sccsid[] = "@(#)pw_copy.c 8.4 (Berkeley) 4/2/94";
-#else
-static char rcsid[] = "$NetBSD: pw_copy.c,v 1.3 1995/03/26 04:55:30 glass Exp $";
-#endif
-#endif /* not lint */
-
-/*
- * This module is used to copy the master password file, replacing a single
- * record, by chpass(1) and passwd(1).
- */
-
-#include <err.h>
-#include <pwd.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <pw_util.h>
-#include "pw_copy.h"
-
-extern char *tempname;
-
-void
-pw_copy(ffd, tfd, pw)
- int ffd, tfd;
- struct passwd *pw;
-{
- FILE *from, *to;
- int done;
- char *p, buf[8192];
-
- if (!(from = fdopen(ffd, "r")))
- pw_error(_PATH_MASTERPASSWD, 1, 1);
- if (!(to = fdopen(tfd, "w")))
- pw_error(tempname, 1, 1);
-
- for (done = 0; fgets(buf, sizeof(buf), from);) {
- if (!strchr(buf, '\n')) {
- warnx("%s: line too long", _PATH_MASTERPASSWD);
- pw_error(NULL, 0, 1);
- }
- if (done) {
- (void)fprintf(to, "%s", buf);
- if (ferror(to))
- goto err;
- continue;
- }
- if (!(p = strchr(buf, ':'))) {
- warnx("%s: corrupted entry", _PATH_MASTERPASSWD);
- pw_error(NULL, 0, 1);
- }
- *p = '\0';
- if (strcmp(buf, pw->pw_name)) {
- *p = ':';
- (void)fprintf(to, "%s", buf);
- if (ferror(to))
- goto err;
- continue;
- }
- (void)fprintf(to, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
- pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid,
- pw->pw_class, pw->pw_change, pw->pw_expire, pw->pw_gecos,
- pw->pw_dir, pw->pw_shell);
- done = 1;
- if (ferror(to))
- goto err;
- }
- if (!done)
- (void)fprintf(to, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
- pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid,
- pw->pw_class, pw->pw_change, pw->pw_expire, pw->pw_gecos,
- pw->pw_dir, pw->pw_shell);
-
- if (ferror(to))
-err: pw_error(NULL, 1, 1);
- (void)fclose(to);
-}
diff --git a/usr.bin/chpass/pw_copy.h b/usr.bin/chpass/pw_copy.h
index ae41c5ad79b..e69de29bb2d 100644
--- a/usr.bin/chpass/pw_copy.h
+++ b/usr.bin/chpass/pw_copy.h
@@ -1,38 +0,0 @@
-/* $NetBSD: pw_copy.h,v 1.2 1995/03/26 04:55:32 glass 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.
- *
- * @(#)pw_copy.h 8.1 (Berkeley) 4/2/94
- */
-
-void pw_copy __P((int, int, struct passwd *));
diff --git a/usr.bin/login/login.c b/usr.bin/login/login.c
index a3d0790ea7a..7f979e242b2 100644
--- a/usr.bin/login/login.c
+++ b/usr.bin/login/login.c
@@ -1,4 +1,4 @@
-/* $NetBSD: login.c,v 1.12 1994/12/23 06:53:01 jtc Exp $ */
+/* $NetBSD: login.c,v 1.13 1996/05/15 23:50:16 jtc Exp $ */
/*-
* Copyright (c) 1980, 1987, 1988, 1991, 1993, 1994
@@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)login.c 8.4 (Berkeley) 4/2/94";
#endif
-static char rcsid[] = "$NetBSD: login.c,v 1.12 1994/12/23 06:53:01 jtc Exp $";
+static char rcsid[] = "$NetBSD: login.c,v 1.13 1996/05/15 23:50:16 jtc Exp $";
#endif /* not lint */
/*
@@ -72,6 +72,7 @@ static char rcsid[] = "$NetBSD: login.c,v 1.12 1994/12/23 06:53:01 jtc Exp $";
#include <tzfile.h>
#include <unistd.h>
#include <utmp.h>
+#include <util.h>
#include "pathnames.h"
diff --git a/usr.bin/passwd/Makefile b/usr.bin/passwd/Makefile
index 6ffcfd56b64..c6111c990e6 100644
--- a/usr.bin/passwd/Makefile
+++ b/usr.bin/passwd/Makefile
@@ -1,15 +1,11 @@
-# from: @(#)Makefile 5.11 (Berkeley) 2/19/91
-# $Id: Makefile,v 1.6 1996/04/03 05:44:45 tholo Exp $
+# $OpenBSD: Makefile,v 1.7 1996/05/22 11:35:26 deraadt Exp $
PROG= passwd
-SRCS= local_passwd.c yp_passwd.c passwd.c pw_copy.c pw_util.c getpwent.c
-.PATH: ${.CURDIR}/../../usr.bin/chpass ${.CURDIR}/../../usr.sbin/vipw \
- ${.CURDIR}/../rlogin ${.CURDIR}/../../lib/libc/gen
-#DPADD+= ${LIBRPCSVC} ${LIBCRYPT}
-DPADD+= ${LIBRPCSVC}
-#LDADD+= -lrpcsvc -lcrypt
-LDADD+= -lrpcsvc
-CFLAGS+=-I${.CURDIR} -I${.CURDIR}/../../usr.sbin/vipw -DYP
+SRCS= local_passwd.c yp_passwd.c passwd.c getpwent.c
+.PATH: ${.CURDIR}/../../lib/libc/gen
+DPADD+= ${LIBRPCSVC} ${LIBCRYPT} ${LIBUTIL}
+LDADD+= -lrpcsvc -lcrypt -lutil
+CFLAGS+=-I${.CURDIR} -DYP
.include <bsd.own.mk> # For Kerberos
@@ -19,6 +15,7 @@ CFLAGS+= -DKERBEROS5
DPADD+= ${LIBKRB5} ${LIBCRYPTO}
LDADD+= -lkrb5 -lcrypto
.elif defined(KERBEROS)
+.PATH: ${.CURDIR}/../rlogin
SRCS+= krb_passwd.c des_rw.c
CFLAGS+= -DKERBEROS
DPADD+= ${LIBKRB} ${LIBDES}
diff --git a/usr.bin/passwd/local_passwd.c b/usr.bin/passwd/local_passwd.c
index 3bf2c2fb1b7..910e911976a 100644
--- a/usr.bin/passwd/local_passwd.c
+++ b/usr.bin/passwd/local_passwd.c
@@ -33,14 +33,18 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)local_passwd.c 5.5 (Berkeley) 5/6/91";*/
-static char rcsid[] = "$Id: local_passwd.c,v 1.1.1.1 1995/10/18 08:45:54 deraadt Exp $";
+static char rcsid[] = "$Id: local_passwd.c,v 1.2 1996/05/22 11:35:27 deraadt Exp $";
#endif /* not lint */
#include <sys/types.h>
+#include <sys/stat.h>
#include <pwd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <util.h>
uid_t uid;
@@ -70,8 +74,12 @@ local_passwd(uname)
}
pw_init();
- pfd = pw_lock();
- tfd = pw_tmp();
+ tfd = pw_lock(0);
+ if (tfd < 0)
+ errx(1, "the passwd file is busy.");
+ pfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0);
+ if (pfd < 0)
+ pw_error(_PATH_MASTERPASSWD, 1, 1);
/*
* Get the new password. Reset passwd change time to zero; when
@@ -82,7 +90,7 @@ local_passwd(uname)
pw->pw_change = 0;
pw_copy(pfd, tfd, pw);
- if (!pw_mkdb())
+ if (pw_mkdb() < 0)
pw_error((char *)NULL, 0, 1);
return(0);
}
diff --git a/usr.bin/systat/Makefile b/usr.bin/systat/Makefile
index 290a3871e49..de284f26bbb 100644
--- a/usr.bin/systat/Makefile
+++ b/usr.bin/systat/Makefile
@@ -1,16 +1,15 @@
-# $NetBSD: Makefile,v 1.3 1995/03/22 15:26:42 mycroft Exp $
-# @(#)Makefile 8.1 (Berkeley) 6/6/93
+# $OpenBSD: Makefile,v 1.3 1996/05/22 11:35:28 deraadt Exp $
+# $NetBSD: Makefile,v 1.5 1996/05/10 23:16:30 thorpej Exp $
PROG= systat
-.if (${MACHINE_ARCH} == "m68k")
-CFLAGS+=-D${MACHINE}
-.endif
-CFLAGS+=-I${.CURDIR}/../../sys/arch -I${.CURDIR}/../vmstat
-SRCS= cmds.c cmdtab.c disks.c fetch.c iostat.c keyboard.c main.c mbufs.c \
- netcmds.c netstat.c pigs.c swap.c vmstat.c
-LDADD= -lcurses -ltermcap -lm -lkvm
+.PATH: ${.CURDIR}/../../usr.bin/vmstat
+
+CFLAGS+=-I${.CURDIR}/../../usr.bin/vmstat
+SRCS= cmds.c cmdtab.c disks.c dkstats.c fetch.c iostat.c keyboard.c \
+ main.c mbufs.c netcmds.c netstat.c pigs.c swap.c vmstat.c
DPADD= ${LIBCURSES} ${LIBTERMCAP} ${LIBM} ${LIBKVM}
+LDADD= -lcurses -ltermcap -lm -lkvm
BINGRP= kmem
BINMODE=2555
diff --git a/usr.bin/systat/cmds.c b/usr.bin/systat/cmds.c
index a75bd24914c..7531ced94b4 100644
--- a/usr.bin/systat/cmds.c
+++ b/usr.bin/systat/cmds.c
@@ -1,4 +1,4 @@
-/* $NetBSD: cmds.c,v 1.3 1995/08/31 22:20:18 jtc Exp $ */
+/* $NetBSD: cmds.c,v 1.4 1996/05/10 23:16:32 thorpej Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)cmds.c 8.2 (Berkeley) 4/29/95";
#endif
-static char rcsid[] = "$NetBSD: cmds.c,v 1.3 1995/08/31 22:20:18 jtc Exp $";
+static char rcsid[] = "$NetBSD: cmds.c,v 1.4 1996/05/10 23:16:32 thorpej Exp $";
#endif /* not lint */
#include <stdlib.h>
@@ -110,7 +110,9 @@ command(cmd)
}
p = lookup(cmd);
if (p == (struct cmdtab *)-1) {
- error("%s: Ambiguous command.", cmd);
+ /* if not a primary command, try a display specific one */
+ if (curcmd->c_cmd == 0 || !(*curcmd->c_cmd)(cmd, cp))
+ error("%s: Ambiguous command.", cmd);
goto done;
}
if (p) {
@@ -140,8 +142,6 @@ command(cmd)
status();
goto done;
}
- if (curcmd->c_cmd == 0 || !(*curcmd->c_cmd)(cmd, cp))
- error("%s: Unknown command.", cmd);
done:
sigsetmask(omask);
}
diff --git a/usr.bin/systat/disks.c b/usr.bin/systat/disks.c
index 2098d6f8b52..348022ace90 100644
--- a/usr.bin/systat/disks.c
+++ b/usr.bin/systat/disks.c
@@ -1,5 +1,4 @@
-/* $OpenBSD: disks.c,v 1.3 1996/04/19 13:31:57 mickey Exp $ */
-/* $NetBSD: disks.c,v 1.3 1996/03/15 22:19:23 ragge Exp $ */
+/* $NetBSD: disks.c,v 1.4 1996/05/10 23:16:33 thorpej Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@@ -37,106 +36,14 @@
#ifndef lint
#if 0
static char sccsid[] = "@(#)disks.c 8.1 (Berkeley) 6/6/93";
-static char rcsid[] = "$NetBSD: disks.c,v 1.3 1996/03/15 22:19:23 ragge Exp $";
#endif
-static char rcsid[] = "$OpenBSD: disks.c,v 1.3 1996/04/19 13:31:57 mickey Exp $";
+static char rcsid[] = "$NetBSD: disks.c,v 1.4 1996/05/10 23:16:33 thorpej Exp $";
#endif /* not lint */
-#include <sys/types.h>
-#include <sys/buf.h>
-
-#include <nlist.h>
-#include <ctype.h>
-#include <paths.h>
-#include <string.h>
-#include <stdlib.h>
#include "systat.h"
#include "extern.h"
+static void dkselect(char *args, int truefalse, int selections[]);
-static void dkselect __P((char *, int, int []));
-static int read_names __P((void));
-
-static struct nlist namelist[] = {
-#define X_DK_NDRIVE 0
- { "_dk_ndrive" },
-#define X_DK_WPMS 1
- { "_dk_wpms" },
-#ifdef sun
-#define X_MBDINIT (X_DK_WPMS+1)
- { "_mbdinit" },
-#endif
-#ifdef tahoe
-#define X_VBDINIT (X_DK_WPMS+1)
- { "_vbdinit" },
-#endif
-#if defined(hp300) || defined(luna68k)
-#define X_HPDINIT (X_DK_WPMS+1)
- { "_hp_dinit" },
-#endif
-#ifdef mips
-#define X_SCSI_DINIT (X_DK_WPMS+1)
- { "_scsi_dinit" },
-#endif
- { "" },
-};
-
-float *dk_mspw;
-int dk_ndrive, *dk_select;
-char **dr_name;
-
-int
-dkinit()
-{
- register int i;
- register char *cp;
- static int once = 0;
- static char buf[1024];
-
- if (once)
- return(1);
-
- if (kvm_nlist(kd, namelist)) {
- nlisterr(namelist);
- return(0);
- }
- if (namelist[X_DK_NDRIVE].n_value == 0) {
- error("dk_ndrive undefined in kernel");
- return(0);
- }
- NREAD(X_DK_NDRIVE, &dk_ndrive, LONG);
- if (dk_ndrive <= 0) {
- error("dk_ndrive=%d according to %s", dk_ndrive, _PATH_UNIX);
- return(0);
- }
- dk_mspw = (float *)calloc(dk_ndrive, sizeof (float));
- {
- long *wpms = (long *)calloc(dk_ndrive, sizeof(long));
- KREAD(NPTR(X_DK_WPMS), wpms, dk_ndrive * sizeof (long));
- for (i = 0; i < dk_ndrive; i++)
- *(dk_mspw + i) = (*(wpms + i) == 0)? 0.0:
- (float) 1.0 / *(wpms + i);
- free(wpms);
- }
- dr_name = (char **)calloc(dk_ndrive, sizeof (char *));
- dk_select = (int *)calloc(dk_ndrive, sizeof (int));
- for (cp = buf, i = 0; i < dk_ndrive; i++) {
- dr_name[i] = cp;
- sprintf(dr_name[i], "dk%d", i);
- cp += strlen(dr_name[i]) + 1;
- if (dk_mspw[i] != 0.0)
- dk_select[i] = 1;
- }
-#if 0
- if (!read_names()) {
- free(dr_name);
- free(dk_select);
- free(dk_mspw);
- return(0);
- }
-#endif
- once = 1;
- return(1);
-}
int
dkcmd(cmd, args)
@@ -155,8 +62,7 @@ dkcmd(cmd, args)
move(CMDLINE, 0); clrtoeol();
for (i = 0; i < dk_ndrive; i++)
- if (dk_mspw[i] != 0.0)
- printw("%s ", dr_name[i]);
+ printw("%s ", dr_name[i]);
return (1);
}
return (0);
@@ -186,11 +92,7 @@ dkselect(args, truefalse, selections)
break;
for (i = 0; i < dk_ndrive; i++)
if (strcmp(args, dr_name[i]) == 0) {
- if (dk_mspw[i] != 0.0)
- selections[i] = truefalse;
- else
- error("%s: drive not configured",
- dr_name[i]);
+ selections[i] = truefalse;
break;
}
if (i >= dk_ndrive)
diff --git a/usr.bin/systat/extern.h b/usr.bin/systat/extern.h
index 183c823e3db..6a9f0f73f21 100644
--- a/usr.bin/systat/extern.h
+++ b/usr.bin/systat/extern.h
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.2 1995/01/20 08:51:54 jtc Exp $ */
+/* $NetBSD: extern.h,v 1.3 1996/05/10 23:16:34 thorpej Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -76,7 +76,7 @@ struct cmdtab *lookup __P((char *));
void command __P((char *));
void die __P((int));
void display __P((int));
-int dkinit __P((void));
+int dkinit __P((int));
int dkcmd __P((char *, char *));
void error __P((const char *fmt, ...));
void fetchiostat __P((void));
diff --git a/usr.bin/systat/iostat.c b/usr.bin/systat/iostat.c
index c2607d46790..d5db76ec76d 100644
--- a/usr.bin/systat/iostat.c
+++ b/usr.bin/systat/iostat.c
@@ -1,5 +1,4 @@
-/* $OpenBSD: iostat.c,v 1.2 1996/03/27 19:32:54 niklas Exp $ */
-/* $NetBSD: iostat.c,v 1.4 1996/03/15 22:19:25 ragge Exp $ */
+/* $NetBSD: iostat.c,v 1.5 1996/05/10 23:16:35 thorpej Exp $ */
/*
* Copyright (c) 1980, 1992, 1993
@@ -37,14 +36,14 @@
#ifndef lint
#if 0
static char sccsid[] = "@(#)iostat.c 8.1 (Berkeley) 6/6/93";
-static char rcsid[] = "$NetBSD: iostat.c,v 1.4 1996/03/15 22:19:25 ragge Exp $";
#endif
-static char rcsid[] = "$OpenBSD: iostat.c,v 1.2 1996/03/27 19:32:54 niklas Exp $";
+static char rcsid[] = "$NetBSD: iostat.c,v 1.5 1996/05/10 23:16:35 thorpej Exp $";
#endif not lint
#include <sys/param.h>
#include <sys/dkstat.h>
#include <sys/buf.h>
+#include <sys/time.h>
#include <string.h>
#include <stdlib.h>
@@ -53,39 +52,13 @@ static char rcsid[] = "$OpenBSD: iostat.c,v 1.2 1996/03/27 19:32:54 niklas Exp $
#include "systat.h"
#include "extern.h"
-static struct nlist namelist[] = {
-#define X_DK_BUSY 0
- { "_dk_busy" },
-#define X_DK_TIME 1
- { "_dk_time" },
-#define X_DK_XFER 2
- { "_dk_xfer" },
-#define X_DK_WDS 3
- { "_dk_wds" },
-#define X_DK_SEEK 4
- { "_dk_seek" },
-#define X_CP_TIME 5
- { "_cp_time" },
-#ifdef tahoe
-#define X_VBDINIT (X_CP_TIME+1)
- { "_vbdinit" },
-#endif
- { "" },
-};
-
-static struct {
- int dk_busy;
- long cp_time[CPUSTATES];
- long *dk_time;
- long *dk_wds;
- long *dk_seek;
- long *dk_xfer;
-} s, s1;
+#include "dkstats.h"
+extern struct _disk cur;
static int linesperregion;
static double etime;
static int numbers = 0; /* default display bar graphs */
-static int msps = 0; /* default ms/seek shown */
+static int secs = 0; /* default seconds shown */
static int barlabels __P((int));
static void histogram __P((double, int, double));
@@ -114,42 +87,16 @@ closeiostat(w)
int
initiostat()
{
- if (namelist[X_DK_BUSY].n_type == 0) {
- if (kvm_nlist(kd, namelist)) {
- nlisterr(namelist);
- return(0);
- }
- if (namelist[X_DK_BUSY].n_type == 0) {
- error("Disk init information isn't in namelist");
- return(0);
- }
- }
- if (! dkinit())
- return(0);
- if (dk_ndrive) {
-#define allocate(e, t) \
- s./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
- s1./**/e = (t *)calloc(dk_ndrive, sizeof (t));
- allocate(dk_time, long);
- allocate(dk_wds, long);
- allocate(dk_seek, long);
- allocate(dk_xfer, long);
-#undef allocate
- }
- return(1);
+ dkinit(1);
+ dkreadstats();
}
void
fetchiostat()
{
- if (namelist[X_DK_BUSY].n_type == 0)
+ if (dk_ndrive == 0)
return;
- NREAD(X_DK_BUSY, &s.dk_busy, LONG);
- NREAD(X_DK_TIME, s.dk_time, dk_ndrive * LONG);
- NREAD(X_DK_XFER, s.dk_xfer, dk_ndrive * LONG);
- NREAD(X_DK_WDS, s.dk_wds, dk_ndrive * LONG);
- NREAD(X_DK_SEEK, s.dk_seek, dk_ndrive * LONG);
- NREAD(X_CP_TIME, s.cp_time, sizeof s.cp_time);
+ dkreadstats();
}
#define INSET 10
@@ -159,8 +106,8 @@ labeliostat()
{
int row;
- if (namelist[X_DK_BUSY].n_type == 0) {
- error("No dk_busy defined.");
+ if (dk_ndrive == 0) {
+ error("No drives defined.");
return;
}
row = 0;
@@ -187,7 +134,7 @@ numlabels(row)
#define COLWIDTH 14
#define DRIVESPERLINE ((wnd->maxx - INSET) / COLWIDTH)
for (ndrives = 0, i = 0; i < dk_ndrive; i++)
- if (dk_select[i])
+ if (cur.dk_select[i])
ndrives++;
regions = howmany(ndrives, DRIVESPERLINE);
/*
@@ -202,14 +149,14 @@ numlabels(row)
linesperregion = 3;
col = 0;
for (i = 0; i < dk_ndrive; i++)
- if (dk_select[i] && dk_mspw[i] != 0.0) {
+ if (cur.dk_select[i] /*&& cur.dk_bytes[i] != 0.0*/) {
if (col + COLWIDTH >= wnd->maxx - INSET) {
col = 0, row += linesperregion + 1;
if (row > wnd->maxy - (linesperregion + 1))
break;
}
- mvwaddstr(wnd, row, col + 4, dr_name[i]);
- mvwaddstr(wnd, row + 1, col, "bps tps msps");
+ mvwaddstr(wnd, row, col + 4, cur.dk_name[i]);
+ mvwaddstr(wnd, row + 1, col, "Kps tps sec");
col += COLWIDTH;
}
if (col)
@@ -224,16 +171,16 @@ barlabels(row)
int i;
mvwaddstr(wnd, row++, INSET,
- "/0 /5 /10 /15 /20 /25 /30 /35 /40 /45 /50");
- linesperregion = 2 + msps;
+ "/0 /10 /20 /30 /40 /50 /60 /70 /80 /90 /100");
+ linesperregion = 2 + secs;
for (i = 0; i < dk_ndrive; i++)
- if (dk_select[i] && dk_mspw[i] != 0.0) {
+ if (cur.dk_select[i] /*&& cur.dk_bytes[i] != 0.0*/) {
if (row > wnd->maxy - linesperregion)
break;
- mvwprintw(wnd, row++, 0, "%3.3s bps|", dr_name[i]);
+ mvwprintw(wnd, row++, 0, "%3.3s Kps|", cur.dk_name[i]);
mvwaddstr(wnd, row++, 0, " tps|");
- if (msps)
- mvwaddstr(wnd, row++, 0, " msps|");
+ if (secs)
+ mvwaddstr(wnd, row++, 0, " msec|");
}
return (row);
}
@@ -242,19 +189,16 @@ barlabels(row)
void
showiostat()
{
- register long t;
+ register u_int64_t t;
register int i, row, col;
- if (namelist[X_DK_BUSY].n_type == 0)
+ if (dk_ndrive == 0)
return;
- for (i = 0; i < dk_ndrive; i++) {
-#define X(fld) t = s.fld[i]; s.fld[i] -= s1.fld[i]; s1.fld[i] = t
- X(dk_xfer); X(dk_seek); X(dk_wds); X(dk_time);
- }
+ dkswap();
+
etime = 0;
for(i = 0; i < CPUSTATES; i++) {
- X(cp_time);
- etime += s.cp_time[i];
+ etime += cur.cp_time[i];
}
if (etime == 0.0)
etime = 1.0;
@@ -269,7 +213,7 @@ showiostat()
if (!numbers) {
row += 2;
for (i = 0; i < dk_ndrive; i++)
- if (dk_select[i] && dk_mspw[i] != 0.0) {
+ if (cur.dk_select[i] /*&& cur.dk_bytes[i] != 0.0*/) {
if (row > wnd->maxy - linesperregion)
break;
row = stats(row, INSET, i);
@@ -282,7 +226,7 @@ showiostat()
wmove(wnd, row + 3, 0);
winsertln(wnd);
for (i = 0; i < dk_ndrive; i++)
- if (dk_select[i] && dk_mspw[i] != 0.0) {
+ if (cur.dk_select[i] /*&& cur.dk_bytes[i] != 0.0*/) {
if (col + COLWIDTH >= wnd->maxx) {
col = 0, row += linesperregion + 1;
if (row > wnd->maxy - (linesperregion + 1))
@@ -301,31 +245,26 @@ static int
stats(row, col, dn)
int row, col, dn;
{
- double atime, words, xtime, itime;
-
- atime = s.dk_time[dn];
- atime /= (float) hz;
- words = s.dk_wds[dn]*32.0; /* number of words transferred */
- xtime = dk_mspw[dn]*words; /* transfer time */
- itime = atime - xtime; /* time not transferring */
- if (xtime < 0)
- itime += xtime, xtime = 0;
- if (itime < 0)
- xtime += itime, itime = 0;
+ double atime, words;
+
+ /* time busy in disk activity */
+ atime = (double)cur.dk_time[dn].tv_sec +
+ ((double)cur.dk_time[dn].tv_usec / (double)1000000);
+
+ words = cur.dk_bytes[dn] / 1024.0; /* # of K transferred */
if (numbers) {
mvwprintw(wnd, row, col, "%3.0f%4.0f%5.1f",
- words / 512 / etime, s.dk_xfer[dn] / etime,
- s.dk_seek[dn] ? itime * 1000. / s.dk_seek[dn] : 0.0);
+ words / etime, cur.dk_xfer[dn] / etime, atime / etime);
return (row);
}
wmove(wnd, row++, col);
- histogram(words / 512 / etime, 50, 1.0);
+ histogram(words / etime, 50, 0.5);
wmove(wnd, row++, col);
- histogram(s.dk_xfer[dn] / etime, 50, 1.0);
- if (msps) {
+ histogram(cur.dk_xfer[dn] / etime, 50, 0.5);
+ if (secs) {
wmove(wnd, row++, col);
- histogram(s.dk_seek[dn] ? itime * 1000. / s.dk_seek[dn] : 0,
- 50, 1.0);
+ atime *= 1000; /* In milliseconds */
+ histogram(atime / etime, 50, 0.5);
}
return (row);
}
@@ -339,12 +278,12 @@ stat1(row, o)
time = 0;
for (i = 0; i < CPUSTATES; i++)
- time += s.cp_time[i];
+ time += cur.cp_time[i];
if (time == 0.0)
time = 1.0;
wmove(wnd, row, INSET);
#define CPUSCALE 0.5
- histogram(100.0 * s.cp_time[o] / time, 50, CPUSCALE);
+ histogram(100.0 * cur.cp_time[o] / time, 50, CPUSCALE);
}
static void
@@ -364,6 +303,7 @@ histogram(val, colwidth, scale)
while (k--)
waddch(wnd, 'X');
waddstr(wnd, buf);
+ wclrtoeol(wnd);
return;
}
while (k--)
@@ -376,8 +316,8 @@ cmdiostat(cmd, args)
char *cmd, *args;
{
- if (prefix(cmd, "msps"))
- msps = !msps;
+ if (prefix(cmd, "secs"))
+ secs = !secs;
else if (prefix(cmd, "numbers"))
numbers = 1;
else if (prefix(cmd, "bars"))
diff --git a/usr.bin/systat/main.c b/usr.bin/systat/main.c
index 6d1e8ee9a0c..03391852d74 100644
--- a/usr.bin/systat/main.c
+++ b/usr.bin/systat/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.7 1996/03/21 18:04:25 jtc Exp $ */
+/* $NetBSD: main.c,v 1.8 1996/05/10 23:16:36 thorpej Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@@ -43,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$NetBSD: main.c,v 1.7 1996/03/21 18:04:25 jtc Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.8 1996/05/10 23:16:36 thorpej Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -53,6 +53,7 @@ static char rcsid[] = "$NetBSD: main.c,v 1.7 1996/03/21 18:04:25 jtc Exp $";
#include <signal.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
#include "systat.h"
#include "extern.h"
@@ -68,6 +69,8 @@ static struct nlist namelist[] = {
static int dellave;
kvm_t *kd;
+char *memf = NULL;
+char *nlistf = NULL;
sig_t sigtstpdfl;
double avenrun[3];
int col;
@@ -82,32 +85,59 @@ int CMDLINE;
static WINDOW *wload; /* one line window for load average */
+static void usage();
+
int
main(argc, argv)
int argc;
char **argv;
{
+ int ch;
char errbuf[80];
- argc--, argv++;
+ while ((ch = getopt(argc, argv, "M:N:w:")) != EOF)
+ switch(ch) {
+ case 'M':
+ memf = optarg;
+ break;
+ case 'N':
+ nlistf = optarg;
+ break;
+ case 'w':
+ if ((naptime = atoi(optarg)) <= 0)
+ errx(1, "interval <= 0.");
+ break;
+ case '?':
+ default:
+ usage();
+ }
+ argc -= optind;
+ argv += optind;
+ /*
+ * Discard setgid privileges if not the running kernel so that bad
+ * guys can't print interesting stuff from kernel memory.
+ */
+ if (nlistf != NULL || memf != NULL)
+ setgid(getgid());
+
while (argc > 0) {
- if (argv[0][0] == '-') {
+ if (isdigit(argv[0][0])) {
+ naptime = atoi(argv[0]);
+ if (naptime <= 0)
+ naptime = 5;
+ } else {
struct cmdtab *p;
- p = lookup(&argv[0][1]);
+ p = lookup(&argv[0][0]);
if (p == (struct cmdtab *)-1)
- errx(1, "ambiguous request: %s", &argv[0][1]);
+ errx(1, "ambiguous request: %s", &argv[0][0]);
if (p == 0)
- errx(1, "unknown request: %s", &argv[0][1]);
+ errx(1, "unknown request: %s", &argv[0][0]);
curcmd = p;
- } else {
- naptime = atoi(argv[0]);
- if (naptime <= 0)
- naptime = 5;
}
argc--, argv++;
}
- kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf);
+ kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
if (kd == NULL) {
error("%s", errbuf);
exit(1);
@@ -162,6 +192,14 @@ main(argc, argv)
/*NOTREACHED*/
}
+static void
+usage()
+{
+ fprintf(stderr, "usage: systat [-M core] [-N system] [-w wait]\n");
+ exit(1);
+}
+
+
void
labels()
{
diff --git a/usr.bin/systat/swap.c b/usr.bin/systat/swap.c
index 75c9fc99a83..63e95c7e883 100644
--- a/usr.bin/systat/swap.c
+++ b/usr.bin/systat/swap.c
@@ -1,4 +1,4 @@
-/* $NetBSD: swap.c,v 1.4 1995/08/31 22:20:19 jtc Exp $ */
+/* $NetBSD: swap.c,v 1.5 1996/05/10 23:16:38 thorpej Exp $ */
/*-
* Copyright (c) 1980, 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)swap.c 8.3 (Berkeley) 4/29/95";
#endif
-static char rcsid[] = "$NetBSD: swap.c,v 1.4 1995/08/31 22:20:19 jtc Exp $";
+static char rcsid[] = "$NetBSD: swap.c,v 1.5 1996/05/10 23:16:38 thorpej Exp $";
#endif /* not lint */
/*
@@ -64,8 +64,6 @@ static char rcsid[] = "$NetBSD: swap.c,v 1.4 1995/08/31 22:20:19 jtc Exp $";
extern char *getbsize __P((int *headerlenp, long *blocksizep));
void showspace __P((char *header, int hlen, long blocksize));
-extern kvm_t *kd;
-
struct nlist syms[] = {
{ "_swapmap" }, /* list of free swap areas */
#define VM_SWAPMAP 0
diff --git a/usr.bin/systat/systat.1 b/usr.bin/systat/systat.1
index 1a652be9264..8d17f8afe41 100644
--- a/usr.bin/systat/systat.1
+++ b/usr.bin/systat/systat.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: systat.1,v 1.5 1995/09/27 19:46:12 jtc Exp $
+.\" $NetBSD: systat.1,v 1.6 1996/05/10 23:16:39 thorpej Exp $
.\"
.\" Copyright (c) 1985, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -41,7 +41,10 @@
.Nd display system statistics on a crt
.Sh SYNOPSIS
.Nm systat
-.Op Fl display
+.Op Fl M Ar core
+.Op Fl N Ar system
+.Op Fl w Ar wait
+.Op Ar display
.Op Ar refresh-interval
.Sh DESCRIPTION
.Nm Systat
@@ -78,12 +81,20 @@ allows each display to have certain display-specific commands.
.Pp
Command line options:
.Bl -tag -width "refresh_interval"
-.It Fl Ns Ar display
+.It Fl M Ar core
+Extract values associated with the name list from
+.Ar core
+instead of the default
+.Pa /dev/mem .
+.It Fl N Ar system
+Extracr the name list from
+.Ar system
+instead of the default
+.Pa /netbsd .
+.It Ar display
The
-.Fl
-flag expects
.Ar display
-to be one of:
+argument expects to be one of:
.Ic pigs ,
.Ic iostat ,
.Ic swap ,
@@ -91,14 +102,17 @@ to be one of:
.Ic vmstat
or
.Ic netstat .
-These displays can also be requested interactively (without the
-.Dq Fl )
-and are described in
+These displays can also be requested interactively and are described in
full detail below.
.It Ar refresh-interval
The
-.Ar refresh-value
-specifies the screen refresh time interval in seconds.
+.Ar refresh-interval
+specifies the screen refresh time interval in seconds. This is provided
+for backwards compatibility, and overrides the
+.Ar refresh-interval
+specified with the
+.Fl w
+flag.
.El
.Pp
Certain characters cause immediate action by
@@ -162,7 +176,7 @@ bar graphs of the amount of time executing in user mode (``user''),
in user mode running low priority processes (``nice''), in
system mode (``system''), and idle (``idle''). Statistics
on disk throughput show, for each drive, kilobytes of data transferred,
-number of disk transactions performed, and average seek time
+number of disk transactions performed, and time spent in disk accesses
(in milliseconds). This information may be displayed as
bar graphs or as rows of numbers which scroll downward. Bar
graphs are shown by default;
@@ -181,9 +195,9 @@ displayed in numeric columns which scroll downward.
Show the disk
.Tn I/O
statistics in bar graph form (default).
-.It Cm msps
-Toggle the display of average seek time (the default is to
-not display seek times).
+.It Cm secs
+Toggle the display of time in disk activity (the default is to
+not display time).
.El
.It Ic swap
Show information about swap space usage on all the
@@ -226,10 +240,10 @@ Finally the last column shows the number of physical pages
on the free list.
.Pp
Below the memory display is the disk usage display.
-It reports the number of seeks, transfers, and number
+It reports the number of seeks, transfers, number
of kilobyte blocks transferred per second averaged over the
-refresh period of the display (by default, five seconds).
-For some disks it also reports the average milliseconds per seek.
+refresh period of the display (by default, five seconds), and
+the time spent in disk accesses.
Note that the system only keeps statistics on at most four disks.
.Pp
Below the disk display is a list of the
diff --git a/usr.bin/systat/vmstat.c b/usr.bin/systat/vmstat.c
index ce8e74da457..4db84af9ccb 100644
--- a/usr.bin/systat/vmstat.c
+++ b/usr.bin/systat/vmstat.c
@@ -1,4 +1,4 @@
-/* $NetBSD: vmstat.c,v 1.4 1995/04/29 05:54:55 cgd Exp $ */
+/* $NetBSD: vmstat.c,v 1.5 1996/05/10 23:16:40 thorpej Exp $ */
/*-
* Copyright (c) 1983, 1989, 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)vmstat.c 8.2 (Berkeley) 1/12/94";
#endif
-static char rcsid[] = "$NetBSD: vmstat.c,v 1.4 1995/04/29 05:54:55 cgd Exp $";
+static char rcsid[] = "$NetBSD: vmstat.c,v 1.5 1996/05/10 23:16:40 thorpej Exp $";
#endif /* not lint */
/*
@@ -72,16 +72,15 @@ static struct Info {
long time[CPUSTATES];
struct vmmeter Cnt;
struct vmtotal Total;
- long *dk_time;
- long *dk_wds;
- long *dk_seek;
- long *dk_xfer;
- int dk_busy;
struct nchstats nchstats;
long nchcount;
long *intrcnt;
} s, s1, s2, z;
+#include "dkstats.h"
+extern struct _disk cur;
+
+
#define cnt s.Cnt
#define oldcnt s1.Cnt
#define total s.Total
@@ -215,7 +214,7 @@ initkre()
}
}
hertz = stathz ? stathz : hz;
- if (! dkinit())
+ if (! dkinit(1))
return(0);
if (dk_ndrive && !once) {
#define allocate(e, t) \
@@ -223,10 +222,6 @@ initkre()
s1./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
s2./**/e = (t *)calloc(dk_ndrive, sizeof (t)); \
z./**/e = (t *)calloc(dk_ndrive, sizeof (t));
- allocate(dk_time, long);
- allocate(dk_wds, long);
- allocate(dk_seek, long);
- allocate(dk_xfer, long);
once = 1;
#undef allocate
}
@@ -331,8 +326,8 @@ labelkre()
mvprintw(DISKROW, DISKCOL, "Discs");
mvprintw(DISKROW + 1, DISKCOL, "seeks");
mvprintw(DISKROW + 2, DISKCOL, "xfers");
- mvprintw(DISKROW + 3, DISKCOL, " blks");
- mvprintw(DISKROW + 4, DISKCOL, " msps");
+ mvprintw(DISKROW + 3, DISKCOL, "Kbyte");
+ mvprintw(DISKROW + 4, DISKCOL, " sec");
j = 0;
for (i = 0; i < dk_ndrive && j < MAXDRIVES; i++)
if (dk_select[i]) {
@@ -367,9 +362,9 @@ showkre()
int i, l, c;
static int failcnt = 0;
- for (i = 0; i < dk_ndrive; i++) {
- X(dk_xfer); X(dk_seek); X(dk_wds); X(dk_time);
- }
+
+ if (state == TIME)
+ dkswap();
etime = 0;
for(i = 0; i < CPUSTATES; i++) {
X(time);
@@ -617,13 +612,9 @@ getinfo(s, st)
size_t size;
extern int errno;
+ dkreadstats();
NREAD(X_CPTIME, s->time, sizeof s->time);
NREAD(X_CNT, &s->Cnt, sizeof s->Cnt);
- NREAD(X_DK_BUSY, &s->dk_busy, LONG);
- NREAD(X_DK_TIME, s->dk_time, dk_ndrive * LONG);
- NREAD(X_DK_XFER, s->dk_xfer, dk_ndrive * LONG);
- NREAD(X_DK_WDS, s->dk_wds, dk_ndrive * LONG);
- NREAD(X_DK_SEEK, s->dk_seek, dk_ndrive * LONG);
NREAD(X_NCHSTATS, &s->nchstats, sizeof s->nchstats);
NREAD(X_INTRCNT, s->intrcnt, nintr * LONG);
size = sizeof(s->Total);
@@ -649,21 +640,10 @@ static void
copyinfo(from, to)
register struct Info *from, *to;
{
- long *time, *wds, *seek, *xfer;
long *intrcnt;
- /*
- * time, wds, seek, and xfer are malloc'd so we have to
- * save the pointers before the structure copy and then
- * copy by hand.
- */
- time = to->dk_time; wds = to->dk_wds; seek = to->dk_seek;
- xfer = to->dk_xfer; intrcnt = to->intrcnt;
+ intrcnt = to->intrcnt;
*to = *from;
- bcopy(from->dk_time, to->dk_time = time, dk_ndrive * sizeof (long));
- bcopy(from->dk_wds, to->dk_wds = wds, dk_ndrive * sizeof (long));
- bcopy(from->dk_seek, to->dk_seek = seek, dk_ndrive * sizeof (long));
- bcopy(from->dk_xfer, to->dk_xfer = xfer, dk_ndrive * sizeof (long));
bcopy(from->intrcnt, to->intrcnt = intrcnt, nintr * sizeof (int));
}
@@ -671,23 +651,18 @@ static void
dinfo(dn, c)
int dn, c;
{
- double words, atime, itime, xtime;
+ double words, atime;
c = DISKCOL + c * 5;
- atime = s.dk_time[dn];
- atime /= hertz;
- words = s.dk_wds[dn]*32.0; /* number of words transferred */
- xtime = dk_mspw[dn]*words; /* transfer time */
- itime = atime - xtime; /* time not transferring */
- if (xtime < 0)
- itime += xtime, xtime = 0;
- if (itime < 0)
- xtime += itime, itime = 0;
- putint((int)((float)s.dk_seek[dn]/etime+0.5), DISKROW + 1, c, 5);
- putint((int)((float)s.dk_xfer[dn]/etime+0.5), DISKROW + 2, c, 5);
- putint((int)(words/etime/512.0 + 0.5), DISKROW + 3, c, 5);
- if (s.dk_seek[dn])
- putfloat(itime*1000.0/s.dk_seek[dn], DISKROW + 4, c, 5, 1, 1);
- else
- putint(0, DISKROW + 4, c, 5);
+
+ /* time busy in disk activity */
+ atime = (double)cur.dk_time[dn].tv_sec +
+ ((double)cur.dk_time[dn].tv_usec / (double)1000000);
+
+ words = cur.dk_bytes[dn] / 1024.0; /* # of K transferred */
+
+ putint((int)((float)cur.dk_seek[dn]/etime+0.5), DISKROW + 1, c, 5);
+ putint((int)((float)cur.dk_xfer[dn]/etime+0.5), DISKROW + 2, c, 5);
+ putint((int)(words/etime + 0.5), DISKROW + 3, c, 5);
+ putfloat(atime/etime, DISKROW + 4, c, 5, 1, 1);
}
diff --git a/usr.bin/vmstat/Makefile b/usr.bin/vmstat/Makefile
index 9718e67d6f0..83a345f760e 100644
--- a/usr.bin/vmstat/Makefile
+++ b/usr.bin/vmstat/Makefile
@@ -1,13 +1,9 @@
-# $OpenBSD: Makefile,v 1.2 1996/03/03 02:51:20 tholo Exp $
-# $NetBSD: Makefile,v 1.14 1995/05/07 22:15:57 cgd Exp $
+# $OpenBSD: Makefile,v 1.3 1996/05/22 11:35:41 deraadt Exp $
+# $NetBSD: Makefile,v 1.15 1996/05/10 23:19:25 thorpej Exp $
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= vmstat
-.if (${MACHINE_ARCH} == "m68k")
-CFLAGS+=-D${MACHINE}
-.endif
-CFLAGS+=-I${.CURDIR}/../../sys/arch
SRCS= dkstats.c vmstat.c
MAN= vmstat.8
DPADD= ${LIBKVM}
diff --git a/usr.bin/vmstat/dkstats.c b/usr.bin/vmstat/dkstats.c
index f7cc56f9a91..70796e86afb 100644
--- a/usr.bin/vmstat/dkstats.c
+++ b/usr.bin/vmstat/dkstats.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: dkstats.c,v 1.1 1996/03/03 02:51:20 tholo Exp $ */
+/* $NetBSD: dkstats.c,v 1.1 1996/05/10 23:19:27 thorpej Exp $ */
/*
- * Copyright (c) 1996 John M. Vinopal (banshee@resort.com)
+ * Copyright (c) 1996 John M. Vinopal
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -99,7 +99,7 @@ char **dr_name;
void dkswap __P((void));
void dkreadstats __P((void));
int dkinit __P((int));
-static void deref_kptr __P(( void *, void *, size_t));
+static void deref_kptr __P((void *, void *, size_t));
/*
* Take the delta between the present values and the last recorded
@@ -265,7 +265,7 @@ deref_kptr(kptr, ptr, len)
if (kvm_read(kd, (u_long)kptr, (char *)ptr, len) != len) {
bzero(buf, sizeof(buf));
snprintf(buf, (sizeof(buf) - 1),
- "can't dereference kptr 0x%x", (uint)kptr);
+ "can't dereference kptr 0x%lx", (u_long)kptr);
KVM_ERROR(buf);
}
}
diff --git a/usr.bin/vmstat/dkstats.h b/usr.bin/vmstat/dkstats.h
index d22e84bf37e..bfde443e533 100644
--- a/usr.bin/vmstat/dkstats.h
+++ b/usr.bin/vmstat/dkstats.h
@@ -1,7 +1,7 @@
-/* $OpenBSD: dkstats.h,v 1.1 1996/03/03 02:51:21 tholo Exp $ */
+/* $NetBSD: dkstats.h,v 1.1 1996/05/10 23:19:28 thorpej Exp $ */
/*
- * Copyright (c) 1996 John M. Vinopal (banshee@resort.com)
+ * Copyright (c) 1996 John M. Vinopal
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -47,4 +47,3 @@ struct _disk {
long tk_nout; /* TTY Chars out. */
long cp_time[CPUSTATES]; /* System timer ticks. */
};
-
diff --git a/usr.bin/vmstat/vmstat.8 b/usr.bin/vmstat/vmstat.8
index 119916d11b8..4f5d6234d73 100644
--- a/usr.bin/vmstat/vmstat.8
+++ b/usr.bin/vmstat/vmstat.8
@@ -1,4 +1,4 @@
-.\" $NetBSD: vmstat.8,v 1.11 1995/08/10 23:29:47 jtc Exp $
+.\" $NetBSD: vmstat.8,v 1.12 1996/05/10 23:19:30 thorpej Exp $
.\"
.\" Copyright (c) 1986, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -190,7 +190,7 @@ Others vary every second and running the output for a while will make it
apparent which are recomputed every second.
.SH FILES
.ta \w'/dev/mem 'u
-/bsd default kernel namelist
+/netbsd default kernel namelist
.br
/dev/mem default memory file
.SH SEE ALSO
diff --git a/usr.bin/vmstat/vmstat.c b/usr.bin/vmstat/vmstat.c
index 9d388064806..86dd3d49bb6 100644
--- a/usr.bin/vmstat/vmstat.c
+++ b/usr.bin/vmstat/vmstat.c
@@ -1,5 +1,4 @@
-/* $OpenBSD: vmstat.c,v 1.9 1996/04/21 23:44:44 deraadt Exp $ */
-/* $NetBSD: vmstat.c,v 1.28 1996/04/04 00:27:50 cgd Exp $ */
+/* $NetBSD: vmstat.c,v 1.29 1996/05/10 23:19:32 thorpej Exp $ */
/*
* Copyright (c) 1980, 1986, 1991, 1993
@@ -44,7 +43,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)vmstat.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$NetBSD: vmstat.c,v 1.28 1996/04/04 00:27:50 cgd Exp $";
+static char rcsid[] = "$NetBSD: vmstat.c,v 1.29 1996/05/10 23:19:32 thorpej Exp $";
#endif
#endif /* not lint */
@@ -107,11 +106,11 @@ struct nlist namelist[] = {
{ "_bucket" },
#define X_ALLEVENTS 14
{ "_allevents" },
-#define X_FORKSTAT 15
- { "_forkstat" },
#ifdef notdef
-#define X_DEFICIT 16
+#define X_DEFICIT 15
{ "_deficit" },
+#define X_FORKSTAT 16
+ { "_forkstat" },
#define X_REC 17
{ "_rectime" },
#define X_PGIN 18
@@ -120,15 +119,7 @@ struct nlist namelist[] = {
{ "_xstats" },
#define X_END 20
#else
-#define X_END 16
-#endif
-#if defined(hp300) || defined(luna68k)
-#define X_HPDINIT (X_END)
- { "_hp_dinit" },
-#endif
-#ifdef mips
-#define X_SCSI_DINIT (X_END)
- { "_scsi_dinit" },
+#define X_END 15
#endif
#ifdef tahoe
#define X_VBDINIT (X_END)
@@ -142,19 +133,13 @@ struct nlist namelist[] = {
#define X_IVT (X_END)
{ "_ivt" },
#endif
-#if defined(i386)
-#define X_INTRHAND (X_END)
- { "_intrhand" },
-#define X_INTRSTRAY (X_END+1)
- { "_intrstray" },
-#endif
{ "" },
};
/* Objects defined in dkstats.c */
extern struct _disk cur;
-extern char **dr_name;
-extern int *dk_select, dk_ndrive;
+extern char **dr_name;
+extern int *dk_select, dk_ndrive;
struct vmmeter sum, osum;
int ndrives;
@@ -170,12 +155,23 @@ kvm_t *kd;
#define TIMESTAT 0x10
#define VMSTAT 0x20
-void cpustats(), dkstats(), dointr(), domem(), dosum();
-void dovmstat(), kread(), usage();
-void dotimes(), doforkst();
+void cpustats __P((void));
+void dkstats __P((void));
+void dointr __P((void));
+void domem __P((void));
+void dosum __P((void));
+void dovmstat __P((u_int, int));
+void kread __P((int, void *, size_t));
+void usage __P((void));
+#ifdef notdef
+void dotimes __P((void));
+void doforkst __P((void));
+#endif
-char *nlistf = NULL;
-char *memf = NULL;
+char **choosedrives __P((char **));
+
+/* Namelist and memory file names. */
+char *nlistf, *memf;
main(argc, argv)
register int argc;
@@ -186,7 +182,6 @@ main(argc, argv)
register int c, todo;
u_int interval;
int reps;
- char *memf, *nlistf;
char errbuf[_POSIX2_LINE_MAX];
memf = nlistf = NULL;
@@ -196,9 +191,11 @@ main(argc, argv)
case 'c':
reps = atoi(optarg);
break;
+#ifndef notdef
case 'f':
todo |= FORKSTAT;
break;
+#endif
case 'i':
todo |= INTRSTAT;
break;
@@ -214,9 +211,11 @@ main(argc, argv)
case 's':
todo |= SUMSTAT;
break;
+#ifndef notdef
case 't':
todo |= TIMESTAT;
break;
+#endif
case 'w':
interval = atoi(optarg);
break;
@@ -262,7 +261,6 @@ main(argc, argv)
}
if (todo & VMSTAT) {
- char **choosedrives();
struct winsize winsize;
dkinit(0); /* Initialize disk stats, no disks selected. */
@@ -289,14 +287,18 @@ main(argc, argv)
} else if (reps)
interval = 1;
+#ifdef notdef
if (todo & FORKSTAT)
doforkst();
+#endif
if (todo & MEMSTAT)
domem();
if (todo & SUMSTAT)
dosum();
+#ifdef notdef
if (todo & TIMESTAT)
dotimes();
+#endif
if (todo & INTRSTAT)
dointr();
if (todo & VMSTAT)
@@ -486,28 +488,25 @@ needhdr()
hdrcnt = 1;
}
+#ifdef notdef
void
dotimes()
{
u_int pgintime, rectime;
-#ifdef NEWVM
- pgintime = 0;
- rectime = 0;
-#else
kread(X_REC, &rectime, sizeof(rectime));
kread(X_PGIN, &pgintime, sizeof(pgintime));
-#endif
kread(X_SUM, &sum, sizeof(sum));
- (void)printf("%u reactivates, %u total time (usec)\n",
- sum.v_reactivated, rectime);
- (void)printf("average: %u usec / reclaim\n", rectime / sum.v_reactivated);
+ (void)printf("%u reclaims, %u total time (usec)\n",
+ sum.v_pgrec, rectime);
+ (void)printf("average: %u usec / reclaim\n", rectime / sum.v_pgrec);
(void)printf("\n");
(void)printf("%u page ins, %u total time (msec)\n",
- sum.v_pageins, pgintime / 10);
+ sum.v_pgin, pgintime / 10);
(void)printf("average: %8.1f msec / page in\n",
- pgintime / (sum.v_pageins * 10.0));
+ pgintime / (sum.v_pgin * 10.0));
}
+#endif
pct(top, bot)
long top, bot;
@@ -595,7 +594,7 @@ dosum()
nchstats.ncs_miss + nchstats.ncs_long;
(void)printf("%9ld total name lookups\n", nchtotal);
(void)printf(
- "%9s cache hits (%d%% pos + %d%% neg) system %d%% per-directory\n",
+ "%9s cache hits (%d%% pos + %d%% neg) system %d%% per-process\n",
"", PCT(nchstats.ncs_goodhits, nchtotal),
PCT(nchstats.ncs_neghits, nchtotal),
PCT(nchstats.ncs_pass2, nchtotal));
@@ -631,6 +630,7 @@ dosum()
#endif
}
+#ifdef notdef
void
doforkst()
{
@@ -640,10 +640,9 @@ doforkst()
(void)printf("%d forks, %d pages, average %.2f\n",
fks.cntfork, fks.sizfork, (double)fks.sizfork / fks.cntfork);
(void)printf("%d vforks, %d pages, average %.2f\n",
- fks.cntvfork, fks.sizvfork, (double)fks.sizvfork / (fks.cntvfork ? fks.cntvfork : 1));
- (void)printf("%d rforks, %d pages, average %.2f\n",
- fks.cntrfork, fks.sizrfork, (double)fks.sizrfork / (fks.cntrfork ? fks.cntrfork : 1));
+ fks.cntvfork, fks.sizvfork, (double)fks.sizvfork / fks.cntvfork);
}
+#endif
void
dkstats()
@@ -722,47 +721,6 @@ dointr()
inttotal, inttotal / uptime);
}
}
-#elif defined(i386)
-/* To get struct intrhand */
-#define _KERNEL
-#include <i386/isa/isa_machdep.h>
-#undef _KERNEL
-void
-dointr()
-{
- struct intrhand *intrhand[16], *ihp, ih;
- u_long inttotal, uptime;
- u_long intrstray[16];
- char iname[17];
- int i;
-
- iname[16] = '\0';
- uptime = getuptime();
- kread(X_INTRHAND, intrhand, sizeof(intrhand));
- kread(X_INTRSTRAY, intrstray, sizeof(intrstray));
-
- (void)printf("interrupt total rate\n");
- inttotal = 0;
- for (i = 0; i < 16; i++) {
- ihp = intrhand[i];
- while (ihp) {
- if (kvm_read(kd, (u_long)ihp, &ih, sizeof(ih)) != sizeof(ih))
- errx(1, "vmstat: ih: %s", kvm_geterr(kd));
- if (kvm_read(kd, (u_long)ih.ih_what, iname, 16) != 16)
- errx(1, "vmstat: ih_what: %s", kvm_geterr(kd));
- printf("%-16.16s %8lu %8lu\n", iname, ih.ih_count, ih.ih_count / uptime);
- inttotal += ih.ih_count;
- ihp = ih.ih_next;
- }
- }
- for (i = 0; i < 16; i++)
- if (intrstray[i]) {
- printf("Stray irq %-2d %8ld %8ld\n",
- i, intrstray[i], intrstray[i] / uptime);
- inttotal += intrstray[i];
- }
- printf("Total %8lu %8lu\n", inttotal, inttotal / uptime);
-}
#else
void
dointr()
diff --git a/usr.sbin/iostat/Makefile b/usr.sbin/iostat/Makefile
index 0dcd91ce116..3785ba53f38 100644
--- a/usr.sbin/iostat/Makefile
+++ b/usr.sbin/iostat/Makefile
@@ -1,17 +1,17 @@
-# $OpenBSD: Makefile,v 1.2 1996/03/03 02:52:32 tholo Exp $
+# $OpenBSD: Makefile,v 1.3 1996/05/22 11:35:47 deraadt Exp $
# $NetBSD: Makefile,v 1.12 1995/12/22 08:04:27 jonathan Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= iostat
-.if (${MACHINE_ARCH} == "m68k")
-CFLAGS+=-D${MACHINE}
-.endif
+MAN= iostat.8
.PATH: ${.CURDIR}/../../usr.bin/vmstat
-CFLAGS+=-I${.CURDIR}/../../sys/arch -I${.CURDIR}/../../usr.bin/vmstat
+CFLAGS+=-I${.CURDIR}/../../usr.bin/vmstat
+
+# dkstats.c pulled in from ../../usr.bin/vmstat
SRCS= dkstats.c iostat.c
-MAN= iostat.8
+
DPADD= ${LIBKVM}
LDADD= -lkvm
BINGRP= kmem
diff --git a/usr.sbin/iostat/iostat.8 b/usr.sbin/iostat/iostat.8
index 16f27ba1eb0..d2ed7c5ae83 100644
--- a/usr.sbin/iostat/iostat.8
+++ b/usr.sbin/iostat/iostat.8
@@ -1,5 +1,5 @@
-.\" $OpenBSD: iostat.8,v 1.2 1996/03/03 02:52:33 tholo Exp $
-.\" $NetBSD: iostat.8,v 1.8 1995/11/28 20:16:30 thorpej Exp $
+.\" $OpenBSD: iostat.8,v 1.3 1996/05/22 11:35:48 deraadt Exp $
+.\" $NetBSD: iostat.8,v 1.9 1996/05/10 23:20:28 thorpej Exp $
.\"
.\" Copyright (c) 1985, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
diff --git a/usr.sbin/iostat/iostat.c b/usr.sbin/iostat/iostat.c
index a9313ed3b47..ab6026f60bf 100644
--- a/usr.sbin/iostat/iostat.c
+++ b/usr.sbin/iostat/iostat.c
@@ -1,8 +1,8 @@
-/* $OpenBSD: iostat.c,v 1.2 1996/03/03 02:52:34 tholo Exp $ */
-/* $NetBSD: iostat.c,v 1.8 1995/11/28 20:16:31 thorpej Exp $ */
+/* $OpenBSD: iostat.c,v 1.3 1996/05/22 11:35:49 deraadt Exp $ */
+/* $NetBSD: iostat.c,v 1.9 1996/05/10 23:20:29 thorpej Exp $ */
/*
- * Copyright (c) 1996 John M. Vinopal (banshee@resort.com)
+ * Copyright (c) 1996 John M. Vinopal
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -76,7 +76,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)iostat.c 8.2 (Berkeley) 1/26/94";
#else
-static char *rcsid = "$NetBSD: iostat.c,v 1.8 1995/11/28 20:16:31 thorpej Exp $"
+static char *rcsid = "$NetBSD: iostat.c,v 1.9 1996/05/10 23:20:29 thorpej Exp $"
;
#endif
#endif /* not lint */
@@ -98,8 +98,8 @@ static char *rcsid = "$NetBSD: iostat.c,v 1.8 1995/11/28 20:16:31 thorpej Exp $"
extern struct _disk cur;
extern int dk_ndrive;
-char *nlistf = NULL;
-char *memf = NULL;
+/* Namelist and memory files. */
+char *nlistf, *memf;
int hz, reps, interval;
static int todo = 0;
diff --git a/usr.sbin/pwd_mkdb/Makefile b/usr.sbin/pwd_mkdb/Makefile
index 4110a97b72f..90f5c280627 100644
--- a/usr.sbin/pwd_mkdb/Makefile
+++ b/usr.sbin/pwd_mkdb/Makefile
@@ -1,9 +1,11 @@
# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
-# $Id: Makefile,v 1.1.1.1 1995/10/18 08:48:01 deraadt Exp $
+# $Id: Makefile,v 1.2 1996/05/22 11:35:51 deraadt Exp $
PROG= pwd_mkdb
-SRCS= pw_scan.c pwd_mkdb.c getpwent.c
+SRCS= pwd_mkdb.c getpwent.c
MAN= pwd_mkdb.8
+LDADD+= -lutil
+DPADD+= ${LIBUTIL}
.PATH: ${.CURDIR}/../../lib/libc/gen
diff --git a/usr.sbin/pwd_mkdb/pw_scan.c b/usr.sbin/pwd_mkdb/pw_scan.c
deleted file mode 100644
index 00fd45cdf64..00000000000
--- a/usr.sbin/pwd_mkdb/pw_scan.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/*-
- * Copyright (c) 1990, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- * Portions Copyright(C) 1995, Jason Downs. 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[] = "from: @(#)pw_scan.c 8.3 (Berkeley) 4/2/94";*/
-static char *rcsid = "$Id: pw_scan.c,v 1.1.1.1 1995/10/18 08:48:01 deraadt Exp $";
-#endif /* not lint */
-
-/*
- * This module is used to "verify" password entries by chpass(1) and
- * pwd_mkdb(8).
- */
-
-#include <sys/param.h>
-
-#include <err.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "pw_scan.h"
-
-int
-pw_scan(bp, pw, flags)
- char *bp;
- struct passwd *pw;
- int *flags;
-{
- long id;
- int root;
- char *p, *sh;
-
- if (flags != (int *)NULL)
- *flags = 0;
-
- if (!(pw->pw_name = strsep(&bp, ":"))) /* login */
- goto fmt;
- root = !strcmp(pw->pw_name, "root");
-
- if (!(pw->pw_passwd = strsep(&bp, ":"))) /* passwd */
- goto fmt;
-
- if (!(p = strsep(&bp, ":"))) /* uid */
- goto fmt;
- id = atol(p);
- if (root && id) {
- warnx("root uid should be 0");
- return (0);
- }
- if (id > USHRT_MAX) {
- warnx("%s > max uid value (%d)", p, USHRT_MAX);
- return (0);
- }
- pw->pw_uid = id;
- if ((*p == '\0') && (flags != (int *)NULL))
- *flags |= _PASSWORD_NOUID;
-
- if (!(p = strsep(&bp, ":"))) /* gid */
- goto fmt;
- id = atol(p);
- if (id > USHRT_MAX) {
- warnx("%s > max gid value (%d)", p, USHRT_MAX);
- return (0);
- }
- pw->pw_gid = id;
- if ((*p == '\0') && (flags != (int *)NULL))
- *flags |= _PASSWORD_NOGID;
-
- pw->pw_class = strsep(&bp, ":"); /* class */
- if (!(p = strsep(&bp, ":"))) /* change */
- goto fmt;
- pw->pw_change = atol(p);
- if ((*p == '\0') && (flags != (int *)NULL))
- *flags |= _PASSWORD_NOCHG;
- if (!(p = strsep(&bp, ":"))) /* expire */
- goto fmt;
- pw->pw_expire = atol(p);
- if ((*p == '\0') && (flags != (int *)NULL))
- *flags |= _PASSWORD_NOEXP;
- pw->pw_gecos = strsep(&bp, ":"); /* gecos */
- pw->pw_dir = strsep(&bp, ":"); /* directory */
- if (!(pw->pw_shell = strsep(&bp, ":"))) /* shell */
- goto fmt;
-
- p = pw->pw_shell;
- if (root && *p) /* empty == /bin/sh */
- for (setusershell();;) {
- if (!(sh = getusershell())) {
- warnx("warning, unknown root shell");
- break;
- }
- if (!strcmp(p, sh))
- break;
- }
-
- if (p = strsep(&bp, ":")) { /* too many */
-fmt: warnx("corrupted entry");
- return (0);
- }
-
- return (1);
-}
diff --git a/usr.sbin/pwd_mkdb/pw_scan.h b/usr.sbin/pwd_mkdb/pw_scan.h
index f1ff78c1f64..e69de29bb2d 100644
--- a/usr.sbin/pwd_mkdb/pw_scan.h
+++ b/usr.sbin/pwd_mkdb/pw_scan.h
@@ -1,36 +0,0 @@
-/*-
- * 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.
- *
- * @(#)pw_scan.h 8.1 (Berkeley) 4/1/94
- */
-
-extern int pw_scan __P((char *, struct passwd *, int *));
diff --git a/usr.sbin/pwd_mkdb/pwd_mkdb.c b/usr.sbin/pwd_mkdb/pwd_mkdb.c
index 2ef250eb835..5c0e3926040 100644
--- a/usr.sbin/pwd_mkdb/pwd_mkdb.c
+++ b/usr.sbin/pwd_mkdb/pwd_mkdb.c
@@ -40,7 +40,7 @@ static char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)pwd_mkdb.c 8.5 (Berkeley) 4/20/94";*/
-static char *rcsid = "$Id: pwd_mkdb.c,v 1.4 1996/05/14 01:06:15 deraadt Exp $";
+static char *rcsid = "$Id: pwd_mkdb.c,v 1.5 1996/05/22 11:35:54 deraadt Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -57,8 +57,7 @@ static char *rcsid = "$Id: pwd_mkdb.c,v 1.4 1996/05/14 01:06:15 deraadt Exp $";
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-
-#include "pw_scan.h"
+#include <util.h>
#define INSECURE 1
#define SECURE 2
diff --git a/usr.sbin/vipw/Makefile b/usr.sbin/vipw/Makefile
index e89edcc054c..8b1123cc125 100644
--- a/usr.sbin/vipw/Makefile
+++ b/usr.sbin/vipw/Makefile
@@ -1,8 +1,10 @@
-# $NetBSD: Makefile,v 1.4 1995/01/20 19:19:53 mycroft Exp $
+# $NetBSD: Makefile,v 1.5 1996/05/15 23:23:45 jtc Exp $
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= vipw
-SRCS= pw_util.c vipw.c
+SRCS= vipw.c
+DPADD= ${LIBUTIL}
+LDADD= -lutil
MAN= vipw.8
.include <bsd.prog.mk>
diff --git a/usr.sbin/vipw/pw_util.c b/usr.sbin/vipw/pw_util.c
index ddafa60d57d..e69de29bb2d 100644
--- a/usr.sbin/vipw/pw_util.c
+++ b/usr.sbin/vipw/pw_util.c
@@ -1,222 +0,0 @@
-/* $NetBSD: pw_util.c,v 1.6 1995/01/20 19:45:39 mycroft Exp $ */
-
-/*-
- * Copyright (c) 1990, 1993, 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[] = "@(#)pw_util.c 8.3 (Berkeley) 4/2/94";
-#endif /* not lint */
-
-/*
- * This file is used by all the "password" programs; vipw(8), chpass(1),
- * and passwd(1).
- */
-
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-
-#include <err.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <paths.h>
-#include <pwd.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "pw_util.h"
-
-extern char *tempname;
-static pid_t editpid = -1;
-static int lockfd;
-
-void
-pw_cont(sig)
- int sig;
-{
-
- if (editpid != -1)
- kill(editpid, sig);
-}
-
-void
-pw_init()
-{
- struct rlimit rlim;
-
- /* Unlimited resource limits. */
- rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY;
- (void)setrlimit(RLIMIT_CPU, &rlim);
- (void)setrlimit(RLIMIT_FSIZE, &rlim);
- (void)setrlimit(RLIMIT_STACK, &rlim);
- (void)setrlimit(RLIMIT_DATA, &rlim);
- (void)setrlimit(RLIMIT_RSS, &rlim);
-
- /* Don't drop core (not really necessary, but GP's). */
- rlim.rlim_cur = rlim.rlim_max = 0;
- (void)setrlimit(RLIMIT_CORE, &rlim);
-
- /* Turn off signals. */
- (void)signal(SIGALRM, SIG_IGN);
- (void)signal(SIGHUP, SIG_IGN);
- (void)signal(SIGINT, SIG_IGN);
- (void)signal(SIGPIPE, SIG_IGN);
- (void)signal(SIGQUIT, SIG_IGN);
- (void)signal(SIGTERM, SIG_IGN);
- (void)signal(SIGCONT, pw_cont);
-
- /* Create with exact permissions. */
- (void)umask(0);
-}
-
-int
-pw_lock()
-{
- /*
- * If the master password file doesn't exist, the system is hosed.
- * Might as well try to build one. Set the close-on-exec bit so
- * that users can't get at the encrypted passwords while editing.
- * Open should allow flock'ing the file; see 4.4BSD. XXX
- */
- lockfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0);
- if (lockfd < 0 || fcntl(lockfd, F_SETFD, 1) == -1)
- err(1, "%s", _PATH_MASTERPASSWD);
- if (flock(lockfd, LOCK_EX|LOCK_NB))
- errx(1, "the password db file is busy");
- return (lockfd);
-}
-
-int
-pw_tmp()
-{
- static char path[MAXPATHLEN] = _PATH_MASTERPASSWD;
- int fd;
- char *p;
-
- if (p = strrchr(path, '/'))
- ++p;
- else
- p = path;
- strcpy(p, "pw.XXXXXX");
- if ((fd = mkstemp(path)) == -1)
- err(1, "%s", path);
- tempname = path;
- return (fd);
-}
-
-int
-pw_mkdb()
-{
- int pstat;
- pid_t pid;
-
- warnx("rebuilding the database...");
- (void)fflush(stderr);
- if (!(pid = vfork())) {
- execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p", tempname, NULL);
- pw_error(_PATH_PWD_MKDB, 1, 1);
- }
- pid = waitpid(pid, &pstat, 0);
- if (pid == -1 || !WIFEXITED(pstat) || WEXITSTATUS(pstat) != 0)
- return (0);
- warnx("done");
- return (1);
-}
-
-void
-pw_edit(notsetuid)
- int notsetuid;
-{
- int pstat;
- char *p, *editor;
-
- if (!(editor = getenv("EDITOR")))
- editor = _PATH_VI;
- if (p = strrchr(editor, '/'))
- ++p;
- else
- p = editor;
-
- if (!(editpid = vfork())) {
- if (notsetuid) {
- (void)setgid(getgid());
- (void)setuid(getuid());
- }
- execlp(editor, p, tempname, NULL);
- _exit(1);
- }
- for (;;) {
- editpid = waitpid(editpid, (int *)&pstat, WUNTRACED);
- if (editpid == -1)
- pw_error(editor, 1, 1);
- else if (WIFSTOPPED(pstat))
- raise(WSTOPSIG(pstat));
- else if (WIFEXITED(pstat) && WEXITSTATUS(pstat) == 0)
- break;
- else
- pw_error(editor, 1, 1);
- }
- editpid = -1;
-}
-
-void
-pw_prompt()
-{
- int c;
-
- (void)printf("re-edit the password file? [y]: ");
- (void)fflush(stdout);
- c = getchar();
- if (c != EOF && c != '\n')
- while (getchar() != '\n');
- if (c == 'n')
- pw_error(NULL, 0, 0);
-}
-
-void
-pw_error(name, err, eval)
- char *name;
- int err, eval;
-{
- if (err)
- warn(name);
-
- warnx("%s: unchanged", _PATH_MASTERPASSWD);
- (void)unlink(tempname);
- exit(eval);
-}
diff --git a/usr.sbin/vipw/pw_util.h b/usr.sbin/vipw/pw_util.h
index 46f811eb672..e69de29bb2d 100644
--- a/usr.sbin/vipw/pw_util.h
+++ b/usr.sbin/vipw/pw_util.h
@@ -1,44 +0,0 @@
-/* $NetBSD: pw_util.h,v 1.2 1995/01/20 19:19:55 mycroft 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.
- *
- * @(#)pw_util.h 8.2 (Berkeley) 4/1/94
- */
-
-void pw_edit __P((int));
-void pw_error __P((char *, int, int));
-void pw_init __P((void));
-int pw_lock __P((void));
-int pw_mkdb __P((void));
-void pw_prompt __P((void));
-int pw_tmp __P((void));
diff --git a/usr.sbin/vipw/vipw.c b/usr.sbin/vipw/vipw.c
index 85fc0412eae..785b8087307 100644
--- a/usr.sbin/vipw/vipw.c
+++ b/usr.sbin/vipw/vipw.c
@@ -1,4 +1,4 @@
-/* $NetBSD: vipw.c,v 1.3 1995/01/20 19:19:57 mycroft Exp $ */
+/* $NetBSD: vipw.c,v 1.4 1996/05/15 23:23:50 jtc Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
@@ -52,10 +52,8 @@ static char sccsid[] = "@(#)vipw.c 8.3 (Berkeley) 4/2/94";
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-
-#include "pw_util.h"
-
-char *tempname;
+#include <fcntl.h>
+#include <util.h>
void copyfile __P((int, int));
void usage __P((void));
@@ -83,22 +81,26 @@ main(argc, argv)
usage();
pw_init();
- pfd = pw_lock();
- tfd = pw_tmp();
+ tfd = pw_lock(0);
+ if (tfd < 0)
+ errx(1, "the passwd file is busy.");
+ pfd = open(_PATH_MASTERPASSWD, O_RDONLY, 0);
+ if (pfd < 0)
+ pw_error(_PATH_MASTERPASSWD, 1, 1);
copyfile(pfd, tfd);
(void)close(tfd);
for (;;) {
- if (stat(tempname, &begin))
- pw_error(tempname, 1, 1);
- pw_edit(0);
- if (stat(tempname, &end))
- pw_error(tempname, 1, 1);
+ if (stat(_PATH_MASTERPASSWD_LOCK, &begin))
+ pw_error(_PATH_MASTERPASSWD_LOCK, 1, 1);
+ pw_edit(0, NULL);
+ if (stat(_PATH_MASTERPASSWD_LOCK, &end))
+ pw_error(_PATH_MASTERPASSWD_LOCK, 1, 1);
if (begin.st_mtime == end.st_mtime) {
warnx("no changes made");
pw_error((char *)NULL, 0, 0);
}
- if (pw_mkdb())
+ if (pw_mkdb() == 0)
break;
pw_prompt();
}
@@ -115,7 +117,7 @@ copyfile(from, to)
while ((nr = read(from, buf, sizeof(buf))) > 0)
for (off = 0; off < nr; nr -= nw, off += nw)
if ((nw = write(to, buf + off, nr)) < 0)
- pw_error(tempname, 1, 1);
+ pw_error(_PATH_MASTERPASSWD_LOCK, 1, 1);
if (nr < 0)
pw_error(_PATH_MASTERPASSWD, 1, 1);
}