2006-04-23 22:26:03 +04:00
|
|
|
/*
|
|
|
|
* "Raw" backend.
|
|
|
|
*/
|
|
|
|
|
1999-11-01 19:40:40 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2012-12-22 13:40:47 +04:00
|
|
|
#include <limits.h>
|
1999-11-01 19:40:40 +03:00
|
|
|
|
|
|
|
#include "putty.h"
|
|
|
|
|
|
|
|
#ifndef FALSE
|
|
|
|
#define FALSE 0
|
|
|
|
#endif
|
|
|
|
#ifndef TRUE
|
|
|
|
#define TRUE 1
|
|
|
|
#endif
|
|
|
|
|
2001-08-25 21:09:23 +04:00
|
|
|
#define RAW_MAX_BACKLOG 4096
|
|
|
|
|
2002-10-25 15:30:33 +04:00
|
|
|
typedef struct raw_backend_data {
|
|
|
|
const struct plug_function_table *fn;
|
|
|
|
/* the above field _must_ be first in the structure */
|
1999-11-01 19:40:40 +03:00
|
|
|
|
2002-10-25 15:30:33 +04:00
|
|
|
Socket s;
|
2012-12-22 13:40:47 +04:00
|
|
|
int closed_on_socket_error;
|
2002-10-25 15:30:33 +04:00
|
|
|
int bufsize;
|
|
|
|
void *frontend;
|
2011-09-13 15:44:03 +04:00
|
|
|
int sent_console_eof, sent_socket_eof;
|
2002-10-25 15:30:33 +04:00
|
|
|
} *Raw;
|
1999-11-01 19:40:40 +03:00
|
|
|
|
2002-10-25 15:30:33 +04:00
|
|
|
static void raw_size(void *handle, int width, int height);
|
|
|
|
|
|
|
|
static void c_write(Raw raw, char *buf, int len)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
2002-10-25 15:30:33 +04:00
|
|
|
int backlog = from_backend(raw->frontend, 0, buf, len);
|
|
|
|
sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG);
|
1999-11-01 19:40:40 +03:00
|
|
|
}
|
|
|
|
|
2005-01-16 17:29:34 +03:00
|
|
|
static void raw_log(Plug plug, int type, SockAddr addr, int port,
|
|
|
|
const char *error_msg, int error_code)
|
|
|
|
{
|
|
|
|
Raw raw = (Raw) plug;
|
|
|
|
char addrbuf[256], *msg;
|
|
|
|
|
|
|
|
sk_getaddr(addr, addrbuf, lenof(addrbuf));
|
|
|
|
|
|
|
|
if (type == 0)
|
|
|
|
msg = dupprintf("Connecting to %s port %d", addrbuf, port);
|
|
|
|
else
|
|
|
|
msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
|
|
|
|
|
|
|
|
logevent(raw->frontend, msg);
|
2013-07-14 14:46:07 +04:00
|
|
|
sfree(msg);
|
2005-01-16 17:29:34 +03:00
|
|
|
}
|
|
|
|
|
2011-09-13 15:44:03 +04:00
|
|
|
static void raw_check_close(Raw raw)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Called after we send EOF on either the socket or the console.
|
|
|
|
* Its job is to wind up the session once we have sent EOF on both.
|
|
|
|
*/
|
|
|
|
if (raw->sent_console_eof && raw->sent_socket_eof) {
|
|
|
|
if (raw->s) {
|
|
|
|
sk_close(raw->s);
|
|
|
|
raw->s = NULL;
|
|
|
|
notify_remote_exit(raw->frontend);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-04 18:18:18 +04:00
|
|
|
static int raw_closing(Plug plug, const char *error_msg, int error_code,
|
2001-05-06 18:35:20 +04:00
|
|
|
int calling_back)
|
|
|
|
{
|
2002-10-25 15:30:33 +04:00
|
|
|
Raw raw = (Raw) plug;
|
|
|
|
|
2001-03-13 13:22:45 +03:00
|
|
|
if (error_msg) {
|
2011-09-13 15:44:03 +04:00
|
|
|
/* A socket error has occurred. */
|
|
|
|
if (raw->s) {
|
|
|
|
sk_close(raw->s);
|
|
|
|
raw->s = NULL;
|
2012-12-22 13:40:47 +04:00
|
|
|
raw->closed_on_socket_error = TRUE;
|
2011-09-13 15:44:03 +04:00
|
|
|
notify_remote_exit(raw->frontend);
|
|
|
|
}
|
|
|
|
logevent(raw->frontend, error_msg);
|
|
|
|
connection_fatal(raw->frontend, "%s", error_msg);
|
|
|
|
} else {
|
|
|
|
/* Otherwise, the remote side closed the connection normally. */
|
|
|
|
if (!raw->sent_console_eof && from_backend_eof(raw->frontend)) {
|
|
|
|
/*
|
|
|
|
* The front end wants us to close the outgoing side of the
|
|
|
|
* connection as soon as we see EOF from the far end.
|
|
|
|
*/
|
|
|
|
if (!raw->sent_socket_eof) {
|
|
|
|
if (raw->s)
|
|
|
|
sk_write_eof(raw->s);
|
|
|
|
raw->sent_socket_eof= TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
raw->sent_console_eof = TRUE;
|
|
|
|
raw_check_close(raw);
|
|
|
|
}
|
2001-03-13 13:22:45 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-05-06 18:35:20 +04:00
|
|
|
static int raw_receive(Plug plug, int urgent, char *data, int len)
|
|
|
|
{
|
2002-10-25 15:30:33 +04:00
|
|
|
Raw raw = (Raw) plug;
|
|
|
|
c_write(raw, data, len);
|
2000-10-23 14:32:37 +04:00
|
|
|
return 1;
|
1999-11-01 19:40:40 +03:00
|
|
|
}
|
|
|
|
|
2001-09-08 02:39:01 +04:00
|
|
|
static void raw_sent(Plug plug, int bufsize)
|
|
|
|
{
|
2002-10-25 15:30:33 +04:00
|
|
|
Raw raw = (Raw) plug;
|
|
|
|
raw->bufsize = bufsize;
|
2001-09-08 02:39:01 +04:00
|
|
|
}
|
|
|
|
|
1999-11-01 19:40:40 +03:00
|
|
|
/*
|
2000-10-23 14:32:37 +04:00
|
|
|
* Called to set up the raw connection.
|
|
|
|
*
|
1999-11-01 19:40:40 +03:00
|
|
|
* Returns an error message, or NULL on success.
|
|
|
|
*
|
2001-05-09 18:01:15 +04:00
|
|
|
* Also places the canonical host name into `realhost'. It must be
|
|
|
|
* freed by the caller.
|
1999-11-01 19:40:40 +03:00
|
|
|
*/
|
2003-05-04 18:18:18 +04:00
|
|
|
static const char *raw_init(void *frontend_handle, void **backend_handle,
|
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 22:52:21 +04:00
|
|
|
Conf *conf,
|
2004-06-20 21:07:38 +04:00
|
|
|
char *host, int port, char **realhost, int nodelay,
|
|
|
|
int keepalive)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
2002-10-25 15:30:33 +04:00
|
|
|
static const struct plug_function_table fn_table = {
|
2005-01-16 17:29:34 +03:00
|
|
|
raw_log,
|
2001-03-13 13:22:45 +03:00
|
|
|
raw_closing,
|
2001-09-08 02:39:01 +04:00
|
|
|
raw_receive,
|
|
|
|
raw_sent
|
2002-10-25 15:30:33 +04:00
|
|
|
};
|
2000-10-23 14:32:37 +04:00
|
|
|
SockAddr addr;
|
2003-05-04 18:18:18 +04:00
|
|
|
const char *err;
|
2002-10-25 15:30:33 +04:00
|
|
|
Raw raw;
|
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 22:52:21 +04:00
|
|
|
int addressfamily;
|
|
|
|
char *loghost;
|
1999-11-01 19:40:40 +03:00
|
|
|
|
2003-03-29 19:14:26 +03:00
|
|
|
raw = snew(struct raw_backend_data);
|
2002-10-25 15:30:33 +04:00
|
|
|
raw->fn = &fn_table;
|
|
|
|
raw->s = NULL;
|
2012-12-22 13:40:47 +04:00
|
|
|
raw->closed_on_socket_error = FALSE;
|
2002-10-25 15:30:33 +04:00
|
|
|
*backend_handle = raw;
|
2011-09-13 15:44:03 +04:00
|
|
|
raw->sent_console_eof = raw->sent_socket_eof = FALSE;
|
2002-10-25 15:30:33 +04:00
|
|
|
|
|
|
|
raw->frontend = frontend_handle;
|
2002-10-22 20:11:33 +04: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 22:52:21 +04:00
|
|
|
addressfamily = conf_get_int(conf, CONF_addressfamily);
|
1999-11-01 19:40:40 +03:00
|
|
|
/*
|
|
|
|
* Try to find host.
|
|
|
|
*/
|
2001-09-08 02:39:01 +04:00
|
|
|
{
|
2002-11-07 22:49:03 +03:00
|
|
|
char *buf;
|
2004-12-30 19:45:11 +03:00
|
|
|
buf = dupprintf("Looking up host \"%s\"%s", host,
|
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 22:52:21 +04:00
|
|
|
(addressfamily == ADDRTYPE_IPV4 ? " (IPv4)" :
|
|
|
|
(addressfamily == ADDRTYPE_IPV6 ? " (IPv6)" :
|
2004-12-30 19:45:11 +03:00
|
|
|
"")));
|
2002-10-26 16:58:13 +04:00
|
|
|
logevent(raw->frontend, buf);
|
2002-11-07 22:49:03 +03:00
|
|
|
sfree(buf);
|
2001-09-08 02:39:01 +04: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 22:52:21 +04:00
|
|
|
addr = name_lookup(host, port, realhost, conf, addressfamily);
|
2003-08-07 20:04:33 +04:00
|
|
|
if ((err = sk_addr_error(addr)) != NULL) {
|
|
|
|
sk_addr_free(addr);
|
2000-10-23 14:32:37 +04:00
|
|
|
return err;
|
2003-08-07 20:04:33 +04:00
|
|
|
}
|
1999-11-01 19:40:40 +03:00
|
|
|
|
|
|
|
if (port < 0)
|
|
|
|
port = 23; /* default telnet port */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open socket.
|
|
|
|
*/
|
2004-06-20 21:07:38 +04:00
|
|
|
raw->s = new_connection(addr, *realhost, port, 0, 1, nodelay, keepalive,
|
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 22:52:21 +04:00
|
|
|
(Plug) raw, conf);
|
2003-01-04 19:21:17 +03:00
|
|
|
if ((err = sk_socket_error(raw->s)) != NULL)
|
2000-10-23 14:32:37 +04:00
|
|
|
return err;
|
1999-11-01 19:40:40 +03: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 22:52:21 +04:00
|
|
|
loghost = conf_get_str(conf, CONF_loghost);
|
|
|
|
if (*loghost) {
|
2008-06-01 15:16:32 +04:00
|
|
|
char *colon;
|
|
|
|
|
|
|
|
sfree(*realhost);
|
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 22:52:21 +04:00
|
|
|
*realhost = dupstr(loghost);
|
2008-06-01 15:16:32 +04:00
|
|
|
colon = strrchr(*realhost, ':');
|
|
|
|
if (colon) {
|
|
|
|
/*
|
|
|
|
* FIXME: if we ever update this aspect of ssh.c for
|
|
|
|
* IPv6 literal management, this should change in line
|
|
|
|
* with it.
|
|
|
|
*/
|
|
|
|
*colon++ = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-01 19:40:40 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-01-16 02:30:21 +03:00
|
|
|
static void raw_free(void *handle)
|
|
|
|
{
|
|
|
|
Raw raw = (Raw) handle;
|
|
|
|
|
|
|
|
if (raw->s)
|
|
|
|
sk_close(raw->s);
|
|
|
|
sfree(raw);
|
|
|
|
}
|
|
|
|
|
2003-01-12 17:48:29 +03:00
|
|
|
/*
|
|
|
|
* Stub routine (we don't have any need to reconfigure this backend).
|
|
|
|
*/
|
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 22:52:21 +04:00
|
|
|
static void raw_reconfig(void *handle, Conf *conf)
|
2003-01-12 17:48:29 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-11-01 19:40:40 +03:00
|
|
|
/*
|
|
|
|
* Called to send data down the raw connection.
|
|
|
|
*/
|
2002-10-25 15:30:33 +04:00
|
|
|
static int raw_send(void *handle, char *buf, int len)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
2002-10-25 15:30:33 +04:00
|
|
|
Raw raw = (Raw) handle;
|
|
|
|
|
|
|
|
if (raw->s == NULL)
|
2001-08-27 19:55:44 +04:00
|
|
|
return 0;
|
1999-11-01 19:40:40 +03:00
|
|
|
|
2002-10-25 15:30:33 +04:00
|
|
|
raw->bufsize = sk_write(raw->s, buf, len);
|
2001-08-25 21:09:23 +04:00
|
|
|
|
2002-10-25 15:30:33 +04:00
|
|
|
return raw->bufsize;
|
2001-08-25 21:09:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to query the current socket sendability status.
|
|
|
|
*/
|
2002-10-25 15:30:33 +04:00
|
|
|
static int raw_sendbuffer(void *handle)
|
2001-08-25 21:09:23 +04:00
|
|
|
{
|
2002-10-25 15:30:33 +04:00
|
|
|
Raw raw = (Raw) handle;
|
|
|
|
return raw->bufsize;
|
1999-11-01 19:40:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called to set the size of the window
|
|
|
|
*/
|
2002-10-25 15:30:33 +04:00
|
|
|
static void raw_size(void *handle, int width, int height)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
1999-11-01 19:40:40 +03:00
|
|
|
/* Do nothing! */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-09-13 15:44:03 +04:00
|
|
|
* Send raw special codes. We only handle outgoing EOF here.
|
1999-11-01 19:40:40 +03:00
|
|
|
*/
|
2002-10-25 15:30:33 +04:00
|
|
|
static void raw_special(void *handle, Telnet_Special code)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
2011-09-13 15:44:03 +04:00
|
|
|
Raw raw = (Raw) handle;
|
|
|
|
if (code == TS_EOF && raw->s) {
|
|
|
|
sk_write_eof(raw->s);
|
|
|
|
raw->sent_socket_eof= TRUE;
|
|
|
|
raw_check_close(raw);
|
|
|
|
}
|
|
|
|
|
1999-11-01 19:40:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-05 00:21:05 +04:00
|
|
|
/*
|
|
|
|
* Return a list of the special codes that make sense in this
|
|
|
|
* protocol.
|
|
|
|
*/
|
|
|
|
static const struct telnet_special *raw_get_specials(void *handle)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-08-27 12:03:19 +04:00
|
|
|
static int raw_connected(void *handle)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
2002-10-25 15:30:33 +04:00
|
|
|
Raw raw = (Raw) handle;
|
2006-08-27 12:03:19 +04:00
|
|
|
return raw->s != NULL;
|
2001-05-06 18:35:20 +04:00
|
|
|
}
|
2000-09-08 20:42:11 +04:00
|
|
|
|
2002-10-25 15:30:33 +04:00
|
|
|
static int raw_sendok(void *handle)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2000-09-08 18:45:20 +04:00
|
|
|
|
2002-10-25 15:30:33 +04:00
|
|
|
static void raw_unthrottle(void *handle, int backlog)
|
2001-08-25 21:09:23 +04:00
|
|
|
{
|
2002-10-25 15:30:33 +04:00
|
|
|
Raw raw = (Raw) handle;
|
|
|
|
sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG);
|
2001-08-25 21:09:23 +04:00
|
|
|
}
|
|
|
|
|
2002-10-25 15:30:33 +04:00
|
|
|
static int raw_ldisc(void *handle, int option)
|
2001-05-06 18:35:20 +04:00
|
|
|
{
|
2001-01-24 17:08:20 +03:00
|
|
|
if (option == LD_EDIT || option == LD_ECHO)
|
2001-05-06 18:35:20 +04:00
|
|
|
return 1;
|
2001-01-24 17:08:20 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-26 14:16:19 +04:00
|
|
|
static void raw_provide_ldisc(void *handle, void *ldisc)
|
|
|
|
{
|
|
|
|
/* This is a stub. */
|
|
|
|
}
|
|
|
|
|
2002-10-26 16:58:13 +04:00
|
|
|
static void raw_provide_logctx(void *handle, void *logctx)
|
|
|
|
{
|
|
|
|
/* This is a stub. */
|
|
|
|
}
|
|
|
|
|
2002-10-25 15:30:33 +04:00
|
|
|
static int raw_exitcode(void *handle)
|
2001-12-29 18:31:42 +03:00
|
|
|
{
|
2003-03-31 16:10:08 +04:00
|
|
|
Raw raw = (Raw) handle;
|
|
|
|
if (raw->s != NULL)
|
|
|
|
return -1; /* still connected */
|
2012-12-22 13:40:47 +04:00
|
|
|
else if (raw->closed_on_socket_error)
|
|
|
|
return INT_MAX; /* a socket error counts as an unclean exit */
|
2003-03-31 16:10:08 +04:00
|
|
|
else
|
|
|
|
/* Exit codes are a meaningless concept in the Raw protocol */
|
|
|
|
return 0;
|
2001-12-29 18:31:42 +03:00
|
|
|
}
|
|
|
|
|
2004-12-29 15:32:25 +03:00
|
|
|
/*
|
|
|
|
* cfg_info for Raw does nothing at all.
|
|
|
|
*/
|
|
|
|
static int raw_cfg_info(void *handle)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-11-01 19:40:40 +03:00
|
|
|
Backend raw_backend = {
|
|
|
|
raw_init,
|
2003-01-16 02:30:21 +03:00
|
|
|
raw_free,
|
2003-01-12 17:48:29 +03:00
|
|
|
raw_reconfig,
|
1999-11-01 19:40:40 +03:00
|
|
|
raw_send,
|
2001-08-25 21:09:23 +04:00
|
|
|
raw_sendbuffer,
|
1999-11-01 19:40:40 +03:00
|
|
|
raw_size,
|
2000-09-08 18:45:20 +04:00
|
|
|
raw_special,
|
2003-04-05 00:21:05 +04:00
|
|
|
raw_get_specials,
|
2006-08-27 12:03:19 +04:00
|
|
|
raw_connected,
|
2001-12-29 18:31:42 +03:00
|
|
|
raw_exitcode,
|
2000-10-04 18:35:15 +04:00
|
|
|
raw_sendok,
|
2001-01-24 17:08:20 +03:00
|
|
|
raw_ldisc,
|
2002-10-26 14:16:19 +04:00
|
|
|
raw_provide_ldisc,
|
2002-10-26 16:58:13 +04:00
|
|
|
raw_provide_logctx,
|
2001-08-25 21:09:23 +04:00
|
|
|
raw_unthrottle,
|
2004-12-29 15:32:25 +03:00
|
|
|
raw_cfg_info,
|
2007-07-01 01:56:44 +04:00
|
|
|
"raw",
|
|
|
|
PROT_RAW,
|
2007-07-01 19:47:31 +04:00
|
|
|
0
|
1999-11-01 19:40:40 +03:00
|
|
|
};
|