]>
Commit | Line | Data |
---|---|---|
1d7b9b20 | 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. | |
1d7b9b20 | 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 | ||
2b87da3b | 28 | /** |
1d7b9b20 | 29 | ** loginrec.h: platform-independent login recording and lastlog retrieval |
30 | **/ | |
31 | ||
32 | #include "includes.h" | |
33 | ||
1d7b9b20 | 34 | /** |
35 | ** you should use the login_* calls to work around platform dependencies | |
36 | **/ | |
37 | ||
1d7b9b20 | 38 | /* |
39 | * login_netinfo structure | |
40 | */ | |
41 | ||
564dd50a | 42 | union login_netinfo { |
43 | struct sockaddr sa; | |
44 | struct sockaddr_in sa_in; | |
45 | struct sockaddr_storage sa_storage; | |
46 | }; | |
1d7b9b20 | 47 | |
1d7b9b20 | 48 | /* |
49 | * * logininfo structure * | |
50 | */ | |
1d7b9b20 | 51 | /* types - different to utmp.h 'type' macros */ |
52 | /* (though set to the same value as linux, openbsd and others...) */ | |
53 | #define LTYPE_LOGIN 7 | |
54 | #define LTYPE_LOGOUT 8 | |
55 | ||
56 | /* string lengths - set very long */ | |
57 | #define LINFO_PROGSIZE 64 | |
58 | #define LINFO_LINESIZE 64 | |
9c1966bf | 59 | #define LINFO_NAMESIZE 128 |
1d7b9b20 | 60 | #define LINFO_HOSTSIZE 256 |
61 | ||
62 | struct logininfo { | |
1d7b9b20 | 63 | char progname[LINFO_PROGSIZE]; /* name of program (for PAM) */ |
64 | int progname_null; | |
1d7b9b20 | 65 | short int type; /* type of login (LTYPE_*) */ |
1d7b9b20 | 66 | int pid; /* PID of login process */ |
67 | int uid; /* UID of this user */ | |
68 | char line[LINFO_LINESIZE]; /* tty/pty name */ | |
69 | char username[LINFO_NAMESIZE]; /* login username */ | |
70 | char hostname[LINFO_HOSTSIZE]; /* remote hostname */ | |
1d7b9b20 | 71 | /* 'exit_status' structure components */ |
72 | int exit; /* process exit status */ | |
73 | int termination; /* process termination status */ | |
1d7b9b20 | 74 | /* struct timeval (sys/time.h) isn't always available, if it isn't we'll |
75 | * use time_t's value as tv_sec and set tv_usec to 0 | |
76 | */ | |
77 | unsigned int tv_sec; | |
2b87da3b | 78 | unsigned int tv_usec; |
564dd50a | 79 | union login_netinfo hostaddr; /* caller's host address(es) */ |
1d7b9b20 | 80 | }; /* struct logininfo */ |
81 | ||
1d7b9b20 | 82 | /* |
83 | * login recording functions | |
84 | */ | |
5abcdf8e | 85 | |
86 | /** 'public' functions */ | |
87 | ||
1d7b9b20 | 88 | /* construct a new login entry */ |
564dd50a | 89 | struct logininfo *login_alloc_entry(int pid, const char *username, |
1d7b9b20 | 90 | const char *hostname, const char *line); |
564dd50a | 91 | /* free a structure */ |
1d7b9b20 | 92 | void login_free_entry(struct logininfo *li); |
564dd50a | 93 | /* fill out a pre-allocated structure with useful information */ |
2b87da3b | 94 | int login_init_entry(struct logininfo *li, int pid, const char *username, |
564dd50a | 95 | const char *hostname, const char *line); |
96 | /* place the current time in a logininfo struct */ | |
1d7b9b20 | 97 | void login_set_current_time(struct logininfo *li); |
564dd50a | 98 | |
1d7b9b20 | 99 | /* record the entry */ |
1d7b9b20 | 100 | int login_login (struct logininfo *li); |
101 | int login_logout(struct logininfo *li); | |
7e2d5fa4 | 102 | #ifdef LOGIN_NEEDS_UTMPX |
103 | int login_utmp_only(struct logininfo *li); | |
104 | #endif | |
5abcdf8e | 105 | |
106 | /** End of public functions */ | |
107 | ||
108 | /* record the entry */ | |
109 | int login_write (struct logininfo *li); | |
1d7b9b20 | 110 | int login_log_entry(struct logininfo *li); |
111 | ||
5abcdf8e | 112 | /* set the network address based on network address type */ |
113 | void login_set_addr(struct logininfo *li, const struct sockaddr *sa, | |
114 | const unsigned int sa_size); | |
115 | ||
1d7b9b20 | 116 | /* |
564dd50a | 117 | * lastlog retrieval functions |
1d7b9b20 | 118 | */ |
119 | /* lastlog *entry* functions fill out a logininfo */ | |
564dd50a | 120 | struct logininfo *login_get_lastlog(struct logininfo *li, const int uid); |
1d7b9b20 | 121 | /* lastlog *time* functions return time_t equivalent (uint) */ |
564dd50a | 122 | unsigned int login_get_lastlog_time(const int uid); |
1d7b9b20 | 123 | |
124 | /* produce various forms of the line filename */ | |
44d71ad5 | 125 | char *line_fullname(char *dst, const char *src, u_int dstsize); |
1d7b9b20 | 126 | char *line_stripname(char *dst, const char *src, int dstsize); |
127 | char *line_abbrevname(char *dst, const char *src, int dstsize); | |
128 | ||
575e336f | 129 | void record_failed_login(const char *, const char *, const char *); |
130 | ||
1d7b9b20 | 131 | #endif /* _HAVE_LOGINREC_H_ */ |