198937Sdes#ifndef _HAVE_LOGINREC_H_ 298937Sdes#define _HAVE_LOGINREC_H_ 398937Sdes 498937Sdes/* 598937Sdes * Copyright (c) 2000 Andre Lucas. All rights reserved. 698937Sdes * 798937Sdes * Redistribution and use in source and binary forms, with or without 898937Sdes * modification, are permitted provided that the following conditions 998937Sdes * are met: 1098937Sdes * 1. Redistributions of source code must retain the above copyright 1198937Sdes * notice, this list of conditions and the following disclaimer. 1298937Sdes * 2. Redistributions in binary form must reproduce the above copyright 1398937Sdes * notice, this list of conditions and the following disclaimer in the 1498937Sdes * documentation and/or other materials provided with the distribution. 1598937Sdes * 1698937Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1798937Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1898937Sdes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1998937Sdes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2098937Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2198937Sdes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2298937Sdes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2398937Sdes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2498937Sdes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2598937Sdes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2698937Sdes */ 2798937Sdes 2898937Sdes/** 2998937Sdes ** loginrec.h: platform-independent login recording and lastlog retrieval 3098937Sdes **/ 3198937Sdes 3298937Sdes#include "includes.h" 3398937Sdes 3498937Sdes/** 3598937Sdes ** you should use the login_* calls to work around platform dependencies 3698937Sdes **/ 3798937Sdes 3898937Sdes/* 3998937Sdes * login_netinfo structure 4098937Sdes */ 4198937Sdes 4298937Sdesunion login_netinfo { 4398937Sdes struct sockaddr sa; 4498937Sdes struct sockaddr_in sa_in; 4598937Sdes struct sockaddr_storage sa_storage; 4698937Sdes}; 4798937Sdes 4898937Sdes/* 4998937Sdes * * logininfo structure * 5098937Sdes */ 5198937Sdes/* types - different to utmp.h 'type' macros */ 5298937Sdes/* (though set to the same value as linux, openbsd and others...) */ 5398937Sdes#define LTYPE_LOGIN 7 5498937Sdes#define LTYPE_LOGOUT 8 5598937Sdes 5698937Sdes/* string lengths - set very long */ 5798937Sdes#define LINFO_PROGSIZE 64 5898937Sdes#define LINFO_LINESIZE 64 59215116Sdes#define LINFO_NAMESIZE 512 6098937Sdes#define LINFO_HOSTSIZE 256 6198937Sdes 6298937Sdesstruct logininfo { 6398937Sdes char progname[LINFO_PROGSIZE]; /* name of program (for PAM) */ 6498937Sdes int progname_null; 6598937Sdes short int type; /* type of login (LTYPE_*) */ 66221420Sdes pid_t pid; /* PID of login process */ 67221420Sdes uid_t uid; /* UID of this user */ 6898937Sdes char line[LINFO_LINESIZE]; /* tty/pty name */ 6998937Sdes char username[LINFO_NAMESIZE]; /* login username */ 7098937Sdes char hostname[LINFO_HOSTSIZE]; /* remote hostname */ 7198937Sdes /* 'exit_status' structure components */ 7298937Sdes int exit; /* process exit status */ 7398937Sdes int termination; /* process termination status */ 7498937Sdes /* struct timeval (sys/time.h) isn't always available, if it isn't we'll 7598937Sdes * use time_t's value as tv_sec and set tv_usec to 0 7698937Sdes */ 7798937Sdes unsigned int tv_sec; 7898937Sdes unsigned int tv_usec; 7998937Sdes union login_netinfo hostaddr; /* caller's host address(es) */ 8098937Sdes}; /* struct logininfo */ 8198937Sdes 8298937Sdes/* 8398937Sdes * login recording functions 8498937Sdes */ 8598937Sdes 8698937Sdes/** 'public' functions */ 8798937Sdes 8898937Sdes/* construct a new login entry */ 89221420Sdesstruct logininfo *login_alloc_entry(pid_t pid, const char *username, 9098937Sdes const char *hostname, const char *line); 9198937Sdes/* free a structure */ 9298937Sdesvoid login_free_entry(struct logininfo *li); 9398937Sdes/* fill out a pre-allocated structure with useful information */ 94221420Sdesint login_init_entry(struct logininfo *li, pid_t pid, const char *username, 9598937Sdes const char *hostname, const char *line); 9698937Sdes/* place the current time in a logininfo struct */ 9798937Sdesvoid login_set_current_time(struct logininfo *li); 9898937Sdes 9998937Sdes/* record the entry */ 10098937Sdesint login_login (struct logininfo *li); 10198937Sdesint login_logout(struct logininfo *li); 10298937Sdes#ifdef LOGIN_NEEDS_UTMPX 10398937Sdesint login_utmp_only(struct logininfo *li); 10498937Sdes#endif 10598937Sdes 10698937Sdes/** End of public functions */ 10798937Sdes 10898937Sdes/* record the entry */ 10998937Sdesint login_write (struct logininfo *li); 11098937Sdesint login_log_entry(struct logininfo *li); 11198937Sdes 11298937Sdes/* set the network address based on network address type */ 11398937Sdesvoid login_set_addr(struct logininfo *li, const struct sockaddr *sa, 11498937Sdes const unsigned int sa_size); 11598937Sdes 11698937Sdes/* 11798937Sdes * lastlog retrieval functions 11898937Sdes */ 11998937Sdes/* lastlog *entry* functions fill out a logininfo */ 120221420Sdesstruct logininfo *login_get_lastlog(struct logininfo *li, const uid_t uid); 12198937Sdes/* lastlog *time* functions return time_t equivalent (uint) */ 122221420Sdesunsigned int login_get_lastlog_time(const uid_t uid); 12398937Sdes 12498937Sdes/* produce various forms of the line filename */ 125149749Sdeschar *line_fullname(char *dst, const char *src, u_int dstsize); 12698937Sdeschar *line_stripname(char *dst, const char *src, int dstsize); 12798937Sdeschar *line_abbrevname(char *dst, const char *src, int dstsize); 12898937Sdes 129146998Sdesvoid record_failed_login(const char *, const char *, const char *); 130146998Sdes 13198937Sdes#endif /* _HAVE_LOGINREC_H_ */ 132