#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
-#include <utmp.h>
+#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
+# include <utmpx.h>
+#endif
+#ifdef HAVE_UTMP_H
+# include <utmp.h>
+#endif
#include <stdio.h>
+#include <string.h>
+#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
+void
+login(utp,utx)
+ struct utmp *utp;
+ struct utmpx *utx;
+#else /* defined(HAVE_UTMPX_H) && defined(USE_UTMPX) */
void
login(utp)
struct utmp *utp;
+#endif /* defined(HAVE_UTMPX_H) && defined(USE_UTMPX) */
{
+#if defined(HAVE_HOST_IN_UTMP)
struct utmp old_ut;
+#endif
+#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
+ struct utmpx *old_utx;
+#endif /* defined(HAVE_UTMPX_H) && defined(USE_UTMPX) */
register int fd;
int tty;
tty = ttyslot();
if (tty > 0 && (fd = open(_PATH_UTMP, O_RDWR|O_CREAT, 0644)) >= 0) {
-#ifdef HAVE_HOST_IN_UTMP
+
+#if defined(HAVE_HOST_IN_UTMP)
+# ifndef UT_LINESIZE
+# define UT_LINESIZE (sizeof(old_ut.ut_line))
+# define UT_NAMESIZE (sizeof(old_ut.ut_name))
+# define UT_HOSTSIZE (sizeof(old_ut.ut_host))
+# endif
(void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET);
/*
* Prevent luser from zero'ing out ut_host.
strncmp(old_ut.ut_line, utp->ut_line, UT_LINESIZE) == 0 &&
strncmp(old_ut.ut_name, utp->ut_name, UT_NAMESIZE) == 0)
(void)memcpy(utp->ut_host, old_ut.ut_host, UT_HOSTSIZE);
-#endif /* HAVE_HOST_IN_UTMP */
+#endif /* defined(HAVE_HOST_IN_UTMP) */
(void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET);
(void)write(fd, utp, sizeof(struct utmp));
(void)close(fd);
(void)write(fd, utp, sizeof(struct utmp));
(void)close(fd);
}
+#if defined(HAVE_UTMPX_H) && defined(USE_UTMPX)
+ old_utx = pututxline(utx);
+# ifdef HAVE_UPDWTMPX
+ updwtmpx(_PATH_WTMPX, utx);
+# endif /* HAVE_UPDWTMPX */
+ endutxent();
+#endif /* defined(HAVE_UTMPX_H) && defined(USE_UTMPX) */
}
#endif /* HAVE_LOGIN */