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