loginrec.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef _HAVE_LOGINREC_H_
  2. #define _HAVE_LOGINREC_H_
  3. /*
  4. * Copyright (c) 2000 Andre Lucas. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. /**
  27. ** loginrec.h: platform-independent login recording and lastlog retrieval
  28. **/
  29. #include "includes.h"
  30. struct ssh;
  31. /**
  32. ** you should use the login_* calls to work around platform dependencies
  33. **/
  34. /*
  35. * login_netinfo structure
  36. */
  37. union login_netinfo {
  38. struct sockaddr sa;
  39. struct sockaddr_in sa_in;
  40. struct sockaddr_storage sa_storage;
  41. };
  42. /*
  43. * * logininfo structure *
  44. */
  45. /* types - different to utmp.h 'type' macros */
  46. /* (though set to the same value as linux, openbsd and others...) */
  47. #define LTYPE_LOGIN 7
  48. #define LTYPE_LOGOUT 8
  49. /* string lengths - set very long */
  50. #define LINFO_PROGSIZE 64
  51. #define LINFO_LINESIZE 64
  52. #define LINFO_NAMESIZE 512
  53. #define LINFO_HOSTSIZE 256
  54. struct logininfo {
  55. char progname[LINFO_PROGSIZE]; /* name of program (for PAM) */
  56. int progname_null;
  57. short int type; /* type of login (LTYPE_*) */
  58. pid_t pid; /* PID of login process */
  59. uid_t uid; /* UID of this user */
  60. char line[LINFO_LINESIZE]; /* tty/pty name */
  61. char username[LINFO_NAMESIZE]; /* login username */
  62. char hostname[LINFO_HOSTSIZE]; /* remote hostname */
  63. /* 'exit_status' structure components */
  64. int exit; /* process exit status */
  65. int termination; /* process termination status */
  66. /* struct timeval (sys/time.h) isn't always available, if it isn't we'll
  67. * use time_t's value as tv_sec and set tv_usec to 0
  68. */
  69. unsigned int tv_sec;
  70. unsigned int tv_usec;
  71. union login_netinfo hostaddr; /* caller's host address(es) */
  72. }; /* struct logininfo */
  73. /*
  74. * login recording functions
  75. */
  76. /** 'public' functions */
  77. /* construct a new login entry */
  78. struct logininfo *login_alloc_entry(pid_t pid, const char *username,
  79. const char *hostname, const char *line);
  80. /* free a structure */
  81. void login_free_entry(struct logininfo *li);
  82. /* fill out a pre-allocated structure with useful information */
  83. int login_init_entry(struct logininfo *li, pid_t pid, const char *username,
  84. const char *hostname, const char *line);
  85. /* place the current time in a logininfo struct */
  86. void login_set_current_time(struct logininfo *li);
  87. /* record the entry */
  88. int login_login (struct logininfo *li);
  89. int login_logout(struct logininfo *li);
  90. #ifdef LOGIN_NEEDS_UTMPX
  91. int login_utmp_only(struct logininfo *li);
  92. #endif
  93. /** End of public functions */
  94. /* record the entry */
  95. int login_write (struct logininfo *li);
  96. int login_log_entry(struct logininfo *li);
  97. /* set the network address based on network address type */
  98. void login_set_addr(struct logininfo *li, const struct sockaddr *sa,
  99. const unsigned int sa_size);
  100. /*
  101. * lastlog retrieval functions
  102. */
  103. /* lastlog *entry* functions fill out a logininfo */
  104. struct logininfo *login_get_lastlog(struct logininfo *li, const uid_t uid);
  105. /* lastlog *time* functions return time_t equivalent (uint) */
  106. unsigned int login_get_lastlog_time(const uid_t uid);
  107. /* produce various forms of the line filename */
  108. char *line_fullname(char *dst, const char *src, u_int dstsize);
  109. char *line_stripname(char *dst, const char *src, int dstsize);
  110. char *line_abbrevname(char *dst, const char *src, int dstsize);
  111. void record_failed_login(struct ssh *, const char *, const char *,
  112. const char *);
  113. #endif /* _HAVE_LOGINREC_H_ */