aboutsummaryrefslogtreecommitdiffstats
path: root/sysutils/su2/files/patch-su2.c_2
blob: 8dae9239b519e8d015e5df6f27000301b4f0680c (plain) (blame)
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
--- su2.c.orig  2012-02-08 01:48:13.000000000 +0400
+++ su2.c   2012-02-08 02:22:42.000000000 +0400
@@ -151,7 +151,12 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <time.h>
+#include <osreldate.h>
+#if defined(__FreeBSD_version) && __FreeBSD_version >= 900007
+#include <utmpx.h>
+#else
 #include <utmp.h>
+#endif
 #include <signal.h>
 #ifdef IOCTL
 #include <sys/ioctl.h>
@@ -383,7 +388,12 @@
     if (FullTTY == (char *) 0)
    FullTTY = "/dev/TTY??";
 
-    TTY = strrchr (FullTTY, '/') + 1;
+    TTY = FullTTY + strlen(FullTTY);
+    while (TTY > FullTTY) {
+        if (TTY[-1] == '/' && (TTY[0] > 57 || TTY[0] < 48))
+            break;
+        TTY--;
+    }
 
     Debug (1, "-> FullTTY=\"%s\"\n", FullTTY);
     Debug (1, "-> TTY=\"%s\"\n", TTY);
@@ -1315,7 +1325,11 @@
  * Copies name into an internal static buffer.
  */
 
+#if __FreeBSD_version >= 900007
+#define MAXNAME sizeof(((struct utmpx *)nptr)->ut_user)
+#else
 #define MAXNAME sizeof(((struct utmp *)nptr)->ut_name)
+#endif
 
 #ifdef BROKENCUSERID
 char *mycuserid ()
@@ -1432,6 +1446,24 @@
 ModifyUtmp (NewUserName)
 register char  *NewUserName;
 {
+#if __FreeBSD_version >= 900007
+    struct utmpx ut, *utr;
+
+    strncpy(ut.ut_line, TTY, sizeof(ut.ut_line));
+    setutxent();
+    if ((utr = getutxline(&ut)) == NULL) {
+        endutxent();
+        (void) fprintf (stderr, "Terminal %s not found\n", ut.ut_line);
+        return (1);
+    }
+    strncpy(utr->ut_user, NewUserName, sizeof(utr->ut_user));
+    if (pututxline(utr) == NULL) {
+        endutxent();
+        (void) fprintf (stderr, "pututxline failed\n");
+        return (1);
+    }
+    endutxent();
+#else
     register int    fd;        /* /etc/utmp file */
     register int    i;     /* index */
 #ifdef hpux
@@ -1482,6 +1514,7 @@
 
     (void) write (fd, (char *) & Utmp, sizeof (Utmp));
     (void) close (fd);
+#endif
     return (0);
 }