]> git.pld-linux.org Git - packages/proftpd.git/blob - proftpd-wtmp.patch
- updated to latest CVS
[packages/proftpd.git] / proftpd-wtmp.patch
1 --- proftpd-1.2.0rc2/src/log.c~ Sat Feb  3 18:19:05 2001
2 +++ proftpd-1.2.0rc2/src/log.c  Sat Feb  3 18:21:08 2001
3 @@ -533,59 +533,22 @@
4  
5  int log_wtmp(char *line, char *name, char *host, struct sockaddr_storage *ip)
6  {
7 -  struct stat buf;
8    struct utmp ut;
9    int res = 0;
10 -  static int fd = -1;
11 -
12 -#if (defined(SVR4) || defined(__SVR4)) && \
13 -    !(defined(LINUX) || defined(__hpux) || defined (_AIX))
14 -  /* This "auxilliary" utmp doesn't exist under linux. */
15 -  struct utmpx utx;
16 -  static int fdx = -1;
17 -
18 -  if(fdx < 0 && (fdx = open(WTMPX_FILE, O_WRONLY | O_APPEND, 0)) < 0) {
19 -    log_pri(LOG_WARNING,"wtmpx %s: %s",WTMPX_FILE,strerror(errno));
20 -    return -1;
21 -  }
22 +  static int washere = 0;
23  
24 +  if (!washere) {
25 +    utmpname(_PATH_WTMP);
26 +    washere = 1;
27 +  } else
28 +    washere = 0;
29    /* Unfortunately, utmp string fields are terminated by '\0' if they are
30     * shorter than the size of the field, but if they are exactly the size of
31     * the field they don't have to be terminated at all.  Frankly, this sucks.
32     * Insane if you ask me.  Unless there's massive uproar, I prefer to err on
33     * the side of caution and always null-terminate our strings.
34     */
35 -  if(fstat(fdx,&buf) == 0) {
36 -    memset(&utx,0,sizeof(utx));
37 -    sstrncpy(utx.ut_user,name,sizeof(utx.ut_user));
38 -    sstrncpy(utx.ut_id,"ftp",sizeof(utx.ut_user));
39 -    sstrncpy(utx.ut_line,line,sizeof(utx.ut_line));
40 -    sstrncpy(utx.ut_host,host,sizeof(utx.ut_host));
41 -    utx.ut_syslen = strlen(utx.ut_host)+1;
42 -    utx.ut_pid = getpid();
43 -    time(&utx.ut_tv.tv_sec);
44 -    if(*name)
45 -      utx.ut_type = USER_PROCESS;
46 -    else
47 -      utx.ut_type = DEAD_PROCESS;
48 -    utx.ut_exit.e_termination = 0;
49 -    utx.ut_exit.e_exit = 0;
50 -    if(write(fdx,(char*)&utx,sizeof(utx)) != sizeof(utx))
51 -      ftruncate(fdx, buf.st_size);
52 -  } else {
53 -    log_debug(DEBUG0,"%s fstat(): %s",WTMPX_FILE,strerror(errno));
54 -    res = -1;
55 -  }
56 -
57 -#else /* Non-SVR4 systems */
58 -
59 -  if(fd < 0 && (fd = open(WTMP_FILE,O_WRONLY|O_APPEND,0)) < 0) {
60 -    log_pri(LOG_WARNING,"wtmp %s: %s",WTMP_FILE,strerror(errno));
61 -    return -1;
62 -  }
63
64 -  if(fstat(fd,&buf) == 0) {
65 -    memset(&ut,0,sizeof(ut));
66 +  memset(&ut,0,sizeof(ut));
67  #ifdef HAVE_UTMAXTYPE
68  #ifdef LINUX
69      if(ip) {
70 @@ -621,13 +584,12 @@
71  #endif /* HAVE_UT_UT_HOST */
72  
73      time(&ut.ut_time);
74 -    if(write(fd,(char*)&ut,sizeof(ut)) != sizeof(ut))
75 -      ftruncate(fd,buf.st_size);
76 -  } else {
77 -    log_debug(DEBUG0,"%s fstat(): %s",WTMP_FILE,strerror(errno));
78 -    res = -1;
79 -  }
80 -#endif /* SVR4 */
81 +
82 +  setutent();
83 +  while ((getutent())) ;
84 +  pututline(&ut);
85 +  if (!washere)
86 +    endutent();
87  
88    return res;
89  }
This page took 0.151089 seconds and 4 git commands to generate.