summaryrefslogtreecommitdiff
path: root/sessreg.c
diff options
context:
space:
mode:
authorEd Schouten <ed@80386.nl>2010-01-16 18:33:53 +0000
committerAlan Coopersmith <alan.coopersmith@sun.com>2010-01-16 11:05:28 -0800
commit9792646873ac0e597cc65ef4a056444fd8f9a7fd (patch)
tree48ed4b0fe321d8f231d2323c182186c044ac3128 /sessreg.c
parent9ca078f8ffc5ab0c4d0f58be26e885a7ad0b8f39 (diff)
Allow sessreg to be built without <utmp.h>.
As of 9.0, FreeBSD will only support <utmpx.h>. It only implements the POSIX interface with minor extensions. There is no need to write to wtmp and lastlog separately, because this is already done by pututxline(). Add additional checks to configure.ac to search for the presence of utmpxname() and updwtmpx(). Signed-off-by: Ed Schouten <ed@80386.nl> Signed-off-by: Alan Coopersmith <alan.coopersmith@sun.com>
Diffstat (limited to 'sessreg.c')
-rw-r--r--sessreg.c60
1 files changed, 45 insertions, 15 deletions
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