1999-10-27 05:42:43 +02:00
|
|
|
/*
|
2000-04-16 03:18:38 +02:00
|
|
|
*
|
1999-11-24 14:26:21 +01:00
|
|
|
* login.c
|
2000-04-16 03:18:38 +02:00
|
|
|
*
|
1999-11-24 14:26:21 +01:00
|
|
|
* Author: Tatu Ylonen <ylo@cs.hut.fi>
|
2000-04-16 03:18:38 +02:00
|
|
|
*
|
1999-11-24 14:26:21 +01:00
|
|
|
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
|
|
|
|
* All rights reserved
|
2000-04-16 03:18:38 +02:00
|
|
|
*
|
1999-11-24 14:26:21 +01:00
|
|
|
* Created: Fri Mar 24 14:51:08 1995 ylo
|
2000-04-16 03:18:38 +02:00
|
|
|
*
|
1999-11-24 14:26:21 +01:00
|
|
|
* This file performs some of the things login(1) normally does. We cannot
|
|
|
|
* easily use something like login -p -h host -f user, because there are
|
|
|
|
* several different logins around, and it is hard to determined what kind of
|
|
|
|
* login the current system has. Also, we want to be able to execute commands
|
|
|
|
* on a tty.
|
2000-04-16 03:18:38 +02:00
|
|
|
*
|
1999-11-24 14:26:21 +01:00
|
|
|
*/
|
1999-10-27 05:42:43 +02:00
|
|
|
|
|
|
|
#include "includes.h"
|
2000-06-03 16:57:40 +02:00
|
|
|
RCSID("$Id: login.c,v 1.31 2000/06/03 14:57:40 andre Exp $");
|
1999-10-27 05:42:43 +02:00
|
|
|
|
2000-06-03 16:57:40 +02:00
|
|
|
#include "loginrec.h"
|
2000-05-31 03:20:11 +02:00
|
|
|
|
1999-11-25 01:54:57 +01:00
|
|
|
/*
|
|
|
|
* Returns the time when the user last logged in. Returns 0 if the
|
|
|
|
* information is not available. This must be called before record_login.
|
|
|
|
* The host the user logged in from will be returned in buf.
|
|
|
|
*/
|
1999-10-27 05:42:43 +02:00
|
|
|
|
2000-04-16 03:18:38 +02:00
|
|
|
unsigned long
|
1999-11-24 14:26:21 +01:00
|
|
|
get_last_login_time(uid_t uid, const char *logname,
|
|
|
|
char *buf, unsigned int bufsize)
|
1999-10-27 05:42:43 +02:00
|
|
|
{
|
2000-06-03 16:57:40 +02:00
|
|
|
struct logininfo li;
|
1999-12-21 01:18:08 +01:00
|
|
|
|
2000-06-03 16:57:40 +02:00
|
|
|
login_getlastentry_uid(&li, uid);
|
|
|
|
strncpy(buf, li.hostname, bufsize);
|
|
|
|
return li.tv_sec;
|
1999-10-27 05:42:43 +02:00
|
|
|
}
|
|
|
|
|
1999-11-25 01:54:57 +01:00
|
|
|
/*
|
2000-06-03 16:57:40 +02:00
|
|
|
* Records that the user has logged in. I these parts of operating systems
|
|
|
|
* were more standardized.
|
1999-11-25 01:54:57 +01:00
|
|
|
*/
|
2000-06-03 16:57:40 +02:00
|
|
|
|
2000-04-16 03:18:38 +02:00
|
|
|
void
|
2000-04-19 23:42:21 +02:00
|
|
|
record_login(pid_t pid, const char *ttyname, const char *user, uid_t uid,
|
2000-01-14 05:45:46 +01:00
|
|
|
const char *host, struct sockaddr * addr)
|
1999-10-27 05:42:43 +02:00
|
|
|
{
|
2000-06-03 16:57:40 +02:00
|
|
|
struct logininfo *li;
|
1999-10-27 05:42:43 +02:00
|
|
|
|
2000-06-03 16:57:40 +02:00
|
|
|
li = login_alloc_entry(pid, user, host, ttyname);
|
|
|
|
login_set_ip4(li, (struct sockaddr_in *)addr);
|
|
|
|
login_login(li);
|
|
|
|
login_free_entry(li);
|
1999-10-27 05:42:43 +02:00
|
|
|
}
|
1999-11-24 14:26:21 +01:00
|
|
|
|
|
|
|
/* Records that the user has logged out. */
|
|
|
|
|
2000-04-16 03:18:38 +02:00
|
|
|
void
|
2000-04-19 23:42:21 +02:00
|
|
|
record_logout(pid_t pid, const char *ttyname)
|
1999-10-27 05:42:43 +02:00
|
|
|
{
|
2000-06-03 16:57:40 +02:00
|
|
|
struct logininfo *li;
|
|
|
|
|
|
|
|
li = login_alloc_entry(pid, NULL, NULL, ttyname);
|
|
|
|
login_logout(li);
|
|
|
|
login_free_entry(li);
|
1999-10-27 05:42:43 +02:00
|
|
|
}
|