home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / n / tcpip / wu-ftpd-.000 / wu-ftpd- / wu-ftpd-2.4 / src / logwtmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-08  |  3.5 KB  |  97 lines

  1. /* Copyright (c) 1988 The Regents of the University of California. All rights
  2.  * reserved.
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions are
  6.  * met: 1. Redistributions of source code must retain the above copyright
  7.  * notice, this list of conditions and the following disclaimer. 2.
  8.  * Redistributions in binary form must reproduce the above copyright notice,
  9.  * this list of conditions and the following disclaimer in the documentation
  10.  * and/or other materials provided with the distribution. 3. All advertising
  11.  * materials mentioning features or use of this software must display the
  12.  * following acknowledgement: This product includes software developed by the
  13.  * University of California, Berkeley and its contributors. 4. Neither the
  14.  * name of the University nor the names of its contributors may be used to
  15.  * endorse or promote products derived from this software without specific
  16.  * prior written permission.
  17.  *
  18.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
  19.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21.  * DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
  22.  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24.  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28.  * SUCH DAMAGE.
  29.  *
  30.  */
  31.  
  32. #ifndef lint
  33. static char sccsid[] = "@(#)logwtmp.c   5.7 (Berkeley) 2/25/91";
  34.  
  35. #endif /* not lint */
  36.  
  37. #include "config.h"
  38.  
  39. #include <sys/types.h>
  40. #include <sys/time.h>
  41. #include <sys/stat.h>
  42. #include <fcntl.h>
  43. #include <utmp.h>
  44. #include <string.h>
  45. #ifdef SYSSYSLOG
  46. #include <sys/syslog.h>
  47. #else
  48. #include <syslog.h>
  49. #endif
  50.  
  51. #include "pathnames.h"
  52.  
  53. static int fd = -1;
  54.  
  55. /* Modified version of logwtmp that holds wtmp file open after first call,
  56.  * for use with ftp (which may chroot after login, but before logout). */
  57.  
  58. logwtmp(char *line, char *name, char *host)
  59. {
  60.     struct utmp ut;
  61.     struct stat buf;
  62.     time_t time(time_t *);
  63.     char *strncpy(char *, const char *, size_t);
  64.  
  65.     if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY | O_APPEND, 0)) < 0) {
  66.         syslog(LOG_ERR, "wtmp %s %m", _PATH_WTMP);
  67.         return;
  68.     }
  69.     if (fstat(fd, &buf) == 0) {
  70. #ifdef UTMAXTYPE
  71.         memset((void *)&ut, 0, sizeof(ut));
  72.         (void) strncpy(ut.ut_user, name, sizeof(ut.ut_user));
  73.         (void) strncpy(ut.ut_id, "ftp", sizeof(ut.ut_id));
  74.         (void) strncpy(ut.ut_line, line, sizeof(ut.ut_line));
  75.         ut.ut_pid = getpid();
  76.         if (name && *name)
  77.             ut.ut_type = USER_PROCESS;
  78.         else
  79.             ut.ut_type = DEAD_PROCESS;
  80.         ut.ut_exit.e_termination = 0;
  81.         ut.ut_exit.e_exit = 0;
  82. #else
  83.         (void) strncpy(ut.ut_line, line, sizeof(ut.ut_line));
  84.         (void) strncpy(ut.ut_name, name, sizeof(ut.ut_name));
  85. #endif /* UTMAXTYPE */
  86.  
  87. #ifdef HAVE_UT_UT_HOST  /* does not have host in utmp */
  88.         (void) strncpy(ut.ut_host, host, sizeof(ut.ut_host));
  89. #endif
  90.  
  91.         (void) time(&ut.ut_time);
  92.         if (write(fd, (char *) &ut, sizeof(struct utmp)) !=
  93.             sizeof(struct utmp))
  94.               (void) ftruncate(fd, buf.st_size);
  95.     }
  96. }
  97.