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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
$NetBSD: patch-al,v 1.8 2020/08/02 10:59:13 kim Exp $
Make extra calls to remove utmp entries when utmpx is used.
For non-login entries we only update utmpx, as it stores
more information, and utilities are reading both.
Do not truncate hostnames that have two colons (:) as they
are likely IPv6 addresses. Wrap them in brackets ([])
unless already wrapped (e.g. from $DISPLAY).
--- utmp.c.orig 2016-06-19 19:41:03.000000000 +0000
+++ utmp.c
@@ -48,6 +48,12 @@ extern char *LoginName;
extern int real_uid, eff_uid;
+#ifdef NetBSD_UTMP
+extern void utmp_login __P((char *));
+extern void utmp_logout __P((char *));
+#endif
+
+
/*
* UTNOKEEP: A (ugly) hack for apollo that does two things:
* 1) Always close and reopen the utmp file descriptor. (I don't know
@@ -315,6 +321,9 @@ RemoveLoginSlot()
ASSERT(display);
debug("RemoveLoginSlot: removing your logintty\n");
+#ifdef NetBSD_UTMP
+ utmp_logout(stripdev(D_usertty));
+#endif
D_loginslot = TtyNameSlot(D_usertty);
if (D_loginslot == (slot_t)0 || D_loginslot == (slot_t)-1)
return;
@@ -379,6 +388,9 @@ RestoreLoginSlot()
debug("RestoreLoginSlot()\n");
ASSERT(display);
+#ifdef NetBSD_UTMP
+ utmp_login(stripdev(D_usertty));
+#endif
if (utmpok && D_loginslot != (slot_t)0 && D_loginslot != (slot_t)-1)
{
debug1(" logging you in again (slot %#x)\n", (int)D_loginslot);
@@ -410,7 +422,7 @@ struct win *wi;
struct utmp u;
int saved_ut;
#ifdef UTHOST
- char *p;
+ char *m, *p;
char host[sizeof(D_loginhost) + 15];
#else
char *host = 0;
@@ -449,12 +461,37 @@ struct win *wi;
* "faui45.informati"......:s.0
* HPUX uses host:0.0, so chop at "." and ":" (Eric Backus)
*/
- for (p = host; *p; p++)
- if ((*p < '0' || *p > '9') && (*p != '.'))
+ for (m = p = host; *p; p++)
+ if (*p == ':')
break;
+ if (*p == ':')
+ for (m = p + 1; *m; m++)
+ if (*m == ':')
+ {
+ if (host[0] != '[')
+ {
+ strncpy(host + 1, D_loginhost, sizeof(host) - 15 - 2);
+ host[0] = '[';
+ p = host + strlen(host);
+ *p++ = ']';
+ }
+ break;
+ }
+ else
+ for (p = host; *p; p++)
+ if ((*p < '0' || *p > '9') && (*p != '.'))
+ break;
if (*p)
{
- for (p = host; *p; p++)
+ p = host;
+ if (host[0] == '[')
+ for (; *p; p++)
+ if (*p == ']')
+ {
+ p++;
+ break;
+ }
+ for (; *p; p++)
if (*p == '.' || (*p == ':' && p != host))
{
*p = '\0';
|