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