From: Ken Raeburn Date: Wed, 17 Apr 1996 02:11:22 +0000 (+0000) Subject: * dump-utmp.c: New file. Not automatically used by anything, but may be useful X-Git-Tag: krb5-1.0-beta6~199 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=703bcf4fcbde6c736551c61ce97287b264d0b1de;p=krb5.git * dump-utmp.c: New file. Not automatically used by anything, but may be useful for examining utmp/wtmp files when comparing behavior against system software. * update_utmp.c (pty_update_utmp): Always use id "cons" for console. For HP-UX, omit "kl" prefix. Reindent for readability. * update_wtmp.c (ptyint_update_wtmp): For HP-UX, copy ut_id and ut_type from input utmp structure. Reindent for readability. Wed Mar 27 21:14:33 1996 Marc Horowitz * init_slave.c (pty_initialize_slave): Spurious signal stuff which did nothing deleted. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@7819 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/util/pty/ChangeLog b/src/util/pty/ChangeLog index 0d40025ad..108075430 100644 --- a/src/util/pty/ChangeLog +++ b/src/util/pty/ChangeLog @@ -1,3 +1,21 @@ +Tue Apr 16 22:06:36 1996 Ken Raeburn + + * dump-utmp.c: New file. Not automatically used by anything, but + may be useful for examining utmp/wtmp files when comparing + behavior against system software. + + Sun Mar 31 02:04:28 1996 Ken Raeburn + + * update_utmp.c (pty_update_utmp): Always use id "cons" for + console. For HP-UX, omit "kl" prefix. Reindent for readability. + * update_wtmp.c (ptyint_update_wtmp): For HP-UX, copy ut_id and + ut_type from input utmp structure. Reindent for readability. + + Wed Mar 27 21:14:33 1996 Marc Horowitz + + * init_slave.c (pty_initialize_slave): Spurious signal stuff + which did nothing deleted. + Tue Apr 16 13:43:43 1996 Sam Hartman * configure.in : Don't use streams on HPUX. diff --git a/src/util/pty/dump-utmp.c b/src/util/pty/dump-utmp.c new file mode 100644 index 000000000..b349b9afe --- /dev/null +++ b/src/util/pty/dump-utmp.c @@ -0,0 +1,102 @@ +#include +#include +#include + +#ifdef UTMPX +#include +#endif +#include + +char *ut_typename (t) { + switch (t) { +#define S(N) case N : return #N + S(EMPTY); + S(RUN_LVL); + S(BOOT_TIME); + S(OLD_TIME); + S(NEW_TIME); + S(INIT_PROCESS); + S(LOGIN_PROCESS); + S(USER_PROCESS); + S(DEAD_PROCESS); + S(ACCOUNTING); + default: return "??"; + } +} + +int main (argc, argv) int argc; char *argv[]; { + int f; + char id[5], user[50]; + char *file = 0; + int all = 0; + + while (*++argv) + { + char *arg = *argv; + if (!arg) + break; + if (!strcmp ("-a", arg)) + all = 1; + else if (file) + { + fprintf (stderr, "already got a file\n"); + return 1; + } + else + file = arg; + } + f = open (file, O_RDONLY); + if (f < 0) { + perror (file); + exit (1); + } + id[4] = 0; +#ifdef UTMPX + if ('x' != file[strlen(file) - 1]) { + struct utmpx u; + while (read (f, &u, sizeof (u)) == sizeof (u)) { + char c; + if ((u.ut_type == DEAD_PROCESS + || u.ut_type == EMPTY) + && !all) + continue; + strncpy (id, u.ut_id, 4); + printf ("%-8s:%-12s:%-4s:%6d %s", + u.ut_user, u.ut_line, id, + u.ut_pid, ut_typename (u.ut_type)); + /* ctime (&u.ut_xtime) + 4 */ + if (u.ut_syslen && u.ut_host[0]) + printf (" %s", u.ut_host); + printf ("\n"); + return 0; + } + } + /* else */ +#endif + { + struct utmp u; + user[sizeof(u.ut_user)] = 0; + while (read (f, &u, sizeof (u)) == sizeof (u)) { + char c; + if ((u.ut_type == DEAD_PROCESS + || u.ut_type == EMPTY) + && !all) + continue; + strncpy (id, u.ut_id, 4); + strncpy (user, u.ut_user, sizeof (u.ut_user)); + printf ("%-8s:%-12s:%-4s:%6d %s", user, u.ut_line, id, + u.ut_pid, ut_typename (u.ut_type)); + printf ("\n"); +#if 0 + printf ("user: %-32s id: %s\n", user, id); + printf (" line: %-32s pid:%-6d type: %s\n", + u.ut_line, u.ut_pid, ut_typename (u.ut_type)); + printf (" exit_status: %d,%d\n", + u.ut_exit.e_termination, u.ut_exit.e_exit); + printf (" time: %s\n", ctime (&u.ut_time) + 4); +#endif + } + } + + return 0; +} diff --git a/src/util/pty/init_slave.c b/src/util/pty/init_slave.c index 10f0efb31..09efc8d9a 100644 --- a/src/util/pty/init_slave.c +++ b/src/util/pty/init_slave.c @@ -49,13 +49,6 @@ long pty_initialize_slave (fd) struct sgttyb b; #endif /* POSIX_TERMIOS */ int pid; -#ifdef POSIX_SIGNALS - struct sigaction sa; - /* Initialize "sa" structure. */ - (void) sigemptyset(&sa.sa_mask); - sa.sa_flags = 0; - -#endif #ifdef HAVE_STREAMS #ifdef HAVE_LINE_PUSH diff --git a/src/util/pty/update_utmp.c b/src/util/pty/update_utmp.c index fa2f5099e..039cf6860 100644 --- a/src/util/pty/update_utmp.c +++ b/src/util/pty/update_utmp.c @@ -80,10 +80,18 @@ long pty_update_utmp (process_type, pid, username, line, host, flags) #endif #ifndef NO_UT_PID - tmpx = line + strlen(line)-1; - if (*(tmpx-1) != '/') tmpx--; /* last two characters, unless it's a / */ - sprintf(utmp_id, "kl%s", tmpx); - strncpy(ent.ut_id, utmp_id, sizeof(ent.ut_id)); + if (!strcmp (line, "/dev/console")) + strncpy (ent.ut_id, "cons", 4); + else { + tmpx = line + strlen(line)-1; + if (*(tmpx-1) != '/') tmpx--; /* last two characters, unless it's a / */ +#ifdef __hpux + strcpy(utmp_id, tmpx); +#else + sprintf(utmp_id, "kl%s", tmpx); +#endif + strncpy(ent.ut_id, utmp_id, sizeof(ent.ut_id)); + } strncpy(ent.ut_user, username, sizeof(ent.ut_user)); #else strncpy(ent.ut_name, username, sizeof(ent.ut_name)); @@ -105,23 +113,24 @@ long pty_update_utmp (process_type, pid, username, line, host, flags) if (( !username[0]) && (flags&PTY_UTMP_USERNAME_VALID) &&line) { -struct utmp *utptr; -strncpy(ut.ut_line, line, sizeof(ut.ut_line)); -utptr = getutline(&ut); -if (utptr) - strncpy(userbuf,utptr->ut_user,sizeof(ut.ut_user)); + struct utmp *utptr; + strncpy(ut.ut_line, line, sizeof(ut.ut_line)); + utptr = getutline(&ut); + if (utptr) + strncpy(userbuf,utptr->ut_user,sizeof(ut.ut_user)); } #endif - + pututline(&ent); endutent(); #ifdef HAVE_SETUTXENT setutxent(); getutmpx(&ent, &utx); -if (host) - strncpy(utx.ut_host, host, sizeof(utx.ut_host)); - else utx.ut_host[0] = 0; + if (host) + strncpy(utx.ut_host, host, sizeof(utx.ut_host)); + else + utx.ut_host[0] = 0; pututxline(&utx); endutxent(); #endif /* HAVE_SETUTXENT */ @@ -130,34 +139,34 @@ if (host) if (flags&PTY_TTYSLOT_USABLE) tty = ttyslot(); else { - int lc; - tty = -1; - if ((fd = open(UTMP_FILE, O_RDWR)) < 0) - return errno; - for (lc = 0; - lseek(fd, (off_t)(lc * sizeof(struct utmp)), SEEK_SET) != -1; - lc++) { - if (read(fd, (char *) &ut, sizeof(struct utmp)) != sizeof(struct utmp)) - break; - if (strncmp(ut.ut_line, ent.ut_line, sizeof(ut.ut_line)) == 0) { - tty = lc; + int lc; + tty = -1; + if ((fd = open(UTMP_FILE, O_RDWR)) < 0) + return errno; + for (lc = 0; + lseek(fd, (off_t)(lc * sizeof(struct utmp)), SEEK_SET) != -1; + lc++) { + if (read(fd, (char *) &ut, sizeof(struct utmp)) != sizeof(struct utmp)) + break; + if (strncmp(ut.ut_line, ent.ut_line, sizeof(ut.ut_line)) == 0) { + tty = lc; #ifdef WTMP_REQUIRES_USERNAME - if (!username&&(flags&PTY_UTMP_USERNAME_VALID)) - strncpy(userbuf, ut.ut_user, sizeof(ut.ut_user)); + if (!username&&(flags&PTY_UTMP_USERNAME_VALID)) + strncpy(userbuf, ut.ut_user, sizeof(ut.ut_user)); #endif - break; - } + break; } -close(fd); + } + close(fd); } - if (tty > 0 && (fd = open(UTMP_FILE, O_WRONLY, 0)) >= 0) { - (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET); - (void)write(fd, (char *)&ent, sizeof(struct utmp)); - (void)close(fd); + if (tty > 0 && (fd = open(UTMP_FILE, O_WRONLY, 0)) >= 0) { + (void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET); + (void)write(fd, (char *)&ent, sizeof(struct utmp)); + (void)close(fd); } - + #endif /* HAVE_SETUTENT */ return ptyint_update_wtmp(&ent, host, userbuf); diff --git a/src/util/pty/update_wtmp.c b/src/util/pty/update_wtmp.c index 0bda4dbac..8017b1100 100644 --- a/src/util/pty/update_wtmp.c +++ b/src/util/pty/update_wtmp.c @@ -34,9 +34,9 @@ long ptyint_update_wtmp (ent , host, user) struct utmp *ent; - char *host; -char *user; - { + char *host; + char *user; +{ struct utmp ut; struct stat statb; int fd; @@ -44,11 +44,12 @@ char *user; struct utmpx utx; getutmpx(ent, &utx); -if (host) - strncpy(utx.ut_host, host, sizeof(utx.ut_host) ); -else utx.ut_host[0] = 0; -if (user) - strncpy(utx.ut_user, user, sizeof(utx.ut_user)); + if (host) + strncpy(utx.ut_host, host, sizeof(utx.ut_host) ); + else + utx.ut_host[0] = 0; + if (user) + strncpy(utx.ut_user, user, sizeof(utx.ut_user)); updwtmpx(WTMPX_FILE, &utx); #endif @@ -62,6 +63,9 @@ if (user) if ((fd = open(WTMP_FILE, O_WRONLY|O_APPEND, 0)) >= 0) { if (!fstat(fd, &statb)) { (void)memset((char *)&ut, 0, sizeof(ut)); +#ifdef __hpux + strncpy (ut.ut_id, ent->ut_id, sizeof (ut.ut_id)); +#endif (void)strncpy(ut.ut_line, ent->ut_line, sizeof(ut.ut_line)); (void)strncpy(ut.ut_name, ent->ut_name, sizeof(ut.ut_name)); #ifndef NO_UT_HOST @@ -72,7 +76,11 @@ if (user) if (ent->ut_name) { if (!ut.ut_pid) ut.ut_pid = getpid(); +#ifndef __hpux ut.ut_type = USER_PROCESS; +#else + ut.ut_type = ent->ut_type; +#endif } else { #ifdef EMPTY ut.ut_type = EMPTY;