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 | |
| 33 | /** |
| 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 | |
| 43 | /* RCSID("$Id: loginrec.h,v 1.1 2000/06/03 14:57:40 andre Exp $"); */ |
| 44 | |
| 45 | /** |
| 46 | ** you should use the login_* calls to work around platform dependencies |
| 47 | **/ |
| 48 | |
| 49 | /* check if we have IP6 on this system */ |
| 50 | #if defined(AF_INET6) || defined(INET6_ADDRSTRLEN) |
| 51 | # define LOGIN_HAVE_IP6 |
| 52 | #endif |
| 53 | |
| 54 | /* |
| 55 | * login_netinfo structure |
| 56 | */ |
| 57 | |
| 58 | struct login_netinfo { |
| 59 | struct sockaddr_in sa_in4; |
| 60 | #ifdef LOGIN_HAVE_IP6 |
| 61 | struct sockaddr_in6 sa_in6; |
| 62 | #endif |
| 63 | |
| 64 | }; /* struct login_netinfo */ |
| 65 | |
| 66 | |
| 67 | /* |
| 68 | * * logininfo structure * |
| 69 | */ |
| 70 | |
| 71 | /* types - different to utmp.h 'type' macros */ |
| 72 | /* (though set to the same value as linux, openbsd and others...) */ |
| 73 | #define LTYPE_LOGIN 7 |
| 74 | #define LTYPE_LOGOUT 8 |
| 75 | |
| 76 | /* string lengths - set very long */ |
| 77 | #define LINFO_PROGSIZE 64 |
| 78 | #define LINFO_LINESIZE 64 |
| 79 | #define LINFO_NAMESIZE 64 |
| 80 | #define LINFO_HOSTSIZE 256 |
| 81 | |
| 82 | struct logininfo { |
| 83 | |
| 84 | char progname[LINFO_PROGSIZE]; /* name of program (for PAM) */ |
| 85 | int progname_null; |
| 86 | |
| 87 | short int type; /* type of login (LTYPE_*) */ |
| 88 | |
| 89 | int pid; /* PID of login process */ |
| 90 | int uid; /* UID of this user */ |
| 91 | char line[LINFO_LINESIZE]; /* tty/pty name */ |
| 92 | char username[LINFO_NAMESIZE]; /* login username */ |
| 93 | char hostname[LINFO_HOSTSIZE]; /* remote hostname */ |
| 94 | |
| 95 | /* 'exit_status' structure components */ |
| 96 | int exit; /* process exit status */ |
| 97 | int termination; /* process termination status */ |
| 98 | |
| 99 | /* struct timeval (sys/time.h) isn't always available, if it isn't we'll |
| 100 | * use time_t's value as tv_sec and set tv_usec to 0 |
| 101 | */ |
| 102 | unsigned int tv_sec; |
| 103 | unsigned int tv_usec; |
| 104 | |
| 105 | struct login_netinfo hostaddr; /* caller's host address(es) */ |
| 106 | |
| 107 | }; /* struct logininfo */ |
| 108 | |
| 109 | |
| 110 | /* |
| 111 | * login recording functions |
| 112 | */ |
| 113 | /* construct a new login entry */ |
| 114 | struct logininfo *login_alloc_entry(int pid, |
| 115 | const char *username, |
| 116 | const char *hostname, const char *line); |
| 117 | void login_free_entry(struct logininfo *li); |
| 118 | int login_init_entry(struct logininfo *li, |
| 119 | int pid, const char *username, |
| 120 | const char *hostname, const char *line); |
| 121 | void login_set_progname(struct logininfo *li, |
| 122 | const char *progname); |
| 123 | /* set the type field (skip if using ...login or ...logout) */ |
| 124 | void login_set_type(struct logininfo *li, int type); |
| 125 | void login_set_pid(struct logininfo *li, int pid); |
| 126 | void login_set_uid(struct logininfo *li, int uid); |
| 127 | void login_set_line(struct logininfo *li, const char *line); |
| 128 | void login_set_username(struct logininfo *li, const char *username); |
| 129 | void login_set_hostname(struct logininfo *li, const char *hostname); |
| 130 | /* set the exit status (used by [uw]tmpx) */ |
| 131 | void login_set_exitstatus(struct logininfo *li, int exit, int termination); |
| 132 | void login_set_time(struct logininfo *li, unsigned int tv_sec, |
| 133 | unsigned int tv_usec); |
| 134 | void login_set_current_time(struct logininfo *li); |
| 135 | /* set the network address based on network address type */ |
| 136 | void login_set_ip4(struct logininfo *li, |
| 137 | const struct sockaddr_in *sa_in4); |
| 138 | # ifdef LOGIN_HAVE_IP6 |
| 139 | void login_set_ip6(struct logininfo *li, |
| 140 | const struct sockaddr_in6 *sa_in6); |
| 141 | # endif /* LOGIN_HAVE_IP6 */ |
| 142 | /* record the entry */ |
| 143 | int login_write (struct logininfo *li); |
| 144 | int login_login (struct logininfo *li); |
| 145 | int login_logout(struct logininfo *li); |
| 146 | int login_log_entry(struct logininfo *li); |
| 147 | |
| 148 | /* |
| 149 | * login record retrieval functions |
| 150 | */ |
| 151 | /* lastlog *entry* functions fill out a logininfo */ |
| 152 | struct logininfo *login_getlastentry_name(struct logininfo *li, |
| 153 | const char *username); |
| 154 | struct logininfo *login_getlastentry_uid(struct logininfo *li, |
| 155 | const int pid); |
| 156 | /* lastlog *time* functions return time_t equivalent (uint) */ |
| 157 | unsigned int login_getlasttime_name(const char *username); |
| 158 | unsigned int login_getlasttime_uid(const int pid); |
| 159 | |
| 160 | /* produce various forms of the line filename */ |
| 161 | char *line_fullname(char *dst, const char *src, int dstsize); |
| 162 | char *line_stripname(char *dst, const char *src, int dstsize); |
| 163 | char *line_abbrevname(char *dst, const char *src, int dstsize); |
| 164 | |
| 165 | |
| 166 | #endif /* _HAVE_LOGINREC_H_ */ |
| 167 | |