home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / networking / tcpip / amitcp-support / wustl-ftpdaemon / src / logwtmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-29  |  3.5 KB  |  101 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. #ifndef AMIGA
  38. #include "config.h"
  39.  
  40. #include <sys/types.h>
  41. #include <sys/time.h>
  42. #include <sys/stat.h>
  43. #include <fcntl.h>
  44. #include <utmp.h>
  45. #include <string.h>
  46. #ifdef SYSSYSLOG
  47. #include <sys/syslog.h>
  48. #else
  49. #include <syslog.h>
  50. #endif
  51.  
  52. #include "pathnames.h"
  53.  
  54. static int fd = -1;
  55. #endif
  56.  
  57. /* Modified version of logwtmp that holds wtmp file open after first call,
  58.  * for use with ftp (which may chroot after login, but before logout). */
  59.  
  60. logwtmp(char *line, char *name, char *host)
  61. {
  62. #ifndef AMIGA
  63.     struct utmp ut;
  64.     struct stat buf;
  65.     time_t time(time_t *);
  66.     char *strncpy(char *, const char *, size_t);
  67.  
  68.     if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY | O_APPEND, 0)) < 0) {
  69.         syslog(LOG_ERR, "wtmp %s %m", _PATH_WTMP);
  70.         return;
  71.     }
  72.     if (fstat(fd, &buf) == 0) {
  73. #ifdef UTMAXTYPE
  74.         memset((void *)&ut, 0, sizeof(ut));
  75.         (void) strncpy(ut.ut_user, name, sizeof(ut.ut_user));
  76.         (void) strncpy(ut.ut_id, "ftp", sizeof(ut.ut_id));
  77.         (void) strncpy(ut.ut_line, line, sizeof(ut.ut_line));
  78.         ut.ut_pid = getpid();
  79.         if (name && *name)
  80.             ut.ut_type = USER_PROCESS;
  81.         else
  82.             ut.ut_type = DEAD_PROCESS;
  83.         ut.ut_exit.e_termination = 0;
  84.         ut.ut_exit.e_exit = 0;
  85. #else
  86.         (void) strncpy(ut.ut_line, line, sizeof(ut.ut_line));
  87.         (void) strncpy(ut.ut_name, name, sizeof(ut.ut_name));
  88. #endif /* UTMAXTYPE */
  89.  
  90. #ifdef HAVE_UT_UT_HOST  /* does not have host in utmp */
  91.         (void) strncpy(ut.ut_host, host, sizeof(ut.ut_host));
  92. #endif
  93.  
  94.         (void) time(&ut.ut_time);
  95.         if (write(fd, (char *) &ut, sizeof(struct utmp)) !=
  96.             sizeof(struct utmp))
  97.               (void) ftruncate(fd, buf.st_size);
  98.     }
  99. #endif
  100. }
  101.