1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
$NetBSD: patch-au,v 1.3 1999/12/01 20:48:35 bouyer Exp $
--- login.c.orig Wed May 12 07:19:26 1999
+++ login.c Sat Sep 18 17:03:20 1999
@@ -271,7 +271,22 @@
struct utmp u, u2;
off_t offset;
const char *utmp, *wtmp;
+#endif
+#if defined(HAVE_HOST_IN_UTMP) || defined(HAVE_LASTLOG_H) || defined(HAVE_LASTLOG)
+ char myname[MAXHOSTNAMELEN];
+ char shost[MAXHOSTNAMELEN];
+ char *p = NULL, *q = NULL;
+
+ memset(shost, 0, sizeof(shost));
+ gethostname(myname, MAXHOSTNAMELEN);
+ if (((p = memchr(myname, '.', MAXHOSTNAMELEN)) != NULL)
+ && ((q = strchr(host, '.')) != NULL)
+ && (strncmp(p, q, MAXHOSTNAMELEN - (p - myname)) == 0)) {
+ strncpy(shost, host, q - host);
+ }
+#endif
+#if defined(HAVE_UTMP_H) && !defined(HAVE_UTMPX_H)
/* Construct an utmp/wtmp entry. */
memset(&u, 0, sizeof(u));
#ifdef DEAD_PROCESS
@@ -301,12 +316,14 @@
strncpy(u.ut_user, user, sizeof(u.ut_user));
#endif /* HAVE_NAME_IN_UTMP */
#ifdef HAVE_HOST_IN_UTMP
- strncpy(u.ut_host, host, sizeof(u.ut_host));
-#ifdef __FreeBSD__
- if (strlen(host) > sizeof(u.ut_host)) {
+ if ((*shost != '\0') && (strlen(shost) <= sizeof(u.ut_host)))
+ strncpy(u.ut_host, shost, sizeof(u.ut_host));
+#ifndef HAVE_ADDR_IN_UTMP
+ else if (strlen(host) > sizeof(u.ut_host))
strncpy(u.ut_host, get_remote_ipaddr(), sizeof(u.ut_host));
- }
-#endif /* __FreeBSD__ */
+#endif /* HAVE_ADDR_IN_UTMP */
+ else
+ strncpy(u.ut_host, host, sizeof(u.ut_host));
#endif /* HAVE_HOST_IN_UTMP */
#ifdef HAVE_ADDR_IN_UTMP
if (addr)
@@ -490,7 +507,12 @@
/* Update lastlog. */
ll.ll_time = time(NULL);
strncpy(ll.ll_line, ttyname + 5, sizeof(ll.ll_line));
- strncpy(ll.ll_host, host, sizeof(ll.ll_host));
+ if ((*shost != '\0') && (strlen(shost) <= sizeof(ll.ll_host)))
+ strncpy(ll.ll_host, shost, sizeof(ll.ll_host));
+ else if (strlen(host) > sizeof(ll.ll_host))
+ strncpy(ll.ll_host, get_remote_ipaddr(), sizeof(ll.ll_host));
+ else
+ strncpy(ll.ll_host, host, sizeof(ll.ll_host));
#ifdef LASTLOG_IS_DIR
snprintf(lastlogfile, sizeof(lastlogfile),
"%.100s/%.100s", lastlog, user);
|