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