]>
Commit | Line | Data |
---|---|---|
7b7692b8 ER |
1 | --- proftpd-1.3.0/src/log.c 2005-11-14 18:33:06.000000000 +0200 |
2 | +++ proftpd-1.3.0.utmp/src/log.c 2006-04-29 14:17:55.023163252 +0300 | |
3 | @@ -54,31 +54,13 @@ | |
12bef652 | 4 | |
c8b81d76 TO |
5 | int log_wtmp(char *line, const char *name, const char *host, |
6 | pr_netaddr_t *ip) { | |
12bef652 JR |
7 | - struct stat buf; |
8 | struct utmp ut; | |
728c4cc1 JR |
9 | int res = 0; |
10 | - static int fd = -1; | |
7b7692b8 | 11 | + static int washere = 0; |
8db28cde | 12 | |
7b7692b8 ER |
13 | -#if ((defined(SVR4) || defined(__SVR4)) || \ |
14 | - (defined(__NetBSD__) && defined(HAVE_UTMPX_H))) && \ | |
12bef652 | 15 | - !(defined(LINUX) || defined(__hpux) || defined (_AIX)) |
ff5ecb89 | 16 | - /* This "auxilliary" utmp doesn't exist under linux. */ |
8db28cde PG |
17 | -#ifdef __sparcv9 |
18 | - struct futmpx utx; | |
19 | - time_t t; | |
20 | -#else | |
ff5ecb89 | 21 | - struct utmpx utx; |
8db28cde | 22 | -#endif |
12bef652 | 23 | - static int fdx = -1; |
850a3e73 | 24 | - |
7b7692b8 ER |
25 | -#if !defined(WTMPX_FILE) && defined(_PATH_WTMPX) |
26 | -# define WTMPX_FILE _PATH_WTMPX | |
27 | -#endif | |
28 | - | |
850a3e73 | 29 | - if (fdx < 0 && |
30 | - (fdx = open(WTMPX_FILE, O_WRONLY|O_APPEND, 0)) < 0) { | |
31 | - pr_log_pri(PR_LOG_WARNING, "wtmpx %s: %s", WTMPX_FILE, strerror(errno)); | |
728c4cc1 | 32 | - return -1; |
12bef652 JR |
33 | + if (!washere) { |
34 | + utmpname(_PATH_WTMP); | |
35 | + washere = 1; | |
7b7692b8 | 36 | } |
8db28cde | 37 | |
12bef652 | 38 | /* Unfortunately, utmp string fields are terminated by '\0' if they are |
7b7692b8 | 39 | @@ -87,52 +69,7 @@ |
12bef652 JR |
40 | * Insane if you ask me. Unless there's massive uproar, I prefer to err on |
41 | * the side of caution and always null-terminate our strings. | |
42 | */ | |
850a3e73 | 43 | - if (fstat(fdx, &buf) == 0) { |
44 | - memset(&utx, 0, sizeof(utx)); | |
45 | - | |
46 | - sstrncpy(utx.ut_user, name, sizeof(utx.ut_user)); | |
47 | - sstrncpy(utx.ut_id, "ftp", sizeof(utx.ut_user)); | |
48 | - sstrncpy(utx.ut_line, line, sizeof(utx.ut_line)); | |
49 | - sstrncpy(utx.ut_host, host, sizeof(utx.ut_host)); | |
ff5ecb89 | 50 | - utx.ut_pid = getpid(); |
7b7692b8 ER |
51 | -#if defined(__NetBSD__) && defined(HAVE_UTMPX_H) |
52 | - memcpy(&utx.ut_ss, pr_netaddr_get_inaddr(ip), sizeof(utx.ut_ss)); | |
53 | - gettimeofday(&utx.ut_tv, NULL); | |
54 | -#else /* SVR4 */ | |
55 | - utx.ut_syslen = strlen(utx.ut_host)+1; | |
56 | -# ifdef __sparcv9 | |
8db28cde PG |
57 | - time(&t); |
58 | - utx.ut_tv.tv_sec = (time32_t)t; | |
7b7692b8 | 59 | -# else |
ff5ecb89 | 60 | - time(&utx.ut_tv.tv_sec); |
7b7692b8 ER |
61 | -# endif |
62 | -#endif /* SVR4 */ | |
63 | - | |
4c6dc458 | 64 | - if (*name) |
ff5ecb89 JR |
65 | - utx.ut_type = USER_PROCESS; |
66 | - else | |
67 | - utx.ut_type = DEAD_PROCESS; | |
4c6dc458 | 68 | -#ifdef HAVE_UT_UT_EXIT |
ff5ecb89 JR |
69 | - utx.ut_exit.e_termination = 0; |
70 | - utx.ut_exit.e_exit = 0; | |
4c6dc458 | 71 | -#endif /* HAVE_UT_UT_EXIT */ |
850a3e73 | 72 | - if (write(fdx, (char *)&utx, sizeof(utx)) != sizeof(utx)) |
728c4cc1 | 73 | - ftruncate(fdx, buf.st_size); |
850a3e73 | 74 | - |
728c4cc1 | 75 | - } else { |
850a3e73 | 76 | - pr_log_debug(DEBUG0, "%s fstat(): %s", WTMPX_FILE, strerror(errno)); |
728c4cc1 JR |
77 | - res = -1; |
78 | - } | |
12bef652 JR |
79 | - |
80 | -#else /* Non-SVR4 systems */ | |
81 | - | |
850a3e73 | 82 | - if (fd < 0 && |
83 | - (fd = open(WTMP_FILE, O_WRONLY|O_APPEND, 0)) < 0) { | |
84 | - pr_log_pri(PR_LOG_WARNING, "wtmp %s: %s", WTMP_FILE, strerror(errno)); | |
728c4cc1 JR |
85 | - return -1; |
86 | - } | |
7b7692b8 | 87 | |
850a3e73 | 88 | - if (fstat(fd, &buf) == 0) { |
89 | memset(&ut, 0, sizeof(ut)); | |
728c4cc1 | 90 | #ifdef HAVE_UTMAXTYPE |
850a3e73 | 91 | # ifdef LINUX |
7b7692b8 | 92 | @@ -169,15 +106,12 @@ |
728c4cc1 JR |
93 | #endif /* HAVE_UT_UT_HOST */ |
94 | ||
12bef652 | 95 | time(&ut.ut_time); |
850a3e73 | 96 | - if (write(fd, (char *)&ut, sizeof(ut)) != sizeof(ut)) |
97 | - ftruncate(fd, buf.st_size); | |
98 | - | |
728c4cc1 | 99 | - } else { |
850a3e73 | 100 | - pr_log_debug(DEBUG0, "%s fstat(): %s",WTMP_FILE,strerror(errno)); |
728c4cc1 | 101 | - res = -1; |
12bef652 JR |
102 | - } |
103 | -#endif /* SVR4 */ | |
850a3e73 | 104 | |
12bef652 JR |
105 | + setutent(); |
106 | + while ((getutent())) ; | |
107 | + pututline(&ut); | |
108 | + if (!washere) | |
109 | + endutent(); | |
728c4cc1 | 110 | return res; |
12bef652 | 111 | } |
850a3e73 | 112 |