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