From e28f4a91c58de4696dc030dfee2a57dd50177c1c Mon Sep 17 00:00:00 2001 From: roland Date: Fri, 21 Jun 1996 21:01:00 +0000 Subject: [PATCH] Fri Jun 21 00:27:51 1996 Roland McGrath Fixes thanks to Raja R Harinath : * sysdeps/unix/sysv/utmpbits.h: Define _HAVE_UT_{TYPE,ID,TV,HOST}. Use __{BEGIN,END}_DECLS. (_PATH_WTMP, _PATH_UTMP, _PATH_LASTLOG): New macros. * login/utmp.h (UTMP_FILE, UTMP_FILENAME, WTMP_FILE, WTMP_FILENAME): New macros, moved here from sysdeps/gnu/utmpbits.h. * sysdeps/generic/utmpbits.h (_HAVE_UT_HOST): Define it. * sysdeps/gnu/utmpbits.h (_HAVE_UT_HOST): Likewise. * login/logout.c: Use ut_host only #if _HAVE_UT_HOST. Use sizeof instead of UT_*SIZE. * login/logwtmp.c: Likewise. --- login/logout.c | 9 +++++---- login/logwtmp.c | 9 +++++---- login/utmp.h | 7 +++++++ sysdeps/generic/utmpbits.h | 4 ++++ sysdeps/gnu/utmpbits.h | 11 +++-------- sysdeps/unix/sysv/utmpbits.h | 16 ++++++++++++++++ 6 files changed, 40 insertions(+), 16 deletions(-) diff --git a/login/logout.c b/login/logout.c index d47a392699..1b8dc317ff 100644 --- a/login/logout.c +++ b/login/logout.c @@ -41,15 +41,16 @@ logout (const char *line) #if _HAVE_UT_TYPE - 0 tmp.ut_type = USER_PROCESS; #endif - strncpy (tmp.ut_line, line, UT_LINESIZE); + strncpy (tmp.ut_line, line, sizeof tmp.ut_line); /* Read the record. */ if (getutline_r (&tmp, &ut, &data) >= 0 || errno == ESRCH) { /* Clear information about who & from where. */ - bzero (ut->ut_name, UT_NAMESIZE); - bzero (ut->ut_host, UT_HOSTSIZE); - + bzero (ut->ut_name, sizeof ut->ut_name); +#if _HAVE_UT_HOST - 0 + bzero (ut->ut_host, sizeof ut->ut_host); +#endif #if _HAVE_UT_TV - 0 gettimeofday (&ut->ut_tv, NULL); #else diff --git a/login/logwtmp.c b/login/logwtmp.c index 10f7384f6c..371f34ee76 100644 --- a/login/logwtmp.c +++ b/login/logwtmp.c @@ -45,9 +45,11 @@ logwtmp (const char *line, const char *name, const char *host) #if _HAVE_UT_TYPE - 0 ut.ut_type = USER_PROCESS; #endif - strncpy (ut.ut_line, line, UT_LINESIZE); - strncpy (ut.ut_name, name, UT_NAMESIZE); - strncpy (ut.ut_host, host, UT_HOSTSIZE); + strncpy (ut.ut_line, line, sizeof ut.ut_line); + strncpy (ut.ut_name, name, sizeof ut.ut_name); +#if _HAVE_UT_HOST - 0 + strncpy (ut.ut_host, host, sizeof ut.ut_host); +#endif #if _HAVE_UT_TV - 0 gettimeofday (&ut.ut_tv, NULL); @@ -60,5 +62,4 @@ logwtmp (const char *line, const char *name, const char *host) /* Close UTMP file. */ endutent_r (&data); - } diff --git a/login/utmp.h b/login/utmp.h index 71f1a093df..e9c1734258 100644 --- a/login/utmp.h +++ b/login/utmp.h @@ -28,6 +28,13 @@ Boston, MA 02111-1307, USA. */ /* Get system dependent values and data structures. */ #include +/* Compatibility names for the strings of the canonical file names. */ +#define UTMP_FILE _PATH_UTMP +#define UTMP_FILENAME _PATH_UTMP +#define WTMP_FILE _PATH_WTMP +#define WTMP_FILENAME _PATH_WTMP + + /* Make FD be the controlling terminal, stdin, stdout, and stderr; then close FD. Returns 0 on success, nonzero on error. */ diff --git a/sysdeps/generic/utmpbits.h b/sysdeps/generic/utmpbits.h index 0cd8f1d238..b3fb36ab4a 100644 --- a/sysdeps/generic/utmpbits.h +++ b/sysdeps/generic/utmpbits.h @@ -46,6 +46,10 @@ struct utmp { long ut_time; }; + +#define _HAVE_UT_HOST 1 /* We have the ut_host field. */ + + __END_DECLS #endif /* utmpbits.h */ diff --git a/sysdeps/gnu/utmpbits.h b/sysdeps/gnu/utmpbits.h index 2244ecbf75..4749fdd3fe 100644 --- a/sysdeps/gnu/utmpbits.h +++ b/sysdeps/gnu/utmpbits.h @@ -28,11 +28,6 @@ Boston, MA 02111-1307, USA. */ #define _PATH_WTMP "/var/log/wtmp" #define _PATH_LASTLOG "/var/log/lastlog" -#define UTMP_FILE _PATH_UTMP -#define WTMP_FILE _PATH_WTMP -#define UTMP_FILENAME UTMP_FILE -#define WTMP_FILENAME WTMP_FILE - #define UT_UNKNOWN 0 /* for ut_type field */ #define RUN_LVL 1 @@ -45,8 +40,6 @@ Boston, MA 02111-1307, USA. */ #define USER_PROCESS 7 #define DEAD_PROCESS 8 -#define ut_name ut_user - #define UT_LINESIZE 32 #define UT_NAMESIZE 32 #define UT_HOSTSIZE 256 @@ -67,6 +60,7 @@ struct utmp char ut_line[UT_LINESIZE]; /* NUL-terminated devicename of tty. */ char ut_id[4]; /* Inittab id. */ char ut_user[UT_NAMESIZE]; /* Username (not NUL terminated). */ +#define ut_name ut_user /* Compatible field name for same. */ char ut_host[UT_HOSTSIZE]; /* Hostname for remote login. */ int ut_exit; /* Process termination/exit status. */ long ut_session; /* Session ID, used for windowing. */ @@ -77,11 +71,12 @@ struct utmp #define ut_time ut_tv.tv_sec /* Backwards compatibility. */ -/* Tell the user that we have a modern system with UT_TYPE, UT_ID +/* Tell the user that we have a modern system with UT_HOST, UT_TYPE, UT_ID and UT_TV fields. */ #define _HAVE_UT_TYPE 1 #define _HAVE_UT_ID 1 #define _HAVE_UT_TV 1 +#define _HAVE_UT_HOST 1 __END_DECLS diff --git a/sysdeps/unix/sysv/utmpbits.h b/sysdeps/unix/sysv/utmpbits.h index e8d9334af1..3d2ccf3b12 100644 --- a/sysdeps/unix/sysv/utmpbits.h +++ b/sysdeps/unix/sysv/utmpbits.h @@ -23,6 +23,12 @@ Cambridge, MA 02139, USA. */ #include +#define _PATH_UTMP "/var/adm/utmp" +#define _PATH_WTMP "/var/adm/wtmp" +#define _PATH_LASTLOG "/var/adm/lastlog" + +__BEGIN_DECLS + struct utmp { #define ut_name ut_user @@ -39,4 +45,14 @@ struct utmp time_t ut_time; }; + +/* Tell the user that we have a modern system with UT_HOST, UT_TYPE, UT_ID + and UT_TV fields. */ +#define _HAVE_UT_TYPE 1 +#define _HAVE_UT_ID 1 +#define _HAVE_UT_TV 1 +#define _HAVE_UT_HOST 1 + +__END_DECLS + #endif /* utmpbits.h */ -- 2.11.0