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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
Description: Stop using utmp, migrate to wtmp.
The old utmp-implementation is buggy since it
corrupts /var/run/wtmp. A standardized use of
logwtmp() is much securer and more common.
.
Built successfully against 1.6.6-9.
Author: Mats Erik Andersson <debian@gisladisker.se>
Last-Update: 2011-03-23
Forwarded: no
--- a/config.c
+++ b/config.c
@@ -120,6 +120,7 @@
/* Check for the ut_host field in the utmp file */
if ( grep(INCLUDE, "utmp.h", "ut_host") ) {
strcat(cflags, " -DHAVE_UTHOST");
+ strcat(ldflags, " -lutil");
VERBOSE_PRINT("\tYour utmp file uses the host field.\n");
}
--- a/splitvt.c
+++ b/splitvt.c
@@ -298,7 +298,6 @@
signal(SIGCLD, SIG_IGN);
#endif
- (void) remove_me();
if ( (topfd=pty_open(upper_args, &toppid, UPPER)) < 0 )
{
end_vt100();
@@ -638,8 +637,11 @@
if ( topok )
if ( kill(toppid, 0) < 0 )
{
- if ( pw )
+ if ( pw && upper_tty[0])
+ {
(void) delutmp(pw->pw_name, upper_tty);
+ upper_tty[0] = '\0';
+ }
if ( thisfd == topfd )
thisfd=bottomfd;
(void) close(topfd);
@@ -650,8 +652,11 @@
if ( bottomok )
if ( kill(bottompid, 0) < 0 )
{
- if ( pw )
+ if ( pw && lower_tty[0])
+ {
(void) delutmp(pw->pw_name, lower_tty);
+ lower_tty[0] = '\0';
+ }
if ( thisfd == bottomfd )
thisfd=topfd;
(void) close(bottomfd);
@@ -667,8 +672,11 @@
if ( topok )
if ( waitpid(toppid, &status, WNOHANG) != 0 )
{
- if ( pw )
+ if ( pw && upper_tty[0])
+ {
(void) delutmp(pw->pw_name, upper_tty);
+ upper_tty[0] = '\0';
+ }
if ( thisfd == topfd )
thisfd=bottomfd;
(void) close(topfd);
@@ -679,8 +687,11 @@
if ( bottomok )
if ( waitpid(bottompid, &status, WNOHANG) != 0 )
{
- if ( pw )
+ if ( pw && lower_tty[0])
+ {
(void) delutmp(pw->pw_name, lower_tty);
+ lower_tty[0] = '\0';
+ }
if ( thisfd == bottomfd )
thisfd=topfd;
(void) close(bottomfd);
@@ -712,7 +723,6 @@
(void) delutmp(pw->pw_name, upper_tty);
if ( pw && bottomok && lower_tty[0] )
(void) delutmp(pw->pw_name, lower_tty);
- (void) replace_me();
if ( sig )
printf("Exiting due to signal: %d\n", sig);
--- a/utmp.c
+++ b/utmp.c
@@ -172,7 +172,9 @@
/* Retrieve any existing utmp entry */
d_zero((char *)&ut, sizeof(ut));
+#if 0 /* Outdated */
(void) get_utmp(tty, &ut);
+#endif /* Outdated */
/* Get the ttyxy form of the tty pathname if possible. */
if ( *tty == '/' ) {
@@ -195,11 +197,15 @@
ut.ut_pid=getpid();
#endif
#if defined(HAVE_UTHOST)
+# if 0 /* Outdated */
/* remove_me() should be called before this function */
if ( utmp_saved ) {
strncpy(ut.ut_host, saved_utmp.ut_host, sizeof(ut.ut_host)-1);
ut.ut_host[sizeof(ut.ut_host)-1]='\0';
}
+# else /* Portable and fun. */
+ strncpy(ut.ut_host, "splitvt", 8);
+# endif
#endif
#if __WORDSIZE == 64 && __WORDSIZE_COMPAT32
/* 'time_t' is 64-bit, 'ut.ut_time' is 32-bit. */
@@ -223,7 +229,12 @@
}
#endif
+#if 0 /* Outdated */
return(set_utmp(tty, &ut));
+#else /* Only the safe use of /var/log/wtmp. */
+ logwtmp(ttyptr, user, "splitvt");
+ return 0;
+#endif
}
@@ -237,6 +248,7 @@
struct utmp ut;
int retval=0;
+#if 0 /* Outdated manual manipulations. */
/* Retrieve any existing utmp entry */
d_zero((char *)&ut, sizeof(ut));
if ( get_utmp(tty, &ut) == 0 ) {
@@ -261,6 +273,22 @@
#endif
retval=set_utmp(tty, &ut);
}
+#else /* Portable, half-way contemporary approach. */
+ char *ttyptr;
+
+ /* Get the ttyxy form of the tty pathname if possible. */
+ if ( *tty == '/' ) {
+ for ( ttyptr=(tty+1); *ttyptr; ++ttyptr ) {
+ if ( *ttyptr == '/' )
+ break;
+ }
+ if ( *ttyptr == '/' )
+ ++ttyptr;
+ } else
+ ttyptr=tty;
+
+ logwtmp(ttyptr, "", "");
+#endif
#if !defined(SOLARIS) && !defined(IRIX)
/* Solaris and Irix machines do this automatically */
--- a/vttest.c
+++ b/vttest.c
@@ -15,6 +15,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
+#include <unistd.h>
#include <fcntl.h>
#ifdef HAVE_TERMIO_H
#include <termio.h>
|