blob: 9d5bd6a2688e55620e2f8b47d93a31c6570aa0fa [file] [log] [blame]
andre2ff7b5d2000-06-03 14:57:40 +00001#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 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Markus Friedl.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33/**
34 ** loginrec.h: platform-independent login recording and lastlog retrieval
35 **/
36
37#include "includes.h"
38
39#include <sys/types.h>
40#include <netinet/in.h>
41#include <sys/socket.h>
42
andre6bb92372000-06-19 08:20:03 +000043/* RCSID("$Id: loginrec.h,v 1.3 2000/06/19 08:20:03 andre Exp $"); */
andre2ff7b5d2000-06-03 14:57:40 +000044
45/**
46 ** you should use the login_* calls to work around platform dependencies
47 **/
48
andre2ff7b5d2000-06-03 14:57:40 +000049/*
50 * login_netinfo structure
51 */
52
andre61e67252000-06-04 17:07:49 +000053union login_netinfo {
54 struct sockaddr sa;
55 struct sockaddr_in sa_in;
56 struct sockaddr_storage sa_storage;
57};
andre2ff7b5d2000-06-03 14:57:40 +000058
59
60/*
61 * * logininfo structure *
62 */
63
64/* types - different to utmp.h 'type' macros */
65/* (though set to the same value as linux, openbsd and others...) */
66#define LTYPE_LOGIN 7
67#define LTYPE_LOGOUT 8
68
69/* string lengths - set very long */
70#define LINFO_PROGSIZE 64
71#define LINFO_LINESIZE 64
72#define LINFO_NAMESIZE 64
73#define LINFO_HOSTSIZE 256
74
75struct logininfo {
76
77 char progname[LINFO_PROGSIZE]; /* name of program (for PAM) */
78 int progname_null;
79
80 short int type; /* type of login (LTYPE_*) */
81
82 int pid; /* PID of login process */
83 int uid; /* UID of this user */
84 char line[LINFO_LINESIZE]; /* tty/pty name */
85 char username[LINFO_NAMESIZE]; /* login username */
86 char hostname[LINFO_HOSTSIZE]; /* remote hostname */
87
88 /* 'exit_status' structure components */
89 int exit; /* process exit status */
90 int termination; /* process termination status */
91
92 /* struct timeval (sys/time.h) isn't always available, if it isn't we'll
93 * use time_t's value as tv_sec and set tv_usec to 0
94 */
95 unsigned int tv_sec;
96 unsigned int tv_usec;
97
andre61e67252000-06-04 17:07:49 +000098 union login_netinfo hostaddr; /* caller's host address(es) */
andre2ff7b5d2000-06-03 14:57:40 +000099}; /* struct logininfo */
100
101
102/*
103 * login recording functions
104 */
andre6bb92372000-06-19 08:20:03 +0000105
106/** 'public' functions */
107
andre2ff7b5d2000-06-03 14:57:40 +0000108/* construct a new login entry */
andre61e67252000-06-04 17:07:49 +0000109struct logininfo *login_alloc_entry(int pid, const char *username,
andre2ff7b5d2000-06-03 14:57:40 +0000110 const char *hostname, const char *line);
andre61e67252000-06-04 17:07:49 +0000111/* free a structure */
andre2ff7b5d2000-06-03 14:57:40 +0000112void login_free_entry(struct logininfo *li);
andre61e67252000-06-04 17:07:49 +0000113/* fill out a pre-allocated structure with useful information */
114int login_init_entry(struct logininfo *li, int pid, const char *username,
115 const char *hostname, const char *line);
116/* place the current time in a logininfo struct */
andre2ff7b5d2000-06-03 14:57:40 +0000117void login_set_current_time(struct logininfo *li);
andre61e67252000-06-04 17:07:49 +0000118
andre6bb92372000-06-19 08:20:03 +0000119/* record the entry */
120int login_login (struct logininfo *li);
121int login_logout(struct logininfo *li);
122
123/** End of public functions */
andre61e67252000-06-04 17:07:49 +0000124
andre2ff7b5d2000-06-03 14:57:40 +0000125/* record the entry */
126int login_write (struct logininfo *li);
andre2ff7b5d2000-06-03 14:57:40 +0000127int login_log_entry(struct logininfo *li);
128
andre6bb92372000-06-19 08:20:03 +0000129/* set the network address based on network address type */
130void login_set_addr(struct logininfo *li, const struct sockaddr *sa,
131 const unsigned int sa_size);
132
andre2ff7b5d2000-06-03 14:57:40 +0000133/*
andre61e67252000-06-04 17:07:49 +0000134 * lastlog retrieval functions
andre2ff7b5d2000-06-03 14:57:40 +0000135 */
136/* lastlog *entry* functions fill out a logininfo */
andre61e67252000-06-04 17:07:49 +0000137struct logininfo *login_get_lastlog(struct logininfo *li, const int uid);
andre2ff7b5d2000-06-03 14:57:40 +0000138/* lastlog *time* functions return time_t equivalent (uint) */
andre61e67252000-06-04 17:07:49 +0000139unsigned int login_get_lastlog_time(const int uid);
andre2ff7b5d2000-06-03 14:57:40 +0000140
141/* produce various forms of the line filename */
142char *line_fullname(char *dst, const char *src, int dstsize);
143char *line_stripname(char *dst, const char *src, int dstsize);
144char *line_abbrevname(char *dst, const char *src, int dstsize);
145
146
147#endif /* _HAVE_LOGINREC_H_ */
148