home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / finger / part02 / lastlog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-03  |  1.8 KB  |  81 lines

  1. /*
  2.  * lastlog.c - get time and location of last login
  3.  *
  4.  * Copyright (C) 1986, 1990  Philip L. Budne
  5.  *
  6.  * This file is part of "Phil's Finger Program".
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 1, or (at your option)
  11.  * any later version.
  12.  *
  13.  */
  14.  
  15. # ifndef lint
  16. static char *rcsid = "$Id: lastlog.c,v 3.0 90/07/06 13:11:14 budd Rel $";
  17. # endif /* lint not defined */
  18.  
  19. # include "finger.h"
  20. # ifdef LASTLOG
  21. # include <sys/types.h>
  22. # include <ctype.h>
  23. # include <lastlog.h>
  24.  
  25. # ifndef LLPATH
  26. # define LLPATH "/usr/adm/lastlog"
  27. # endif /* LLPATH not defined */
  28.  
  29. LOCAL llfile = -1;
  30.  
  31. GLOBAL void llopen() {
  32.     if( llfile < 0 )
  33.     llfile = open(LLPATH, 0);
  34.     else
  35.     lseek( llfile, 0L, 0 );
  36. } /* llopen */
  37.  
  38. GLOBAL void llclose() {
  39.     if( llfile >= 0 )
  40.     close( llfile );
  41. } /* llclose */
  42.  
  43. GLOBAL BOOL lltime( uid, location, time, host )
  44. short uid;
  45. char *location;
  46. time_t *time;
  47. int *host;
  48. {
  49.     struct lastlog ll;
  50.  
  51.     if( llfile < 0 )
  52.     return( FALSE );
  53.  
  54.     lseek( llfile, uid * sizeof( ll ), 0 );
  55.     if( read(llfile, &ll, sizeof( ll ) ) != sizeof( ll ) )
  56.     return( FALSE );
  57.  
  58.     *time = ll.ll_time;            /* return time of login */
  59.     if( ll.ll_host[0] != EOS ) {
  60.     *host = TRUE;
  61.     strzcpy(location, ll.ll_host,
  62.         sizeof( ll.ll_host ) );    /* copy fixed len */
  63.  
  64.     if( isdigit(*location) )
  65.         checkhost( location, sizeof( location ) ); /* hack octets */
  66.     undomain( location, 0 );     /* remove domains, but not prefixes */
  67.     HZUP( location );        /* upper caseify */
  68.     }
  69.     else {
  70.     *host = FALSE;
  71.     strzcpy(location, ll.ll_line, sizeof( ll.ll_line ) );
  72.     }
  73.     return( TRUE );
  74. } /* lltime */
  75. # endif /* LASTLOG defined */
  76. /*
  77.  * Local variables:
  78.  * comment-column: 40
  79.  * End:
  80.  */
  81.