From dcf05d27e2a54eeb2049ff136baabeca32534bbe Mon Sep 17 00:00:00 2001 From: Sam Hartman Date: Tue, 1 Aug 1995 17:56:08 +0000 Subject: [PATCH] Change to use libpty for utmp handling in login.krb5. Remove logutil.c as it is no longer needed. Use new interface to pty_getpty. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@6375 dc483132-0cff-0310-8789-dd5450dbe970 --- src/appl/bsd/.Sanitize | 1 - src/appl/bsd/ChangeLog | 14 +++ src/appl/bsd/Makefile.in | 16 +-- src/appl/bsd/krlogind.c | 2 +- src/appl/bsd/krshd.c | 12 +-- src/appl/bsd/login.c | 5 +- src/appl/bsd/logutil.c | 225 --------------------------------------- 7 files changed, 33 insertions(+), 242 deletions(-) delete mode 100644 src/appl/bsd/logutil.c diff --git a/src/appl/bsd/.Sanitize b/src/appl/bsd/.Sanitize index f24682ef4..b9c402057 100644 --- a/src/appl/bsd/.Sanitize +++ b/src/appl/bsd/.Sanitize @@ -42,7 +42,6 @@ krshd.M krshd.c login.c loginpaths.h -logutil.c rcp.M rlogin.M rpaths.h diff --git a/src/appl/bsd/ChangeLog b/src/appl/bsd/ChangeLog index 8854a3d09..a9404ab26 100644 --- a/src/appl/bsd/ChangeLog +++ b/src/appl/bsd/ChangeLog @@ -1,3 +1,17 @@ +Tue Aug 1 08:43:22 1995 Sam Hartman + + * Makefile.in : Remove references to logutil.c and logutil.o + + + * krshd.c (doit): Replace logwtmp with pty_logwtmp + + * login.c (main): use pty_update_utmp not update_utmp + + * logutil.c: Removed because all its functionality is incorperated + into libpty. + + * krlogind.c (doit): Pass length of line to pty_getpty + Mon Jul 31 17:07:59 1995 Sam Hartman * login.c (main): Don't call TIOCSETD under Posix. diff --git a/src/appl/bsd/Makefile.in b/src/appl/bsd/Makefile.in index 5cb4e5d88..9bbdd56d2 100644 --- a/src/appl/bsd/Makefile.in +++ b/src/appl/bsd/Makefile.in @@ -9,9 +9,9 @@ LIBOBJS=@LIBOBJS@ LOCAL_LIBRARIES=-lpty DEPLOCAL_LIBRARIES=$(TOPLIBD)/../util/pty/libpty.a -SRCS= krcp.c krlogin.c krsh.c kcmd.c forward.c logutil.c $(SETENVSRC) \ +SRCS= krcp.c krlogin.c krsh.c kcmd.c forward.c $(SETENVSRC) \ login.c krshd.c krlogind.c -OBJS= krcp.o krlogin.o krsh.o kcmd.o forward.o logutil.o $(SETENVOBJ) \ +OBJS= krcp.o krlogin.o krsh.o kcmd.o forward.o $(SETENVOBJ) \ login.o krshd.o krlogind.o $(LIBOBJS) UCB_RLOGIN = @UCB_RLOGIN@ @@ -51,15 +51,15 @@ install:: $(INSTALL_PROGRAM) rlogin $(DESTDIR)$(CLIENT_BINDIR)/rlogin $(INSTALL_DATA) $(srcdir)/rlogin.M ${DESTDIR}$(CLIENT_MANDIR)/rlogin.1 -krshd: krshd.o kcmd.o logutil.o forward.o $(SETENVOBJ) $(LIBOBJS) $(DEPLIBS) - $(LD) $(LDFLAGS) $(LDARGS) -o krshd krshd.o kcmd.o logutil.o forward.o $(SETENVOBJ) $(LIBOBJS) $(LIBS) +krshd: krshd.o kcmd.o forward.o $(SETENVOBJ) $(LIBOBJS) $(DEPLIBS) + $(LD) $(LDFLAGS) $(LDARGS) -o krshd krshd.o kcmd.o forward.o $(SETENVOBJ) $(LIBOBJS) $(LIBS) install:: $(INSTALL_PROGRAM) krshd $(DESTDIR)$(SERVER_BINDIR)/krshd $(INSTALL_DATA) $(srcdir)/krshd.M ${DESTDIR}$(SERVER_MANDIR)/krshd.8 -krlogind: krlogind.o logutil.o kcmd.o forward.o $(SETENVOBJ) $(LIBOBJS) $(DEPLIBS) - $(LD) $(LDFLAGS) $(LDARGS) -o krlogind krlogind.o logutil.o kcmd.o forward.o $(SETENVOBJ) $(LIBOBJS) $(LIBS) +krlogind: krlogind.o kcmd.o forward.o $(SETENVOBJ) $(LIBOBJS) $(DEPLIBS) + $(LD) $(LDFLAGS) $(LDARGS) -o krlogind krlogind.o kcmd.o forward.o $(SETENVOBJ) $(LIBOBJS) $(LIBS) install:: $(INSTALL_PROGRAM) krlogind $(DESTDIR)$(SERVER_BINDIR)/krlogind @@ -69,8 +69,8 @@ install:: # We load the libraries twice here since des425 has a dependency on # krb5_read_passwrd in krb5.a. Sigh, circular references. # -login.krb5: login.o logutil.o $(SETENVOBJ) $(LIBOBJS) $(DEPLIBS) - $(LD) $(LDFLAGS) $(LDARGS) -o login.krb5 login.o logutil.o $(SETENVOBJ) $(LIBOBJS) $(LIBS) $(LOGINLIBS) +login.krb5: login.o $(SETENVOBJ) $(LIBOBJS) $(DEPLIBS) + $(LD) $(LDFLAGS) $(LDARGS) -o login.krb5 login.o $(SETENVOBJ) $(LIBOBJS) $(LIBS) $(LOGINLIBS) install:: $(INSTALL_PROGRAM) login.krb5 $(DESTDIR)$(SERVER_BINDIR)/login.krb5 diff --git a/src/appl/bsd/krlogind.c b/src/appl/bsd/krlogind.c index 28d32cf87..823898e43 100644 --- a/src/appl/bsd/krlogind.c +++ b/src/appl/bsd/krlogind.c @@ -578,7 +578,7 @@ int syncpipe[2]; #endif write(f, "", 1); - if (retval = pty_getpty(&p,line)) { + if (retval = pty_getpty(&p,line, sizeof(line))) { com_err(progname, retval, "while getting master pty"); exit(2); } diff --git a/src/appl/bsd/krshd.c b/src/appl/bsd/krshd.c index f844606d8..801c4068d 100644 --- a/src/appl/bsd/krshd.c +++ b/src/appl/bsd/krshd.c @@ -820,13 +820,13 @@ doit(f, fromp) if (port) { /* Place entry into wtmp */ sprintf(ttyn,"krsh%1d",getpid()); - logwtmp(ttyn,locuser,hostname); + pty_logwtmp(ttyn,locuser,hostname); } /* We are simply execing a program over rshd : log entry into wtmp, as kexe(pid), then finish out the session right after that. Syslog should have the information as to what was exec'd */ else { - logwtmp(ttyn,locuser,hostname); + pty_logwtmp(ttyn,locuser,hostname); } #ifdef CRAY @@ -1185,7 +1185,7 @@ doit(f, fromp) "Shell process completed."); #endif /* Finish session in wmtp */ - logwtmp(ttyn,"",""); + pty_logwtmp(ttyn,"",""); exit(0); } #ifdef SETPGRP_TWOARG @@ -1212,7 +1212,7 @@ doit(f, fromp) as kexe(pid), then finish out the session right after that. Syslog should have the information as to what was exec'd */ else { - logwtmp(ttyn,"",""); + pty_logwtmp(ttyn,"",""); } if (*pwd->pw_shell == '\0') @@ -1288,7 +1288,7 @@ doit(f, fromp) exit(1); signout_please: - logwtmp(ttyn,"",""); + pty_logwtmp(ttyn,"",""); exit(1); } @@ -1357,7 +1357,7 @@ krb5_sigtype #endif wait(0); - logwtmp(ttyn,"",""); + pty_logwtmp(ttyn,"",""); syslog(LOG_INFO ,"Shell process completed."); exit(0); } diff --git a/src/appl/bsd/login.c b/src/appl/bsd/login.c index e3b60e1a7..dceecc0fb 100644 --- a/src/appl/bsd/login.c +++ b/src/appl/bsd/login.c @@ -256,6 +256,8 @@ int main(argc, argv) char tbuf[MAXPATHLEN + 2]; char *ttyname(), *stypeof(), *crypt(), *getpass(); time_t login_time; +int retval; + off_t lseek(); #ifdef POSIX_TERMIOS struct termios tc; @@ -785,7 +787,8 @@ bad_login: utmp.ut_pid = getppid(); #endif login_time = time(&utmp.ut_time); - update_utmp(&utmp, username, ttyn, hostname); + if ( (retval = pty_update_utmp(&utmp, username, ttyn, hostname)) < 0 ) + com_err (argv[0], retval, "while updating utmp"); } quietlog = access(HUSHLOGIN, F_OK) == 0; diff --git a/src/appl/bsd/logutil.c b/src/appl/bsd/logutil.c deleted file mode 100644 index 12c67f282..000000000 --- a/src/appl/bsd/logutil.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (c) 1988 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. - */ - -#ifdef HAVE_UNISTD_H -#include -#endif -#ifdef HAVE_STDLIB_H -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_SETUTXENT -#include -#endif - -#ifndef UTMP_FILE -#define UTMP_FILE "/etc/utmp" -#endif -#ifndef WTMP_FILE -#define WTMP_FILE "/usr/adm/wtmp" -#endif - - -#ifndef EMPTY -/* linux has UT_UNKNOWN but not EMPTY */ -#define EMPTY UT_UNKNOWN -#endif - -void update_utmp(); -void update_wtmp(); -void logwtmp(); - - -void update_utmp(ent, username, line, host) - struct utmp *ent; - char *username, *line, *host; -{ -#ifdef HAVE_SETUTENT - struct utmp ut; -#else - struct stat statb; - int tty; -#endif -#ifdef HAVE_SETUTXENT - struct utmpx utx; -#endif -#ifndef NO_UT_PID - char *tmpx; - char utmp_id[5]; -#endif - int fd; - - strncpy(ent->ut_line, line+sizeof("/dev/")-1, sizeof(ent->ut_line)); - ent->ut_time = time(0); - -#ifndef NO_UT_HOST - if (host) - strncpy(ent->ut_host, host, sizeof(ent->ut_host)); - else - ent->ut_host[0] = '\0'; -#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)); - strncpy(ent->ut_user, username, sizeof(ent->ut_user)); -#else - strncpy(ent->ut_name, username, sizeof(ent->ut_name)); -#endif - -#ifdef HAVE_SETUTENT - - utmpname(UTMP_FILE); - setutent(); - pututline(ent); - endutent(); - -#if 0 - /* XXX -- NOT NEEDED ANYMORE */ - - if (ent->ut_type == DEAD_PROCESS) { - if ((fd = open(UTMP_FILE, O_RDWR)) >= 0) { - int cnt = 0; - while(read(fd, (char *)&ut, sizeof(ut)) == sizeof(ut)) { - if (!strncmp(ut.ut_id, ent->ut_id, sizeof(ut.ut_id))) { - (void) memset(ut.ut_host, 0, sizeof(ut.ut_host)); - (void) memset(ut.ut_user, 0, sizeof(ut.ut_user)); - (void) time(&ut.ut_time); - ut.ut_exit.e_exit = ut.ut_pid = 0; - ut.ut_type = EMPTY; - (void) lseek(fd, -sizeof(ut), SEEK_CUR); - (void) write(fd, &ut, sizeof(ut)); - } - cnt++; - } - close(fd); - } - } -#endif - -#ifdef HAVE_SETUTXENT - setutxent(); - getutmpx(ent, &utx); - pututxline(&utx); - endutxent(); -#endif /* HAVE_SETUTXENT */ - -#else /* HAVE_SETUTENT */ - - tty = ttyslot(); - 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 */ - - update_wtmp(ent); -} - -void update_wtmp(ent) - struct utmp *ent; -{ - struct utmp ut; - struct stat statb; - int fd; -#ifdef HAVE_SETUTXENT - struct utmpx utx; - - getutmpx(ent, &utx); - updwtmpx(WTMPX_FILE, &utx); -#endif - -#ifdef HAVE_UPDWTMP - updwtmp(WTMP_FILE, ent); -#else /* HAVE_UPDWTMP */ - - if ((fd = open(WTMP_FILE, O_WRONLY|O_APPEND, 0)) >= 0) { - if (!fstat(fd, &statb)) { - (void)memset((char *)&ut, 0, sizeof(ut)); - (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 - (void)strncpy(ut.ut_host, ent->ut_host, sizeof(ut.ut_host)); -#endif - (void)time(&ut.ut_time); -#if defined(HAVE_GETUTENT) && defined(USER_PROCESS) - if (ent->ut_name) { - if (!ut.ut_pid) - ut.ut_pid = getpid(); - ut.ut_type = USER_PROCESS; - } else { - ut.ut_type = EMPTY; - } -#endif - if (write(fd, (char *)&ut, sizeof(struct utmp)) != - sizeof(struct utmp)) - (void)ftruncate(fd, statb.st_size); - } - (void)close(fd); - } -#endif /* HAVE_UPDWTMP */ -} - -#ifndef HAVE_LOGWTMP -void logwtmp(tty, locuser, host) - char *tty; - char *locuser; - char *host; -{ - struct utmp ut; - char *tmpx; - char utmp_id[5]; - - /* Will be empty for logout */ - int loggingin = locuser[0]; - - -#ifndef NO_UT_HOST - strncpy(ut.ut_host, host, sizeof(ut.ut_host)); -#endif - - strncpy(ut.ut_line, tty, sizeof(ut.ut_line)); - ut.ut_time = time(0); - -#ifndef NO_UT_PID - ut.ut_pid = getpid(); - strncpy(ut.ut_user, locuser, sizeof(ut.ut_user)); - - tmpx = tty + strlen(tty) - 2; - sprintf(utmp_id, "kr%s", tmpx); - strncpy(ut.ut_id, utmp_id, sizeof(ut.ut_id)); - ut.ut_pid = (loggingin ? getpid() : 0); - ut.ut_type = (loggingin ? USER_PROCESS : DEAD_PROCESS); -#else - strncpy(ut.ut_name, locuser, sizeof(ut.ut_name)); -#endif - - update_wtmp(&ut); -} -#endif -- 2.26.2