home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1989, 1990, John F. Haugh II
- * All rights reserved.
- *
- * Use, duplication, and disclosure prohibited without
- * the express written permission of the author.
- */
-
- #include <sys/types.h>
- #include <utmp.h>
- #ifndef BSD
- #include <string.h>
- #include <memory.h>
- #else
- #include <strings.h>
- #define strchr index
- #define strrchr rindex
- #endif
- #include <stdio.h>
- #include "config.h"
-
- #ifndef lint
- static char sccsid[] = "@(#)utmp.c 2.3 19:24:26 7/29/90";
- #endif
-
- extern struct utmp utent;
- extern char name[];
-
- struct utmp *getutent ();
- void setutent ();
- void endutent ();
- void pututline ();
- time_t time ();
-
- void checkutmp ()
- {
- struct utmp *ut;
- #ifndef NDEBUG
- int pid = getppid ();
- #else
- int pid = getpid ();
- #endif
- setutent ();
-
- while (ut = getutent ())
- if (ut->ut_pid == pid)
- break;
-
- if (ut)
- utent = *ut;
-
- endutent ();
-
- if (ut && utent.ut_pid == pid)
- return;
-
- puts ("No utmp entry. You must exec \"login\" from the lowest level \"sh\"");
- exit (1);
- }
-
- void setutmp ()
- {
- FILE *wtmp;
- char tty[sizeof utent.ut_line + 1];
- char *line;
-
- setutent ();
-
- (void) strncpy (utent.ut_user, name, sizeof utent.ut_user);
-
- utent.ut_type = USER_PROCESS;
-
- if (line = strrchr (utent.ut_line, '/')) {
- (void) strcpy (tty, line + 1);
- #ifndef BSD
- (void) memset (utent.ut_line, '\0', sizeof utent.ut_line);
- #else
- bzero (utent.ut_line, sizeof utent.ut_line);
- #endif
- (void) strcpy (utent.ut_line, tty);
- }
- (void) time (&utent.ut_time);
-
- pututline (&utent);
- endutent ();
-
- if ((wtmp = fopen (WTMP_FILE, "a+"))) {
- fwrite (&utent, sizeof utent, 1, wtmp);
- fclose (wtmp);
- }
- }
-