2000-09-11 08:27:15 +00:00
|
|
|
/*
|
2004-04-27 12:31:57 +00:00
|
|
|
* PLink - a Windows command-line (stdin/stdout) variant of PuTTY.
|
2000-09-11 08:27:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2000-10-24 10:47:49 +00:00
|
|
|
#include <stdlib.h>
|
2002-03-01 13:17:45 +00:00
|
|
|
#include <assert.h>
|
2000-09-11 08:27:15 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2001-05-06 14:35:20 +00:00
|
|
|
#define PUTTY_DO_GLOBALS /* actually _define_ globals */
|
2000-09-11 08:27:15 +00:00
|
|
|
#include "putty.h"
|
2000-10-06 13:21:36 +00:00
|
|
|
#include "storage.h"
|
2000-10-23 10:32:37 +00:00
|
|
|
#include "tree234.h"
|
2000-09-11 08:27:15 +00:00
|
|
|
|
2005-08-10 18:31:24 +00:00
|
|
|
#define WM_AGENT_CALLBACK (WM_APP + 4)
|
2003-04-28 13:59:32 +00:00
|
|
|
|
|
|
|
struct agent_callback {
|
|
|
|
void (*callback)(void *, void *, int);
|
|
|
|
void *callback_ctx;
|
|
|
|
void *data;
|
|
|
|
int len;
|
|
|
|
};
|
|
|
|
|
2001-05-06 14:35:20 +00:00
|
|
|
void fatalbox(char *p, ...)
|
2002-10-09 18:09:42 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
fprintf(stderr, "FATAL ERROR: ");
|
|
|
|
va_start(ap, p);
|
|
|
|
vfprintf(stderr, p, ap);
|
|
|
|
va_end(ap);
|
|
|
|
fputc('\n', stderr);
|
2006-08-29 18:50:07 +00:00
|
|
|
if (logctx) {
|
|
|
|
log_free(logctx);
|
|
|
|
logctx = NULL;
|
|
|
|
}
|
2002-10-09 18:09:42 +00:00
|
|
|
cleanup_exit(1);
|
|
|
|
}
|
|
|
|
void modalfatalbox(char *p, ...)
|
2001-05-06 14:35:20 +00:00
|
|
|
{
|
2000-09-11 08:27:15 +00:00
|
|
|
va_list ap;
|
2000-10-24 10:47:49 +00:00
|
|
|
fprintf(stderr, "FATAL ERROR: ");
|
2000-09-11 08:27:15 +00:00
|
|
|
va_start(ap, p);
|
|
|
|
vfprintf(stderr, p, ap);
|
|
|
|
va_end(ap);
|
|
|
|
fputc('\n', stderr);
|
2006-08-29 18:50:07 +00:00
|
|
|
if (logctx) {
|
|
|
|
log_free(logctx);
|
|
|
|
logctx = NULL;
|
|
|
|
}
|
2002-03-06 20:13:22 +00:00
|
|
|
cleanup_exit(1);
|
2000-09-11 08:27:15 +00:00
|
|
|
}
|
2002-10-26 12:58:13 +00:00
|
|
|
void connection_fatal(void *frontend, char *p, ...)
|
2001-05-06 14:35:20 +00:00
|
|
|
{
|
2000-09-22 11:04:57 +00:00
|
|
|
va_list ap;
|
2000-10-24 10:47:49 +00:00
|
|
|
fprintf(stderr, "FATAL ERROR: ");
|
2000-09-22 11:04:57 +00:00
|
|
|
va_start(ap, p);
|
|
|
|
vfprintf(stderr, p, ap);
|
|
|
|
va_end(ap);
|
|
|
|
fputc('\n', stderr);
|
2006-08-29 18:50:07 +00:00
|
|
|
if (logctx) {
|
|
|
|
log_free(logctx);
|
|
|
|
logctx = NULL;
|
|
|
|
}
|
2002-03-06 20:13:22 +00:00
|
|
|
cleanup_exit(1);
|
2000-09-22 11:04:57 +00:00
|
|
|
}
|
2002-08-04 21:18:56 +00:00
|
|
|
void cmdline_error(char *p, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
fprintf(stderr, "plink: ");
|
|
|
|
va_start(ap, p);
|
|
|
|
vfprintf(stderr, p, ap);
|
|
|
|
va_end(ap);
|
|
|
|
fputc('\n', stderr);
|
|
|
|
exit(1);
|
|
|
|
}
|
2000-09-11 08:27:15 +00:00
|
|
|
|
2001-01-24 14:08:20 +00:00
|
|
|
HANDLE inhandle, outhandle, errhandle;
|
2006-08-25 22:10:16 +00:00
|
|
|
struct handle *stdin_handle, *stdout_handle, *stderr_handle;
|
2000-09-22 13:10:19 +00:00
|
|
|
DWORD orig_console_mode;
|
2006-08-25 22:10:16 +00:00
|
|
|
int connopen;
|
2000-09-22 13:10:19 +00:00
|
|
|
|
2000-10-23 10:32:37 +00:00
|
|
|
WSAEVENT netevent;
|
|
|
|
|
2002-10-26 10:33:59 +00:00
|
|
|
static Backend *back;
|
|
|
|
static void *backhandle;
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
static Conf *conf;
|
2002-10-26 10:33:59 +00:00
|
|
|
|
2002-10-22 16:11:33 +00:00
|
|
|
int term_ldisc(Terminal *term, int mode)
|
2001-05-06 14:35:20 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-10-26 10:16:19 +00:00
|
|
|
void ldisc_update(void *frontend, int echo, int edit)
|
2001-05-06 14:35:20 +00:00
|
|
|
{
|
2001-01-24 14:08:20 +00:00
|
|
|
/* Update stdin read mode to reflect changes in line discipline. */
|
|
|
|
DWORD mode;
|
|
|
|
|
|
|
|
mode = ENABLE_PROCESSED_INPUT;
|
|
|
|
if (echo)
|
2001-05-06 14:35:20 +00:00
|
|
|
mode = mode | ENABLE_ECHO_INPUT;
|
2001-01-24 14:08:20 +00:00
|
|
|
else
|
2001-05-06 14:35:20 +00:00
|
|
|
mode = mode & ~ENABLE_ECHO_INPUT;
|
2001-01-24 14:08:20 +00:00
|
|
|
if (edit)
|
2001-05-06 14:35:20 +00:00
|
|
|
mode = mode | ENABLE_LINE_INPUT;
|
2001-01-24 14:08:20 +00:00
|
|
|
else
|
2001-05-06 14:35:20 +00:00
|
|
|
mode = mode & ~ENABLE_LINE_INPUT;
|
2001-01-24 14:08:20 +00:00
|
|
|
SetConsoleMode(inhandle, mode);
|
|
|
|
}
|
|
|
|
|
2005-04-21 13:57:08 +00:00
|
|
|
char *get_ttymode(void *frontend, const char *mode) { return NULL; }
|
|
|
|
|
2003-02-01 17:24:27 +00:00
|
|
|
int from_backend(void *frontend_handle, int is_stderr,
|
|
|
|
const char *data, int len)
|
2001-08-25 17:09:23 +00:00
|
|
|
{
|
|
|
|
if (is_stderr) {
|
2006-08-25 22:10:16 +00:00
|
|
|
handle_write(stderr_handle, data, len);
|
2001-08-25 17:09:23 +00:00
|
|
|
} else {
|
2006-08-25 22:10:16 +00:00
|
|
|
handle_write(stdout_handle, data, len);
|
2001-08-25 17:09:23 +00:00
|
|
|
}
|
|
|
|
|
2006-08-25 22:10:16 +00:00
|
|
|
return handle_backlog(stdout_handle) + handle_backlog(stderr_handle);
|
2001-08-25 17:09:23 +00:00
|
|
|
}
|
|
|
|
|
2005-10-30 20:24:09 +00:00
|
|
|
int from_backend_untrusted(void *frontend_handle, const char *data, int len)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* No "untrusted" output should get here (the way the code is
|
|
|
|
* currently, it's all diverted by FLAG_STDERR).
|
|
|
|
*/
|
|
|
|
assert(!"Unexpected call to from_backend_untrusted()");
|
|
|
|
return 0; /* not reached */
|
|
|
|
}
|
|
|
|
|
|
|
|
int get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
ret = cmdline_get_passwd_input(p, in, inlen);
|
|
|
|
if (ret == -1)
|
|
|
|
ret = console_get_userpass_input(p, in, inlen);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-04-28 13:59:32 +00:00
|
|
|
static DWORD main_thread_id;
|
|
|
|
|
|
|
|
void agent_schedule_callback(void (*callback)(void *, void *, int),
|
|
|
|
void *callback_ctx, void *data, int len)
|
|
|
|
{
|
|
|
|
struct agent_callback *c = snew(struct agent_callback);
|
|
|
|
c->callback = callback;
|
|
|
|
c->callback_ctx = callback_ctx;
|
|
|
|
c->data = data;
|
|
|
|
c->len = len;
|
|
|
|
PostThreadMessage(main_thread_id, WM_AGENT_CALLBACK, 0, (LPARAM)c);
|
|
|
|
}
|
|
|
|
|
2000-09-29 08:56:30 +00:00
|
|
|
/*
|
|
|
|
* Short description of parameters.
|
|
|
|
*/
|
|
|
|
static void usage(void)
|
|
|
|
{
|
|
|
|
printf("PuTTY Link: command-line connection utility\n");
|
|
|
|
printf("%s\n", ver);
|
|
|
|
printf("Usage: plink [options] [user@]host [command]\n");
|
2001-09-26 20:31:02 +00:00
|
|
|
printf(" (\"host\" can also be a PuTTY saved session name)\n");
|
2000-09-29 08:56:30 +00:00
|
|
|
printf("Options:\n");
|
2005-03-19 02:26:58 +00:00
|
|
|
printf(" -V print version information and exit\n");
|
|
|
|
printf(" -pgpfp print PGP key fingerprints and exit\n");
|
2000-09-29 08:56:30 +00:00
|
|
|
printf(" -v show verbose messages\n");
|
2002-09-11 17:30:36 +00:00
|
|
|
printf(" -load sessname Load settings from saved session\n");
|
2009-08-13 22:01:20 +00:00
|
|
|
printf(" -ssh -telnet -rlogin -raw -serial\n");
|
2004-08-19 13:15:02 +00:00
|
|
|
printf(" force use of a particular protocol\n");
|
2000-09-29 08:56:30 +00:00
|
|
|
printf(" -P port connect to specified port\n");
|
2002-09-11 17:30:36 +00:00
|
|
|
printf(" -l user connect with specified username\n");
|
|
|
|
printf(" -batch disable all interactive prompts\n");
|
|
|
|
printf("The following options only apply to SSH connections:\n");
|
|
|
|
printf(" -pw passw login with specified password\n");
|
2004-01-20 12:46:36 +00:00
|
|
|
printf(" -D [listen-IP:]listen-port\n");
|
|
|
|
printf(" Dynamic SOCKS-based port forwarding\n");
|
|
|
|
printf(" -L [listen-IP:]listen-port:host:port\n");
|
|
|
|
printf(" Forward local port to remote address\n");
|
|
|
|
printf(" -R [listen-IP:]listen-port:host:port\n");
|
|
|
|
printf(" Forward remote port to local address\n");
|
2002-09-11 17:30:36 +00:00
|
|
|
printf(" -X -x enable / disable X11 forwarding\n");
|
|
|
|
printf(" -A -a enable / disable agent forwarding\n");
|
|
|
|
printf(" -t -T enable / disable pty allocation\n");
|
|
|
|
printf(" -1 -2 force use of particular protocol version\n");
|
2004-12-30 16:45:11 +00:00
|
|
|
printf(" -4 -6 force use of IPv4 or IPv6\n");
|
2002-09-11 17:30:36 +00:00
|
|
|
printf(" -C enable compression\n");
|
|
|
|
printf(" -i key private key file for authentication\n");
|
2006-02-19 12:52:28 +00:00
|
|
|
printf(" -noagent disable use of Pageant\n");
|
|
|
|
printf(" -agent enable use of Pageant\n");
|
2005-03-01 00:33:18 +00:00
|
|
|
printf(" -m file read remote command(s) from file\n");
|
2003-08-29 19:06:22 +00:00
|
|
|
printf(" -s remote command is an SSH subsystem (SSH-2 only)\n");
|
2004-10-15 23:32:01 +00:00
|
|
|
printf(" -N don't start a shell/command (SSH-2 only)\n");
|
2006-08-28 17:47:43 +00:00
|
|
|
printf(" -nc host:port\n");
|
|
|
|
printf(" open tunnel in place of session (SSH-2 only)\n");
|
2009-08-10 20:55:19 +00:00
|
|
|
printf(" -sercfg configuration-string (e.g. 19200,8,n,1,X)\n");
|
|
|
|
printf(" Specify the serial configuration (serial only)\n");
|
2004-04-17 20:25:09 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void version(void)
|
|
|
|
{
|
|
|
|
printf("plink: %s\n", ver);
|
2000-09-29 08:56:30 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2001-05-06 14:35:20 +00:00
|
|
|
char *do_select(SOCKET skt, int startup)
|
|
|
|
{
|
2000-10-23 10:32:37 +00:00
|
|
|
int events;
|
|
|
|
if (startup) {
|
2001-09-07 22:39:01 +00:00
|
|
|
events = (FD_CONNECT | FD_READ | FD_WRITE |
|
|
|
|
FD_OOB | FD_CLOSE | FD_ACCEPT);
|
2000-10-23 10:32:37 +00:00
|
|
|
} else {
|
|
|
|
events = 0;
|
|
|
|
}
|
2003-10-12 13:46:12 +00:00
|
|
|
if (p_WSAEventSelect(skt, netevent, events) == SOCKET_ERROR) {
|
|
|
|
switch (p_WSAGetLastError()) {
|
2001-05-06 14:35:20 +00:00
|
|
|
case WSAENETDOWN:
|
|
|
|
return "Network is down";
|
|
|
|
default:
|
2003-10-12 13:46:12 +00:00
|
|
|
return "WSAEventSelect(): unknown error";
|
2001-05-06 14:35:20 +00:00
|
|
|
}
|
2000-10-23 10:32:37 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-08-25 22:10:16 +00:00
|
|
|
int stdin_gotdata(struct handle *h, void *data, int len)
|
|
|
|
{
|
|
|
|
if (len < 0) {
|
|
|
|
/*
|
|
|
|
* Special case: report read error.
|
|
|
|
*/
|
2007-03-27 19:10:10 +00:00
|
|
|
char buf[4096];
|
|
|
|
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, -len, 0,
|
|
|
|
buf, lenof(buf), NULL);
|
|
|
|
buf[lenof(buf)-1] = '\0';
|
|
|
|
if (buf[strlen(buf)-1] == '\n')
|
|
|
|
buf[strlen(buf)-1] = '\0';
|
|
|
|
fprintf(stderr, "Unable to read from standard input: %s\n", buf);
|
2006-08-25 22:10:16 +00:00
|
|
|
cleanup_exit(0);
|
|
|
|
}
|
|
|
|
noise_ultralight(len);
|
2006-08-27 08:03:19 +00:00
|
|
|
if (connopen && back->connected(backhandle)) {
|
2006-08-25 22:10:16 +00:00
|
|
|
if (len > 0) {
|
|
|
|
return back->send(backhandle, data, len);
|
|
|
|
} else {
|
|
|
|
back->special(backhandle, TS_EOF);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void stdouterr_sent(struct handle *h, int new_backlog)
|
|
|
|
{
|
|
|
|
if (new_backlog < 0) {
|
|
|
|
/*
|
|
|
|
* Special case: report write error.
|
|
|
|
*/
|
2007-03-27 19:10:10 +00:00
|
|
|
char buf[4096];
|
|
|
|
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, -new_backlog, 0,
|
|
|
|
buf, lenof(buf), NULL);
|
|
|
|
buf[lenof(buf)-1] = '\0';
|
|
|
|
if (buf[strlen(buf)-1] == '\n')
|
|
|
|
buf[strlen(buf)-1] = '\0';
|
|
|
|
fprintf(stderr, "Unable to write to standard %s: %s\n",
|
|
|
|
(h == stdout_handle ? "output" : "error"), buf);
|
2006-08-25 22:10:16 +00:00
|
|
|
cleanup_exit(0);
|
|
|
|
}
|
2006-08-27 08:03:19 +00:00
|
|
|
if (connopen && back->connected(backhandle)) {
|
2006-08-25 22:10:16 +00:00
|
|
|
back->unthrottle(backhandle, (handle_backlog(stdout_handle) +
|
|
|
|
handle_backlog(stderr_handle)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-06 14:35:20 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2000-09-11 08:27:15 +00:00
|
|
|
int sending;
|
2000-09-29 08:56:30 +00:00
|
|
|
int portnumber = -1;
|
2000-10-23 10:32:37 +00:00
|
|
|
SOCKET *sklist;
|
|
|
|
int skcount, sksize;
|
2001-12-29 15:31:42 +00:00
|
|
|
int exitcode;
|
2002-11-20 20:09:02 +00:00
|
|
|
int errors;
|
2009-09-14 21:26:48 +00:00
|
|
|
int got_host = FALSE;
|
2003-08-29 19:06:22 +00:00
|
|
|
int use_subsystem = 0;
|
2004-11-27 13:20:21 +00:00
|
|
|
long now, next;
|
2000-09-11 08:27:15 +00:00
|
|
|
|
2001-05-06 14:35:20 +00:00
|
|
|
sklist = NULL;
|
|
|
|
skcount = sksize = 0;
|
2001-05-19 15:59:02 +00:00
|
|
|
/*
|
|
|
|
* Initialise port and protocol to sensible defaults. (These
|
|
|
|
* will be overridden by more or less anything.)
|
|
|
|
*/
|
|
|
|
default_protocol = PROT_SSH;
|
|
|
|
default_port = 22;
|
2000-10-23 10:32:37 +00:00
|
|
|
|
2000-09-21 14:34:32 +00:00
|
|
|
flags = FLAG_STDERR;
|
2000-09-11 08:27:15 +00:00
|
|
|
/*
|
|
|
|
* Process the command line.
|
|
|
|
*/
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
conf = conf_new();
|
|
|
|
do_defaults(NULL, conf);
|
2004-07-25 14:00:26 +00:00
|
|
|
loaded_session = FALSE;
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
default_protocol = conf_get_int(conf, CONF_protocol);
|
|
|
|
default_port = conf_get_int(conf, CONF_port);
|
2002-11-20 20:09:02 +00:00
|
|
|
errors = 0;
|
2000-10-05 12:15:22 +00:00
|
|
|
{
|
2001-05-06 14:35:20 +00:00
|
|
|
/*
|
|
|
|
* Override the default protocol if PLINK_PROTOCOL is set.
|
|
|
|
*/
|
|
|
|
char *p = getenv("PLINK_PROTOCOL");
|
|
|
|
if (p) {
|
2007-06-30 21:56:44 +00:00
|
|
|
const Backend *b = backend_from_name(p);
|
|
|
|
if (b) {
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
default_protocol = b->protocol;
|
|
|
|
default_port = b->default_port;
|
|
|
|
conf_set_int(conf, CONF_protocol, default_protocol);
|
|
|
|
conf_set_int(conf, CONF_port, default_port);
|
2001-05-06 14:35:20 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-05 12:15:22 +00:00
|
|
|
}
|
2000-09-11 08:27:15 +00:00
|
|
|
while (--argc) {
|
2001-05-06 14:35:20 +00:00
|
|
|
char *p = *++argv;
|
|
|
|
if (*p == '-') {
|
2003-01-12 14:17:03 +00:00
|
|
|
int ret = cmdline_process_param(p, (argc > 1 ? argv[1] : NULL),
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
1, conf);
|
2002-08-04 21:18:56 +00:00
|
|
|
if (ret == -2) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"plink: option \"%s\" requires an argument\n", p);
|
2002-11-20 20:09:02 +00:00
|
|
|
errors = 1;
|
2002-08-04 21:18:56 +00:00
|
|
|
} else if (ret == 2) {
|
|
|
|
--argc, ++argv;
|
|
|
|
} else if (ret == 1) {
|
|
|
|
continue;
|
2001-12-31 16:15:19 +00:00
|
|
|
} else if (!strcmp(p, "-batch")) {
|
2002-08-04 21:18:56 +00:00
|
|
|
console_batch_mode = 1;
|
2003-08-29 19:06:22 +00:00
|
|
|
} else if (!strcmp(p, "-s")) {
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
/* Save status to write to conf later. */
|
2003-08-29 19:06:22 +00:00
|
|
|
use_subsystem = 1;
|
2004-04-17 20:25:09 +00:00
|
|
|
} else if (!strcmp(p, "-V")) {
|
|
|
|
version();
|
2005-03-19 02:26:58 +00:00
|
|
|
} else if (!strcmp(p, "-pgpfp")) {
|
|
|
|
pgp_fingerprints();
|
|
|
|
exit(1);
|
2002-11-20 20:09:02 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "plink: unknown option \"%s\"\n", p);
|
|
|
|
errors = 1;
|
2001-05-06 14:35:20 +00:00
|
|
|
}
|
2000-09-11 08:27:15 +00:00
|
|
|
} else if (*p) {
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
if (!conf_launchable(conf) || !(got_host || loaded_session)) {
|
2001-05-06 14:35:20 +00:00
|
|
|
char *q = p;
|
|
|
|
/*
|
|
|
|
* If the hostname starts with "telnet:", set the
|
|
|
|
* protocol to Telnet and process the string as a
|
|
|
|
* Telnet URL.
|
|
|
|
*/
|
|
|
|
if (!strncmp(q, "telnet:", 7)) {
|
|
|
|
char c;
|
|
|
|
|
|
|
|
q += 7;
|
|
|
|
if (q[0] == '/' && q[1] == '/')
|
|
|
|
q += 2;
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
conf_set_int(conf, CONF_protocol, PROT_TELNET);
|
2001-05-06 14:35:20 +00:00
|
|
|
p = q;
|
|
|
|
while (*p && *p != ':' && *p != '/')
|
|
|
|
p++;
|
|
|
|
c = *p;
|
|
|
|
if (*p)
|
|
|
|
*p++ = '\0';
|
|
|
|
if (c == ':')
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
conf_set_int(conf, CONF_port, atoi(p));
|
2001-05-06 14:35:20 +00:00
|
|
|
else
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
conf_set_int(conf, CONF_port, -1);
|
|
|
|
conf_set_str(conf, CONF_host, q);
|
2009-09-14 21:26:48 +00:00
|
|
|
got_host = TRUE;
|
2001-05-06 14:35:20 +00:00
|
|
|
} else {
|
2004-08-19 15:05:31 +00:00
|
|
|
char *r, *user, *host;
|
2001-05-06 14:35:20 +00:00
|
|
|
/*
|
|
|
|
* Before we process the [user@]host string, we
|
|
|
|
* first check for the presence of a protocol
|
|
|
|
* prefix (a protocol name followed by ",").
|
|
|
|
*/
|
|
|
|
r = strchr(p, ',');
|
|
|
|
if (r) {
|
2007-06-30 21:56:44 +00:00
|
|
|
const Backend *b;
|
|
|
|
*r = '\0';
|
|
|
|
b = backend_from_name(p);
|
|
|
|
if (b) {
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
default_protocol = b->protocol;
|
|
|
|
conf_set_int(conf, CONF_protocol,
|
|
|
|
default_protocol);
|
2007-06-30 21:56:44 +00:00
|
|
|
portnumber = b->default_port;
|
2001-05-06 14:35:20 +00:00
|
|
|
}
|
2007-06-30 21:56:44 +00:00
|
|
|
p = r + 1;
|
2001-05-06 14:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-08-19 15:05:31 +00:00
|
|
|
* A nonzero length string followed by an @ is treated
|
|
|
|
* as a username. (We discount an _initial_ @.) The
|
|
|
|
* rest of the string (or the whole string if no @)
|
|
|
|
* is treated as a session name and/or hostname.
|
2001-05-06 14:35:20 +00:00
|
|
|
*/
|
|
|
|
r = strrchr(p, '@');
|
|
|
|
if (r == p)
|
|
|
|
p++, r = NULL; /* discount initial @ */
|
2004-08-19 15:05:31 +00:00
|
|
|
if (r) {
|
|
|
|
*r++ = '\0';
|
|
|
|
user = p, host = r;
|
|
|
|
} else {
|
|
|
|
user = NULL, host = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now attempt to load a saved session with the
|
|
|
|
* same name as the hostname.
|
|
|
|
*/
|
|
|
|
{
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
Conf *conf2 = conf_new();
|
|
|
|
do_defaults(host, conf2);
|
|
|
|
if (loaded_session || !conf_launchable(conf2)) {
|
2001-05-06 14:35:20 +00:00
|
|
|
/* No settings for this host; use defaults */
|
2004-07-25 14:00:26 +00:00
|
|
|
/* (or session was already loaded with -load) */
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
conf_set_str(conf, CONF_host, host);
|
|
|
|
conf_set_int(conf, CONF_port, default_port);
|
2009-09-14 21:26:48 +00:00
|
|
|
got_host = TRUE;
|
2001-05-06 14:35:20 +00:00
|
|
|
} else {
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
conf_copy_into(conf, conf2);
|
2009-09-14 21:26:48 +00:00
|
|
|
loaded_session = TRUE;
|
2001-05-06 14:35:20 +00:00
|
|
|
}
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
conf_free(conf2);
|
2004-08-19 15:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (user) {
|
|
|
|
/* Patch in specified username. */
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
conf_set_str(conf, CONF_username, user);
|
2001-05-06 14:35:20 +00:00
|
|
|
}
|
2004-08-19 15:05:31 +00:00
|
|
|
|
2001-05-06 14:35:20 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-02-27 22:31:23 +00:00
|
|
|
char *command;
|
|
|
|
int cmdlen, cmdsize;
|
|
|
|
cmdlen = cmdsize = 0;
|
|
|
|
command = NULL;
|
|
|
|
|
|
|
|
while (argc) {
|
|
|
|
while (*p) {
|
|
|
|
if (cmdlen >= cmdsize) {
|
|
|
|
cmdsize = cmdlen + 512;
|
2003-03-29 16:14:26 +00:00
|
|
|
command = sresize(command, cmdsize, char);
|
2002-02-27 22:31:23 +00:00
|
|
|
}
|
|
|
|
command[cmdlen++]=*p++;
|
|
|
|
}
|
|
|
|
if (cmdlen >= cmdsize) {
|
|
|
|
cmdsize = cmdlen + 512;
|
2003-03-29 16:14:26 +00:00
|
|
|
command = sresize(command, cmdsize, char);
|
2002-02-27 22:31:23 +00:00
|
|
|
}
|
|
|
|
command[cmdlen++]=' '; /* always add trailing space */
|
|
|
|
if (--argc) p = *++argv;
|
2001-05-06 14:35:20 +00:00
|
|
|
}
|
2002-02-27 22:31:23 +00:00
|
|
|
if (cmdlen) command[--cmdlen]='\0';
|
|
|
|
/* change trailing blank to NUL */
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
conf_set_str(conf, CONF_remote_cmd, command);
|
|
|
|
conf_set_str(conf, CONF_remote_cmd2, "");
|
|
|
|
conf_set_int(conf, CONF_nopty, TRUE); /* command => no tty */
|
2002-02-27 22:31:23 +00:00
|
|
|
|
2001-05-06 14:35:20 +00:00
|
|
|
break; /* done with cmdline */
|
|
|
|
}
|
2000-09-11 08:27:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-20 20:09:02 +00:00
|
|
|
if (errors)
|
|
|
|
return 1;
|
|
|
|
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
if (!conf_launchable(conf) || !(got_host || loaded_session)) {
|
2001-05-06 14:35:20 +00:00
|
|
|
usage();
|
2000-09-29 08:56:30 +00:00
|
|
|
}
|
|
|
|
|
2001-10-30 21:45:27 +00:00
|
|
|
/*
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
* Muck about with the hostname in various ways.
|
2001-10-30 21:45:27 +00:00
|
|
|
*/
|
|
|
|
{
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
char *hostbuf = dupstr(conf_get_str(conf, CONF_host));
|
|
|
|
char *host = hostbuf;
|
|
|
|
char *p, *q;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Trim leading whitespace.
|
|
|
|
*/
|
|
|
|
host += strspn(host, " \t");
|
2001-10-30 21:45:27 +00:00
|
|
|
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
/*
|
|
|
|
* See if host is of the form user@host, and separate out
|
|
|
|
* the username if so.
|
|
|
|
*/
|
|
|
|
if (host[0] != '\0') {
|
|
|
|
char *atsign = strrchr(host, '@');
|
|
|
|
if (atsign) {
|
|
|
|
*atsign = '\0';
|
|
|
|
conf_set_str(conf, CONF_username, host);
|
|
|
|
host = atsign + 1;
|
2001-10-30 21:45:27 +00:00
|
|
|
}
|
|
|
|
}
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Trim off a colon suffix if it's there.
|
|
|
|
*/
|
|
|
|
host[strcspn(host, ":")] = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove any remaining whitespace.
|
|
|
|
*/
|
|
|
|
p = hostbuf;
|
|
|
|
q = host;
|
|
|
|
while (*q) {
|
|
|
|
if (*q != ' ' && *q != '\t')
|
|
|
|
*p++ = *q;
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
conf_set_str(conf, CONF_host, hostbuf);
|
|
|
|
sfree(hostbuf);
|
2001-10-30 21:45:27 +00:00
|
|
|
}
|
|
|
|
|
2002-08-04 21:18:56 +00:00
|
|
|
/*
|
|
|
|
* Perform command-line overrides on session configuration.
|
|
|
|
*/
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
cmdline_run_saved(conf);
|
2002-08-04 21:18:56 +00:00
|
|
|
|
2003-08-29 19:06:22 +00:00
|
|
|
/*
|
|
|
|
* Apply subsystem status.
|
|
|
|
*/
|
|
|
|
if (use_subsystem)
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
conf_set_int(conf, CONF_ssh_subsys, TRUE);
|
2002-10-16 11:35:13 +00:00
|
|
|
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
if (!*conf_get_str(conf, CONF_remote_cmd) &&
|
|
|
|
!*conf_get_str(conf, CONF_remote_cmd2) &&
|
|
|
|
!*conf_get_str(conf, CONF_ssh_nc_host))
|
2001-05-06 14:35:20 +00:00
|
|
|
flags |= FLAG_INTERACTIVE;
|
2000-09-21 14:34:32 +00:00
|
|
|
|
2000-09-11 08:27:15 +00:00
|
|
|
/*
|
|
|
|
* Select protocol. This is farmed out into a table in a
|
|
|
|
* separate file to enable an ssh-free variant.
|
|
|
|
*/
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
back = backend_from_proto(conf_get_int(conf, CONF_protocol));
|
2007-06-30 21:56:44 +00:00
|
|
|
if (back == NULL) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Internal fault: Unsupported protocol found\n");
|
|
|
|
return 1;
|
2000-09-11 08:27:15 +00:00
|
|
|
}
|
|
|
|
|
2000-10-05 12:15:22 +00:00
|
|
|
/*
|
|
|
|
* Select port.
|
|
|
|
*/
|
|
|
|
if (portnumber != -1)
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
conf_set_int(conf, CONF_port, portnumber);
|
2000-10-05 12:15:22 +00:00
|
|
|
|
2003-10-12 13:46:12 +00:00
|
|
|
sk_init();
|
|
|
|
if (p_WSAEventSelect == NULL) {
|
|
|
|
fprintf(stderr, "Plink requires WinSock 2\n");
|
2000-09-11 08:27:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
logctx = log_init(NULL, conf);
|
2006-08-27 08:34:04 +00:00
|
|
|
console_provide_logctx(logctx);
|
|
|
|
|
2000-09-11 08:27:15 +00:00
|
|
|
/*
|
|
|
|
* Start up the connection.
|
|
|
|
*/
|
2000-10-23 10:32:37 +00:00
|
|
|
netevent = CreateEvent(NULL, FALSE, FALSE, NULL);
|
2000-09-11 08:27:15 +00:00
|
|
|
{
|
2003-05-04 14:18:18 +00:00
|
|
|
const char *error;
|
2000-09-11 08:27:15 +00:00
|
|
|
char *realhost;
|
2001-11-29 21:47:11 +00:00
|
|
|
/* nodelay is only useful if stdin is a character device (console) */
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
int nodelay = conf_get_int(conf, CONF_tcp_nodelay) &&
|
2001-11-29 21:47:11 +00:00
|
|
|
(GetFileType(GetStdHandle(STD_INPUT_HANDLE)) == FILE_TYPE_CHAR);
|
2000-09-11 08:27:15 +00:00
|
|
|
|
Post-release destabilisation! Completely remove the struct type
'Config' in putty.h, which stores all PuTTY's settings and includes an
arbitrary length limit on every single one of those settings which is
stored in string form. In place of it is 'Conf', an opaque data type
everywhere outside the new file conf.c, which stores a list of (key,
value) pairs in which every key contains an integer identifying a
configuration setting, and for some of those integers the key also
contains extra parts (so that, for instance, CONF_environmt is a
string-to-string mapping). Everywhere that a Config was previously
used, a Conf is now; everywhere there was a Config structure copy,
conf_copy() is called; every lookup, adjustment, load and save
operation on a Config has been rewritten; and there's a mechanism for
serialising a Conf into a binary blob and back for use with Duplicate
Session.
User-visible effects of this change _should_ be minimal, though I
don't doubt I've introduced one or two bugs here and there which will
eventually be found. The _intended_ visible effects of this change are
that all arbitrary limits on configuration strings and lists (e.g.
limit on number of port forwardings) should now disappear; that list
boxes in the configuration will now be displayed in a sorted order
rather than the arbitrary order in which they were added to the list
(since the underlying data structure is now a sorted tree234 rather
than an ad-hoc comma-separated string); and one more specific change,
which is that local and dynamic port forwardings on the same port
number are now mutually exclusive in the configuration (putting 'D' in
the key rather than the value was a mistake in the first place).
One other reorganisation as a result of this is that I've moved all
the dialog.c standard handlers (dlg_stdeditbox_handler and friends)
out into config.c, because I can't really justify calling them generic
any more. When they took a pointer to an arbitrary structure type and
the offset of a field within that structure, they were independent of
whether that structure was a Config or something completely different,
but now they really do expect to talk to a Conf, which can _only_ be
used for PuTTY configuration, so I've renamed them all things like
conf_editbox_handler and moved them out of the nominally independent
dialog-box management module into the PuTTY-specific config.c.
[originally from svn r9214]
2011-07-14 18:52:21 +00:00
|
|
|
error = back->init(NULL, &backhandle, conf,
|
|
|
|
conf_get_str(conf, CONF_host),
|
|
|
|
conf_get_int(conf, CONF_port),
|
|
|
|
&realhost, nodelay,
|
|
|
|
conf_get_int(conf, CONF_tcp_keepalives));
|
2000-09-11 08:27:15 +00:00
|
|
|
if (error) {
|
|
|
|
fprintf(stderr, "Unable to open connection:\n%s", error);
|
|
|
|
return 1;
|
|
|
|
}
|
2002-10-26 12:58:13 +00:00
|
|
|
back->provide_logctx(backhandle, logctx);
|
2001-05-09 14:01:15 +00:00
|
|
|
sfree(realhost);
|
2000-09-11 08:27:15 +00:00
|
|
|
}
|
2000-10-23 10:32:37 +00:00
|
|
|
connopen = 1;
|
2000-09-11 08:27:15 +00:00
|
|
|
|
2001-01-24 14:08:20 +00:00
|
|
|
inhandle = GetStdHandle(STD_INPUT_HANDLE);
|
2000-09-11 08:27:15 +00:00
|
|
|
outhandle = GetStdHandle(STD_OUTPUT_HANDLE);
|
2000-10-20 13:51:46 +00:00
|
|
|
errhandle = GetStdHandle(STD_ERROR_HANDLE);
|
2006-08-25 22:10:16 +00:00
|
|
|
|
2000-09-11 08:27:15 +00:00
|
|
|
/*
|
|
|
|
* Turn off ECHO and LINE input modes. We don't care if this
|
|
|
|
* call fails, because we know we aren't necessarily running in
|
|
|
|
* a console.
|
|
|
|
*/
|
2005-06-19 13:57:50 +00:00
|
|
|
GetConsoleMode(inhandle, &orig_console_mode);
|
|
|
|
SetConsoleMode(inhandle, ENABLE_PROCESSED_INPUT);
|
|
|
|
|
2006-08-25 22:10:16 +00:00
|
|
|
/*
|
|
|
|
* Pass the output handles to the handle-handling subsystem.
|
|
|
|
* (The input one we leave until we're through the
|
|
|
|
* authentication process.)
|
|
|
|
*/
|
2006-08-27 10:00:36 +00:00
|
|
|
stdout_handle = handle_output_new(outhandle, stdouterr_sent, NULL, 0);
|
|
|
|
stderr_handle = handle_output_new(errhandle, stdouterr_sent, NULL, 0);
|
2006-08-25 22:10:16 +00:00
|
|
|
|
2005-06-19 13:57:50 +00:00
|
|
|
main_thread_id = GetCurrentThreadId();
|
|
|
|
|
2000-09-11 08:27:15 +00:00
|
|
|
sending = FALSE;
|
2001-08-25 17:09:23 +00:00
|
|
|
|
2004-11-27 13:20:21 +00:00
|
|
|
now = GETTICKCOUNT();
|
|
|
|
|
2000-09-11 08:27:15 +00:00
|
|
|
while (1) {
|
2006-08-25 22:10:16 +00:00
|
|
|
int nhandles;
|
|
|
|
HANDLE *handles;
|
2001-05-06 14:35:20 +00:00
|
|
|
int n;
|
2004-11-27 13:20:21 +00:00
|
|
|
DWORD ticks;
|
2001-05-06 14:35:20 +00:00
|
|
|
|
2002-10-25 11:30:33 +00:00
|
|
|
if (!sending && back->sendok(backhandle)) {
|
2006-08-27 10:00:36 +00:00
|
|
|
stdin_handle = handle_input_new(inhandle, stdin_gotdata, NULL,
|
|
|
|
0);
|
2001-05-06 14:35:20 +00:00
|
|
|
sending = TRUE;
|
|
|
|
}
|
|
|
|
|
2004-11-27 13:20:21 +00:00
|
|
|
if (run_timers(now, &next)) {
|
|
|
|
ticks = next - GETTICKCOUNT();
|
|
|
|
if (ticks < 0) ticks = 0; /* just in case */
|
|
|
|
} else {
|
|
|
|
ticks = INFINITE;
|
|
|
|
}
|
|
|
|
|
2006-08-25 22:10:16 +00:00
|
|
|
handles = handle_get_events(&nhandles);
|
|
|
|
handles = sresize(handles, nhandles+1, HANDLE);
|
|
|
|
handles[nhandles] = netevent;
|
|
|
|
n = MsgWaitForMultipleObjects(nhandles+1, handles, FALSE, ticks,
|
2003-04-28 13:59:32 +00:00
|
|
|
QS_POSTMESSAGE);
|
2006-08-25 22:10:16 +00:00
|
|
|
if ((unsigned)(n - WAIT_OBJECT_0) < (unsigned)nhandles) {
|
|
|
|
handle_got_event(handles[n - WAIT_OBJECT_0]);
|
|
|
|
} else if (n == WAIT_OBJECT_0 + nhandles) {
|
2001-05-06 14:35:20 +00:00
|
|
|
WSANETWORKEVENTS things;
|
2000-10-23 10:32:37 +00:00
|
|
|
SOCKET socket;
|
2001-04-16 17:18:24 +00:00
|
|
|
extern SOCKET first_socket(int *), next_socket(int *);
|
2000-10-23 10:32:37 +00:00
|
|
|
extern int select_result(WPARAM, LPARAM);
|
2001-05-06 14:35:20 +00:00
|
|
|
int i, socketstate;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We must not call select_result() for any socket
|
|
|
|
* until we have finished enumerating within the tree.
|
|
|
|
* This is because select_result() may close the socket
|
|
|
|
* and modify the tree.
|
|
|
|
*/
|
|
|
|
/* Count the active sockets. */
|
|
|
|
i = 0;
|
|
|
|
for (socket = first_socket(&socketstate);
|
|
|
|
socket != INVALID_SOCKET;
|
|
|
|
socket = next_socket(&socketstate)) i++;
|
|
|
|
|
|
|
|
/* Expand the buffer if necessary. */
|
|
|
|
if (i > sksize) {
|
|
|
|
sksize = i + 16;
|
2003-03-29 16:14:26 +00:00
|
|
|
sklist = sresize(sklist, sksize, SOCKET);
|
2001-05-06 14:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Retrieve the sockets into sklist. */
|
|
|
|
skcount = 0;
|
|
|
|
for (socket = first_socket(&socketstate);
|
|
|
|
socket != INVALID_SOCKET;
|
2001-04-16 17:18:24 +00:00
|
|
|
socket = next_socket(&socketstate)) {
|
2001-05-06 14:35:20 +00:00
|
|
|
sklist[skcount++] = socket;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now we're done enumerating; go through the list. */
|
|
|
|
for (i = 0; i < skcount; i++) {
|
|
|
|
WPARAM wp;
|
|
|
|
socket = sklist[i];
|
|
|
|
wp = (WPARAM) socket;
|
2003-10-12 13:46:12 +00:00
|
|
|
if (!p_WSAEnumNetworkEvents(socket, NULL, &things)) {
|
2002-01-10 13:06:26 +00:00
|
|
|
static const struct { int bit, mask; } eventtypes[] = {
|
|
|
|
{FD_CONNECT_BIT, FD_CONNECT},
|
|
|
|
{FD_READ_BIT, FD_READ},
|
|
|
|
{FD_CLOSE_BIT, FD_CLOSE},
|
|
|
|
{FD_OOB_BIT, FD_OOB},
|
|
|
|
{FD_WRITE_BIT, FD_WRITE},
|
|
|
|
{FD_ACCEPT_BIT, FD_ACCEPT},
|
|
|
|
};
|
|
|
|
int e;
|
|
|
|
|
2001-05-06 14:35:20 +00:00
|
|
|
noise_ultralight(socket);
|
|
|
|
noise_ultralight(things.lNetworkEvents);
|
2001-08-08 20:44:35 +00:00
|
|
|
|
2002-01-10 13:06:26 +00:00
|
|
|
for (e = 0; e < lenof(eventtypes); e++)
|
|
|
|
if (things.lNetworkEvents & eventtypes[e].mask) {
|
|
|
|
LPARAM lp;
|
|
|
|
int err = things.iErrorCode[eventtypes[e].bit];
|
|
|
|
lp = WSAMAKESELECTREPLY(eventtypes[e].mask, err);
|
|
|
|
connopen &= select_result(wp, lp);
|
|
|
|
}
|
2000-10-23 10:32:37 +00:00
|
|
|
}
|
|
|
|
}
|
2006-08-25 22:10:16 +00:00
|
|
|
} else if (n == WAIT_OBJECT_0 + nhandles + 1) {
|
2003-04-28 13:59:32 +00:00
|
|
|
MSG msg;
|
|
|
|
while (PeekMessage(&msg, INVALID_HANDLE_VALUE,
|
|
|
|
WM_AGENT_CALLBACK, WM_AGENT_CALLBACK,
|
|
|
|
PM_REMOVE)) {
|
|
|
|
struct agent_callback *c = (struct agent_callback *)msg.lParam;
|
|
|
|
c->callback(c->callback_ctx, c->data, c->len);
|
|
|
|
sfree(c);
|
|
|
|
}
|
2001-08-25 17:09:23 +00:00
|
|
|
}
|
2004-11-27 13:20:21 +00:00
|
|
|
|
|
|
|
if (n == WAIT_TIMEOUT) {
|
|
|
|
now = next;
|
|
|
|
} else {
|
|
|
|
now = GETTICKCOUNT();
|
|
|
|
}
|
|
|
|
|
2006-08-25 22:10:16 +00:00
|
|
|
sfree(handles);
|
|
|
|
|
|
|
|
if (sending)
|
|
|
|
handle_unthrottle(stdin_handle, back->sendbuffer(backhandle));
|
|
|
|
|
2006-08-27 08:03:19 +00:00
|
|
|
if ((!connopen || !back->connected(backhandle)) &&
|
2006-08-25 22:10:16 +00:00
|
|
|
handle_backlog(stdout_handle) + handle_backlog(stderr_handle) == 0)
|
2001-05-06 14:35:20 +00:00
|
|
|
break; /* we closed the connection */
|
2000-09-11 08:27:15 +00:00
|
|
|
}
|
2002-10-25 11:30:33 +00:00
|
|
|
exitcode = back->exitcode(backhandle);
|
2001-12-29 15:31:42 +00:00
|
|
|
if (exitcode < 0) {
|
|
|
|
fprintf(stderr, "Remote process exit code unavailable\n");
|
|
|
|
exitcode = 1; /* this is an error condition */
|
|
|
|
}
|
2003-10-12 13:46:12 +00:00
|
|
|
cleanup_exit(exitcode);
|
|
|
|
return 0; /* placate compiler warning */
|
2000-09-11 08:27:15 +00:00
|
|
|
}
|