diff -ruNp sysvinit-2.96.orig/src/last.c sysvinit-2.96/src/last.c --- sysvinit-2.96.orig/src/last.c 2019-09-11 19:43:12.000000000 +0200 +++ sysvinit-2.96/src/last.c 2019-12-01 05:14:37.344902512 +0100 @@ -44,6 +44,25 @@ #include #include "oldutmp.h" +/* + * Try to be smart about the location of the BTMP file + */ +#ifndef _PATH_BTMP +#define _PATH_BTMP "/var/log/btmp" +#define BTMP_FILE _PATH_BTMP +#endif + +#define TRANSFORM_UTMP_FILE_NAME(file_name) \ + ((strcmp (file_name, _PATH_WTMP) == 0 \ + && access ( _PATH_WTMP "x", F_OK) == 0) ? (_PATH_WTMP "x") : \ + ((strcmp (file_name, _PATH_BTMP) == 0 \ + && access ( _PATH_BTMP "x", F_OK) == 0) ? (_PATH_BTMP "x") : \ + ((strcmp (file_name, _PATH_WTMP "x") == 0 \ + && access (_PATH_WTMP "x", F_OK) != 0) ? _PATH_WTMP : \ + ((strcmp (file_name, _PATH_BTMP "x") == 0 \ + && access (_PATH_BTMP "x", F_OK) != 0) ? _PATH_BTMP : \ + file_name)))) + #ifndef SHUTDOWN_TIME # define SHUTDOWN_TIME 254 #endif @@ -251,28 +270,6 @@ int uread(FILE *fp, struct utmp *u, int #endif /* - * Try to be smart about the location of the BTMP file - */ -#ifndef BTMP_FILE -#define BTMP_FILE getbtmp() -char *getbtmp() -{ - static char btmp[PATH_MAX + 5]; /* max path + btmp + null terminator */ - char *p; - - memset(btmp, '\0', PATH_MAX + 5); - strncpy(btmp, WTMP_FILE, PATH_MAX); - if ((p = strrchr(btmp, '/')) == NULL) - p = btmp; - else - p++; - *p = 0; - strcat(btmp, "btmp"); - return btmp; -} -#endif - -/* * Print a short date. */ char *showdate() @@ -381,6 +378,8 @@ int list(struct utmp *p, time_t t, int w strncat(utline, p->ut_line, UT_LINESIZE); if (strncmp(utline, "ftp", 3) == 0 && isdigit(utline[3])) utline[3] = 0; + if (strncmp(utline, "ftpd", 4) == 0 && isdigit(utline[4])) + utline[4] = 0; if (strncmp(utline, "uucp", 4) == 0 && isdigit(utline[4])) utline[4] = 0; @@ -708,10 +707,10 @@ int main(int argc, char **argv) * Which file do we want to read? */ if (strcmp(progname, "lastb") == 0) { - ufile = BTMP_FILE; + ufile = TRANSFORM_UTMP_FILE_NAME(BTMP_FILE); lastb = 1; } else - ufile = WTMP_FILE; + ufile = TRANSFORM_UTMP_FILE_NAME(WTMP_FILE); if (altufile) ufile = altufile; time(&lastdown); diff -ruNp sysvinit-2.96.orig/src/utmp.c sysvinit-2.96/src/utmp.c --- sysvinit-2.96.orig/src/utmp.c 2019-09-11 19:43:12.000000000 +0200 +++ sysvinit-2.96/src/utmp.c 2019-12-01 05:15:12.143729210 +0100 @@ -80,7 +80,9 @@ char *line) /* Which line is this */ * this if we have updwtmp() so we can see if the * wtmp file is accessible. */ +#if !HAVE_UPDWTMP if ((fd = open(WTMP_FILE, O_WRONLY|O_APPEND)) < 0) return; +#endif #ifdef INIT_MAIN /* @@ -140,8 +142,8 @@ char *line) /* Which line is this */ updwtmp(WTMP_FILE, &utmp); #else write(fd, (char *)&utmp, sizeof(utmp)); -#endif close(fd); +#endif } /* @@ -164,8 +166,10 @@ char *oldline) /* Line of old utmp ent /* * Can't do much if UTMP_FILE is not present or not writable. */ +#if !HAVE_UPDWTMP if (access(UTMP_FILE, W_OK) < 0) return; +#endif #ifdef INIT_MAIN /*