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