]>
Commit | Line | Data |
---|---|---|
8efc0c15 | 1 | /* |
6ae2364d | 2 | * |
5260325f | 3 | * login.c |
6ae2364d | 4 | * |
5260325f | 5 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
6ae2364d | 6 | * |
5260325f | 7 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
8 | * All rights reserved | |
6ae2364d | 9 | * |
5260325f | 10 | * Created: Fri Mar 24 14:51:08 1995 ylo |
6ae2364d | 11 | * |
5260325f | 12 | * This file performs some of the things login(1) normally does. We cannot |
13 | * easily use something like login -p -h host -f user, because there are | |
14 | * several different logins around, and it is hard to determined what kind of | |
15 | * login the current system has. Also, we want to be able to execute commands | |
16 | * on a tty. | |
6ae2364d | 17 | * |
5260325f | 18 | */ |
8efc0c15 | 19 | |
20 | #include "includes.h" | |
21 | RCSID("$Id$"); | |
22 | ||
1d7b9b20 | 23 | #include "loginrec.h" |
5daf7064 | 24 | |
aa3378df | 25 | /* |
26 | * Returns the time when the user last logged in. Returns 0 if the | |
27 | * information is not available. This must be called before record_login. | |
28 | * The host the user logged in from will be returned in buf. | |
29 | */ | |
8efc0c15 | 30 | |
6ae2364d | 31 | unsigned long |
5260325f | 32 | get_last_login_time(uid_t uid, const char *logname, |
33 | char *buf, unsigned int bufsize) | |
8efc0c15 | 34 | { |
1d7b9b20 | 35 | struct logininfo li; |
a7effaac | 36 | |
1d7b9b20 | 37 | login_getlastentry_uid(&li, uid); |
38 | strncpy(buf, li.hostname, bufsize); | |
39 | return li.tv_sec; | |
8efc0c15 | 40 | } |
41 | ||
aa3378df | 42 | /* |
1d7b9b20 | 43 | * Records that the user has logged in. I these parts of operating systems |
44 | * were more standardized. | |
aa3378df | 45 | */ |
1d7b9b20 | 46 | |
6ae2364d | 47 | void |
9da5c3c9 | 48 | record_login(pid_t pid, const char *ttyname, const char *user, uid_t uid, |
48e671d5 | 49 | const char *host, struct sockaddr * addr) |
8efc0c15 | 50 | { |
1d7b9b20 | 51 | struct logininfo *li; |
8efc0c15 | 52 | |
1d7b9b20 | 53 | li = login_alloc_entry(pid, user, host, ttyname); |
54 | login_set_ip4(li, (struct sockaddr_in *)addr); | |
55 | login_login(li); | |
56 | login_free_entry(li); | |
8efc0c15 | 57 | } |
5260325f | 58 | |
59 | /* Records that the user has logged out. */ | |
60 | ||
6ae2364d | 61 | void |
9da5c3c9 | 62 | record_logout(pid_t pid, const char *ttyname) |
8efc0c15 | 63 | { |
1d7b9b20 | 64 | struct logininfo *li; |
65 | ||
66 | li = login_alloc_entry(pid, NULL, NULL, ttyname); | |
67 | login_logout(li); | |
68 | login_free_entry(li); | |
8efc0c15 | 69 | } |