summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac3
-rw-r--r--sessreg.c60
-rw-r--r--sessreg.h12
3 files changed, 54 insertions, 21 deletions
diff --git a/configure.ac b/configure.ac
index 6e2f470..be1b4b4 100644
--- a/configure.ac
+++ b/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
diff --git a/sessreg.c b/sessreg.c
index c674450..3dc2992 100644
--- a/sessreg.c
+++ b/sessreg.c
@@ -75,7 +75,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
@@ -84,7 +83,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,
@@ -94,7 +96,12 @@ static void set_utmpx (struct utmpx *u, const char *line, const char *user,
static int wflag, uflag, lflag;
static 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
static int utmp_none, wtmp_none;
/*
@@ -103,7 +110,9 @@ static int utmp_none, wtmp_none;
*/
static int hflag, sflag, xflag, tflag;
static char *host_name = NULL;
+#ifdef USE_UTMP
static int slot_number;
+#endif
static char *xservers_file, *ttys_file;
static char *user_name;
static int aflag, dflag;
@@ -175,7 +184,7 @@ sysnerr (int x, const char *s)
int
main (int argc, char **argv)
{
-#ifndef SYSV
+#if defined(USE_UTMP) && !defined(SYSV)
int utmp;
#endif
char *line_tmp;
@@ -183,7 +192,9 @@ main (int argc, char **argv)
int wtmp;
#endif
Time_t current_time;
+#ifdef USE_UTMP
struct utmp utmp_entry;
+#endif
#ifdef USE_UTMPX
struct utmpx utmpx_entry;
#endif
@@ -218,7 +229,9 @@ main (int argc, char **argv)
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);
@@ -244,14 +257,14 @@ main (int argc, char **argv)
/* 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
}
@@ -262,7 +275,7 @@ main (int argc, char **argv)
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) {
@@ -281,34 +294,42 @@ main (int argc, char **argv)
line = line_tmp;
}
time (&current_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");
@@ -316,13 +337,16 @@ main (int argc, char **argv)
== 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) {
@@ -365,6 +389,7 @@ main (int argc, char **argv)
* 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)
{
@@ -411,6 +436,7 @@ set_utmp (struct utmp *u, char *line, char *user, char *host, Time_t date, int a
#endif
u->ut_time = date;
}
+#endif /* USE_UTMP */
#ifdef USE_UTMPX
static int
@@ -418,6 +444,8 @@ UtmpxIdOpen( char *utmpId )
{
struct utmpx *u; /* pointer to entry in utmp file */
int status = 1; /* return code */
+
+ setutxent();
while ( (u = getutxent()) != NULL ) {
@@ -429,7 +457,7 @@ UtmpxIdOpen( char *utmpId )
}
}
- endutent();
+ endutxent();
return (status);
}
@@ -448,14 +476,16 @@ set_utmpx (struct utmpx *u, const char *line, const char *user,
(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;
@@ -514,7 +544,7 @@ set_utmpx (struct utmpx *u, const char *line, const char *user,
}
#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
diff --git a/sessreg.h b/sessreg.h
index 6583d57..6b3edc2 100644
--- a/sessreg.h
+++ b/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