Hi!
After reviewing my port and looking at the port of ssh 1.2.26, I made
a new version. Though the problem that ssh / sshd hang after logout
remains.
Due to some difficulties in compiling I have added a description:
Unpack the souces
gzip -cd openssh-3.0.2p1.tar.gz | tar xv
cd into the directory
cd openssh-3.0.2p1
Apply the patch
cat …/openssh-3.0.2p1.diff | patch -p1
Copy the files qnx.c, qsetlogin.c into the openbsd-compat subdirectory
Configure the package:
CC=cc bash ./configure --prefix=/usr --sysconfdir=/etc/ssh --localstatedir=/var
–bindir=/usr/bin --sbindir=/usr/ucb --enable-debug --disable-nls
–with-ipv4-default --without-4in6 --with-mantype=man --without-lastlog
–without-xauth
Edit the Makefile and do the following changes (to add -lunix to LIBS and
-lqcrypt to the libraries linked to sshd):
32c32
< LIBS=-lz -lsocket -lcrypto
LIBS=-lz -lsocket -lunix -lcrypto
101c101
< $(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS)
$(LD) -o $@ $(SSHDOBJS) $(LDFLAGS) -lssh -lopenbsd-compat $(LIBS) -lqcrypt
Don’t configure with --with-libs=-lunix! If you do so, the built software
crashes with SIGSEGV immediately. The reason is probably that some of
openssh’s own compatibility finctions are not used in this case, but
the ones from the unix library instead. Compare the config.h file in
both cases!
Edit openbsd-compat/Makefile and make the following changes (to add
qnx.o and qsetlogin.o):
21c21
< COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o
COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o qnx4.o qsetlogin.o
Edit config.h and
- disable HAS_SHADOW_EXPIRE
- enable MISSING_NFDBITS, MISSING_HOWMANY and MISSING_FD_MASK
Build the executables
make
That’s it!
If you have any suggestion what to do to solve that “hang”-problem,
please let me know.
-Andreas
—snip----------------------------------------------------------------------
Here comes the diff:
diff -cr openssh-3.0.2p1.orig/includes.h openssh-3.0.2p1.qnx/includes.h
*** openssh-3.0.2p1.orig/includes.h Thu Sep 20 04:07:51 2001
— openssh-3.0.2p1.qnx/includes.h Sun Jan 6 17:16:05 2002
*** 27,33 ****
— 27,35 ----
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
-
#if !defined(QNX) || defined(QNXNTO)
#include <sys/resource.h> - #endif /* !QNX || QNXNTO */
#include <netinet/tcp.h>
#include <arpa/inet.h>
diff -cr openssh-3.0.2p1.orig/install-sh openssh-3.0.2p1.qnx/install-sh
*** openssh-3.0.2p1.orig/install-sh Thu Nov 25 02:31:26 1999
— openssh-3.0.2p1.qnx/install-sh Sun Jan 6 17:16:05 2002
*** 79,85 ****
shift
continue;;
! -s) stripcmd="$stripprog"
shift
continue;;
— 79,85 ----
shift
continue;;
! -s) #stripcmd="$stripprog"
shift
continue;;
diff -cr openssh-3.0.2p1.orig/loginrec.c openssh-3.0.2p1.qnx/loginrec.c
*** openssh-3.0.2p1.orig/loginrec.c Tue Oct 30 03:50:40 2001
— openssh-3.0.2p1.qnx/loginrec.c Sun Jan 6 17:17:10 2002
*** 786,797 ****
— 786,802 ----
}
#else /* FIXME */
- #if defined(QNX) && !defined(QNXNTO)
- tty = 1;
-
#else
tty = ttyslot(); /* seems only to work for /dev/ttyp? style names */ - #endif /* QNX && !QNXNTO */
#endif /* HAVE_GETTTYENT */
if (tty > 0 && (fd = open(UTMP_FILE, O_RDWR|O_CREAT, 0644)) >= 0) {
(void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET);
-
#ifdef HAVE_HOST_IN_UTMP
/*
- Prevent luser from zero’ing out ut_host.
- If the new ut_line is empty but the old one is not
*** 803,808 ****
— 808,814 ----
(strncmp(old_ut.ut_name, ut->ut_name, sizeof(ut->ut_name)) == 0)) {
(void)memcpy(ut->ut_host, old_ut.ut_host, sizeof(ut->ut_host));
}
-
#endif /* HAVE_HOST_IN_UTMP */
(void)lseek(fd, (off_t)(tty * sizeof(struct utmp)), SEEK_SET);
if (atomicio(write, fd, ut, sizeof(*ut)) != sizeof(*ut))
diff -cr openssh-3.0.2p1.orig/rijndael.c openssh-3.0.2p1.qnx/rijndael.c
*** openssh-3.0.2p1.orig/rijndael.c Sat Sep 15 13:31:54 2001
— openssh-3.0.2p1.qnx/rijndael.c Sun Jan 6 17:16:05 2002
*** 856,862 ****
return Nr;
}
! static void rijndaelEncrypt(const u32 rk[/4(Nr + 1)*/], int Nr, const u8 pt[16], u8 ct[16]) {
u32 s0, s1, s2, s3, t0, t1, t2, t3;
#ifndef FULL_UNROLL
int r;
— 856,862 ----
return Nr;
}
! static void rijndaelEncrypt(u32 rk[/4(Nr + 1)*/], int Nr, const u8 pt[16], u8 ct[16]) {
u32 s0, s1, s2, s3, t0, t1, t2, t3;
#ifndef FULL_UNROLL
int r;
*** 1037,1043 ****
PUTU32(ct + 12, s3);
}
! static void rijndaelDecrypt(const u32 rk[/4(Nr + 1)*/], int Nr, const u8 ct[16], u8 pt[16]) {
u32 s0, s1, s2, s3, t0, t1, t2, t3;
#ifndef FULL_UNROLL
int r;
— 1037,1043 ----
PUTU32(ct + 12, s3);
}
! static void rijndaelDecrypt(u32 rk[/4(Nr + 1)*/], int Nr, const u8 ct[16], u8 pt[16]) {
u32 s0, s1, s2, s3, t0, t1, t2, t3;
#ifndef FULL_UNROLL
int r;
diff -cr openssh-3.0.2p1.orig/scp.c openssh-3.0.2p1.qnx/scp.c
*** openssh-3.0.2p1.orig/scp.c Mon Oct 22 02:53:59 2001
— openssh-3.0.2p1.qnx/scp.c Mon Jan 7 18:42:39 2002
*** 564,570 ****
if (response() < 0)
goto next;
if ((bp = allocbuf(&buffer, fd, 2048)) == NULL) {
! next: (void) close(fd);
continue;
}
if (showprogress) {
— 564,574 ----
if (response() < 0)
goto next;
if ((bp = allocbuf(&buffer, fd, 2048)) == NULL) {
! next:
! #if defined(QNX) && !defined(QNXNTO)
! if (fd != -1)
! #endif /* QNX && !QNXNTO */
! (void) close(fd);
continue;
}
if (showprogress) {
*** 641,647 ****
— 645,655 ----
return;
}
while ((dp = readdir(dirp)) != NULL) {
- #if defined(QNX) && !defined(QNXNTO)
-
if (dp->d_stat.st_ino == 0) /* other naming under QNX 4 */
-
#else /* !QNX || QNXNTO */
if (dp->d_ino == 0) -
#endif /* !QNX || QNXNTO */
continue;
if (!strcmp(dp->d_name, “.”) || !strcmp(dp->d_name, “…”))
continue;
diff -cr openssh-3.0.2p1.orig/servconf.c openssh-3.0.2p1.qnx/servconf.c
*** openssh-3.0.2p1.orig/servconf.c Tue Nov 13 14:03:15 2001
— openssh-3.0.2p1.qnx/servconf.c Sun Jan 6 17:16:06 2002
*** 695,719 ****
goto parse_flag;
case sLogFacility:
! intptr = (int *) &options->log_facility;
! arg = strdelim(&cp);
! value = log_facility_number(arg);
! if (value == (SyslogFacility) - 1)
! fatal("%.200s line %d: unsupported log facility ‘%s’",
! filename, linenum, arg ? arg : “”);
! if (*intptr == -1)
! *intptr = (SyslogFacility) value;
! break;
case sLogLevel:
! intptr = (int *) &options->log_level;
! arg = strdelim(&cp);
! value = log_level_number(arg);
! if (value == (LogLevel) - 1)
! fatal("%.200s line %d: unsupported log level ‘%s’",
! filename, linenum, arg ? arg : “”);
! if (*intptr == -1)
! *intptr = (LogLevel) value;
break;
case sAllowTcpForwarding:
— 695,727 ----
goto parse_flag;
case sLogFacility:
! {
! SyslogFacility *sptr;
-
sptr = (SyslogFacility *) &options->log_facility;
-
arg = strdelim(&cp);
-
value = log_facility_number(arg);
-
if (value == (SyslogFacility) - 1)
-
fatal("%.200s line %d: unsupported log facility '%s'",
-
filename, linenum, arg ? arg : "<NONE>");
-
if (*sptr == -1)
-
*sptr = (SyslogFacility) value;
-
}
-
break;
case sLogLevel:
! {
! LogLevel *lptr;
!
! lptr = (LogLevel *) &options->log_level;
! arg = strdelim(&cp);
! value = log_level_number(arg);
! if (value == (LogLevel) - 1)
! fatal("%.200s line %d: unsupported log level ‘%s’",
! filename, linenum, arg ? arg : “”);
! if (*lptr == -1)
! *lptr = (LogLevel) value;
! }
break;
case sAllowTcpForwarding:
diff -cr openssh-3.0.2p1.orig/session.c openssh-3.0.2p1.qnx/session.c
*** openssh-3.0.2p1.orig/session.c Sun Dec 2 00:37:08 2001
— openssh-3.0.2p1.qnx/session.c Sun Jan 6 17:51:44 2002
*** 568,574 ****
close(ptyfd);
/* Make the pseudo tty our controlling tty. */
! pty_make_controlling_tty(&ttyfd, s->tty);
/* Redirect stdin/stdout/stderr from the pseudo tty. */
if (dup2(ttyfd, 0) < 0)
— 568,574 ----
close(ptyfd);
/* Make the pseudo tty our controlling tty. */
! pty_make_controlling_tty(&ttyfd, s->tty, s->pw->pw_name);
/* Redirect stdin/stdout/stderr from the pseudo tty. */
if (dup2(ttyfd, 0) < 0)
*** 1109,1115 ****
— 1109,1119 ----
error(“setluid: %s”, strerror(errno));
#endif /* defined(HAVE_GETLUID) && defined(HAVE_SETLUID) */
- #if defined(QNX) && !defined(QNXNTO)
-
if (qsetlogin(pw->pw_name, ttyname) < 0)
-
#else /* !QNX || QNXNTO */
if (setlogin(pw->pw_name) < 0) -
#endif /* !QNX || QNXNTO */
error(“setlogin failed: %s”, strerror(errno));
if (setgid(pw->pw_gid) < 0) {
perror(“setgid”);
diff -cr openssh-3.0.2p1.orig/sshpty.c openssh-3.0.2p1.qnx/sshpty.c
*** openssh-3.0.2p1.orig/sshpty.c Fri Oct 12 11:15:49 2001
— openssh-3.0.2p1.qnx/sshpty.c Sun Jan 6 17:53:49 2002
*** 247,253 ****
/* Makes the tty the processes controlling tty and sets it to sane modes. */
void
! pty_make_controlling_tty(int *ttyfd, const char ttyname)
{
int fd;
#ifdef USE_VHANGUP
— 247,253 ----
/ Makes the tty the processes controlling tty and sets it to sane modes. */
void
! pty_make_controlling_tty(int *ttyfd, const char *ttyname, const char *loginname)
{
int fd;
#ifdef USE_VHANGUP
*** 258,263 ****
— 258,267 ----
if (setsid() < 0)
error(“setsid: %.100s”, strerror(errno));
- #if defined(QNX) && !defined(QNXNTO)
- qsetlogin(loginname,ttyname);
- #endif /* QNX && !QNXNTO */
fd = open(ttyname, O_RDWR|O_NOCTTY);
if (fd != -1) {
mysignal(SIGHUP, SIG_IGN);
*** 289,294 ****
— 293,302 ----
if (setsid() < 0)
error(“setsid: %.100s”, strerror(errno));
- #if defined(QNX) && !defined(QNXNTO)
- qsetlogin(loginname,ttyname);
- #endif /* QNX && !QNXNTO */
/*
- Verify that we are successfully disconnected from the controlling
- tty.
*** 299,304 ****
— 307,315 ----
close(fd);
}
/* Make it our controlling tty. */
- #if defined(QNX)
- fcntl( *ttyfd, F_SETFD, FD_CLOEXEC);
-
#endif
#ifdef TIOCSCTTY
debug(“Setting controlling tty using TIOCSCTTY.”);
if (ioctl(*ttyfd, TIOCSCTTY, NULL) < 0)
diff -cr openssh-3.0.2p1.orig/sshpty.h openssh-3.0.2p1.qnx/sshpty.h
*** openssh-3.0.2p1.orig/sshpty.h Wed Jul 4 06:46:58 2001
— openssh-3.0.2p1.qnx/sshpty.h Sun Jan 6 17:51:44 2002
*** 19,26 ****
int pty_allocate(int *, int *, char *, int);
void pty_release(const char *);
! void pty_make_controlling_tty(int *, const char *);
void pty_change_window_size(int, int, int, int, int);
void pty_setowner(struct passwd *, const char *);
#endif /* SSHPTY_H */
— 19,26 ----
int pty_allocate(int *, int *, char *, int);
void pty_release(const char *);
! void pty_make_controlling_tty(int *, const char *, const char *);
void pty_change_window_size(int, int, int, int, int);
void pty_setowner(struct passwd *, const char *);
#endif /* SSHPTY_H */
diff -cr openssh-3.0.2p1.orig/sshtty.c openssh-3.0.2p1.qnx/sshtty.c
*** openssh-3.0.2p1.orig/sshtty.c Sun Apr 15 01:21:51 2001
— openssh-3.0.2p1.qnx/sshtty.c Sun Jan 6 17:40:13 2002
*** 77,85 ****
— 77,93 ----
perror(“tcgetattr”);
return;
}
- #if defined(QNX) && !defined(QNXNTO)
- memcpy( &_saved_tio, &tio, sizeof(tio) );
-
#else /* !QNX || QNXNTO */
_saved_tio = tio; -
#endif /* !QNX || QNXNTO */
tio.c_iflag |= IGNPAR; - #if defined(QNX) && !defined(QNXNTO)
- tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF);
-
#else /* !QNX || QNXNTO */
tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF); -
#endif /* !QNX || QNXNTO */
tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
#ifdef IEXTEN
tio.c_lflag &= ~IEXTEN;
diff -cr openssh-3.0.2p1.orig/ttymodes.h openssh-3.0.2p1.qnx/ttymodes.h
*** openssh-3.0.2p1.orig/ttymodes.h Sun Apr 15 01:13:03 2001
— openssh-3.0.2p1.qnx/ttymodes.h Sun Jan 6 17:29:09 2002
*** 121,127 ****
— 121,129 ----
TTYMODE(IUCLC, c_iflag, 37)
#endif
TTYMODE(IXON, c_iflag, 38)
-
#if !defined(QNX) || defined(QNXNTO)
TTYMODE(IXANY, c_iflag, 39) -
#endif /* !QNX || QNXNTO */
TTYMODE(IXOFF, c_iflag, 40)
#ifdef IMAXBEL
TTYMODE(IMAXBEL,c_iflag, 41)
*** 155,161 ****
— 157,165 ----
#if defined(OLCUC)
TTYMODE(OLCUC, c_oflag, 71)
#endif
-
#if !defined(QNX) || defined(QNXNTO)
TTYMODE(ONLCR, c_oflag, 72) -
#endif /* !QNX || QNXNTO */
#ifdef OCRNL
TTYMODE(OCRNL, c_oflag, 73)
#endif
diff -cr openssh-3.0.2p1.orig/uidswap.c openssh-3.0.2p1.qnx/uidswap.c
*** openssh-3.0.2p1.orig/uidswap.c Thu Aug 16 01:17:22 2001
— openssh-3.0.2p1.qnx/uidswap.c Sun Jan 6 17:16:06 2002
*** 80,90 ****
if (user_groupslen < 0)
fatal(“getgroups: %.100s”, strerror(errno));
}
! #ifndef HAVE_CYGWIN
/* Set the effective uid to the given (unprivileged) uid. /
if (setgroups(user_groupslen, user_groups) < 0)
fatal(“setgroups: %.100s”, strerror(errno));
! #endif / !HAVE_CYWIN /
#ifndef SAVED_IDS_WORK_WITH_SETEUID
/ Propagate the privileged gid to all of our gids. /
if (setgid(getegid()) < 0)
— 80,90 ----
if (user_groupslen < 0)
fatal(“getgroups: %.100s”, strerror(errno));
}
! #if !( defined(HAVE_CYGWIN) || (defined(QNX) && !defined(QNXNTO)) )
/ Set the effective uid to the given (unprivileged) uid. /
if (setgroups(user_groupslen, user_groups) < 0)
fatal(“setgroups: %.100s”, strerror(errno));
! #endif / !( HAVE_CYWIN || (QNX && !QNXNTO) ) /
#ifndef SAVED_IDS_WORK_WITH_SETEUID
/ Propagate the privileged gid to all of our gids. */
if (setgid(getegid()) < 0)
*** 131,140 ****
setgid(getgid());
#endif /* SAVED_IDS_WORK_WITH_SETEUID */
! #ifndef HAVE_CYGWIN
if (setgroups(saved_egroupslen, saved_egroups) < 0)
fatal(“setgroups: %.100s”, strerror(errno));
! #endif /* !HAVE_CYGWIN */
temporarily_use_uid_effective = 0;
}
— 131,140 ----
setgid(getgid());
#endif /* SAVED_IDS_WORK_WITH_SETEUID */
! #if !( defined(HAVE_CYGWIN) || (defined(QNX) && !defined(QNXNTO)) )
if (setgroups(saved_egroupslen, saved_egroups) < 0)
fatal(“setgroups: %.100s”, strerror(errno));
! #endif /* !( HAVE_CYWIN || (QNX && !QNXNTO) ) */
temporarily_use_uid_effective = 0;
}
diff -cr openssh-3.0.2p1.orig/openbsd-compat/bsd-snprintf.c openssh-3.0.2p1.qnx/openbsd-compat/bsd-snprintf.c
*** openssh-3.0.2p1.orig/openbsd-compat/bsd-snprintf.c Mon Feb 26 00:20:41 2001
— openssh-3.0.2p1.qnx/openbsd-compat/bsd-snprintf.c Sun Jan 6 17:16:06 2002
*** 53,58 ****
— 53,62 ----
RCSID("$Id: bsd-snprintf.c,v 1.5 2001/02/25 23:20:41 mouring Exp $");
- #if !defined(QNX) || defined(QNXNTO)
- #define HAVE_LONG_LONG
- #endif /* !QNX || QNXNTO */
#if defined(BROKEN_SNPRINTF) /* For those with broken snprintf() */
undef HAVE_SNPRINTF
undef HAVE_VSNPRINTF
*** 232,239 ****
— 236,245 ----
value = va_arg(args, int);
else if (cflags == DP_C_LONG)
value = va_arg(args, long int);
-
#ifdef HAVE_LONG_LONG
else if (cflags == DP_C_LONG_LONG)
value = va_arg (args, long long); -
#endif /* HAVE_LONG_LONG */
else
value = va_arg (args, int);
fmtint(buffer, &currlen, maxlen, value, 10, min, max, flags);
*** 244,251 ****
— 250,259 ----
value = va_arg(args, unsigned int);
else if (cflags == DP_C_LONG)
value = va_arg(args, unsigned long int);
-
#ifdef HAVE_LONG_LONG
else if (cflags == DP_C_LONG_LONG)
value = va_arg(args, unsigned long long); -
#endif /* HAVE_LONG_LONG */
else
value = va_arg(args, unsigned int);
fmtint(buffer, &currlen, maxlen, value, 8, min, max, flags);
*** 256,263 ****
— 264,273 ----
value = va_arg(args, unsigned int);
else if (cflags == DP_C_LONG)
value = va_arg(args, unsigned long int);
-
#ifdef HAVE_LONG_LONG
else if (cflags == DP_C_LONG_LONG)
value = va_arg(args, unsigned long long); -
#endif /* HAVE_LONG_LONG */
else
value = va_arg(args, unsigned int);
fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
*** 270,277 ****
— 280,289 ----
value = va_arg(args, unsigned int);
else if (cflags == DP_C_LONG)
value = va_arg(args, unsigned long int);
-
#ifdef HAVE_LONG_LONG
else if (cflags == DP_C_LONG_LONG)
value = va_arg(args, unsigned long long); -
#endif /* HAVE_LONG_LONG */
else
value = va_arg(args, unsigned int);
fmtint(buffer, &currlen, maxlen, value, 16, min, max, flags);
*** 322,331 ****
— 334,345 ----
long int *num;
num = va_arg(args, long int *);
*num = currlen;
-
#ifdef HAVE_LONG_LONG
} else if (cflags == DP_C_LONG_LONG) {
long long *num;
num = va_arg(args, long long *);
*num = currlen; -
#endif /* HAVE_LONG_LONG */
} else {
int *num;
num = va_arg(args, int *);
*** 703,709 ****
— 717,727 ----
“%qd”,
NULL
};
-
#ifdef HAVE_LONG_LONG
long long int_nums[] = { -1, 134, 91340, 341, 0203, 0, 9999999 }; - #else /* !HAVE_LONG_LONG */
- long int_nums[] = { -1, 134, 91340, 341, 0203, 0, 9999999 };
-
#endif /* !HAVE_LONG_LONG */
int x, y;
int fail = 0;
int num = 0;
—snip-------------------------------------------------------------------
Here comes the file qnx4.c:
#if defined(QNX) && !defined(QNXNTO)
#include <grp.h>
int initgroups(char name,gid_t id)
{
return(0);
}
#endif / QNX && !QNXNTO */
—snip-------------------------------------------------------------------
Here comes the file qsetlogin.c:
#if defined(QNX) && !defined(QNXNTO)
#include <sys/types.h>
#include <sys/proc_msg.h>
#include <sys/kernel.h>
#include <string.h>
#include <errno.h>
struct _proc_session ps;
struct _proc_session_reply rps;
int qsetlogin( char *login, char *ttyname )
{
int v = getsid( getpid() );
memset( &ps, 0, sizeof(ps) );
memset( &rps, 0, sizeof(rps) );
ps.type = _PROC_SESSION;
ps.subtype = _PROC_SUB_ACTION1;
ps.sid = v;
strcpy( ps.name, login );
Send( 1, &ps, &rps, sizeof(ps), sizeof(rps) );
ps.type = _PROC_SESSION;
ps.subtype = _PROC_SUB_ACTION2;
ps.sid = v;
sprintf( ps.name, “//%d%s”, getnid(), ttyname );
Send( 1, &ps, &rps, sizeof(ps), sizeof(rps) );
return( rps.status );
}
#endif /* QNX && !QNXNTO */