home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / NETKIT-B.05 / NETKIT-B / NetKit-B-0.05 / ftpd / logwtmp.c,v < prev    next >
Encoding:
Text File  |  1994-07-27  |  3.0 KB  |  99 lines

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