home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / logdaemon-2 / lib / utmpx_login.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-31  |  1.3 KB  |  47 lines

  1. /* Author: Wietse Venema <wietse@wzv.win.tue.nl> */
  2.  
  3. #include <sys/types.h>
  4. #include <sys/time.h>
  5. #include <utmpx.h>
  6. #include <string.h>
  7.  
  8. /* utmpx_login - update utmp and wtmp after login */
  9.  
  10. utmpx_login(line, user, host)
  11. char   *line;
  12. char   *user;
  13. char   *host;
  14. {
  15.     struct utmpx *ut;
  16.     pid_t   mypid = getpid();
  17.     int     ret = (-1);
  18.  
  19.     /*
  20.      * SYSV4 ttymon and login use tty port names with the "/dev/" prefix
  21.      * stripped off. Rlogind and telnetd, on the other hand, make utmpx
  22.      * entries with device names like /dev/pts/nnn. We therefore cannot use
  23.      * getutxline(). Return nonzero if no utmp entry was found with our own
  24.      * process ID for a login or user process.
  25.      */
  26.  
  27.     while ((ut = getutxent())) {
  28.     if (ut->ut_pid == mypid
  29.      && (ut->ut_type == LOGIN_PROCESS || ut->ut_type == USER_PROCESS)) {
  30.         strncpy(ut->ut_line, line, sizeof(ut->ut_line));
  31.         strncpy(ut->ut_user, user, sizeof(ut->ut_user));
  32.         strncpy(ut->ut_host, host, sizeof(ut->ut_host));
  33.         ut->ut_syslen = strlen(host) + 1;
  34.         if (ut->ut_syslen > sizeof(ut->ut_host))
  35.         ut->ut_syslen = sizeof(ut->ut_host);
  36.         ut->ut_type = USER_PROCESS;
  37.         gettimeofday(&(ut->ut_tv));
  38.         pututxline(ut);
  39.         updwtmpx(WTMPX_FILE, ut);
  40.         ret = 0;
  41.         break;
  42.     }
  43.     }
  44.     endutxent();
  45.     return (ret);
  46. }
  47.