home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume6
/
shadow-2.pt3
/
utmp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-03
|
1KB
|
70 lines
#include <sys/types.h>
#include <utmp.h>
#include <string.h>
#include <stdio.h>
#include "config.h"
extern struct utmp utent;
extern char name[];
struct utmp *getutent ();
void setutent ();
void endutent ();
void pututline ();
char *memset ();
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);
(void) memset (utent.ut_line, '\0', sizeof utent.ut_line);
(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);
}
}