2 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 * Copyright (c) 2000 Andre Lucas. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
34 * loginrec.h: platform-independent login recording and lastlog retrieval
40 #pragma ident "%Z%%M% %I% %E% SMI"
48 #include <sys/types.h>
49 #include <netinet/in.h>
50 #include <sys/socket.h>
52 /* RCSID("$Id: loginrec.h,v 1.6 2001/05/08 20:33:06 mouring Exp $"); */
55 ** you should use the login_* calls to work around platform dependencies
59 * login_netinfo structure
64 struct sockaddr_in sa_in
;
65 struct sockaddr_storage sa_storage
;
69 * * logininfo structure *
71 /* types - different to utmp.h 'type' macros */
72 /* (though set to the same value as linux, openbsd and others...) */
74 #define LTYPE_LOGOUT 8
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
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 */
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
100 union login_netinfo hostaddr
; /* caller's host address(es) */
101 }; /* struct logininfo */
104 * login recording functions
107 /** 'public' functions */
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
);
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
);
129 /** End of public functions */
131 /* record the entry */
132 int login_write (struct logininfo
*li
);
133 int login_log_entry(struct logininfo
*li
);
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
);
140 * lastlog retrieval functions
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
);
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
);
156 #endif /* _LOGINREC_H */