2004-04-27 16:31:57 +04:00
|
|
|
/*
|
|
|
|
* Platform-independent routines shared between all PuTTY programs.
|
Move standalone parts of misc.c into utils.c.
misc.c has always contained a combination of things that are tied
tightly into the PuTTY code base (e.g. they use the conf system, or
work with our sockets abstraction) and things that are pure standalone
utility functions like nullstrcmp() which could quite happily be
dropped into any C program without causing a link failure.
Now the latter kind of standalone utility code lives in the new source
file utils.c, whose only external dependency is on memory.c (for snew,
sfree etc), which in turn requires the user to provide an
out_of_memory() function. So it should now be much easier to link test
programs that use PuTTY's low-level functions without also pulling in
half its bulky infrastructure.
In the process, I came across a memory allocation logging system
enabled by -DMALLOC_LOG that looks long since bit-rotted; in any case
we have much more advanced tools for that kind of thing these days,
like valgrind and Leak Sanitiser, so I've just removed it rather than
trying to transplant it somewhere sensible. (We can always pull it
back out of the version control history if really necessary, but I
haven't used it in at least a decade.)
The other slightly silly thing I did was to give bufchain a function
pointer field that points to queue_idempotent_callback(), and disallow
direct setting of the 'ic' field in favour of calling
bufchain_set_callback which will fill that pointer in too. That allows
the bufchain system to live in utils.c rather than misc.c, so that
programs can use it without also having to link in the callback system
or provide an annoying stub of that function. In fact that's just
allowed me to remove stubs of that kind from PuTTYgen and Pageant!
2019-01-03 11:44:11 +03:00
|
|
|
*
|
|
|
|
* This file contains functions that use the kind of infrastructure
|
|
|
|
* like conf.c that tends to only live in the main applications, or
|
|
|
|
* that do things that only something like a main PuTTY application
|
|
|
|
* would need. So standalone test programs should generally be able to
|
|
|
|
* avoid linking against it.
|
|
|
|
*
|
|
|
|
* More standalone functions that depend on nothing but the C library
|
|
|
|
* live in utils.c.
|
2004-04-27 16:31:57 +04:00
|
|
|
*/
|
|
|
|
|
1999-01-08 16:02:13 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-10-09 22:09:42 +04:00
|
|
|
#include <stdarg.h>
|
2005-02-20 13:30:05 +03:00
|
|
|
#include <limits.h>
|
2002-11-07 22:49:03 +03:00
|
|
|
#include <ctype.h>
|
2001-08-25 21:09:23 +04:00
|
|
|
#include <assert.h>
|
Move standalone parts of misc.c into utils.c.
misc.c has always contained a combination of things that are tied
tightly into the PuTTY code base (e.g. they use the conf system, or
work with our sockets abstraction) and things that are pure standalone
utility functions like nullstrcmp() which could quite happily be
dropped into any C program without causing a link failure.
Now the latter kind of standalone utility code lives in the new source
file utils.c, whose only external dependency is on memory.c (for snew,
sfree etc), which in turn requires the user to provide an
out_of_memory() function. So it should now be much easier to link test
programs that use PuTTY's low-level functions without also pulling in
half its bulky infrastructure.
In the process, I came across a memory allocation logging system
enabled by -DMALLOC_LOG that looks long since bit-rotted; in any case
we have much more advanced tools for that kind of thing these days,
like valgrind and Leak Sanitiser, so I've just removed it rather than
trying to transplant it somewhere sensible. (We can always pull it
back out of the version control history if really necessary, but I
haven't used it in at least a decade.)
The other slightly silly thing I did was to give bufchain a function
pointer field that points to queue_idempotent_callback(), and disallow
direct setting of the 'ic' field in favour of calling
bufchain_set_callback which will fill that pointer in too. That allows
the bufchain system to live in utils.c rather than misc.c, so that
programs can use it without also having to link in the callback system
or provide an annoying stub of that function. In fact that's just
allowed me to remove stubs of that kind from PuTTYgen and Pageant!
2019-01-03 11:44:11 +03:00
|
|
|
|
|
|
|
#include "defs.h"
|
1999-01-08 16:02:13 +03:00
|
|
|
#include "putty.h"
|
2015-04-27 22:48:29 +03:00
|
|
|
#include "misc.h"
|
1999-01-08 16:02:13 +03:00
|
|
|
|
New abstraction 'Seat', to pass to backends.
This is a new vtable-based abstraction which is passed to a backend in
place of Frontend, and it implements only the subset of the Frontend
functions needed by a backend. (Many other Frontend functions still
exist, notably the wide range of things called by terminal.c providing
platform-independent operations on the GUI terminal window.)
The purpose of making it a vtable is that this opens up the
possibility of creating a backend as an internal implementation detail
of some other activity, by providing just that one backend with a
custom Seat that implements the methods differently.
For example, this refactoring should make it feasible to directly
implement an SSH proxy type, aka the 'jump host' feature supported by
OpenSSH, aka 'open a secondary SSH session in MAINCHAN_DIRECT_TCP
mode, and then expose the main channel of that as the Socket for the
primary connection'. (Which of course you can already do by spawning
'plink -nc' as a separate proxy process, but this would permit it in
the _same_ process without anything getting confused.)
I've centralised a full set of stub methods in misc.c for the new
abstraction, which allows me to get rid of several annoying stubs in
the previous code. Also, while I'm here, I've moved a lot of
duplicated modalfatalbox() type functions from application main
program files into wincons.c / uxcons.c, which I think saves
duplication overall. (A minor visible effect is that the prefixes on
those console-based fatal error messages will now be more consistent
between applications.)
2018-10-11 21:58:42 +03:00
|
|
|
void seat_connection_fatal(Seat *seat, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char *msg;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
msg = dupvprintf(fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
seat->vt->connection_fatal(seat, msg);
|
|
|
|
sfree(msg); /* if we return */
|
|
|
|
}
|
|
|
|
|
|
|
|
prompts_t *new_prompts(void)
|
2005-10-30 23:24:09 +03:00
|
|
|
{
|
|
|
|
prompts_t *p = snew(prompts_t);
|
|
|
|
p->prompts = NULL;
|
New array-growing macros: sgrowarray and sgrowarrayn.
The idea of these is that they centralise the common idiom along the
lines of
if (logical_array_len >= physical_array_size) {
physical_array_size = logical_array_len * 5 / 4 + 256;
array = sresize(array, physical_array_size, ElementType);
}
which happens at a zillion call sites throughout this code base, with
different random choices of the geometric factor and additive
constant, sometimes forgetting them completely, and generally doing a
lot of repeated work.
The new macro sgrowarray(array,size,n) has the semantics: here are the
array pointer and its physical size for you to modify, now please
ensure that the nth element exists, so I can write into it. And
sgrowarrayn(array,size,n,m) is the same except that it ensures that
the array has size at least n+m (so sgrowarray is just the special
case where m=1).
Now that this is a single centralised implementation that will be used
everywhere, I've also gone to more effort in the implementation, with
careful overflow checks that would have been painful to put at all the
previous call sites.
This commit also switches over every use of sresize(), apart from a
few where I really didn't think it would gain anything. A consequence
of that is that a lot of array-size variables have to have their types
changed to size_t, because the macros require that (they address-take
the size to pass to the underlying function).
2019-02-28 23:07:30 +03:00
|
|
|
p->n_prompts = p->prompts_size = 0;
|
2005-10-30 23:24:09 +03:00
|
|
|
p->data = NULL;
|
2018-10-29 22:50:29 +03:00
|
|
|
p->to_server = true; /* to be on the safe side */
|
2005-10-30 23:24:09 +03:00
|
|
|
p->name = p->instruction = NULL;
|
2018-10-29 22:50:29 +03:00
|
|
|
p->name_reqd = p->instr_reqd = false;
|
2005-10-30 23:24:09 +03:00
|
|
|
return p;
|
|
|
|
}
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 22:23:19 +03:00
|
|
|
void add_prompt(prompts_t *p, char *promptstr, bool echo)
|
2005-10-30 23:24:09 +03:00
|
|
|
{
|
|
|
|
prompt_t *pr = snew(prompt_t);
|
|
|
|
pr->prompt = promptstr;
|
|
|
|
pr->echo = echo;
|
2020-01-21 23:19:47 +03:00
|
|
|
pr->result = strbuf_new_nm();
|
New array-growing macros: sgrowarray and sgrowarrayn.
The idea of these is that they centralise the common idiom along the
lines of
if (logical_array_len >= physical_array_size) {
physical_array_size = logical_array_len * 5 / 4 + 256;
array = sresize(array, physical_array_size, ElementType);
}
which happens at a zillion call sites throughout this code base, with
different random choices of the geometric factor and additive
constant, sometimes forgetting them completely, and generally doing a
lot of repeated work.
The new macro sgrowarray(array,size,n) has the semantics: here are the
array pointer and its physical size for you to modify, now please
ensure that the nth element exists, so I can write into it. And
sgrowarrayn(array,size,n,m) is the same except that it ensures that
the array has size at least n+m (so sgrowarray is just the special
case where m=1).
Now that this is a single centralised implementation that will be used
everywhere, I've also gone to more effort in the implementation, with
careful overflow checks that would have been painful to put at all the
previous call sites.
This commit also switches over every use of sresize(), apart from a
few where I really didn't think it would gain anything. A consequence
of that is that a lot of array-size variables have to have their types
changed to size_t, because the macros require that (they address-take
the size to pass to the underlying function).
2019-02-28 23:07:30 +03:00
|
|
|
sgrowarray(p->prompts, p->prompts_size, p->n_prompts);
|
|
|
|
p->prompts[p->n_prompts++] = pr;
|
2005-10-30 23:24:09 +03:00
|
|
|
}
|
2020-01-21 23:19:47 +03:00
|
|
|
void prompt_set_result(prompt_t *pr, const char *newstr)
|
2011-10-02 15:50:45 +04:00
|
|
|
{
|
2020-01-21 23:19:47 +03:00
|
|
|
strbuf_clear(pr->result);
|
|
|
|
put_datapl(pr->result, ptrlen_from_asciz(newstr));
|
2011-10-02 15:50:45 +04:00
|
|
|
}
|
2020-01-21 23:19:47 +03:00
|
|
|
const char *prompt_get_result_ref(prompt_t *pr)
|
|
|
|
{
|
|
|
|
return pr->result->s;
|
|
|
|
}
|
|
|
|
char *prompt_get_result(prompt_t *pr)
|
2011-10-02 15:50:45 +04:00
|
|
|
{
|
2020-01-21 23:19:47 +03:00
|
|
|
return dupstr(pr->result->s);
|
2011-10-02 15:50:45 +04:00
|
|
|
}
|
2005-10-30 23:24:09 +03:00
|
|
|
void free_prompts(prompts_t *p)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for (i=0; i < p->n_prompts; i++) {
|
2019-09-08 22:29:00 +03:00
|
|
|
prompt_t *pr = p->prompts[i];
|
2020-01-21 23:19:47 +03:00
|
|
|
strbuf_free(pr->result);
|
2019-09-08 22:29:00 +03:00
|
|
|
sfree(pr->prompt);
|
|
|
|
sfree(pr);
|
2005-10-30 23:24:09 +03:00
|
|
|
}
|
|
|
|
sfree(p->prompts);
|
|
|
|
sfree(p->name);
|
|
|
|
sfree(p->instruction);
|
|
|
|
sfree(p);
|
|
|
|
}
|
|
|
|
|
2006-08-28 14:35:12 +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
|
|
|
* Determine whether or not a Conf represents a session which can
|
|
|
|
* sensibly be launched right now.
|
2006-08-28 14:35:12 +04:00
|
|
|
*/
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 22:23:19 +03:00
|
|
|
bool conf_launchable(Conf *conf)
|
2006-08-28 14:35:12 +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
|
|
|
if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL)
|
2019-09-08 22:29:00 +03:00
|
|
|
return conf_get_str(conf, CONF_serline)[0] != 0;
|
2006-08-28 14:35:12 +04:00
|
|
|
else
|
2019-09-08 22:29:00 +03:00
|
|
|
return conf_get_str(conf, CONF_host)[0] != 0;
|
2006-08-28 14:35:12 +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
|
|
|
char const *conf_dest(Conf *conf)
|
2006-08-28 14:35:12 +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
|
|
|
if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL)
|
2019-09-08 22:29:00 +03:00
|
|
|
return conf_get_str(conf, CONF_serline);
|
2006-08-28 14:35:12 +04:00
|
|
|
else
|
2019-09-08 22:29:00 +03:00
|
|
|
return conf_get_str(conf, CONF_host);
|
2006-08-28 14:35:12 +04:00
|
|
|
}
|
2012-07-22 23:51:50 +04:00
|
|
|
|
New option to manually configure the expected host key(s).
This option is available from the command line as '-hostkey', and is
also configurable through the GUI. When enabled, it completely
replaces all of the automated host key management: the server's host
key will be checked against the manually configured list, and the
connection will be allowed or disconnected on that basis, and the host
key store in the registry will not be either consulted or updated.
The main aim is to provide a means of automatically running Plink,
PSCP or PSFTP deep inside Windows services where HKEY_CURRENT_USER
isn't available to have stored the right host key in. But it also
permits you to specify a list of multiple host keys, which means a
second use case for the same mechanism will probably be round-robin
DNS names that select one of several servers with different host keys.
Host keys can be specified as the standard MD5 fingerprint or as an
SSH-2 base64 blob, and are canonicalised on input. (The base64 blob is
more unwieldy, especially with Windows command-line length limits, but
provides a means of specifying the _whole_ public key in case you
don't trust MD5. I haven't bothered to provide an analogous mechanism
for SSH-1, on the basis that anyone worrying about MD5 should have
stopped using SSH-1 already!)
[originally from svn r10220]
2014-09-09 15:46:24 +04:00
|
|
|
/*
|
|
|
|
* Validate a manual host key specification (either entered in the
|
2018-10-29 22:50:29 +03:00
|
|
|
* GUI, or via -hostkey). If valid, we return true, and update 'key'
|
New option to manually configure the expected host key(s).
This option is available from the command line as '-hostkey', and is
also configurable through the GUI. When enabled, it completely
replaces all of the automated host key management: the server's host
key will be checked against the manually configured list, and the
connection will be allowed or disconnected on that basis, and the host
key store in the registry will not be either consulted or updated.
The main aim is to provide a means of automatically running Plink,
PSCP or PSFTP deep inside Windows services where HKEY_CURRENT_USER
isn't available to have stored the right host key in. But it also
permits you to specify a list of multiple host keys, which means a
second use case for the same mechanism will probably be round-robin
DNS names that select one of several servers with different host keys.
Host keys can be specified as the standard MD5 fingerprint or as an
SSH-2 base64 blob, and are canonicalised on input. (The base64 blob is
more unwieldy, especially with Windows command-line length limits, but
provides a means of specifying the _whole_ public key in case you
don't trust MD5. I haven't bothered to provide an analogous mechanism
for SSH-1, on the basis that anyone worrying about MD5 should have
stopped using SSH-1 already!)
[originally from svn r10220]
2014-09-09 15:46:24 +04:00
|
|
|
* to contain a canonicalised version of the key string in 'key'
|
|
|
|
* (which is guaranteed to take up at most as much space as the
|
|
|
|
* original version), suitable for putting into the Conf. If not
|
2018-10-29 22:50:29 +03:00
|
|
|
* valid, we return false.
|
New option to manually configure the expected host key(s).
This option is available from the command line as '-hostkey', and is
also configurable through the GUI. When enabled, it completely
replaces all of the automated host key management: the server's host
key will be checked against the manually configured list, and the
connection will be allowed or disconnected on that basis, and the host
key store in the registry will not be either consulted or updated.
The main aim is to provide a means of automatically running Plink,
PSCP or PSFTP deep inside Windows services where HKEY_CURRENT_USER
isn't available to have stored the right host key in. But it also
permits you to specify a list of multiple host keys, which means a
second use case for the same mechanism will probably be round-robin
DNS names that select one of several servers with different host keys.
Host keys can be specified as the standard MD5 fingerprint or as an
SSH-2 base64 blob, and are canonicalised on input. (The base64 blob is
more unwieldy, especially with Windows command-line length limits, but
provides a means of specifying the _whole_ public key in case you
don't trust MD5. I haven't bothered to provide an analogous mechanism
for SSH-1, on the basis that anyone worrying about MD5 should have
stopped using SSH-1 already!)
[originally from svn r10220]
2014-09-09 15:46:24 +04:00
|
|
|
*/
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 22:23:19 +03:00
|
|
|
bool validate_manual_hostkey(char *key)
|
New option to manually configure the expected host key(s).
This option is available from the command line as '-hostkey', and is
also configurable through the GUI. When enabled, it completely
replaces all of the automated host key management: the server's host
key will be checked against the manually configured list, and the
connection will be allowed or disconnected on that basis, and the host
key store in the registry will not be either consulted or updated.
The main aim is to provide a means of automatically running Plink,
PSCP or PSFTP deep inside Windows services where HKEY_CURRENT_USER
isn't available to have stored the right host key in. But it also
permits you to specify a list of multiple host keys, which means a
second use case for the same mechanism will probably be round-robin
DNS names that select one of several servers with different host keys.
Host keys can be specified as the standard MD5 fingerprint or as an
SSH-2 base64 blob, and are canonicalised on input. (The base64 blob is
more unwieldy, especially with Windows command-line length limits, but
provides a means of specifying the _whole_ public key in case you
don't trust MD5. I haven't bothered to provide an analogous mechanism
for SSH-1, on the basis that anyone worrying about MD5 should have
stopped using SSH-1 already!)
[originally from svn r10220]
2014-09-09 15:46:24 +04:00
|
|
|
{
|
|
|
|
char *p, *q, *r, *s;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Step through the string word by word, looking for a word that's
|
|
|
|
* in one of the formats we like.
|
|
|
|
*/
|
|
|
|
p = key;
|
|
|
|
while ((p += strspn(p, " \t"))[0]) {
|
|
|
|
q = p;
|
|
|
|
p += strcspn(p, " \t");
|
2014-11-22 13:12:47 +03:00
|
|
|
if (*p) *p++ = '\0';
|
New option to manually configure the expected host key(s).
This option is available from the command line as '-hostkey', and is
also configurable through the GUI. When enabled, it completely
replaces all of the automated host key management: the server's host
key will be checked against the manually configured list, and the
connection will be allowed or disconnected on that basis, and the host
key store in the registry will not be either consulted or updated.
The main aim is to provide a means of automatically running Plink,
PSCP or PSFTP deep inside Windows services where HKEY_CURRENT_USER
isn't available to have stored the right host key in. But it also
permits you to specify a list of multiple host keys, which means a
second use case for the same mechanism will probably be round-robin
DNS names that select one of several servers with different host keys.
Host keys can be specified as the standard MD5 fingerprint or as an
SSH-2 base64 blob, and are canonicalised on input. (The base64 blob is
more unwieldy, especially with Windows command-line length limits, but
provides a means of specifying the _whole_ public key in case you
don't trust MD5. I haven't bothered to provide an analogous mechanism
for SSH-1, on the basis that anyone worrying about MD5 should have
stopped using SSH-1 already!)
[originally from svn r10220]
2014-09-09 15:46:24 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now q is our word.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (strlen(q) == 16*3 - 1 &&
|
|
|
|
q[strspn(q, "0123456789abcdefABCDEF:")] == 0) {
|
|
|
|
/*
|
|
|
|
* Might be a key fingerprint. Check the colons are in the
|
|
|
|
* right places, and if so, return the same fingerprint
|
|
|
|
* canonicalised into lowercase.
|
|
|
|
*/
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
if (q[3*i] == ':' || q[3*i+1] == ':')
|
|
|
|
goto not_fingerprint; /* sorry */
|
|
|
|
for (i = 0; i < 15; i++)
|
|
|
|
if (q[3*i+2] != ':')
|
|
|
|
goto not_fingerprint; /* sorry */
|
|
|
|
for (i = 0; i < 16*3 - 1; i++)
|
|
|
|
key[i] = tolower(q[i]);
|
|
|
|
key[16*3 - 1] = '\0';
|
2018-10-29 22:50:29 +03:00
|
|
|
return true;
|
New option to manually configure the expected host key(s).
This option is available from the command line as '-hostkey', and is
also configurable through the GUI. When enabled, it completely
replaces all of the automated host key management: the server's host
key will be checked against the manually configured list, and the
connection will be allowed or disconnected on that basis, and the host
key store in the registry will not be either consulted or updated.
The main aim is to provide a means of automatically running Plink,
PSCP or PSFTP deep inside Windows services where HKEY_CURRENT_USER
isn't available to have stored the right host key in. But it also
permits you to specify a list of multiple host keys, which means a
second use case for the same mechanism will probably be round-robin
DNS names that select one of several servers with different host keys.
Host keys can be specified as the standard MD5 fingerprint or as an
SSH-2 base64 blob, and are canonicalised on input. (The base64 blob is
more unwieldy, especially with Windows command-line length limits, but
provides a means of specifying the _whole_ public key in case you
don't trust MD5. I haven't bothered to provide an analogous mechanism
for SSH-1, on the basis that anyone worrying about MD5 should have
stopped using SSH-1 already!)
[originally from svn r10220]
2014-09-09 15:46:24 +04:00
|
|
|
}
|
|
|
|
not_fingerprint:;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Before we check for a public-key blob, trim newlines out of
|
|
|
|
* the middle of the word, in case someone's managed to paste
|
|
|
|
* in a public-key blob _with_ them.
|
|
|
|
*/
|
|
|
|
for (r = s = q; *r; r++)
|
|
|
|
if (*r != '\n' && *r != '\r')
|
|
|
|
*s++ = *r;
|
|
|
|
*s = '\0';
|
|
|
|
|
|
|
|
if (strlen(q) % 4 == 0 && strlen(q) > 2*4 &&
|
|
|
|
q[strspn(q, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
"abcdefghijklmnopqrstuvwxyz+/=")] == 0) {
|
|
|
|
/*
|
|
|
|
* Might be a base64-encoded SSH-2 public key blob. Check
|
|
|
|
* that it starts with a sensible algorithm string. No
|
|
|
|
* canonicalisation is necessary for this string type.
|
|
|
|
*
|
|
|
|
* The algorithm string must be at most 64 characters long
|
|
|
|
* (RFC 4251 section 6).
|
|
|
|
*/
|
|
|
|
unsigned char decoded[6];
|
|
|
|
unsigned alglen;
|
|
|
|
int minlen;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
len += base64_decode_atom(q, decoded+len);
|
|
|
|
if (len < 3)
|
|
|
|
goto not_ssh2_blob; /* sorry */
|
|
|
|
len += base64_decode_atom(q+4, decoded+len);
|
|
|
|
if (len < 4)
|
|
|
|
goto not_ssh2_blob; /* sorry */
|
|
|
|
|
|
|
|
alglen = GET_32BIT_MSB_FIRST(decoded);
|
|
|
|
if (alglen > 64)
|
|
|
|
goto not_ssh2_blob; /* sorry */
|
|
|
|
|
|
|
|
minlen = ((alglen + 4) + 2) / 3;
|
|
|
|
if (strlen(q) < minlen)
|
|
|
|
goto not_ssh2_blob; /* sorry */
|
|
|
|
|
|
|
|
strcpy(key, q);
|
2018-10-29 22:50:29 +03:00
|
|
|
return true;
|
New option to manually configure the expected host key(s).
This option is available from the command line as '-hostkey', and is
also configurable through the GUI. When enabled, it completely
replaces all of the automated host key management: the server's host
key will be checked against the manually configured list, and the
connection will be allowed or disconnected on that basis, and the host
key store in the registry will not be either consulted or updated.
The main aim is to provide a means of automatically running Plink,
PSCP or PSFTP deep inside Windows services where HKEY_CURRENT_USER
isn't available to have stored the right host key in. But it also
permits you to specify a list of multiple host keys, which means a
second use case for the same mechanism will probably be round-robin
DNS names that select one of several servers with different host keys.
Host keys can be specified as the standard MD5 fingerprint or as an
SSH-2 base64 blob, and are canonicalised on input. (The base64 blob is
more unwieldy, especially with Windows command-line length limits, but
provides a means of specifying the _whole_ public key in case you
don't trust MD5. I haven't bothered to provide an analogous mechanism
for SSH-1, on the basis that anyone worrying about MD5 should have
stopped using SSH-1 already!)
[originally from svn r10220]
2014-09-09 15:46:24 +04:00
|
|
|
}
|
|
|
|
not_ssh2_blob:;
|
|
|
|
}
|
|
|
|
|
2018-10-29 22:50:29 +03:00
|
|
|
return false;
|
New option to manually configure the expected host key(s).
This option is available from the command line as '-hostkey', and is
also configurable through the GUI. When enabled, it completely
replaces all of the automated host key management: the server's host
key will be checked against the manually configured list, and the
connection will be allowed or disconnected on that basis, and the host
key store in the registry will not be either consulted or updated.
The main aim is to provide a means of automatically running Plink,
PSCP or PSFTP deep inside Windows services where HKEY_CURRENT_USER
isn't available to have stored the right host key in. But it also
permits you to specify a list of multiple host keys, which means a
second use case for the same mechanism will probably be round-robin
DNS names that select one of several servers with different host keys.
Host keys can be specified as the standard MD5 fingerprint or as an
SSH-2 base64 blob, and are canonicalised on input. (The base64 blob is
more unwieldy, especially with Windows command-line length limits, but
provides a means of specifying the _whole_ public key in case you
don't trust MD5. I haven't bothered to provide an analogous mechanism
for SSH-1, on the basis that anyone worrying about MD5 should have
stopped using SSH-1 already!)
[originally from svn r10220]
2014-09-09 15:46:24 +04:00
|
|
|
}
|
2015-04-27 01:31:11 +03:00
|
|
|
|
2017-01-21 17:55:53 +03:00
|
|
|
char *buildinfo(const char *newline)
|
|
|
|
{
|
|
|
|
strbuf *buf = strbuf_new();
|
|
|
|
|
|
|
|
strbuf_catf(buf, "Build platform: %d-bit %s",
|
|
|
|
(int)(CHAR_BIT * sizeof(void *)),
|
|
|
|
BUILDINFO_PLATFORM);
|
|
|
|
|
|
|
|
#ifdef __clang_version__
|
2017-05-31 00:49:25 +03:00
|
|
|
#define FOUND_COMPILER
|
2017-01-21 17:55:53 +03:00
|
|
|
strbuf_catf(buf, "%sCompiler: clang %s", newline, __clang_version__);
|
|
|
|
#elif defined __GNUC__ && defined __VERSION__
|
2017-05-31 00:49:25 +03:00
|
|
|
#define FOUND_COMPILER
|
2017-01-21 17:55:53 +03:00
|
|
|
strbuf_catf(buf, "%sCompiler: gcc %s", newline, __VERSION__);
|
2017-05-31 00:49:25 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined _MSC_VER
|
|
|
|
#ifndef FOUND_COMPILER
|
|
|
|
#define FOUND_COMPILER
|
|
|
|
strbuf_catf(buf, "%sCompiler: ", newline);
|
|
|
|
#else
|
|
|
|
strbuf_catf(buf, ", emulating ");
|
|
|
|
#endif
|
2020-01-26 18:00:13 +03:00
|
|
|
strbuf_catf(buf, "Visual Studio");
|
2019-03-22 10:04:57 +03:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* List of _MSC_VER values and their translations taken from
|
|
|
|
* https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros
|
|
|
|
*
|
|
|
|
* The pointless #if 0 branch containing this comment is there so
|
|
|
|
* that every real clause can start with #elif and there's no
|
|
|
|
* anomalous first clause. That way the patch looks nicer when you
|
|
|
|
* add extra ones.
|
|
|
|
*/
|
2020-01-26 18:16:47 +03:00
|
|
|
#elif _MSC_VER == 1923
|
|
|
|
strbuf_catf(buf, " 2019 (16.3)");
|
|
|
|
#elif _MSC_VER == 1922
|
|
|
|
strbuf_catf(buf, " 2019 (16.2)");
|
|
|
|
#elif _MSC_VER == 1921
|
|
|
|
strbuf_catf(buf, " 2019 (16.1)");
|
2019-03-22 10:04:57 +03:00
|
|
|
#elif _MSC_VER == 1920
|
2020-01-26 18:16:47 +03:00
|
|
|
strbuf_catf(buf, " 2019 (16.0)");
|
2019-03-22 10:04:57 +03:00
|
|
|
#elif _MSC_VER == 1916
|
|
|
|
strbuf_catf(buf, " 2017 version 15.9");
|
|
|
|
#elif _MSC_VER == 1915
|
|
|
|
strbuf_catf(buf, " 2017 version 15.8");
|
|
|
|
#elif _MSC_VER == 1914
|
|
|
|
strbuf_catf(buf, " 2017 version 15.7");
|
|
|
|
#elif _MSC_VER == 1913
|
|
|
|
strbuf_catf(buf, " 2017 version 15.6");
|
2018-04-25 18:27:10 +03:00
|
|
|
#elif _MSC_VER == 1912
|
2019-03-22 10:04:57 +03:00
|
|
|
strbuf_catf(buf, " 2017 version 15.5");
|
|
|
|
#elif _MSC_VER == 1911
|
|
|
|
strbuf_catf(buf, " 2017 version 15.3");
|
|
|
|
#elif _MSC_VER == 1910
|
|
|
|
strbuf_catf(buf, " 2017 RTW (15.0)");
|
|
|
|
#elif _MSC_VER == 1900
|
|
|
|
strbuf_catf(buf, " 2015 (14.0)");
|
2017-01-21 17:55:53 +03:00
|
|
|
#elif _MSC_VER == 1800
|
2019-03-22 10:04:57 +03:00
|
|
|
strbuf_catf(buf, " 2013 (12.0)");
|
2017-01-21 17:55:53 +03:00
|
|
|
#elif _MSC_VER == 1700
|
2019-03-22 10:04:57 +03:00
|
|
|
strbuf_catf(buf, " 2012 (11.0)");
|
2017-01-21 17:55:53 +03:00
|
|
|
#elif _MSC_VER == 1600
|
2019-03-22 10:04:57 +03:00
|
|
|
strbuf_catf(buf, " 2010 (10.0)");
|
2017-05-31 00:49:25 +03:00
|
|
|
#elif _MSC_VER == 1500
|
2019-03-22 10:04:57 +03:00
|
|
|
strbuf_catf(buf, " 2008 (9.0)");
|
2017-05-31 00:49:25 +03:00
|
|
|
#elif _MSC_VER == 1400
|
2019-03-22 10:04:57 +03:00
|
|
|
strbuf_catf(buf, " 2005 (8.0)");
|
2017-05-31 00:49:25 +03:00
|
|
|
#elif _MSC_VER == 1310
|
2019-03-22 10:04:57 +03:00
|
|
|
strbuf_catf(buf, " .NET 2003 (7.1)");
|
2017-05-31 00:49:25 +03:00
|
|
|
#elif _MSC_VER == 1300
|
2019-03-22 10:04:57 +03:00
|
|
|
strbuf_catf(buf, " .NET 2002 (7.0)");
|
|
|
|
#elif _MSC_VER == 1200
|
|
|
|
strbuf_catf(buf, " 6.0");
|
2017-01-21 17:55:53 +03:00
|
|
|
#else
|
|
|
|
strbuf_catf(buf, ", unrecognised version");
|
|
|
|
#endif
|
2019-03-22 10:04:57 +03:00
|
|
|
strbuf_catf(buf, ", _MSC_VER=%d", (int)_MSC_VER);
|
2017-01-21 17:55:53 +03:00
|
|
|
#endif
|
|
|
|
|
2017-02-15 22:29:05 +03:00
|
|
|
#ifdef BUILDINFO_GTK
|
|
|
|
{
|
|
|
|
char *gtk_buildinfo = buildinfo_gtk_version();
|
|
|
|
if (gtk_buildinfo) {
|
|
|
|
strbuf_catf(buf, "%sCompiled against GTK version %s",
|
|
|
|
newline, gtk_buildinfo);
|
|
|
|
sfree(gtk_buildinfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2019-01-26 23:26:09 +03:00
|
|
|
#if defined _WINDOWS
|
|
|
|
{
|
|
|
|
int echm = has_embedded_chm();
|
|
|
|
if (echm >= 0)
|
|
|
|
strbuf_catf(buf, "%sEmbedded HTML Help file: %s", newline,
|
|
|
|
echm ? "yes" : "no");
|
|
|
|
}
|
|
|
|
#endif
|
2017-02-15 22:29:05 +03:00
|
|
|
|
2017-07-03 09:27:05 +03:00
|
|
|
#if defined _WINDOWS && defined MINEFIELD
|
|
|
|
strbuf_catf(buf, "%sBuild option: MINEFIELD", newline);
|
|
|
|
#endif
|
2017-01-21 17:55:53 +03:00
|
|
|
#ifdef NO_SECURITY
|
|
|
|
strbuf_catf(buf, "%sBuild option: NO_SECURITY", newline);
|
|
|
|
#endif
|
|
|
|
#ifdef NO_SECUREZEROMEMORY
|
|
|
|
strbuf_catf(buf, "%sBuild option: NO_SECUREZEROMEMORY", newline);
|
|
|
|
#endif
|
|
|
|
#ifdef NO_IPV6
|
|
|
|
strbuf_catf(buf, "%sBuild option: NO_IPV6", newline);
|
|
|
|
#endif
|
|
|
|
#ifdef NO_GSSAPI
|
|
|
|
strbuf_catf(buf, "%sBuild option: NO_GSSAPI", newline);
|
|
|
|
#endif
|
|
|
|
#ifdef STATIC_GSSAPI
|
|
|
|
strbuf_catf(buf, "%sBuild option: STATIC_GSSAPI", newline);
|
|
|
|
#endif
|
|
|
|
#ifdef UNPROTECT
|
|
|
|
strbuf_catf(buf, "%sBuild option: UNPROTECT", newline);
|
|
|
|
#endif
|
|
|
|
#ifdef FUZZING
|
|
|
|
strbuf_catf(buf, "%sBuild option: FUZZING", newline);
|
|
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
|
|
strbuf_catf(buf, "%sBuild option: DEBUG", newline);
|
|
|
|
#endif
|
|
|
|
|
2017-01-21 17:55:53 +03:00
|
|
|
strbuf_catf(buf, "%sSource commit: %s", newline, commitid);
|
|
|
|
|
2017-01-21 17:55:53 +03:00
|
|
|
return strbuf_to_str(buf);
|
|
|
|
}
|
New abstraction 'Seat', to pass to backends.
This is a new vtable-based abstraction which is passed to a backend in
place of Frontend, and it implements only the subset of the Frontend
functions needed by a backend. (Many other Frontend functions still
exist, notably the wide range of things called by terminal.c providing
platform-independent operations on the GUI terminal window.)
The purpose of making it a vtable is that this opens up the
possibility of creating a backend as an internal implementation detail
of some other activity, by providing just that one backend with a
custom Seat that implements the methods differently.
For example, this refactoring should make it feasible to directly
implement an SSH proxy type, aka the 'jump host' feature supported by
OpenSSH, aka 'open a secondary SSH session in MAINCHAN_DIRECT_TCP
mode, and then expose the main channel of that as the Socket for the
primary connection'. (Which of course you can already do by spawning
'plink -nc' as a separate proxy process, but this would permit it in
the _same_ process without anything getting confused.)
I've centralised a full set of stub methods in misc.c for the new
abstraction, which allows me to get rid of several annoying stubs in
the previous code. Also, while I'm here, I've moved a lot of
duplicated modalfatalbox() type functions from application main
program files into wincons.c / uxcons.c, which I think saves
duplication overall. (A minor visible effect is that the prefixes on
those console-based fatal error messages will now be more consistent
between applications.)
2018-10-11 21:58:42 +03:00
|
|
|
|
2019-02-06 23:42:44 +03:00
|
|
|
size_t nullseat_output(
|
|
|
|
Seat *seat, bool is_stderr, const void *data, size_t len) { return 0; }
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 22:23:19 +03:00
|
|
|
bool nullseat_eof(Seat *seat) { return true; }
|
New abstraction 'Seat', to pass to backends.
This is a new vtable-based abstraction which is passed to a backend in
place of Frontend, and it implements only the subset of the Frontend
functions needed by a backend. (Many other Frontend functions still
exist, notably the wide range of things called by terminal.c providing
platform-independent operations on the GUI terminal window.)
The purpose of making it a vtable is that this opens up the
possibility of creating a backend as an internal implementation detail
of some other activity, by providing just that one backend with a
custom Seat that implements the methods differently.
For example, this refactoring should make it feasible to directly
implement an SSH proxy type, aka the 'jump host' feature supported by
OpenSSH, aka 'open a secondary SSH session in MAINCHAN_DIRECT_TCP
mode, and then expose the main channel of that as the Socket for the
primary connection'. (Which of course you can already do by spawning
'plink -nc' as a separate proxy process, but this would permit it in
the _same_ process without anything getting confused.)
I've centralised a full set of stub methods in misc.c for the new
abstraction, which allows me to get rid of several annoying stubs in
the previous code. Also, while I'm here, I've moved a lot of
duplicated modalfatalbox() type functions from application main
program files into wincons.c / uxcons.c, which I think saves
duplication overall. (A minor visible effect is that the prefixes on
those console-based fatal error messages will now be more consistent
between applications.)
2018-10-11 21:58:42 +03:00
|
|
|
int nullseat_get_userpass_input(
|
|
|
|
Seat *seat, prompts_t *p, bufchain *input) { return 0; }
|
|
|
|
void nullseat_notify_remote_exit(Seat *seat) {}
|
|
|
|
void nullseat_connection_fatal(Seat *seat, const char *message) {}
|
|
|
|
void nullseat_update_specials_menu(Seat *seat) {}
|
|
|
|
char *nullseat_get_ttymode(Seat *seat, const char *mode) { return NULL; }
|
|
|
|
void nullseat_set_busy_status(Seat *seat, BusyStatus status) {}
|
|
|
|
int nullseat_verify_ssh_host_key(
|
|
|
|
Seat *seat, const char *host, int port,
|
|
|
|
const char *keytype, char *keystr, char *key_fingerprint,
|
|
|
|
void (*callback)(void *ctx, int result), void *ctx) { return 0; }
|
|
|
|
int nullseat_confirm_weak_crypto_primitive(
|
|
|
|
Seat *seat, const char *algtype, const char *algname,
|
|
|
|
void (*callback)(void *ctx, int result), void *ctx) { return 0; }
|
|
|
|
int nullseat_confirm_weak_cached_hostkey(
|
|
|
|
Seat *seat, const char *algname, const char *betteralgs,
|
|
|
|
void (*callback)(void *ctx, int result), void *ctx) { return 0; }
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 22:23:19 +03:00
|
|
|
bool nullseat_is_never_utf8(Seat *seat) { return false; }
|
|
|
|
bool nullseat_is_always_utf8(Seat *seat) { return true; }
|
|
|
|
void nullseat_echoedit_update(Seat *seat, bool echoing, bool editing) {}
|
New abstraction 'Seat', to pass to backends.
This is a new vtable-based abstraction which is passed to a backend in
place of Frontend, and it implements only the subset of the Frontend
functions needed by a backend. (Many other Frontend functions still
exist, notably the wide range of things called by terminal.c providing
platform-independent operations on the GUI terminal window.)
The purpose of making it a vtable is that this opens up the
possibility of creating a backend as an internal implementation detail
of some other activity, by providing just that one backend with a
custom Seat that implements the methods differently.
For example, this refactoring should make it feasible to directly
implement an SSH proxy type, aka the 'jump host' feature supported by
OpenSSH, aka 'open a secondary SSH session in MAINCHAN_DIRECT_TCP
mode, and then expose the main channel of that as the Socket for the
primary connection'. (Which of course you can already do by spawning
'plink -nc' as a separate proxy process, but this would permit it in
the _same_ process without anything getting confused.)
I've centralised a full set of stub methods in misc.c for the new
abstraction, which allows me to get rid of several annoying stubs in
the previous code. Also, while I'm here, I've moved a lot of
duplicated modalfatalbox() type functions from application main
program files into wincons.c / uxcons.c, which I think saves
duplication overall. (A minor visible effect is that the prefixes on
those console-based fatal error messages will now be more consistent
between applications.)
2018-10-11 21:58:42 +03:00
|
|
|
const char *nullseat_get_x_display(Seat *seat) { return NULL; }
|
Convert a lot of 'int' variables to 'bool'.
My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.
PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.
I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!
To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.
In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
- the 'multisel' field in dialog.h's list box structure, for which
the GTK front end in particular recognises a difference between 1
and 2 but nearly everything else treats as boolean
- the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
something about the specific location of the urgent pointer, but
most clients only care about 0 vs 'something nonzero'
- the return value of wc_match, where -1 indicates a syntax error in
the wildcard.
- the return values from SSH-1 RSA-key loading functions, which use
-1 for 'wrong passphrase' and 0 for all other failures (so any
caller which already knows it's not loading an _encrypted private_
key can treat them as boolean)
- term->esc_query, and the 'query' parameter in toggle_mode in
terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
but can also hold -1 for some other intervening character that we
don't support.
In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
- the return value of plug_accepting uses the POSIXish convention of
0=success and nonzero=error; I think if I made it bool then I'd
also want to reverse its sense, and that's a job for a separate
piece of work.
- the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
represent the default and alternate screens. There's no obvious
reason why one of those should be considered 'true' or 'positive'
or 'success' - they're just indices - so I've left it as int.
ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.
In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.
Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
2018-11-02 22:23:19 +03:00
|
|
|
bool nullseat_get_windowid(Seat *seat, long *id_out) { return false; }
|
|
|
|
bool nullseat_get_window_pixel_size(
|
2018-10-29 22:50:29 +03:00
|
|
|
Seat *seat, int *width, int *height) { return false; }
|
2019-03-06 00:13:00 +03:00
|
|
|
StripCtrlChars *nullseat_stripctrl_new(
|
2019-03-07 11:19:38 +03:00
|
|
|
Seat *seat, BinarySink *bs_out, SeatInteractionContext sic) {return NULL;}
|
2019-03-10 17:42:11 +03:00
|
|
|
bool nullseat_set_trust_status(Seat *seat, bool tr) { return false; }
|
|
|
|
bool nullseat_set_trust_status_vacuously(Seat *seat, bool tr) { return true; }
|
2018-10-18 22:06:42 +03:00
|
|
|
|
|
|
|
void sk_free_peer_info(SocketPeerInfo *pi)
|
|
|
|
{
|
|
|
|
if (pi) {
|
|
|
|
sfree((char *)pi->addr_text);
|
|
|
|
sfree((char *)pi->log_text);
|
|
|
|
sfree(pi);
|
|
|
|
}
|
|
|
|
}
|
Move standalone parts of misc.c into utils.c.
misc.c has always contained a combination of things that are tied
tightly into the PuTTY code base (e.g. they use the conf system, or
work with our sockets abstraction) and things that are pure standalone
utility functions like nullstrcmp() which could quite happily be
dropped into any C program without causing a link failure.
Now the latter kind of standalone utility code lives in the new source
file utils.c, whose only external dependency is on memory.c (for snew,
sfree etc), which in turn requires the user to provide an
out_of_memory() function. So it should now be much easier to link test
programs that use PuTTY's low-level functions without also pulling in
half its bulky infrastructure.
In the process, I came across a memory allocation logging system
enabled by -DMALLOC_LOG that looks long since bit-rotted; in any case
we have much more advanced tools for that kind of thing these days,
like valgrind and Leak Sanitiser, so I've just removed it rather than
trying to transplant it somewhere sensible. (We can always pull it
back out of the version control history if really necessary, but I
haven't used it in at least a decade.)
The other slightly silly thing I did was to give bufchain a function
pointer field that points to queue_idempotent_callback(), and disallow
direct setting of the 'ic' field in favour of calling
bufchain_set_callback which will fill that pointer in too. That allows
the bufchain system to live in utils.c rather than misc.c, so that
programs can use it without also having to link in the callback system
or provide an annoying stub of that function. In fact that's just
allowed me to remove stubs of that kind from PuTTYgen and Pageant!
2019-01-03 11:44:11 +03:00
|
|
|
|
|
|
|
void out_of_memory(void)
|
|
|
|
{
|
|
|
|
modalfatalbox("Out of memory");
|
|
|
|
}
|