xref: /titanic_50/usr/src/cmd/ssh/include/loginrec.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
3*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
4*7c478bd9Sstevel@tonic-gate  */
5*7c478bd9Sstevel@tonic-gate /*
6*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2000 Andre Lucas.  All rights reserved.
7*7c478bd9Sstevel@tonic-gate  *
8*7c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
9*7c478bd9Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
10*7c478bd9Sstevel@tonic-gate  * are met:
11*7c478bd9Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
12*7c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
13*7c478bd9Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
14*7c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
15*7c478bd9Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
16*7c478bd9Sstevel@tonic-gate  * 3. All advertising materials mentioning features or use of this software
17*7c478bd9Sstevel@tonic-gate  *    must display the following acknowledgement:
18*7c478bd9Sstevel@tonic-gate  *      This product includes software developed by Markus Friedl.
19*7c478bd9Sstevel@tonic-gate  * 4. The name of the author may not be used to endorse or promote products
20*7c478bd9Sstevel@tonic-gate  *    derived from this software without specific prior written permission.
21*7c478bd9Sstevel@tonic-gate  *
22*7c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23*7c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24*7c478bd9Sstevel@tonic-gate  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25*7c478bd9Sstevel@tonic-gate  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26*7c478bd9Sstevel@tonic-gate  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27*7c478bd9Sstevel@tonic-gate  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28*7c478bd9Sstevel@tonic-gate  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29*7c478bd9Sstevel@tonic-gate  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30*7c478bd9Sstevel@tonic-gate  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31*7c478bd9Sstevel@tonic-gate  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*7c478bd9Sstevel@tonic-gate  */
33*7c478bd9Sstevel@tonic-gate /*
34*7c478bd9Sstevel@tonic-gate  * loginrec.h:  platform-independent login recording and lastlog retrieval
35*7c478bd9Sstevel@tonic-gate  */
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #ifndef	_LOGINREC_H
38*7c478bd9Sstevel@tonic-gate #define	_LOGINREC_H
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
43*7c478bd9Sstevel@tonic-gate extern "C" {
44*7c478bd9Sstevel@tonic-gate #endif
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate #include "includes.h"
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
49*7c478bd9Sstevel@tonic-gate #include <netinet/in.h>
50*7c478bd9Sstevel@tonic-gate #include <sys/socket.h>
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate /* RCSID("$Id: loginrec.h,v 1.6 2001/05/08 20:33:06 mouring Exp $"); */
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate /**
55*7c478bd9Sstevel@tonic-gate  ** you should use the login_* calls to work around platform dependencies
56*7c478bd9Sstevel@tonic-gate  **/
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate /*
59*7c478bd9Sstevel@tonic-gate  * login_netinfo structure
60*7c478bd9Sstevel@tonic-gate  */
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate union login_netinfo {
63*7c478bd9Sstevel@tonic-gate 	struct sockaddr sa;
64*7c478bd9Sstevel@tonic-gate 	struct sockaddr_in sa_in;
65*7c478bd9Sstevel@tonic-gate 	struct sockaddr_storage sa_storage;
66*7c478bd9Sstevel@tonic-gate };
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate /*
69*7c478bd9Sstevel@tonic-gate  *   * logininfo structure  *
70*7c478bd9Sstevel@tonic-gate  */
71*7c478bd9Sstevel@tonic-gate /* types - different to utmp.h 'type' macros */
72*7c478bd9Sstevel@tonic-gate /* (though set to the same value as linux, openbsd and others...) */
73*7c478bd9Sstevel@tonic-gate #define LTYPE_LOGIN    7
74*7c478bd9Sstevel@tonic-gate #define LTYPE_LOGOUT   8
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate /* string lengths - set very long */
77*7c478bd9Sstevel@tonic-gate #define LINFO_PROGSIZE 64
78*7c478bd9Sstevel@tonic-gate #define LINFO_LINESIZE 64
79*7c478bd9Sstevel@tonic-gate #define LINFO_NAMESIZE 64
80*7c478bd9Sstevel@tonic-gate #define LINFO_HOSTSIZE 256
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate struct logininfo {
83*7c478bd9Sstevel@tonic-gate 	int        progname_null;
84*7c478bd9Sstevel@tonic-gate 	char       progname[LINFO_PROGSIZE];     /* name of program (for PAM) */
85*7c478bd9Sstevel@tonic-gate 	short int  type;                         /* type of login (LTYPE_*) */
86*7c478bd9Sstevel@tonic-gate 	int        pid;                          /* PID of login process */
87*7c478bd9Sstevel@tonic-gate 	int        uid;                          /* UID of this user */
88*7c478bd9Sstevel@tonic-gate 	int        line_null;
89*7c478bd9Sstevel@tonic-gate 	char       line[LINFO_LINESIZE];         /* tty/pty name */
90*7c478bd9Sstevel@tonic-gate 	char       username[LINFO_NAMESIZE];     /* login username */
91*7c478bd9Sstevel@tonic-gate 	char       hostname[LINFO_HOSTSIZE];     /* remote hostname */
92*7c478bd9Sstevel@tonic-gate 	/* 'exit_status' structure components */
93*7c478bd9Sstevel@tonic-gate 	int        exit;                        /* process exit status */
94*7c478bd9Sstevel@tonic-gate 	int        termination;                 /* process termination status */
95*7c478bd9Sstevel@tonic-gate 	/* struct timeval (sys/time.h) isn't always available, if it isn't we'll
96*7c478bd9Sstevel@tonic-gate 	 * use time_t's value as tv_sec and set tv_usec to 0
97*7c478bd9Sstevel@tonic-gate 	 */
98*7c478bd9Sstevel@tonic-gate 	unsigned int tv_sec;
99*7c478bd9Sstevel@tonic-gate 	unsigned int tv_usec;
100*7c478bd9Sstevel@tonic-gate 	union login_netinfo hostaddr;       /* caller's host address(es) */
101*7c478bd9Sstevel@tonic-gate }; /* struct logininfo */
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate /*
104*7c478bd9Sstevel@tonic-gate  * login recording functions
105*7c478bd9Sstevel@tonic-gate  */
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate /** 'public' functions */
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate /* construct a new login entry */
110*7c478bd9Sstevel@tonic-gate struct logininfo *login_alloc_entry(int pid, const char *username,
111*7c478bd9Sstevel@tonic-gate 				    const char *hostname, const char *line,
112*7c478bd9Sstevel@tonic-gate 				    const char *progname);
113*7c478bd9Sstevel@tonic-gate /* free a structure */
114*7c478bd9Sstevel@tonic-gate void login_free_entry(struct logininfo *li);
115*7c478bd9Sstevel@tonic-gate /* fill out a pre-allocated structure with useful information */
116*7c478bd9Sstevel@tonic-gate int login_init_entry(struct logininfo *li, int pid, const char *username,
117*7c478bd9Sstevel@tonic-gate 		     const char *hostname, const char *line,
118*7c478bd9Sstevel@tonic-gate 		     const char *progname);
119*7c478bd9Sstevel@tonic-gate /* place the current time in a logininfo struct */
120*7c478bd9Sstevel@tonic-gate void login_set_current_time(struct logininfo *li);
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate /* record the entry */
123*7c478bd9Sstevel@tonic-gate int login_login (struct logininfo *li);
124*7c478bd9Sstevel@tonic-gate int login_logout(struct logininfo *li);
125*7c478bd9Sstevel@tonic-gate #ifdef LOGIN_NEEDS_UTMPX
126*7c478bd9Sstevel@tonic-gate int login_utmp_only(struct logininfo *li);
127*7c478bd9Sstevel@tonic-gate #endif
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate /** End of public functions */
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate /* record the entry */
132*7c478bd9Sstevel@tonic-gate int login_write (struct logininfo *li);
133*7c478bd9Sstevel@tonic-gate int login_log_entry(struct logininfo *li);
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate /* set the network address based on network address type */
136*7c478bd9Sstevel@tonic-gate void login_set_addr(struct logininfo *li, const struct sockaddr *sa,
137*7c478bd9Sstevel@tonic-gate 		    const unsigned int sa_size);
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate /*
140*7c478bd9Sstevel@tonic-gate  * lastlog retrieval functions
141*7c478bd9Sstevel@tonic-gate  */
142*7c478bd9Sstevel@tonic-gate /* lastlog *entry* functions fill out a logininfo */
143*7c478bd9Sstevel@tonic-gate struct logininfo *login_get_lastlog(struct logininfo *li, const int uid);
144*7c478bd9Sstevel@tonic-gate /* lastlog *time* functions return time_t equivalent (uint) */
145*7c478bd9Sstevel@tonic-gate unsigned int login_get_lastlog_time(const int uid);
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate /* produce various forms of the line filename */
148*7c478bd9Sstevel@tonic-gate char *line_fullname(char *dst, const char *src, int dstsize);
149*7c478bd9Sstevel@tonic-gate char *line_stripname(char *dst, const char *src, int dstsize);
150*7c478bd9Sstevel@tonic-gate char *line_abbrevname(char *dst, const char *src, int dstsize);
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
153*7c478bd9Sstevel@tonic-gate }
154*7c478bd9Sstevel@tonic-gate #endif
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate #endif /* _LOGINREC_H */
157