$NetBSD: patch-al,v 1.3 2003/02/27 21:43:36 fredb Exp $ --- utmp.c.orig 2001-12-17 16:43:25.000000000 -0600 +++ utmp.c @@ -7,7 +7,7 @@ #include "mgetty.h" -#if defined(sunos4) || defined(BSD) +#if defined(sunos4) || ( defined(BSD) && !defined(NETBSD_UTMPX) ) #include #include @@ -20,10 +20,11 @@ #include #include #include -#include - -#ifndef ENOENT -#include +#if !defined(SVR4) && !defined(NETBSD_UTMPX) && !defined(__GLIBC__) || __GLIBC__ < 2 +# include +# ifndef ENOENT +# include +# endif #endif #if defined(_3B1_) || defined(MEIBE) || defined(ISC) @@ -42,8 +43,14 @@ # endif #endif +#ifndef WTMPX_FILE +# ifdef _PATH_WTMPX +# define WTMPX_FILE _PATH_WTMPX /* NetBSD */ +# endif +#endif + -#if defined(sunos4) || defined(BSD) || defined(ultrix) +#if ( defined(sunos4) || defined(BSD) || defined(ultrix) ) && !defined(NETBSD_UTMPX) /* on SunOS (and other BSD-derived systems), the getty process does * * not have to care for the utmp entries, login and init do all the work * Anyway, we have to _read_ it to get the number of users logged in. @@ -109,26 +116,74 @@ { struct utmp *utmp; pid_t pid; +#ifdef NETBSD_UTMPX +struct utmpx ut; +char *id; +#else +# if !defined(SVR4) && !defined(__GLIBC__) || __GLIBC__ < 2 struct stat st; +# endif +#endif FILE * fp; +#ifdef NETBSD_UTMPX + id = line; + if ( strlen( line ) > sizeof( ut.ut_id ) ) + id += strlen( line ) - sizeof( ut.ut_id ); + + if ( ut_type == UT_INIT ) { + lprintf(L_JUNK, + "creating initial utmp entry... (ID: %s)", + id); + + memset( &ut, 0, sizeof( ut ) ); + strncpy( ut.ut_id, id, sizeof( ut.ut_id ) ); + strncpy( ut.ut_line, line, sizeof( ut.ut_line ) ); + gettimeofday( &ut.ut_tv, NULL ); + ut.ut_type = INIT_PROCESS; + login( &ut ); + + lprintf(L_NOISE, "initial utmp + wtmp entry made"); + return; + } + + if ((pid = checklock( line )) == NO_LOCK) { + pid = getpid(); + } + + lprintf(L_JUNK, + "looking for utmp entry... (ID: %s)", id); +#else pid = getpid(); + lprintf(L_JUNK, "looking for utmp entry... (my PID: %d)", pid); +#endif + setutent(); while ((utmp = getutent()) != (struct utmp *) NULL) { - if (utmp->ut_pid == pid && - (utmp->ut_type == INIT_PROCESS || utmp->ut_type == LOGIN_PROCESS)) +#ifdef NETBSD_UTMPX + if ( strncmp( utmp->ut_id, id, sizeof( utmp->ut_id ) ) == 0 && +#else + if ( utmp->ut_pid == pid && +#endif + (utmp->ut_type == INIT_PROCESS || utmp->ut_type == LOGIN_PROCESS) ) { - strcpy(utmp->ut_line, line ); + strncpy(utmp->ut_line, line, sizeof( utmp->ut_line) ); +#ifdef NETBSD_UTMPX + utmp->ut_pid = pid; + gettimeofday( &utmp->ut_tv, NULL ); +#else utmp->ut_time = time( NULL ); +#endif utmp->ut_type = ut_type; /* {INIT,LOGIN,USER}_PROCESS */ - /* "LOGIN", "uugetty", "dialout" */ + strncpy( utmp->ut_user, ut_user, sizeof( utmp->ut_user ) ); + /* "LOGIN", "uugetty", "dialout" */ -#if defined(SVR4) || defined(linux) +#if defined(SVR4) || defined(linux) || defined(NETBSD_UTMPX) if (ut_host != NULL) { strncpy( utmp->ut_host, ut_host, sizeof( utmp->ut_host ) - 1); @@ -138,7 +193,7 @@ } #endif /* SVR4 */ -#if defined(M_UNIX) || defined(__GLIBC__) +#if defined(M_UNIX) || defined(__GLIBC__) || defined(NETBSD_UTMPX) if ( pututline(utmp) == NULL ) { lprintf( L_ERROR, "cannot create utmp entry" ); @@ -151,7 +206,7 @@ /* write same record to end of wtmp * if wtmp file exists */ -#ifdef SVR4 +#if defined(SVR4) || defined(NETBSD_UTMPX) updwtmpx(WTMPX_FILE, utmp); #else # if defined(__GLIBC__) && __GLIBC__ >= 2