- int log_wtmp(char *line, char *name, char *host, p_in_addr_t *ip)
- {
-- struct stat buf;
-- struct utmp ut;
- int res = 0;
-- static int fd = -1;
-
--#if defined(SVR4) || defined(__SVR4)
--#if !(defined(LINUX) || defined(__hpux) || defined (_AIX))
-+#ifdef HAVE_UTMPX_H
- /* This "auxilliary" utmp doesn't exist under linux. */
- struct utmpx utx;
-- static int fdx = -1;
--
-- if(fdx < 0 && (fdx = open(WTMPX_FILE, O_WRONLY | O_APPEND, 0)) < 0) {
-- log_pri(LOG_WARNING,"wtmpx %s: %s",WTMPX_FILE,strerror(errno));
-- return -1;
-- }
-
- /* Unfortunately, utmp string fields are terminated by '\0' if they are
- * shorter than the size of the field, but if they are exactly the size of
-@@ -551,37 +541,29 @@
- * Insane if you ask me. Unless there's massive uproar, I prefer to err on
- * the side of caution and always null-terminate our strings.
- */
-- if(fstat(fdx,&buf) == 0) {
- memset(&utx,0,sizeof(utx));
- sstrncpy(utx.ut_user,name,sizeof(utx.ut_user));
- sstrncpy(utx.ut_id,"ftp",sizeof(utx.ut_user));
- sstrncpy(utx.ut_line,line,sizeof(utx.ut_line));
- sstrncpy(utx.ut_host,host,sizeof(utx.ut_host));
-- utx.ut_syslen = strlen(utx.ut_host)+1;
- utx.ut_pid = getpid();
- time(&utx.ut_tv.tv_sec);
- if(*name)
- utx.ut_type = USER_PROCESS;
- else
- utx.ut_type = DEAD_PROCESS;
-+#if defined(__linux)
-+ utx.ut_exit.__e_termination = 0;
-+ utx.ut_exit.__e_exit = 0;
-+#else
- utx.ut_exit.e_termination = 0;
- utx.ut_exit.e_exit = 0;
-- if(write(fdx,(char*)&utx,sizeof(utx)) != sizeof(utx))
-- ftruncate(fdx, buf.st_size);
-- } else {
-- log_debug(DEBUG0,"%s fstat(): %s",WTMPX_FILE,strerror(errno));
-- res = -1;
-- }
--
- #endif
--#endif /* SVR4 */
-+ updwtmpx(_PATH_WTMP, &utx);
-+
++#if defined(HAVE_UTMPX_H)
++#if !defined(WTMPX_FILE) && defined(_PATH_WTMPX)
++# define WTMPX_FILE _PATH_WTMPX
++#endif
++ static char *wtmp_file = NULL;
++ if (wtmp_file == NULL) {
++ if (access(WTMPX_FILE"x", F_OK) == 0)
++ wtmp_file = WTMPX_FILE"x";
++ else if (access(WTMPX_FILE, F_OK) == 0)
++ wtmp_file = WTMPX_FILE;
++ else if (access(WTMP_FILE"x", F_OK) == 0)
++ wtmp_file = WTMP_FILE"x";
++ else if (access(WTMP_FILE, F_OK) == 0)
++ wtmp_file = WTMP_FILE;
++ else {
++ pr_log_pri(PR_LOG_WARNING, "cannot find "WTMPX_FILE);
++ return -1;
++ }
++ }