This file contains patches converting stock moussh into something that builds for me on Linux - at least the Linux I have at ready hand, which as I understand it may well not say much about other distros. The resulting code is workable as a client, but the server cide is suboptimal; for exmaple, it will be unable to allocate ptys unless you have BSD-style ptys set up on your system (and maybe even then, for all I know). I really need to pull all the system-specific stuff in moussh out into system-dependent modules. These patches assume the use of my local-software build paradigm - for exmaple, they assume that the crypto stuff is obtainable with a bunch of -l options at link time, rather than (eg) pulling the source into the same directory as moussh. They also assume the presence of an additional dependency not noted in WHERE_I_CAME_FROM: liblinuxcompat. These patches are relative to moussh-20100430. They may work with later versions to varying extents, too, depending on how different from 20100429 they are. --- STOCK/Makefile Sat Jun 9 18:08:19 2007 +++ LINUX/Makefile Sat Aug 29 17:04:31 2009 @@ -8,9 +8,9 @@ # If building on non-NetBSD, you may need to tweak the .if test. OS != uname -s OSREV != uname -r -.if "${OS}" == "NetBSD" && ${OSREV:C/\..*//} > 1 +#.if "${OS}" == "NetBSD" && ${OSREV:C/\..*//} > 1 CC_ADD += -DNEW_CMSG_INTERFACE -.endif +#.endif # What we want to build. BUILDBINS = moussh # Manpages to be installed (source files). @@ -35,7 +35,7 @@ .endif # Libraries to link moussh with. LIBS_moussh = -lXau -larc4 -lblowfish -lcrypt -ldes -ldsa -lgmp -lidea\ - -lmd5 -lrijndael -lsha -lz + -lmd5 -lrijndael -lsha -lz -llinuxcompat -lresolv # On some arches, we wrap malloc calls. This is indicated by the # presence of a malwrap-$ARCH.c file for that arch. If it's there, # include the malloc wrapper files, and tack on the linker options @@ -90,11 +90,11 @@ # and the compiler proper. UNAME_R != uname -r .undef MOUSEISMS_TEST -.if "$(UNAME_R)" == "1.4T" -.if exists(/local/bin/mcsh) -MOUSEISMS_TEST = yes -.endif -.endif +#.if "$(UNAME_R)" == "1.4T" +#.if exists(/local/bin/mcsh) +#MOUSEISMS_TEST = yes +#.endif +#.endif CLEANFILES += lcs-cvt _.i .ifndef MOUSEISMS_TEST .c.o: lcs-cvt $< --- STOCK/agent-client.c Fri Apr 9 16:42:04 2010 +++ LINUX/agent-client.c Sat Aug 29 17:04:31 2009 @@ -12,6 +12,8 @@ #include #include +#include + extern const char *__progname; #include "pp.h" @@ -432,7 +434,7 @@ slen = sizeof(*s_un) - sizeof(s_un->sun_path) + plen + 1; s_un = malloc(slen); s_un->sun_family = AF_LOCAL; - s_un->sun_len = slen; + /* s_un->sun_len = slen; */ bcopy(((unsigned char *)blob)+1+1+clen,&s_un->sun_path[0],plen); s_un->sun_path[plen] = '\0'; s = socket(AF_LOCAL,SOCK_DGRAM,0); --- STOCK/agent-int.c Mon Nov 6 03:31:59 2006 +++ LINUX/agent-int.c Sat Aug 29 17:04:31 2009 @@ -25,6 +25,10 @@ #include "agent-int.h" +#ifndef TCSASOFT +#define TCSASOFT 0 +#endif + /* * External interface to the interactive agent code. * --- STOCK/agent-server.c Fri Apr 9 16:42:05 2010 +++ LINUX/agent-server.c Sat Aug 29 17:04:31 2009 @@ -20,6 +20,8 @@ #include #include +#include + extern const char *__progname; #include "oq.h" @@ -1729,8 +1731,11 @@ { neg = 0; } if ((cx->len > 1) && (cx->bp[0] == '"')) adv(cx,1); - r.re_endp = (void *) (cx->bp+cx->len); - e = regcomp(&r,cx->bp,REG_EXTENDED|REG_NOSUB|REG_PEND); + et = malloc(cx->len+1); + bcopy(cx->bp,et,cx->len); + et[cx->len] = '\0'; + e = regcomp(&r,et,REG_EXTENDED|REG_NOSUB); + free(et); if (e) { el = regerror(e,&r,0,0); et = malloc(el); @@ -2452,7 +2457,7 @@ } slen = sizeof(*s_un) - sizeof(s_un->sun_path) + strlen(path) + 1; s_un = malloc(slen); - s_un->sun_len = slen; + /* s_un->sun_len = slen; */ s_un->sun_family = AF_LOCAL; strcpy(&s_un->sun_path[0],path); if (bind(fd,(void *)s_un,slen) < 0) --- STOCK/alg-ua-password.c Fri Jul 7 23:25:00 2006 +++ LINUX/alg-ua-password.c Sat Aug 29 17:04:31 2009 @@ -1,5 +1,6 @@ /* This file is in the public domain. */ +#define _XOPEN_SOURCE /* Linux seems to demand this to get crypt(3) declared */ #include #include #include --- STOCK/alg-ua-publickey.c Sat Jun 28 06:56:53 2008 +++ LINUX/alg-ua-publickey.c Sat Aug 29 17:04:31 2009 @@ -5,6 +5,8 @@ #include #include +#include + extern const char *__progname; #include "pp.h" --- STOCK/b64.c Fri Aug 19 12:12:33 2005 +++ LINUX/b64.c Sat Aug 29 17:04:31 2009 @@ -3,6 +3,8 @@ #include #include +#include + #include "b64.h" typedef struct b64rstate B64RSTATE; --- STOCK/client.c Sat Jun 28 06:57:01 2008 +++ LINUX/client.c Sat Aug 29 17:04:31 2009 @@ -20,6 +20,12 @@ #undef session #include +#include + +#ifndef TCSASOFT +#define TCSASOFT 0 +#endif + /* * Length of the random part of our synthetic X cookies, used for * broken X forwarding. This value is in bytes *before* hex encoding. @@ -3097,10 +3103,14 @@ opp = (*ops->req_hdr)(s->chan,cstr_to_rostr("missing-pty-modes@rodents.montreal.qc.ca")); *opp++ = MOUSETTY_OP_ECHOPRT; *opp++ = (tio_o.c_lflag & ECHOPRT) ? 1 : 0; +#ifdef ALTWERASE *opp++ = MOUSETTY_OP_ALTWERASE; *opp++ = (tio_o.c_lflag & ALTWERASE) ? 1 : 0; +#endif +#ifdef NOKERNINFO *opp++ = MOUSETTY_OP_NOKERNINFO; *opp++ = (tio_o.c_lflag & NOKERNINFO) ? 1 : 0; +#endif *opp++ = MOUSETTY_OP_CS; switch (tio_i.c_cflag & CSIZE) { case CS5: *opp++ = 5; break; --- STOCK/connshare-auto.c Wed Feb 28 14:37:31 2007 +++ LINUX/connshare-auto.c Sat Aug 29 17:04:31 2009 @@ -7,6 +7,7 @@ #include #include #include +#include #include extern const char *__progname; @@ -28,6 +29,7 @@ { int s; struct sockaddr_un *sun; + int sunlen; int pl; pid_t kid; int cp[2]; @@ -35,7 +37,8 @@ NESTED void setsun(void) { sun->sun_family = AF_LOCAL; - sun->sun_len = sizeof(*sun) - sizeof(sun->sun_path) + pl; + /* sun->sun_len = sizeof(*sun) - sizeof(sun->sun_path) + pl; */ + sunlen = sizeof(*sun) - sizeof(sun->sun_path) + pl; bcopy(rz,&sun->sun_path[0],pl); } @@ -62,7 +65,7 @@ } getsocket(); setsun(); - if (connect(s,(void *)sun,sun->sun_len) >= 0) + if (connect(s,(void *)sun,sunlen) >= 0) { close(lock_fd); share_client_auto(s); config_set_bool("share-client",1); @@ -92,7 +95,7 @@ } getsocket(); setsun(); - if (bind(s,(void *)sun,sun->sun_len) < 0) + if (bind(s,(void *)sun,sunlen) < 0) { fprintf(errf,"%s: can't create sharing socket: %s\n",__progname,strerror(errno)); exit(1); } @@ -135,7 +138,7 @@ close(cp[0]); getsocket(); setsun(); - if (connect(s,(void *)sun,sun->sun_len) < 0) + if (connect(s,(void *)sun,sunlen) < 0) { fprintf(errf,"%s: *still* can't connect sharing socket %s: %s\n",__progname,rz,strerror(errno)); exit(1); } --- STOCK/connshare-c.c Thu Apr 29 10:37:43 2010 +++ LINUX/connshare-c.c Sat Aug 29 17:04:31 2009 @@ -780,9 +780,9 @@ pl = strlen(path); sun = malloc(sizeof(*sun)-sizeof(sun->sun_path)+pl); sun->sun_family = AF_LOCAL; - sun->sun_len = sizeof(*sun) - sizeof(sun->sun_path) + pl; + /* sun->sun_len = sizeof(*sun) - sizeof(sun->sun_path) + pl; */ bcopy(path,&sun->sun_path[0],pl); - if (connect(fd,(void *)sun,sun->sun_len) < 0) (*fail)("connect: %s",strerror(errno)); + if (connect(fd,(void *)sun,sizeof(*sun)-sizeof(sun->sun_path)+pl) < 0) (*fail)("connect: %s",strerror(errno)); free(sun); return(fd); } --- STOCK/connshare-s.c Sun Jul 29 18:30:04 2007 +++ LINUX/connshare-s.c Sat Aug 29 17:04:31 2009 @@ -1619,14 +1619,14 @@ pl = strlen(path); sun = malloc(sizeof(*sun)-sizeof(sun->sun_path)+pl); sun->sun_family = AF_LOCAL; - sun->sun_len = sizeof(*sun) - sizeof(sun->sun_path) + pl; + /* sun->sun_len = sizeof(*sun) - sizeof(sun->sun_path) + pl; */ bcopy(path,&sun->sun_path[0],pl); sfd = socket(AF_LOCAL,SOCK_STREAM,0); if (sfd < 0) { fprintf(errf,"%s: socket; %s\n",__progname,strerror(errno)); exit(1); } - if (bind(sfd,(void *)sun,sun->sun_len) < 0) + if (bind(sfd,(void *)sun,sizeof(*sun)-sizeof(sun->sun_path)+pl) < 0) { fprintf(errf,"%s: bind %s: %s\n",__progname,path,strerror(errno)); exit(1); } --- STOCK/errf.c Tue Mar 14 02:13:18 2006 +++ LINUX/errf.c Sat Aug 29 17:04:31 2009 @@ -9,6 +9,8 @@ #include #include +#include + extern const char *__progname; #include "bpp.h" --- STOCK/hkdb.c Fri Apr 9 16:42:10 2010 +++ LINUX/hkdb.c Sat Aug 29 17:04:31 2009 @@ -8,6 +8,7 @@ #include #include #include +#include extern const char *__progname; @@ -227,12 +228,13 @@ fprintf(o,"\n"); } - dbfd = open(dbf,O_RDWR|O_EXLOCK|O_CREAT,0666); + dbfd = open(dbf,O_RDWR|O_CREAT,0666); if (dbfd < 0) { fprintf(errf,"%s: %s: %s\n",__progname,dbf,strerror(errno)); fflush(errf); return; } + flock(dbfd,LOCK_EX); i = fdopen(dbfd,"r+"); o = fopen_alloc(&obuf,&olen); hbuf = 0; @@ -406,12 +408,13 @@ fprintf(o,"\n"); } - dbfd = open(dbf,O_RDWR|O_EXLOCK|O_CREAT|O_APPEND,0666); + dbfd = open(dbf,O_RDWR|O_CREAT|O_APPEND,0666); if (dbfd < 0) { fprintf(errf,"%s: %s: %s\n",__progname,dbf,strerror(errno)); fflush(errf); return; } + flock(dbfd,LOCK_EX); o = fopen_alloc(&obuf,&olen); (*fn)(&save); fclose(o); --- STOCK/interact.c Wed Feb 28 14:37:37 2007 +++ LINUX/interact.c Sat Aug 29 17:04:31 2009 @@ -10,6 +10,8 @@ #include #include +#include + extern const char *__progname; #include "errf.h" --- STOCK/keygen.c Fri Jul 7 23:25:38 2006 +++ LINUX/keygen.c Sat Aug 29 17:04:31 2009 @@ -8,6 +8,8 @@ #include #include +#include + extern const char *__progname; #include "b64.h" --- STOCK/keyutils.c Fri Jul 7 23:25:39 2006 +++ LINUX/keyutils.c Sat Aug 29 17:04:31 2009 @@ -4,6 +4,8 @@ #include #include +#include + extern const char *__progname; #include "b64.h" --- STOCK/oq.c Fri Jul 7 23:25:50 2006 +++ LINUX/oq.c Sat Aug 29 17:04:31 2009 @@ -131,17 +131,7 @@ OQE *e; if (maxiov < 0) - { int mib[2]; - size_t oldlen; - mib[0] = CTL_KERN; - mib[1] = KERN_IOV_MAX; - oldlen = sizeof(maxiov); - if (sysctl(&mib[0],2,&maxiov,&oldlen,0,0) < 0) - { logmsg(LM_ERR|LM_PEER,"can't get kern.iov_max: %s",strerror(errno)); - exit(1); - } - if (maxiov > 64) maxiov = 64; - if (maxiov < 1) maxiov = 1; + { maxiov = 64; iov = 0; iovn = 0; } --- STOCK/rnd.c Sun Jul 29 18:30:19 2007 +++ LINUX/rnd.c Sat Aug 29 17:04:31 2009 @@ -1,5 +1,10 @@ /* This file is in the public domain. */ +#define _XOPEN_SOURCE 500 /* Linux seems to demand this to get pread/pwrite(!) */ +/* The manpage says wait4() is available if _BSD_SOURCE or _XOPEN_SOURCE>=500. But + the actual code in the include file uses __USE_BSD, which depends on _BSD_SOURCE only. + So, contrary to the manpage, we have to use _BSD_SOURCE to get wait4(). */ +#define _BSD_SOURCE #include #include #include @@ -9,6 +14,7 @@ #include #include #include +#include #include "errf.h" #include "util.h" @@ -185,7 +191,7 @@ { poolfd = open(path,O_RDWR,0600); if (poolfd < 0) { if (errno == ENOENT) - { poolfd = open(path,O_RDWR|O_CREAT|O_EXCL|O_EXLOCK,0600); + { poolfd = open(path,O_RDWR|O_CREAT|O_EXCL,0600); if (poolfd < 0) { switch (errno) { case EEXIST: @@ -197,6 +203,7 @@ break; } } + flock(poolfd,LOCK_EX); new_pool(); break; } --- STOCK/server.c Fri Apr 9 16:42:16 2010 +++ LINUX/server.c Sat Aug 29 17:04:31 2009 @@ -1015,7 +1015,9 @@ case SIGTERM: sigstr = "TERM"; break; case SIGUSR1: sigstr = "USR1"; break; case SIGUSR2: sigstr = "USR2"; break; +#ifdef SIGEMT case SIGEMT: sigstr = "EMT@NetBSD"; break; +#endif case SIGBUS: sigstr = "BUS@NetBSD"; break; case SIGSYS: sigstr = "SYS@NetBSD"; break; case SIGURG: sigstr = "URG@NetBSD"; break; @@ -1031,7 +1033,9 @@ case SIGVTALRM: sigstr = "VTALRM@NetBSD"; break; case SIGPROF: sigstr = "PROF@NetBSD"; break; case SIGWINCH: sigstr = "WINCH@NetBSD"; break; +#ifdef SIGINFO case SIGINFO: sigstr = "INFO@NetBSD"; break; +#endif case SIGPWR: sigstr = "PWR@NetBSD"; break; default: sprintf(&buf[0],"%d@NetBSD",sig); @@ -2847,7 +2851,7 @@ { asprintf(&b->peer_text,"%s/%s",&hbuf[0],&sbuf[0]); } verb(PROGRESS,"Accepted connection, server pid %d: %s\n",(int)getpid(),b->peer_text); - setproctitle("serving %s",b->peer_text); + /* setproctitle("serving %s",b->peer_text); */ fcntl(new,F_SETFD,1); b->fd = new; sendversion(b); @@ -3030,5 +3034,5 @@ for (j=0;(a=(*t->list)(j));j++) (*t->servidle_init)(a); } daemon_idle_id = add_block_fn(&daemon_idle_block,0); - setproctitle("server"); + /* setproctitle("server"); */ } --- STOCK/stdio-util.c Fri Apr 9 16:42:17 2010 +++ LINUX/stdio-util.c Sat Aug 29 17:04:31 2009 @@ -6,6 +6,8 @@ #include #include +#include + #include "stdio-util.h" typedef struct allocblk ALLOCBLK; --- STOCK/userauth-conn-s.c Sun Apr 8 02:46:57 2007 +++ LINUX/userauth-conn-s.c Sat Aug 29 17:04:31 2009 @@ -1,6 +1,7 @@ /* This file is in the public domain. */ #include +#include #include #include #include @@ -282,7 +283,7 @@ } below_opkt(l); logmsg(LM_INFO|LM_PEER,"authenticated as %s (%s)",s->uastate.curuser,alg->name); - setproctitle("serving %s from %s",s->uastate.curuser,l->b->peer_text); + /* setproctitle("serving %s from %s",s->uastate.curuser,l->b->peer_text); */ config_set_bool("user-authenticated",1); config_set_str("user",s->uastate.curuser); config_set_str("home",s->uastate.homedir); --- STOCK/util.c Fri Jul 7 23:26:03 2006 +++ LINUX/util.c Sat Aug 29 17:04:31 2009 @@ -65,6 +65,8 @@ */ void spt_av0(const char *av0, const char *fmt, ...) { + av0=av0;fmt=fmt; +/* char *s; FILE *f; const char *ppn; @@ -81,6 +83,7 @@ setproctitle("%s",s); __progname = ppn; free(s); +*/ } int moussh_fork(void) --- STOCK/verbose.c Sat Feb 3 10:27:22 2007 +++ LINUX/verbose.c Sat Aug 29 17:04:31 2009 @@ -10,6 +10,8 @@ #include #include +#include + extern const char *__progname; #include "panic.h" --- STOCK/writev.c Fri Jul 7 23:26:07 2006 +++ LINUX/writev.c Sat Aug 29 17:04:31 2009 @@ -33,19 +33,7 @@ static void get_max(void) { - int mib[2]; - size_t l; - - if (maxiov > 0) return; - mib[0] = CTL_KERN; - mib[1] = KERN_IOV_MAX; - l = sizeof(maxiov); - if (sysctl(&mib[0],2,&maxiov,&l,0,0) < 0) - { fprintf(stderr,"%s: can't get kern.iov_max: %s\n",__progname,strerror(errno)); - exit(1); - } - if (maxiov < 1) panic("kern.iov_max (%d) < 1",maxiov); - if (maxiov > 1024) maxiov = 1024; + maxiov = 1024; } static void flush(WV *w)