summaryrefslogtreecommitdiff
path: root/comms/mgetty+sendfax/patches/patch-al
blob: 952e385cd59c50043c7b37c0bf928e0917522859 (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
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
$NetBSD: patch-al,v 1.3 2003/02/27 21:43:36 fredb Exp $

--- utmp.c.orig	2001-12-17 16:43:25.000000000 -0600
+++ utmp.c
@@ -7,7 +7,7 @@
 
 #include "mgetty.h"
 
-#if defined(sunos4) || defined(BSD)
+#if defined(sunos4) || ( defined(BSD) && !defined(NETBSD_UTMPX) )
 
 #include <stdio.h>
 #include <string.h>
@@ -20,10 +20,11 @@
 #include <time.h>
 #include <string.h>
 #include <sys/types.h>
-#include <sys/stat.h>
-
-#ifndef ENOENT
-#include <errno.h>
+#if !defined(SVR4) && !defined(NETBSD_UTMPX) && !defined(__GLIBC__) || __GLIBC__ < 2
+# include <sys/stat.h>
+# ifndef ENOENT
+#  include <errno.h>
+# endif
 #endif
 
 #if defined(_3B1_) || defined(MEIBE) || defined(ISC)
@@ -42,8 +43,14 @@
 # endif
 #endif
 
+#ifndef WTMPX_FILE
+# ifdef _PATH_WTMPX
+#  define WTMPX_FILE _PATH_WTMPX	/* NetBSD */
+# endif
+#endif
+
 
-#if defined(sunos4) || defined(BSD) || defined(ultrix)
+#if ( defined(sunos4) || defined(BSD) || defined(ultrix) ) && !defined(NETBSD_UTMPX)
 /* on SunOS (and other BSD-derived systems), the getty process does *
  * not have to care for the utmp entries, login and init do all the work
  * Anyway, we have to _read_ it to get the number of users logged in.
@@ -109,26 +116,74 @@
 {
 struct utmp *utmp;
 pid_t	pid;
+#ifdef NETBSD_UTMPX
+struct utmpx ut;
+char *id;
+#else
+# if !defined(SVR4) && !defined(__GLIBC__) || __GLIBC__ < 2
 struct stat	st;
+# endif
+#endif
 FILE *	fp;
 
+#ifdef NETBSD_UTMPX
+    id = line;
+    if ( strlen( line ) > sizeof( ut.ut_id ) )
+	id += strlen( line ) - sizeof( ut.ut_id );
+
+    if ( ut_type == UT_INIT ) {
+	lprintf(L_JUNK,
+	    "creating initial utmp entry... (ID: %s)",
+	    id);
+
+	memset( &ut, 0, sizeof( ut ) );
+	strncpy( ut.ut_id, id, sizeof( ut.ut_id ) );
+	strncpy( ut.ut_line, line, sizeof( ut.ut_line ) );
+	gettimeofday( &ut.ut_tv, NULL );
+	ut.ut_type = INIT_PROCESS;
+	login( &ut );
+
+	lprintf(L_NOISE, "initial utmp + wtmp entry made");
+	return;
+    }
+
+    if ((pid = checklock( line )) == NO_LOCK) {
+	pid = getpid();
+    }
+
+    lprintf(L_JUNK,
+	"looking for utmp entry... (ID: %s)", id);
+#else
     pid = getpid();
+
     lprintf(L_JUNK, "looking for utmp entry... (my PID: %d)", pid);
+#endif
 
+    setutent();
     while ((utmp = getutent()) != (struct utmp *) NULL)
     {
-	if (utmp->ut_pid == pid &&
-	    (utmp->ut_type == INIT_PROCESS || utmp->ut_type == LOGIN_PROCESS))
+#ifdef NETBSD_UTMPX
+	if ( strncmp( utmp->ut_id, id, sizeof( utmp->ut_id ) ) == 0 &&
+#else
+	if ( utmp->ut_pid == pid &&
+#endif
+	    (utmp->ut_type == INIT_PROCESS || utmp->ut_type == LOGIN_PROCESS) )
 	{
-	    strcpy(utmp->ut_line, line );
+	    strncpy(utmp->ut_line, line, sizeof( utmp->ut_line) );
 
+#ifdef NETBSD_UTMPX
+	    utmp->ut_pid = pid;
+	    gettimeofday( &utmp->ut_tv, NULL );
+#else
 	    utmp->ut_time = time( NULL );
+#endif
 
 	    utmp->ut_type = ut_type;	/* {INIT,LOGIN,USER}_PROCESS */
-	                                /* "LOGIN", "uugetty", "dialout" */
+
 	    strncpy( utmp->ut_user, ut_user, sizeof( utmp->ut_user ) );
+	                                /* "LOGIN", "uugetty", "dialout" */
 
-#if defined(SVR4) || defined(linux)
+#if defined(SVR4) || defined(linux) || defined(NETBSD_UTMPX)
 	    if (ut_host != NULL)
 	    {
 	    	strncpy( utmp->ut_host, ut_host, sizeof( utmp->ut_host ) - 1);
@@ -138,7 +193,7 @@
 	    }
 #endif		/* SVR4 */
 
-#if defined(M_UNIX) || defined(__GLIBC__)
+#if defined(M_UNIX) || defined(__GLIBC__) || defined(NETBSD_UTMPX)
 	    if ( pututline(utmp) == NULL )
 	    {
 		lprintf( L_ERROR, "cannot create utmp entry" );
@@ -151,7 +206,7 @@
 	    /* write same record to end of wtmp
 	     * if wtmp file exists
 	     */
-#ifdef SVR4
+#if defined(SVR4) || defined(NETBSD_UTMPX)
 	    updwtmpx(WTMPX_FILE, utmp);
 #else
 # if defined(__GLIBC__) && __GLIBC__ >= 2