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