blob: 4fe24ac2a6824a821d9fdd083f06301ba211e25d [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.
andre2ff7b5d2000-06-03 14:57:40 +000015 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
Kevin Stevesef4eea92001-02-05 12:42:17 +000028/**
andre2ff7b5d2000-06-03 14:57:40 +000029 ** loginrec.h: platform-independent login recording and lastlog retrieval
30 **/
31
32#include "includes.h"
33
34#include <sys/types.h>
35#include <netinet/in.h>
36#include <sys/socket.h>
37
andre2ff7b5d2000-06-03 14:57:40 +000038/**
39 ** you should use the login_* calls to work around platform dependencies
40 **/
41
andre2ff7b5d2000-06-03 14:57:40 +000042/*
43 * login_netinfo structure
44 */
45
andre61e67252000-06-04 17:07:49 +000046union login_netinfo {
47 struct sockaddr sa;
48 struct sockaddr_in sa_in;
49 struct sockaddr_storage sa_storage;
50};
andre2ff7b5d2000-06-03 14:57:40 +000051
andre2ff7b5d2000-06-03 14:57:40 +000052/*
53 * * logininfo structure *
54 */
andre2ff7b5d2000-06-03 14:57:40 +000055/* types - different to utmp.h 'type' macros */
56/* (though set to the same value as linux, openbsd and others...) */
57#define LTYPE_LOGIN 7
58#define LTYPE_LOGOUT 8
59
60/* string lengths - set very long */
61#define LINFO_PROGSIZE 64
62#define LINFO_LINESIZE 64
Darren Tucker33bc3342005-01-20 22:07:29 +110063#define LINFO_NAMESIZE 128
andre2ff7b5d2000-06-03 14:57:40 +000064#define LINFO_HOSTSIZE 256
65
66struct logininfo {
andre2ff7b5d2000-06-03 14:57:40 +000067 char progname[LINFO_PROGSIZE]; /* name of program (for PAM) */
68 int progname_null;
andre2ff7b5d2000-06-03 14:57:40 +000069 short int type; /* type of login (LTYPE_*) */
andre2ff7b5d2000-06-03 14:57:40 +000070 int pid; /* PID of login process */
71 int uid; /* UID of this user */
72 char line[LINFO_LINESIZE]; /* tty/pty name */
73 char username[LINFO_NAMESIZE]; /* login username */
74 char hostname[LINFO_HOSTSIZE]; /* remote hostname */
andre2ff7b5d2000-06-03 14:57:40 +000075 /* 'exit_status' structure components */
76 int exit; /* process exit status */
77 int termination; /* process termination status */
andre2ff7b5d2000-06-03 14:57:40 +000078 /* struct timeval (sys/time.h) isn't always available, if it isn't we'll
79 * use time_t's value as tv_sec and set tv_usec to 0
80 */
81 unsigned int tv_sec;
Kevin Stevesef4eea92001-02-05 12:42:17 +000082 unsigned int tv_usec;
andre61e67252000-06-04 17:07:49 +000083 union login_netinfo hostaddr; /* caller's host address(es) */
andre2ff7b5d2000-06-03 14:57:40 +000084}; /* struct logininfo */
85
andre2ff7b5d2000-06-03 14:57:40 +000086/*
87 * login recording functions
88 */
andre6bb92372000-06-19 08:20:03 +000089
90/** 'public' functions */
91
andre2ff7b5d2000-06-03 14:57:40 +000092/* construct a new login entry */
andre61e67252000-06-04 17:07:49 +000093struct logininfo *login_alloc_entry(int pid, const char *username,
andre2ff7b5d2000-06-03 14:57:40 +000094 const char *hostname, const char *line);
andre61e67252000-06-04 17:07:49 +000095/* free a structure */
andre2ff7b5d2000-06-03 14:57:40 +000096void login_free_entry(struct logininfo *li);
andre61e67252000-06-04 17:07:49 +000097/* fill out a pre-allocated structure with useful information */
Kevin Stevesef4eea92001-02-05 12:42:17 +000098int login_init_entry(struct logininfo *li, int pid, const char *username,
andre61e67252000-06-04 17:07:49 +000099 const char *hostname, const char *line);
100/* place the current time in a logininfo struct */
andre2ff7b5d2000-06-03 14:57:40 +0000101void login_set_current_time(struct logininfo *li);
andre61e67252000-06-04 17:07:49 +0000102
andre6bb92372000-06-19 08:20:03 +0000103/* record the entry */
104int login_login (struct logininfo *li);
105int login_logout(struct logininfo *li);
Ben Lindstrom97c677d2001-05-08 20:33:05 +0000106#ifdef LOGIN_NEEDS_UTMPX
107int login_utmp_only(struct logininfo *li);
108#endif
andre6bb92372000-06-19 08:20:03 +0000109
110/** End of public functions */
andre61e67252000-06-04 17:07:49 +0000111
andre2ff7b5d2000-06-03 14:57:40 +0000112/* record the entry */
113int login_write (struct logininfo *li);
andre2ff7b5d2000-06-03 14:57:40 +0000114int login_log_entry(struct logininfo *li);
115
andre6bb92372000-06-19 08:20:03 +0000116/* set the network address based on network address type */
117void login_set_addr(struct logininfo *li, const struct sockaddr *sa,
118 const unsigned int sa_size);
119
andre2ff7b5d2000-06-03 14:57:40 +0000120/*
andre61e67252000-06-04 17:07:49 +0000121 * lastlog retrieval functions
andre2ff7b5d2000-06-03 14:57:40 +0000122 */
123/* lastlog *entry* functions fill out a logininfo */
andre61e67252000-06-04 17:07:49 +0000124struct logininfo *login_get_lastlog(struct logininfo *li, const int uid);
andre2ff7b5d2000-06-03 14:57:40 +0000125/* lastlog *time* functions return time_t equivalent (uint) */
andre61e67252000-06-04 17:07:49 +0000126unsigned int login_get_lastlog_time(const int uid);
andre2ff7b5d2000-06-03 14:57:40 +0000127
128/* produce various forms of the line filename */
Damien Miller52c8afe2005-06-19 10:19:43 +1000129char *line_fullname(char *dst, const char *src, u_int dstsize);
andre2ff7b5d2000-06-03 14:57:40 +0000130char *line_stripname(char *dst, const char *src, int dstsize);
131char *line_abbrevname(char *dst, const char *src, int dstsize);
132
Darren Tucker42d9dc72005-02-02 17:10:11 +1100133void record_failed_login(const char *, const char *, const char *);
134
andre2ff7b5d2000-06-03 14:57:40 +0000135#endif /* _HAVE_LOGINREC_H_ */