xref: /titanic_54/usr/src/cmd/acct/wtmpfix.c (revision 414388d7cb2ee98771e2ac7c2338c460abd44304)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate 
237c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
247c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
257c478bd9Sstevel@tonic-gate 
26*414388d7Ssl108498 /*
27*414388d7Ssl108498  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
28*414388d7Ssl108498  * Use is subject to license terms.
29*414388d7Ssl108498  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * wtmpfix - adjust wtmpx file and remove date changes.
347c478bd9Sstevel@tonic-gate  *	wtmpfix <wtmpx1 >wtmpx2
357c478bd9Sstevel@tonic-gate  *
367c478bd9Sstevel@tonic-gate  *	code are added to really fix wtmpx if it is corrupted ..
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <stdio.h>
407c478bd9Sstevel@tonic-gate #include <sys/types.h>
417c478bd9Sstevel@tonic-gate #include <sys/param.h>
427c478bd9Sstevel@tonic-gate #include "acctdef.h"
437c478bd9Sstevel@tonic-gate #include <utmpx.h>
447c478bd9Sstevel@tonic-gate #include <signal.h>
457c478bd9Sstevel@tonic-gate #include <time.h>
467c478bd9Sstevel@tonic-gate #include <ctype.h>
477c478bd9Sstevel@tonic-gate #include <locale.h>
487c478bd9Sstevel@tonic-gate #include <limits.h>
497c478bd9Sstevel@tonic-gate #include <stdlib.h>
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #define	MAXRUNTIME	3600	/* time out after 1 hour */
527c478bd9Sstevel@tonic-gate #define	DAYEPOCH	(60 * 60 * 24)
537c478bd9Sstevel@tonic-gate #define	wout(f, w)	 fwrite(w, sizeof (struct utmpx), 1, f);
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate FILE	*Wtmpx, *Opw;
567c478bd9Sstevel@tonic-gate FILE	*fp;
577c478bd9Sstevel@tonic-gate char	Ofile[]	= "/tmp/wXXXXXX";
587c478bd9Sstevel@tonic-gate static char time_buf[50];
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate struct	dtab
617c478bd9Sstevel@tonic-gate {
627c478bd9Sstevel@tonic-gate 	off_t	d_off1;		/* file offset start */
637c478bd9Sstevel@tonic-gate 	off_t	d_off2;		/* file offset stop */
647c478bd9Sstevel@tonic-gate 	time_t	d_adj;		/* time adjustment */
657c478bd9Sstevel@tonic-gate 	struct dtab *d_ndp;	/* next record */
667c478bd9Sstevel@tonic-gate };
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate struct	dtab	*Fdp;		/* list header */
697c478bd9Sstevel@tonic-gate struct	dtab	*Ldp;		/* list trailer */
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate time_t 	lastmonth, nextmonth;
727c478bd9Sstevel@tonic-gate off_t	recno;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate struct	utmpx	Ut, Ut2;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate int	year, month;
777c478bd9Sstevel@tonic-gate int 	ch;
787c478bd9Sstevel@tonic-gate int	n;
797c478bd9Sstevel@tonic-gate int	multimode;		/* multi user mode	 WHCC */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate static int winp(FILE *, struct utmpx *);
827c478bd9Sstevel@tonic-gate static void mkdtab(off_t);
837c478bd9Sstevel@tonic-gate static void setdtab(off_t, struct utmpx *, struct utmpx *);
847c478bd9Sstevel@tonic-gate static void adjust(off_t, struct utmpx *);
857c478bd9Sstevel@tonic-gate static int invalid(char *);
86*414388d7Ssl108498 static void intr(int) __NORETURN;
877c478bd9Sstevel@tonic-gate static void scanfile(void);
887c478bd9Sstevel@tonic-gate static int inrange(void);
897c478bd9Sstevel@tonic-gate static void wabort(int);
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate int
927c478bd9Sstevel@tonic-gate main(int argc, char **argv)
937c478bd9Sstevel@tonic-gate {
947c478bd9Sstevel@tonic-gate 	time_t tloc;
957c478bd9Sstevel@tonic-gate 	struct tm *tmp;
967c478bd9Sstevel@tonic-gate 	int fd;
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
997c478bd9Sstevel@tonic-gate 	setbuf(stdout, NULL);
1007c478bd9Sstevel@tonic-gate 	alarm(MAXRUNTIME);
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	if (signal(SIGALRM, wabort) == SIG_ERR) {
1037c478bd9Sstevel@tonic-gate 		perror("signal");
1047c478bd9Sstevel@tonic-gate 		return (1);
1057c478bd9Sstevel@tonic-gate 	}
1067c478bd9Sstevel@tonic-gate 	if (signal(SIGINT, intr) == SIG_ERR) {
1077c478bd9Sstevel@tonic-gate 		perror("signal");
1087c478bd9Sstevel@tonic-gate 		return (1);
1097c478bd9Sstevel@tonic-gate 	}
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 	time(&tloc);
1127c478bd9Sstevel@tonic-gate 	tmp = localtime(&tloc);
1137c478bd9Sstevel@tonic-gate 	year = tmp->tm_year;
1147c478bd9Sstevel@tonic-gate 	month = tmp->tm_mon + 1;
1157c478bd9Sstevel@tonic-gate 	lastmonth = ((year + 1900 - 1970) * 365 +
1167c478bd9Sstevel@tonic-gate 	    (month - 1) * 30) * DAYEPOCH;
1177c478bd9Sstevel@tonic-gate 	nextmonth = ((year + 1900 - 1970) * 365 +
1187c478bd9Sstevel@tonic-gate 	    (month + 1) * 30) * DAYEPOCH;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	if (argc < 2) {
1217c478bd9Sstevel@tonic-gate 		argv[argc] = "-";
1227c478bd9Sstevel@tonic-gate 		argc++;
1237c478bd9Sstevel@tonic-gate 	}
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	if ((fd = mkstemp(Ofile)) == -1) {
1267c478bd9Sstevel@tonic-gate 		fprintf(stderr, "cannot make temporary: %s\n", Ofile);
1277c478bd9Sstevel@tonic-gate 		intr(0);
1287c478bd9Sstevel@tonic-gate 	}
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	if ((Opw = fdopen(fd, "w")) == NULL) {
1317c478bd9Sstevel@tonic-gate 		fprintf(stderr, "cannot open temporary: %s\n", Ofile);
1327c478bd9Sstevel@tonic-gate 		intr(0);
1337c478bd9Sstevel@tonic-gate 	}
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	while (--argc > 0) {
1367c478bd9Sstevel@tonic-gate 		argv++;
1377c478bd9Sstevel@tonic-gate 		if (strcmp(*argv, "-") == 0)
1387c478bd9Sstevel@tonic-gate 			Wtmpx = stdin;
1397c478bd9Sstevel@tonic-gate 		else if ((Wtmpx = fopen(*argv, "r")) == NULL) {
1407c478bd9Sstevel@tonic-gate 			fprintf(stderr, "Cannot open: %s\n", *argv);
1417c478bd9Sstevel@tonic-gate 			intr(0);
1427c478bd9Sstevel@tonic-gate 		}
1437c478bd9Sstevel@tonic-gate 		scanfile();
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 		if (Wtmpx != stdin)
1467c478bd9Sstevel@tonic-gate 			fclose(Wtmpx);
1477c478bd9Sstevel@tonic-gate 	}
1487c478bd9Sstevel@tonic-gate 	fclose(Opw);
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	if ((Opw = fopen(Ofile, "r")) == NULL) {
1517c478bd9Sstevel@tonic-gate 		fprintf(stderr, "Cannot read from temp: %s\n", Ofile);
1527c478bd9Sstevel@tonic-gate 		intr(0);
1537c478bd9Sstevel@tonic-gate 	}
1547c478bd9Sstevel@tonic-gate 	recno = 0;
1557c478bd9Sstevel@tonic-gate 	while (winp(Opw, &Ut)) {
1567c478bd9Sstevel@tonic-gate 		adjust(recno, &Ut);
1577c478bd9Sstevel@tonic-gate 		recno += sizeof (struct utmpx);
1587c478bd9Sstevel@tonic-gate 		wout(stdout, &Ut);
1597c478bd9Sstevel@tonic-gate 	}
1607c478bd9Sstevel@tonic-gate 	fclose(Opw);
1617c478bd9Sstevel@tonic-gate 	unlink(Ofile);
1627c478bd9Sstevel@tonic-gate 	return (0);
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate static int
1667c478bd9Sstevel@tonic-gate winp(FILE *f, struct utmpx *w)
1677c478bd9Sstevel@tonic-gate {
1687c478bd9Sstevel@tonic-gate 	if (fread(w, sizeof (struct utmpx), 1, f) != 1)
1697c478bd9Sstevel@tonic-gate 		return (0);
1707c478bd9Sstevel@tonic-gate 	if ((w->ut_type >= EMPTY) && (w->ut_type <= UTMAXTYPE))
1717c478bd9Sstevel@tonic-gate 		return (1);
1727c478bd9Sstevel@tonic-gate 	else {
1737c478bd9Sstevel@tonic-gate 		fprintf(stderr, "Bad file at offset %ld\n",
1747c478bd9Sstevel@tonic-gate 			ftell(f) - sizeof (struct utmpx));
1757c478bd9Sstevel@tonic-gate 		cftime(time_buf, DATE_FMT, &w->ut_xtime);
1767c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%-12s %-8s %lu %s",
1777c478bd9Sstevel@tonic-gate 			w->ut_line, w->ut_user, w->ut_xtime, time_buf);
1787c478bd9Sstevel@tonic-gate 		intr(0);
1797c478bd9Sstevel@tonic-gate 	}
1807c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate static void
1847c478bd9Sstevel@tonic-gate mkdtab(off_t p)
1857c478bd9Sstevel@tonic-gate {
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 	struct dtab *dp;
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	dp = Ldp;
1907c478bd9Sstevel@tonic-gate 	if (dp == NULL) {
1917c478bd9Sstevel@tonic-gate 		dp = calloc(sizeof (struct dtab), 1);
1927c478bd9Sstevel@tonic-gate 		if (dp == NULL) {
1937c478bd9Sstevel@tonic-gate 			fprintf(stderr, "out of core\n");
1947c478bd9Sstevel@tonic-gate 			intr(0);
1957c478bd9Sstevel@tonic-gate 		}
1967c478bd9Sstevel@tonic-gate 		Fdp = Ldp = dp;
1977c478bd9Sstevel@tonic-gate 	}
1987c478bd9Sstevel@tonic-gate 	dp->d_off1 = p;
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate static void
2027c478bd9Sstevel@tonic-gate setdtab(off_t p, struct utmpx *w1, struct utmpx *w2)
2037c478bd9Sstevel@tonic-gate {
2047c478bd9Sstevel@tonic-gate 	struct dtab *dp;
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	if ((dp = Ldp) == NULL) {
2077c478bd9Sstevel@tonic-gate 		fprintf(stderr, "no dtab\n");
2087c478bd9Sstevel@tonic-gate 		intr(0);
2097c478bd9Sstevel@tonic-gate 	}
2107c478bd9Sstevel@tonic-gate 	dp->d_off2 = p;
2117c478bd9Sstevel@tonic-gate 	dp->d_adj = w2->ut_xtime - w1->ut_xtime;
2127c478bd9Sstevel@tonic-gate 	if ((Ldp = calloc(sizeof (struct dtab), 1)) == NULL) {
2137c478bd9Sstevel@tonic-gate 		fprintf(stderr, "out of core\n");
2147c478bd9Sstevel@tonic-gate 		intr(0);
2157c478bd9Sstevel@tonic-gate 	}
2167c478bd9Sstevel@tonic-gate 	Ldp->d_off1 = dp->d_off1;
2177c478bd9Sstevel@tonic-gate 	dp->d_ndp = Ldp;
2187c478bd9Sstevel@tonic-gate }
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate static void
2217c478bd9Sstevel@tonic-gate adjust(off_t p, struct utmpx *w)
2227c478bd9Sstevel@tonic-gate {
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 	off_t pp;
2257c478bd9Sstevel@tonic-gate 	struct dtab *dp;
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	pp = p;
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	for (dp = Fdp; dp != NULL; dp = dp->d_ndp) {
2307c478bd9Sstevel@tonic-gate 		if (dp->d_adj == 0)
2317c478bd9Sstevel@tonic-gate 			continue;
2327c478bd9Sstevel@tonic-gate 		if (pp >= dp->d_off1 && pp < dp->d_off2)
2337c478bd9Sstevel@tonic-gate 			w->ut_xtime += dp->d_adj;
2347c478bd9Sstevel@tonic-gate 	}
2357c478bd9Sstevel@tonic-gate }
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate /*
2387c478bd9Sstevel@tonic-gate  *	invalid() determines whether the name field adheres to
2397c478bd9Sstevel@tonic-gate  *	the criteria set forth in acctcon1.  If the name violates
2407c478bd9Sstevel@tonic-gate  *	conventions, it returns a truth value meaning the name is
2417c478bd9Sstevel@tonic-gate  *	invalid; if the name is okay, it returns false indicating
2427c478bd9Sstevel@tonic-gate  *	the name is not invalid.
2437c478bd9Sstevel@tonic-gate  */
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate static int
2467c478bd9Sstevel@tonic-gate invalid(char *name)
2477c478bd9Sstevel@tonic-gate {
2487c478bd9Sstevel@tonic-gate 	int	i;
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate 	for (i = 0; i < NSZ; i++) {
2517c478bd9Sstevel@tonic-gate 		if (name[i] == '\0')
2527c478bd9Sstevel@tonic-gate 			return (VALID);
2537c478bd9Sstevel@tonic-gate 		if (! (isalnum(name[i]) || (name[i] == '$') ||
2547c478bd9Sstevel@tonic-gate 		    (name[i] == ' ') || (name[i] == '.') ||
2557c478bd9Sstevel@tonic-gate 		    (name[i] == '_') || (name[i] == '-'))) {
2567c478bd9Sstevel@tonic-gate 			return (INVALID);
2577c478bd9Sstevel@tonic-gate 		}
2587c478bd9Sstevel@tonic-gate 	}
2597c478bd9Sstevel@tonic-gate 	return (VALID);
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate static void
2637c478bd9Sstevel@tonic-gate intr(int sig)
2647c478bd9Sstevel@tonic-gate {
2657c478bd9Sstevel@tonic-gate 	signal(SIGINT, SIG_IGN);
2667c478bd9Sstevel@tonic-gate 	unlink(Ofile);
2677c478bd9Sstevel@tonic-gate 	exit(1);
2687c478bd9Sstevel@tonic-gate }
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate /*
2717c478bd9Sstevel@tonic-gate  * scanfile:
2727c478bd9Sstevel@tonic-gate  * 1)  	reads the file, to see if the record is within reasonable
2737c478bd9Sstevel@tonic-gate  * 	range; if not, then it will scan the file, delete foreign stuff.
2747c478bd9Sstevel@tonic-gate  * 2)   enter setdtab if in multiuser mode
2757c478bd9Sstevel@tonic-gate  * 3)   change bad login names to INVALID
2767c478bd9Sstevel@tonic-gate  */
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate static void
2797c478bd9Sstevel@tonic-gate scanfile()
2807c478bd9Sstevel@tonic-gate {
2817c478bd9Sstevel@tonic-gate 	while ((n = fread(&Ut, sizeof (Ut), 1, Wtmpx)) > 0) {
2827c478bd9Sstevel@tonic-gate 		if (n == 0) {
2837c478bd9Sstevel@tonic-gate 			unlink(Ofile);
2847c478bd9Sstevel@tonic-gate 			exit(0);
2857c478bd9Sstevel@tonic-gate 		}
2867c478bd9Sstevel@tonic-gate 		if (!inrange()) {
2877c478bd9Sstevel@tonic-gate 			for (;;) {
2887c478bd9Sstevel@tonic-gate 				if (fseek(Wtmpx,
2897c478bd9Sstevel@tonic-gate 				    -(off_t)sizeof (Ut), 1) != 0) {
2907c478bd9Sstevel@tonic-gate 					perror("seek error\n");
2917c478bd9Sstevel@tonic-gate 					exit(1);
2927c478bd9Sstevel@tonic-gate 				}
2937c478bd9Sstevel@tonic-gate 				if ((ch = getc(Wtmpx)) == EOF) {
2947c478bd9Sstevel@tonic-gate 					perror("read\n");
2957c478bd9Sstevel@tonic-gate 					exit(1);
2967c478bd9Sstevel@tonic-gate 				}
2977c478bd9Sstevel@tonic-gate 				fprintf(stderr, "checking offset %lo\n",
2987c478bd9Sstevel@tonic-gate 				    ftell(Wtmpx));
2997c478bd9Sstevel@tonic-gate 				if (fread(&Ut, sizeof (Ut), 1, Wtmpx) == 0) {
3007c478bd9Sstevel@tonic-gate 					exit(1);
3017c478bd9Sstevel@tonic-gate 				}
3027c478bd9Sstevel@tonic-gate 				if (inrange())
3037c478bd9Sstevel@tonic-gate 					break;
3047c478bd9Sstevel@tonic-gate 			}
3057c478bd9Sstevel@tonic-gate 		}
3067c478bd9Sstevel@tonic-gate 		/* Now we have a good utmpx record, do more processing */
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate #define	UTYPE	Ut.ut_type
3097c478bd9Sstevel@tonic-gate #define	ULINE	Ut.ut_line
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 			if (recno == 0 || UTYPE == BOOT_TIME)
3127c478bd9Sstevel@tonic-gate 				mkdtab(recno);
3137c478bd9Sstevel@tonic-gate 			if (UTYPE == RUN_LVL) {
3147c478bd9Sstevel@tonic-gate 				if (strncmp(ULINE, "run-level S", 11) == 0)
3157c478bd9Sstevel@tonic-gate 					multimode = 0;
3167c478bd9Sstevel@tonic-gate 				if (strncmp(ULINE, "run-level 2", 11) == 0)
3177c478bd9Sstevel@tonic-gate 					multimode++;
3187c478bd9Sstevel@tonic-gate 			}
3197c478bd9Sstevel@tonic-gate 			if (invalid(Ut.ut_name)) {
3207c478bd9Sstevel@tonic-gate 				fprintf(stderr,
3217c478bd9Sstevel@tonic-gate 				    "wtmpfix: logname \"%*.*s\" changed "
3227c478bd9Sstevel@tonic-gate 				    "to \"INVALID\"\n", OUTPUT_NSZ,
3237c478bd9Sstevel@tonic-gate 				    OUTPUT_NSZ, Ut.ut_name);
3247c478bd9Sstevel@tonic-gate 				(void) strncpy(Ut.ut_name, "INVALID", NSZ);
3257c478bd9Sstevel@tonic-gate 			}
3267c478bd9Sstevel@tonic-gate 			if (UTYPE == OLD_TIME) {
3277c478bd9Sstevel@tonic-gate 				if (!winp(Wtmpx, &Ut2)) {
3287c478bd9Sstevel@tonic-gate 					fprintf(stderr, "Input truncated at "
3297c478bd9Sstevel@tonic-gate 					    "offset %ld\n", recno);
3307c478bd9Sstevel@tonic-gate 					intr(0);
3317c478bd9Sstevel@tonic-gate 				}
3327c478bd9Sstevel@tonic-gate 				if (Ut2.ut_type != NEW_TIME) {
3337c478bd9Sstevel@tonic-gate 					fprintf(stderr, "New date expected at "
3347c478bd9Sstevel@tonic-gate 					    "offset %ld", recno);
3357c478bd9Sstevel@tonic-gate 					intr(0);
3367c478bd9Sstevel@tonic-gate 				}
3377c478bd9Sstevel@tonic-gate 				if (multimode)  /* multiuser */
3387c478bd9Sstevel@tonic-gate 					setdtab(recno, &Ut, &Ut2);
3397c478bd9Sstevel@tonic-gate 				recno += (2 * sizeof (struct utmpx));
3407c478bd9Sstevel@tonic-gate 				wout(Opw, &Ut);
3417c478bd9Sstevel@tonic-gate 				wout(Opw, &Ut2);
3427c478bd9Sstevel@tonic-gate 				continue;
3437c478bd9Sstevel@tonic-gate 			}
3447c478bd9Sstevel@tonic-gate 			wout(Opw, &Ut);
3457c478bd9Sstevel@tonic-gate 			recno += sizeof (struct utmpx);
3467c478bd9Sstevel@tonic-gate 	}
3477c478bd9Sstevel@tonic-gate }
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate static int
3507c478bd9Sstevel@tonic-gate inrange()
3517c478bd9Sstevel@tonic-gate {
3527c478bd9Sstevel@tonic-gate 	if ((strcmp(Ut.ut_line, RUNLVL_MSG) == 0) ||
3537c478bd9Sstevel@tonic-gate 	    (strcmp(Ut.ut_line, BOOT_MSG) == 0) ||
3547c478bd9Sstevel@tonic-gate 	    (strcmp(Ut.ut_line, "acctg on") == 0) ||
3557c478bd9Sstevel@tonic-gate 	    (strcmp(Ut.ut_line, OTIME_MSG) == 0) ||
3567c478bd9Sstevel@tonic-gate 	    (strcmp(Ut.ut_line, NTIME_MSG) == 0))
3577c478bd9Sstevel@tonic-gate 			return (1);
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 	if (Ut.ut_id != 0 &&
3607c478bd9Sstevel@tonic-gate 		Ut.ut_xtime > 0 &&
3617c478bd9Sstevel@tonic-gate 		Ut.ut_xtime > lastmonth &&
3627c478bd9Sstevel@tonic-gate 		Ut.ut_xtime < nextmonth &&
3637c478bd9Sstevel@tonic-gate 		Ut.ut_type >= EMPTY &&
3647c478bd9Sstevel@tonic-gate 		Ut.ut_type <= UTMAXTYPE &&
3657c478bd9Sstevel@tonic-gate 		Ut.ut_pid >= 0)
3667c478bd9Sstevel@tonic-gate 		return (1);
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate 	return (0);
3697c478bd9Sstevel@tonic-gate }
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate static void
3727c478bd9Sstevel@tonic-gate wabort(int sig)
3737c478bd9Sstevel@tonic-gate {
3747c478bd9Sstevel@tonic-gate 	fprintf(stderr, "give up\n");
3757c478bd9Sstevel@tonic-gate 	exit(1);
3767c478bd9Sstevel@tonic-gate }
377