Date: Mon, 12 Apr 1999 01:08:10 GMT From: howardjp@wam.umd.edu To: FreeBSD-gnats-submit@freebsd.org Subject: bin/11094: lastlogin.8 from NetBSD Message-ID: <199904120108.BAA69009@byzantine.student.umd.edu>
next in thread | raw e-mail | index | archive | help
>Number: 11094 >Category: bin >Synopsis: lastlogin.8 from NetBSD >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Apr 11 22:00:00 PDT 1999 >Closed-Date: >Last-Modified: >Originator: James Howard >Release: FreeBSD 3.1-RELEASE i386 >Organization: University of Maryland >Environment: FreeBSD byzantine.student.umd.edu 3.1-RELEASE FreeBSD 3.1-RELEASE #0: Mon Feb 15 11:08:08 GMT 1999 jkh@usw3.freebsd.org:/usr/src/sys/compile/GENERIC i386 >Description: lastlogin.8 from NetBSD. It lists the last time a given user logged in, or if no user is given, lists last time each user logged in. Also similar to a program called laston that floats about the Internet sometimes. >How-To-Repeat: >Fix: Here is a shar file containing the code from the NetBSD source tree. The only change needed is a patch to the Makefile to handle the FreeBSD manpage style. # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # Makefile # lastlogin.8 # lastlogin.c # echo x - Makefile sed 's/^X//' >Makefile << 'END-of-Makefile' X# $NetBSD: Makefile,v 1.1.1.1 1997/02/11 18:36:51 phil Exp $ X XPROG= lastlogin XMAN8= lastlogin.8 X X.include <bsd.prog.mk> END-of-Makefile echo x - lastlogin.8 sed 's/^X//' >lastlogin.8 << 'END-of-lastlogin.8' X.\" $NetBSD: lastlogin.8,v 1.4 1999/03/22 18:43:58 garbled Exp $ X.\" X.\" Copyright (c) 1996 John M. Vinopal X.\" All rights reserved. X.\" X.\" Redistribution and use in source and binary forms, with or without X.\" modification, are permitted provided that the following conditions X.\" are met: X.\" 1. Redistributions of source code must retain the above copyright X.\" notice, this list of conditions and the following disclaimer. X.\" 2. Redistributions in binary form must reproduce the above copyright X.\" notice, this list of conditions and the following disclaimer in the X.\" documentation and/or other materials provided with the distribution. X.\" 3. All advertising materials mentioning features or use of this software X.\" must display the following acknowledgement: X.\" This product includes software developed for the NetBSD Project X.\" by John M. Vinopal. X.\" 4. The name of the author may not be used to endorse or promote products X.\" derived from this software without specific prior written permission. X.\" X.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR X.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES X.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. X.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, X.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, X.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; X.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED X.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, X.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X.\" SUCH DAMAGE. X.\" X.Dd January 11, 1996 X.Dt LASTLOGIN 8 X.Os X.Sh NAME X.Nm lastlogin X.Nd indicate last login time of users X.Sh SYNOPSIS X.Nm X.Op user ... X.Sh DESCRIPTION X.Nm Xwill list the last login session of specified X.Ar users , Xor for all users by default. Each line of output contains Xthe user name, the tty from which the session was conducted, any Xhostname, and the start time for the session. X.Pp XIf multiple X.Ar users Xare given, the session information for each user is printed in Xthe order given on the command line. Otherwise, information Xfor all users is printed, sorted by uid. X.Pp X.Nm Xdiffers from X.Xr last 1 Xin that it only prints information regarding the very last login session. XThe last login database is never turned over or deleted in standard usage. X.Sh FILES X.Bl -tag -width /var/log/lastlog -compact X.It Pa /var/log/lastlog Xlast login database X.El X.Sh SEE ALSO X.Xr last 1 , X.Xr lastlog 5 , X.Xr ac 8 X.Sh AUTHOR XJohn M. Vinopal wrote this program in January 1996 and contributed it Xto the X.Nx Xproject. END-of-lastlogin.8 echo x - lastlogin.c sed 's/^X//' >lastlogin.c << 'END-of-lastlogin.c' X/* $NetBSD: lastlogin.c,v 1.4 1998/02/03 04:45:35 perry Exp $ */ X/* X * Copyright (c) 1996 John M. Vinopal X * All rights reserved. X * X * Redistribution and use in source and binary forms, with or without X * modification, are permitted provided that the following conditions X * are met: X * 1. Redistributions of source code must retain the above copyright X * notice, this list of conditions and the following disclaimer. X * 2. Redistributions in binary form must reproduce the above copyright X * notice, this list of conditions and the following disclaimer in the X * documentation and/or other materials provided with the distribution. X * 3. All advertising materials mentioning features or use of this software X * must display the following acknowledgement: X * This product includes software developed for the NetBSD Project X * by John M. Vinopal. X * 4. The name of the author may not be used to endorse or promote products X * derived from this software without specific prior written permission. X * X * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR X * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES X * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. X * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, X * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, X * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; X * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED X * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, X * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X */ X X#include <sys/cdefs.h> X#ifndef lint X__RCSID("$NetBSD: lastlogin.c,v 1.4 1998/02/03 04:45:35 perry Exp $"); X#endif X X#include <sys/types.h> X#include <err.h> X#include <errno.h> X#include <pwd.h> X#include <stdio.h> X#include <time.h> X#include <utmp.h> X#include <unistd.h> X Xextern char *__progname; Xstatic char *logfile = _PATH_LASTLOG; X X int main __P((int, char **)); Xstatic void output __P((struct passwd *, struct lastlog *)); Xstatic void usage __P((void)); X Xint Xmain(argc, argv) X int argc; X char *argv[]; X{ X int ch, i; X FILE *fp; X struct passwd *passwd; X struct lastlog last; X X while ((ch = getopt(argc, argv, "")) != -1) { X usage(); X } X X fp = fopen(logfile, "r"); X if (fp == NULL) X err(1, "%s", logfile); X X setpassent(1); /* Keep passwd file pointers open */ X X /* Process usernames given on the command line. */ X if (argc > 1) { X long offset; X for (i = 1; i < argc; ++i) { X if ((passwd = getpwnam(argv[i])) == NULL) { X warnx("user '%s' not found", argv[i]); X continue; X } X /* Calculate the offset into the lastlog file. */ X offset = (long)(passwd->pw_uid * sizeof(last)); X if (fseek(fp, offset, SEEK_SET)) { X warn("fseek error"); X continue; X } X if (fread(&last, sizeof(last), 1, fp) != 1) { X warnx("fread error on '%s'", passwd->pw_name); X clearerr(fp); X continue; X } X output(passwd, &last); X } X } X /* Read all lastlog entries, looking for active ones */ X else { X for (i = 0; fread(&last, sizeof(last), 1, fp) == 1; i++) { X if (last.ll_time == 0) X continue; X if ((passwd = getpwuid(i)) != NULL) X output(passwd, &last); X } X if (ferror(fp)) X warnx("fread error"); X } X X setpassent(0); /* Close passwd file pointers */ X X fclose(fp); X exit(0); X} X X/* Duplicate the output of last(1) */ Xstatic void Xoutput(p, l) X struct passwd *p; X struct lastlog *l; X{ X printf("%-*.*s %-*.*s %-*.*s %s", X UT_NAMESIZE, UT_NAMESIZE, p->pw_name, X UT_LINESIZE, UT_LINESIZE, l->ll_line, X UT_HOSTSIZE, UT_HOSTSIZE, l->ll_host, X (l->ll_time) ? ctime(&(l->ll_time)) : "Never logged in\n"); X} X Xstatic void Xusage() X{ X fprintf(stderr, "usage: %s [user ...]\n", __progname); X exit(1); X} END-of-lastlogin.c exit >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199904120108.BAA69009>