From 29b909ee59c66bb7e5b2e9fdd5b5307bddd8d57c Mon Sep 17 00:00:00 2001 From: Bryan Stansell Date: Mon, 22 Mar 2004 17:14:45 -0800 Subject: [PATCH] Imported from conserver-8.1.3.tar.gz --- CHANGES | 12 +- INSTALL | 6 +- TODO | 4 +- config.guess | 5 +- config.sub | 12 +- conserver.cf/conserver.cf.man | 2 +- conserver.cf/conserver.passwd.man | 2 +- conserver.html | 8 +- conserver/client.c | 4 +- conserver/conserver.man | 6 +- conserver/cutil.c | 5 +- conserver/group.c | 44 +-- conserver/version.h | 4 +- console/console.c | 475 +++++++++++++++++------------- console/console.man | 6 +- contrib/redhat-rpm/conserver.spec | 2 +- contrib/solaris-package/pkginfo | 2 +- test/results/test2 | 2 +- test/results/test7 | 2 +- 19 files changed, 347 insertions(+), 256 deletions(-) diff --git a/CHANGES b/CHANGES index 24451f6..cf5d844 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,14 @@ CHANGES ======= +version 8.1.3 (Mar 22, 2004): + - fixed small memory and file descriptor leak in client when + using '^Ec;' + - '^Ec;' now only disconnects from the previous console only + after a successfully move to a new console, allowing you to + abort the move - suggested by Christopher T. Beers + + version 8.1.2 (Mar 11, 2004): - better handling of client command (^Ec|) when user is bumped, conserver is reconfigured, etc @@ -15,7 +23,7 @@ version 8.1.2 (Mar 11, 2004): patch by Bill Sommerfeld - added --with-extmsgs configure switch to enable entertaining messages - - marked various undocumented client commands as depreciated so + - marked various undocumented client commands as deprecated so that they can be removed in a future version - added ability to "move" to a new console via '^Ec;' - suggested by Christopher T. Beers @@ -690,5 +698,5 @@ before version 6.05: and enhancements of various types were applied. # -# $Id: CHANGES,v 1.158 2004/03/11 16:31:27 bryan Exp $ +# $Id: CHANGES,v 1.162 2004/03/23 00:55:04 bryan Exp $ # diff --git a/INSTALL b/INSTALL index 95fdb46..899ae6f 100644 --- a/INSTALL +++ b/INSTALL @@ -10,6 +10,10 @@ Upgrading? new features added to the client if you're considering *not* upgrading. + Version 8.1.3 + - The '^Ec;' sequence won't work correctly with 8.1.2 (where it + was introduced). + Version 8.1.2 - The 'devicesubst' and 'execsubst' formats have changed from 8.1.1. It's fairly simple to update your config file to the @@ -270,5 +274,5 @@ Other Information And Gotchas # -# $Id: INSTALL,v 1.36 2004/02/22 21:04:06 bryan Exp $ +# $Id: INSTALL,v 1.37 2004/03/23 00:55:04 bryan Exp $ # diff --git a/TODO b/TODO index 6063eec..93a6f93 100644 --- a/TODO +++ b/TODO @@ -102,10 +102,10 @@ Bryan Stansell - strict file permission checks on conserver.passwd/conserver.cf : Erik Sjolund -- imbedded startup delays per remote host...or "group" of consoles in +- embedded startup delays per remote host...or "group" of consoles in some way 'cause some ssh connections to console servers need significant throttling : Jay McCanta # -# $Id: TODO,v 1.46 2004/03/11 16:45:57 bryan Exp $ +# $Id: TODO,v 1.47 2004/03/12 17:34:49 bryan Exp $ # diff --git a/config.guess b/config.guess index 0773d0f..51fab47 100755 --- a/config.guess +++ b/config.guess @@ -3,7 +3,7 @@ # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, # 2000, 2001, 2002, 2003 Free Software Foundation, Inc. -timestamp='2004-03-03' +timestamp='2004-03-12' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -853,6 +853,9 @@ EOF ia64:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit 0 ;; + m32r*:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-gnu + exit 0 ;; m68*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-gnu exit 0 ;; diff --git a/config.sub b/config.sub index 264f820..ba33103 100755 --- a/config.sub +++ b/config.sub @@ -3,7 +3,7 @@ # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, # 2000, 2001, 2002, 2003 Free Software Foundation, Inc. -timestamp='2004-02-23' +timestamp='2004-03-12' # This file is (in principle) common to ALL GNU software. # The presence of a machine in this file suggests that SOME GNU software @@ -237,7 +237,7 @@ case $basic_machine in | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ | i370 | i860 | i960 | ia64 \ | ip2k | iq2000 \ - | m32r | m68000 | m68k | m88k | mcore \ + | m32r | m32rle | m68000 | m68k | m88k | mcore \ | mips | mipsbe | mipseb | mipsel | mipsle \ | mips16 \ | mips64 | mips64el \ @@ -262,7 +262,7 @@ case $basic_machine in | pyramid \ | sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \ | sh64 | sh64le \ - | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \ + | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv8 | sparcv9 | sparcv9b \ | strongarm \ | tahoe | thumb | tic4x | tic80 | tron \ | v850 | v850e \ @@ -308,7 +308,7 @@ case $basic_machine in | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ | i*86-* | i860-* | i960-* | ia64-* \ | ip2k-* | iq2000-* \ - | m32r-* \ + | m32r-* | m32rle-* \ | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ | m88110-* | m88k-* | mcore-* \ | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ @@ -336,7 +336,7 @@ case $basic_machine in | sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \ | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ | sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \ - | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ + | sparcv8-* | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ | tahoe-* | thumb-* \ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ | tron-* \ @@ -1081,7 +1081,7 @@ case $basic_machine in sh64) basic_machine=sh64-unknown ;; - sparc | sparcv9 | sparcv9b) + sparc | sparcv8 | sparcv9 | sparcv9b) basic_machine=sparc-sun ;; cydra) diff --git a/conserver.cf/conserver.cf.man b/conserver.cf/conserver.cf.man index f310a87..67436c7 100644 --- a/conserver.cf/conserver.cf.man +++ b/conserver.cf/conserver.cf.man @@ -1,5 +1,5 @@ .\" $Id: conserver.cf.man,v 1.58 2004/02/24 02:59:36 bryan Exp $ -.TH CONSERVER.CF 5 "2004/02/24" "conserver-8.1.2" "conserver" +.TH CONSERVER.CF 5 "2004/02/24" "conserver-8.1.3" "conserver" .SH NAME conserver.cf \- console configuration file for .BR conserver (8) diff --git a/conserver.cf/conserver.passwd.man b/conserver.cf/conserver.passwd.man index b221042..4ae55a6 100644 --- a/conserver.cf/conserver.passwd.man +++ b/conserver.cf/conserver.passwd.man @@ -1,5 +1,5 @@ .\" $Id: conserver.passwd.man,v 1.10 2004/01/08 16:12:33 bryan Exp $ -.TH CONSERVER.PASSWD 5 "2004/01/08" "conserver-8.1.2" "conserver" +.TH CONSERVER.PASSWD 5 "2004/01/08" "conserver-8.1.3" "conserver" .SH NAME conserver.passwd \- user access information for .BR conserver (8) diff --git a/conserver.html b/conserver.html index 1f91262..27390f5 100644 --- a/conserver.html +++ b/conserver.html @@ -181,11 +181,11 @@

