summaryrefslogtreecommitdiff
path: root/security/ssh/patches/patch-au
blob: 4c883c22ce071d2162bb152b398347dbffa9695d (plain)
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
$NetBSD: patch-au,v 1.7 2002/08/07 13:27:52 agc Exp $

--- login.c.orig	Wed May 12 07:19:26 1999
+++ login.c	Fri Dec 24 22:01:25 1999
@@ -117,6 +117,7 @@
 #include <hpsecurity.h>
 #include <prot.h>
 #endif /* HAVE_HPUX_TCB_AUTH */
+#include <sys/param.h>
 #include "ssh.h"
 
 /* Returns the time when the user last logged in.  Returns 0 if the 
@@ -271,7 +272,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,17 +317,21 @@
   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 0 /* XXX */
   if (addr)
     memcpy(&u.ut_addr, &addr->sin_addr, sizeof(u.ut_addr));
   else
+#endif /* XXX */
     memset(&u.ut_addr, 0, sizeof(u.ut_addr));
 #endif
 
@@ -462,8 +482,10 @@
         makeutx(&ux);
 #else
     pututxline(&ux);
+#ifdef WTMPX_FILE
     updwtmpx(WTMPX_FILE, &ux);
 #endif
+#endif
     endutxent();
   }
 #endif /* HAVE_UTMPX_H */
@@ -490,7 +512,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);