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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
--- configure.ac
+++ configure.ac
@@ -39,13 +39,14 @@ AC_PROG_INSTALL
XORG_DEFAULT_OPTIONS
-AC_CHECK_HEADERS([lastlog.h utmpx.h sys/param.h])
+AC_CHECK_HEADERS([lastlog.h utmp.h utmpx.h sys/param.h])
AC_CHECK_MEMBER([struct utmpx.ut_syslen],
HAVE_SYSLEN=1,
HAVE_SYSLEN=0,
[#include <utmpx.h>])
AC_DEFINE_UNQUOTED(HAVE_UTMPX_UT_SYSLEN,$HAVE_SYSLEN,
[utmpx structure includes ut_syslen field])
+AC_CHECK_FUNCS([updwtmpx utmpxname])
AC_SYS_LARGEFILE
--- sessreg.c
+++ sessreg.c
@@ -80,7 +80,6 @@
# include <X11/Xfuncs.h>
# include <stdio.h>
# include <stdlib.h>
-# include <utmp.h>
#if defined(__SVR4) || defined(SVR4) || defined(linux) || defined(__GLIBC__)
# define SYSV
@@ -89,7 +88,10 @@
#include <time.h>
#define Time_t time_t
-static void set_utmp (struct utmp *u, char *line, char *user, char *host, Time_t date, int addp);
+#ifdef USE_UTMP
+static void set_utmp (struct utmp *u, char *line, char *user, char *host,
+ Time_t date, int addp);
+#endif
#ifdef USE_UTMPX
static void set_utmpx (struct utmpx *u, const char *line, const char *user,
@@ -99,7 +101,12 @@
int wflag, uflag, lflag;
char *wtmp_file, *utmp_file, *line;
#ifdef USE_UTMPX
-static char *wtmpx_file = NULL, *utmpx_file = NULL;
+#ifdef HAVE_UPDWTMPX
+static char *wtmpx_file = NULL;
+#endif
+#ifdef HAVE_UTMPXNAME
+static char *utmpx_file = NULL;
+#endif
#endif
int utmp_none, wtmp_none;
/*
@@ -108,7 +115,9 @@
*/
int hflag, sflag, xflag, tflag;
char *host_name = NULL;
+#ifdef USE_UTMP
int slot_number;
+#endif
char *xservers_file, *ttys_file;
char *user_name;
int aflag, dflag;
@@ -180,7 +189,7 @@
int
main (int argc, char **argv)
{
-#ifndef SYSV
+#if defined(USE_UTMP) && !defined(SYSV)
int utmp;
#endif
char *line_tmp;
@@ -188,7 +197,9 @@
int wtmp;
#endif
Time_t current_time;
+#ifdef USE_UTMP
struct utmp utmp_entry;
+#endif
#ifdef USE_UTMPX
struct utmpx utmpx_entry;
#endif
@@ -223,7 +234,9 @@
host_name = getstring (&argv, &hflag);
break;
case 's':
+#ifdef USE_UTMP
slot_number = atoi (getstring (&argv, &sflag));
+#endif
break;
case 'x':
xservers_file = getstring (&argv, &xflag);
@@ -249,14 +262,14 @@
/* set up default file names */
if (!wflag) {
wtmp_file = WTMP_FILE;
-#ifdef USE_UTMPX
+#if defined(USE_UTMPX) && defined(HAVE_UPDWTMPX)
wtmpx_file = WTMPX_FILE;
#endif
}
#ifndef NO_UTMP
if (!uflag) {
utmp_file = UTMP_FILE;
-#ifdef USE_UTMPX
+#if defined(USE_UTMPX) && defined(HAVE_UTMPXNAME)
utmpx_file = UTMPX_FILE;
#endif
}
@@ -267,7 +280,7 @@
if (!Lflag)
llog_file = LLOG_FILE;
#endif
-#if !defined(SYSV) && !defined(linux) && !defined(__QNX__)
+#if defined(USE_UTMP) && !defined(SYSV) && !defined(linux) && !defined(__QNX__)
if (!tflag)
ttys_file = TTYS_FILE;
if (!sflag && !utmp_none) {
@@ -286,34 +299,42 @@
line = line_tmp;
}
time (¤t_time);
+#ifdef USE_UTMP
set_utmp (&utmp_entry, line, user_name, host_name, current_time, aflag);
+#endif
#ifdef USE_UTMPX
/* need to set utmpxname() before calling set_utmpx() for
UtmpxIdOpen to work */
+# ifdef HAVE_UTMPXNAME
if (utmpx_file != NULL) {
utmpxname (utmpx_file);
}
+# endif
set_utmpx (&utmpx_entry, line, user_name,
host_name, current_time, aflag);
#endif
if (!utmp_none) {
#ifdef USE_UTMPX
- if (utmpx_file != NULL) {
+# ifdef HAVE_UTMPX_NAME
+ if (utmpx_file != NULL)
+# endif
+ {
setutxent ();
(void) getutxid (&utmpx_entry);
pututxline (&utmpx_entry);
endutxent ();
}
#endif
-#ifdef SYSV
+#ifdef USE_UTMP
+# ifdef SYSV
utmpname (utmp_file);
setutent ();
(void) getutid (&utmp_entry);
pututline (&utmp_entry);
endutent ();
-#else
+# else
utmp = open (utmp_file, O_RDWR);
if (utmp != -1) {
syserr ((int) lseek (utmp, (long) slot_number * sizeof (struct utmp), 0), "lseek");
@@ -321,13 +342,16 @@
== sizeof (utmp_entry), "write utmp entry");
close (utmp);
}
-#endif
+# endif
+#endif /* USE_UTMP */
}
if (!wtmp_none) {
#ifdef USE_UTMPX
+# ifdef HAVE_UPDWTMPX
if (wtmpx_file != NULL) {
updwtmpx(wtmpx_file, &utmpx_entry);
}
+# endif
#else
wtmp = open (wtmp_file, O_WRONLY|O_APPEND);
if (wtmp != -1) {
@@ -370,6 +394,7 @@
* fill in the appropriate records of the utmp entry
*/
+#ifdef USE_UTMP
static void
set_utmp (struct utmp *u, char *line, char *user, char *host, Time_t date, int addp)
{
@@ -416,6 +441,7 @@
#endif
u->ut_time = date;
}
+#endif /* USE_UTMP */
#ifdef USE_UTMPX
static int
@@ -423,6 +449,8 @@
{
struct utmpx *u; /* pointer to entry in utmp file */
int status = 1; /* return code */
+
+ setutxent();
while ( (u = getutxent()) != NULL ) {
@@ -434,7 +462,7 @@
}
}
- endutent();
+ endutxent();
return (status);
}
@@ -453,14 +481,16 @@
(void) strncpy (u->ut_line, line, sizeof (u->ut_line));
strncpy(u->ut_host, line, sizeof(u->ut_host));
+#if HAVE_UTMPX_UT_SYSLEN
u->ut_syslen = strlen(line);
+#endif
}
else
bzero (u->ut_line, sizeof (u->ut_line));
if (addp && user)
- (void) strncpy (u->ut_name, user, sizeof (u->ut_name));
+ (void) strncpy (u->ut_user, user, sizeof (u->ut_user));
else
- bzero (u->ut_name, sizeof (u->ut_name));
+ bzero (u->ut_user, sizeof (u->ut_user));
if (line) {
int i;
@@ -519,7 +549,7 @@
}
#endif /* USE_UTMPX */
-#ifndef SYSV
+#if defined(USE_UTMP) && !defined(SYSV)
/*
* compute the slot-number for an X display. This is computed
* by counting the lines in /etc/ttys and adding the line-number
--- sessreg.h
+++ sessreg.h
@@ -51,13 +51,15 @@
#include <sys/types.h>
#include <time.h>
-#include <utmp.h>
+
+#ifdef HAVE_UTMP_H
+# include <utmp.h>
+# define USE_UTMP
+#endif
#ifdef HAVE_UTMPX_H
-# if HAVE_UTMPX_UT_SYSLEN
-# include <utmpx.h>
-# define USE_UTMPX
-# endif
+# include <utmpx.h>
+# define USE_UTMPX
#endif
#ifdef HAVE_SYS_PARAM_H
|