Downloading

-

The current version, released on Mar 11, 2004, is 8.1.2.tar.gz. You can get it via +

The current version, released on Mar 22, 2004, is 8.1.3.tar.gz. You can get it via FTP - or HTTP. See the FTP + or HTTP. See the CHANGES file for information on the latest updates.

diff --git a/conserver/client.c b/conserver/client.c index 83de702..7e9d32f 100644 --- a/conserver/client.c +++ b/conserver/client.c @@ -1,5 +1,5 @@ /* - * $Id: client.c,v 5.80 2004/03/10 02:55:45 bryan Exp $ + * $Id: client.c,v 5.81 2004/03/20 14:40:40 bryan Exp $ * * Copyright conserver.com, 2000 * @@ -379,7 +379,7 @@ typedef struct HLnode { static HELP aHLTable[] = { {WHEN_ALWAYS, ". disconnect"}, - {WHEN_ALWAYS, "; switch to another console"}, + {WHEN_ALWAYS, "; move to another console"}, {WHEN_ALWAYS, "a attach read/write"}, {WHEN_ALWAYS, "b send broadcast message"}, {WHEN_ATTACH, "c toggle flow control"}, diff --git a/conserver/conserver.man b/conserver/conserver.man index 2c627c8..e127d0b 100644 --- a/conserver/conserver.man +++ b/conserver/conserver.man @@ -1,6 +1,6 @@ .\" @(#)conserver.8 01/06/91 OSU CIS; Thomas A. Fine -.\" $Id: conserver.man,v 1.42 2004/03/11 17:52:08 bryan Exp $ -.TH CONSERVER 8 "2004/03/11" "conserver-8.1.2" "conserver" +.\" $Id: conserver.man,v 1.43 2004/03/23 01:02:29 bryan Exp $ +.TH CONSERVER 8 "2004/03/23" "conserver-8.1.3" "conserver" .SH NAME conserver \- console server daemon .SH SYNOPSIS @@ -334,7 +334,7 @@ Since this is .I highly environment-specific, conserver cannot do the check internally. .RS -.TP 8 +.TP 9 .I name The name of the console. .TP diff --git a/conserver/cutil.c b/conserver/cutil.c index 16630ce..34609f3 100644 --- a/conserver/cutil.c +++ b/conserver/cutil.c @@ -1,5 +1,5 @@ /* - * $Id: cutil.c,v 1.115 2004/03/11 16:23:59 bryan Exp $ + * $Id: cutil.c,v 1.116 2004/03/19 05:23:21 bryan Exp $ * * Copyright conserver.com, 2000 * @@ -839,6 +839,9 @@ FileUnopen(cfp) { int retval = 0; + if (cfp == (CONSFILE *)0) + return 0; + switch (cfp->ftype) { case simpleFile: retval = cfp->fd; diff --git a/conserver/group.c b/conserver/group.c index 39bde16..d02eae9 100644 --- a/conserver/group.c +++ b/conserver/group.c @@ -1,5 +1,5 @@ /* - * $Id: group.c,v 5.289 2004/03/10 02:55:45 bryan Exp $ + * $Id: group.c,v 5.291 2004/03/16 04:17:31 bryan Exp $ * * Copyright conserver.com, 2000 * @@ -3264,8 +3264,7 @@ DoClientRead(pGE, pCLServing) "%c%c", OB_IAC, OB_GOTO); FileSetQuoteIAC(pCLServing->fd, FLAGTRUE); - DisconnectClient(pGE, pCLServing, - (char *)0, FLAGFALSE); + goto bottomSuspend; } else { FileWrite(pCLServing->fd, FLAGFALSE, "connected]\r\n", -1); @@ -3283,9 +3282,9 @@ DoClientRead(pGE, pCLServing) "no drop line]\r\n", -1); break; -#define DEPRECIATED FileWrite(pCLServing->fd, FLAGFALSE, " ", -1) +#define DEPRECATED FileWrite(pCLServing->fd, FLAGFALSE, " ", -1) case 'B': - DEPRECIATED; + DEPRECATED; case 'b': /* broadcast message */ FileWrite(pCLServing->fd, FLAGFALSE, "Enter message: ", -1); @@ -3293,28 +3292,28 @@ DoClientRead(pGE, pCLServing) break; case 'A': - DEPRECIATED; + DEPRECATED; case 'a': /* attach */ CommandAttach(pGE, pCLServing, pCEServing, tyme); break; case 'C': - DEPRECIATED; + DEPRECATED; case 'c': CommandChangeFlow(pGE, pCLServing, pCEServing, tyme); break; case 'D': - DEPRECIATED; + DEPRECATED; case 'd': /* down a console */ CommandDown(pGE, pCLServing, pCEServing, tyme); break; case 'E': - DEPRECIATED; + DEPRECATED; case 'e': /* redefine escape keys */ pCLServing->iState = S_CATTN; FileWrite(pCLServing->fd, FLAGFALSE, @@ -3322,14 +3321,14 @@ DoClientRead(pGE, pCLServing) break; case 'F': - DEPRECIATED; + DEPRECATED; case 'f': /* force attach */ CommandForce(pGE, pCLServing, pCEServing, tyme); break; case 'G': - DEPRECIATED; + DEPRECATED; case 'g': /* group info */ FilePrint(pCLServing->fd, FLAGFALSE, "group %s]\r\n", @@ -3340,14 +3339,14 @@ DoClientRead(pGE, pCLServing) case 'H': case 'P': /* DEC vt100 pf1 */ - DEPRECIATED; + DEPRECATED; case 'h': /* help */ case '?': HelpUser(pCLServing); break; case 'I': - DEPRECIATED; + DEPRECATED; case 'i': FileWrite(pCLServing->fd, FLAGFALSE, "info]\r\n", -1); @@ -3383,7 +3382,7 @@ DoClientRead(pGE, pCLServing) break; case 'O': - DEPRECIATED; + DEPRECATED; case 'o': /* close and re-open line */ CommandOpen(pGE, pCLServing, pCEServing, tyme); @@ -3396,7 +3395,7 @@ DoClientRead(pGE, pCLServing) break; case 'R': /* DEC vt100 pf3 */ - DEPRECIATED; + DEPRECATED; case 'r': /* replay 20 lines */ FileWrite(pCLServing->fd, FLAGFALSE, "replay]\r\n", -1); @@ -3410,7 +3409,7 @@ DoClientRead(pGE, pCLServing) break; case 'S': /* DEC vt100 pf4 */ - DEPRECIATED; + DEPRECATED; case 's': /* spy mode */ pCLServing->fwantwr = 0; if (!pCLServing->fwr) { @@ -3428,7 +3427,7 @@ DoClientRead(pGE, pCLServing) break; case 'U': - DEPRECIATED; + DEPRECATED; case 'u': /* hosts on server this */ FileWrite(pCLServing->fd, FLAGFALSE, "hosts]\r\n", -1); @@ -3437,7 +3436,7 @@ DoClientRead(pGE, pCLServing) break; case 'V': - DEPRECIATED; + DEPRECATED; case 'v': /* version */ FilePrint(pCLServing->fd, FLAGFALSE, "version `%s']\r\n", @@ -3445,7 +3444,7 @@ DoClientRead(pGE, pCLServing) break; case 'W': - DEPRECIATED; + DEPRECATED; case 'w': /* who */ FilePrint(pCLServing->fd, FLAGFALSE, "who %s]\r\n", @@ -3455,7 +3454,7 @@ DoClientRead(pGE, pCLServing) break; case 'X': - DEPRECIATED; + DEPRECATED; case 'x': FileWrite(pCLServing->fd, FLAGFALSE, "examine]\r\n", -1); @@ -3479,13 +3478,14 @@ DoClientRead(pGE, pCLServing) break; case 'Z': - DEPRECIATED; + DEPRECATED; case 'z': /* suspend the client */ case '\032': FileSetQuoteIAC(pCLServing->fd, FLAGFALSE); FilePrint(pCLServing->fd, FLAGFALSE, "%c%c", OB_IAC, OB_SUSP); FileSetQuoteIAC(pCLServing->fd, FLAGTRUE); + bottomSuspend: pCLServing->fcon = 0; pCLServing->iState = S_SUSP; if (pCEServing->pCLwr == pCLServing) { @@ -3547,7 +3547,7 @@ DoClientRead(pGE, pCLServing) break; case 'Q': /* DEC vt100 PF2 */ - DEPRECIATED; + DEPRECATED; case '.': /* disconnect */ case '\004': case '\003': diff --git a/conserver/version.h b/conserver/version.h index a0c1ea5..81bacc3 100644 --- a/conserver/version.h +++ b/conserver/version.h @@ -1,5 +1,5 @@ /* - * $Id: version.h,v 1.58 2004/02/17 15:34:42 bryan Exp $ + * $Id: version.h,v 1.59 2004/03/16 04:17:31 bryan Exp $ * * Copyright conserver.com, 2000 * @@ -14,4 +14,4 @@ @(#) Copyright 2000 conserver.com.\n\ All rights reserved.\n" -#define THIS_VERSION "conserver.com version 8.1.2" +#define THIS_VERSION "conserver.com version 8.1.3" diff --git a/console/console.c b/console/console.c index 2efcfc7..5337fa2 100644 --- a/console/console.c +++ b/console/console.c @@ -1,5 +1,5 @@ /* - * $Id: console.c,v 5.157 2004/03/10 02:55:47 bryan Exp $ + * $Id: console.c,v 5.161 2004/03/20 14:40:42 bryan Exp $ * * Copyright conserver.com, 2000 * @@ -57,7 +57,10 @@ int disconnectCount = 0; STRING *execCmd = (STRING *)0; CONSFILE *execCmdFile = (CONSFILE *)0; pid_t execCmdPid = 0; -int gotoConsole = 0; +CONSFILE *gotoConsole = (CONSFILE *)0; +CONSFILE *prevConsole = (CONSFILE *)0; +char *gotoName = (char *)0; +char *prevName = (char *)0; #if HAVE_OPENSSL SSL_CTX *ctx = (SSL_CTX *)0; @@ -553,6 +556,9 @@ DestroyDataStructures() #endif { C2Cooked(); + if (cfstdout != (CONSFILE *)0) + FileUnopen(cfstdout); + DestroyStrings(); } char * @@ -888,9 +894,217 @@ DoExec(pcf) } } +void +#if PROTOTYPES +Interact(CONSFILE *pcf, char *pcMach) +#else +Interact(pcf, pcMach) + CONSFILE *pcf; + char *pcMach; +#endif +{ + int i; + int nc; + fd_set rmask, wmask; + int justSuspended = 0; + static char acMesg[8192]; + + /* if this is true, it means we successfully moved to a new console + * so we need to close the old one. + */ + if (prevConsole != (CONSFILE *)0) + FileClose(&prevConsole); + if (prevName != (char *)0) { + free(prevName); + prevName = (char *)0; + } + + /* this is only true in other parts of the code iff pcf == gotoConsole */ + if (gotoConsole != (CONSFILE *)0) { + gotoConsole = (CONSFILE *)0; + FilePrint(cfstdout, FLAGFALSE, "[returning to `%s'", pcMach); + FileWrite(pcf, FLAGFALSE, "\n", 1); + } + + C2Raw(); + + /* set socket to non-blocking */ + SetFlags(FileFDNum(pcf), O_NONBLOCK, 0); + + /* read from stdin and the socket (non-blocking!). + * rmask indicates which descriptors to read from, + * the others are not used, nor is the result from + * select, read, or write. + */ + FD_ZERO(&rinit); + FD_ZERO(&winit); + FD_SET(FileFDNum(pcf), &rinit); + FD_SET(0, &rinit); + if (maxfd < FileFDNum(pcf) + 1) + maxfd = FileFDNum(pcf) + 1; + for (;;) { + justSuspended = 0; + if (fSawReapVirt) { + fSawReapVirt = 0; + ReapVirt(); + } + /* reset read mask and select on it + */ + rmask = rinit; + wmask = winit; + if (-1 == + select(maxfd, &rmask, &wmask, (fd_set *)0, + (struct timeval *)0)) { + if (errno != EINTR) { + Error("Master(): select(): %s", strerror(errno)); + break; + } + continue; + } + + /* anything from execCmd */ + if (execCmdFile != (CONSFILE *)0) { + if (FileCanRead(execCmdFile, &rmask, &wmask)) { + if ((nc = + FileRead(execCmdFile, acMesg, sizeof(acMesg))) < 0) { + FD_CLR(FileFDNum(execCmdFile), &rinit); + FD_CLR(FileFDOutNum(execCmdFile), &winit); + FileClose(&execCmdFile); + FileSetQuoteIAC(pcf, FLAGFALSE); + FilePrint(pcf, FLAGFALSE, "%c%c", OB_IAC, OB_ABRT); + FileSetQuoteIAC(pcf, FLAGTRUE); + } else { + if (fStrip) { + for (i = 0; i < nc; ++i) + acMesg[i] &= 127; + } + FileWrite(pcf, FLAGFALSE, acMesg, nc); + } + } else if (!FileBufEmpty(execCmdFile) && + FileCanWrite(execCmdFile, &rmask, &wmask)) { + CONDDEBUG((1, "Interact(): flushing fd %d", + FileFDNum(execCmdFile))); + if (FileWrite(execCmdFile, FLAGFALSE, (char *)0, 0) < 0) { + /* -bryan */ + break; + } + } + } + + /* anything from socket? */ + if (FileCanRead(pcf, &rmask, &wmask)) { + int l; + if ((nc = FileRead(pcf, acMesg, sizeof(acMesg))) < 0) { + /* if we got an error/eof after returning from suspend */ + if (justSuspended) { + fprintf(stderr, "\n"); + Error("lost connection"); + } + break; + } + while ((l = ParseIACBuf(pcf, acMesg, &nc)) >= 0) { + if (l == 0) { + if (execCmdFile == (CONSFILE *)0) { + if (FileSawQuoteExec(pcf) == FLAGTRUE) + DoExec(pcf); + else if (FileSawQuoteSusp(pcf) == FLAGTRUE) { + justSuspended = 1; +#if defined(SIGSTOP) + FileWrite(cfstdout, FLAGFALSE, "stop]", 5); + C2Cooked(); + kill(thepid, SIGSTOP); + C2Raw(); + FileWrite(cfstdout, FLAGFALSE, + "[press any character to continue", + 32); +#else + FileWrite(cfstdout, FLAGFALSE, + "stop not supported -- press any character to continue", + 53); +#endif + } else if (FileSawQuoteGoto(pcf) == FLAGTRUE) { + gotoConsole = pcf; + if (gotoName != (char *)0) + free(gotoName); + if ((gotoName = StrDup(pcMach)) == (char *)0) + OutOfMem(); + C2Cooked(); + return; + } + } else { + if (FileSawQuoteAbrt(pcf) == FLAGTRUE) { + FD_CLR(FileFDNum(execCmdFile), &rinit); + FD_CLR(FileFDOutNum(execCmdFile), &winit); + FileClose(&execCmdFile); + kill(execCmdPid, SIGHUP); + } + } + continue; + } + if (fStrip) { + for (i = 0; i < l; ++i) + acMesg[i] &= 127; + } + FileWrite(cfstdout, FLAGFALSE, acMesg, l); + if (execCmdFile != (CONSFILE *)0) { + FileWrite(execCmdFile, FLAGFALSE, acMesg, l); + } + nc -= l; + MemMove(acMesg, acMesg + l, nc); + } + } else if (!FileBufEmpty(pcf) && FileCanWrite(pcf, &rmask, &wmask)) { + CONDDEBUG((1, "Interact(): flushing fd %d", FileFDNum(pcf))); + if (FileWrite(pcf, FLAGFALSE, (char *)0, 0) < 0) { + /* -bryan */ + break; + } + } + + /* anything from stdin? */ + if (FD_ISSET(0, &rmask)) { + if ((nc = read(0, acMesg, sizeof(acMesg))) == 0) { + if (screwy) + break; + else { + FD_SET(0, &rinit); + continue; + } + } + if (execCmdFile == (CONSFILE *)0) { + if (fStrip) { + for (i = 0; i < nc; ++i) + acMesg[i] &= 127; + } + FileWrite(pcf, FLAGFALSE, acMesg, nc); + } else { + for (i = 0; i < nc; ++i) { + if (acMesg[i] == '\n' || acMesg[i] == '\r') + FilePrint(cfstdout, FLAGFALSE, + "[local command running - pid %lu]\r\n", + execCmdPid); + else if (acMesg[i] == 0x03) { /* ctrl-c */ + kill(execCmdPid, SIGHUP); + FilePrint(cfstdout, FLAGFALSE, + "[local command sent SIGHUP - pid %lu]\r\n", + execCmdPid); + } else if (acMesg[i] == 0x1c) { /* ctrl-\ */ + kill(execCmdPid, SIGKILL); + FilePrint(cfstdout, FLAGFALSE, + "[local command sent SIGKILL - pid %lu]\r\n", + execCmdPid); + } + } + } + } + } + C2Cooked(); + if (fVerbose) + printf("Console %s closed.\n", pcMach); +} + /* interact with a group server (ksb) */ -static int +void #if PROTOTYPES CallUp(CONSFILE *pcf, char *pcMaster, char *pcMach, char *pcHow, char *result) @@ -900,15 +1114,9 @@ CallUp(pcf, pcMaster, pcMach, pcHow, result) char *pcMaster, *pcMach, *pcHow, *result; #endif { - int nc; int fIn = '-'; - fd_set rmask, wmask; - int i; - int justSuspended = 0; char *r = (char *)0; - static char acMesg[8192]; - gotoConsole = 0; if (fVerbose) { Msg("%s to %s (on %s)", pcHow, pcMach, pcMaster); } @@ -1027,176 +1235,7 @@ CallUp(pcf, pcMaster, pcMach, pcHow, result) fflush(stdout); fflush(stderr); - C2Raw(); - - /* set socket to non-blocking */ - SetFlags(FileFDNum(pcf), O_NONBLOCK, 0); - - /* read from stdin and the socket (non-blocking!). - * rmask indicates which descriptors to read from, - * the others are not used, nor is the result from - * select, read, or write. - */ - FD_ZERO(&rinit); - FD_ZERO(&winit); - FD_SET(FileFDNum(pcf), &rinit); - FD_SET(0, &rinit); - if (maxfd < FileFDNum(pcf) + 1) - maxfd = FileFDNum(pcf) + 1; - for (;;) { - justSuspended = 0; - if (fSawReapVirt) { - fSawReapVirt = 0; - ReapVirt(); - } - /* reset read mask and select on it - */ - rmask = rinit; - wmask = winit; - if (-1 == - select(maxfd, &rmask, &wmask, (fd_set *)0, - (struct timeval *)0)) { - if (errno != EINTR) { - Error("Master(): select(): %s", strerror(errno)); - break; - } - continue; - } - - /* anything from execCmd */ - if (execCmdFile != (CONSFILE *)0) { - if (FileCanRead(execCmdFile, &rmask, &wmask)) { - if ((nc = - FileRead(execCmdFile, acMesg, sizeof(acMesg))) < 0) { - FD_CLR(FileFDNum(execCmdFile), &rinit); - FD_CLR(FileFDOutNum(execCmdFile), &winit); - FileClose(&execCmdFile); - FileSetQuoteIAC(pcf, FLAGFALSE); - FilePrint(pcf, FLAGFALSE, "%c%c", OB_IAC, OB_ABRT); - FileSetQuoteIAC(pcf, FLAGTRUE); - } else { - if (fStrip) { - for (i = 0; i < nc; ++i) - acMesg[i] &= 127; - } - FileWrite(pcf, FLAGFALSE, acMesg, nc); - } - } else if (!FileBufEmpty(execCmdFile) && - FileCanWrite(execCmdFile, &rmask, &wmask)) { - CONDDEBUG((1, "CallUp(): flushing fd %d", - FileFDNum(execCmdFile))); - if (FileWrite(execCmdFile, FLAGFALSE, (char *)0, 0) < 0) { - /* -bryan */ - break; - } - } - } - - /* anything from socket? */ - if (FileCanRead(pcf, &rmask, &wmask)) { - int l; - if ((nc = FileRead(pcf, acMesg, sizeof(acMesg))) < 0) { - /* if we got an error/eof after returning from suspend */ - if (justSuspended) { - fprintf(stderr, "\n"); - Error("lost connection"); - } - break; - } - while ((l = ParseIACBuf(pcf, acMesg, &nc)) >= 0) { - if (l == 0) { - if (execCmdFile == (CONSFILE *)0) { - if (FileSawQuoteExec(pcf) == FLAGTRUE) - DoExec(pcf); - else if (FileSawQuoteSusp(pcf) == FLAGTRUE) { - justSuspended = 1; -#if defined(SIGSTOP) - FileWrite(cfstdout, FLAGFALSE, "stop]", 5); - C2Cooked(); - kill(thepid, SIGSTOP); - C2Raw(); - FileWrite(cfstdout, FLAGFALSE, - "[press any character to continue", - 32); -#else - FileWrite(cfstdout, FLAGFALSE, - "stop not supported -- press any character to continue", - 53); -#endif - } else if (FileSawQuoteGoto(pcf) == FLAGTRUE) { - gotoConsole = 1; - break; - } - } else { - if (FileSawQuoteAbrt(pcf) == FLAGTRUE) { - FD_CLR(FileFDNum(execCmdFile), &rinit); - FD_CLR(FileFDOutNum(execCmdFile), &winit); - FileClose(&execCmdFile); - kill(execCmdPid, SIGHUP); - } - } - continue; - } - if (fStrip) { - for (i = 0; i < l; ++i) - acMesg[i] &= 127; - } - FileWrite(cfstdout, FLAGFALSE, acMesg, l); - if (execCmdFile != (CONSFILE *)0) { - FileWrite(execCmdFile, FLAGFALSE, acMesg, l); - } - nc -= l; - MemMove(acMesg, acMesg + l, nc); - } - } else if (!FileBufEmpty(pcf) && FileCanWrite(pcf, &rmask, &wmask)) { - CONDDEBUG((1, "CallUp(): flushing fd %d", FileFDNum(pcf))); - if (FileWrite(pcf, FLAGFALSE, (char *)0, 0) < 0) { - /* -bryan */ - break; - } - } - - /* anything from stdin? */ - if (FD_ISSET(0, &rmask)) { - if ((nc = read(0, acMesg, sizeof(acMesg))) == 0) { - if (screwy) - break; - else { - FD_SET(0, &rinit); - continue; - } - } - if (execCmdFile == (CONSFILE *)0) { - if (fStrip) { - for (i = 0; i < nc; ++i) - acMesg[i] &= 127; - } - FileWrite(pcf, FLAGFALSE, acMesg, nc); - } else { - for (i = 0; i < nc; ++i) { - if (acMesg[i] == '\n' || acMesg[i] == '\r') - FilePrint(cfstdout, FLAGFALSE, - "[local command running - pid %lu]\r\n", - execCmdPid); - else if (acMesg[i] == 0x03) { /* ctrl-c */ - kill(execCmdPid, SIGHUP); - FilePrint(cfstdout, FLAGFALSE, - "[local command sent SIGHUP - pid %lu]\r\n", - execCmdPid); - } else if (acMesg[i] == 0x1c) { /* ctrl-\ */ - kill(execCmdPid, SIGKILL); - FilePrint(cfstdout, FLAGFALSE, - "[local command sent SIGKILL - pid %lu]\r\n", - execCmdPid); - } - } - } - } - } - C2Cooked(); - if (fVerbose) - printf("Console %s closed.\n", pcMach); - return 0; + Interact(pcf, pcMach); } /* shouldn't need more than 3 levels of commands (but alloc 4 just 'cause) @@ -1214,11 +1253,11 @@ char *cmdarg = (char *)0; */ int #if PROTOTYPES -DoCmds(char *master, char *ports, int cmdi) +DoCmds(char *master, char *pports, int cmdi) #else -DoCmds(master, ports, cmdi) +DoCmds(master, pports, cmdi) char *master; - char *ports; + char *pports; int cmdi; #endif { @@ -1229,6 +1268,11 @@ DoCmds(master, ports, cmdi) unsigned short port; char *result = (char *)0; int len; + char *ports; + char *pcopy; + + if ((pcopy = ports = StrDup(pports)) == (char *)0) + OutOfMem(); len = strlen(ports); while (len > 0 && (ports[len - 1] == '\r' || ports[len - 1] == '\n')) @@ -1352,6 +1396,8 @@ DoCmds(master, ports, cmdi) if (cmdi != 0) { t = ReadReply(pcf, 0); /* save the result */ + if (result != (char *)0) + free(result); if ((result = StrDup(t)) == (char *)0) OutOfMem(); } @@ -1371,7 +1417,9 @@ DoCmds(master, ports, cmdi) continue; } else { CallUp(pcf, server, cmdarg, cmds[0], result); - return 0; + if (pcf != gotoConsole) + FileClose(&pcf); + break; } } else if (cmds[cmdi][0] == 'q') { t = ReadReply(pcf, 0); @@ -1388,6 +1436,8 @@ DoCmds(master, ports, cmdi) if (cmdi == 0) { int len; /* if we hit bottom, this is where we get our results */ + if (result != (char *)0) + free(result); if ((result = StrDup(t)) == (char *)0) OutOfMem(); len = strlen(result); @@ -1427,9 +1477,14 @@ DoCmds(master, ports, cmdi) DoCmds(server, result, cmdi); else if (cmdi > 0) DoCmds(server, result, cmdi - 1); - free(result); + if (result != (char *)0) + free(result); + result = (char *)0; } + if (result != (char *)0) + free(result); + free(pcopy); return 0; } @@ -1462,7 +1517,6 @@ main(argc, argv) int i; static STRING *textMsg = (STRING *)0; int cmdi; - int retval; static STRING *consoleName = (STRING *)0; isMultiProc = 0; /* make sure stuff DOESN'T have the pid */ @@ -1648,7 +1702,8 @@ main(argc, argv) Error("missing console name"); Bye(EX_UNAVAILABLE); } - cmdarg = argv[optind++]; + if ((cmdarg = StrDup(argv[optind++])) == (char *)0) + OutOfMem(); } else if (*pcCmd == 't') { if (optind >= argc) { Error("missing message text"); @@ -1737,35 +1792,53 @@ main(argc, argv) } for (;;) { - char *ports; - if ((ports = StrDup(acPorts->string)) == (char *)0) - OutOfMem(); - retval = DoCmds(pcInMaster, ports, cmdi); - free(ports); - /* if we didn't "call" or we didn't ask for another console, abort */ - if (cmds[cmdi][0] != 'c' || gotoConsole == 0) + if (gotoConsole == (CONSFILE *)0) + DoCmds(pcInMaster, acPorts->string, cmdi); + else + Interact(gotoConsole, gotoName); + + /* if we didn't ask for another console, done */ + if (gotoConsole == (CONSFILE *)0 && prevConsole == (CONSFILE *)0) break; if (consoleName == (STRING *)0) consoleName = AllocString(); C2Raw(); - if (gotoConsole == -1) - FileWrite(cfstdout, FLAGFALSE, "[console: ", 10); - else + if (prevConsole == (CONSFILE *)0) FileWrite(cfstdout, FLAGFALSE, "console: ", 9); + else + FileWrite(cfstdout, FLAGFALSE, "[console: ", 10); GetUserInput(consoleName); FileWrite(cfstdout, FLAGFALSE, "]\r\n", 3); C2Cooked(); - if (consoleName->used <= 1) - break; - cmdarg = consoleName->string; - gotoConsole = -1; + if (consoleName->used > 1) { + if (cmdarg != (char *)0) + free(cmdarg); + if ((cmdarg = StrDup(consoleName->string)) == (char *)0) + OutOfMem(); + if (prevConsole == (CONSFILE *)0) { + prevConsole = gotoConsole; + gotoConsole = (CONSFILE *)0; + prevName = gotoName; + gotoName = (char *)0; + } + } else { + if (prevConsole != (CONSFILE *)0) { + gotoConsole = prevConsole; + prevConsole = (CONSFILE *)0; + gotoName = prevName; + prevName = (char *)0; + } + } } + if (cmdarg != (char *)0) + free(cmdarg); + if (*pcCmd == 'd') FilePrint(cfstdout, FLAGFALSE, "Disconnected %d users\n", disconnectCount); - Bye(retval); + Bye(0); return 0; /* noop - Bye() terminates us */ } diff --git a/console/console.man b/console/console.man index 13be1f5..6ec8790 100644 --- a/console/console.man +++ b/console/console.man @@ -1,5 +1,5 @@ -.\" $Id: console.man,v 1.44 2004/03/11 16:23:29 bryan Exp $ -.TH CONSOLE 1 "2004/03/11" "conserver-8.1.2" "conserver" +.\" $Id: console.man,v 1.45 2004/03/20 14:40:42 bryan Exp $ +.TH CONSOLE 1 "2004/03/20" "conserver-8.1.3" "conserver" .SH NAME console \- console server client program .SH SYNOPSIS @@ -391,7 +391,7 @@ Commands are: disconnect .TP .B ; -disconnect and login to another console +move to another console .TP .B a attach read-write if nobody already is diff --git a/contrib/redhat-rpm/conserver.spec b/contrib/redhat-rpm/conserver.spec index 66b280c..75be7a6 100644 --- a/contrib/redhat-rpm/conserver.spec +++ b/contrib/redhat-rpm/conserver.spec @@ -4,7 +4,7 @@ # %define pkg conserver -%define ver 8.1.2 +%define ver 8.1.3 # define the name of the machine on which the main conserver # daemon will be running if you don't want to use the default diff --git a/contrib/solaris-package/pkginfo b/contrib/solaris-package/pkginfo index 0dff7a4..93bd381 100644 --- a/contrib/solaris-package/pkginfo +++ b/contrib/solaris-package/pkginfo @@ -1,7 +1,7 @@ PKG="conserver" NAME="Console server and client" CATEGORY="system" -VERSION="8.1.2" +VERSION="8.1.3" DESC="Console server and client" CLASSES=none ARCH=sparc diff --git a/test/results/test2 b/test/results/test2 index 931773d..f128892 100644 --- a/test/results/test2 +++ b/test/results/test2 @@ -1,6 +1,6 @@ [Enter `^Ec?' for help] [help] - . disconnect ; switch to another console + . disconnect ; move to another console a attach read/write b send broadcast message c toggle flow control d down a console e change escape sequence f force attach read/write diff --git a/test/results/test7 b/test/results/test7 index 931773d..f128892 100644 --- a/test/results/test7 +++ b/test/results/test7 @@ -1,6 +1,6 @@ [Enter `^Ec?' for help] [help] - . disconnect ; switch to another console + . disconnect ; move to another console a attach read/write b send broadcast message c toggle flow control d down a console e change escape sequence f force attach read/write