dutmp.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* CHK=0xD757 */
  2. char *revision = "1.2";
  3. /*+-----------------------------------------------------------------------
  4. dutmp.c -- dump /etc/utmp
  5. wht@wht.net
  6. ------------------------------------------------------------------------*/
  7. /*+:EDITS:*/
  8. /*:04-26-2000-11:15-wht@bob-RELEASE 4.42 */
  9. /*:01-24-1997-02:36-wht@yuriatin-SOURCE RELEASE 4.00 */
  10. /*:09-11-1996-19:59-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
  11. /*:11-23-1995-11:20-wht@kepler-source control 3.37 for tsx-11 */
  12. /*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
  13. /*:05-04-1994-04:38-wht@n4hgf-ECU release 3.30 */
  14. /*:09-10-1992-13:58-wht@n4hgf-ECU release 3.20 */
  15. /*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  16. /*:04-28-1992-13:05-wht@n4hgf-clean up for inclusion in ecu */
  17. /*:11-19-1989-16:34-wht-creation */
  18. #include <stdio.h>
  19. #include <fcntl.h>
  20. #include <ctype.h>
  21. #include <sys/types.h>
  22. #include <utmp.h>
  23. char *utmp_file = "/etc/utmp";
  24. extern char *ctime();
  25. /*+-------------------------------------------------------------------------
  26. main(argc,argv)
  27. --------------------------------------------------------------------------*/
  28. main(argc, argv)
  29. int argc;
  30. char **argv;
  31. {
  32. struct utmp ut;
  33. int ufd;
  34. printf("dutmp %s\n", revision);
  35. if ((ufd = open(utmp_file, O_RDONLY, 755)) < 0)
  36. {
  37. perror(utmp_file);
  38. exit(1);
  39. }
  40. while (read(ufd, &ut, sizeof(ut)) > 0)
  41. {
  42. #if defined(sun)
  43. if (!*ut.ut_name || (ut.ut_time < 0))
  44. continue;
  45. printf("%-10.10s %-14.14s %-15.15s %s",
  46. ut.ut_name,
  47. ut.ut_line,
  48. ut.ut_host,
  49. ctime(&ut.ut_time));
  50. #else
  51. printf("%-10.10s %-7.7s %-14.14s %6u %s",
  52. ut.ut_user,
  53. ut.ut_id,
  54. ut.ut_line,
  55. ut.ut_pid,
  56. ctime(&ut.ut_time));
  57. #endif
  58. }
  59. close(ufd);
  60. exit(0);
  61. } /* end of main */
  62. /* vi: set tabstop=4 shiftwidth=4: */
  63. /* end of dutmp.c */