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. |
| 15 | * 3. All advertising materials mentioning features or use of this software |
| 16 | * must display the following acknowledgement: |
| 17 | * This product includes software developed by Markus Friedl. |
| 18 | * 4. The name of the author may not be used to endorse or promote products |
| 19 | * derived from this software without specific prior written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 22 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 23 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 24 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 26 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 30 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | */ |
| 32 | |
Kevin Steves | ef4eea9 | 2001-02-05 12:42:17 +0000 | [diff] [blame] | 33 | /** |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 34 | ** loginrec.h: platform-independent login recording and lastlog retrieval |
| 35 | **/ |
| 36 | |
| 37 | #include "includes.h" |
| 38 | |
| 39 | #include <sys/types.h> |
| 40 | #include <netinet/in.h> |
| 41 | #include <sys/socket.h> |
| 42 | |
Ben Lindstrom | 97c677d | 2001-05-08 20:33:05 +0000 | [diff] [blame] | 43 | /* RCSID("$Id: loginrec.h,v 1.6 2001/05/08 20:33:06 mouring Exp $"); */ |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | ** you should use the login_* calls to work around platform dependencies |
| 47 | **/ |
| 48 | |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 49 | /* |
| 50 | * login_netinfo structure |
| 51 | */ |
| 52 | |
andre | 61e6725 | 2000-06-04 17:07:49 +0000 | [diff] [blame] | 53 | union login_netinfo { |
| 54 | struct sockaddr sa; |
| 55 | struct sockaddr_in sa_in; |
| 56 | struct sockaddr_storage sa_storage; |
| 57 | }; |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 58 | |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 59 | /* |
| 60 | * * logininfo structure * |
| 61 | */ |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 62 | /* types - different to utmp.h 'type' macros */ |
| 63 | /* (though set to the same value as linux, openbsd and others...) */ |
| 64 | #define LTYPE_LOGIN 7 |
| 65 | #define LTYPE_LOGOUT 8 |
| 66 | |
| 67 | /* string lengths - set very long */ |
| 68 | #define LINFO_PROGSIZE 64 |
| 69 | #define LINFO_LINESIZE 64 |
| 70 | #define LINFO_NAMESIZE 64 |
| 71 | #define LINFO_HOSTSIZE 256 |
| 72 | |
| 73 | struct logininfo { |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 74 | char progname[LINFO_PROGSIZE]; /* name of program (for PAM) */ |
| 75 | int progname_null; |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 76 | short int type; /* type of login (LTYPE_*) */ |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 77 | int pid; /* PID of login process */ |
| 78 | int uid; /* UID of this user */ |
| 79 | char line[LINFO_LINESIZE]; /* tty/pty name */ |
| 80 | char username[LINFO_NAMESIZE]; /* login username */ |
| 81 | char hostname[LINFO_HOSTSIZE]; /* remote hostname */ |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 82 | /* 'exit_status' structure components */ |
| 83 | int exit; /* process exit status */ |
| 84 | int termination; /* process termination status */ |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 85 | /* struct timeval (sys/time.h) isn't always available, if it isn't we'll |
| 86 | * use time_t's value as tv_sec and set tv_usec to 0 |
| 87 | */ |
| 88 | unsigned int tv_sec; |
Kevin Steves | ef4eea9 | 2001-02-05 12:42:17 +0000 | [diff] [blame] | 89 | unsigned int tv_usec; |
andre | 61e6725 | 2000-06-04 17:07:49 +0000 | [diff] [blame] | 90 | union login_netinfo hostaddr; /* caller's host address(es) */ |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 91 | }; /* struct logininfo */ |
| 92 | |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 93 | /* |
| 94 | * login recording functions |
| 95 | */ |
andre | 6bb9237 | 2000-06-19 08:20:03 +0000 | [diff] [blame] | 96 | |
| 97 | /** 'public' functions */ |
| 98 | |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 99 | /* construct a new login entry */ |
andre | 61e6725 | 2000-06-04 17:07:49 +0000 | [diff] [blame] | 100 | struct logininfo *login_alloc_entry(int pid, const char *username, |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 101 | const char *hostname, const char *line); |
andre | 61e6725 | 2000-06-04 17:07:49 +0000 | [diff] [blame] | 102 | /* free a structure */ |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 103 | void login_free_entry(struct logininfo *li); |
andre | 61e6725 | 2000-06-04 17:07:49 +0000 | [diff] [blame] | 104 | /* fill out a pre-allocated structure with useful information */ |
Kevin Steves | ef4eea9 | 2001-02-05 12:42:17 +0000 | [diff] [blame] | 105 | int login_init_entry(struct logininfo *li, int pid, const char *username, |
andre | 61e6725 | 2000-06-04 17:07:49 +0000 | [diff] [blame] | 106 | const char *hostname, const char *line); |
| 107 | /* place the current time in a logininfo struct */ |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 108 | void login_set_current_time(struct logininfo *li); |
andre | 61e6725 | 2000-06-04 17:07:49 +0000 | [diff] [blame] | 109 | |
andre | 6bb9237 | 2000-06-19 08:20:03 +0000 | [diff] [blame] | 110 | /* record the entry */ |
| 111 | int login_login (struct logininfo *li); |
| 112 | int login_logout(struct logininfo *li); |
Ben Lindstrom | 97c677d | 2001-05-08 20:33:05 +0000 | [diff] [blame] | 113 | #ifdef LOGIN_NEEDS_UTMPX |
| 114 | int login_utmp_only(struct logininfo *li); |
| 115 | #endif |
andre | 6bb9237 | 2000-06-19 08:20:03 +0000 | [diff] [blame] | 116 | |
| 117 | /** End of public functions */ |
andre | 61e6725 | 2000-06-04 17:07:49 +0000 | [diff] [blame] | 118 | |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 119 | /* record the entry */ |
| 120 | int login_write (struct logininfo *li); |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 121 | int login_log_entry(struct logininfo *li); |
| 122 | |
andre | 6bb9237 | 2000-06-19 08:20:03 +0000 | [diff] [blame] | 123 | /* set the network address based on network address type */ |
| 124 | void login_set_addr(struct logininfo *li, const struct sockaddr *sa, |
| 125 | const unsigned int sa_size); |
| 126 | |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 127 | /* |
andre | 61e6725 | 2000-06-04 17:07:49 +0000 | [diff] [blame] | 128 | * lastlog retrieval functions |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 129 | */ |
| 130 | /* lastlog *entry* functions fill out a logininfo */ |
andre | 61e6725 | 2000-06-04 17:07:49 +0000 | [diff] [blame] | 131 | struct logininfo *login_get_lastlog(struct logininfo *li, const int uid); |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 132 | /* lastlog *time* functions return time_t equivalent (uint) */ |
andre | 61e6725 | 2000-06-04 17:07:49 +0000 | [diff] [blame] | 133 | unsigned int login_get_lastlog_time(const int uid); |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 134 | |
| 135 | /* produce various forms of the line filename */ |
| 136 | char *line_fullname(char *dst, const char *src, int dstsize); |
| 137 | char *line_stripname(char *dst, const char *src, int dstsize); |
| 138 | char *line_abbrevname(char *dst, const char *src, int dstsize); |
| 139 | |
andre | 2ff7b5d | 2000-06-03 14:57:40 +0000 | [diff] [blame] | 140 | #endif /* _HAVE_LOGINREC_H_ */ |