• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  *
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 /* RCSID("Id: loginrec.h,v 1.2 2004/05/04 10:17:43 matt Exp "); */
35 
36 /* The following #defines are from OpenSSH's defines.h, required for loginrec */
37 
38 /* FIXME: put default paths back in */
39 #ifndef UTMP_FILE
40 #  ifdef _PATH_UTMP
41 #    define UTMP_FILE _PATH_UTMP
42 #  else
43 #    ifdef CONF_UTMP_FILE
44 #      define UTMP_FILE CONF_UTMP_FILE
45 #    endif
46 #  endif
47 #endif
48 #ifndef WTMP_FILE
49 #  ifdef _PATH_WTMP
50 #    define WTMP_FILE _PATH_WTMP
51 #  else
52 #    ifdef CONF_WTMP_FILE
53 #      define WTMP_FILE CONF_WTMP_FILE
54 #    endif
55 #  endif
56 #endif
57 /* pick up the user's location for lastlog if given */
58 #ifndef LASTLOG_FILE
59 #  ifdef _PATH_LASTLOG
60 #    define LASTLOG_FILE _PATH_LASTLOG
61 #  else
62 #    ifdef CONF_LASTLOG_FILE
63 #      define LASTLOG_FILE CONF_LASTLOG_FILE
64 #    endif
65 #  endif
66 #endif
67 
68 
69 /* The login() library function in libutil is first choice */
70 #if defined(HAVE_LOGIN) && !defined(DISABLE_LOGIN)
71 #  define USE_LOGIN
72 
73 #else
74 /* Simply select your favourite login types. */
75 /* Can't do if-else because some systems use several... <sigh> */
76 #  if defined(UTMPX_FILE) && !defined(DISABLE_UTMPX)
77 #    define USE_UTMPX
78 #  endif
79 #  if defined(UTMP_FILE) && !defined(DISABLE_UTMP)
80 #    define USE_UTMP
81 #  endif
82 #  if defined(WTMPX_FILE) && !defined(DISABLE_WTMPX)
83 #    define USE_WTMPX
84 #  endif
85 #  if defined(WTMP_FILE) && !defined(DISABLE_WTMP)
86 #    define USE_WTMP
87 #  endif
88 
89 #endif
90 
91 /* I hope that the presence of LASTLOG_FILE is enough to detect this */
92 #if defined(LASTLOG_FILE) && !defined(DISABLE_LASTLOG)
93 #  define USE_LASTLOG
94 #endif
95 
96 
97 /**
98  ** you should use the login_* calls to work around platform dependencies
99  **/
100 
101 /*
102  * login_netinfo structure
103  */
104 
105 union login_netinfo {
106 	struct sockaddr sa;
107 	struct sockaddr_in sa_in;
108 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
109 	struct sockaddr_storage sa_storage;
110 #endif
111 };
112 
113 /*
114  *   * logininfo structure  *
115  */
116 /* types - different to utmp.h 'type' macros */
117 /* (though set to the same value as linux, openbsd and others...) */
118 #define LTYPE_LOGIN    7
119 #define LTYPE_LOGOUT   8
120 
121 /* string lengths - set very long */
122 #define LINFO_PROGSIZE 64
123 #define LINFO_LINESIZE 64
124 #define LINFO_NAMESIZE 64
125 #define LINFO_HOSTSIZE 256
126 
127 struct logininfo {
128 	char       progname[LINFO_PROGSIZE];     /* name of program (for PAM) */
129 	int        progname_null;
130 	short int  type;                         /* type of login (LTYPE_*) */
131 	int        pid;                          /* PID of login process */
132 	int        uid;                          /* UID of this user */
133 	char       line[LINFO_LINESIZE];         /* tty/pty name */
134 	char       username[LINFO_NAMESIZE];     /* login username */
135 	char       hostname[LINFO_HOSTSIZE];     /* remote hostname */
136 	/* 'exit_status' structure components */
137 	int        exit;                        /* process exit status */
138 	int        termination;                 /* process termination status */
139 	/* struct timeval (sys/time.h) isn't always available, if it isn't we'll
140 	 * use time_t's value as tv_sec and set tv_usec to 0
141 	 */
142 	unsigned int tv_sec;
143 	unsigned int tv_usec;
144 	union login_netinfo hostaddr;       /* caller's host address(es) */
145 }; /* struct logininfo */
146 
147 /*
148  * login recording functions
149  */
150 
151 /** 'public' functions */
152 
153 struct logininfo *login_alloc_entry(int pid, const char *username,
154 				    const char *hostname, const char *line);
155 /* free a structure */
156 void login_free_entry(struct logininfo *li);
157 /* fill out a pre-allocated structure with useful information */
158 int login_init_entry(struct logininfo *li, int pid, const char *username,
159 		     const char *hostname, const char *line);
160 /* place the current time in a logininfo struct */
161 void login_set_current_time(struct logininfo *li);
162 
163 /* record the entry */
164 int login_login (struct logininfo *li);
165 int login_logout(struct logininfo *li);
166 #ifdef LOGIN_NEEDS_UTMPX
167 int login_utmp_only(struct logininfo *li);
168 #endif
169 
170 /** End of public functions */
171 
172 /* record the entry */
173 int login_write (struct logininfo *li);
174 int login_log_entry(struct logininfo *li);
175 
176 /* set the network address based on network address type */
177 void login_set_addr(struct logininfo *li, const struct sockaddr *sa,
178 		    const unsigned int sa_size);
179 
180 /* produce various forms of the line filename */
181 char *line_fullname(char *dst, const char *src, size_t dstsize);
182 char *line_stripname(char *dst, const char *src, size_t dstsize);
183 char *line_abbrevname(char *dst, const char *src, size_t dstsize);
184 
185 #endif /* _HAVE_LOGINREC_H_ */
186