wtmpx problem on Solaris 8 sparcv9 (64bit) environment
Takefumi Iseki
iseki at ksp.nis.nec.co.jp
Fri Jun 29 12:30:16 EST 2001
Hello
When I was using OpenSSH-2.9p2 in Solaris 8 sparcv9 (64bit)
environment, I found some trouble that wtmpx has broken.
The size of utmpx structure object becomes larger than 32 bit environment
in sparcv9 environment.Therefore, instead of using utmpx structure object,
using futmpx structure object is better.
In sparcv9 environment, futmpx structure object is used instead of utmpx
structure object.
The system is as follows.
OpenSSH Version: 2.9p2
OS:
% uname -a
SunOS foo 5.8 Generic_108528-06 sun4u sparc SUNW,UltraSPARC-IIi-cEngine
% isainfo -v
64-bit sparcv9 applications
32-bit sparc applications
Please look at reference.
% cat utmptest.c
#include <stdio.h>
#include <utmp.h>
#include <utmpx.h>
main ()
{
struct utmp utmp;
struct futmp futmp;
struct utmpx utmpx;
struct futmpx futmpx;
printf("utmp: %d, futmp: %d / utmpx: %d, futmpx: %d\n",
sizeof(utmp), sizeof(futmp), sizeof(utmpx), sizeof(futmpx));
return(1);
}
% cc utmptest.c
% ./a.out
utmp: 36, futmp: 36 / utmpx: 372, futmpx: 372
% cc -xarch=v9 utmptest.c
% ./a.out
utmp: 40, futmp: 36 / utmpx: 384, futmpx: 372
Following are patch for "openssh-2.9p2/loginrec.c" file.
diff -Naur openssh-2.9p2.org/loginrec.c openssh-2.9p2.cast/loginrec.c
--- openssh-2.9p2.org/loginrec.c Wed May 9 05:34:33 2001
+++ openssh-2.9p2.cast/loginrec.c Thu Jun 28 11:06:22 2001
@@ -887,7 +891,11 @@
/* write a utmpx entry with the system's help (pututxline() and pals) */
# ifdef UTMPX_USE_LIBRARY
static int
+#ifdef __sparcv9
+utmpx_write_library(struct logininfo *li, struct utmpx *utx)
+#else
utmpx_write_library(struct logininfo *li, struct utmpx *utx)
+#endif
{
setutxent();
pututxline(utx);
@@ -902,7 +910,11 @@
/* write a utmp entry direct to the file */
static int
+#ifdef __sparcv9
+utmpx_write_direct(struct logininfo *li, struct futmpx *utx)
+#else
utmpx_write_direct(struct logininfo *li, struct utmpx *utx)
+#endif
{
log("utmpx_write_direct: not implemented!");
return 0;
@@ -1144,7 +1156,11 @@
/* write a wtmpx entry direct to the end of the file */
/* This is a slight modification of code in OpenBSD's logwtmp.c */
static int
+#ifdef __sparcv9
+wtmpx_write(struct logininfo *li, struct futmpx *utx)
+#else
wtmpx_write(struct logininfo *li, struct utmpx *utx)
+#endif
{
struct stat buf;
int fd, ret = 1;
@@ -1167,6 +1183,24 @@
return ret;
}
+#ifdef __sparcv9
+void
+utmpx_to_futmpx(struct utmpx *utx, struct futmpx *futx)
+{
+ strncpy(futx->ut_user, utx->ut_user, sizeof(futx->ut_user));
+ strncpy(futx->ut_id, utx->ut_id, sizeof(futx->ut_id));
+ strncpy(futx->ut_line, utx->ut_line, sizeof(futx->ut_line));
+ futx->ut_pid = (pid32_t)utx->ut_pid;
+ futx->ut_type = (int16_t)utx->ut_type;
+ futx->ut_exit.e_termination = (int16_t)utx->ut_exit.e_termination;
+ futx->ut_exit.e_exit = (int16_t)utx->ut_exit.e_exit;
+ futx->ut_tv.tv_sec = (time32_t)utx->ut_tv.tv_sec;
+ futx->ut_tv.tv_usec = (int32_t)utx->ut_tv.tv_usec;
+ futx->ut_session = (int32_t)utx->ut_session;
+ futx->ut_syslen = (int16_t)utx->ut_syslen;
+ strncpy(futx->ut_host, utx->ut_host, sizeof(futx->ut_host));
+}
+#endif
static int
wtmpx_perform_login(struct logininfo *li)
@@ -1174,7 +1208,15 @@
struct utmpx utx;
construct_utmpx(li, &utx);
+#ifdef __sparcv9
+ {
+ struct futmpx futx;
+ utmpx_to_futmpx(&utx , &futx);
+ return wtmpx_write(li, &futx);
+ }
+#else
return wtmpx_write(li, &utx);
+#endif
}
@@ -1184,7 +1226,16 @@
struct utmpx utx;
construct_utmpx(li, &utx);
- return wtmpx_write(li, &utx);
+#ifdef __sparcv9
+ {
+ struct futmpx futx;
+ utmpx_to_futmpx(&utx , &futx);
+ return wtmpx_write(li, &futx);
+ }
+#else
+ return wtmpx_write(li, &utx);
+#endif
+
}
@@ -1207,7 +1258,11 @@
/* Return true if this wtmpx entry indicates a login */
static int
+#ifdef __sparcv9
+wtmpx_islogin(struct logininfo *li, struct futmpx *utx)
+#else
wtmpx_islogin(struct logininfo *li, struct utmpx *utx)
+#endif
{
if ( strncmp(li->username, utx->ut_name,
MIN_SIZEOF(li->username, utx->ut_name)) == 0 ) {
@@ -1226,7 +1281,11 @@
wtmpx_get_entry(struct logininfo *li)
{
struct stat st;
+#ifdef __sparcv9
+ struct futmpx utx;
+#else
struct utmpx utx;
+#endif
int fd, found=0;
/* Clear the time entries */
@@ -1245,7 +1304,11 @@
}
/* Seek to the start of the last struct utmpx */
+#ifdef __sparcv9
+ if (lseek(fd, (off_t)(0-sizeof(struct futmpx)), SEEK_END) == -1 ) {
+#else
if (lseek(fd, (off_t)(0-sizeof(struct utmpx)), SEEK_END) == -1 ) {
+#endif
/* probably a newly rotated wtmpx file */
close(fd);
return 0;
@@ -1275,7 +1338,11 @@
# endif
continue;
}
+#ifdef __sparcv9
+ if (lseek(fd, (off_t)(0-2*sizeof(struct futmpx)), SEEK_CUR) == -1) {
+#else
if (lseek(fd, (off_t)(0-2*sizeof(struct utmpx)), SEEK_CUR) == -1) {
+#endif
close (fd);
return 0;
}
More information about the openssh-unix-dev
mailing list