1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00: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'!
This commit is contained in:
Simon Tatham 2018-11-02 19:23:19 +00:00
parent 1378bb049a
commit 3214563d8e
164 changed files with 2914 additions and 2805 deletions

View File

@ -15,8 +15,8 @@ typedef struct agentf {
SshChannel *c;
bufchain inbuffer;
agent_pending_query *pending;
int input_wanted;
int rcvd_eof;
bool input_wanted;
bool rcvd_eof;
Channel chan;
} agentf;
@ -142,10 +142,10 @@ static void agentf_callback(void *vctx, void *reply, int replylen)
}
static void agentf_free(Channel *chan);
static int agentf_send(Channel *chan, int is_stderr, const void *, int);
static int agentf_send(Channel *chan, bool is_stderr, const void *, int);
static void agentf_send_eof(Channel *chan);
static char *agentf_log_close_msg(Channel *chan);
static void agentf_set_input_wanted(Channel *chan, int wanted);
static void agentf_set_input_wanted(Channel *chan, bool wanted);
static const struct ChannelVtable agentf_channelvt = {
agentf_free,
@ -196,7 +196,7 @@ static void agentf_free(Channel *chan)
sfree(af);
}
static int agentf_send(Channel *chan, int is_stderr,
static int agentf_send(Channel *chan, bool is_stderr,
const void *data, int length)
{
assert(chan->vt == &agentf_channelvt);
@ -233,7 +233,7 @@ static char *agentf_log_close_msg(Channel *chan)
return dupstr("Agent-forwarding connection closed");
}
static void agentf_set_input_wanted(Channel *chan, int wanted)
static void agentf_set_input_wanted(Channel *chan, bool wanted)
{
assert(chan->vt == &agentf_channelvt);
agentf *af = container_of(chan, agentf, chan);

View File

@ -11,7 +11,7 @@
void backend_socket_log(Seat *seat, LogContext *logctx,
int type, SockAddr *addr, int port,
const char *error_msg, int error_code, Conf *conf,
int session_started)
bool session_started)
{
char addrbuf[256], *msg;

View File

@ -99,9 +99,9 @@ void queue_toplevel_callback(toplevel_callback_fn_t fn, void *ctx)
cb->next = NULL;
}
int run_toplevel_callbacks(void)
bool run_toplevel_callbacks(void)
{
int done_something = false;
bool done_something = false;
if (cbhead) {
/*
@ -127,7 +127,7 @@ int run_toplevel_callbacks(void)
return done_something;
}
int toplevel_callback_pending(void)
bool toplevel_callback_pending(void)
{
return cbcurr != NULL || cbhead != NULL;
}

View File

@ -114,7 +114,7 @@ void showversion(void)
sfree(buildinfo_text);
}
void usage(int standalone)
void usage(bool standalone)
{
fprintf(standalone ? stderr : stdout,
"Usage: puttygen ( keyfile | -t type [ -b bits ] )\n"
@ -163,7 +163,7 @@ void help(void)
);
}
static int move(char *from, char *to)
static bool move(char *from, char *to)
{
int ret;
@ -208,7 +208,7 @@ static char *readpassphrase(const char *filename)
#define DEFAULT_RSADSA_BITS 2048
/* For Unix in particular, but harmless if this main() is reused elsewhere */
const int buildinfo_gtk_relevant = false;
const bool buildinfo_gtk_relevant = false;
int main(int argc, char **argv)
{
@ -220,8 +220,8 @@ int main(int argc, char **argv)
OPENSSH_NEW, SSHCOM } outtype = PRIVATE;
int bits = -1;
char *comment = NULL, *origcomment = NULL;
int change_passphrase = false;
int errs = false, nogo = false;
bool change_passphrase = false;
bool errs = false, nogo = false;
int intype = SSH_KEYTYPE_UNOPENABLE;
int sshver = 0;
struct ssh2_userkey *ssh2key = NULL;
@ -229,7 +229,7 @@ int main(int argc, char **argv)
strbuf *ssh2blob = NULL;
char *ssh2alg = NULL;
char *old_passphrase = NULL, *new_passphrase = NULL;
int load_encrypted;
bool load_encrypted;
progfn_t progressfn = is_interactive() ? progress_update : no_progress;
const char *random_device = NULL;
@ -735,7 +735,7 @@ int main(int argc, char **argv)
} else {
const char *error = NULL;
int encrypted;
bool encrypted;
assert(infile != NULL);
@ -930,7 +930,8 @@ int main(int argc, char **argv)
outfilename = filename_from_str(outfile ? outfile : "");
switch (outtype) {
int ret, real_outtype;
bool ret;
int real_outtype;
case PRIVATE:
if (sshver == 1) {

View File

@ -87,7 +87,7 @@ void cmdline_cleanup(void)
*/
int cmdline_get_passwd_input(prompts_t *p)
{
static int tried_once = 0;
static bool tried_once = false;
/*
* We only handle prompts which don't echo (which we assume to be
@ -109,7 +109,7 @@ int cmdline_get_passwd_input(prompts_t *p)
smemclr(cmdline_password, strlen(cmdline_password));
sfree(cmdline_password);
cmdline_password = NULL;
tried_once = 1;
tried_once = true;
return 1;
}
@ -125,13 +125,13 @@ int cmdline_get_passwd_input(prompts_t *p)
*/
int cmdline_tooltype = 0;
static int cmdline_check_unavailable(int flag, const char *p)
static bool cmdline_check_unavailable(int flag, const char *p)
{
if (cmdline_tooltype & flag) {
cmdline_error("option \"%s\" not available in this tool", p);
return 1;
return true;
}
return 0;
return false;
}
#define UNAVAILABLE_IN(flag) do { \
@ -159,8 +159,8 @@ static int cmdline_check_unavailable(int flag, const char *p)
if (need_save < 0) return x; \
} while (0)
static int seen_hostname_argument = false;
static int seen_port_argument = false;
static bool seen_hostname_argument = false;
static bool seen_port_argument = false;
int cmdline_process_param(const char *p, char *value,
int need_save, Conf *conf)
@ -881,7 +881,7 @@ void cmdline_run_saved(Conf *conf)
}
}
int cmdline_host_ok(Conf *conf)
bool cmdline_host_ok(Conf *conf)
{
/*
* Return true if the command-line arguments we've processed in

5
conf.c
View File

@ -425,7 +425,8 @@ void conf_set_int(Conf *conf, int primary, int value)
conf_insert(conf, entry);
}
void conf_set_int_int(Conf *conf, int primary, int secondary, int value)
void conf_set_int_int(Conf *conf, int primary,
int secondary, int value)
{
struct conf_entry *entry = snew(struct conf_entry);
@ -537,7 +538,7 @@ void conf_serialise(BinarySink *bs, Conf *conf)
put_uint32(bs, 0xFFFFFFFFU);
}
int conf_deserialise(Conf *conf, BinarySource *src)
bool conf_deserialise(Conf *conf, BinarySource *src)
{
struct conf_entry *entry;
unsigned primary;

View File

@ -85,9 +85,9 @@ void conf_checkbox_handler(union control *ctrl, dlgparam *dlg,
key = ctrl->checkbox.context.i;
if (key & CHECKBOX_INVERT) {
key &= ~CHECKBOX_INVERT;
invert = 1;
invert = true;
} else
invert = 0;
invert = false;
/*
* C lacks a logical XOR, so the following code uses the idiom
@ -159,7 +159,8 @@ void conf_filesel_handler(union control *ctrl, dlgparam *dlg,
Conf *conf = (Conf *)data;
if (event == EVENT_REFRESH) {
dlg_filesel_set(ctrl, dlg, conf_get_filename(conf, key));
dlg_filesel_set(
ctrl, dlg, conf_get_filename(conf, key));
} else if (event == EVENT_VALCHANGE) {
Filename *filename = dlg_filesel_get(ctrl, dlg);
conf_set_filename(conf, key, filename);
@ -174,7 +175,8 @@ void conf_fontsel_handler(union control *ctrl, dlgparam *dlg,
Conf *conf = (Conf *)data;
if (event == EVENT_REFRESH) {
dlg_fontsel_set(ctrl, dlg, conf_get_fontspec(conf, key));
dlg_fontsel_set(
ctrl, dlg, conf_get_fontspec(conf, key));
} else if (event == EVENT_VALCHANGE) {
FontSpec *fontspec = dlg_fontsel_get(ctrl, dlg);
conf_set_fontspec(conf, key, fontspec);
@ -634,7 +636,7 @@ struct sessionsaver_data {
union control *editbox, *listbox, *loadbutton, *savebutton, *delbutton;
union control *okbutton, *cancelbutton;
struct sesslist sesslist;
int midsession;
bool midsession;
char *savedsession; /* the current contents of ssd->editbox */
};
@ -651,14 +653,15 @@ static void sessionsaver_data_free(void *ssdv)
* any, as this is done in more than one place below. Returns 0 for
* failure.
*/
static int load_selected_session(struct sessionsaver_data *ssd,
dlgparam *dlg, Conf *conf, int *maybe_launch)
static bool load_selected_session(
struct sessionsaver_data *ssd,
dlgparam *dlg, Conf *conf, bool *maybe_launch)
{
int i = dlg_listbox_index(ssd->listbox, dlg);
int isdef;
bool isdef;
if (i < 0) {
dlg_beep(dlg);
return 0;
return false;
}
isdef = !strcmp(ssd->sesslist.sessions[i], "Default Settings");
load_settings(ssd->sesslist.sessions[i], conf);
@ -670,7 +673,7 @@ static int load_selected_session(struct sessionsaver_data *ssd,
/* Restore the selection, which might have been clobbered by
* changing the value of the edit box. */
dlg_listbox_select(ssd->listbox, dlg, i);
return 1;
return true;
}
static void sessionsaver_handler(union control *ctrl, dlgparam *dlg,
@ -713,7 +716,7 @@ static void sessionsaver_handler(union control *ctrl, dlgparam *dlg,
dlg_listbox_select(ssd->listbox, dlg, top);
}
} else if (event == EVENT_ACTION) {
int mbl = false;
bool mbl = false;
if (!ssd->midsession &&
(ctrl == ssd->listbox ||
(ssd->loadbutton && ctrl == ssd->loadbutton))) {
@ -729,7 +732,7 @@ static void sessionsaver_handler(union control *ctrl, dlgparam *dlg,
dlg_end(dlg, 1); /* it's all over, and succeeded */
}
} else if (ctrl == ssd->savebutton) {
int isdef = !strcmp(ssd->savedsession, "Default Settings");
bool isdef = !strcmp(ssd->savedsession, "Default Settings");
if (!ssd->savedsession[0]) {
int i = dlg_listbox_index(ssd->listbox, dlg);
if (i < 0) {
@ -779,7 +782,7 @@ static void sessionsaver_handler(union control *ctrl, dlgparam *dlg,
if (dlg_last_focused(ctrl, dlg) == ssd->listbox &&
!conf_launchable(conf)) {
Conf *conf2 = conf_new();
int mbl = false;
bool mbl = false;
if (!load_selected_session(ssd, dlg, conf2, &mbl)) {
dlg_beep(dlg);
conf_free(conf2);
@ -875,7 +878,8 @@ static void colour_handler(union control *ctrl, dlgparam *dlg,
Conf *conf = (Conf *)data;
struct colour_data *cd =
(struct colour_data *)ctrl->generic.context.p;
int update = false, clear = false, r, g, b;
bool update = false, clear = false;
int r, g, b;
if (event == EVENT_REFRESH) {
if (ctrl == cd->listbox) {
@ -1464,7 +1468,7 @@ static void clipboard_control(struct controlset *s, const char *label,
#endif
}
void setup_config_box(struct controlbox *b, int midsession,
void setup_config_box(struct controlbox *b, bool midsession,
int protocol, int protcfginfo)
{
struct controlset *s;
@ -2275,7 +2279,7 @@ void setup_config_box(struct controlbox *b, int midsession,
HELPCTX(proxy_auth),
conf_editbox_handler,
I(CONF_proxy_password), I(1));
c->editbox.password = 1;
c->editbox.password = true;
ctrl_editbox(s, "Telnet command", 'm', 100,
HELPCTX(proxy_command),
conf_editbox_handler,
@ -2501,7 +2505,7 @@ void setup_config_box(struct controlbox *b, int midsession,
HELPCTX(ssh_kex_manual_hostkeys),
manual_hostkey_handler, P(mh));
mh->rembutton->generic.column = 1;
mh->rembutton->generic.tabdelay = 1;
mh->rembutton->generic.tabdelay = true;
mh->listbox = ctrl_listbox(s, NULL, NO_SHORTCUT,
HELPCTX(ssh_kex_manual_hostkeys),
manual_hostkey_handler, P(mh));
@ -2683,7 +2687,7 @@ void setup_config_box(struct controlbox *b, int midsession,
HELPCTX(ssh_ttymodes),
ttymodes_handler, P(td));
td->setbutton->generic.column = 1;
td->setbutton->generic.tabdelay = 1;
td->setbutton->generic.tabdelay = true;
ctrl_columns(s, 1, 100); /* column break */
/* Bit of a hack to get the value radio buttons and
* edit-box on the same row. */
@ -2752,7 +2756,7 @@ void setup_config_box(struct controlbox *b, int midsession,
HELPCTX(ssh_tunnels_portfwd),
portfwd_handler, P(pfd));
pfd->rembutton->generic.column = 2;
pfd->rembutton->generic.tabdelay = 1;
pfd->rembutton->generic.tabdelay = true;
pfd->listbox = ctrl_listbox(s, NULL, NO_SHORTCUT,
HELPCTX(ssh_tunnels_portfwd),
portfwd_handler, P(pfd));
@ -2769,7 +2773,7 @@ void setup_config_box(struct controlbox *b, int midsession,
HELPCTX(ssh_tunnels_portfwd),
portfwd_handler, P(pfd));
pfd->addbutton->generic.column = 2;
pfd->addbutton->generic.tabdelay = 1;
pfd->addbutton->generic.tabdelay = true;
pfd->sourcebox = ctrl_editbox(s, "Source port", 's', 40,
HELPCTX(ssh_tunnels_portfwd),
portfwd_handler, P(pfd), P(NULL));

View File

@ -86,7 +86,7 @@ void ctrl_free_set(struct controlset *s)
* path. If that path doesn't exist, return the index where it
* should be inserted.
*/
static int ctrl_find_set(struct controlbox *b, const char *path, int start)
static int ctrl_find_set(struct controlbox *b, const char *path, bool start)
{
int i, last, thisone;
@ -115,7 +115,7 @@ static int ctrl_find_set(struct controlbox *b, const char *path, int start)
int ctrl_find_path(struct controlbox *b, const char *path, int index)
{
if (index < 0)
index = ctrl_find_set(b, path, 1);
index = ctrl_find_set(b, path, true);
else
index++;
@ -131,7 +131,7 @@ struct controlset *ctrl_settitle(struct controlbox *b,
{
struct controlset *s = snew(struct controlset);
int index = ctrl_find_set(b, path, 1);
int index = ctrl_find_set(b, path, true);
s->pathname = dupstr(path);
s->boxname = NULL;
s->boxtitle = dupstr(title);
@ -155,7 +155,7 @@ struct controlset *ctrl_getset(struct controlbox *b, const char *path,
const char *name, const char *boxtitle)
{
struct controlset *s;
int index = ctrl_find_set(b, path, 1);
int index = ctrl_find_set(b, path, true);
while (index < b->nctrlsets &&
!strcmp(b->ctrlsets[index]->pathname, path)) {
if (b->ctrlsets[index]->boxname &&
@ -227,7 +227,7 @@ static union control *ctrl_new(struct controlset *s, int type,
* Fill in the standard fields.
*/
c->generic.type = type;
c->generic.tabdelay = 0;
c->generic.tabdelay = false;
c->generic.column = COLUMN_FIELD(0, s->ncolumns);
c->generic.helpctx = helpctx;
c->generic.handler = handler;
@ -266,8 +266,8 @@ union control *ctrl_editbox(struct controlset *s, const char *label,
c->editbox.label = label ? dupstr(label) : NULL;
c->editbox.shortcut = shortcut;
c->editbox.percentwidth = percentage;
c->editbox.password = 0;
c->editbox.has_list = 0;
c->editbox.password = false;
c->editbox.has_list = false;
c->editbox.context2 = context2;
return c;
}
@ -281,8 +281,8 @@ union control *ctrl_combobox(struct controlset *s, const char *label,
c->editbox.label = label ? dupstr(label) : NULL;
c->editbox.shortcut = shortcut;
c->editbox.percentwidth = percentage;
c->editbox.password = 0;
c->editbox.has_list = 1;
c->editbox.password = false;
c->editbox.has_list = true;
c->editbox.context2 = context2;
return c;
}
@ -346,8 +346,8 @@ union control *ctrl_pushbutton(struct controlset *s, const char *label,
union control *c = ctrl_new(s, CTRL_BUTTON, helpctx, handler, context);
c->button.label = label ? dupstr(label) : NULL;
c->button.shortcut = shortcut;
c->button.isdefault = 0;
c->button.iscancel = 0;
c->button.isdefault = false;
c->button.iscancel = false;
return c;
}
@ -359,7 +359,7 @@ union control *ctrl_listbox(struct controlset *s, const char *label,
c->listbox.label = label ? dupstr(label) : NULL;
c->listbox.shortcut = shortcut;
c->listbox.height = 5; /* *shrug* a plausible default */
c->listbox.draglist = 0;
c->listbox.draglist = false;
c->listbox.multisel = 0;
c->listbox.percentwidth = 100;
c->listbox.ncols = 0;
@ -376,7 +376,7 @@ union control *ctrl_droplist(struct controlset *s, const char *label,
c->listbox.label = label ? dupstr(label) : NULL;
c->listbox.shortcut = shortcut;
c->listbox.height = 0; /* means it's a drop-down list */
c->listbox.draglist = 0;
c->listbox.draglist = false;
c->listbox.multisel = 0;
c->listbox.percentwidth = percentage;
c->listbox.ncols = 0;
@ -393,7 +393,7 @@ union control *ctrl_draglist(struct controlset *s, const char *label,
c->listbox.label = label ? dupstr(label) : NULL;
c->listbox.shortcut = shortcut;
c->listbox.height = 5; /* *shrug* a plausible default */
c->listbox.draglist = 1;
c->listbox.draglist = true;
c->listbox.multisel = 0;
c->listbox.percentwidth = 100;
c->listbox.ncols = 0;
@ -403,7 +403,7 @@ union control *ctrl_draglist(struct controlset *s, const char *label,
}
union control *ctrl_filesel(struct controlset *s, const char *label,
char shortcut, const char *filter, int write,
char shortcut, const char *filter, bool write,
const char *title, intorptr helpctx,
handler_fn handler, intorptr context)
{

View File

@ -109,7 +109,7 @@ typedef void (*handler_fn)(union control *ctrl, dlgparam *dp,
#define STANDARD_PREFIX \
int type; \
char *label; \
int tabdelay; \
bool tabdelay; \
int column; \
handler_fn handler; \
intorptr context; \
@ -142,7 +142,7 @@ union control {
* particular control should not yet appear in the tab
* order. A subsequent CTRL_TABDELAY entry will place it.
*/
int tabdelay;
bool tabdelay;
/*
* Indicate which column(s) this control occupies. This can
* be unpacked into starting column and column span by the
@ -197,7 +197,7 @@ union control {
* itself.
*/
int percentwidth;
int password; /* details of input are hidden */
bool password; /* details of input are hidden */
/*
* A special case of the edit box is the combo box, which
* has a drop-down list built in. (Note that a _non_-
@ -208,7 +208,7 @@ union control {
* control; front ends are not required to support that
* combination.
*/
int has_list;
bool has_list;
/*
* Edit boxes tend to need two items of context, so here's
* a spare.
@ -279,12 +279,12 @@ union control {
* button', which gets implicitly pressed when you hit
* Return even if it doesn't have the input focus.
*/
int isdefault;
bool isdefault;
/*
* Also, the reverse of this: a default cancel-type button,
* which is implicitly pressed when you hit Escape.
*/
int iscancel;
bool iscancel;
} button;
struct {
STANDARD_PREFIX;
@ -301,7 +301,7 @@ union control {
* comfortable with). This is not guaranteed to work on a
* drop-down list, so don't try it!
*/
int draglist;
bool draglist;
/*
* If this is non-zero, the list can have more than one
* element selected at a time. This is not guaranteed to
@ -344,7 +344,7 @@ union control {
* scroll bar if a list box entry goes off the right-hand
* side.
*/
int hscroll;
bool hscroll;
} listbox;
struct {
STANDARD_PREFIX;
@ -374,7 +374,7 @@ union control {
* choosing a file to read or one to write (and possibly
* create).
*/
int for_writing;
bool for_writing;
/*
* On at least some platforms, the file selector is a
* separate dialog box, and contains a user-settable title.
@ -517,7 +517,7 @@ union control *ctrl_draglist(struct controlset *, const char *label,
char shortcut, intorptr helpctx,
handler_fn handler, intorptr context);
union control *ctrl_filesel(struct controlset *, const char *label,
char shortcut, const char *filter, int write,
char shortcut, const char *filter, bool write,
const char *title, intorptr helpctx,
handler_fn handler, intorptr context);
union control *ctrl_fontsel(struct controlset *, const char *label,
@ -536,8 +536,8 @@ union control *ctrl_tabdelay(struct controlset *, union control *);
*/
void dlg_radiobutton_set(union control *ctrl, dlgparam *dp, int whichbutton);
int dlg_radiobutton_get(union control *ctrl, dlgparam *dp);
void dlg_checkbox_set(union control *ctrl, dlgparam *dp, int checked);
int dlg_checkbox_get(union control *ctrl, dlgparam *dp);
void dlg_checkbox_set(union control *ctrl, dlgparam *dp, bool checked);
bool dlg_checkbox_get(union control *ctrl, dlgparam *dp);
void dlg_editbox_set(union control *ctrl, dlgparam *dp, char const *text);
char *dlg_editbox_get(union control *ctrl, dlgparam *dp); /* result must be freed by caller */
/* The `listbox' functions can also apply to combo boxes. */
@ -556,7 +556,7 @@ void dlg_listbox_addwithid(union control *ctrl, dlgparam *dp,
int dlg_listbox_getid(union control *ctrl, dlgparam *dp, int index);
/* dlg_listbox_index returns <0 if no single element is selected. */
int dlg_listbox_index(union control *ctrl, dlgparam *dp);
int dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index);
bool dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index);
void dlg_listbox_select(union control *ctrl, dlgparam *dp, int index);
void dlg_text_set(union control *ctrl, dlgparam *dp, char const *text);
void dlg_filesel_set(union control *ctrl, dlgparam *dp, Filename *fn);
@ -614,8 +614,8 @@ void dlg_end(dlgparam *dp, int value);
*/
void dlg_coloursel_start(union control *ctrl, dlgparam *dp,
int r, int g, int b);
int dlg_coloursel_results(union control *ctrl, dlgparam *dp,
int *r, int *g, int *b);
bool dlg_coloursel_results(union control *ctrl, dlgparam *dp,
int *r, int *g, int *b);
/*
* This routine is used by the platform-independent code to

View File

@ -7,7 +7,7 @@
#include "terminal.h"
/* For Unix in particular, but harmless if this main() is reused elsewhere */
const int buildinfo_gtk_relevant = false;
const bool buildinfo_gtk_relevant = false;
static const TermWinVtable fuzz_termwin_vt;
@ -37,14 +37,14 @@ int main(int argc, char **argv)
#endif
while (!feof(stdin)) {
len = fread(blk, 1, sizeof(blk), stdin);
term_data(term, 0, blk, len);
term_data(term, false, blk, len);
}
term_update(term);
return 0;
}
/* functions required by terminal.c */
static int fuzz_setup_draw_ctx(TermWin *tw) { return true; }
static bool fuzz_setup_draw_ctx(TermWin *tw) { return true; }
static void fuzz_draw_text(
TermWin *tw, int x, int y, wchar_t *text, int len,
unsigned long attr, int lattr, truecolour tc)
@ -72,30 +72,30 @@ static void fuzz_draw_cursor(
static int fuzz_char_width(TermWin *tw, int uc) { return 1; }
static void fuzz_free_draw_ctx(TermWin *tw) {}
static void fuzz_set_cursor_pos(TermWin *tw, int x, int y) {}
static void fuzz_set_raw_mouse_mode(TermWin *tw, int enable) {}
static void fuzz_set_raw_mouse_mode(TermWin *tw, bool enable) {}
static void fuzz_set_scrollbar(TermWin *tw, int total, int start, int page) {}
static void fuzz_bell(TermWin *tw, int mode) {}
static void fuzz_clip_write(
TermWin *tw, int clipboard, wchar_t *text, int *attrs,
truecolour *colours, int len, int must_deselect) {}
truecolour *colours, int len, bool must_deselect) {}
static void fuzz_clip_request_paste(TermWin *tw, int clipboard) {}
static void fuzz_refresh(TermWin *tw) {}
static void fuzz_request_resize(TermWin *tw, int w, int h) {}
static void fuzz_set_title(TermWin *tw, const char *title) {}
static void fuzz_set_icon_title(TermWin *tw, const char *icontitle) {}
static void fuzz_set_minimised(TermWin *tw, int minimised) {}
static int fuzz_is_minimised(TermWin *tw) { return false; }
static void fuzz_set_maximised(TermWin *tw, int maximised) {}
static void fuzz_set_minimised(TermWin *tw, bool minimised) {}
static bool fuzz_is_minimised(TermWin *tw) { return false; }
static void fuzz_set_maximised(TermWin *tw, bool maximised) {}
static void fuzz_move(TermWin *tw, int x, int y) {}
static void fuzz_set_zorder(TermWin *tw, int top) {}
static int fuzz_palette_get(TermWin *tw, int n, int *r, int *g, int *b)
static void fuzz_set_zorder(TermWin *tw, bool top) {}
static bool fuzz_palette_get(TermWin *tw, int n, int *r, int *g, int *b)
{ return false; }
static void fuzz_palette_set(TermWin *tw, int n, int r, int g, int b) {}
static void fuzz_palette_reset(TermWin *tw) {}
static void fuzz_get_pos(TermWin *tw, int *x, int *y) { *x = *y = 0; }
static void fuzz_get_pixels(TermWin *tw, int *x, int *y) { *x = *y = 0; }
static const char *fuzz_get_title(TermWin *tw, int icon) { return "moo"; }
static int fuzz_is_utf8(TermWin *tw) { return true; }
static const char *fuzz_get_title(TermWin *tw, bool icon) { return "moo"; }
static bool fuzz_is_utf8(TermWin *tw) { return true; }
static const TermWinVtable fuzz_termwin_vt = {
fuzz_setup_draw_ctx,
@ -127,7 +127,7 @@ static const TermWinVtable fuzz_termwin_vt = {
fuzz_is_utf8,
};
void ldisc_send(Ldisc *ldisc, const void *buf, int len, int interactive) {}
void ldisc_send(Ldisc *ldisc, const void *buf, int len, bool interactive) {}
void ldisc_echoedit_update(Ldisc *ldisc) {}
void modalfatalbox(const char *fmt, ...) { exit(0); }
void nonfatal(const char *fmt, ...) { }
@ -167,8 +167,8 @@ void dlg_error_msg(void *dlg, const char *msg) { }
void dlg_end(void *dlg, int value) { }
void dlg_coloursel_start(union control *ctrl, void *dlg,
int r, int g, int b) { }
int dlg_coloursel_results(union control *ctrl, void *dlg,
int *r, int *g, int *b) { return 0; }
bool dlg_coloursel_results(union control *ctrl, void *dlg,
int *r, int *g, int *b) { return false; }
void dlg_refresh(union control *ctrl, void *dlg) { }
const char *const appname = "FuZZterm";

117
import.c
View File

@ -12,39 +12,39 @@
#include "ssh.h"
#include "misc.h"
int openssh_pem_encrypted(const Filename *filename);
int openssh_new_encrypted(const Filename *filename);
bool openssh_pem_encrypted(const Filename *filename);
bool openssh_new_encrypted(const Filename *filename);
struct ssh2_userkey *openssh_pem_read(const Filename *filename,
char *passphrase,
const char **errmsg_p);
struct ssh2_userkey *openssh_new_read(const Filename *filename,
char *passphrase,
const char **errmsg_p);
int openssh_auto_write(const Filename *filename, struct ssh2_userkey *key,
bool openssh_auto_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase);
bool openssh_pem_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase);
bool openssh_new_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase);
int openssh_pem_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase);
int openssh_new_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase);
int sshcom_encrypted(const Filename *filename, char **comment);
bool sshcom_encrypted(const Filename *filename, char **comment);
struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase,
const char **errmsg_p);
int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase);
bool sshcom_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase);
/*
* Given a key type, determine whether we know how to import it.
*/
int import_possible(int type)
bool import_possible(int type)
{
if (type == SSH_KEYTYPE_OPENSSH_PEM)
return 1;
return true;
if (type == SSH_KEYTYPE_OPENSSH_NEW)
return 1;
return true;
if (type == SSH_KEYTYPE_SSHCOM)
return 1;
return 0;
return true;
return false;
}
/*
@ -63,7 +63,7 @@ int import_target_type(int type)
/*
* Determine whether a foreign key is encrypted.
*/
int import_encrypted(const Filename *filename, int type, char **comment)
bool import_encrypted(const Filename *filename, int type, char **comment)
{
if (type == SSH_KEYTYPE_OPENSSH_PEM) {
/* OpenSSH PEM format doesn't contain a key comment at all */
@ -77,7 +77,7 @@ int import_encrypted(const Filename *filename, int type, char **comment)
} else if (type == SSH_KEYTYPE_SSHCOM) {
return sshcom_encrypted(filename, comment);
}
return 0;
return false;
}
/*
@ -107,17 +107,17 @@ struct ssh2_userkey *import_ssh2(const Filename *filename, int type,
/*
* Export an SSH-1 key.
*/
int export_ssh1(const Filename *filename, int type, struct RSAKey *key,
char *passphrase)
bool export_ssh1(const Filename *filename, int type, struct RSAKey *key,
char *passphrase)
{
return 0;
return false;
}
/*
* Export an SSH-2 key.
*/
int export_ssh2(const Filename *filename, int type,
struct ssh2_userkey *key, char *passphrase)
bool export_ssh2(const Filename *filename, int type,
struct ssh2_userkey *key, char *passphrase)
{
if (type == SSH_KEYTYPE_OPENSSH_AUTO)
return openssh_auto_write(filename, key, passphrase);
@ -125,7 +125,7 @@ int export_ssh2(const Filename *filename, int type,
return openssh_new_write(filename, key, passphrase);
if (type == SSH_KEYTYPE_SSHCOM)
return sshcom_write(filename, key, passphrase);
return 0;
return false;
}
/*
@ -276,7 +276,7 @@ typedef enum {
struct openssh_pem_key {
openssh_pem_keytype keytype;
int encrypted;
bool encrypted;
openssh_pem_enc encryption;
char iv[32];
strbuf *keyblob;
@ -309,7 +309,7 @@ static struct openssh_pem_key *load_openssh_pem_key(const Filename *filename,
char *line = NULL;
const char *errmsg;
char *p;
int headers_done;
bool headers_done;
char base64_bit[4];
int base64_chars = 0;
@ -358,7 +358,7 @@ static struct openssh_pem_key *load_openssh_pem_key(const Filename *filename,
ret->encrypted = false;
memset(ret->iv, 0, sizeof(ret->iv));
headers_done = 0;
headers_done = false;
while (1) {
if (!(line = fgetline(fp))) {
errmsg = "unexpected end of file";
@ -415,7 +415,7 @@ static struct openssh_pem_key *load_openssh_pem_key(const Filename *filename,
}
}
} else {
headers_done = 1;
headers_done = true;
p = line;
while (isbase64(*p)) {
@ -482,13 +482,13 @@ static struct openssh_pem_key *load_openssh_pem_key(const Filename *filename,
return NULL;
}
int openssh_pem_encrypted(const Filename *filename)
bool openssh_pem_encrypted(const Filename *filename)
{
struct openssh_pem_key *key = load_openssh_pem_key(filename, NULL);
int ret;
bool ret;
if (!key)
return 0;
return false;
ret = key->encrypted;
strbuf_free(key->keyblob);
smemclr(key, sizeof(*key));
@ -775,8 +775,8 @@ struct ssh2_userkey *openssh_pem_read(const Filename *filename,
return retval;
}
int openssh_pem_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase)
bool openssh_pem_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase)
{
strbuf *pubblob, *privblob, *outblob;
unsigned char *spareblob;
@ -786,7 +786,7 @@ int openssh_pem_write(const Filename *filename, struct ssh2_userkey *key,
const char *header, *footer;
char zero[1];
unsigned char iv[8];
int ret = 0;
bool ret = false;
FILE *fp;
BinarySource src[1];
@ -1061,7 +1061,7 @@ int openssh_pem_write(const Filename *filename, struct ssh2_userkey *key,
base64_encode(fp, outblob->u, outblob->len, 64);
fputs(footer, fp);
fclose(fp);
ret = 1;
ret = true;
error:
if (outblob)
@ -1319,13 +1319,13 @@ static struct openssh_new_key *load_openssh_new_key(const Filename *filename,
return NULL;
}
int openssh_new_encrypted(const Filename *filename)
bool openssh_new_encrypted(const Filename *filename)
{
struct openssh_new_key *key = load_openssh_new_key(filename, NULL);
int ret;
bool ret;
if (!key)
return 0;
return false;
ret = (key->cipher != ON_E_NONE);
smemclr(key->keyblob, key->keyblob_size);
sfree(key->keyblob);
@ -1515,13 +1515,13 @@ struct ssh2_userkey *openssh_new_read(const Filename *filename,
return retval;
}
int openssh_new_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase)
bool openssh_new_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase)
{
strbuf *pubblob, *privblob, *cblob;
int padvalue, i;
unsigned checkint;
int ret = 0;
bool ret = false;
unsigned char bcrypt_salt[16];
const int bcrypt_rounds = 16;
FILE *fp;
@ -1628,7 +1628,7 @@ int openssh_new_write(const Filename *filename, struct ssh2_userkey *key,
base64_encode(fp, cblob->u, cblob->len, 64);
fputs("-----END OPENSSH PRIVATE KEY-----\n", fp);
fclose(fp);
ret = 1;
ret = true;
error:
if (cblob)
@ -1644,8 +1644,8 @@ int openssh_new_write(const Filename *filename, struct ssh2_userkey *key,
* The switch function openssh_auto_write(), which chooses one of the
* concrete OpenSSH output formats based on the key type.
*/
int openssh_auto_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase)
bool openssh_auto_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase)
{
/*
* The old OpenSSH format supports a fixed list of key types. We
@ -1753,7 +1753,7 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename,
int hdrstart, len;
const char *errmsg;
char *p;
int headers_done;
bool headers_done;
char base64_bit[4];
int base64_chars = 0;
@ -1780,7 +1780,7 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename,
sfree(line);
line = NULL;
headers_done = 0;
headers_done = false;
while (1) {
if (!(line = fgetline(fp))) {
errmsg = "unexpected end of file";
@ -1840,7 +1840,7 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename,
ret->comment[sizeof(ret->comment)-1] = '\0';
}
} else {
headers_done = 1;
headers_done = true;
p = line;
while (isbase64(*p)) {
@ -1905,12 +1905,12 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename,
return NULL;
}
int sshcom_encrypted(const Filename *filename, char **comment)
bool sshcom_encrypted(const Filename *filename, char **comment)
{
struct sshcom_key *key = load_sshcom_key(filename, NULL);
BinarySource src[1];
ptrlen str;
int answer = false;
bool answer = false;
*comment = NULL;
if (!key)
@ -1981,7 +1981,7 @@ struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase,
const char prefix_rsa[] = "if-modn{sign{rsa";
const char prefix_dsa[] = "dl-modp{sign{dsa";
enum { RSA, DSA } type;
int encrypted;
bool encrypted;
struct ssh2_userkey *ret = NULL, *retkey;
const ssh_keyalg *alg;
strbuf *blob = NULL;
@ -2017,9 +2017,9 @@ struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase,
*/
str = get_string(src);
if (ptrlen_eq_string(str, "none"))
encrypted = 0;
encrypted = false;
else if (ptrlen_eq_string(str, "3des-cbc"))
encrypted = 1;
encrypted = true;
else {
errmsg = "key encryption is of unknown type";
goto error;
@ -2181,17 +2181,18 @@ struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase,
return ret;
}
int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase)
bool sshcom_write(const Filename *filename, struct ssh2_userkey *key,
char *passphrase)
{
strbuf *pubblob, *privblob, *outblob;
ptrlen numbers[6];
int nnumbers, initial_zero, lenpos, i;
int nnumbers, lenpos, i;
bool initial_zero;
BinarySource src[1];
const char *type;
char *ciphertext;
int cipherlen;
int ret = 0;
bool ret = false;
FILE *fp;
/*
@ -2234,7 +2235,7 @@ int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
numbers[5] = p;
nnumbers = 6;
initial_zero = 0;
initial_zero = false;
type = "if-modn{sign{rsa-pkcs1-sha1},encrypt{rsa-pkcs1v2-oaep}}";
} else if (ssh_key_alg(key->key) == &ssh_dss) {
ptrlen p, q, g, y, x;
@ -2261,7 +2262,7 @@ int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
numbers[4] = x;
nnumbers = 5;
initial_zero = 1;
initial_zero = true;
type = "dl-modp{sign{dsa-nist-sha1},dh{plain}}";
} else {
goto error; /* unsupported key type */
@ -2362,7 +2363,7 @@ int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
base64_encode(fp, outblob->u, outblob->len, 70);
fputs("---- END SSH2 ENCRYPTED PRIVATE KEY ----\n", fp);
fclose(fp);
ret = 1;
ret = true;
error:
if (outblob)

View File

@ -60,12 +60,12 @@ static void pwrite(Ldisc *ldisc, unsigned char c)
}
}
static int char_start(Ldisc *ldisc, unsigned char c)
static bool char_start(Ldisc *ldisc, unsigned char c)
{
if (in_utf(ldisc->term))
return (c < 0x80 || c >= 0xC0);
else
return 1;
return true;
}
static void bsb(Ldisc *ldisc, int n)
@ -84,7 +84,7 @@ Ldisc *ldisc_create(Conf *conf, Terminal *term, Backend *backend, Seat *seat)
ldisc->buf = NULL;
ldisc->buflen = 0;
ldisc->bufsiz = 0;
ldisc->quotenext = 0;
ldisc->quotenext = false;
ldisc->backend = backend;
ldisc->term = term;
@ -126,7 +126,7 @@ void ldisc_echoedit_update(Ldisc *ldisc)
seat_echoedit_update(ldisc->seat, ECHOING, EDITING);
}
void ldisc_send(Ldisc *ldisc, const void *vbuf, int len, int interactive)
void ldisc_send(Ldisc *ldisc, const void *vbuf, int len, bool interactive)
{
const char *buf = (const char *)vbuf;
int keyflag = 0;

View File

@ -16,10 +16,12 @@ struct Ldisc_tag {
/*
* Values cached out of conf.
*/
int telnet_keyboard, telnet_newline, protocol, localecho, localedit;
bool telnet_keyboard, telnet_newline;
int protocol, localecho, localedit;
char *buf;
int buflen, bufsiz, quotenext;
int buflen, bufsiz;
bool quotenext;
};
#endif /* PUTTY_LDISC_H */

View File

@ -13,7 +13,7 @@
#include "ldisc.h"
void lpage_send(Ldisc *ldisc,
int codepage, const char *buf, int len, int interactive)
int codepage, const char *buf, int len, bool interactive)
{
wchar_t *widebuffer = 0;
int widesize = 0;
@ -33,7 +33,7 @@ void lpage_send(Ldisc *ldisc,
sfree(widebuffer);
}
void luni_send(Ldisc *ldisc, const wchar_t *widebuf, int len, int interactive)
void luni_send(Ldisc *ldisc, const wchar_t *widebuf, int len, bool interactive)
{
int ratio = (in_utf(ldisc->term))?3:1;
char *linebuffer;

View File

@ -87,7 +87,7 @@ static void logfopen_callback(void *vctx, int mode)
char buf[256], *event;
struct tm tm;
const char *fmode;
int shout = false;
bool shout = false;
if (mode == 0) {
ctx->state = L_ERROR; /* disable logging */
@ -419,7 +419,7 @@ void log_free(LogContext *ctx)
void log_reconfig(LogContext *ctx, Conf *conf)
{
int reset_logging;
bool reset_logging;
if (!filename_equal(conf_get_filename(ctx->conf, CONF_logfilename),
conf_get_filename(conf, CONF_logfilename)) ||
@ -463,7 +463,7 @@ static Filename *xlatlognam(Filename *src, char *hostname, int port,
s = filename_to_str(src);
while (*s) {
int sanitise = false;
bool sanitise = false;
/* Let (bufp, len) be the string to append. */
bufp = buf; /* don't usually override this */
if (*s == '&') {

View File

@ -14,16 +14,16 @@
static void mainchan_free(Channel *chan);
static void mainchan_open_confirmation(Channel *chan);
static void mainchan_open_failure(Channel *chan, const char *errtext);
static int mainchan_send(Channel *chan, int is_stderr, const void *, int);
static int mainchan_send(Channel *chan, bool is_stderr, const void *, int);
static void mainchan_send_eof(Channel *chan);
static void mainchan_set_input_wanted(Channel *chan, int wanted);
static void mainchan_set_input_wanted(Channel *chan, bool wanted);
static char *mainchan_log_close_msg(Channel *chan);
static int mainchan_rcvd_exit_status(Channel *chan, int status);
static int mainchan_rcvd_exit_signal(
Channel *chan, ptrlen signame, int core_dumped, ptrlen msg);
static int mainchan_rcvd_exit_signal_numeric(
Channel *chan, int signum, int core_dumped, ptrlen msg);
static void mainchan_request_response(Channel *chan, int success);
static bool mainchan_rcvd_exit_status(Channel *chan, int status);
static bool mainchan_rcvd_exit_signal(
Channel *chan, ptrlen signame, bool core_dumped, ptrlen msg);
static bool mainchan_rcvd_exit_signal_numeric(
Channel *chan, int signum, bool core_dumped, ptrlen msg);
static void mainchan_request_response(Channel *chan, bool success);
static const struct ChannelVtable mainchan_channelvt = {
mainchan_free,
@ -61,11 +61,11 @@ struct mainchan {
ConnectionLayer *cl;
MainChanType type;
int is_simple;
bool is_simple;
int req_x11, req_agent, req_pty, req_cmd_primary, req_cmd_fallback;
bool req_x11, req_agent, req_pty, req_cmd_primary, req_cmd_fallback;
int n_req_env, n_env_replies, n_env_fails;
int eof_pending, eof_sent, got_pty, ready;
bool eof_pending, eof_sent, got_pty, ready;
int term_width, term_height;
@ -74,7 +74,7 @@ struct mainchan {
mainchan *mainchan_new(
PacketProtocolLayer *ppl, ConnectionLayer *cl, Conf *conf,
int term_width, int term_height, int is_simple, SshChannel **sc_out)
int term_width, int term_height, bool is_simple, SshChannel **sc_out)
{
mainchan *mc;
@ -139,7 +139,7 @@ static void mainchan_open_confirmation(Channel *chan)
char *key, *val, *cmd;
struct X11Display *x11disp;
struct X11FakeAuth *x11auth;
int retry_cmd_now = false;
bool retry_cmd_now = false;
if (conf_get_bool(mc->conf, CONF_x11_forward)) {;
char *x11_setup_err;
@ -212,7 +212,7 @@ static void mainchan_try_fallback_command(mainchan *mc)
mc->req_cmd_fallback = true;
}
static void mainchan_request_response(Channel *chan, int success)
static void mainchan_request_response(Channel *chan, bool success)
{
assert(chan->vt == &mainchan_channelvt);
mainchan *mc = container_of(chan, mainchan, chan);
@ -362,7 +362,7 @@ static void mainchan_open_failure(Channel *chan, const char *errtext)
queue_toplevel_callback(mainchan_open_failure_abort, ctx);
}
static int mainchan_send(Channel *chan, int is_stderr,
static int mainchan_send(Channel *chan, bool is_stderr,
const void *data, int length)
{
assert(chan->vt == &mainchan_channelvt);
@ -391,7 +391,7 @@ static void mainchan_send_eof(Channel *chan)
ssh_set_wants_user_input(mc->cl, false); /* now stop reading from stdin */
}
static void mainchan_set_input_wanted(Channel *chan, int wanted)
static void mainchan_set_input_wanted(Channel *chan, bool wanted)
{
assert(chan->vt == &mainchan_channelvt);
mainchan *mc = container_of(chan, mainchan, chan);
@ -410,7 +410,7 @@ static char *mainchan_log_close_msg(Channel *chan)
return dupstr("Main session channel closed");
}
static int mainchan_rcvd_exit_status(Channel *chan, int status)
static bool mainchan_rcvd_exit_status(Channel *chan, int status)
{
assert(chan->vt == &mainchan_channelvt);
mainchan *mc = container_of(chan, mainchan, chan);
@ -423,7 +423,7 @@ static int mainchan_rcvd_exit_status(Channel *chan, int status)
static void mainchan_log_exit_signal_common(
mainchan *mc, const char *sigdesc,
int core_dumped, ptrlen msg)
bool core_dumped, ptrlen msg)
{
PacketProtocolLayer *ppl = mc->ppl; /* for ppl_logevent */
@ -434,8 +434,8 @@ static void mainchan_log_exit_signal_common(
sigdesc, core_msg, msg_pre, PTRLEN_PRINTF(msg), msg_post));
}
static int mainchan_rcvd_exit_signal(
Channel *chan, ptrlen signame, int core_dumped, ptrlen msg)
static bool mainchan_rcvd_exit_signal(
Channel *chan, ptrlen signame, bool core_dumped, ptrlen msg)
{
assert(chan->vt == &mainchan_channelvt);
mainchan *mc = container_of(chan, mainchan, chan);
@ -469,8 +469,8 @@ static int mainchan_rcvd_exit_signal(
return true;
}
static int mainchan_rcvd_exit_signal_numeric(
Channel *chan, int signum, int core_dumped, ptrlen msg)
static bool mainchan_rcvd_exit_signal_numeric(
Channel *chan, int signum, bool core_dumped, ptrlen msg)
{
assert(chan->vt == &mainchan_channelvt);
mainchan *mc = container_of(chan, mainchan, chan);

View File

@ -26,7 +26,7 @@ void BinarySink_put_byte(BinarySink *bs, unsigned char val)
bs->write(bs, &val, 1);
}
void BinarySink_put_bool(BinarySink *bs, int val)
void BinarySink_put_bool(BinarySink *bs, bool val)
{
unsigned char cval = val ? 1 : 0;
bs->write(bs, &cval, 1);
@ -84,7 +84,7 @@ void BinarySink_put_asciz(BinarySink *bs, const char *str)
bs->write(bs, str, strlen(str) + 1);
}
int BinarySink_put_pstring(BinarySink *bs, const char *str)
bool BinarySink_put_pstring(BinarySink *bs, const char *str)
{
size_t len = strlen(str);
if (len > 255)
@ -96,7 +96,7 @@ int BinarySink_put_pstring(BinarySink *bs, const char *str)
/* ---------------------------------------------------------------------- */
static int BinarySource_data_avail(BinarySource *src, size_t wanted)
static bool BinarySource_data_avail(BinarySource *src, size_t wanted)
{
if (src->err)
return false;
@ -134,12 +134,12 @@ unsigned char BinarySource_get_byte(BinarySource *src)
return *ucp;
}
int BinarySource_get_bool(BinarySource *src)
bool BinarySource_get_bool(BinarySource *src)
{
const unsigned char *ucp;
if (!avail(1))
return 0;
return false;
ucp = consume(1);
return *ucp != 0;

View File

@ -142,7 +142,7 @@ struct BinarySink {
void BinarySink_put_data(BinarySink *, const void *data, size_t len);
void BinarySink_put_padding(BinarySink *, size_t len, unsigned char padbyte);
void BinarySink_put_byte(BinarySink *, unsigned char);
void BinarySink_put_bool(BinarySink *, int);
void BinarySink_put_bool(BinarySink *, bool);
void BinarySink_put_uint16(BinarySink *, unsigned long);
void BinarySink_put_uint32(BinarySink *, unsigned long);
void BinarySink_put_uint64(BinarySink *, uint64_t);
@ -152,7 +152,7 @@ void BinarySink_put_stringz(BinarySink *, const char *str);
struct strbuf;
void BinarySink_put_stringsb(BinarySink *, struct strbuf *);
void BinarySink_put_asciz(BinarySink *, const char *str);
int BinarySink_put_pstring(BinarySink *, const char *str);
bool BinarySink_put_pstring(BinarySink *, const char *str);
/* ---------------------------------------------------------------------- */
@ -274,7 +274,7 @@ struct BinarySource {
ptrlen BinarySource_get_data(BinarySource *, size_t);
unsigned char BinarySource_get_byte(BinarySource *);
int BinarySource_get_bool(BinarySource *);
bool BinarySource_get_bool(BinarySource *);
unsigned BinarySource_get_uint16(BinarySource *);
unsigned long BinarySource_get_uint32(BinarySource *);
uint64_t BinarySource_get_uint64(BinarySource *);

View File

@ -1086,9 +1086,10 @@ int getPreviousLevel(unsigned char* level, int from)
*/
int do_shape(bidi_char *line, bidi_char *to, int count)
{
int i, tempShape, ligFlag;
int i, tempShape;
bool ligFlag = false;
for (ligFlag=i=0; i<count; i++) {
for (i=0; i<count; i++) {
to[i] = line[i];
tempShape = STYPE(line[i].wc);
switch (tempShape) {
@ -1113,28 +1114,28 @@ int do_shape(bidi_char *line, bidi_char *to, int count)
if (line[i].wc == 0x644) {
if (i > 0) switch (line[i-1].wc) {
case 0x622:
ligFlag = 1;
ligFlag = true;
if ((tempShape == SL) || (tempShape == SD) || (tempShape == SC))
to[i].wc = 0xFEF6;
else
to[i].wc = 0xFEF5;
break;
case 0x623:
ligFlag = 1;
ligFlag = true;
if ((tempShape == SL) || (tempShape == SD) || (tempShape == SC))
to[i].wc = 0xFEF8;
else
to[i].wc = 0xFEF7;
break;
case 0x625:
ligFlag = 1;
ligFlag = true;
if ((tempShape == SL) || (tempShape == SD) || (tempShape == SC))
to[i].wc = 0xFEFA;
else
to[i].wc = 0xFEF9;
break;
case 0x627:
ligFlag = 1;
ligFlag = true;
if ((tempShape == SL) || (tempShape == SD) || (tempShape == SC))
to[i].wc = 0xFEFC;
else
@ -1143,7 +1144,7 @@ int do_shape(bidi_char *line, bidi_char *to, int count)
}
if (ligFlag) {
to[i-1].wc = 0x20;
ligFlag = 0;
ligFlag = false;
break;
}
}
@ -1186,18 +1187,19 @@ int do_bidi(bidi_char *line, int count)
unsigned char currentEmbedding;
unsigned char currentOverride;
unsigned char tempType;
int i, j, yes, bover;
int i, j;
bool yes, bover;
/* Check the presence of R or AL types as optimization */
yes = 0;
yes = false;
for (i=0; i<count; i++) {
int type = getType(line[i].wc);
if (type == R || type == AL) {
yes = 1;
yes = true;
break;
}
}
if (yes == 0)
if (!yes)
return L;
/* Initialize types, levels */
@ -1250,7 +1252,7 @@ int do_bidi(bidi_char *line, int count)
* terminated at the end of each paragraph. Paragraph separators are not
* included in the embedding. (Useless here) NOT IMPLEMENTED
*/
bover = 0;
bover = false;
for (i=0; i<count; i++) {
tempType = getType(line[i].wc);
switch (tempType) {
@ -1269,13 +1271,13 @@ int do_bidi(bidi_char *line, int count)
case RLO:
currentEmbedding = levels[i] = leastGreaterOdd(currentEmbedding);
tempType = currentOverride = R;
bover = 1;
bover = true;
break;
case LRO:
currentEmbedding = levels[i] = leastGreaterEven(currentEmbedding);
tempType = currentOverride = L;
bover = 1;
bover = true;
break;
case PDF:

36
misc.c
View File

@ -97,7 +97,7 @@ char ctrlparse(char *s, char **next)
* various standard string.h functions.
*/
static const char *host_strchr_internal(const char *s, const char *set,
int first)
bool first)
{
int brackets = 0;
const char *ret = NULL;
@ -240,7 +240,7 @@ prompts_t *new_prompts(void)
p->name_reqd = p->instr_reqd = false;
return p;
}
void add_prompt(prompts_t *p, char *promptstr, int echo)
void add_prompt(prompts_t *p, char *promptstr, bool echo)
{
prompt_t *pr = snew(prompt_t);
pr->prompt = promptstr;
@ -826,7 +826,7 @@ void bufchain_fetch_consume(bufchain *ch, void *data, int len)
bufchain_consume(ch, len);
}
int bufchain_try_fetch_consume(bufchain *ch, void *data, int len)
bool bufchain_try_fetch_consume(bufchain *ch, void *data, int len)
{
if (ch->buffersize >= len) {
bufchain_fetch_consume(ch, data, len);
@ -1055,7 +1055,7 @@ void debug_memdump(const void *buf, int len, int L)
* Determine whether or not a Conf represents a session which can
* sensibly be launched right now.
*/
int conf_launchable(Conf *conf)
bool conf_launchable(Conf *conf)
{
if (conf_get_int(conf, CONF_protocol) == PROT_SERIAL)
return conf_get_str(conf, CONF_serline)[0] != 0;
@ -1119,7 +1119,7 @@ void smemclr(void *b, size_t n) {
* original version), suitable for putting into the Conf. If not
* valid, we return false.
*/
int validate_manual_hostkey(char *key)
bool validate_manual_hostkey(char *key)
{
char *p, *q, *r, *s;
@ -1208,7 +1208,7 @@ int validate_manual_hostkey(char *key)
return false;
}
int smemeq(const void *av, const void *bv, size_t len)
bool smemeq(const void *av, const void *bv, size_t len)
{
const unsigned char *a = (const unsigned char *)av;
const unsigned char *b = (const unsigned char *)bv;
@ -1253,18 +1253,18 @@ ptrlen ptrlen_from_strbuf(strbuf *sb)
return make_ptrlen(sb->u, sb->len);
}
int ptrlen_eq_string(ptrlen pl, const char *str)
bool ptrlen_eq_string(ptrlen pl, const char *str)
{
size_t len = strlen(str);
return (pl.len == len && !memcmp(pl.ptr, str, len));
}
int ptrlen_eq_ptrlen(ptrlen pl1, ptrlen pl2)
bool ptrlen_eq_ptrlen(ptrlen pl1, ptrlen pl2)
{
return (pl1.len == pl2.len && !memcmp(pl1.ptr, pl2.ptr, pl1.len));
}
int ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail)
bool ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail)
{
if (whole.len >= prefix.len &&
!memcmp(whole.ptr, prefix.ptr, prefix.len)) {
@ -1285,12 +1285,12 @@ char *mkstr(ptrlen pl)
return p;
}
int strstartswith(const char *s, const char *t)
bool strstartswith(const char *s, const char *t)
{
return !memcmp(s, t, strlen(t));
}
int strendswith(const char *s, const char *t)
bool strendswith(const char *s, const char *t)
{
size_t slen = strlen(s), tlen = strlen(t);
return slen >= tlen && !strcmp(s + (slen - tlen), t);
@ -1390,8 +1390,8 @@ char *buildinfo(const char *newline)
}
int nullseat_output(
Seat *seat, int is_stderr, const void *data, int len) { return 0; }
int nullseat_eof(Seat *seat) { return true; }
Seat *seat, bool is_stderr, const void *data, int len) { return 0; }
bool nullseat_eof(Seat *seat) { return true; }
int nullseat_get_userpass_input(
Seat *seat, prompts_t *p, bufchain *input) { return 0; }
void nullseat_notify_remote_exit(Seat *seat) {}
@ -1409,12 +1409,12 @@ int nullseat_confirm_weak_crypto_primitive(
int nullseat_confirm_weak_cached_hostkey(
Seat *seat, const char *algname, const char *betteralgs,
void (*callback)(void *ctx, int result), void *ctx) { return 0; }
int nullseat_is_never_utf8(Seat *seat) { return false; }
int nullseat_is_always_utf8(Seat *seat) { return true; }
void nullseat_echoedit_update(Seat *seat, int echoing, int editing) {}
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) {}
const char *nullseat_get_x_display(Seat *seat) { return NULL; }
int nullseat_get_windowid(Seat *seat, long *id_out) { return false; }
int nullseat_get_window_pixel_size(
bool nullseat_get_windowid(Seat *seat, long *id_out) { return false; }
bool nullseat_get_window_pixel_size(
Seat *seat, int *width, int *height) { return false; }
void sk_free_peer_info(SocketPeerInfo *pi)

26
misc.h
View File

@ -61,8 +61,8 @@ int toint(unsigned);
char *fgetline(FILE *fp);
char *chomp(char *str);
int strstartswith(const char *s, const char *t);
int strendswith(const char *s, const char *t);
bool strstartswith(const char *s, const char *t);
bool strendswith(const char *s, const char *t);
void base64_encode_atom(const unsigned char *data, int n, char *out);
int base64_decode_atom(const char *atom, unsigned char *out);
@ -82,11 +82,11 @@ void bufchain_prefix(bufchain *ch, void **data, int *len);
void bufchain_consume(bufchain *ch, int len);
void bufchain_fetch(bufchain *ch, void *data, int len);
void bufchain_fetch_consume(bufchain *ch, void *data, int len);
int bufchain_try_fetch_consume(bufchain *ch, void *data, int len);
bool bufchain_try_fetch_consume(bufchain *ch, void *data, int len);
void sanitise_term_data(bufchain *out, const void *vdata, int len);
int validate_manual_hostkey(char *key);
bool validate_manual_hostkey(char *key);
struct tm ltime(void);
@ -99,9 +99,9 @@ int nullstrcmp(const char *a, const char *b);
ptrlen make_ptrlen(const void *ptr, size_t len);
ptrlen ptrlen_from_asciz(const char *str);
ptrlen ptrlen_from_strbuf(strbuf *sb);
int ptrlen_eq_string(ptrlen pl, const char *str);
int ptrlen_eq_ptrlen(ptrlen pl1, ptrlen pl2);
int ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail);
bool ptrlen_eq_string(ptrlen pl, const char *str);
bool ptrlen_eq_ptrlen(ptrlen pl1, ptrlen pl2);
bool ptrlen_startswith(ptrlen whole, ptrlen prefix, ptrlen *tail);
char *mkstr(ptrlen pl);
int string_length_for_printf(size_t);
/* Derive two printf arguments from a ptrlen, suitable for "%.*s" */
@ -124,9 +124,9 @@ void smemclr(void *b, size_t len);
/* Compare two fixed-length chunks of memory for equality, without
* data-dependent control flow (so an attacker with a very accurate
* stopwatch can't try to guess where the first mismatching byte was).
* Returns 0 for mismatch or 1 for equality (unlike memcmp), hinted at
* by the 'eq' in the name. */
int smemeq(const void *av, const void *bv, size_t len);
* Returns false for mismatch or true for equality (unlike memcmp),
* hinted at by the 'eq' in the name. */
bool smemeq(const void *av, const void *bv, size_t len);
char *buildinfo(const char *newline);
@ -145,10 +145,10 @@ char *buildinfo(const char *newline);
#ifdef DEBUG
void debug_printf(const char *fmt, ...);
void debug_memdump(const void *buf, int len, int L);
void debug_memdump(const void *buf, int len, bool L);
#define debug(x) (debug_printf x)
#define dmemdump(buf,len) debug_memdump (buf, len, 0);
#define dmemdumpl(buf,len) debug_memdump (buf, len, 1);
#define dmemdump(buf,len) debug_memdump (buf, len, false);
#define dmemdumpl(buf,len) debug_memdump (buf, len, true);
#else
#define debug(x)
#define dmemdump(buf,len)

View File

@ -32,7 +32,7 @@ struct SocketVtable {
int (*write_oob) (Socket *s, const void *data, int len);
void (*write_eof) (Socket *s);
void (*flush) (Socket *s);
void (*set_frozen) (Socket *s, int is_frozen);
void (*set_frozen) (Socket *s, bool is_frozen);
/* ignored by tcp, but vital for ssl */
const char *(*socket_error) (Socket *s);
SocketPeerInfo *(*peer_info) (Socket *s);
@ -66,7 +66,7 @@ struct PlugVtable {
* indicate this.
*/
void (*closing)
(Plug *p, const char *error_msg, int error_code, int calling_back);
(Plug *p, const char *error_msg, int error_code, bool calling_back);
/* error_msg is NULL iff it is not an error (ie it closed normally) */
/* calling_back != 0 iff there is a Plug function */
/* currently running (would cure the fixme in try_send()) */
@ -100,22 +100,22 @@ struct PlugVtable {
/* NB, control of 'addr' is passed via new_connection, which takes
* responsibility for freeing it */
Socket *new_connection(SockAddr *addr, const char *hostname,
int port, int privport,
int oobinline, int nodelay, int keepalive,
int port, bool privport,
bool oobinline, bool nodelay, bool keepalive,
Plug *plug, Conf *conf);
Socket *new_listener(const char *srcaddr, int port, Plug *plug,
int local_host_only, Conf *conf, int addressfamily);
bool local_host_only, Conf *conf, int addressfamily);
SockAddr *name_lookup(const char *host, int port, char **canonicalname,
Conf *conf, int addressfamily, LogContext *logctx,
const char *lookup_reason_for_logging);
int proxy_for_destination (SockAddr *addr, const char *hostname, int port,
Conf *conf);
bool proxy_for_destination (SockAddr *addr, const char *hostname, int port,
Conf *conf);
/* platform-dependent callback from new_connection() */
/* (same caveat about addr as new_connection()) */
Socket *platform_new_connection(SockAddr *addr, const char *hostname,
int port, int privport,
int oobinline, int nodelay, int keepalive,
int port, bool privport,
bool oobinline, bool nodelay, bool keepalive,
Plug *plug, Conf *conf);
/* socket functions */
@ -126,10 +126,10 @@ void sk_cleanup(void); /* called just before program exit */
SockAddr *sk_namelookup(const char *host, char **canonicalname, int address_family);
SockAddr *sk_nonamelookup(const char *host);
void sk_getaddr(SockAddr *addr, char *buf, int buflen);
int sk_addr_needs_port(SockAddr *addr);
int sk_hostname_is_local(const char *name);
int sk_address_is_local(SockAddr *addr);
int sk_address_is_special_local(SockAddr *addr);
bool sk_addr_needs_port(SockAddr *addr);
bool sk_hostname_is_local(const char *name);
bool sk_address_is_local(SockAddr *addr);
bool sk_address_is_special_local(SockAddr *addr);
int sk_addrtype(SockAddr *addr);
void sk_addrcopy(SockAddr *addr, char *buf);
void sk_addr_free(SockAddr *addr);
@ -142,11 +142,11 @@ SockAddr *sk_addr_dup(SockAddr *addr);
/* NB, control of 'addr' is passed via sk_new, which takes responsibility
* for freeing it, as for new_connection() */
Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline,
int nodelay, int keepalive, Plug *p);
Socket *sk_new(SockAddr *addr, int port, bool privport, bool oobinline,
bool nodelay, bool keepalive, Plug *p);
Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
int local_host_only, int address_family);
bool local_host_only, int address_family);
#define sk_plug(s,p) (((s)->vt->plug) (s, p))
#define sk_close(s) (((s)->vt->close) (s))
@ -278,7 +278,7 @@ extern Plug *const nullplug;
void backend_socket_log(Seat *seat, LogContext *logctx,
int type, SockAddr *addr, int port,
const char *error_msg, int error_code, Conf *conf,
int session_started);
bool session_started);
void log_proxy_stderr(Plug *plug, bufchain *buf, const void *vdata, int len);
#endif

View File

@ -13,7 +13,7 @@ static void nullplug_socket_log(Plug *plug, int type, SockAddr *addr, int port,
}
static void nullplug_closing(Plug *plug, const char *error_msg, int error_code,
int calling_back)
bool calling_back)
{
}

View File

@ -27,7 +27,7 @@ int random_byte(void)
return 0; /* unreachable, but placate optimiser */
}
static int pageant_local = false;
static bool pageant_local = false;
/*
* rsakeys stores SSH-1 RSA keys. ssh2keys stores all SSH-2 keys.
@ -652,17 +652,17 @@ int pageant_count_ssh2_keys(void)
return count234(ssh2keys);
}
int pageant_add_ssh1_key(struct RSAKey *rkey)
bool pageant_add_ssh1_key(struct RSAKey *rkey)
{
return add234(rsakeys, rkey) == rkey;
}
int pageant_add_ssh2_key(struct ssh2_userkey *skey)
bool pageant_add_ssh2_key(struct ssh2_userkey *skey)
{
return add234(ssh2keys, skey) == skey;
}
int pageant_delete_ssh1_key(struct RSAKey *rkey)
bool pageant_delete_ssh1_key(struct RSAKey *rkey)
{
struct RSAKey *deleted = del234(rsakeys, rkey);
if (!deleted)
@ -671,7 +671,7 @@ int pageant_delete_ssh1_key(struct RSAKey *rkey)
return true;
}
int pageant_delete_ssh2_key(struct ssh2_userkey *skey)
bool pageant_delete_ssh2_key(struct ssh2_userkey *skey)
{
struct ssh2_userkey *deleted = del234(ssh2keys, skey);
if (!deleted)
@ -704,14 +704,14 @@ struct pageant_conn_state {
pageant_logfn_t logfn;
unsigned char lenbuf[4], pktbuf[AGENT_MAX_MSGLEN];
unsigned len, got;
int real_packet;
bool real_packet;
int crLine; /* for coroutine in pageant_conn_receive */
Plug plug;
};
static void pageant_conn_closing(Plug *plug, const char *error_msg,
int error_code, int calling_back)
int error_code, bool calling_back)
{
struct pageant_conn_state *pc = container_of(
plug, struct pageant_conn_state, plug);
@ -805,7 +805,7 @@ struct pageant_listen_state {
};
static void pageant_listen_closing(Plug *plug, const char *error_msg,
int error_code, int calling_back)
int error_code, bool calling_back)
{
struct pageant_listen_state *pl = container_of(
plug, struct pageant_listen_state, plug);
@ -842,7 +842,7 @@ static int pageant_listen_accepting(Plug *plug,
if ((err = sk_socket_error(pc->connsock)) != NULL) {
sk_close(pc->connsock);
sfree(pc);
return true;
return 1;
}
sk_set_frozen(pc->connsock, 0);
@ -998,7 +998,7 @@ int pageant_add_keyfile(Filename *filename, const char *passphrase,
{
struct RSAKey *rkey = NULL;
struct ssh2_userkey *skey = NULL;
int needs_pass;
bool needs_pass;
int ret;
int attempts;
char *comment;
@ -1432,7 +1432,8 @@ int pageant_delete_all_keys(char **retstr)
{
strbuf *request;
unsigned char *response;
int resplen, success;
int resplen;
bool success;
void *vresponse;
request = strbuf_new_for_agent_query();

View File

@ -60,10 +60,10 @@ struct RSAKey *pageant_nth_ssh1_key(int i);
struct ssh2_userkey *pageant_nth_ssh2_key(int i);
int pageant_count_ssh1_keys(void);
int pageant_count_ssh2_keys(void);
int pageant_add_ssh1_key(struct RSAKey *rkey);
int pageant_add_ssh2_key(struct ssh2_userkey *skey);
int pageant_delete_ssh1_key(struct RSAKey *rkey);
int pageant_delete_ssh2_key(struct ssh2_userkey *skey);
bool pageant_add_ssh1_key(struct RSAKey *rkey);
bool pageant_add_ssh2_key(struct ssh2_userkey *skey);
bool pageant_delete_ssh1_key(struct RSAKey *rkey);
bool pageant_delete_ssh2_key(struct ssh2_userkey *skey);
/*
* This callback must be provided by the Pageant front end code.

View File

@ -7,7 +7,7 @@
struct Pinger {
int interval;
int pending;
bool pending;
unsigned long when_set, next;
Backend *backend;
};

View File

@ -27,8 +27,8 @@ typedef struct PortForwarding {
ConnectionLayer *cl; /* the connection layer itself */
/* Note that ssh need not be filled in if c is non-NULL */
Socket *s;
int input_wanted;
int ready;
bool input_wanted;
bool ready;
SocksState socks_state;
/*
* `hostname' and `port' are the real hostname and port, once
@ -51,7 +51,7 @@ typedef struct PortForwarding {
struct PortListener {
ConnectionLayer *cl;
Socket *s;
int is_dynamic;
bool is_dynamic;
/*
* `hostname' and `port' are the real hostname and port, for
* ordinary forwardings.
@ -110,7 +110,7 @@ static void pfl_log(Plug *plug, int type, SockAddr *addr, int port,
static void pfd_close(struct PortForwarding *pf);
static void pfd_closing(Plug *plug, const char *error_msg, int error_code,
int calling_back)
bool calling_back)
{
struct PortForwarding *pf =
container_of(plug, struct PortForwarding, plug);
@ -143,7 +143,7 @@ static void pfd_closing(Plug *plug, const char *error_msg, int error_code,
static void pfl_terminate(struct PortListener *pl);
static void pfl_closing(Plug *plug, const char *error_msg, int error_code,
int calling_back)
bool calling_back)
{
struct PortListener *pl = (struct PortListener *) plug;
pfl_terminate(pl);
@ -254,7 +254,7 @@ static void pfd_receive(Plug *plug, int urgent, char *data, int len)
return;
if (socks_version == 4 && message_type == 1) {
/* CONNECT message */
int name_based = false;
bool name_based = false;
port = get_uint16(src);
ipv4 = get_uint32(src);
@ -437,9 +437,9 @@ static const PlugVtable PortForwarding_plugvt = {
static void pfd_chan_free(Channel *chan);
static void pfd_open_confirmation(Channel *chan);
static void pfd_open_failure(Channel *chan, const char *errtext);
static int pfd_send(Channel *chan, int is_stderr, const void *data, int len);
static int pfd_send(Channel *chan, bool is_stderr, const void *data, int len);
static void pfd_send_eof(Channel *chan);
static void pfd_set_input_wanted(Channel *chan, int wanted);
static void pfd_set_input_wanted(Channel *chan, bool wanted);
static char *pfd_log_close_msg(Channel *chan);
static const struct ChannelVtable PortForwarding_channelvt = {
@ -481,7 +481,7 @@ Channel *portfwd_raw_new(ConnectionLayer *cl, Plug **plug)
pf->cl = cl;
pf->input_wanted = true;
pf->ready = 0;
pf->ready = false;
pf->socks_state = SOCKS_NONE;
pf->hostname = NULL;
@ -526,7 +526,7 @@ static int pfl_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
s = constructor(ctx, plug);
if ((err = sk_socket_error(s)) != NULL) {
portfwd_raw_free(chan);
return true;
return 1;
}
pf = container_of(chan, struct PortForwarding, chan);
@ -626,7 +626,7 @@ static void pfl_terminate(struct PortListener *pl)
free_portlistener_state(pl);
}
static void pfd_set_input_wanted(Channel *chan, int wanted)
static void pfd_set_input_wanted(Channel *chan, bool wanted)
{
assert(chan->vt == &PortForwarding_channelvt);
PortForwarding *pf = container_of(chan, PortForwarding, chan);
@ -644,7 +644,7 @@ static void pfd_chan_free(Channel *chan)
/*
* Called to send data down the raw connection.
*/
static int pfd_send(Channel *chan, int is_stderr, const void *data, int len)
static int pfd_send(Channel *chan, bool is_stderr, const void *data, int len)
{
assert(chan->vt == &PortForwarding_channelvt);
PortForwarding *pf = container_of(chan, PortForwarding, chan);
@ -663,7 +663,7 @@ static void pfd_open_confirmation(Channel *chan)
assert(chan->vt == &PortForwarding_channelvt);
PortForwarding *pf = container_of(chan, PortForwarding, chan);
pf->ready = 1;
pf->ready = true;
sk_set_frozen(pf->s, 0);
sk_write(pf->s, NULL, 0);
if (pf->socksbuf) {
@ -1050,8 +1050,8 @@ void portfwdmgr_config(PortFwdManager *mgr, Conf *conf)
}
}
int portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port,
const char *keyhost, int keyport, Conf *conf)
bool portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port,
const char *keyhost, int keyport, Conf *conf)
{
PortFwdRecord *pfr;
@ -1091,7 +1091,7 @@ int portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port,
return true;
}
int portfwdmgr_unlisten(PortFwdManager *mgr, const char *host, int port)
bool portfwdmgr_unlisten(PortFwdManager *mgr, const char *host, int port)
{
PortFwdRecord pfr_key;
@ -1153,13 +1153,13 @@ char *portfwdmgr_connect(PortFwdManager *mgr, Channel **chan_ret,
pf->chan.initial_fixed_window_size = 0;
pf->chan.vt = &PortForwarding_channelvt;
pf->input_wanted = true;
pf->ready = 1;
pf->ready = true;
pf->c = c;
pf->cl = mgr->cl;
pf->socks_state = SOCKS_NONE;
pf->s = new_connection(addr, dummy_realhost, port,
0, 1, 0, 0, &pf->plug, mgr->conf);
false, true, false, false, &pf->plug, mgr->conf);
sfree(dummy_realhost);
if ((err = sk_socket_error(pf->s)) != NULL) {
char *err_ret = dupstr(err);

52
proxy.c
View File

@ -33,7 +33,7 @@ void proxy_activate (ProxySocket *p)
/* we want to ignore new receive events until we have sent
* all of our buffered receive data.
*/
sk_set_frozen(p->sub_socket, 1);
sk_set_frozen(p->sub_socket, true);
/* how many bytes of output have we buffered? */
output_before = bufchain_size(&p->pending_oob_output_data) +
@ -124,7 +124,7 @@ static void sk_proxy_write_eof (Socket *s)
ProxySocket *ps = container_of(s, ProxySocket, sock);
if (ps->state != PROXY_STATE_ACTIVE) {
ps->pending_eof = 1;
ps->pending_eof = true;
return;
}
sk_write_eof(ps->sub_socket);
@ -135,13 +135,13 @@ static void sk_proxy_flush (Socket *s)
ProxySocket *ps = container_of(s, ProxySocket, sock);
if (ps->state != PROXY_STATE_ACTIVE) {
ps->pending_flush = 1;
ps->pending_flush = true;
return;
}
sk_flush(ps->sub_socket);
}
static void sk_proxy_set_frozen (Socket *s, int is_frozen)
static void sk_proxy_set_frozen (Socket *s, bool is_frozen)
{
ProxySocket *ps = container_of(s, ProxySocket, sock);
@ -200,7 +200,7 @@ static void plug_proxy_log(Plug *plug, int type, SockAddr *addr, int port,
}
static void plug_proxy_closing (Plug *p, const char *error_msg,
int error_code, int calling_back)
int error_code, bool calling_back)
{
ProxySocket *ps = container_of(p, ProxySocket, plugimpl);
@ -224,7 +224,7 @@ static void plug_proxy_receive (Plug *p, int urgent, char *data, int len)
* process, hopefully it won't affect the protocol above us
*/
bufchain_add(&ps->pending_input_data, data, len);
ps->receive_urgent = urgent;
ps->receive_urgent = (urgent != 0);
ps->receive_data = data;
ps->receive_len = len;
ps->negotiate(ps, PROXY_CHANGE_RECEIVE);
@ -262,7 +262,7 @@ static int plug_proxy_accepting(Plug *p,
* This function can accept a NULL pointer as `addr', in which case
* it will only check the host name.
*/
int proxy_for_destination (SockAddr *addr, const char *hostname,
bool proxy_for_destination (SockAddr *addr, const char *hostname,
int port, Conf *conf)
{
int s = 0, e = 0;
@ -277,7 +277,7 @@ int proxy_for_destination (SockAddr *addr, const char *hostname,
* them.
*/
if (addr && sk_address_is_special_local(addr))
return 0; /* do not proxy */
return false; /* do not proxy */
/*
* Check the host name and IP against the hard-coded
@ -286,7 +286,7 @@ int proxy_for_destination (SockAddr *addr, const char *hostname,
if (!conf_get_bool(conf, CONF_even_proxy_localhost) &&
(sk_hostname_is_local(hostname) ||
(addr && sk_address_is_local(addr))))
return 0; /* do not proxy */
return false; /* do not proxy */
/* we want a string representation of the IP address for comparisons */
if (addr) {
@ -324,25 +324,27 @@ int proxy_for_destination (SockAddr *addr, const char *hostname,
if ((addr && strnicmp(hostip + hostip_len - (e - s - 1),
exclude_list + s + 1, e - s - 1) == 0) ||
strnicmp(hostname + hostname_len - (e - s - 1),
exclude_list + s + 1, e - s - 1) == 0)
return 0; /* IP/hostname range excluded. do not use proxy. */
exclude_list + s + 1, e - s - 1) == 0) {
/* IP/hostname range excluded. do not use proxy. */
return false;
}
} else if (exclude_list[e-1] == '*') {
/* wildcard at end of entry */
if ((addr && strnicmp(hostip, exclude_list + s, e - s - 1) == 0) ||
strnicmp(hostname, exclude_list + s, e - s - 1) == 0)
return 0; /* IP/hostname range excluded. do not use proxy. */
strnicmp(hostname, exclude_list + s, e - s - 1) == 0) {
/* IP/hostname range excluded. do not use proxy. */
return false;
}
} else {
/* no wildcard at either end, so let's try an absolute
* match (ie. a specific IP)
*/
if (addr && strnicmp(hostip, exclude_list + s, e - s) == 0)
return 0; /* IP/hostname excluded. do not use proxy. */
return false; /* IP/hostname excluded. do not use proxy. */
if (strnicmp(hostname, exclude_list + s, e - s) == 0)
return 0; /* IP/hostname excluded. do not use proxy. */
return false; /* IP/hostname excluded. do not use proxy. */
}
s = e;
@ -354,7 +356,7 @@ int proxy_for_destination (SockAddr *addr, const char *hostname,
}
/* no matches in the exclude list, so use the proxy */
return 1;
return true;
}
static char *dns_log_msg(const char *host, int addressfamily,
@ -410,8 +412,8 @@ static const struct PlugVtable ProxySocket_plugvt = {
};
Socket *new_connection(SockAddr *addr, const char *hostname,
int port, int privport,
int oobinline, int nodelay, int keepalive,
int port, bool privport,
bool oobinline, bool nodelay, bool keepalive,
Plug *plug, Conf *conf)
{
if (conf_get_int(conf, CONF_proxy_type) != PROXY_NONE &&
@ -439,9 +441,9 @@ Socket *new_connection(SockAddr *addr, const char *hostname,
ret->remote_port = port;
ret->error = NULL;
ret->pending_flush = 0;
ret->pending_eof = 0;
ret->freeze = 0;
ret->pending_flush = false;
ret->pending_eof = false;
ret->freeze = false;
bufchain_init(&ret->pending_input_data);
bufchain_init(&ret->pending_output_data);
@ -530,7 +532,7 @@ Socket *new_connection(SockAddr *addr, const char *hostname,
}
Socket *new_listener(const char *srcaddr, int port, Plug *plug,
int local_host_only, Conf *conf, int addressfamily)
bool local_host_only, Conf *conf, int addressfamily)
{
/* TODO: SOCKS (and potentially others) support inbound
* TODO: connections via the proxy. support them.
@ -778,7 +780,7 @@ int proxy_socks4_negotiate (ProxySocket *p, int change)
strbuf *command = strbuf_new();
char hostname[512];
int write_hostname = false;
bool write_hostname = false;
put_byte(command, 4); /* SOCKS version 4 */
put_byte(command, 1); /* CONNECT command */

16
proxy.h
View File

@ -25,9 +25,9 @@ struct ProxySocket {
bufchain pending_output_data;
bufchain pending_oob_output_data;
int pending_flush;
bool pending_flush;
bufchain pending_input_data;
int pending_eof;
bool pending_eof;
#define PROXY_STATE_NEW -1
#define PROXY_STATE_ACTIVE 0
@ -37,10 +37,10 @@ struct ProxySocket {
* of the initialization/setup/negotiation with the
* proxy server.
*/
int freeze; /* should we freeze the underlying socket when
* we are done with the proxy negotiation? this
* simply caches the value of sk_set_frozen calls.
*/
bool freeze; /* should we freeze the underlying socket when
* we are done with the proxy negotiation? this
* simply caches the value of sk_set_frozen calls.
*/
#define PROXY_CHANGE_NEW -1
#define PROXY_CHANGE_CLOSING 0
@ -64,10 +64,10 @@ struct ProxySocket {
/* closing */
const char *closing_error_msg;
int closing_error_code;
int closing_calling_back;
bool closing_calling_back;
/* receive */
int receive_urgent;
bool receive_urgent;
char *receive_data;
int receive_len;

191
pscp.c
View File

@ -26,25 +26,25 @@
#include "sftp.h"
#include "storage.h"
static int list = 0;
static int verbose = 0;
static int recursive = 0;
static int preserve = 0;
static int targetshouldbedirectory = 0;
static int statistics = 1;
static bool list = false;
static bool verbose = false;
static bool recursive = false;
static bool preserve = false;
static bool targetshouldbedirectory = false;
static bool statistics = true;
static int prev_stats_len = 0;
static int scp_unsafe_mode = 0;
static bool scp_unsafe_mode = false;
static int errs = 0;
static int try_scp = 1;
static int try_sftp = 1;
static int main_cmd_is_sftp = 0;
static int fallback_cmd_is_sftp = 0;
static int using_sftp = 0;
static int uploading = 0;
static bool try_scp = true;
static bool try_sftp = true;
static bool main_cmd_is_sftp = false;
static bool fallback_cmd_is_sftp = false;
static bool using_sftp = false;
static bool uploading = false;
static Backend *backend;
static Conf *conf;
int sent_eof = false;
bool sent_eof = false;
static void source(const char *src);
static void rsource(const char *src);
@ -60,8 +60,8 @@ const char *const appname = "PSCP";
void ldisc_echoedit_update(Ldisc *ldisc) { }
static int pscp_output(Seat *, int is_stderr, const void *, int);
static int pscp_eof(Seat *);
static int pscp_output(Seat *, bool is_stderr, const void *, int);
static bool pscp_eof(Seat *);
static const SeatVtable pscp_seat_vt = {
pscp_output,
@ -148,7 +148,7 @@ static unsigned char *outptr; /* where to put the data */
static unsigned outlen; /* how much data required */
static unsigned char *pending = NULL; /* any spare data */
static unsigned pendlen = 0, pendsize = 0; /* length and phys. size of buffer */
static int pscp_output(Seat *seat, int is_stderr,
static int pscp_output(Seat *seat, bool is_stderr,
const void *data, int datalen)
{
unsigned char *p = (unsigned char *) data;
@ -187,7 +187,7 @@ static int pscp_output(Seat *seat, int is_stderr,
return 0;
}
static int pscp_eof(Seat *seat)
static bool pscp_eof(Seat *seat)
{
/*
* We usually expect to be the party deciding when to close the
@ -201,7 +201,7 @@ static int pscp_eof(Seat *seat)
}
return false;
}
static int ssh_scp_recv(void *buf, int len)
static bool ssh_scp_recv(void *buf, int len)
{
outptr = buf;
outlen = len;
@ -225,15 +225,15 @@ static int ssh_scp_recv(void *buf, int len)
pending = NULL;
}
if (outlen == 0)
return len;
return true;
}
while (outlen > 0) {
if (backend_exitcode(backend) >= 0 || ssh_sftp_loop_iteration() < 0)
return 0; /* doom */
return false; /* doom */
}
return len;
return true;
}
/*
@ -455,19 +455,19 @@ static void do_cmd(char *host, char *user, char *cmd)
conf_set_str(conf, CONF_remote_cmd2, "");
if (try_sftp) {
/* First choice is SFTP subsystem. */
main_cmd_is_sftp = 1;
main_cmd_is_sftp = true;
conf_set_str(conf, CONF_remote_cmd, "sftp");
conf_set_bool(conf, CONF_ssh_subsys, true);
if (try_scp) {
/* Fallback is to use the provided scp command. */
fallback_cmd_is_sftp = 0;
fallback_cmd_is_sftp = false;
conf_set_str(conf, CONF_remote_cmd2, cmd);
conf_set_bool(conf, CONF_ssh_subsys2, false);
} else {
/* Since we're not going to try SCP, we may as well try
* harder to find an SFTP server, since in the current
* implementation we have a spare slot. */
fallback_cmd_is_sftp = 1;
fallback_cmd_is_sftp = true;
/* see psftp.c for full explanation of this kludge */
conf_set_str(conf, CONF_remote_cmd2,
"test -x /usr/lib/sftp-server &&"
@ -479,7 +479,7 @@ static void do_cmd(char *host, char *user, char *cmd)
}
} else {
/* Don't try SFTP at all; just try the scp command. */
main_cmd_is_sftp = 0;
main_cmd_is_sftp = false;
conf_set_str(conf, CONF_remote_cmd, cmd);
conf_set_bool(conf, CONF_ssh_subsys, false);
}
@ -572,7 +572,7 @@ static char *colon(char *str)
/*
* Determine whether a string is entirely composed of dots.
*/
static int is_dots(char *str)
static bool is_dots(char *str)
{
return str[strspn(str, ".")] == '\0';
}
@ -586,7 +586,7 @@ static int response(void)
char ch, resp, rbuf[2048];
int p;
if (ssh_scp_recv(&resp, 1) <= 0)
if (!ssh_scp_recv(&resp, 1))
bump("Lost connection");
p = 0;
@ -599,7 +599,7 @@ static int response(void)
case 1: /* error */
case 2: /* fatal error */
do {
if (ssh_scp_recv(&ch, 1) <= 0)
if (!ssh_scp_recv(&ch, 1))
bump("Protocol error: Lost connection");
rbuf[p++] = ch;
} while (p < sizeof(rbuf) && ch != '\n');
@ -613,14 +613,14 @@ static int response(void)
}
}
int sftp_recvdata(char *buf, int len)
bool sftp_recvdata(char *buf, int len)
{
return ssh_scp_recv(buf, len);
}
int sftp_senddata(char *buf, int len)
bool sftp_senddata(char *buf, int len)
{
backend_send(backend, buf, len);
return 1;
return true;
}
int sftp_sendbuffer(void)
{
@ -724,19 +724,19 @@ static struct scp_sftp_dirstack {
int namepos, namelen;
char *dirpath;
char *wildcard;
int matched_something; /* wildcard match set was non-empty */
bool matched_something; /* wildcard match set was non-empty */
} *scp_sftp_dirstack_head;
static char *scp_sftp_remotepath, *scp_sftp_currentname;
static char *scp_sftp_wildcard;
static int scp_sftp_targetisdir, scp_sftp_donethistarget;
static int scp_sftp_preserve, scp_sftp_recursive;
static bool scp_sftp_targetisdir, scp_sftp_donethistarget;
static bool scp_sftp_preserve, scp_sftp_recursive;
static unsigned long scp_sftp_mtime, scp_sftp_atime;
static int scp_has_times;
static bool scp_has_times;
static struct fxp_handle *scp_sftp_filehandle;
static struct fxp_xfer *scp_sftp_xfer;
static uint64_t scp_sftp_fileoffset;
int scp_source_setup(const char *target, int shouldbedir)
int scp_source_setup(const char *target, bool shouldbedir)
{
if (using_sftp) {
/*
@ -746,7 +746,7 @@ int scp_source_setup(const char *target, int shouldbedir)
struct sftp_packet *pktin;
struct sftp_request *req;
struct fxp_attrs attrs;
int ret;
bool ret;
if (!fxp_init()) {
tell_user(stderr, "unable to initialise SFTP: %s", fxp_error());
@ -759,7 +759,7 @@ int scp_source_setup(const char *target, int shouldbedir)
ret = fxp_stat_recv(pktin, req, &attrs);
if (!ret || !(attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS))
scp_sftp_targetisdir = 0;
scp_sftp_targetisdir = false;
else
scp_sftp_targetisdir = (attrs.permissions & 0040000) != 0;
@ -769,7 +769,7 @@ int scp_source_setup(const char *target, int shouldbedir)
scp_sftp_remotepath = dupstr(target);
scp_has_times = 0;
scp_has_times = false;
} else {
(void) response();
}
@ -792,7 +792,7 @@ int scp_send_filetimes(unsigned long mtime, unsigned long atime)
if (using_sftp) {
scp_sftp_mtime = mtime;
scp_sftp_atime = atime;
scp_has_times = 1;
scp_has_times = true;
return 0;
} else {
char buf[80];
@ -901,11 +901,10 @@ int scp_send_finish(void)
struct fxp_attrs attrs;
struct sftp_packet *pktin;
struct sftp_request *req;
int ret;
while (!xfer_done(scp_sftp_xfer)) {
pktin = sftp_recv();
ret = xfer_upload_gotpkt(scp_sftp_xfer, pktin);
int ret = xfer_upload_gotpkt(scp_sftp_xfer, pktin);
if (ret <= 0) {
tell_user(stderr, "error while writing: %s", fxp_error());
if (ret == INT_MIN) /* pktin not even freed */
@ -925,7 +924,7 @@ int scp_send_finish(void)
attrs.mtime = scp_sftp_mtime;
req = fxp_fsetstat_send(scp_sftp_filehandle, attrs);
pktin = sftp_wait_for_reply(req);
ret = fxp_fsetstat_recv(pktin, req);
bool ret = fxp_fsetstat_recv(pktin, req);
if (!ret) {
tell_user(stderr, "unable to set file times: %s", fxp_error());
errs++;
@ -934,7 +933,7 @@ int scp_send_finish(void)
req = fxp_close_send(scp_sftp_filehandle);
pktin = sftp_wait_for_reply(req);
fxp_close_recv(pktin, req);
scp_has_times = 0;
scp_has_times = false;
return 0;
} else {
backend_send(backend, "", 1);
@ -964,7 +963,7 @@ int scp_send_dirname(const char *name, int modes)
struct fxp_attrs attrs;
struct sftp_packet *pktin;
struct sftp_request *req;
int ret;
bool ret;
if (scp_sftp_targetisdir) {
fullname = dupcat(scp_sftp_remotepath, "/", name, NULL);
@ -1031,7 +1030,7 @@ int scp_send_enddir(void)
* right at the start, whereas scp_sink_init is called to
* initialise every level of recursion in the protocol.
*/
int scp_sink_setup(const char *source, int preserve, int recursive)
int scp_sink_setup(const char *source, bool preserve, bool recursive)
{
if (using_sftp) {
char *newsource;
@ -1056,7 +1055,7 @@ int scp_sink_setup(const char *source, int preserve, int recursive)
sfree(newsource);
dupsource = dupstr(source);
lastpart = stripslashes(dupsource, 0);
lastpart = stripslashes(dupsource, false);
wildcard = dupstr(lastpart);
*lastpart = '\0';
if (*dupsource && dupsource[1]) {
@ -1109,7 +1108,7 @@ int scp_sink_setup(const char *source, int preserve, int recursive)
}
scp_sftp_preserve = preserve;
scp_sftp_recursive = recursive;
scp_sftp_donethistarget = 0;
scp_sftp_donethistarget = false;
scp_sftp_dirstack_head = NULL;
}
return 0;
@ -1133,7 +1132,7 @@ struct scp_sink_action {
char *name; /* filename or dirname (not ENDDIR) */
long permissions; /* access permissions (not ENDDIR) */
uint64_t size; /* file size (not ENDDIR) */
int settime; /* 1 if atime and mtime are filled */
bool settime; /* true if atime and mtime are filled */
unsigned long atime, mtime; /* access times for the file */
};
@ -1141,11 +1140,11 @@ int scp_get_sink_action(struct scp_sink_action *act)
{
if (using_sftp) {
char *fname;
int must_free_fname;
bool must_free_fname;
struct fxp_attrs attrs;
struct sftp_packet *pktin;
struct sftp_request *req;
int ret;
bool ret;
if (!scp_sftp_dirstack_head) {
if (!scp_sftp_donethistarget) {
@ -1153,8 +1152,8 @@ int scp_get_sink_action(struct scp_sink_action *act)
* Simple case: we are only dealing with one file.
*/
fname = scp_sftp_remotepath;
must_free_fname = 0;
scp_sftp_donethistarget = 1;
must_free_fname = false;
scp_sftp_donethistarget = true;
} else {
/*
* Even simpler case: one file _which we've done_.
@ -1176,11 +1175,11 @@ int scp_get_sink_action(struct scp_sink_action *act)
head->names[head->namepos].filename))))
head->namepos++; /* skip . and .. */
if (head->namepos < head->namelen) {
head->matched_something = 1;
head->matched_something = true;
fname = dupcat(head->dirpath, "/",
head->names[head->namepos++].filename,
NULL);
must_free_fname = 1;
must_free_fname = true;
} else {
/*
* We've come to the end of the list; pop it off
@ -1345,7 +1344,7 @@ int scp_get_sink_action(struct scp_sink_action *act)
newitem->dirpath = dupstr(fname);
if (scp_sftp_wildcard) {
newitem->wildcard = scp_sftp_wildcard;
newitem->matched_something = 0;
newitem->matched_something = false;
scp_sftp_wildcard = NULL;
} else {
newitem->wildcard = NULL;
@ -1356,7 +1355,7 @@ int scp_get_sink_action(struct scp_sink_action *act)
act->action = SCP_SINK_RETRY;
} else {
act->action = SCP_SINK_DIR;
act->buf = dupstr(stripslashes(fname, 0));
act->buf = dupstr(stripslashes(fname, false));
act->name = act->buf;
act->size = 0; /* duhh, it's a directory */
act->permissions = 07777 & attrs.permissions;
@ -1364,9 +1363,9 @@ int scp_get_sink_action(struct scp_sink_action *act)
(attrs.flags & SSH_FILEXFER_ATTR_ACMODTIME)) {
act->atime = attrs.atime;
act->mtime = attrs.mtime;
act->settime = 1;
act->settime = true;
} else
act->settime = 0;
act->settime = false;
}
return 0;
@ -1375,7 +1374,7 @@ int scp_get_sink_action(struct scp_sink_action *act)
* It's a file. Return SCP_SINK_FILE.
*/
act->action = SCP_SINK_FILE;
act->buf = dupstr(stripslashes(fname, 0));
act->buf = dupstr(stripslashes(fname, false));
act->name = act->buf;
if (attrs.flags & SSH_FILEXFER_ATTR_SIZE) {
act->size = attrs.size;
@ -1386,9 +1385,9 @@ int scp_get_sink_action(struct scp_sink_action *act)
(attrs.flags & SSH_FILEXFER_ATTR_ACMODTIME)) {
act->atime = attrs.atime;
act->mtime = attrs.mtime;
act->settime = 1;
act->settime = true;
} else
act->settime = 0;
act->settime = false;
if (must_free_fname)
scp_sftp_currentname = fname;
else
@ -1397,24 +1396,24 @@ int scp_get_sink_action(struct scp_sink_action *act)
}
} else {
int done = 0;
bool done = false;
int i, bufsize;
int action;
char ch;
act->settime = 0;
act->settime = false;
act->buf = NULL;
bufsize = 0;
while (!done) {
if (ssh_scp_recv(&ch, 1) <= 0)
if (!ssh_scp_recv(&ch, 1))
return 1;
if (ch == '\n')
bump("Protocol error: Unexpected newline");
i = 0;
action = ch;
do {
if (ssh_scp_recv(&ch, 1) <= 0)
if (!ssh_scp_recv(&ch, 1))
bump("Lost connection");
if (i >= bufsize) {
bufsize = i + 128;
@ -1437,7 +1436,7 @@ int scp_get_sink_action(struct scp_sink_action *act)
case 'T':
if (sscanf(act->buf, "%lu %*d %lu %*d",
&act->mtime, &act->atime) == 2) {
act->settime = 1;
act->settime = true;
backend_send(backend, "", 1);
continue; /* go round again */
}
@ -1457,7 +1456,7 @@ int scp_get_sink_action(struct scp_sink_action *act)
* We will go round this loop only once, unless we hit
* `continue' above.
*/
done = 1;
done = true;
}
/*
@ -1542,7 +1541,7 @@ int scp_recv_filedata(char *data, int len)
return actuallen;
} else {
return ssh_scp_recv(data, len);
return ssh_scp_recv(data, len) ? len : 0;
}
}
@ -1763,19 +1762,19 @@ static void rsource(const char *src)
static void sink(const char *targ, const char *src)
{
char *destfname;
int targisdir = 0;
int exists;
bool targisdir = false;
bool exists;
int attr;
WFile *f;
uint64_t received;
int wrerror = 0;
bool wrerror = false;
uint64_t stat_bytes;
time_t stat_starttime, stat_lasttime;
char *stat_name;
attr = file_type(targ);
if (attr == FILE_TYPE_DIRECTORY)
targisdir = 1;
targisdir = true;
if (targetshouldbedirectory && !targisdir)
bump("%s: Not a directory", targ);
@ -1825,7 +1824,7 @@ static void sink(const char *targ, const char *src)
*/
char *striptarget, *stripsrc;
striptarget = stripslashes(act.name, 1);
striptarget = stripslashes(act.name, true);
if (striptarget != act.name) {
tell_user(stderr, "warning: remote host sent a compound"
" pathname '%s'", act.name);
@ -1844,7 +1843,7 @@ static void sink(const char *targ, const char *src)
}
if (src) {
stripsrc = stripslashes(src, 1);
stripsrc = stripslashes(src, true);
if (strcmp(striptarget, stripsrc) &&
!using_sftp && !scp_unsafe_mode) {
tell_user(stderr, "warning: remote host tried to write "
@ -1910,7 +1909,7 @@ static void sink(const char *targ, const char *src)
stat_bytes = 0;
stat_starttime = time(NULL);
stat_lasttime = 0;
stat_name = stripslashes(destfname, 1);
stat_name = stripslashes(destfname, true);
received = 0;
while (received < act.size) {
@ -1928,7 +1927,7 @@ static void sink(const char *targ, const char *src)
continue;
}
if (write_to_file(f, transbuf, read) != (int)read) {
wrerror = 1;
wrerror = true;
/* FIXME: in sftp we can actually abort the transfer */
if (statistics)
printf("\r%-25.25s | %50s\n",
@ -1974,7 +1973,7 @@ static void toremote(int argc, char *argv[])
char *cmd;
int i, wc_type;
uploading = 1;
uploading = true;
wtarg = argv[argc - 1];
@ -2006,11 +2005,11 @@ static void toremote(int argc, char *argv[])
if (colon(argv[0]) != NULL)
bump("%s: Remote to remote not supported", argv[0]);
wc_type = test_wildcard(argv[0], 1);
wc_type = test_wildcard(argv[0], true);
if (wc_type == WCTYPE_NONEXISTENT)
bump("%s: No such file or directory\n", argv[0]);
else if (wc_type == WCTYPE_WILDCARD)
targetshouldbedirectory = 1;
targetshouldbedirectory = true;
}
cmd = dupprintf("scp%s%s%s%s -t %s",
@ -2032,7 +2031,7 @@ static void toremote(int argc, char *argv[])
continue;
}
wc_type = test_wildcard(src, 1);
wc_type = test_wildcard(src, true);
if (wc_type == WCTYPE_NONEXISTENT) {
run_err("%s: No such file or directory", src);
continue;
@ -2068,7 +2067,7 @@ static void tolocal(int argc, char *argv[])
const char *src, *targ;
char *cmd;
uploading = 0;
uploading = false;
if (argc != 2)
bump("More than one remote source not supported");
@ -2173,7 +2172,7 @@ static void get_dir_list(int argc, char *argv[])
if (using_sftp) {
scp_sftp_listdir(src);
} else {
while (ssh_scp_recv(&c, 1) > 0)
while (ssh_scp_recv(&c, 1))
tell_char(stdout, c);
}
}
@ -2239,8 +2238,8 @@ void cmdline_error(const char *p, ...)
exit(1);
}
const int share_can_be_downstream = true;
const int share_can_be_upstream = false;
const bool share_can_be_downstream = true;
const bool share_can_be_upstream = false;
/*
* Main program. (Called `psftp_main' because it gets called from
@ -2277,16 +2276,16 @@ int psftp_main(int argc, char *argv[])
} else if (ret == 1) {
/* We have our own verbosity in addition to `flags'. */
if (flags & FLAG_VERBOSE)
verbose = 1;
verbose = true;
} else if (strcmp(argv[i], "-pgpfp") == 0) {
pgp_fingerprints();
return 1;
} else if (strcmp(argv[i], "-r") == 0) {
recursive = 1;
recursive = true;
} else if (strcmp(argv[i], "-p") == 0) {
preserve = 1;
preserve = true;
} else if (strcmp(argv[i], "-q") == 0) {
statistics = 0;
statistics = false;
} else if (strcmp(argv[i], "-h") == 0 ||
strcmp(argv[i], "-?") == 0 ||
strcmp(argv[i], "--help") == 0) {
@ -2295,15 +2294,15 @@ int psftp_main(int argc, char *argv[])
strcmp(argv[i], "--version") == 0) {
version();
} else if (strcmp(argv[i], "-ls") == 0) {
list = 1;
list = true;
} else if (strcmp(argv[i], "-batch") == 0) {
console_batch_mode = 1;
console_batch_mode = true;
} else if (strcmp(argv[i], "-unsafe") == 0) {
scp_unsafe_mode = 1;
scp_unsafe_mode = true;
} else if (strcmp(argv[i], "-sftp") == 0) {
try_scp = 0; try_sftp = 1;
try_scp = false; try_sftp = true;
} else if (strcmp(argv[i], "-scp") == 0) {
try_scp = 1; try_sftp = 0;
try_scp = true; try_sftp = false;
} else if (strcmp(argv[i], "--") == 0) {
i++;
break;
@ -2325,7 +2324,7 @@ int psftp_main(int argc, char *argv[])
if (argc < 2)
usage();
if (argc > 2)
targetshouldbedirectory = 1;
targetshouldbedirectory = true;
if (colon(argv[argc - 1]) != NULL)
toremote(argc, argv);

270
psftp.c
View File

@ -35,14 +35,14 @@ void do_sftp_cleanup();
char *pwd, *homedir;
static Backend *backend;
static Conf *conf;
int sent_eof = false;
bool sent_eof = false;
/* ------------------------------------------------------------
* Seat vtable.
*/
static int psftp_output(Seat *, int is_stderr, const void *, int);
static int psftp_eof(Seat *);
static int psftp_output(Seat *, bool is_stderr, const void *, int);
static bool psftp_eof(Seat *);
static const SeatVtable psftp_seat_vt = {
psftp_output,
@ -227,7 +227,7 @@ static void not_connected(void)
/* ----------------------------------------------------------------------
* The meat of the `get' and `put' commands.
*/
int sftp_get_file(char *fname, char *outfname, int recurse, int restart)
bool sftp_get_file(char *fname, char *outfname, bool recurse, bool restart)
{
struct fxp_handle *fh;
struct sftp_packet *pktin;
@ -235,7 +235,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart)
struct fxp_xfer *xfer;
uint64_t offset;
WFile *file;
int ret, shown_err = false;
bool toret, shown_err = false;
struct fxp_attrs attrs;
/*
@ -244,7 +244,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart)
* subsequent FXP_OPEN will return a usable error message.)
*/
if (recurse) {
int result;
bool result;
req = fxp_stat_send(fname);
pktin = sftp_wait_for_reply(req);
@ -267,7 +267,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart)
if (file_type(outfname) != FILE_TYPE_DIRECTORY &&
!create_directory(outfname)) {
printf("%s: Cannot create directory\n", outfname);
return 0;
return false;
}
/*
@ -281,7 +281,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart)
if (!dirhandle) {
printf("%s: unable to open directory: %s\n",
fname, fxp_error());
return 0;
return false;
}
nnames = namesize = 0;
ournames = NULL;
@ -302,7 +302,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart)
fxp_close_recv(pktin, req);
sfree(ournames);
return 0;
return false;
}
if (names->nnames == 0) {
fxp_free_names(names);
@ -352,12 +352,13 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart)
if (restart) {
while (i < nnames) {
char *nextoutfname;
int ret;
bool nonexistent;
nextoutfname = dir_file_cat(outfname,
ournames[i]->filename);
ret = (file_type(nextoutfname) == FILE_TYPE_NONEXISTENT);
nonexistent = (file_type(nextoutfname) ==
FILE_TYPE_NONEXISTENT);
sfree(nextoutfname);
if (ret)
if (nonexistent)
break;
i++;
}
@ -373,20 +374,21 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart)
*/
for (; i < nnames; i++) {
char *nextfname, *nextoutfname;
int ret;
bool retd;
nextfname = dupcat(fname, "/", ournames[i]->filename, NULL);
nextoutfname = dir_file_cat(outfname, ournames[i]->filename);
ret = sftp_get_file(nextfname, nextoutfname, recurse, restart);
retd = sftp_get_file(
nextfname, nextoutfname, recurse, restart);
restart = false; /* after first partial file, do full */
sfree(nextoutfname);
sfree(nextfname);
if (!ret) {
if (!retd) {
for (i = 0; i < nnames; i++) {
fxp_free_name(ournames[i]);
}
sfree(ournames);
return 0;
return false;
}
}
@ -398,7 +400,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart)
}
sfree(ournames);
return 1;
return true;
}
}
@ -413,7 +415,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart)
if (!fh) {
printf("%s: open for read: %s\n", fname, fxp_error());
return 0;
return false;
}
if (restart) {
@ -429,7 +431,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart)
pktin = sftp_wait_for_reply(req);
fxp_close_recv(pktin, req);
return 0;
return false;
}
if (restart) {
@ -441,7 +443,7 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart)
pktin = sftp_wait_for_reply(req);
fxp_close_recv(pktin, req);
return 0;
return false;
}
offset = get_file_posn(file);
@ -456,24 +458,24 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart)
* FIXME: we can use FXP_FSTAT here to get the file size, and
* thus put up a progress bar.
*/
ret = 1;
toret = true;
xfer = xfer_download_init(fh, offset);
while (!xfer_done(xfer)) {
void *vbuf;
int len;
int retd, len;
int wpos, wlen;
xfer_download_queue(xfer);
pktin = sftp_recv();
ret = xfer_download_gotpkt(xfer, pktin);
if (ret <= 0) {
retd = xfer_download_gotpkt(xfer, pktin);
if (retd <= 0) {
if (!shown_err) {
printf("error while reading: %s\n", fxp_error());
shown_err = true;
}
if (ret == INT_MIN) /* pktin not even freed */
if (retd == INT_MIN) /* pktin not even freed */
sfree(pktin);
ret = 0;
toret = false;
}
while (xfer_download_data(xfer, &vbuf, &len)) {
@ -484,14 +486,14 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart)
wlen = write_to_file(file, buf + wpos, len - wpos);
if (wlen <= 0) {
printf("error while writing local file\n");
ret = 0;
toret = false;
xfer_set_error(xfer);
break;
}
wpos += wlen;
}
if (wpos < len) { /* we had an error */
ret = 0;
toret = false;
xfer_set_error(xfer);
}
@ -507,10 +509,10 @@ int sftp_get_file(char *fname, char *outfname, int recurse, int restart)
pktin = sftp_wait_for_reply(req);
fxp_close_recv(pktin, req);
return ret;
return toret;
}
int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
bool sftp_put_file(char *fname, char *outfname, bool recurse, bool restart)
{
struct fxp_handle *fh;
struct fxp_xfer *xfer;
@ -518,7 +520,7 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
struct sftp_request *req;
uint64_t offset;
RFile *file;
int err = 0, eof;
bool err = false, eof;
struct fxp_attrs attrs;
long permissions;
@ -528,7 +530,7 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
* subsequent fopen will return an error message.)
*/
if (recurse && file_type(fname) == FILE_TYPE_DIRECTORY) {
int result;
bool result;
int nnames, namesize;
char *name, **ournames;
DirHandle *dh;
@ -551,7 +553,7 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
if (!result) {
printf("%s: create directory: %s\n",
outfname, fxp_error());
return 0;
return false;
}
}
@ -564,7 +566,7 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
dh = open_directory(fname);
if (!dh) {
printf("%s: unable to open directory\n", fname);
return 0;
return false;
}
while ((name = read_filename(dh)) != NULL) {
if (nnames >= namesize) {
@ -617,20 +619,20 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
*/
for (; i < nnames; i++) {
char *nextfname, *nextoutfname;
int ret;
bool retd;
nextfname = dir_file_cat(fname, ournames[i]);
nextoutfname = dupcat(outfname, "/", ournames[i], NULL);
ret = sftp_put_file(nextfname, nextoutfname, recurse, restart);
retd = sftp_put_file(nextfname, nextoutfname, recurse, restart);
restart = false; /* after first partial file, do full */
sfree(nextoutfname);
sfree(nextfname);
if (!ret) {
if (!retd) {
for (i = 0; i < nnames; i++) {
sfree(ournames[i]);
}
sfree(ournames);
return 0;
return false;
}
}
@ -642,13 +644,13 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
}
sfree(ournames);
return 1;
return true;
}
file = open_existing_file(fname, NULL, NULL, NULL, &permissions);
if (!file) {
printf("local: unable to open %s\n", fname);
return 0;
return false;
}
attrs.flags = 0;
PUT_PERMISSIONS(attrs, permissions);
@ -665,25 +667,25 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
if (!fh) {
close_rfile(file);
printf("%s: open for write: %s\n", outfname, fxp_error());
return 0;
return false;
}
if (restart) {
struct fxp_attrs attrs;
int ret;
bool retd;
req = fxp_fstat_send(fh);
pktin = sftp_wait_for_reply(req);
ret = fxp_fstat_recv(pktin, req, &attrs);
retd = fxp_fstat_recv(pktin, req, &attrs);
if (!ret) {
if (!retd) {
printf("read size of %s: %s\n", outfname, fxp_error());
err = 1;
err = true;
goto cleanup;
}
if (!(attrs.flags & SSH_FILEXFER_ATTR_SIZE)) {
printf("read size of %s: size was not given\n", outfname);
err = 1;
err = true;
goto cleanup;
}
offset = attrs.size;
@ -702,7 +704,7 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
* thus put up a progress bar.
*/
xfer = xfer_upload_init(fh, offset);
eof = 0;
eof = false;
while ((!err && !eof) || !xfer_done(xfer)) {
char buffer[4096];
int len, ret;
@ -711,9 +713,9 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
len = read_from_file(file, buffer, sizeof(buffer));
if (len == -1) {
printf("error while reading local file\n");
err = 1;
err = true;
} else if (len == 0) {
eof = 1;
eof = true;
} else {
xfer_upload_data(xfer, buffer, len);
}
@ -727,7 +729,7 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
sfree(pktin);
if (!err) {
printf("error while writing: %s\n", fxp_error());
err = 1;
err = true;
}
}
}
@ -741,13 +743,13 @@ int sftp_put_file(char *fname, char *outfname, int recurse, int restart)
if (!fxp_close_recv(pktin, req)) {
if (!err) {
printf("error while closing: %s", fxp_error());
err = 1;
err = true;
}
}
close_rfile(file);
return (err == 0) ? 1 : 0;
return !err;
}
/* ----------------------------------------------------------------------
@ -768,7 +770,8 @@ SftpWildcardMatcher *sftp_begin_wildcard_matching(char *name)
struct sftp_request *req;
char *wildcard;
char *unwcdir, *tmpdir, *cdir;
int len, check;
int len;
bool check;
SftpWildcardMatcher *swcm;
struct fxp_handle *dirh;
@ -777,7 +780,7 @@ SftpWildcardMatcher *sftp_begin_wildcard_matching(char *name)
* a fully specified directory part, followed by a wildcard
* after that.
*/
wildcard = stripslashes(name, 0);
wildcard = stripslashes(name, false);
unwcdir = dupstr(name);
len = wildcard - name;
@ -904,33 +907,34 @@ void sftp_finish_wildcard_matching(SftpWildcardMatcher *swcm)
* argument and iterate over every matching file. Used in several
* PSFTP commands (rmdir, rm, chmod, mv).
*/
int wildcard_iterate(char *filename, int (*func)(void *, char *), void *ctx)
bool wildcard_iterate(char *filename, bool (*func)(void *, char *), void *ctx)
{
char *unwcfname, *newname, *cname;
int is_wc, ret;
bool is_wc, toret;
unwcfname = snewn(strlen(filename)+1, char);
is_wc = !wc_unescape(unwcfname, filename);
if (is_wc) {
SftpWildcardMatcher *swcm = sftp_begin_wildcard_matching(filename);
int matched = false;
bool matched = false;
sfree(unwcfname);
if (!swcm)
return 0;
return false;
ret = 1;
toret = true;
while ( (newname = sftp_wildcard_get_filename(swcm)) != NULL ) {
cname = canonify(newname);
if (!cname) {
printf("%s: canonify: %s\n", newname, fxp_error());
ret = 0;
toret = false;
}
sfree(newname);
matched = true;
ret &= func(ctx, cname);
if (!func(ctx, cname))
toret = false;
sfree(cname);
}
@ -944,23 +948,23 @@ int wildcard_iterate(char *filename, int (*func)(void *, char *), void *ctx)
cname = canonify(unwcfname);
if (!cname) {
printf("%s: canonify: %s\n", filename, fxp_error());
ret = 0;
toret = false;
}
ret = func(ctx, cname);
toret = func(ctx, cname);
sfree(cname);
sfree(unwcfname);
}
return ret;
return toret;
}
/*
* Handy helper function.
*/
int is_wildcard(char *name)
bool is_wildcard(char *name)
{
char *unwcfname = snewn(strlen(name)+1, char);
int is_wc = !wc_unescape(unwcfname, name);
bool is_wc = !wc_unescape(unwcfname, name);
sfree(unwcfname);
return is_wc;
}
@ -1040,10 +1044,11 @@ int sftp_cmd_ls(struct sftp_command *cmd)
wildcard = NULL;
} else {
char *tmpdir;
int len, check;
int len;
bool check;
sfree(unwcdir);
wildcard = stripslashes(dir, 0);
wildcard = stripslashes(dir, false);
unwcdir = dupstr(dir);
len = wildcard - dir;
unwcdir[len] = '\0';
@ -1207,11 +1212,11 @@ int sftp_cmd_pwd(struct sftp_command *cmd)
* transfer (never as a different local name for a remote file) and
* can handle wildcards.
*/
int sftp_general_get(struct sftp_command *cmd, int restart, int multiple)
int sftp_general_get(struct sftp_command *cmd, bool restart, bool multiple)
{
char *fname, *unwcfname, *origfname, *origwfname, *outfname;
int i, ret;
int recurse = false;
int i, toret;
bool recurse = false;
if (!backend) {
not_connected();
@ -1238,7 +1243,7 @@ int sftp_general_get(struct sftp_command *cmd, int restart, int multiple)
return 0;
}
ret = 1;
toret = 1;
do {
SftpWildcardMatcher *swcm;
@ -1278,9 +1283,9 @@ int sftp_general_get(struct sftp_command *cmd, int restart, int multiple)
if (!multiple && i < cmd->nwords)
outfname = cmd->words[i++];
else
outfname = stripslashes(origwfname, 0);
outfname = stripslashes(origwfname, false);
ret = sftp_get_file(fname, outfname, recurse, restart);
toret = sftp_get_file(fname, outfname, recurse, restart);
sfree(fname);
@ -1294,24 +1299,24 @@ int sftp_general_get(struct sftp_command *cmd, int restart, int multiple)
sfree(unwcfname);
if (swcm)
sftp_finish_wildcard_matching(swcm);
if (!ret)
return ret;
if (!toret)
return toret;
} while (multiple && i < cmd->nwords);
return ret;
return toret;
}
int sftp_cmd_get(struct sftp_command *cmd)
{
return sftp_general_get(cmd, 0, 0);
return sftp_general_get(cmd, false, false);
}
int sftp_cmd_mget(struct sftp_command *cmd)
{
return sftp_general_get(cmd, 0, 1);
return sftp_general_get(cmd, false, true);
}
int sftp_cmd_reget(struct sftp_command *cmd)
{
return sftp_general_get(cmd, 1, 0);
return sftp_general_get(cmd, true, false);
}
/*
@ -1323,11 +1328,12 @@ int sftp_cmd_reget(struct sftp_command *cmd)
* transfer (never as a different remote name for a local file) and
* can handle wildcards.
*/
int sftp_general_put(struct sftp_command *cmd, int restart, int multiple)
int sftp_general_put(struct sftp_command *cmd, bool restart, bool multiple)
{
char *fname, *wfname, *origoutfname, *outfname;
int i, ret;
int recurse = false;
int i;
int toret;
bool recurse = false;
if (!backend) {
not_connected();
@ -1354,7 +1360,7 @@ int sftp_general_put(struct sftp_command *cmd, int restart, int multiple)
return 0;
}
ret = 1;
toret = 1;
do {
WildcardMatcher *wcm;
fname = cmd->words[i++];
@ -1377,7 +1383,7 @@ int sftp_general_put(struct sftp_command *cmd, int restart, int multiple)
if (!multiple && i < cmd->nwords)
origoutfname = cmd->words[i++];
else
origoutfname = stripslashes(wfname, 1);
origoutfname = stripslashes(wfname, true);
outfname = canonify(origoutfname);
if (!outfname) {
@ -1388,7 +1394,7 @@ int sftp_general_put(struct sftp_command *cmd, int restart, int multiple)
}
return 0;
}
ret = sftp_put_file(wfname, outfname, recurse, restart);
toret = sftp_put_file(wfname, outfname, recurse, restart);
sfree(outfname);
if (wcm) {
@ -1402,24 +1408,24 @@ int sftp_general_put(struct sftp_command *cmd, int restart, int multiple)
if (wcm)
finish_wildcard_matching(wcm);
if (!ret)
return ret;
if (!toret)
return toret;
} while (multiple && i < cmd->nwords);
return ret;
return toret;
}
int sftp_cmd_put(struct sftp_command *cmd)
{
return sftp_general_put(cmd, 0, 0);
return sftp_general_put(cmd, false, false);
}
int sftp_cmd_mput(struct sftp_command *cmd)
{
return sftp_general_put(cmd, 0, 1);
return sftp_general_put(cmd, false, true);
}
int sftp_cmd_reput(struct sftp_command *cmd)
{
return sftp_general_put(cmd, 1, 0);
return sftp_general_put(cmd, true, false);
}
int sftp_cmd_mkdir(struct sftp_command *cmd)
@ -1427,7 +1433,7 @@ int sftp_cmd_mkdir(struct sftp_command *cmd)
char *dir;
struct sftp_packet *pktin;
struct sftp_request *req;
int result;
bool result;
int i, ret;
if (!backend) {
@ -1464,11 +1470,11 @@ int sftp_cmd_mkdir(struct sftp_command *cmd)
return ret;
}
static int sftp_action_rmdir(void *vctx, char *dir)
static bool sftp_action_rmdir(void *vctx, char *dir)
{
struct sftp_packet *pktin;
struct sftp_request *req;
int result;
bool result;
req = fxp_rmdir_send(dir);
pktin = sftp_wait_for_reply(req);
@ -1476,12 +1482,12 @@ static int sftp_action_rmdir(void *vctx, char *dir)
if (!result) {
printf("rmdir %s: %s\n", dir, fxp_error());
return 0;
return false;
}
printf("rmdir %s: OK\n", dir);
return 1;
return true;
}
int sftp_cmd_rmdir(struct sftp_command *cmd)
@ -1505,11 +1511,11 @@ int sftp_cmd_rmdir(struct sftp_command *cmd)
return ret;
}
static int sftp_action_rm(void *vctx, char *fname)
static bool sftp_action_rm(void *vctx, char *fname)
{
struct sftp_packet *pktin;
struct sftp_request *req;
int result;
bool result;
req = fxp_remove_send(fname);
pktin = sftp_wait_for_reply(req);
@ -1517,12 +1523,12 @@ static int sftp_action_rm(void *vctx, char *fname)
if (!result) {
printf("rm %s: %s\n", fname, fxp_error());
return 0;
return false;
}
printf("rm %s: OK\n", fname);
return 1;
return true;
}
int sftp_cmd_rm(struct sftp_command *cmd)
@ -1546,12 +1552,12 @@ int sftp_cmd_rm(struct sftp_command *cmd)
return ret;
}
static int check_is_dir(char *dstfname)
static bool check_is_dir(char *dstfname)
{
struct sftp_packet *pktin;
struct sftp_request *req;
struct fxp_attrs attrs;
int result;
bool result;
req = fxp_stat_send(dstfname);
pktin = sftp_wait_for_reply(req);
@ -1567,17 +1573,17 @@ static int check_is_dir(char *dstfname)
struct sftp_context_mv {
char *dstfname;
int dest_is_dir;
bool dest_is_dir;
};
static int sftp_action_mv(void *vctx, char *srcfname)
static bool sftp_action_mv(void *vctx, char *srcfname)
{
struct sftp_context_mv *ctx = (struct sftp_context_mv *)vctx;
struct sftp_packet *pktin;
struct sftp_request *req;
const char *error;
char *finalfname, *newcanon = NULL;
int ret, result;
bool toret, result;
if (ctx->dest_is_dir) {
char *p;
@ -1590,7 +1596,7 @@ static int sftp_action_mv(void *vctx, char *srcfname)
if (!newcanon) {
printf("%s: canonify: %s\n", newname, fxp_error());
sfree(newname);
return 0;
return false;
}
sfree(newname);
@ -1607,14 +1613,14 @@ static int sftp_action_mv(void *vctx, char *srcfname)
if (error) {
printf("mv %s %s: %s\n", srcfname, finalfname, error);
ret = 0;
toret = false;
} else {
printf("%s -> %s\n", srcfname, finalfname);
ret = 1;
toret = true;
}
sfree(newcanon);
return ret;
return toret;
}
int sftp_cmd_mv(struct sftp_command *cmd)
@ -1666,12 +1672,12 @@ struct sftp_context_chmod {
unsigned attrs_clr, attrs_xor;
};
static int sftp_action_chmod(void *vctx, char *fname)
static bool sftp_action_chmod(void *vctx, char *fname)
{
struct fxp_attrs attrs;
struct sftp_packet *pktin;
struct sftp_request *req;
int result;
bool result;
unsigned oldperms, newperms;
struct sftp_context_chmod *ctx = (struct sftp_context_chmod *)vctx;
@ -1682,7 +1688,7 @@ static int sftp_action_chmod(void *vctx, char *fname)
if (!result || !(attrs.flags & SSH_FILEXFER_ATTR_PERMISSIONS)) {
printf("get attrs for %s: %s\n", fname,
result ? "file permissions not provided" : fxp_error());
return 0;
return false;
}
attrs.flags = SSH_FILEXFER_ATTR_PERMISSIONS; /* perms _only_ */
@ -1692,7 +1698,7 @@ static int sftp_action_chmod(void *vctx, char *fname)
newperms = attrs.permissions & 07777;
if (oldperms == newperms)
return 1; /* no need to do anything! */
return true; /* no need to do anything! */
req = fxp_setstat_send(fname, attrs);
pktin = sftp_wait_for_reply(req);
@ -1700,12 +1706,12 @@ static int sftp_action_chmod(void *vctx, char *fname)
if (!result) {
printf("set attrs for %s: %s\n", fname, fxp_error());
return 0;
return false;
}
printf("%s: %04o -> %04o\n", fname, oldperms, newperms);
return 1;
return true;
}
int sftp_cmd_chmod(struct sftp_command *cmd)
@ -1925,7 +1931,7 @@ static struct sftp_cmd_lookup {
* `shorthelp' is the name of a primary command, which
* contains the help that should double up for this command.
*/
int listed; /* do we list this in primary help? */
bool listed; /* do we list this in primary help? */
const char *shorthelp;
const char *longhelp;
int (*obey) (struct sftp_command *);
@ -2225,7 +2231,7 @@ struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags)
char *line;
struct sftp_command *cmd;
char *p, *q, *r;
int quoting;
bool quoting;
cmd = snew(struct sftp_command);
cmd->words = NULL;
@ -2302,7 +2308,7 @@ struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags)
break;
/* mark start of word */
q = r = p; /* q sits at start, r writes word */
quoting = 0;
quoting = false;
while (*p) {
if (!quoting && (*p == ' ' || *p == '\t'))
break; /* reached end of word */
@ -2461,7 +2467,7 @@ int do_sftp(int mode, int modeflags, char *batchfile)
* Dirty bits: integration with PuTTY.
*/
static int verbose = 0;
static bool verbose = false;
void ldisc_echoedit_update(Ldisc *ldisc) { }
@ -2488,7 +2494,7 @@ static unsigned char *outptr; /* where to put the data */
static unsigned outlen; /* how much data required */
static unsigned char *pending = NULL; /* any spare data */
static unsigned pendlen = 0, pendsize = 0; /* length and phys. size of buffer */
static int psftp_output(Seat *seat, int is_stderr,
static int psftp_output(Seat *seat, bool is_stderr,
const void *data, int datalen)
{
unsigned char *p = (unsigned char *) data;
@ -2534,7 +2540,7 @@ static int psftp_output(Seat *seat, int is_stderr,
return 0;
}
static int psftp_eof(Seat *seat)
static bool psftp_eof(Seat *seat)
{
/*
* We expect to be the party deciding when to close the
@ -2548,7 +2554,7 @@ static int psftp_eof(Seat *seat)
return false;
}
int sftp_recvdata(char *buf, int len)
bool sftp_recvdata(char *buf, int len)
{
outptr = (unsigned char *) buf;
outlen = len;
@ -2572,20 +2578,20 @@ int sftp_recvdata(char *buf, int len)
pending = NULL;
}
if (outlen == 0)
return 1;
return true;
}
while (outlen > 0) {
if (backend_exitcode(backend) >= 0 || ssh_sftp_loop_iteration() < 0)
return 0; /* doom */
return false; /* doom */
}
return 1;
return true;
}
int sftp_senddata(char *buf, int len)
bool sftp_senddata(char *buf, int len)
{
backend_send(backend, buf, len);
return 1;
return true;
}
int sftp_sendbuffer(void)
{
@ -2839,8 +2845,8 @@ void cmdline_error(const char *p, ...)
exit(1);
}
const int share_can_be_downstream = true;
const int share_can_be_upstream = false;
const bool share_can_be_downstream = true;
const bool share_can_be_upstream = false;
/*
* Main program. Parse arguments etc.
@ -2886,7 +2892,7 @@ int psftp_main(int argc, char *argv[])
} else if (ret == 1) {
/* We have our own verbosity in addition to `flags'. */
if (flags & FLAG_VERBOSE)
verbose = 1;
verbose = true;
} else if (strcmp(argv[i], "-h") == 0 ||
strcmp(argv[i], "-?") == 0 ||
strcmp(argv[i], "--help") == 0) {
@ -2898,7 +2904,7 @@ int psftp_main(int argc, char *argv[])
strcmp(argv[i], "--version") == 0) {
version();
} else if (strcmp(argv[i], "-batch") == 0) {
console_batch_mode = 1;
console_batch_mode = true;
} else if (strcmp(argv[i], "-b") == 0 && i + 1 < argc) {
mode = 1;
batchfile = argv[++i];

12
psftp.h
View File

@ -43,7 +43,7 @@ int ssh_sftp_loop_iteration(void);
* false, a back end is not (intentionally) active at all (e.g.
* psftp before an `open' command).
*/
char *ssh_sftp_get_cmdline(const char *prompt, int backend_required);
char *ssh_sftp_get_cmdline(const char *prompt, bool backend_required);
/*
* Platform-specific function called when we're about to make a
@ -149,7 +149,7 @@ void close_directory(DirHandle *dir);
enum {
WCTYPE_NONEXISTENT, WCTYPE_FILENAME, WCTYPE_WILDCARD
};
int test_wildcard(const char *name, int cmdline);
int test_wildcard(const char *name, bool cmdline);
/*
* Actually return matching file names for a local wildcard.
@ -168,12 +168,12 @@ void finish_wildcard_matching(WildcardMatcher *dir);
*
* Returns true if the filename is kosher, false if dangerous.
*/
int vet_filename(const char *name);
bool vet_filename(const char *name);
/*
* Create a directory. Returns 0 on error, !=0 on success.
* Create a directory. Returns true on success, false on error.
*/
int create_directory(const char *name);
bool create_directory(const char *name);
/*
* Concatenate a directory name and a file name. The way this is
@ -196,6 +196,6 @@ char *dir_file_cat(const char *dir, const char *file);
* pair of overloaded functions, one mapping mutable->mutable and the
* other const->const :-(
*/
char *stripslashes(const char *str, int local);
char *stripslashes(const char *str, bool local);
#endif /* PUTTY_PSFTP_H */

135
putty.h
View File

@ -153,7 +153,7 @@ struct sesslist {
struct unicode_data {
char **uni_tbl;
int dbcs_screenfont;
bool dbcs_screenfont;
int font_codepage;
int line_codepage;
wchar_t unitab_scoacs[256];
@ -497,7 +497,7 @@ struct BackendVtable {
const char *(*init) (Seat *seat, Backend **backend_out,
LogContext *logctx, Conf *conf,
const char *host, int port,
char **realhost, int nodelay, int keepalive);
char **realhost, bool nodelay, bool keepalive);
void (*free) (Backend *be);
/* Pass in a replacement configuration. */
@ -509,13 +509,13 @@ struct BackendVtable {
void (*size) (Backend *be, int width, int height);
void (*special) (Backend *be, SessionSpecialCode code, int arg);
const SessionSpecial *(*get_specials) (Backend *be);
int (*connected) (Backend *be);
bool (*connected) (Backend *be);
int (*exitcode) (Backend *be);
/* If back->sendok() returns false, the backend doesn't currently
* want input data, so the frontend should avoid acquiring any if
* possible (passing back-pressure on to its sender). */
int (*sendok) (Backend *be);
int (*ldisc_option_state) (Backend *be, int);
bool (*sendok) (Backend *be);
bool (*ldisc_option_state) (Backend *be, int);
void (*provide_ldisc) (Backend *be, Ldisc *ldisc);
/* Tells the back end that the front end buffer is clearing. */
void (*unthrottle) (Backend *be, int bufsize);
@ -523,7 +523,7 @@ struct BackendVtable {
/* Only implemented in the SSH protocol: check whether a
* connection-sharing upstream exists for a given configuration. */
int (*test_for_upstream)(const char *host, int port, Conf *conf);
bool (*test_for_upstream)(const char *host, int port, Conf *conf);
const char *name;
int protocol;
@ -595,7 +595,7 @@ GLOBAL int default_port;
/*
* This is set true by cmdline.c iff a session is loaded with "-load".
*/
GLOBAL int loaded_session;
GLOBAL bool loaded_session;
/*
* This is set to the name of the loaded session.
*/
@ -619,7 +619,7 @@ GLOBAL char *cmdline_session_name;
*/
typedef struct {
char *prompt;
int echo;
bool echo;
/*
* 'result' must be a dynamically allocated array of exactly
* 'resultsize' chars. The code for actually reading input may
@ -642,11 +642,11 @@ typedef struct {
* information (so the caller should ensure that the supplied text is
* sufficient).
*/
int to_server;
bool to_server;
char *name; /* Short description, perhaps for dialog box title */
int name_reqd; /* Display of `name' required or optional? */
bool name_reqd; /* Display of `name' required or optional? */
char *instruction; /* Long description, maybe with embedded newlines */
int instr_reqd; /* Display of `instruction' required or optional? */
bool instr_reqd; /* Display of `instruction' required or optional? */
size_t n_prompts; /* May be zero (in which case display the foregoing,
* if any, and return success) */
prompt_t **prompts;
@ -654,7 +654,7 @@ typedef struct {
* seat_get_userpass_input(); initially NULL */
} prompts_t;
prompts_t *new_prompts();
void add_prompt(prompts_t *p, char *promptstr, int echo);
void add_prompt(prompts_t *p, char *promptstr, bool echo);
void prompt_set_result(prompt_t *pr, const char *newstr);
void prompt_ensure_result_size(prompt_t *pr, int len);
/* Burn the evidence. (Assumes _all_ strings want free()ing.) */
@ -668,7 +668,7 @@ void free_prompts(prompts_t *p);
* background.
*/
typedef struct optionalrgb {
unsigned char enabled;
bool enabled;
unsigned char r, g, b;
} optionalrgb;
extern const optionalrgb optionalrgb_none;
@ -742,7 +742,7 @@ struct SeatVtable {
*
* The return value is the current size of the output backlog.
*/
int (*output)(Seat *seat, int is_stderr, const void *data, int len);
int (*output)(Seat *seat, bool is_stderr, const void *data, int len);
/*
* Called when the back end wants to indicate that EOF has arrived
@ -750,7 +750,7 @@ struct SeatVtable {
* we intend to keep the session open in the other direction, or
* true to indicate that if they're closing so are we.
*/
int (*eof)(Seat *seat);
bool (*eof)(Seat *seat);
/*
* Try to get answers from a set of interactive login prompts. The
@ -884,14 +884,14 @@ struct SeatVtable {
* user in the UTF-8 character set. (Affects e.g. visual erase
* handling in local line editing.)
*/
int (*is_utf8)(Seat *seat);
bool (*is_utf8)(Seat *seat);
/*
* Notify the seat that the back end, and/or the ldisc between
* them, have changed their idea of whether they currently want
* local echo and/or local line editing enabled.
*/
void (*echoedit_update)(Seat *seat, int echoing, int editing);
void (*echoedit_update)(Seat *seat, bool echoing, bool editing);
/*
* Return the local X display string relevant to a seat, or NULL
@ -904,7 +904,7 @@ struct SeatVtable {
* by returning true and filling in the output pointer. Return
* false if there isn't one or if the concept is meaningless.
*/
int (*get_windowid)(Seat *seat, long *id_out);
bool (*get_windowid)(Seat *seat, long *id_out);
/*
* Return the size of the terminal window in pixels. If the
@ -912,7 +912,7 @@ struct SeatVtable {
* return false; otherwise fill in the output pointers and return
* true.
*/
int (*get_window_pixel_size)(Seat *seat, int *width, int *height);
bool (*get_window_pixel_size)(Seat *seat, int *width, int *height);
};
#define seat_output(seat, is_stderr, data, len) \
@ -964,8 +964,8 @@ void seat_connection_fatal(Seat *seat, const char *fmt, ...);
* These are generally obvious, except for is_utf8, where you might
* plausibly want to return either fixed answer 'no' or 'yes'.
*/
int nullseat_output(Seat *seat, int is_stderr, const void *data, int len);
int nullseat_eof(Seat *seat);
int nullseat_output(Seat *seat, bool is_stderr, const void *data, int len);
bool nullseat_eof(Seat *seat);
int nullseat_get_userpass_input(Seat *seat, prompts_t *p, bufchain *input);
void nullseat_notify_remote_exit(Seat *seat);
void nullseat_connection_fatal(Seat *seat, const char *message);
@ -982,12 +982,12 @@ int nullseat_confirm_weak_crypto_primitive(
int nullseat_confirm_weak_cached_hostkey(
Seat *seat, const char *algname, const char *betteralgs,
void (*callback)(void *ctx, int result), void *ctx);
int nullseat_is_never_utf8(Seat *seat);
int nullseat_is_always_utf8(Seat *seat);
void nullseat_echoedit_update(Seat *seat, int echoing, int editing);
bool nullseat_is_never_utf8(Seat *seat);
bool nullseat_is_always_utf8(Seat *seat);
void nullseat_echoedit_update(Seat *seat, bool echoing, bool editing);
const char *nullseat_get_x_display(Seat *seat);
int nullseat_get_windowid(Seat *seat, long *id_out);
int nullseat_get_window_pixel_size(Seat *seat, int *width, int *height);
bool nullseat_get_windowid(Seat *seat, long *id_out);
bool nullseat_get_window_pixel_size(Seat *seat, int *width, int *height);
/*
* Seat functions provided by the platform's console-application
@ -1029,7 +1029,7 @@ struct TermWinVtable {
* of TermWin handles it by loading the currently configured font
* into the HDC and doing a GDI query.)
*/
int (*setup_draw_ctx)(TermWin *);
bool (*setup_draw_ctx)(TermWin *);
/* Draw text in the window, during a painting operation */
void (*draw_text)(TermWin *, int x, int y, wchar_t *text, int len,
unsigned long attrs, int line_attrs, truecolour tc);
@ -1045,14 +1045,14 @@ struct TermWinVtable {
void (*set_cursor_pos)(TermWin *, int x, int y);
void (*set_raw_mouse_mode)(TermWin *, int enable);
void (*set_raw_mouse_mode)(TermWin *, bool enable);
void (*set_scrollbar)(TermWin *, int total, int start, int page);
void (*bell)(TermWin *, int mode);
void (*clip_write)(TermWin *, int clipboard, wchar_t *text, int *attrs,
truecolour *colours, int len, int must_deselect);
truecolour *colours, int len, bool must_deselect);
void (*clip_request_paste)(TermWin *, int clipboard);
void (*refresh)(TermWin *);
@ -1066,20 +1066,20 @@ struct TermWinVtable {
* {min,normal,max} switch. The idea is that when you un-minimise
* the window it remembers whether to go back to normal or
* maximised. */
void (*set_minimised)(TermWin *, int minimised);
int (*is_minimised)(TermWin *);
void (*set_maximised)(TermWin *, int maximised);
void (*set_minimised)(TermWin *, bool minimised);
bool (*is_minimised)(TermWin *);
void (*set_maximised)(TermWin *, bool maximised);
void (*move)(TermWin *, int x, int y);
void (*set_zorder)(TermWin *, int top);
void (*set_zorder)(TermWin *, bool top);
int (*palette_get)(TermWin *, int n, int *r, int *g, int *b);
bool (*palette_get)(TermWin *, int n, int *r, int *g, int *b);
void (*palette_set)(TermWin *, int n, int r, int g, int b);
void (*palette_reset)(TermWin *);
void (*get_pos)(TermWin *, int *x, int *y);
void (*get_pixels)(TermWin *, int *x, int *y);
const char *(*get_title)(TermWin *, int icon);
int (*is_utf8)(TermWin *);
const char *(*get_title)(TermWin *, bool icon);
bool (*is_utf8)(TermWin *);
};
#define win_setup_draw_ctx(win) \
@ -1397,6 +1397,7 @@ void cleanup_exit(int);
X(INT, NONE, shadowboldoffset) /* in pixels */ \
X(BOOL, NONE, crhaslf) \
X(STR, NONE, winclass) \
/* end of list */
/* Now define the actual enum of option keywords using that macro. */
#define CONF_ENUM_DEF(valtype, keytype, keyword) CONF_ ## keyword,
@ -1439,7 +1440,7 @@ void conf_set_filename(Conf *conf, int key, const Filename *val);
void conf_set_fontspec(Conf *conf, int key, const FontSpec *val);
/* Serialisation functions for Duplicate Session */
void conf_serialise(BinarySink *bs, Conf *conf);
int conf_deserialise(Conf *conf, BinarySource *src);/*returns true on success*/
bool conf_deserialise(Conf *conf, BinarySource *src);/*returns true on success*/
/*
* Functions to copy, free, serialise and deserialise FontSpecs.
@ -1475,7 +1476,7 @@ char *save_settings(const char *section, Conf *conf);
void save_open_settings(settings_w *sesskey, Conf *conf);
void load_settings(const char *section, Conf *conf);
void load_open_settings(settings_r *sesskey, Conf *conf);
void get_sesslist(struct sesslist *, int allocate);
void get_sesslist(struct sesslist *, bool allocate);
void do_defaults(const char *, Conf *);
void registry_cleanup(void);
@ -1507,35 +1508,35 @@ FontSpec *platform_default_fontspec(const char *name);
Terminal *term_init(Conf *, struct unicode_data *, TermWin *);
void term_free(Terminal *);
void term_size(Terminal *, int, int, int);
void term_paint(Terminal *, int, int, int, int, int);
void term_paint(Terminal *, int, int, int, int, bool);
void term_scroll(Terminal *, int, int);
void term_scroll_to_selection(Terminal *, int);
void term_pwron(Terminal *, int);
void term_pwron(Terminal *, bool);
void term_clrsb(Terminal *);
void term_mouse(Terminal *, Mouse_Button, Mouse_Button, Mouse_Action,
int,int,int,int,int);
int, int, bool, bool, bool);
void term_key(Terminal *, Key_Sym, wchar_t *, size_t, unsigned int,
unsigned int);
void term_lost_clipboard_ownership(Terminal *, int clipboard);
void term_update(Terminal *);
void term_invalidate(Terminal *);
void term_blink(Terminal *, int set_cursor);
void term_blink(Terminal *, bool set_cursor);
void term_do_paste(Terminal *, const wchar_t *, int);
void term_nopaste(Terminal *);
int term_ldisc(Terminal *, int option);
bool term_ldisc(Terminal *, int option);
void term_copyall(Terminal *, const int *, int);
void term_reconfig(Terminal *, Conf *);
void term_request_copy(Terminal *, const int *clipboards, int n_clipboards);
void term_request_paste(Terminal *, int clipboard);
void term_seen_key_event(Terminal *);
int term_data(Terminal *, int is_stderr, const void *data, int len);
int term_data(Terminal *, bool is_stderr, const void *data, int len);
void term_provide_backend(Terminal *term, Backend *backend);
void term_provide_logctx(Terminal *term, LogContext *logctx);
void term_set_focus(Terminal *term, int has_focus);
void term_set_focus(Terminal *term, bool has_focus);
char *term_get_ttymode(Terminal *term, const char *mode);
int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input);
int format_arrow_key(char *buf, Terminal *term, int xkey, int ctrl);
int format_arrow_key(char *buf, Terminal *term, int xkey, bool ctrl);
/*
* Exports from logging.c.
@ -1653,15 +1654,15 @@ extern const struct BackendVtable ssh_backend;
Ldisc *ldisc_create(Conf *, Terminal *, Backend *, Seat *);
void ldisc_configure(Ldisc *, Conf *);
void ldisc_free(Ldisc *);
void ldisc_send(Ldisc *, const void *buf, int len, int interactive);
void ldisc_send(Ldisc *, const void *buf, int len, bool interactive);
void ldisc_echoedit_update(Ldisc *);
/*
* Exports from ldiscucs.c.
*/
void lpage_send(Ldisc *, int codepage, const char *buf, int len,
int interactive);
void luni_send(Ldisc *, const wchar_t * widebuf, int len, int interactive);
bool interactive);
void luni_send(Ldisc *, const wchar_t * widebuf, int len, bool interactive);
/*
* Exports from sshrand.c.
@ -1690,7 +1691,7 @@ void pinger_free(Pinger *);
*/
#include "misc.h"
int conf_launchable(Conf *conf);
bool conf_launchable(Conf *conf);
char const *conf_dest(Conf *conf);
/*
@ -1701,7 +1702,7 @@ void prepare_session(Conf *conf);
/*
* Exports from sercfg.c.
*/
void ser_setup_config_box(struct controlbox *b, int midsession,
void ser_setup_config_box(struct controlbox *b, bool midsession,
int parity_mask, int flow_mask);
/*
@ -1716,7 +1717,7 @@ extern const char ver[];
#define CP_UTF8 65001
#endif
/* void init_ucs(void); -- this is now in platform-specific headers */
int is_dbcs_leadbyte(int codepage, char byte);
bool is_dbcs_leadbyte(int codepage, char byte);
int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen,
wchar_t *wcstr, int wclen);
int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen,
@ -1766,7 +1767,7 @@ agent_pending_query *agent_query(
void (*callback)(void *, void *, int), void *callback_ctx);
void agent_cancel_query(agent_pending_query *);
void agent_query_synchronous(strbuf *in, void **out, int *outlen);
int agent_exists(void);
bool agent_exists(void);
/*
* Exports from wildcard.c
@ -1774,7 +1775,7 @@ int agent_exists(void);
const char *wc_error(int value);
int wc_match_pl(const char *wildcard, ptrlen target);
int wc_match(const char *wildcard, const char *target);
int wc_unescape(char *output, const char *wildcard);
bool wc_unescape(char *output, const char *wildcard);
/*
* Exports from frontend (windlg.c etc)
@ -1784,15 +1785,15 @@ void pgp_fingerprints(void);
* have_ssh_host_key() just returns true if a key of that type is
* already cached and false otherwise.
*/
int have_ssh_host_key(const char *host, int port, const char *keytype);
bool have_ssh_host_key(const char *host, int port, const char *keytype);
/*
* Exports from console frontends (wincons.c, uxcons.c)
* that aren't equivalents to things in windlg.c et al.
*/
extern int console_batch_mode;
extern bool console_batch_mode;
int console_get_userpass_input(prompts_t *p);
int is_interactive(void);
bool is_interactive(void);
void console_print_error_msg(const char *prefix, const char *msg);
void console_print_error_msg_fmt_v(
const char *prefix, const char *fmt, va_list ap);
@ -1824,7 +1825,7 @@ int cmdline_process_param(const char *, char *, int, Conf *);
void cmdline_run_saved(Conf *);
void cmdline_cleanup(void);
int cmdline_get_passwd_input(prompts_t *p);
int cmdline_host_ok(Conf *);
bool cmdline_host_ok(Conf *);
#define TOOLTYPE_FILETRANSFER 1
#define TOOLTYPE_NONNETWORK 2
#define TOOLTYPE_HOST_ARG 4
@ -1852,7 +1853,7 @@ void conf_filesel_handler(union control *ctrl, dlgparam *dlg,
void *data, int event);
void conf_fontsel_handler(union control *ctrl, dlgparam *dlg,
void *data, int event);
void setup_config_box(struct controlbox *b, int midsession,
void setup_config_box(struct controlbox *b, bool midsession,
int protocol, int protcfginfo);
/*
@ -1864,7 +1865,7 @@ typedef struct bidi_char {
} bidi_char;
int do_bidi(bidi_char *line, int count);
int do_shape(bidi_char *line, bidi_char *to, int count);
int is_rtl(int c);
bool is_rtl(int c);
/*
* X11 auth mechanisms we know about.
@ -1895,8 +1896,8 @@ enum {
*/
Filename *filename_from_str(const char *string);
const char *filename_to_str(const Filename *fn);
int filename_equal(const Filename *f1, const Filename *f2);
int filename_is_null(const Filename *fn);
bool filename_equal(const Filename *f1, const Filename *f2);
bool filename_is_null(const Filename *fn);
Filename *filename_copy(const Filename *fn);
void filename_free(Filename *fn);
void filename_serialise(BinarySink *bs, const Filename *f);
@ -1904,7 +1905,7 @@ Filename *filename_deserialise(BinarySource *src);
char *get_username(void); /* return value needs freeing */
char *get_random_data(int bytes, const char *device); /* used in cmdgen.c */
char filename_char_sanitise(char c); /* rewrite special pathname chars */
int open_for_write_would_lose_data(const Filename *fn);
bool open_for_write_would_lose_data(const Filename *fn);
/*
* Exports and imports from timing.c.
@ -1999,7 +2000,7 @@ int open_for_write_would_lose_data(const Filename *fn);
typedef void (*timer_fn_t)(void *ctx, unsigned long now);
unsigned long schedule_timer(int ticks, timer_fn_t fn, void *ctx);
void expire_timer_context(void *ctx);
int run_timers(unsigned long now, unsigned long *next);
bool run_timers(unsigned long now, unsigned long *next);
void timer_change_notify(unsigned long next);
unsigned long timing_last_clock(void);
@ -2031,8 +2032,8 @@ unsigned long timing_last_clock(void);
*/
typedef void (*toplevel_callback_fn_t)(void *ctx);
void queue_toplevel_callback(toplevel_callback_fn_t fn, void *ctx);
int run_toplevel_callbacks(void);
int toplevel_callback_pending(void);
bool run_toplevel_callbacks(void);
bool toplevel_callback_pending(void);
void delete_callbacks_for_context(void *ctx);
/*
@ -2047,7 +2048,7 @@ void delete_callbacks_for_context(void *ctx);
struct IdempotentCallback {
toplevel_callback_fn_t fn;
void *ctx;
int queued;
bool queued;
};
void queue_idempotent_callback(struct IdempotentCallback *ic);

24
raw.c
View File

@ -13,11 +13,11 @@
typedef struct Raw Raw;
struct Raw {
Socket *s;
int closed_on_socket_error;
bool closed_on_socket_error;
int bufsize;
Seat *seat;
LogContext *logctx;
int sent_console_eof, sent_socket_eof, session_started;
bool sent_console_eof, sent_socket_eof, session_started;
Conf *conf;
@ -57,7 +57,7 @@ static void raw_check_close(Raw *raw)
}
static void raw_closing(Plug *plug, const char *error_msg, int error_code,
int calling_back)
bool calling_back)
{
Raw *raw = container_of(plug, Raw, plug);
@ -122,7 +122,7 @@ static const PlugVtable Raw_plugvt = {
static const char *raw_init(Seat *seat, Backend **backend_handle,
LogContext *logctx, Conf *conf,
const char *host, int port, char **realhost,
int nodelay, int keepalive)
bool nodelay, bool keepalive)
{
SockAddr *addr;
const char *err;
@ -161,8 +161,8 @@ static const char *raw_init(Seat *seat, Backend **backend_handle,
/*
* Open socket.
*/
raw->s = new_connection(addr, *realhost, port, 0, 1, nodelay, keepalive,
&raw->plug, conf);
raw->s = new_connection(addr, *realhost, port, false, true, nodelay,
keepalive, &raw->plug, conf);
if ((err = sk_socket_error(raw->s)) != NULL)
return err;
@ -255,15 +255,15 @@ static const SessionSpecial *raw_get_specials(Backend *be)
return NULL;
}
static int raw_connected(Backend *be)
static bool raw_connected(Backend *be)
{
Raw *raw = container_of(be, Raw, backend);
return raw->s != NULL;
}
static int raw_sendok(Backend *be)
static bool raw_sendok(Backend *be)
{
return 1;
return true;
}
static void raw_unthrottle(Backend *be, int backlog)
@ -272,11 +272,11 @@ static void raw_unthrottle(Backend *be, int backlog)
sk_set_frozen(raw->s, backlog > RAW_MAX_BACKLOG);
}
static int raw_ldisc(Backend *be, int option)
static bool raw_ldisc(Backend *be, int option)
{
if (option == LD_EDIT || option == LD_ECHO)
return 1;
return 0;
return true;
return false;
}
static void raw_provide_ldisc(Backend *be, Ldisc *ldisc)

View File

@ -14,10 +14,10 @@
typedef struct Rlogin Rlogin;
struct Rlogin {
Socket *s;
int closed_on_socket_error;
bool closed_on_socket_error;
int bufsize;
int firstbyte;
int cansize;
bool firstbyte;
bool cansize;
int term_width, term_height;
Seat *seat;
LogContext *logctx;
@ -47,7 +47,7 @@ static void rlogin_log(Plug *plug, int type, SockAddr *addr, int port,
}
static void rlogin_closing(Plug *plug, const char *error_msg, int error_code,
int calling_back)
bool calling_back)
{
Rlogin *rlogin = container_of(plug, Rlogin, plug);
@ -80,7 +80,7 @@ static void rlogin_receive(Plug *plug, int urgent, char *data, int len)
c = *data++;
len--;
if (c == '\x80') {
rlogin->cansize = 1;
rlogin->cansize = true;
backend_size(&rlogin->backend,
rlogin->term_width, rlogin->term_height);
}
@ -101,7 +101,7 @@ static void rlogin_receive(Plug *plug, int urgent, char *data, int len)
data++;
len--;
}
rlogin->firstbyte = 0;
rlogin->firstbyte = false;
}
if (len > 0)
c_write(rlogin, data, len);
@ -153,7 +153,7 @@ static const PlugVtable Rlogin_plugvt = {
static const char *rlogin_init(Seat *seat, Backend **backend_handle,
LogContext *logctx, Conf *conf,
const char *host, int port, char **realhost,
int nodelay, int keepalive)
bool nodelay, bool keepalive)
{
SockAddr *addr;
const char *err;
@ -171,8 +171,8 @@ static const char *rlogin_init(Seat *seat, Backend **backend_handle,
rlogin->logctx = logctx;
rlogin->term_width = conf_get_int(conf, CONF_width);
rlogin->term_height = conf_get_int(conf, CONF_height);
rlogin->firstbyte = 1;
rlogin->cansize = 0;
rlogin->firstbyte = true;
rlogin->cansize = false;
rlogin->prompt = NULL;
rlogin->conf = conf_copy(conf);
*backend_handle = &rlogin->backend;
@ -194,7 +194,7 @@ static const char *rlogin_init(Seat *seat, Backend **backend_handle,
/*
* Open socket.
*/
rlogin->s = new_connection(addr, *realhost, port, 1, 0,
rlogin->s = new_connection(addr, *realhost, port, true, false,
nodelay, keepalive, &rlogin->plug, conf);
if ((err = sk_socket_error(rlogin->s)) != NULL)
return err;
@ -346,16 +346,16 @@ static const SessionSpecial *rlogin_get_specials(Backend *be)
return NULL;
}
static int rlogin_connected(Backend *be)
static bool rlogin_connected(Backend *be)
{
Rlogin *rlogin = container_of(be, Rlogin, backend);
return rlogin->s != NULL;
}
static int rlogin_sendok(Backend *be)
static bool rlogin_sendok(Backend *be)
{
/* Rlogin *rlogin = container_of(be, Rlogin, backend); */
return 1;
return true;
}
static void rlogin_unthrottle(Backend *be, int backlog)
@ -364,10 +364,10 @@ static void rlogin_unthrottle(Backend *be, int backlog)
sk_set_frozen(rlogin->s, backlog > RLOGIN_MAX_BACKLOG);
}
static int rlogin_ldisc(Backend *be, int option)
static bool rlogin_ldisc(Backend *be, int option)
{
/* Rlogin *rlogin = container_of(be, Rlogin, backend); */
return 0;
return false;
}
static void rlogin_provide_ldisc(Backend *be, Ldisc *ldisc)

View File

@ -256,7 +256,7 @@
typedef struct ScpReplyReceiver ScpReplyReceiver;
struct ScpReplyReceiver {
int err;
bool err;
unsigned code;
char *errmsg;
struct fxp_attrs attrs;
@ -371,12 +371,13 @@ typedef struct ScpSourceStackEntry ScpSourceStackEntry;
struct ScpSource {
SftpServer *sf;
int acks, expect_newline, eof, throttled, finished;
int acks;
bool expect_newline, eof, throttled, finished;
SshChannel *sc;
ScpSourceStackEntry *head;
int recursive;
int send_file_times;
bool recursive;
bool send_file_times;
strbuf *pending_commands[3];
int n_pending_commands;
@ -482,7 +483,7 @@ static void scp_source_push_name(
static void scp_source_free(ScpServer *s);
static int scp_source_send(ScpServer *s, const void *data, size_t length);
static void scp_source_eof(ScpServer *s);
static void scp_source_throttle(ScpServer *s, int throttled);
static void scp_source_throttle(ScpServer *s, bool throttled);
static struct ScpServerVtable ScpSource_ScpServer_vt = {
scp_source_free,
@ -899,7 +900,7 @@ static int scp_source_send(ScpServer *s, const void *vdata, size_t length)
return 0;
}
static void scp_source_throttle(ScpServer *s, int throttled)
static void scp_source_throttle(ScpServer *s, bool throttled)
{
ScpSource *scp = container_of(s, ScpSource, scpserver);
@ -937,10 +938,10 @@ struct ScpSink {
uint64_t file_offset, file_size;
unsigned long atime, mtime;
int got_file_times;
bool got_file_times;
bufchain data;
int input_eof;
bool input_eof;
strbuf *command;
char command_chr;
@ -968,10 +969,10 @@ struct ScpSinkStackEntry {
* should be created _as_ - regardless of the filename in the 'C'
* command.
*/
int isdir;
bool isdir;
};
static void scp_sink_push(ScpSink *scp, ptrlen pathname, int isdir)
static void scp_sink_push(ScpSink *scp, ptrlen pathname, bool isdir)
{
ScpSinkStackEntry *node = snew_plus(ScpSinkStackEntry, pathname.len);
char *p = snew_plus_get_aux(node);
@ -995,7 +996,7 @@ static void scp_sink_pop(ScpSink *scp)
static void scp_sink_free(ScpServer *s);
static int scp_sink_send(ScpServer *s, const void *data, size_t length);
static void scp_sink_eof(ScpServer *s);
static void scp_sink_throttle(ScpServer *s, int throttled) {}
static void scp_sink_throttle(ScpServer *s, bool throttled) {}
static struct ScpServerVtable ScpSink_ScpServer_vt = {
scp_sink_free,
@ -1012,7 +1013,7 @@ static void scp_sink_start_callback(void *vscp)
static ScpSink *scp_sink_new(
SshChannel *sc, const SftpServerVtable *sftpserver_vt, ptrlen pathname,
int pathname_is_definitely_dir)
bool pathname_is_definitely_dir)
{
ScpSink *scp = snew(ScpSink);
memset(scp, 0, sizeof(*scp));
@ -1295,7 +1296,7 @@ static void scp_error_free(ScpServer *s);
static int scp_error_send(ScpServer *s, const void *data, size_t length)
{ return 0; }
static void scp_error_eof(ScpServer *s) {}
static void scp_error_throttle(ScpServer *s, int throttled) {}
static void scp_error_throttle(ScpServer *s, bool throttled) {}
static struct ScpServerVtable ScpError_ScpServer_vt = {
scp_error_free,
@ -1353,8 +1354,8 @@ static void scp_error_free(ScpServer *s)
ScpServer *scp_recognise_exec(
SshChannel *sc, const SftpServerVtable *sftpserver_vt, ptrlen command)
{
int recursive = false, preserve = false;
int targetshouldbedirectory = false;
bool recursive = false, preserve = false;
bool targetshouldbedirectory = false;
ptrlen command_orig = command;
if (!ptrlen_startswith(command, PTRLEN_LITERAL("scp "), &command))

View File

@ -124,7 +124,7 @@ static void serial_flow_handler(union control *ctrl, dlgparam *dlg,
}
}
void ser_setup_config_box(struct controlbox *b, int midsession,
void ser_setup_config_box(struct controlbox *b, bool midsession,
int parity_mask, int flow_mask)
{
struct controlset *s;

View File

@ -23,13 +23,13 @@ typedef struct sesschan {
LogPolicy logpolicy;
Seat seat;
int want_pty;
bool want_pty;
struct ssh_ttymodes ttymodes;
int wc, hc, wp, hp;
strbuf *termtype;
int ignoring_input;
int seen_eof, seen_exit;
bool ignoring_input;
bool seen_eof, seen_exit;
Plug xfwd_plug;
int n_x11_sockets;
@ -48,25 +48,25 @@ typedef struct sesschan {
} sesschan;
static void sesschan_free(Channel *chan);
static int sesschan_send(Channel *chan, int is_stderr, const void *, int);
static int sesschan_send(Channel *chan, bool is_stderr, const void *, int);
static void sesschan_send_eof(Channel *chan);
static char *sesschan_log_close_msg(Channel *chan);
static int sesschan_want_close(Channel *, int, int);
static void sesschan_set_input_wanted(Channel *chan, int wanted);
static int sesschan_run_shell(Channel *chan);
static int sesschan_run_command(Channel *chan, ptrlen command);
static int sesschan_run_subsystem(Channel *chan, ptrlen subsys);
static int sesschan_enable_x11_forwarding(
Channel *chan, int oneshot, ptrlen authproto, ptrlen authdata,
static bool sesschan_want_close(Channel *, bool, bool);
static void sesschan_set_input_wanted(Channel *chan, bool wanted);
static bool sesschan_run_shell(Channel *chan);
static bool sesschan_run_command(Channel *chan, ptrlen command);
static bool sesschan_run_subsystem(Channel *chan, ptrlen subsys);
static bool sesschan_enable_x11_forwarding(
Channel *chan, bool oneshot, ptrlen authproto, ptrlen authdata,
unsigned screen_number);
static int sesschan_enable_agent_forwarding(Channel *chan);
static int sesschan_allocate_pty(
static bool sesschan_enable_agent_forwarding(Channel *chan);
static bool sesschan_allocate_pty(
Channel *chan, ptrlen termtype, unsigned width, unsigned height,
unsigned pixwidth, unsigned pixheight, struct ssh_ttymodes modes);
static int sesschan_set_env(Channel *chan, ptrlen var, ptrlen value);
static int sesschan_send_break(Channel *chan, unsigned length);
static int sesschan_send_signal(Channel *chan, ptrlen signame);
static int sesschan_change_window_size(
static bool sesschan_set_env(Channel *chan, ptrlen var, ptrlen value);
static bool sesschan_send_break(Channel *chan, unsigned length);
static bool sesschan_send_signal(Channel *chan, ptrlen signame);
static bool sesschan_change_window_size(
Channel *chan, unsigned width, unsigned height,
unsigned pixwidth, unsigned pixheight);
@ -95,7 +95,7 @@ static const struct ChannelVtable sesschan_channelvt = {
chan_no_request_response,
};
static int sftp_chan_send(Channel *chan, int is_stderr, const void *, int);
static int sftp_chan_send(Channel *chan, bool is_stderr, const void *, int);
static void sftp_chan_send_eof(Channel *chan);
static char *sftp_log_close_msg(Channel *chan);
@ -124,9 +124,9 @@ static const struct ChannelVtable sftp_channelvt = {
chan_no_request_response,
};
static int scp_chan_send(Channel *chan, int is_stderr, const void *, int);
static int scp_chan_send(Channel *chan, bool is_stderr, const void *, int);
static void scp_chan_send_eof(Channel *chan);
static void scp_set_input_wanted(Channel *chan, int wanted);
static void scp_set_input_wanted(Channel *chan, bool wanted);
static char *scp_log_close_msg(Channel *chan);
static const struct ChannelVtable scp_channelvt = {
@ -166,11 +166,11 @@ static const LogPolicyVtable sesschan_logpolicy_vt = {
sesschan_logging_error,
};
static int sesschan_seat_output(Seat *, int is_stderr, const void *, int);
static int sesschan_seat_eof(Seat *);
static int sesschan_seat_output(Seat *, bool is_stderr, const void *, int);
static bool sesschan_seat_eof(Seat *);
static void sesschan_notify_remote_exit(Seat *seat);
static void sesschan_connection_fatal(Seat *seat, const char *message);
static int sesschan_get_window_pixel_size(Seat *seat, int *width, int *height);
static bool sesschan_get_window_pixel_size(Seat *seat, int *w, int *h);
static const SeatVtable sesschan_seat_vt = {
sesschan_seat_output,
@ -241,7 +241,7 @@ static void sesschan_free(Channel *chan)
sfree(sess);
}
static int sesschan_send(Channel *chan, int is_stderr,
static int sesschan_send(Channel *chan, bool is_stderr,
const void *data, int length)
{
sesschan *sess = container_of(chan, sesschan, chan);
@ -264,7 +264,7 @@ static char *sesschan_log_close_msg(Channel *chan)
return dupstr("Session channel closed");
}
static void sesschan_set_input_wanted(Channel *chan, int wanted)
static void sesschan_set_input_wanted(Channel *chan, bool wanted)
{
/* I don't think we need to do anything here */
}
@ -277,7 +277,7 @@ static void sesschan_start_backend(sesschan *sess, const char *cmd)
backend_size(sess->backend, sess->wc, sess->hc);
}
int sesschan_run_shell(Channel *chan)
bool sesschan_run_shell(Channel *chan)
{
sesschan *sess = container_of(chan, sesschan, chan);
@ -288,7 +288,7 @@ int sesschan_run_shell(Channel *chan)
return true;
}
int sesschan_run_command(Channel *chan, ptrlen command)
bool sesschan_run_command(Channel *chan, ptrlen command)
{
sesschan *sess = container_of(chan, sesschan, chan);
@ -310,7 +310,7 @@ int sesschan_run_command(Channel *chan, ptrlen command)
return true;
}
int sesschan_run_subsystem(Channel *chan, ptrlen subsys)
bool sesschan_run_subsystem(Channel *chan, ptrlen subsys)
{
sesschan *sess = container_of(chan, sesschan, chan);
@ -328,7 +328,7 @@ static void fwd_log(Plug *plug, int type, SockAddr *addr, int port,
const char *error_msg, int error_code)
{ /* don't expect any weirdnesses from a listening socket */ }
static void fwd_closing(Plug *plug, const char *error_msg, int error_code,
int calling_back)
bool calling_back)
{ /* not here, either */ }
static int xfwd_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
@ -344,13 +344,13 @@ static int xfwd_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
s = constructor(ctx, plug);
if ((err = sk_socket_error(s)) != NULL) {
portfwd_raw_free(chan);
return true;
return 1;
}
pi = sk_peer_info(s);
portfwd_raw_setup(chan, s, ssh_serverside_x11_open(sess->c->cl, chan, pi));
sk_free_peer_info(pi);
return false;
return 0;
}
static const PlugVtable xfwd_plugvt = {
@ -361,8 +361,8 @@ static const PlugVtable xfwd_plugvt = {
xfwd_accepting,
};
int sesschan_enable_x11_forwarding(
Channel *chan, int oneshot, ptrlen authproto, ptrlen authdata_hex,
bool sesschan_enable_x11_forwarding(
Channel *chan, bool oneshot, ptrlen authproto, ptrlen authdata_hex,
unsigned screen_number)
{
sesschan *sess = container_of(chan, sesschan, chan);
@ -420,11 +420,11 @@ static int agentfwd_accepting(
s = constructor(ctx, plug);
if ((err = sk_socket_error(s)) != NULL) {
portfwd_raw_free(chan);
return true;
return 1;
}
portfwd_raw_setup(chan, s, ssh_serverside_agent_open(sess->c->cl, chan));
return false;
return 0;
}
static const PlugVtable agentfwd_plugvt = {
@ -435,7 +435,7 @@ static const PlugVtable agentfwd_plugvt = {
agentfwd_accepting,
};
int sesschan_enable_agent_forwarding(Channel *chan)
bool sesschan_enable_agent_forwarding(Channel *chan)
{
sesschan *sess = container_of(chan, sesschan, chan);
char *error, *socketname, *dir_prefix;
@ -459,7 +459,7 @@ int sesschan_enable_agent_forwarding(Channel *chan)
return sess->agentfwd_socket != NULL;
}
int sesschan_allocate_pty(
bool sesschan_allocate_pty(
Channel *chan, ptrlen termtype, unsigned width, unsigned height,
unsigned pixwidth, unsigned pixheight, struct ssh_ttymodes modes)
{
@ -483,7 +483,7 @@ int sesschan_allocate_pty(
return true;
}
int sesschan_set_env(Channel *chan, ptrlen var, ptrlen value)
bool sesschan_set_env(Channel *chan, ptrlen var, ptrlen value)
{
sesschan *sess = container_of(chan, sesschan, chan);
@ -495,7 +495,7 @@ int sesschan_set_env(Channel *chan, ptrlen var, ptrlen value)
return true;
}
int sesschan_send_break(Channel *chan, unsigned length)
bool sesschan_send_break(Channel *chan, unsigned length)
{
sesschan *sess = container_of(chan, sesschan, chan);
@ -511,7 +511,7 @@ int sesschan_send_break(Channel *chan, unsigned length)
return false;
}
int sesschan_send_signal(Channel *chan, ptrlen signame)
bool sesschan_send_signal(Channel *chan, ptrlen signame)
{
sesschan *sess = container_of(chan, sesschan, chan);
@ -533,7 +533,7 @@ int sesschan_send_signal(Channel *chan, ptrlen signame)
return true;
}
int sesschan_change_window_size(
bool sesschan_change_window_size(
Channel *chan, unsigned width, unsigned height,
unsigned pixwidth, unsigned pixheight)
{
@ -554,7 +554,7 @@ int sesschan_change_window_size(
}
static int sesschan_seat_output(
Seat *seat, int is_stderr, const void *data, int len)
Seat *seat, bool is_stderr, const void *data, int len)
{
sesschan *sess = container_of(seat, sesschan, seat);
return sshfwd_write_ext(sess->c, is_stderr, data, len);
@ -573,7 +573,7 @@ static void sesschan_check_close_callback(void *vctx)
sshfwd_initiate_close(sess->c, NULL);
}
static int sesschan_want_close(Channel *chan, int seen_eof, int rcvd_eof)
static bool sesschan_want_close(Channel *chan, bool seen_eof, bool rcvd_eof)
{
sesschan *sess = container_of(chan, sesschan, chan);
@ -585,7 +585,7 @@ static int sesschan_want_close(Channel *chan, int seen_eof, int rcvd_eof)
return (sess->seen_eof && sess->seen_exit);
}
static int sesschan_seat_eof(Seat *seat)
static bool sesschan_seat_eof(Seat *seat)
{
sesschan *sess = container_of(seat, sesschan, seat);
@ -633,7 +633,7 @@ static void sesschan_connection_fatal(Seat *seat, const char *message)
sess->ignoring_input = true;
}
static int sesschan_get_window_pixel_size(Seat *seat, int *width, int *height)
static bool sesschan_get_window_pixel_size(Seat *seat, int *width, int *height)
{
sesschan *sess = container_of(seat, sesschan, seat);
@ -647,7 +647,7 @@ static int sesschan_get_window_pixel_size(Seat *seat, int *width, int *height)
* Built-in SFTP subsystem.
*/
static int sftp_chan_send(Channel *chan, int is_stderr,
static int sftp_chan_send(Channel *chan, bool is_stderr,
const void *data, int length)
{
sesschan *sess = container_of(chan, sesschan, chan);
@ -695,7 +695,7 @@ static char *sftp_log_close_msg(Channel *chan)
* Built-in SCP subsystem.
*/
static int scp_chan_send(Channel *chan, int is_stderr,
static int scp_chan_send(Channel *chan, bool is_stderr,
const void *data, int length)
{
sesschan *sess = container_of(chan, sesschan, chan);
@ -713,7 +713,7 @@ static char *scp_log_close_msg(Channel *chan)
return dupstr("Session channel (SCP) closed");
}
static void scp_set_input_wanted(Channel *chan, int wanted)
static void scp_set_input_wanted(Channel *chan, bool wanted)
{
sesschan *sess = container_of(chan, sesschan, chan);
scp_throttle(sess->scpsrv, !wanted);

View File

@ -153,8 +153,8 @@ static bool gppb_raw(settings_r *sesskey, const char *name, bool def)
return sesskey ? read_setting_i(sesskey, name, def) != 0 : def;
}
static void gppb(settings_r *sesskey, const char *name, int def,
Conf *conf, conf_BOOL_NONE primary)
static void gppb(settings_r *sesskey, const char *name, bool def,
Conf *conf, int primary)
{
conf_set_bool(conf, primary, gppb_raw(sesskey, name, def));
}
@ -178,8 +178,8 @@ static void gppi(settings_r *sesskey, const char *name, int def,
* If there's no "=VALUE" (e.g. just NAME,NAME,NAME) then those keys
* are mapped to the empty string.
*/
static int gppmap(settings_r *sesskey, const char *name,
Conf *conf, int primary)
static bool gppmap(settings_r *sesskey, const char *name,
Conf *conf, int primary)
{
char *buf, *p, *q, *key, *val;
@ -247,7 +247,7 @@ static int gppmap(settings_r *sesskey, const char *name,
* names if include_values is false.
*/
static void wmap(settings_w *sesskey, char const *outkey, Conf *conf,
int primary, int include_values)
int primary, bool include_values)
{
char *buf, *p, *key, *realkey;
const char *val, *q;
@ -805,10 +805,10 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
gppfile(sesskey, "LogFileName", conf, CONF_logfilename);
gppi(sesskey, "LogType", 0, conf, CONF_logtype);
gppi(sesskey, "LogFileClash", LGXF_ASK, conf, CONF_logxfovr);
gppb(sesskey, "LogFlush", 1, conf, CONF_logflush);
gppb(sesskey, "LogHeader", 1, conf, CONF_logheader);
gppb(sesskey, "SSHLogOmitPasswords", 1, conf, CONF_logomitpass);
gppb(sesskey, "SSHLogOmitData", 0, conf, CONF_logomitdata);
gppb(sesskey, "LogFlush", true, conf, CONF_logflush);
gppb(sesskey, "LogHeader", true, conf, CONF_logheader);
gppb(sesskey, "SSHLogOmitPasswords", true, conf, CONF_logomitpass);
gppb(sesskey, "SSHLogOmitData", false, conf, CONF_logomitdata);
prot = gpps_raw(sesskey, "Protocol", "default");
conf_set_int(conf, CONF_protocol, default_protocol);
@ -828,7 +828,7 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
/* The CloseOnExit numbers are arranged in a different order from
* the standard FORCE_ON / FORCE_OFF / AUTO. */
i = gppi_raw(sesskey, "CloseOnExit", 1); conf_set_int(conf, CONF_close_on_exit, (i+1)%3);
gppb(sesskey, "WarnOnClose", 1, conf, CONF_warn_on_close);
gppb(sesskey, "WarnOnClose", true, conf, CONF_warn_on_close);
{
/* This is two values for backward compatibility with 0.50/0.51 */
int pingmin, pingsec;
@ -836,8 +836,8 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
pingsec = gppi_raw(sesskey, "PingIntervalSecs", 0);
conf_set_int(conf, CONF_ping_interval, pingmin * 60 + pingsec);
}
gppb(sesskey, "TCPNoDelay", 1, conf, CONF_tcp_nodelay);
gppb(sesskey, "TCPKeepalives", 0, conf, CONF_tcp_keepalives);
gppb(sesskey, "TCPNoDelay", true, conf, CONF_tcp_nodelay);
gppb(sesskey, "TCPKeepalives", false, conf, CONF_tcp_keepalives);
gpps(sesskey, "TerminalType", "xterm", conf, CONF_termtype);
gpps(sesskey, "TerminalSpeed", "38400,38400", conf, CONF_termspeed);
if (gppmap(sesskey, "TerminalModes", conf, CONF_ttymodes)) {
@ -894,7 +894,7 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
/* proxy settings */
gpps(sesskey, "ProxyExcludeList", "", conf, CONF_proxy_exclude_list);
i = gppi_raw(sesskey, "ProxyDNS", 1); conf_set_int(conf, CONF_proxy_dns, (i+1)%3);
gppb(sesskey, "ProxyLocalhost", 0, conf, CONF_even_proxy_localhost);
gppb(sesskey, "ProxyLocalhost", false, conf, CONF_even_proxy_localhost);
gppi(sesskey, "ProxyMethod", -1, conf, CONF_proxy_type);
if (conf_get_int(conf, CONF_proxy_type) == -1) {
int i;
@ -924,14 +924,15 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
gppi(sesskey, "ProxyLogToTerm", FORCE_OFF, conf, CONF_proxy_log_to_term);
gppmap(sesskey, "Environment", conf, CONF_environmt);
gpps(sesskey, "UserName", "", conf, CONF_username);
gppb(sesskey, "UserNameFromEnvironment", 0, conf, CONF_username_from_env);
gppb(sesskey, "UserNameFromEnvironment", false,
conf, CONF_username_from_env);
gpps(sesskey, "LocalUserName", "", conf, CONF_localusername);
gppb(sesskey, "NoPTY", 0, conf, CONF_nopty);
gppb(sesskey, "Compression", 0, conf, CONF_compression);
gppb(sesskey, "TryAgent", 1, conf, CONF_tryagent);
gppb(sesskey, "AgentFwd", 0, conf, CONF_agentfwd);
gppb(sesskey, "ChangeUsername", 0, conf, CONF_change_username);
gppb(sesskey, "GssapiFwd", 0, conf, CONF_gssapifwd);
gppb(sesskey, "NoPTY", false, conf, CONF_nopty);
gppb(sesskey, "Compression", false, conf, CONF_compression);
gppb(sesskey, "TryAgent", true, conf, CONF_tryagent);
gppb(sesskey, "AgentFwd", false, conf, CONF_agentfwd);
gppb(sesskey, "ChangeUsername", false, conf, CONF_change_username);
gppb(sesskey, "GssapiFwd", false, conf, CONF_gssapifwd);
gprefs(sesskey, "Cipher", "\0",
ciphernames, CIPHER_MAX, conf, CONF_ssh_cipherlist);
{
@ -996,33 +997,34 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
conf_set_int(conf, CONF_sshprot, sshprot);
}
gpps(sesskey, "LogHost", "", conf, CONF_loghost);
gppb(sesskey, "SSH2DES", 0, conf, CONF_ssh2_des_cbc);
gppb(sesskey, "SshNoAuth", 0, conf, CONF_ssh_no_userauth);
gppb(sesskey, "SshBanner", 1, conf, CONF_ssh_show_banner);
gppb(sesskey, "AuthTIS", 0, conf, CONF_try_tis_auth);
gppb(sesskey, "AuthKI", 1, conf, CONF_try_ki_auth);
gppb(sesskey, "AuthGSSAPI", 1, conf, CONF_try_gssapi_auth);
gppb(sesskey, "AuthGSSAPIKEX", 1, conf, CONF_try_gssapi_kex);
gppb(sesskey, "SSH2DES", false, conf, CONF_ssh2_des_cbc);
gppb(sesskey, "SshNoAuth", false, conf, CONF_ssh_no_userauth);
gppb(sesskey, "SshBanner", true, conf, CONF_ssh_show_banner);
gppb(sesskey, "AuthTIS", false, conf, CONF_try_tis_auth);
gppb(sesskey, "AuthKI", true, conf, CONF_try_ki_auth);
gppb(sesskey, "AuthGSSAPI", true, conf, CONF_try_gssapi_auth);
gppb(sesskey, "AuthGSSAPIKEX", true, conf, CONF_try_gssapi_kex);
#ifndef NO_GSSAPI
gprefs(sesskey, "GSSLibs", "\0",
gsslibkeywords, ngsslibs, conf, CONF_ssh_gsslist);
gppfile(sesskey, "GSSCustom", conf, CONF_ssh_gss_custom);
#endif
gppb(sesskey, "SshNoShell", 0, conf, CONF_ssh_no_shell);
gppb(sesskey, "SshNoShell", false, conf, CONF_ssh_no_shell);
gppfile(sesskey, "PublicKeyFile", conf, CONF_keyfile);
gpps(sesskey, "RemoteCommand", "", conf, CONF_remote_cmd);
gppb(sesskey, "RFCEnviron", 0, conf, CONF_rfc_environ);
gppb(sesskey, "PassiveTelnet", 0, conf, CONF_passive_telnet);
gppb(sesskey, "BackspaceIsDelete", 1, conf, CONF_bksp_is_delete);
gppb(sesskey, "RXVTHomeEnd", 0, conf, CONF_rxvt_homeend);
gppb(sesskey, "RFCEnviron", false, conf, CONF_rfc_environ);
gppb(sesskey, "PassiveTelnet", false, conf, CONF_passive_telnet);
gppb(sesskey, "BackspaceIsDelete", true, conf, CONF_bksp_is_delete);
gppb(sesskey, "RXVTHomeEnd", false, conf, CONF_rxvt_homeend);
gppi(sesskey, "LinuxFunctionKeys", 0, conf, CONF_funky_type);
gppb(sesskey, "NoApplicationKeys", 0, conf, CONF_no_applic_k);
gppb(sesskey, "NoApplicationCursors", 0, conf, CONF_no_applic_c);
gppb(sesskey, "NoMouseReporting", 0, conf, CONF_no_mouse_rep);
gppb(sesskey, "NoRemoteResize", 0, conf, CONF_no_remote_resize);
gppb(sesskey, "NoAltScreen", 0, conf, CONF_no_alt_screen);
gppb(sesskey, "NoRemoteWinTitle", 0, conf, CONF_no_remote_wintitle);
gppb(sesskey, "NoRemoteClearScroll", 0, conf, CONF_no_remote_clearscroll);
gppb(sesskey, "NoApplicationKeys", false, conf, CONF_no_applic_k);
gppb(sesskey, "NoApplicationCursors", false, conf, CONF_no_applic_c);
gppb(sesskey, "NoMouseReporting", false, conf, CONF_no_mouse_rep);
gppb(sesskey, "NoRemoteResize", false, conf, CONF_no_remote_resize);
gppb(sesskey, "NoAltScreen", false, conf, CONF_no_alt_screen);
gppb(sesskey, "NoRemoteWinTitle", false, conf, CONF_no_remote_wintitle);
gppb(sesskey, "NoRemoteClearScroll", false,
conf, CONF_no_remote_clearscroll);
{
/* Backward compatibility */
int no_remote_qtitle = gppi_raw(sesskey, "NoRemoteQTitle", 1);
@ -1033,37 +1035,38 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
no_remote_qtitle ? TITLE_EMPTY : TITLE_REAL,
conf, CONF_remote_qtitle_action);
}
gppb(sesskey, "NoDBackspace", 0, conf, CONF_no_dbackspace);
gppb(sesskey, "NoRemoteCharset", 0, conf, CONF_no_remote_charset);
gppb(sesskey, "ApplicationCursorKeys", 0, conf, CONF_app_cursor);
gppb(sesskey, "ApplicationKeypad", 0, conf, CONF_app_keypad);
gppb(sesskey, "NetHackKeypad", 0, conf, CONF_nethack_keypad);
gppb(sesskey, "AltF4", 1, conf, CONF_alt_f4);
gppb(sesskey, "AltSpace", 0, conf, CONF_alt_space);
gppb(sesskey, "AltOnly", 0, conf, CONF_alt_only);
gppb(sesskey, "ComposeKey", 0, conf, CONF_compose_key);
gppb(sesskey, "CtrlAltKeys", 1, conf, CONF_ctrlaltkeys);
gppb(sesskey, "NoDBackspace", false, conf, CONF_no_dbackspace);
gppb(sesskey, "NoRemoteCharset", false, conf, CONF_no_remote_charset);
gppb(sesskey, "ApplicationCursorKeys", false, conf, CONF_app_cursor);
gppb(sesskey, "ApplicationKeypad", false, conf, CONF_app_keypad);
gppb(sesskey, "NetHackKeypad", false, conf, CONF_nethack_keypad);
gppb(sesskey, "AltF4", true, conf, CONF_alt_f4);
gppb(sesskey, "AltSpace", false, conf, CONF_alt_space);
gppb(sesskey, "AltOnly", false, conf, CONF_alt_only);
gppb(sesskey, "ComposeKey", false, conf, CONF_compose_key);
gppb(sesskey, "CtrlAltKeys", true, conf, CONF_ctrlaltkeys);
#ifdef OSX_META_KEY_CONFIG
gppb(sesskey, "OSXOptionMeta", 1, conf, CONF_osx_option_meta);
gppb(sesskey, "OSXCommandMeta", 0, conf, CONF_osx_command_meta);
gppb(sesskey, "OSXOptionMeta", true, conf, CONF_osx_option_meta);
gppb(sesskey, "OSXCommandMeta", false, conf, CONF_osx_command_meta);
#endif
gppb(sesskey, "TelnetKey", 0, conf, CONF_telnet_keyboard);
gppb(sesskey, "TelnetRet", 1, conf, CONF_telnet_newline);
gppb(sesskey, "TelnetKey", false, conf, CONF_telnet_keyboard);
gppb(sesskey, "TelnetRet", true, conf, CONF_telnet_newline);
gppi(sesskey, "LocalEcho", AUTO, conf, CONF_localecho);
gppi(sesskey, "LocalEdit", AUTO, conf, CONF_localedit);
gpps(sesskey, "Answerback", "PuTTY", conf, CONF_answerback);
gppb(sesskey, "AlwaysOnTop", 0, conf, CONF_alwaysontop);
gppb(sesskey, "FullScreenOnAltEnter", 0, conf, CONF_fullscreenonaltenter);
gppb(sesskey, "HideMousePtr", 0, conf, CONF_hide_mouseptr);
gppb(sesskey, "SunkenEdge", 0, conf, CONF_sunken_edge);
gppb(sesskey, "AlwaysOnTop", false, conf, CONF_alwaysontop);
gppb(sesskey, "FullScreenOnAltEnter", false,
conf, CONF_fullscreenonaltenter);
gppb(sesskey, "HideMousePtr", false, conf, CONF_hide_mouseptr);
gppb(sesskey, "SunkenEdge", false, conf, CONF_sunken_edge);
gppi(sesskey, "WindowBorder", 1, conf, CONF_window_border);
gppi(sesskey, "CurType", 0, conf, CONF_cursor_type);
gppb(sesskey, "BlinkCur", 0, conf, CONF_blink_cur);
gppb(sesskey, "BlinkCur", false, conf, CONF_blink_cur);
/* pedantic compiler tells me I can't use conf, CONF_beep as an int * :-) */
gppi(sesskey, "Beep", 1, conf, CONF_beep);
gppi(sesskey, "BeepInd", 0, conf, CONF_beep_ind);
gppfile(sesskey, "BellWaveFile", conf, CONF_bell_wavefile);
gppb(sesskey, "BellOverload", 1, conf, CONF_bellovl);
gppb(sesskey, "BellOverload", true, conf, CONF_bellovl);
gppi(sesskey, "BellOverloadN", 5, conf, CONF_bellovl_n);
i = gppi_raw(sesskey, "BellOverloadT", 2*TICKSPERSEC
#ifdef PUTTY_UNIX_H
@ -1086,24 +1089,24 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
#endif
);
gppi(sesskey, "ScrollbackLines", 2000, conf, CONF_savelines);
gppb(sesskey, "DECOriginMode", 0, conf, CONF_dec_om);
gppb(sesskey, "AutoWrapMode", 1, conf, CONF_wrap_mode);
gppb(sesskey, "LFImpliesCR", 0, conf, CONF_lfhascr);
gppb(sesskey, "CRImpliesLF", 0, conf, CONF_crhaslf);
gppb(sesskey, "DisableArabicShaping", 0, conf, CONF_arabicshaping);
gppb(sesskey, "DisableBidi", 0, conf, CONF_bidi);
gppb(sesskey, "WinNameAlways", 1, conf, CONF_win_name_always);
gppb(sesskey, "DECOriginMode", false, conf, CONF_dec_om);
gppb(sesskey, "AutoWrapMode", true, conf, CONF_wrap_mode);
gppb(sesskey, "LFImpliesCR", false, conf, CONF_lfhascr);
gppb(sesskey, "CRImpliesLF", false, conf, CONF_crhaslf);
gppb(sesskey, "DisableArabicShaping", false, conf, CONF_arabicshaping);
gppb(sesskey, "DisableBidi", false, conf, CONF_bidi);
gppb(sesskey, "WinNameAlways", true, conf, CONF_win_name_always);
gpps(sesskey, "WinTitle", "", conf, CONF_wintitle);
gppi(sesskey, "TermWidth", 80, conf, CONF_width);
gppi(sesskey, "TermHeight", 24, conf, CONF_height);
gppfont(sesskey, "Font", conf, CONF_font);
gppi(sesskey, "FontQuality", FQ_DEFAULT, conf, CONF_font_quality);
gppi(sesskey, "FontVTMode", VT_UNICODE, conf, CONF_vtmode);
gppb(sesskey, "UseSystemColours", 0, conf, CONF_system_colour);
gppb(sesskey, "TryPalette", 0, conf, CONF_try_palette);
gppb(sesskey, "ANSIColour", 1, conf, CONF_ansi_colour);
gppb(sesskey, "Xterm256Colour", 1, conf, CONF_xterm_256_colour);
gppb(sesskey, "TrueColour", 1, conf, CONF_true_colour);
gppb(sesskey, "UseSystemColours", false, conf, CONF_system_colour);
gppb(sesskey, "TryPalette", false, conf, CONF_try_palette);
gppb(sesskey, "ANSIColour", true, conf, CONF_ansi_colour);
gppb(sesskey, "Xterm256Colour", true, conf, CONF_xterm_256_colour);
gppb(sesskey, "TrueColour", true, conf, CONF_true_colour);
i = gppi_raw(sesskey, "BoldAsColour", 1); conf_set_int(conf, CONF_bold_style, i+1);
for (i = 0; i < 22; i++) {
@ -1125,13 +1128,13 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
}
sfree(buf2);
}
gppb(sesskey, "RawCNP", 0, conf, CONF_rawcnp);
gppb(sesskey, "UTF8linedraw", 0, conf, CONF_utf8linedraw);
gppb(sesskey, "PasteRTF", 0, conf, CONF_rtf_paste);
gppb(sesskey, "RawCNP", false, conf, CONF_rawcnp);
gppb(sesskey, "UTF8linedraw", false, conf, CONF_utf8linedraw);
gppb(sesskey, "PasteRTF", false, conf, CONF_rtf_paste);
gppi(sesskey, "MouseIsXterm", 0, conf, CONF_mouse_is_xterm);
gppb(sesskey, "RectSelect", 0, conf, CONF_rect_select);
gppb(sesskey, "PasteControls", 0, conf, CONF_paste_controls);
gppb(sesskey, "MouseOverride", 1, conf, CONF_mouse_override);
gppb(sesskey, "RectSelect", false, conf, CONF_rect_select);
gppb(sesskey, "PasteControls", false, conf, CONF_paste_controls);
gppb(sesskey, "MouseOverride", true, conf, CONF_mouse_override);
for (i = 0; i < 256; i += 32) {
static const char *const defaults[] = {
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
@ -1171,25 +1174,26 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
* into a plausible default for the locale.
*/
gpps(sesskey, "LineCodePage", "", conf, CONF_line_codepage);
gppb(sesskey, "CJKAmbigWide", 0, conf, CONF_cjk_ambig_wide);
gppb(sesskey, "UTF8Override", 1, conf, CONF_utf8_override);
gppb(sesskey, "CJKAmbigWide", false, conf, CONF_cjk_ambig_wide);
gppb(sesskey, "UTF8Override", true, conf, CONF_utf8_override);
gpps(sesskey, "Printer", "", conf, CONF_printer);
gppb(sesskey, "CapsLockCyr", 0, conf, CONF_xlat_capslockcyr);
gppb(sesskey, "ScrollBar", 1, conf, CONF_scrollbar);
gppb(sesskey, "ScrollBarFullScreen", 0, conf, CONF_scrollbar_in_fullscreen);
gppb(sesskey, "ScrollOnKey", 0, conf, CONF_scroll_on_key);
gppb(sesskey, "ScrollOnDisp", 1, conf, CONF_scroll_on_disp);
gppb(sesskey, "EraseToScrollback", 1, conf, CONF_erase_to_scrollback);
gppb(sesskey, "CapsLockCyr", false, conf, CONF_xlat_capslockcyr);
gppb(sesskey, "ScrollBar", true, conf, CONF_scrollbar);
gppb(sesskey, "ScrollBarFullScreen", false,
conf, CONF_scrollbar_in_fullscreen);
gppb(sesskey, "ScrollOnKey", false, conf, CONF_scroll_on_key);
gppb(sesskey, "ScrollOnDisp", true, conf, CONF_scroll_on_disp);
gppb(sesskey, "EraseToScrollback", true, conf, CONF_erase_to_scrollback);
gppi(sesskey, "LockSize", 0, conf, CONF_resize_action);
gppb(sesskey, "BCE", 1, conf, CONF_bce);
gppb(sesskey, "BlinkText", 0, conf, CONF_blinktext);
gppb(sesskey, "X11Forward", 0, conf, CONF_x11_forward);
gppb(sesskey, "BCE", true, conf, CONF_bce);
gppb(sesskey, "BlinkText", false, conf, CONF_blinktext);
gppb(sesskey, "X11Forward", false, conf, CONF_x11_forward);
gpps(sesskey, "X11Display", "", conf, CONF_x11_display);
gppi(sesskey, "X11AuthType", X11_MIT, conf, CONF_x11_auth);
gppfile(sesskey, "X11AuthFile", conf, CONF_xauthfile);
gppb(sesskey, "LocalPortAcceptAll", 0, conf, CONF_lport_acceptall);
gppb(sesskey, "RemotePortAcceptAll", 0, conf, CONF_rport_acceptall);
gppb(sesskey, "LocalPortAcceptAll", false, conf, CONF_lport_acceptall);
gppb(sesskey, "RemotePortAcceptAll", false, conf, CONF_rport_acceptall);
gppmap(sesskey, "PortForwardings", conf, CONF_portfwd);
i = gppi_raw(sesskey, "BugIgnore1", 0); conf_set_int(conf, CONF_sshbug_ignore1, 2-i);
i = gppi_raw(sesskey, "BugPlainPW1", 0); conf_set_int(conf, CONF_sshbug_plainpw1, 2-i);
@ -1213,10 +1217,10 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
i = gppi_raw(sesskey, "BugWinadj", 0); conf_set_int(conf, CONF_sshbug_winadj, 2-i);
i = gppi_raw(sesskey, "BugChanReq", 0); conf_set_int(conf, CONF_sshbug_chanreq, 2-i);
conf_set_bool(conf, CONF_ssh_simple, false);
gppb(sesskey, "StampUtmp", 1, conf, CONF_stamp_utmp);
gppb(sesskey, "LoginShell", 1, conf, CONF_login_shell);
gppb(sesskey, "ScrollbarOnLeft", 0, conf, CONF_scrollbar_on_left);
gppb(sesskey, "ShadowBold", 0, conf, CONF_shadowbold);
gppb(sesskey, "StampUtmp", true, conf, CONF_stamp_utmp);
gppb(sesskey, "LoginShell", true, conf, CONF_login_shell);
gppb(sesskey, "ScrollbarOnLeft", false, conf, CONF_scrollbar_on_left);
gppb(sesskey, "ShadowBold", false, conf, CONF_shadowbold);
gppfont(sesskey, "BoldFont", conf, CONF_boldfont);
gppfont(sesskey, "WideFont", conf, CONF_widefont);
gppfont(sesskey, "WideBoldFont", conf, CONF_wideboldfont);
@ -1228,9 +1232,12 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
gppi(sesskey, "SerialParity", SER_PAR_NONE, conf, CONF_serparity);
gppi(sesskey, "SerialFlowControl", SER_FLOW_XONXOFF, conf, CONF_serflow);
gpps(sesskey, "WindowClass", "", conf, CONF_winclass);
gppb(sesskey, "ConnectionSharing", 0, conf, CONF_ssh_connection_sharing);
gppb(sesskey, "ConnectionSharingUpstream", 1, conf, CONF_ssh_connection_sharing_upstream);
gppb(sesskey, "ConnectionSharingDownstream", 1, conf, CONF_ssh_connection_sharing_downstream);
gppb(sesskey, "ConnectionSharing", false,
conf, CONF_ssh_connection_sharing);
gppb(sesskey, "ConnectionSharingUpstream", true,
conf, CONF_ssh_connection_sharing_upstream);
gppb(sesskey, "ConnectionSharingDownstream", true,
conf, CONF_ssh_connection_sharing_downstream);
gppmap(sesskey, "SSHManualHostKeys", conf, CONF_ssh_manual_hostkeys);
}
@ -1259,7 +1266,7 @@ static int sessioncmp(const void *av, const void *bv)
return strcmp(a, b); /* otherwise, compare normally */
}
void get_sesslist(struct sesslist *list, int allocate)
void get_sesslist(struct sesslist *list, bool allocate)
{
char otherbuf[2048];
int buflen, bufsize, i;

114
sftp.c
View File

@ -21,9 +21,9 @@ static void fxp_internal_error(const char *msg);
* Client-specific parts of the send- and receive-packet system.
*/
int sftp_send(struct sftp_packet *pkt)
bool sftp_send(struct sftp_packet *pkt)
{
int ret;
bool ret;
sftp_send_prepare(pkt);
ret = sftp_senddata(pkt->data, pkt->length);
sftp_pkt_free(pkt);
@ -61,7 +61,7 @@ struct sftp_packet *sftp_recv(void)
struct sftp_request {
unsigned id;
int registered;
bool registered;
void *userdata;
};
@ -132,7 +132,7 @@ static struct sftp_request *sftp_alloc_request(void)
*/
r = snew(struct sftp_request);
r->id = low + 1 + REQUEST_ID_OFFSET;
r->registered = 0;
r->registered = false;
r->userdata = NULL;
add234(sftp_requests, r);
return r;
@ -148,7 +148,7 @@ void sftp_cleanup_request(void)
void sftp_register(struct sftp_request *req)
{
req->registered = 1;
req->registered = true;
}
struct sftp_request *sftp_find_request(struct sftp_packet *pktin)
@ -248,7 +248,7 @@ int fxp_error_type(void)
/*
* Perform exchange of init/version packets. Return 0 on failure.
*/
int fxp_init(void)
bool fxp_init(void)
{
struct sftp_packet *pktout, *pktin;
unsigned long remotever;
@ -260,24 +260,24 @@ int fxp_init(void)
pktin = sftp_recv();
if (!pktin) {
fxp_internal_error("could not connect");
return 0;
return false;
}
if (pktin->type != SSH_FXP_VERSION) {
fxp_internal_error("did not receive FXP_VERSION");
sftp_pkt_free(pktin);
return 0;
return false;
}
remotever = get_uint32(pktin);
if (get_err(pktin)) {
fxp_internal_error("malformed FXP_VERSION packet");
sftp_pkt_free(pktin);
return 0;
return false;
}
if (remotever > SFTP_PROTO_VERSION) {
fxp_internal_error
("remote protocol is more advanced than we support");
sftp_pkt_free(pktin);
return 0;
return false;
}
/*
* In principle, this packet might also contain extension-
@ -287,7 +287,7 @@ int fxp_init(void)
*/
sftp_pkt_free(pktin);
return 1;
return true;
}
/*
@ -436,7 +436,7 @@ struct sftp_request *fxp_close_send(struct fxp_handle *handle)
return req;
}
int fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req)
bool fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req)
{
sfree(req);
fxp_got_status(pktin);
@ -459,16 +459,13 @@ struct sftp_request *fxp_mkdir_send(const char *path,
return req;
}
int fxp_mkdir_recv(struct sftp_packet *pktin, struct sftp_request *req)
bool fxp_mkdir_recv(struct sftp_packet *pktin, struct sftp_request *req)
{
int id;
sfree(req);
id = fxp_got_status(pktin);
sftp_pkt_free(pktin);
if (id != 1) {
return 0;
}
return 1;
return id == 1;
}
struct sftp_request *fxp_rmdir_send(const char *path)
@ -484,16 +481,13 @@ struct sftp_request *fxp_rmdir_send(const char *path)
return req;
}
int fxp_rmdir_recv(struct sftp_packet *pktin, struct sftp_request *req)
bool fxp_rmdir_recv(struct sftp_packet *pktin, struct sftp_request *req)
{
int id;
sfree(req);
id = fxp_got_status(pktin);
sftp_pkt_free(pktin);
if (id != 1) {
return 0;
}
return 1;
return id == 1;
}
struct sftp_request *fxp_remove_send(const char *fname)
@ -509,16 +503,13 @@ struct sftp_request *fxp_remove_send(const char *fname)
return req;
}
int fxp_remove_recv(struct sftp_packet *pktin, struct sftp_request *req)
bool fxp_remove_recv(struct sftp_packet *pktin, struct sftp_request *req)
{
int id;
sfree(req);
id = fxp_got_status(pktin);
sftp_pkt_free(pktin);
if (id != 1) {
return 0;
}
return 1;
return id == 1;
}
struct sftp_request *fxp_rename_send(const char *srcfname,
@ -536,16 +527,13 @@ struct sftp_request *fxp_rename_send(const char *srcfname,
return req;
}
int fxp_rename_recv(struct sftp_packet *pktin, struct sftp_request *req)
bool fxp_rename_recv(struct sftp_packet *pktin, struct sftp_request *req)
{
int id;
sfree(req);
id = fxp_got_status(pktin);
sftp_pkt_free(pktin);
if (id != 1) {
return 0;
}
return 1;
return id == 1;
}
/*
@ -565,19 +553,19 @@ struct sftp_request *fxp_stat_send(const char *fname)
return req;
}
static int fxp_got_attrs(struct sftp_packet *pktin, struct fxp_attrs *attrs)
static bool fxp_got_attrs(struct sftp_packet *pktin, struct fxp_attrs *attrs)
{
get_fxp_attrs(pktin, attrs);
if (get_err(pktin)) {
fxp_internal_error("malformed SSH_FXP_ATTRS packet");
sftp_pkt_free(pktin);
return 0;
return false;
}
sftp_pkt_free(pktin);
return 1;
return true;
}
int fxp_stat_recv(struct sftp_packet *pktin, struct sftp_request *req,
bool fxp_stat_recv(struct sftp_packet *pktin, struct sftp_request *req,
struct fxp_attrs *attrs)
{
sfree(req);
@ -586,7 +574,7 @@ int fxp_stat_recv(struct sftp_packet *pktin, struct sftp_request *req,
} else {
fxp_got_status(pktin);
sftp_pkt_free(pktin);
return 0;
return false;
}
}
@ -603,18 +591,18 @@ struct sftp_request *fxp_fstat_send(struct fxp_handle *handle)
return req;
}
int fxp_fstat_recv(struct sftp_packet *pktin, struct sftp_request *req,
struct fxp_attrs *attrs)
bool fxp_fstat_recv(struct sftp_packet *pktin, struct sftp_request *req,
struct fxp_attrs *attrs)
{
sfree(req);
if (pktin->type == SSH_FXP_ATTRS) {
return fxp_got_attrs(pktin, attrs);
sftp_pkt_free(pktin);
return 1;
return true;
} else {
fxp_got_status(pktin);
sftp_pkt_free(pktin);
return 0;
return false;
}
}
@ -636,16 +624,13 @@ struct sftp_request *fxp_setstat_send(const char *fname,
return req;
}
int fxp_setstat_recv(struct sftp_packet *pktin, struct sftp_request *req)
bool fxp_setstat_recv(struct sftp_packet *pktin, struct sftp_request *req)
{
int id;
sfree(req);
id = fxp_got_status(pktin);
sftp_pkt_free(pktin);
if (id != 1) {
return 0;
}
return 1;
return id == 1;
}
struct sftp_request *fxp_fsetstat_send(struct fxp_handle *handle,
@ -663,16 +648,13 @@ struct sftp_request *fxp_fsetstat_send(struct fxp_handle *handle,
return req;
}
int fxp_fsetstat_recv(struct sftp_packet *pktin, struct sftp_request *req)
bool fxp_fsetstat_recv(struct sftp_packet *pktin, struct sftp_request *req)
{
int id;
sfree(req);
id = fxp_got_status(pktin);
sftp_pkt_free(pktin);
if (id != 1) {
return 0;
}
return 1;
return id == 1;
}
/*
@ -826,7 +808,7 @@ struct sftp_request *fxp_write_send(struct fxp_handle *handle,
return req;
}
int fxp_write_recv(struct sftp_packet *pktin, struct sftp_request *req)
bool fxp_write_recv(struct sftp_packet *pktin, struct sftp_request *req)
{
sfree(req);
fxp_got_status(pktin);
@ -899,7 +881,8 @@ struct req {
struct fxp_xfer {
uint64_t offset, furthestdata, filesize;
int req_totalsize, req_maxsize, eof, err;
int req_totalsize, req_maxsize;
bool eof, err;
struct fxp_handle *fh;
struct req *head, *tail;
};
@ -913,14 +896,14 @@ static struct fxp_xfer *xfer_init(struct fxp_handle *fh, uint64_t offset)
xfer->head = xfer->tail = NULL;
xfer->req_totalsize = 0;
xfer->req_maxsize = 1048576;
xfer->err = 0;
xfer->err = false;
xfer->filesize = UINT64_MAX;
xfer->furthestdata = 0;
return xfer;
}
int xfer_done(struct fxp_xfer *xfer)
bool xfer_done(struct fxp_xfer *xfer)
{
/*
* We're finished if we've seen EOF _and_ there are no
@ -1059,10 +1042,10 @@ int xfer_download_gotpkt(struct fxp_xfer *xfer, struct sftp_packet *pktin)
void xfer_set_error(struct fxp_xfer *xfer)
{
xfer->err = 1;
xfer->err = true;
}
int xfer_download_data(struct fxp_xfer *xfer, void **buf, int *len)
bool xfer_download_data(struct fxp_xfer *xfer, void **buf, int *len)
{
void *retbuf = NULL;
int retlen = 0;
@ -1098,9 +1081,9 @@ int xfer_download_data(struct fxp_xfer *xfer, void **buf, int *len)
if (retbuf) {
*buf = retbuf;
*len = retlen;
return 1;
return true;
} else
return 0;
return false;
}
struct fxp_xfer *xfer_upload_init(struct fxp_handle *fh, uint64_t offset)
@ -1115,17 +1098,14 @@ struct fxp_xfer *xfer_upload_init(struct fxp_handle *fh, uint64_t offset)
* from us is whether the outstanding requests have been
* handled once that's done.
*/
xfer->eof = 1;
xfer->eof = true;
return xfer;
}
int xfer_upload_ready(struct fxp_xfer *xfer)
bool xfer_upload_ready(struct fxp_xfer *xfer)
{
if (sftp_sendbuffer() == 0)
return 1;
else
return 0;
return sftp_sendbuffer() == 0;
}
void xfer_upload_data(struct fxp_xfer *xfer, char *buffer, int len)
@ -1168,7 +1148,7 @@ int xfer_upload_gotpkt(struct fxp_xfer *xfer, struct sftp_packet *pktin)
{
struct sftp_request *rreq;
struct req *rr, *prev, *next;
int ret;
bool ret;
rreq = sftp_find_request(pktin);
if (!rreq)
@ -1180,7 +1160,7 @@ int xfer_upload_gotpkt(struct fxp_xfer *xfer, struct sftp_packet *pktin)
}
ret = fxp_write_recv(pktin, rreq);
#ifdef DEBUG_UPLOAD
printf("write request %p has returned [%d]\n", rr, ret);
printf("write request %p has returned [%d]\n", rr, ret ? 1 : 0);
#endif
/*

59
sftp.h
View File

@ -62,16 +62,17 @@
* able to get at these functions.
*
* sftp_recvdata must never return less than len. It either blocks
* until len is available, or it returns failure.
* until len is available and then returns true, or it returns false
* for failure.
*
* Both functions return 1 on success, 0 on failure.
* sftp_senddata returns true on success, false on failure.
*
* sftp_sendbuffer returns the size of the backlog of data in the
* transmit queue.
*/
int sftp_senddata(char *data, int len);
bool sftp_senddata(char *data, int len);
int sftp_sendbuffer(void);
int sftp_recvdata(char *data, int len);
bool sftp_recvdata(char *data, int len);
/*
* Free sftp_requests
@ -144,13 +145,13 @@ void sftp_send_prepare(struct sftp_packet *pkt);
* that many bytes into pkt->data, and call sftp_recv_finish to set up
* the type code and BinarySource. */
struct sftp_packet *sftp_recv_prepare(unsigned length);
int sftp_recv_finish(struct sftp_packet *pkt);
bool sftp_recv_finish(struct sftp_packet *pkt);
/* Either kind of packet can be freed afterwards with sftp_pkt_free. */
void sftp_pkt_free(struct sftp_packet *pkt);
void BinarySink_put_fxp_attrs(BinarySink *bs, struct fxp_attrs attrs);
int BinarySource_get_fxp_attrs(BinarySource *src, struct fxp_attrs *attrs);
bool BinarySource_get_fxp_attrs(BinarySource *src, struct fxp_attrs *attrs);
#define put_fxp_attrs(bs, attrs) \
BinarySink_put_fxp_attrs(BinarySink_UPCAST(bs), attrs)
#define get_fxp_attrs(bs, attrs) \
@ -164,9 +165,9 @@ const char *fxp_error(void);
int fxp_error_type(void);
/*
* Perform exchange of init/version packets. Return 0 on failure.
* Perform exchange of init/version packets. Return false on failure.
*/
int fxp_init(void);
bool fxp_init(void);
/*
* Canonify a pathname. Concatenate the two given path elements
@ -192,56 +193,56 @@ struct fxp_handle *fxp_opendir_recv(struct sftp_packet *pktin,
struct sftp_request *req);
/*
* Close a file/dir. Returns 1 on success, 0 on error.
* Close a file/dir. Returns true on success, false on error.
*/
struct sftp_request *fxp_close_send(struct fxp_handle *handle);
int fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req);
bool fxp_close_recv(struct sftp_packet *pktin, struct sftp_request *req);
/*
* Make a directory.
*/
struct sftp_request *fxp_mkdir_send(const char *path,
const struct fxp_attrs *attrs);
int fxp_mkdir_recv(struct sftp_packet *pktin, struct sftp_request *req);
bool fxp_mkdir_recv(struct sftp_packet *pktin, struct sftp_request *req);
/*
* Remove a directory.
*/
struct sftp_request *fxp_rmdir_send(const char *path);
int fxp_rmdir_recv(struct sftp_packet *pktin, struct sftp_request *req);
bool fxp_rmdir_recv(struct sftp_packet *pktin, struct sftp_request *req);
/*
* Remove a file.
*/
struct sftp_request *fxp_remove_send(const char *fname);
int fxp_remove_recv(struct sftp_packet *pktin, struct sftp_request *req);
bool fxp_remove_recv(struct sftp_packet *pktin, struct sftp_request *req);
/*
* Rename a file.
*/
struct sftp_request *fxp_rename_send(const char *srcfname,
const char *dstfname);
int fxp_rename_recv(struct sftp_packet *pktin, struct sftp_request *req);
bool fxp_rename_recv(struct sftp_packet *pktin, struct sftp_request *req);
/*
* Return file attributes.
*/
struct sftp_request *fxp_stat_send(const char *fname);
int fxp_stat_recv(struct sftp_packet *pktin, struct sftp_request *req,
struct fxp_attrs *attrs);
bool fxp_stat_recv(struct sftp_packet *pktin, struct sftp_request *req,
struct fxp_attrs *attrs);
struct sftp_request *fxp_fstat_send(struct fxp_handle *handle);
int fxp_fstat_recv(struct sftp_packet *pktin, struct sftp_request *req,
struct fxp_attrs *attrs);
bool fxp_fstat_recv(struct sftp_packet *pktin, struct sftp_request *req,
struct fxp_attrs *attrs);
/*
* Set file attributes.
*/
struct sftp_request *fxp_setstat_send(const char *fname,
struct fxp_attrs attrs);
int fxp_setstat_recv(struct sftp_packet *pktin, struct sftp_request *req);
bool fxp_setstat_recv(struct sftp_packet *pktin, struct sftp_request *req);
struct sftp_request *fxp_fsetstat_send(struct fxp_handle *handle,
struct fxp_attrs attrs);
int fxp_fsetstat_recv(struct sftp_packet *pktin, struct sftp_request *req);
bool fxp_fsetstat_recv(struct sftp_packet *pktin, struct sftp_request *req);
/*
* Read from a file.
@ -249,14 +250,14 @@ int fxp_fsetstat_recv(struct sftp_packet *pktin, struct sftp_request *req);
struct sftp_request *fxp_read_send(struct fxp_handle *handle,
uint64_t offset, int len);
int fxp_read_recv(struct sftp_packet *pktin, struct sftp_request *req,
char *buffer, int len);
char *buffer, int len);
/*
* Write to a file. Returns 0 on error, 1 on OK.
* Write to a file.
*/
struct sftp_request *fxp_write_send(struct fxp_handle *handle,
void *buffer, uint64_t offset, int len);
int fxp_write_recv(struct sftp_packet *pktin, struct sftp_request *req);
bool fxp_write_recv(struct sftp_packet *pktin, struct sftp_request *req);
/*
* Read from a directory.
@ -301,14 +302,14 @@ struct fxp_xfer;
struct fxp_xfer *xfer_download_init(struct fxp_handle *fh, uint64_t offset);
void xfer_download_queue(struct fxp_xfer *xfer);
int xfer_download_gotpkt(struct fxp_xfer *xfer, struct sftp_packet *pktin);
int xfer_download_data(struct fxp_xfer *xfer, void **buf, int *len);
bool xfer_download_data(struct fxp_xfer *xfer, void **buf, int *len);
struct fxp_xfer *xfer_upload_init(struct fxp_handle *fh, uint64_t offset);
int xfer_upload_ready(struct fxp_xfer *xfer);
bool xfer_upload_ready(struct fxp_xfer *xfer);
void xfer_upload_data(struct fxp_xfer *xfer, char *buffer, int len);
int xfer_upload_gotpkt(struct fxp_xfer *xfer, struct sftp_packet *pktin);
int xfer_done(struct fxp_xfer *xfer);
bool xfer_done(struct fxp_xfer *xfer);
void xfer_set_error(struct fxp_xfer *xfer);
void xfer_cleanup(struct fxp_xfer *xfer);
@ -362,7 +363,7 @@ struct SftpServerVtable {
/* Should call fxp_reply_error or fxp_reply_attrs */
void (*stat)(SftpServer *srv, SftpReplyBuilder *reply, ptrlen path,
int follow_symlinks);
bool follow_symlinks);
/* Should call fxp_reply_error or fxp_reply_attrs */
void (*fstat)(SftpServer *srv, SftpReplyBuilder *reply, ptrlen handle);
@ -386,7 +387,7 @@ struct SftpServerVtable {
/* Should call fxp_reply_error, or fxp_reply_name_count once and
* then fxp_reply_full_name that many times */
void (*readdir)(SftpServer *srv, SftpReplyBuilder *reply, ptrlen handle,
int max_entries, int omit_longname);
int max_entries, bool omit_longname);
};
#define sftpsrv_new(vt) \
@ -494,7 +495,7 @@ struct ScpServerVtable {
void (*free)(ScpServer *s);
int (*send)(ScpServer *s, const void *data, size_t length);
void (*throttle)(ScpServer *s, int throttled);
void (*throttle)(ScpServer *s, bool throttled);
void (*eof)(ScpServer *s);
};

View File

@ -73,7 +73,7 @@ const struct fxp_attrs no_attrs = { 0 };
#define put_fxp_attrs(bs, attrs) \
BinarySink_put_fxp_attrs(BinarySink_UPCAST(bs), attrs)
int BinarySource_get_fxp_attrs(BinarySource *src, struct fxp_attrs *attrs)
bool BinarySource_get_fxp_attrs(BinarySource *src, struct fxp_attrs *attrs)
{
attrs->flags = get_uint32(src);
if (attrs->flags & SSH_FILEXFER_ATTR_SIZE)
@ -99,7 +99,7 @@ int BinarySource_get_fxp_attrs(BinarySource *src, struct fxp_attrs *attrs)
get_string(src);
}
}
return 1;
return true;
}
void sftp_pkt_free(struct sftp_packet *pkt)
@ -131,7 +131,7 @@ struct sftp_packet *sftp_recv_prepare(unsigned length)
return pkt;
}
int sftp_recv_finish(struct sftp_packet *pkt)
bool sftp_recv_finish(struct sftp_packet *pkt)
{
BinarySource_INIT(pkt, pkt->data, pkt->length);
pkt->type = get_byte(pkt);

51
ssh.c
View File

@ -46,9 +46,9 @@ struct Ssh {
/* The last list returned from get_specials. */
SessionSpecial *specials;
int bare_connection;
bool bare_connection;
ssh_sharing_state *connshare;
int attempting_connshare;
bool attempting_connshare;
struct ssh_connection_shared_gss_state gss_state;
@ -56,20 +56,20 @@ struct Ssh {
int savedport;
char *fullhostname;
int fallback_cmd;
bool fallback_cmd;
int exitcode;
int version;
int conn_throttle_count;
int overall_bufsize;
int throttled_all;
int frozen;
bool throttled_all;
bool frozen;
/* in case we find these out before we have a ConnectionLayer to tell */
int term_width, term_height;
bufchain in_raw, out_raw, user_input;
int pending_close;
bool pending_close;
IdempotentCallback ic_out_raw;
PacketLogSettings pls;
@ -105,11 +105,11 @@ struct Ssh {
* It's also used to mark the point where we stop counting proxy
* command diagnostics as pre-session-startup.
*/
int session_started;
bool session_started;
Pinger *pinger;
int need_random_unref;
bool need_random_unref;
};
@ -117,7 +117,7 @@ struct Ssh {
logevent_and_free((ssh)->logctx, dupprintf params))
static void ssh_shutdown(Ssh *ssh);
static void ssh_throttle_all(Ssh *ssh, int enable, int bufsize);
static void ssh_throttle_all(Ssh *ssh, bool enable, int bufsize);
static void ssh_bpp_output_raw_data_callback(void *vctx);
LogContext *ssh_get_logctx(Ssh *ssh)
@ -316,7 +316,7 @@ static void ssh_bpp_output_raw_data_callback(void *vctx)
bufchain_consume(&ssh->out_raw, len);
if (backlog > SSH_MAX_BACKLOG) {
ssh_throttle_all(ssh, 1, backlog);
ssh_throttle_all(ssh, true, backlog);
return;
}
}
@ -515,7 +515,7 @@ static void ssh_socket_log(Plug *plug, int type, SockAddr *addr, int port,
}
static void ssh_closing(Plug *plug, const char *error_msg, int error_code,
int calling_back)
bool calling_back)
{
Ssh *ssh = container_of(plug, Ssh, plug);
if (error_msg) {
@ -550,7 +550,7 @@ static void ssh_sent(Plug *plug, int bufsize)
* some more data off its bufchain.
*/
if (bufsize < SSH_MAX_BACKLOG) {
ssh_throttle_all(ssh, 0, bufsize);
ssh_throttle_all(ssh, false, bufsize);
queue_idempotent_callback(&ssh->ic_out_raw);
}
}
@ -592,11 +592,11 @@ static void ssh_hostport_setup(const char *host, int port, Conf *conf,
}
}
static int ssh_test_for_upstream(const char *host, int port, Conf *conf)
static bool ssh_test_for_upstream(const char *host, int port, Conf *conf)
{
char *savedhost;
int savedport;
int ret;
bool ret;
random_ref(); /* platform may need this to determine share socket name */
ssh_hostport_setup(host, port, conf, &savedhost, &savedport, NULL);
@ -621,8 +621,9 @@ static const PlugVtable Ssh_plugvt = {
* Also places the canonical host name into `realhost'. It must be
* freed by the caller.
*/
static const char *connect_to_host(Ssh *ssh, const char *host, int port,
char **realhost, int nodelay, int keepalive)
static const char *connect_to_host(
Ssh *ssh, const char *host, int port, char **realhost,
bool nodelay, bool keepalive)
{
SockAddr *addr;
const char *err;
@ -686,7 +687,7 @@ static const char *connect_to_host(Ssh *ssh, const char *host, int port,
ssh->fullhostname = dupstr(*realhost); /* save in case of GSSAPI */
ssh->s = new_connection(addr, *realhost, port,
0, 1, nodelay, keepalive,
false, true, nodelay, keepalive,
&ssh->plug, ssh->conf);
if ((err = sk_socket_error(ssh->s)) != NULL) {
ssh->s = NULL;
@ -739,7 +740,7 @@ static const char *connect_to_host(Ssh *ssh, const char *host, int port,
void ssh_throttle_conn(Ssh *ssh, int adjust)
{
int old_count = ssh->conn_throttle_count;
int frozen;
bool frozen;
ssh->conn_throttle_count += adjust;
assert(ssh->conn_throttle_count >= 0);
@ -769,7 +770,7 @@ void ssh_throttle_conn(Ssh *ssh, int adjust)
* Throttle or unthrottle _all_ local data streams (for when sends
* on the SSH connection itself back up).
*/
static void ssh_throttle_all(Ssh *ssh, int enable, int bufsize)
static void ssh_throttle_all(Ssh *ssh, bool enable, int bufsize)
{
if (enable == ssh->throttled_all)
return;
@ -793,7 +794,7 @@ static void ssh_cache_conf_values(Ssh *ssh)
static const char *ssh_init(Seat *seat, Backend **backend_handle,
LogContext *logctx, Conf *conf,
const char *host, int port, char **realhost,
int nodelay, int keepalive)
bool nodelay, bool keepalive)
{
const char *p;
Ssh *ssh;
@ -838,7 +839,7 @@ static const char *ssh_init(Seat *seat, Backend **backend_handle,
static void ssh_free(Backend *be)
{
Ssh *ssh = container_of(be, Ssh, backend);
int need_random_unref;
bool need_random_unref;
ssh_shutdown(ssh);
@ -1015,13 +1016,13 @@ static void ssh_unthrottle(Backend *be, int bufsize)
ssh_stdout_unthrottle(ssh->cl, bufsize);
}
static int ssh_connected(Backend *be)
static bool ssh_connected(Backend *be)
{
Ssh *ssh = container_of(be, Ssh, backend);
return ssh->s != NULL;
}
static int ssh_sendok(Backend *be)
static bool ssh_sendok(Backend *be)
{
Ssh *ssh = container_of(be, Ssh, backend);
return ssh->base_layer && ssh_ppl_want_user_input(ssh->base_layer);
@ -1035,7 +1036,7 @@ void ssh_ldisc_update(Ssh *ssh)
ldisc_echoedit_update(ssh->ldisc);
}
static int ssh_ldisc(Backend *be, int option)
static bool ssh_ldisc(Backend *be, int option)
{
Ssh *ssh = container_of(be, Ssh, backend);
return ssh->cl ? ssh_ldisc_option(ssh->cl, option) : false;
@ -1082,7 +1083,7 @@ static int ssh_cfg_info(Backend *be)
* that fails. This variable is the means by which scp.c can reach
* into the SSH code and find out which one it got.
*/
extern int ssh_fallback_cmd(Backend *be)
extern bool ssh_fallback_cmd(Backend *be)
{
Ssh *ssh = container_of(be, Ssh, backend);
return ssh->fallback_cmd;

126
ssh.h
View File

@ -52,7 +52,7 @@ struct ssh_channel;
typedef struct PacketQueueNode PacketQueueNode;
struct PacketQueueNode {
PacketQueueNode *next, *prev;
int on_free_queue; /* is this packet scheduled for freeing? */
bool on_free_queue; /* is this packet scheduled for freeing? */
};
typedef struct PktIn {
@ -89,12 +89,12 @@ typedef struct PacketQueueBase {
typedef struct PktInQueue {
PacketQueueBase pqb;
PktIn *(*after)(PacketQueueBase *, PacketQueueNode *prev, int pop);
PktIn *(*after)(PacketQueueBase *, PacketQueueNode *prev, bool pop);
} PktInQueue;
typedef struct PktOutQueue {
PacketQueueBase pqb;
PktOut *(*after)(PacketQueueBase *, PacketQueueNode *prev, int pop);
PktOut *(*after)(PacketQueueBase *, PacketQueueNode *prev, bool pop);
} PktOutQueue;
void pq_base_push(PacketQueueBase *pqb, PacketQueueNode *node);
@ -146,17 +146,17 @@ typedef enum {
} Pkt_ACtx;
typedef struct PacketLogSettings {
int omit_passwords, omit_data;
bool omit_passwords, omit_data;
Pkt_KCtx kctx;
Pkt_ACtx actx;
} PacketLogSettings;
#define MAX_BLANKS 4 /* no packet needs more censored sections than this */
int ssh1_censor_packet(
const PacketLogSettings *pls, int type, int sender_is_client,
const PacketLogSettings *pls, int type, bool sender_is_client,
ptrlen pkt, logblank_t *blanks);
int ssh2_censor_packet(
const PacketLogSettings *pls, int type, int sender_is_client,
const PacketLogSettings *pls, int type, bool sender_is_client,
ptrlen pkt, logblank_t *blanks);
PktOut *ssh_new_packet(void);
@ -167,7 +167,7 @@ Socket *ssh_connection_sharing_init(
Plug *sshplug, ssh_sharing_state **state);
void ssh_connshare_provide_connlayer(ssh_sharing_state *sharestate,
ConnectionLayer *cl);
int ssh_share_test_for_upstream(const char *host, int port, Conf *conf);
bool ssh_share_test_for_upstream(const char *host, int port, Conf *conf);
void share_got_pkt_from_server(ssh_sharing_connstate *ctx, int type,
const void *pkt, int pktlen);
void share_activate(ssh_sharing_state *sharestate,
@ -259,7 +259,7 @@ struct ConnectionLayerVtable {
void (*sharing_no_more_downstreams)(ConnectionLayer *cl);
/* Query whether the connection layer is doing agent forwarding */
int (*agent_forwarding_permitted)(ConnectionLayer *cl);
bool (*agent_forwarding_permitted)(ConnectionLayer *cl);
/* Set the size of the main terminal window (if any) */
void (*terminal_size)(ConnectionLayer *cl, int width, int height);
@ -274,15 +274,15 @@ struct ConnectionLayerVtable {
* backed up, so it should tell all currently open channels to
* cease reading from their local input sources if they can. (Or
* tell it that that state of affairs has gone away again.) */
void (*throttle_all_channels)(ConnectionLayer *cl, int throttled);
void (*throttle_all_channels)(ConnectionLayer *cl, bool throttled);
/* Ask the connection layer about its current preference for
* line-discipline options. */
int (*ldisc_option)(ConnectionLayer *cl, int option);
bool (*ldisc_option)(ConnectionLayer *cl, int option);
/* Communicate _to_ the connection layer (from the main session
* channel) what its preference for line-discipline options is. */
void (*set_ldisc_option)(ConnectionLayer *cl, int option, int value);
void (*set_ldisc_option)(ConnectionLayer *cl, int option, bool value);
/* Communicate to the connection layer whether X and agent
* forwarding were successfully enabled (for purposes of
@ -292,7 +292,7 @@ struct ConnectionLayerVtable {
/* Communicate to the connection layer whether the main session
* channel currently wants user input. */
void (*set_wants_user_input)(ConnectionLayer *cl, int wanted);
void (*set_wants_user_input)(ConnectionLayer *cl, bool wanted);
};
struct ConnectionLayer {
@ -354,9 +354,9 @@ void portfwdmgr_close_all(PortFwdManager *mgr);
char *portfwdmgr_connect(PortFwdManager *mgr, Channel **chan_ret,
char *hostname, int port, SshChannel *c,
int addressfamily);
int portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port,
const char *keyhost, int keyport, Conf *conf);
int portfwdmgr_unlisten(PortFwdManager *mgr, const char *host, int port);
bool portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port,
const char *keyhost, int keyport, Conf *conf);
bool portfwdmgr_unlisten(PortFwdManager *mgr, const char *host, int port);
Channel *portfwd_raw_new(ConnectionLayer *cl, Plug **plug);
void portfwd_raw_free(Channel *pfchan);
void portfwd_raw_setup(Channel *pfchan, Socket *s, SshChannel *sc);
@ -415,7 +415,7 @@ struct ec_point {
const struct ec_curve *curve;
Bignum x, y;
Bignum z; /* Jacobian denominator */
unsigned char infinity;
bool infinity;
};
void ec_point_free(struct ec_point *point);
@ -464,12 +464,12 @@ const ssh_keyalg *ec_alg_by_oid(int len, const void *oid,
const struct ec_curve **curve);
const unsigned char *ec_alg_oid(const ssh_keyalg *alg, int *oidlen);
extern const int ec_nist_curve_lengths[], n_ec_nist_curve_lengths;
int ec_nist_alg_and_curve_by_bits(int bits,
const struct ec_curve **curve,
const ssh_keyalg **alg);
int ec_ed_alg_and_curve_by_bits(int bits,
const struct ec_curve **curve,
const ssh_keyalg **alg);
bool ec_nist_alg_and_curve_by_bits(int bits,
const struct ec_curve **curve,
const ssh_keyalg **alg);
bool ec_ed_alg_and_curve_by_bits(int bits,
const struct ec_curve **curve,
const ssh_keyalg **alg);
struct ec_key {
struct ec_point publicKey;
@ -493,14 +493,14 @@ void BinarySource_get_rsa_ssh1_pub(
BinarySource *src, struct RSAKey *result, RsaSsh1Order order);
void BinarySource_get_rsa_ssh1_priv(
BinarySource *src, struct RSAKey *rsa);
int rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key);
bool rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key);
Bignum rsa_ssh1_decrypt(Bignum input, struct RSAKey *key);
int rsa_ssh1_decrypt_pkcs1(Bignum input, struct RSAKey *key, strbuf *outbuf);
bool rsa_ssh1_decrypt_pkcs1(Bignum input, struct RSAKey *key, strbuf *outbuf);
void rsasanitise(struct RSAKey *key);
int rsastr_len(struct RSAKey *key);
void rsastr_fmt(char *str, struct RSAKey *key);
char *rsa_ssh1_fingerprint(struct RSAKey *key);
int rsa_verify(struct RSAKey *key);
bool rsa_verify(struct RSAKey *key);
void rsa_ssh1_public_blob(BinarySink *bs, struct RSAKey *key,
RsaSsh1Order order);
int rsa_ssh1_public_blob_len(void *data, int maxlen);
@ -513,8 +513,8 @@ unsigned long crc32_update(unsigned long crc_input, const void *s, size_t len);
struct crcda_ctx;
struct crcda_ctx *crcda_make_context(void);
void crcda_free_context(struct crcda_ctx *ctx);
int detect_attack(struct crcda_ctx *ctx, unsigned char *buf, uint32_t len,
unsigned char *IV);
bool detect_attack(struct crcda_ctx *ctx, unsigned char *buf, uint32_t len,
unsigned char *IV);
/*
* SSH2 RSA key exchange functions
@ -575,7 +575,7 @@ void hmacmd5_key(struct hmacmd5_context *ctx, void const *key, int len);
void hmacmd5_do_hmac(struct hmacmd5_context *ctx,
const void *blk, int len, unsigned char *hmac);
int supports_sha_ni(void);
bool supports_sha_ni(void);
typedef struct SHA_State {
uint32_t h[5];
@ -718,9 +718,9 @@ struct ssh2_macalg {
#define ssh2_mac_alg(ctx) ((ctx)->vt)
/* Centralised 'methods' for ssh2_mac, defined in sshmac.c */
int ssh2_mac_verresult(ssh2_mac *, const void *);
bool ssh2_mac_verresult(ssh2_mac *, const void *);
void ssh2_mac_generate(ssh2_mac *, void *, int, unsigned long seq);
int ssh2_mac_verify(ssh2_mac *, const void *, int, unsigned long seq);
bool ssh2_mac_verify(ssh2_mac *, const void *, int, unsigned long seq);
typedef struct ssh_hash {
const struct ssh_hashalg *vt;
@ -763,7 +763,7 @@ struct ssh_keyalg {
/* Methods that operate on an existing ssh_key */
void (*freekey) (ssh_key *key);
void (*sign) (ssh_key *key, const void *data, int datalen, BinarySink *);
int (*verify) (ssh_key *key, ptrlen sig, ptrlen data);
bool (*verify) (ssh_key *key, ptrlen sig, ptrlen data);
void (*public_blob)(ssh_key *key, BinarySink *);
void (*private_blob)(ssh_key *key, BinarySink *);
void (*openssh_blob) (ssh_key *key, BinarySink *);
@ -815,8 +815,8 @@ struct ssh_compression_alg {
int minlen);
ssh_decompressor *(*decompress_new)(void);
void (*decompress_free)(ssh_decompressor *);
int (*decompress)(ssh_decompressor *, unsigned char *block, int len,
unsigned char **outblock, int *outlen);
bool (*decompress)(ssh_decompressor *, unsigned char *block, int len,
unsigned char **outblock, int *outlen);
const char *text_name;
};
@ -893,7 +893,7 @@ extern const char sshver[];
* that fails. This variable is the means by which scp.c can reach
* into the SSH code and find out which one it got.
*/
extern int ssh_fallback_cmd(Backend *backend);
extern bool ssh_fallback_cmd(Backend *backend);
void SHATransform(uint32_t *digest, uint32_t *data);
@ -930,7 +930,7 @@ enum {
};
struct X11Display {
/* Broken-down components of the display name itself */
int unixdomain;
bool unixdomain;
char *hostname;
int displaynum;
int screennum;
@ -996,12 +996,12 @@ struct X11FakeAuth *x11_invent_fake_auth(tree234 *t, int authtype);
void x11_free_fake_auth(struct X11FakeAuth *auth);
Channel *x11_new_channel(tree234 *authtree, SshChannel *c,
const char *peeraddr, int peerport,
int connection_sharing_possible);
bool connection_sharing_possible);
char *x11_display(const char *display);
/* Platform-dependent X11 functions */
extern void platform_get_x11_auth(struct X11Display *display, Conf *);
/* examine a mostly-filled-in X11Display and fill in localauth* */
extern const int platform_uses_x11_unix_by_default;
extern const bool platform_uses_x11_unix_by_default;
/* choose default X transport in the absence of a specified one */
SockAddr *platform_get_x11_unix_address(const char *path, int displaynum);
/* make up a SockAddr naming the address for displaynum */
@ -1074,7 +1074,7 @@ Bignum BinarySource_get_mp_ssh2(BinarySource *);
void diagbn(char *prefix, Bignum md);
#endif
int dh_is_gex(const struct ssh_kex *kex);
bool dh_is_gex(const struct ssh_kex *kex);
struct dh_ctx;
struct dh_ctx *dh_setup_group(const struct ssh_kex *kex);
struct dh_ctx *dh_setup_gex(Bignum pval, Bignum gval);
@ -1083,13 +1083,13 @@ Bignum dh_create_e(struct dh_ctx *, int nbits);
const char *dh_validate_f(struct dh_ctx *, Bignum f);
Bignum dh_find_K(struct dh_ctx *, Bignum f);
int rsa_ssh1_encrypted(const Filename *filename, char **comment);
bool rsa_ssh1_encrypted(const Filename *filename, char **comment);
int rsa_ssh1_loadpub(const Filename *filename, BinarySink *bs,
char **commentptr, const char **errorstr);
int rsa_ssh1_loadkey(const Filename *filename, struct RSAKey *key,
const char *passphrase, const char **errorstr);
int rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key,
char *passphrase);
bool rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key,
char *passphrase);
extern int base64_decode_atom(const char *atom, unsigned char *out);
extern int base64_lines(int datalen);
@ -1101,15 +1101,15 @@ extern void base64_encode(FILE *fp, const unsigned char *data, int datalen,
extern struct ssh2_userkey ssh2_wrong_passphrase;
#define SSH2_WRONG_PASSPHRASE (&ssh2_wrong_passphrase)
int ssh2_userkey_encrypted(const Filename *filename, char **comment);
bool ssh2_userkey_encrypted(const Filename *filename, char **comment);
struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
const char *passphrase,
const char **errorstr);
int ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
BinarySink *bs,
char **commentptr, const char **errorstr);
int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
char *passphrase);
bool ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
BinarySink *bs,
char **commentptr, const char **errorstr);
bool ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
char *passphrase);
const ssh_keyalg *find_pubkey_alg(const char *name);
const ssh_keyalg *find_pubkey_alg_len(ptrlen name);
@ -1167,17 +1167,17 @@ char *ssh2_fingerprint(ssh_key *key);
int key_type(const Filename *filename);
const char *key_type_to_str(int type);
int import_possible(int type);
bool import_possible(int type);
int import_target_type(int type);
int import_encrypted(const Filename *filename, int type, char **comment);
bool import_encrypted(const Filename *filename, int type, char **comment);
int import_ssh1(const Filename *filename, int type,
struct RSAKey *key, char *passphrase, const char **errmsg_p);
struct ssh2_userkey *import_ssh2(const Filename *filename, int type,
char *passphrase, const char **errmsg_p);
int export_ssh1(const Filename *filename, int type,
struct RSAKey *key, char *passphrase);
int export_ssh2(const Filename *filename, int type,
struct ssh2_userkey *key, char *passphrase);
bool export_ssh1(const Filename *filename, int type,
struct RSAKey *key, char *passphrase);
bool export_ssh2(const Filename *filename, int type,
struct ssh2_userkey *key, char *passphrase);
void des3_decrypt_pubkey(const void *key, void *blk, int len);
void des3_encrypt_pubkey(const void *key, void *blk, int len);
@ -1231,7 +1231,7 @@ enum { SHARE_NONE, SHARE_DOWNSTREAM, SHARE_UPSTREAM };
int platform_ssh_share(const char *name, Conf *conf,
Plug *downplug, Plug *upplug, Socket **sock,
char **logtext, char **ds_err, char **us_err,
int can_upstream, int can_downstream);
bool can_upstream, bool can_downstream);
void platform_ssh_share_cleanup(const char *name);
/*
@ -1449,7 +1449,7 @@ enum {
struct ssh_ttymodes {
/* A boolean per mode, indicating whether it's set. */
int have_mode[TTYMODE_LIMIT];
bool have_mode[TTYMODE_LIMIT];
/* The actual value for each mode. */
unsigned mode_val[TTYMODE_LIMIT];
@ -1463,7 +1463,7 @@ void write_ttymodes_to_packet(BinarySink *bs, int ssh_version,
const char *ssh1_pkt_type(int type);
const char *ssh2_pkt_type(Pkt_KCtx pkt_kctx, Pkt_ACtx pkt_actx, int type);
int ssh2_pkt_type_code_valid(unsigned type);
bool ssh2_pkt_type_code_valid(unsigned type);
/*
* Need this to warn about support for the original SSH-2 keyfile
@ -1505,11 +1505,11 @@ unsigned alloc_channel_id_general(tree234 *channels, size_t localid_offset);
TYPECHECK(&((type *)0)->localid == (unsigned *)0, \
alloc_channel_id_general(tree, offsetof(type, localid)))
int first_in_commasep_string(char const *needle, char const *haystack,
int haylen);
int in_commasep_string(char const *needle, char const *haystack, int haylen);
bool first_in_commasep_string(char const *needle, char const *haystack,
int haylen);
bool in_commasep_string(char const *needle, char const *haystack, int haylen);
void add_to_commasep(strbuf *buf, const char *data);
int get_commasep_word(ptrlen *list, ptrlen *word);
bool get_commasep_word(ptrlen *list, ptrlen *word);
int verify_ssh_manual_host_key(
Conf *conf, const char *fingerprint, ssh_key *key);
@ -1519,8 +1519,8 @@ ssh_transient_hostkey_cache *ssh_transient_hostkey_cache_new(void);
void ssh_transient_hostkey_cache_free(ssh_transient_hostkey_cache *thc);
void ssh_transient_hostkey_cache_add(
ssh_transient_hostkey_cache *thc, ssh_key *key);
int ssh_transient_hostkey_cache_verify(
bool ssh_transient_hostkey_cache_verify(
ssh_transient_hostkey_cache *thc, ssh_key *key);
int ssh_transient_hostkey_cache_has(
bool ssh_transient_hostkey_cache_has(
ssh_transient_hostkey_cache *thc, const ssh_keyalg *alg);
int ssh_transient_hostkey_cache_non_empty(ssh_transient_hostkey_cache *thc);
bool ssh_transient_hostkey_cache_non_empty(ssh_transient_hostkey_cache *thc);

View File

@ -21,7 +21,7 @@ struct ssh1_bpp_state {
struct crcda_ctx *crcda_ctx;
int pending_compression_request;
bool pending_compression_request;
ssh_compressor *compctx;
ssh_decompressor *decompctx;

View File

@ -10,7 +10,7 @@
#include "ssh.h"
int ssh1_censor_packet(
const PacketLogSettings *pls, int type, int sender_is_client,
const PacketLogSettings *pls, int type, bool sender_is_client,
ptrlen pkt, logblank_t *blanks)
{
int nblanks = 0;

View File

@ -29,7 +29,7 @@ void ssh1_connection_direction_specific_setup(
}
typedef void (*sf_handler_fn_t)(struct ssh1_connection_state *s,
int success, void *ctx);
bool success, void *ctx);
struct outstanding_succfail {
sf_handler_fn_t handler;
@ -43,14 +43,14 @@ struct outstanding_succfail {
* expect to get an acknowledgment regardless, so we arrange to
* send that ack immediately after the rest of the queue empties.
*/
int trivial;
bool trivial;
};
static void ssh1_connection_process_trivial_succfails(void *vs);
static void ssh1_queue_succfail_handler(
struct ssh1_connection_state *s, sf_handler_fn_t handler, void *ctx,
int trivial)
bool trivial)
{
struct outstanding_succfail *osf = snew(struct outstanding_succfail);
osf->handler = handler;
@ -71,7 +71,7 @@ static void ssh1_queue_succfail_handler(
}
static void ssh1_connection_process_succfail(
struct ssh1_connection_state *s, int success)
struct ssh1_connection_state *s, bool success)
{
struct outstanding_succfail *prevhead = s->succfail_head;
s->succfail_head = s->succfail_head->next;
@ -88,7 +88,7 @@ static void ssh1_connection_process_trivial_succfails(void *vs)
ssh1_connection_process_succfail(s, true);
}
int ssh1_handle_direction_specific_packet(
bool ssh1_handle_direction_specific_packet(
struct ssh1_connection_state *s, PktIn *pktin)
{
PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */
@ -233,7 +233,7 @@ int ssh1_handle_direction_specific_packet(
s->ppl.seat, pktin->type == SSH1_SMSG_STDERR_DATA,
data.ptr, data.len);
if (!s->stdout_throttling && bufsize > SSH1_BUFFER_LIMIT) {
s->stdout_throttling = 1;
s->stdout_throttling = true;
ssh_throttle_conn(s->ppl.ssh, +1);
}
}
@ -256,18 +256,18 @@ int ssh1_handle_direction_specific_packet(
}
static void ssh1mainchan_succfail_wantreply(struct ssh1_connection_state *s,
int success, void *ctx)
bool success, void *ctx)
{
chan_request_response(s->mainchan_chan, success);
}
static void ssh1mainchan_succfail_nowantreply(struct ssh1_connection_state *s,
int success, void *ctx)
bool success, void *ctx)
{
}
static void ssh1mainchan_queue_response(struct ssh1_connection_state *s,
int want_reply, int trivial)
bool want_reply, bool trivial)
{
sf_handler_fn_t handler = (want_reply ? ssh1mainchan_succfail_wantreply :
ssh1mainchan_succfail_nowantreply);
@ -275,8 +275,8 @@ static void ssh1mainchan_queue_response(struct ssh1_connection_state *s,
}
static void ssh1mainchan_request_x11_forwarding(
SshChannel *sc, int want_reply, const char *authproto,
const char *authdata, int screen_number, int oneshot)
SshChannel *sc, bool want_reply, const char *authproto,
const char *authdata, int screen_number, bool oneshot)
{
struct ssh1_connection_state *s =
container_of(sc, struct ssh1_connection_state, mainchan_sc);
@ -293,7 +293,7 @@ static void ssh1mainchan_request_x11_forwarding(
}
static void ssh1mainchan_request_agent_forwarding(
SshChannel *sc, int want_reply)
SshChannel *sc, bool want_reply)
{
struct ssh1_connection_state *s =
container_of(sc, struct ssh1_connection_state, mainchan_sc);
@ -307,7 +307,7 @@ static void ssh1mainchan_request_agent_forwarding(
}
static void ssh1mainchan_request_pty(
SshChannel *sc, int want_reply, Conf *conf, int w, int h)
SshChannel *sc, bool want_reply, Conf *conf, int w, int h)
{
struct ssh1_connection_state *s =
container_of(sc, struct ssh1_connection_state, mainchan_sc);
@ -327,14 +327,13 @@ static void ssh1mainchan_request_pty(
ssh1mainchan_queue_response(s, want_reply, false);
}
static int ssh1mainchan_send_env_var(
SshChannel *sc, int want_reply, const char *var, const char *value)
static bool ssh1mainchan_send_env_var(
SshChannel *sc, bool want_reply, const char *var, const char *value)
{
return false; /* SSH-1 doesn't support this at all */
}
static void ssh1mainchan_start_shell(
SshChannel *sc, int want_reply)
static void ssh1mainchan_start_shell(SshChannel *sc, bool want_reply)
{
struct ssh1_connection_state *s =
container_of(sc, struct ssh1_connection_state, mainchan_sc);
@ -347,7 +346,7 @@ static void ssh1mainchan_start_shell(
}
static void ssh1mainchan_start_command(
SshChannel *sc, int want_reply, const char *command)
SshChannel *sc, bool want_reply, const char *command)
{
struct ssh1_connection_state *s =
container_of(sc, struct ssh1_connection_state, mainchan_sc);
@ -360,20 +359,20 @@ static void ssh1mainchan_start_command(
ssh1mainchan_queue_response(s, want_reply, true);
}
static int ssh1mainchan_start_subsystem(
SshChannel *sc, int want_reply, const char *subsystem)
static bool ssh1mainchan_start_subsystem(
SshChannel *sc, bool want_reply, const char *subsystem)
{
return false; /* SSH-1 doesn't support this at all */
}
static int ssh1mainchan_send_serial_break(
SshChannel *sc, int want_reply, int length)
static bool ssh1mainchan_send_serial_break(
SshChannel *sc, bool want_reply, int length)
{
return false; /* SSH-1 doesn't support this at all */
}
static int ssh1mainchan_send_signal(
SshChannel *sc, int want_reply, const char *signame)
static bool ssh1mainchan_send_signal(
SshChannel *sc, bool want_reply, const char *signame)
{
return false; /* SSH-1 doesn't support this at all */
}
@ -398,7 +397,7 @@ static void ssh1mainchan_hint_channel_is_simple(SshChannel *sc)
}
static int ssh1mainchan_write(
SshChannel *sc, int is_stderr, const void *data, int len)
SshChannel *sc, bool is_stderr, const void *data, int len)
{
struct ssh1_connection_state *s =
container_of(sc, struct ssh1_connection_state, mainchan_sc);
@ -463,7 +462,7 @@ SshChannel *ssh1_session_open(ConnectionLayer *cl, Channel *chan)
}
static void ssh1_rportfwd_response(struct ssh1_connection_state *s,
int success, void *ctx)
bool success, void *ctx)
{
PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */
struct ssh_rportfwd *rpf = (struct ssh_rportfwd *)ctx;

View File

@ -13,12 +13,13 @@
#include "ssh1connection.h"
#include "sshserver.h"
static int ssh1sesschan_write(SshChannel *c, int is_stderr, const void *, int);
static int ssh1sesschan_write(SshChannel *c, bool is_stderr,
const void *, int);
static void ssh1sesschan_write_eof(SshChannel *c);
static void ssh1sesschan_initiate_close(SshChannel *c, const char *err);
static void ssh1sesschan_send_exit_status(SshChannel *c, int status);
static void ssh1sesschan_send_exit_signal(
SshChannel *c, ptrlen signame, int core_dumped, ptrlen msg);
SshChannel *c, ptrlen signame, bool core_dumped, ptrlen msg);
static const struct SshChannelVtable ssh1sesschan_vtable = {
ssh1sesschan_write,
@ -54,7 +55,7 @@ void ssh1_connection_direction_specific_setup(
}
}
int ssh1_handle_direction_specific_packet(
bool ssh1_handle_direction_specific_packet(
struct ssh1_connection_state *s, PktIn *pktin)
{
PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */
@ -63,7 +64,8 @@ int ssh1_handle_direction_specific_packet(
unsigned remid;
ptrlen host, cmd, data;
char *host_str, *err;
int port, listenport, success;
int port, listenport;
bool success;
switch (pktin->type) {
case SSH1_CMSG_EXEC_SHELL:
@ -264,7 +266,7 @@ struct ssh_rportfwd *ssh1_rportfwd_alloc(
return NULL;
}
static int ssh1sesschan_write(SshChannel *sc, int is_stderr,
static int ssh1sesschan_write(SshChannel *sc, bool is_stderr,
const void *data, int len)
{
struct ssh1_connection_state *s =
@ -303,7 +305,7 @@ static void ssh1sesschan_send_exit_status(SshChannel *sc, int status)
}
static void ssh1sesschan_send_exit_signal(
SshChannel *sc, ptrlen signame, int core_dumped, ptrlen msg)
SshChannel *sc, ptrlen signame, bool core_dumped, ptrlen msg)
{
/* SSH-1 has no separate representation for signals */
ssh1sesschan_send_exit_status(sc, 128);

View File

@ -31,7 +31,7 @@ static void ssh1_connection_free(PacketProtocolLayer *);
static void ssh1_connection_process_queue(PacketProtocolLayer *);
static void ssh1_connection_special_cmd(PacketProtocolLayer *ppl,
SessionSpecialCode code, int arg);
static int ssh1_connection_want_user_input(PacketProtocolLayer *ppl);
static bool ssh1_connection_want_user_input(PacketProtocolLayer *ppl);
static void ssh1_connection_got_user_input(PacketProtocolLayer *ppl);
static void ssh1_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf);
@ -53,16 +53,16 @@ static SshChannel *ssh1_lportfwd_open(
const char *description, const SocketPeerInfo *pi, Channel *chan);
static struct X11FakeAuth *ssh1_add_x11_display(
ConnectionLayer *cl, int authtype, struct X11Display *disp);
static int ssh1_agent_forwarding_permitted(ConnectionLayer *cl);
static bool ssh1_agent_forwarding_permitted(ConnectionLayer *cl);
static void ssh1_terminal_size(ConnectionLayer *cl, int width, int height);
static void ssh1_stdout_unthrottle(ConnectionLayer *cl, int bufsize);
static int ssh1_stdin_backlog(ConnectionLayer *cl);
static void ssh1_throttle_all_channels(ConnectionLayer *cl, int throttled);
static int ssh1_ldisc_option(ConnectionLayer *cl, int option);
static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, int value);
static void ssh1_throttle_all_channels(ConnectionLayer *cl, bool throttled);
static bool ssh1_ldisc_option(ConnectionLayer *cl, int option);
static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, bool value);
static void ssh1_enable_x_fwd(ConnectionLayer *cl);
static void ssh1_enable_agent_fwd(ConnectionLayer *cl);
static void ssh1_set_wants_user_input(ConnectionLayer *cl, int wanted);
static void ssh1_set_wants_user_input(ConnectionLayer *cl, bool wanted);
static const struct ConnectionLayerVtable ssh1_connlayer_vtable = {
ssh1_rportfwd_alloc,
@ -92,7 +92,7 @@ static const struct ConnectionLayerVtable ssh1_connlayer_vtable = {
};
static int ssh1channel_write(
SshChannel *c, int is_stderr, const void *buf, int len);
SshChannel *c, bool is_stderr, const void *buf, int len);
static void ssh1channel_write_eof(SshChannel *c);
static void ssh1channel_initiate_close(SshChannel *c, const char *err);
static void ssh1channel_unthrottle(SshChannel *c, int bufsize);
@ -224,13 +224,13 @@ void ssh1_connection_set_protoflags(PacketProtocolLayer *ppl,
s->remote_protoflags = remote;
}
static int ssh1_connection_filter_queue(struct ssh1_connection_state *s)
static bool ssh1_connection_filter_queue(struct ssh1_connection_state *s)
{
PktIn *pktin;
ptrlen data;
struct ssh1_channel *c;
unsigned localid;
int expect_halfopen;
bool expect_halfopen;
while (1) {
if (ssh1_common_filter_queue(&s->ppl))
@ -511,7 +511,7 @@ static void ssh1_channel_destroy(struct ssh1_channel *c)
queue_toplevel_callback(ssh1_check_termination_callback, s);
}
int ssh1_check_termination(struct ssh1_connection_state *s)
bool ssh1_check_termination(struct ssh1_connection_state *s)
{
/*
* Decide whether we should terminate the SSH connection now.
@ -584,13 +584,13 @@ static void ssh1channel_unthrottle(SshChannel *sc, int bufsize)
struct ssh1_connection_state *s = c->connlayer;
if (c->throttling_conn && bufsize <= SSH1_BUFFER_LIMIT) {
c->throttling_conn = 0;
c->throttling_conn = false;
ssh_throttle_conn(s->ppl.ssh, -1);
}
}
static int ssh1channel_write(
SshChannel *sc, int is_stderr, const void *buf, int len)
SshChannel *sc, bool is_stderr, const void *buf, int len)
{
struct ssh1_channel *c = container_of(sc, struct ssh1_channel, sc);
struct ssh1_connection_state *s = c->connlayer;
@ -659,7 +659,7 @@ static void ssh1_rportfwd_remove(ConnectionLayer *cl, struct ssh_rportfwd *rpf)
*/
}
static int ssh1_agent_forwarding_permitted(ConnectionLayer *cl)
static bool ssh1_agent_forwarding_permitted(ConnectionLayer *cl)
{
struct ssh1_connection_state *s =
container_of(cl, struct ssh1_connection_state, cl);
@ -701,7 +701,7 @@ static void ssh1_stdout_unthrottle(ConnectionLayer *cl, int bufsize)
container_of(cl, struct ssh1_connection_state, cl);
if (s->stdout_throttling && bufsize < SSH1_BUFFER_LIMIT) {
s->stdout_throttling = 0;
s->stdout_throttling = false;
ssh_throttle_conn(s->ppl.ssh, -1);
}
}
@ -711,7 +711,7 @@ static int ssh1_stdin_backlog(ConnectionLayer *cl)
return 0;
}
static void ssh1_throttle_all_channels(ConnectionLayer *cl, int throttled)
static void ssh1_throttle_all_channels(ConnectionLayer *cl, bool throttled)
{
struct ssh1_connection_state *s =
container_of(cl, struct ssh1_connection_state, cl);
@ -722,7 +722,7 @@ static void ssh1_throttle_all_channels(ConnectionLayer *cl, int throttled)
chan_set_input_wanted(c->chan, !throttled);
}
static int ssh1_ldisc_option(ConnectionLayer *cl, int option)
static bool ssh1_ldisc_option(ConnectionLayer *cl, int option)
{
struct ssh1_connection_state *s =
container_of(cl, struct ssh1_connection_state, cl);
@ -730,7 +730,7 @@ static int ssh1_ldisc_option(ConnectionLayer *cl, int option)
return s->ldisc_opts[option];
}
static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, int value)
static void ssh1_set_ldisc_option(ConnectionLayer *cl, int option, bool value)
{
struct ssh1_connection_state *s =
container_of(cl, struct ssh1_connection_state, cl);
@ -754,7 +754,7 @@ static void ssh1_enable_agent_fwd(ConnectionLayer *cl)
s->agent_fwd_enabled = true;
}
static void ssh1_set_wants_user_input(ConnectionLayer *cl, int wanted)
static void ssh1_set_wants_user_input(ConnectionLayer *cl, bool wanted)
{
struct ssh1_connection_state *s =
container_of(cl, struct ssh1_connection_state, cl);
@ -763,7 +763,7 @@ static void ssh1_set_wants_user_input(ConnectionLayer *cl, int wanted)
s->finished_setup = true;
}
static int ssh1_connection_want_user_input(PacketProtocolLayer *ppl)
static bool ssh1_connection_want_user_input(PacketProtocolLayer *ppl)
{
struct ssh1_connection_state *s =
container_of(ppl, struct ssh1_connection_state, ppl);

View File

@ -21,25 +21,25 @@ struct ssh1_connection_state {
Channel *mainchan_chan; /* the other end of mainchan_sc */
mainchan *mainchan; /* and its subtype */
int got_pty;
int ldisc_opts[LD_N_OPTIONS];
int stdout_throttling;
int want_user_input;
int session_terminated;
bool got_pty;
bool ldisc_opts[LD_N_OPTIONS];
bool stdout_throttling;
bool want_user_input;
bool session_terminated;
int term_width, term_height, term_width_orig, term_height_orig;
int X11_fwd_enabled;
bool X11_fwd_enabled;
struct X11Display *x11disp;
struct X11FakeAuth *x11auth;
tree234 *x11authtree;
int agent_fwd_enabled;
bool agent_fwd_enabled;
tree234 *rportfwds;
PortFwdManager *portfwdmgr;
int portfwdmgr_configured;
bool portfwdmgr_configured;
int finished_setup;
bool finished_setup;
/*
* These store the list of requests that we're waiting for
@ -49,7 +49,7 @@ struct ssh1_connection_state {
*/
struct outstanding_succfail *succfail_head, *succfail_tail;
int compressing; /* used in server mode only */
bool compressing; /* used in server mode only */
ConnectionLayer cl;
PacketProtocolLayer ppl;
@ -61,7 +61,7 @@ struct ssh1_channel {
unsigned remoteid, localid;
int type;
/* True if we opened this channel but server hasn't confirmed. */
int halfopen;
bool halfopen;
/* Bitmap of whether we've sent/received CHANNEL_CLOSE and
* CHANNEL_CLOSE_CONFIRMATION. */
@ -79,13 +79,13 @@ struct ssh1_channel {
* we set this flag instead to remind us to do so once our buffer
* is clear.
*/
int pending_eof;
bool pending_eof;
/*
* True if this channel is causing the underlying connection to be
* throttled.
*/
int throttling_conn;
bool throttling_conn;
/*
* True if we currently have backed-up data on the direction of
@ -93,7 +93,7 @@ struct ssh1_channel {
* would prefer the 'Channel' implementation not to read further
* local input if possible.
*/
int throttled_by_backlog;
bool throttled_by_backlog;
Channel *chan; /* handle the client side of this channel, if not */
SshChannel sc; /* entry point for chan to talk back to */
@ -113,7 +113,7 @@ SshChannel *ssh1_serverside_agent_open(ConnectionLayer *cl, Channel *chan);
void ssh1_connection_direction_specific_setup(
struct ssh1_connection_state *s);
int ssh1_handle_direction_specific_packet(
bool ssh1_handle_direction_specific_packet(
struct ssh1_connection_state *s, PktIn *pktin);
int ssh1_check_termination(struct ssh1_connection_state *s);
bool ssh1_check_termination(struct ssh1_connection_state *s);

View File

@ -28,14 +28,14 @@ struct ssh1_login_server_state {
ptrlen username;
struct RSAKey *servkey, *hostkey;
int servkey_generated_here;
bool servkey_generated_here;
Bignum sesskey;
AuthPolicy *authpolicy;
unsigned ap_methods, current_method;
unsigned char auth_rsa_expected_response[16];
struct RSAKey *authkey;
int auth_successful;
bool auth_successful;
PacketProtocolLayer ppl;
};
@ -43,12 +43,12 @@ struct ssh1_login_server_state {
static void ssh1_login_server_free(PacketProtocolLayer *);
static void ssh1_login_server_process_queue(PacketProtocolLayer *);
static int ssh1_login_server_get_specials(
static bool ssh1_login_server_get_specials(
PacketProtocolLayer *ppl, add_special_fn_t add_special,
void *ctx) { return false; }
static void ssh1_login_server_special_cmd(PacketProtocolLayer *ppl,
SessionSpecialCode code, int arg) {}
static int ssh1_login_server_want_user_input(
static bool ssh1_login_server_want_user_input(
PacketProtocolLayer *ppl) { return false; }
static void ssh1_login_server_got_user_input(PacketProtocolLayer *ppl) {}
static void ssh1_login_server_reconfigure(
@ -101,7 +101,7 @@ static void ssh1_login_server_free(PacketProtocolLayer *ppl)
sfree(s);
}
static int ssh1_login_server_filter_queue(struct ssh1_login_server_state *s)
static bool ssh1_login_server_filter_queue(struct ssh1_login_server_state *s)
{
return ssh1_common_filter_queue(&s->ppl);
}

View File

@ -20,7 +20,7 @@ struct ssh1_login_state {
char *savedhost;
int savedport;
int try_agent_auth;
bool try_agent_auth;
int remote_protoflags;
int local_protoflags;
@ -31,14 +31,14 @@ struct ssh1_login_state {
int len;
unsigned char *rsabuf;
unsigned long supported_ciphers_mask, supported_auths_mask;
int tried_publickey, tried_agent;
int tis_auth_refused, ccard_auth_refused;
bool tried_publickey, tried_agent;
bool tis_auth_refused, ccard_auth_refused;
unsigned char cookie[8];
unsigned char session_id[16];
int cipher_type;
strbuf *publickey_blob;
char *publickey_comment;
int privatekey_available, privatekey_encrypted;
bool privatekey_available, privatekey_encrypted;
prompts_t *cur_prompt;
int userpass_ret;
char c;
@ -47,14 +47,14 @@ struct ssh1_login_state {
ptrlen agent_response;
BinarySource asrc[1]; /* response from SSH agent */
int keyi, nkeys;
int authed;
bool authed;
struct RSAKey key;
Bignum challenge;
ptrlen comment;
int dlgret;
Filename *keyfile;
struct RSAKey servkey, hostkey;
int want_user_input;
bool want_user_input;
PacketProtocolLayer ppl;
};
@ -64,7 +64,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *);
static void ssh1_login_dialog_callback(void *, int);
static void ssh1_login_special_cmd(PacketProtocolLayer *ppl,
SessionSpecialCode code, int arg);
static int ssh1_login_want_user_input(PacketProtocolLayer *ppl);
static bool ssh1_login_want_user_input(PacketProtocolLayer *ppl);
static void ssh1_login_got_user_input(PacketProtocolLayer *ppl);
static void ssh1_login_reconfigure(PacketProtocolLayer *ppl, Conf *conf);
@ -120,7 +120,7 @@ static void ssh1_login_free(PacketProtocolLayer *ppl)
sfree(s);
}
static int ssh1_login_filter_queue(struct ssh1_login_state *s)
static bool ssh1_login_filter_queue(struct ssh1_login_state *s)
{
return ssh1_common_filter_queue(&s->ppl);
}
@ -279,7 +279,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
ppl_logevent(("Encrypted session key"));
{
int cipher_chosen = 0, warn = 0;
bool cipher_chosen = false, warn = false;
const char *cipher_string = NULL;
int i;
for (i = 0; !cipher_chosen && i < CIPHER_MAX; i++) {
@ -287,7 +287,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
s->conf, CONF_ssh_cipherlist, i);
if (next_cipher == CIPHER_WARN) {
/* If/when we choose a cipher, warn about it */
warn = 1;
warn = true;
} else if (next_cipher == CIPHER_AES) {
/* XXX Probably don't need to mention this. */
ppl_logevent(("AES not supported in SSH-1, skipping"));
@ -301,7 +301,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
cipher_string = "single-DES"; break;
}
if (s->supported_ciphers_mask & (1 << s->cipher_type))
cipher_chosen = 1;
cipher_chosen = true;
}
}
if (!cipher_chosen) {
@ -492,7 +492,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
* Attempt RSA authentication using Pageant.
*/
s->authed = false;
s->tried_agent = 1;
s->tried_agent = true;
ppl_logevent(("Pageant is running. Requesting keys."));
/* Request the keys held by the agent. */
@ -535,7 +535,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
s->publickey_blob->len)) {
ppl_logevent(("Pageant key #%d matches "
"configured key file", s->keyi));
s->tried_publickey = 1;
s->tried_publickey = true;
} else
/* Skip non-configured key */
continue;
@ -632,12 +632,12 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
* Try public key authentication with the specified
* key file.
*/
int got_passphrase; /* need not be kept over crReturn */
bool got_passphrase; /* need not be kept over crReturn */
if (flags & FLAG_VERBOSE)
ppl_printf(("Trying public key authentication.\r\n"));
ppl_logevent(("Trying public key \"%s\"",
filename_to_str(s->keyfile)));
s->tried_publickey = 1;
s->tried_publickey = true;
got_passphrase = false;
while (!got_passphrase) {
/*
@ -805,7 +805,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
ppl_logevent(("TIS authentication declined"));
if (flags & FLAG_INTERACTIVE)
ppl_printf(("TIS authentication refused.\r\n"));
s->tis_auth_refused = 1;
s->tis_auth_refused = true;
continue;
} else if (pktin->type == SSH1_SMSG_AUTH_TIS_CHALLENGE) {
ptrlen challenge;
@ -853,7 +853,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl)
if (pktin->type == SSH1_SMSG_FAILURE) {
ppl_logevent(("CryptoCard authentication declined"));
ppl_printf(("CryptoCard authentication refused.\r\n"));
s->ccard_auth_refused = 1;
s->ccard_auth_refused = true;
continue;
} else if (pktin->type == SSH1_SMSG_AUTH_CCARD_CHALLENGE) {
ptrlen challenge;
@ -1145,7 +1145,7 @@ static void ssh1_login_special_cmd(PacketProtocolLayer *ppl,
}
}
static int ssh1_login_want_user_input(PacketProtocolLayer *ppl)
static bool ssh1_login_want_user_input(PacketProtocolLayer *ppl)
{
struct ssh1_login_state *s =
container_of(ppl, struct ssh1_login_state, ppl);

View File

@ -13,7 +13,7 @@ struct ssh2_bpp_direction {
unsigned long sequence;
ssh2_cipher *cipher;
ssh2_mac *mac;
int etm_mode;
bool etm_mode;
const struct ssh_compression_alg *pending_compression;
};
@ -26,7 +26,7 @@ struct ssh2_bpp_state {
unsigned cipherblk;
PktIn *pktin;
struct DataTransferStats *stats;
int cbc_ignore_workaround;
bool cbc_ignore_workaround;
struct ssh2_bpp_direction in, out;
/* comp and decomp logically belong in the per-direction
@ -34,9 +34,9 @@ struct ssh2_bpp_state {
ssh_decompressor *in_decomp;
ssh_compressor *out_comp;
int is_server;
int pending_newkeys;
int pending_compression, seen_userauth_success;
bool is_server;
bool pending_newkeys;
bool pending_compression, seen_userauth_success;
BinaryPacketProtocol bpp;
};
@ -55,7 +55,7 @@ static const struct BinaryPacketProtocolVtable ssh2_bpp_vtable = {
};
BinaryPacketProtocol *ssh2_bpp_new(
LogContext *logctx, struct DataTransferStats *stats, int is_server)
LogContext *logctx, struct DataTransferStats *stats, bool is_server)
{
struct ssh2_bpp_state *s = snew(struct ssh2_bpp_state);
memset(s, 0, sizeof(*s));
@ -90,8 +90,8 @@ static void ssh2_bpp_free(BinaryPacketProtocol *bpp)
void ssh2_bpp_new_outgoing_crypto(
BinaryPacketProtocol *bpp,
const struct ssh2_cipheralg *cipher, const void *ckey, const void *iv,
const struct ssh2_macalg *mac, int etm_mode, const void *mac_key,
const struct ssh_compression_alg *compression, int delayed_compression)
const struct ssh2_macalg *mac, bool etm_mode, const void *mac_key,
const struct ssh_compression_alg *compression, bool delayed_compression)
{
struct ssh2_bpp_state *s;
assert(bpp->vt == &ssh2_bpp_vtable);
@ -157,8 +157,8 @@ void ssh2_bpp_new_outgoing_crypto(
void ssh2_bpp_new_incoming_crypto(
BinaryPacketProtocol *bpp,
const struct ssh2_cipheralg *cipher, const void *ckey, const void *iv,
const struct ssh2_macalg *mac, int etm_mode, const void *mac_key,
const struct ssh_compression_alg *compression, int delayed_compression)
const struct ssh2_macalg *mac, bool etm_mode, const void *mac_key,
const struct ssh_compression_alg *compression, bool delayed_compression)
{
struct ssh2_bpp_state *s;
assert(bpp->vt == &ssh2_bpp_vtable);
@ -224,7 +224,7 @@ void ssh2_bpp_new_incoming_crypto(
queue_idempotent_callback(&s->bpp.ic_in_raw);
}
int ssh2_bpp_rekey_inadvisable(BinaryPacketProtocol *bpp)
bool ssh2_bpp_rekey_inadvisable(BinaryPacketProtocol *bpp)
{
struct ssh2_bpp_state *s;
assert(bpp->vt == &ssh2_bpp_vtable);

View File

@ -10,7 +10,7 @@
#include "ssh.h"
int ssh2_censor_packet(
const PacketLogSettings *pls, int type, int sender_is_client,
const PacketLogSettings *pls, int type, bool sender_is_client,
ptrlen pkt, logblank_t *blanks)
{
int nblanks = 0;

View File

@ -124,7 +124,7 @@ ChanopenResult ssh2_connection_parse_channel_open(
}
}
int ssh2_connection_parse_global_request(
bool ssh2_connection_parse_global_request(
struct ssh2_connection_state *s, ptrlen type, PktIn *pktin)
{
/*
@ -240,7 +240,7 @@ struct ssh_rportfwd *ssh2_rportfwd_alloc(
PktOut *pktout = ssh_bpp_new_pktout(
s->ppl.bpp, SSH2_MSG_GLOBAL_REQUEST);
put_stringz(pktout, "tcpip-forward");
put_bool(pktout, 1); /* want reply */
put_bool(pktout, true); /* want reply */
put_stringz(pktout, rpf->shost);
put_uint32(pktout, rpf->sport);
pq_push(s->ppl.out_pq, pktout);
@ -268,7 +268,7 @@ void ssh2_rportfwd_remove(ConnectionLayer *cl, struct ssh_rportfwd *rpf)
PktOut *pktout = ssh_bpp_new_pktout(
s->ppl.bpp, SSH2_MSG_GLOBAL_REQUEST);
put_stringz(pktout, "cancel-tcpip-forward");
put_bool(pktout, 0); /* _don't_ want reply */
put_bool(pktout, false); /* _don't_ want reply */
put_stringz(pktout, rpf->shost);
put_uint32(pktout, rpf->sport);
pq_push(s->ppl.out_pq, pktout);
@ -320,7 +320,7 @@ static void ssh2_channel_response(
chan_request_response(c->chan, pkt->type == SSH2_MSG_CHANNEL_SUCCESS);
}
void ssh2channel_start_shell(SshChannel *sc, int want_reply)
void ssh2channel_start_shell(SshChannel *sc, bool want_reply)
{
struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
struct ssh2_connection_state *s = c->connlayer;
@ -331,7 +331,7 @@ void ssh2channel_start_shell(SshChannel *sc, int want_reply)
}
void ssh2channel_start_command(
SshChannel *sc, int want_reply, const char *command)
SshChannel *sc, bool want_reply, const char *command)
{
struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
struct ssh2_connection_state *s = c->connlayer;
@ -342,8 +342,8 @@ void ssh2channel_start_command(
pq_push(s->ppl.out_pq, pktout);
}
int ssh2channel_start_subsystem(
SshChannel *sc, int want_reply, const char *subsystem)
bool ssh2channel_start_subsystem(
SshChannel *sc, bool want_reply, const char *subsystem)
{
struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
struct ssh2_connection_state *s = c->connlayer;
@ -362,20 +362,20 @@ void ssh2channel_send_exit_status(SshChannel *sc, int status)
}
void ssh2channel_send_exit_signal(
SshChannel *sc, ptrlen signame, int core_dumped, ptrlen msg)
SshChannel *sc, ptrlen signame, bool core_dumped, ptrlen msg)
{
assert(false && "Should never be called in the client");
}
void ssh2channel_send_exit_signal_numeric(
SshChannel *sc, int signum, int core_dumped, ptrlen msg)
SshChannel *sc, int signum, bool core_dumped, ptrlen msg)
{
assert(false && "Should never be called in the client");
}
void ssh2channel_request_x11_forwarding(
SshChannel *sc, int want_reply, const char *authproto,
const char *authdata, int screen_number, int oneshot)
SshChannel *sc, bool want_reply, const char *authproto,
const char *authdata, int screen_number, bool oneshot)
{
struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
struct ssh2_connection_state *s = c->connlayer;
@ -389,7 +389,7 @@ void ssh2channel_request_x11_forwarding(
pq_push(s->ppl.out_pq, pktout);
}
void ssh2channel_request_agent_forwarding(SshChannel *sc, int want_reply)
void ssh2channel_request_agent_forwarding(SshChannel *sc, bool want_reply)
{
struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
struct ssh2_connection_state *s = c->connlayer;
@ -401,7 +401,7 @@ void ssh2channel_request_agent_forwarding(SshChannel *sc, int want_reply)
}
void ssh2channel_request_pty(
SshChannel *sc, int want_reply, Conf *conf, int w, int h)
SshChannel *sc, bool want_reply, Conf *conf, int w, int h)
{
struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
struct ssh2_connection_state *s = c->connlayer;
@ -422,8 +422,8 @@ void ssh2channel_request_pty(
pq_push(s->ppl.out_pq, pktout);
}
int ssh2channel_send_env_var(
SshChannel *sc, int want_reply, const char *var, const char *value)
bool ssh2channel_send_env_var(
SshChannel *sc, bool want_reply, const char *var, const char *value)
{
struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
struct ssh2_connection_state *s = c->connlayer;
@ -437,7 +437,7 @@ int ssh2channel_send_env_var(
return true;
}
int ssh2channel_send_serial_break(SshChannel *sc, int want_reply, int length)
bool ssh2channel_send_serial_break(SshChannel *sc, bool want_reply, int length)
{
struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
struct ssh2_connection_state *s = c->connlayer;
@ -450,8 +450,8 @@ int ssh2channel_send_serial_break(SshChannel *sc, int want_reply, int length)
return true;
}
int ssh2channel_send_signal(
SshChannel *sc, int want_reply, const char *signame)
bool ssh2channel_send_signal(
SshChannel *sc, bool want_reply, const char *signame)
{
struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
struct ssh2_connection_state *s = c->connlayer;

View File

@ -79,7 +79,7 @@ ChanopenResult ssh2_connection_parse_channel_open(
}
}
int ssh2_connection_parse_global_request(
bool ssh2_connection_parse_global_request(
struct ssh2_connection_state *s, ptrlen type, PktIn *pktin)
{
if (ptrlen_eq_string(type, "tcpip-forward")) {
@ -88,14 +88,14 @@ int ssh2_connection_parse_global_request(
/* In SSH-2, the host/port we listen on are the same host/port
* we want reported back to us when a connection comes in,
* because that's what we tell the client */
int toret = portfwdmgr_listen(
bool toret = portfwdmgr_listen(
s->portfwdmgr, host, port, host, port, s->conf);
sfree(host);
return toret;
} else if (ptrlen_eq_string(type, "cancel-tcpip-forward")) {
char *host = mkstr(get_string(pktin));
unsigned port = get_uint32(pktin);
int toret = portfwdmgr_unlisten(s->portfwdmgr, host, port);
bool toret = portfwdmgr_unlisten(s->portfwdmgr, host, port);
sfree(host);
return toret;
} else {
@ -200,19 +200,19 @@ SshChannel *ssh2_serverside_agent_open(ConnectionLayer *cl, Channel *chan)
return &c->sc;
}
void ssh2channel_start_shell(SshChannel *sc, int want_reply)
void ssh2channel_start_shell(SshChannel *sc, bool want_reply)
{
assert(false && "Should never be called in the server");
}
void ssh2channel_start_command(
SshChannel *sc, int want_reply, const char *command)
SshChannel *sc, bool want_reply, const char *command)
{
assert(false && "Should never be called in the server");
}
int ssh2channel_start_subsystem(
SshChannel *sc, int want_reply, const char *subsystem)
bool ssh2channel_start_subsystem(
SshChannel *sc, bool want_reply, const char *subsystem)
{
assert(false && "Should never be called in the server");
}
@ -229,7 +229,7 @@ void ssh2channel_send_exit_status(SshChannel *sc, int status)
}
void ssh2channel_send_exit_signal(
SshChannel *sc, ptrlen signame, int core_dumped, ptrlen msg)
SshChannel *sc, ptrlen signame, bool core_dumped, ptrlen msg)
{
struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
struct ssh2_connection_state *s = c->connlayer;
@ -244,7 +244,7 @@ void ssh2channel_send_exit_signal(
}
void ssh2channel_send_exit_signal_numeric(
SshChannel *sc, int signum, int core_dumped, ptrlen msg)
SshChannel *sc, int signum, bool core_dumped, ptrlen msg)
{
struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
struct ssh2_connection_state *s = c->connlayer;
@ -259,36 +259,36 @@ void ssh2channel_send_exit_signal_numeric(
}
void ssh2channel_request_x11_forwarding(
SshChannel *sc, int want_reply, const char *authproto,
const char *authdata, int screen_number, int oneshot)
SshChannel *sc, bool want_reply, const char *authproto,
const char *authdata, int screen_number, bool oneshot)
{
assert(false && "Should never be called in the server");
}
void ssh2channel_request_agent_forwarding(SshChannel *sc, int want_reply)
void ssh2channel_request_agent_forwarding(SshChannel *sc, bool want_reply)
{
assert(false && "Should never be called in the server");
}
void ssh2channel_request_pty(
SshChannel *sc, int want_reply, Conf *conf, int w, int h)
SshChannel *sc, bool want_reply, Conf *conf, int w, int h)
{
assert(false && "Should never be called in the server");
}
int ssh2channel_send_env_var(
SshChannel *sc, int want_reply, const char *var, const char *value)
bool ssh2channel_send_env_var(
SshChannel *sc, bool want_reply, const char *var, const char *value)
{
assert(false && "Should never be called in the server");
}
int ssh2channel_send_serial_break(SshChannel *sc, int want_reply, int length)
bool ssh2channel_send_serial_break(SshChannel *sc, bool want_reply, int length)
{
assert(false && "Should never be called in the server");
}
int ssh2channel_send_signal(
SshChannel *sc, int want_reply, const char *signame)
bool ssh2channel_send_signal(
SshChannel *sc, bool want_reply, const char *signame)
{
assert(false && "Should never be called in the server");
}

View File

@ -14,11 +14,11 @@
static void ssh2_connection_free(PacketProtocolLayer *);
static void ssh2_connection_process_queue(PacketProtocolLayer *);
static int ssh2_connection_get_specials(
static bool ssh2_connection_get_specials(
PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx);
static void ssh2_connection_special_cmd(PacketProtocolLayer *ppl,
SessionSpecialCode code, int arg);
static int ssh2_connection_want_user_input(PacketProtocolLayer *ppl);
static bool ssh2_connection_want_user_input(PacketProtocolLayer *ppl);
static void ssh2_connection_got_user_input(PacketProtocolLayer *ppl);
static void ssh2_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf);
@ -53,16 +53,16 @@ static void ssh2_delete_sharing_channel(
static void ssh2_sharing_queue_global_request(
ConnectionLayer *cl, ssh_sharing_connstate *share_ctx);
static void ssh2_sharing_no_more_downstreams(ConnectionLayer *cl);
static int ssh2_agent_forwarding_permitted(ConnectionLayer *cl);
static bool ssh2_agent_forwarding_permitted(ConnectionLayer *cl);
static void ssh2_terminal_size(ConnectionLayer *cl, int width, int height);
static void ssh2_stdout_unthrottle(ConnectionLayer *cl, int bufsize);
static int ssh2_stdin_backlog(ConnectionLayer *cl);
static void ssh2_throttle_all_channels(ConnectionLayer *cl, int throttled);
static int ssh2_ldisc_option(ConnectionLayer *cl, int option);
static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, int value);
static void ssh2_throttle_all_channels(ConnectionLayer *cl, bool throttled);
static bool ssh2_ldisc_option(ConnectionLayer *cl, int option);
static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, bool value);
static void ssh2_enable_x_fwd(ConnectionLayer *cl);
static void ssh2_enable_agent_fwd(ConnectionLayer *cl);
static void ssh2_set_wants_user_input(ConnectionLayer *cl, int wanted);
static void ssh2_set_wants_user_input(ConnectionLayer *cl, bool wanted);
static const struct ConnectionLayerVtable ssh2_connlayer_vtable = {
ssh2_rportfwd_alloc,
@ -119,7 +119,7 @@ static char *ssh2_channel_open_failure_error_text(PktIn *pktin)
}
static int ssh2channel_write(
SshChannel *c, int is_stderr, const void *buf, int len);
SshChannel *c, bool is_stderr, const void *buf, int len);
static void ssh2channel_write_eof(SshChannel *c);
static void ssh2channel_initiate_close(SshChannel *c, const char *err);
static void ssh2channel_unthrottle(SshChannel *c, int bufsize);
@ -239,7 +239,7 @@ static void ssh2_channel_free(struct ssh2_channel *c)
}
PacketProtocolLayer *ssh2_connection_new(
Ssh *ssh, ssh_sharing_state *connshare, int is_simple,
Ssh *ssh, ssh_sharing_state *connshare, bool is_simple,
Conf *conf, const char *peer_verstring, ConnectionLayer **cl_out)
{
struct ssh2_connection_state *s = snew(struct ssh2_connection_state);
@ -313,7 +313,7 @@ static void ssh2_connection_free(PacketProtocolLayer *ppl)
sfree(s);
}
static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
static bool ssh2_connection_filter_queue(struct ssh2_connection_state *s)
{
PktIn *pktin;
PktOut *pktout;
@ -321,7 +321,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
struct ssh2_channel *c;
struct outstanding_channel_request *ocr;
unsigned localid, remid, winsize, pktsize, ext_type;
int want_reply, reply_success, expect_halfopen;
bool want_reply, reply_success, expect_halfopen;
ChanopenResult chanopen_result;
PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */
@ -330,7 +330,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
* we have an instance of ssh2transport below us, then those
* messages won't come here anyway, but they could if we're
* running in bare ssh2-connection mode. */
extern int ssh2_common_filter_queue(PacketProtocolLayer *ppl);
extern bool ssh2_common_filter_queue(PacketProtocolLayer *ppl);
while (1) {
if (ssh2_common_filter_queue(&s->ppl))
@ -610,7 +610,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
} else if (ptrlen_eq_string(type, "exit-signal")) {
ptrlen signame;
int signum;
int core = false;
bool core = false;
ptrlen errmsg;
int format;
@ -669,7 +669,7 @@ static int ssh2_connection_filter_queue(struct ssh2_connection_state *s)
ptrlen subsys = get_string(pktin);
reply_success = chan_run_subsystem(c->chan, subsys);
} else if (ptrlen_eq_string(type, "x11-req")) {
int oneshot = get_bool(pktin);
bool oneshot = get_bool(pktin);
ptrlen authproto = get_string(pktin);
ptrlen authdata = get_string(pktin);
unsigned screen_number = get_uint32(pktin);
@ -1341,13 +1341,13 @@ static void ssh2channel_unthrottle(SshChannel *sc, int bufsize)
ssh2_set_window(c, buflimit - bufsize);
if (c->throttling_conn && bufsize <= buflimit) {
c->throttling_conn = 0;
c->throttling_conn = false;
ssh_throttle_conn(s->ppl.ssh, -1);
}
}
static int ssh2channel_write(
SshChannel *sc, int is_stderr, const void *buf, int len)
SshChannel *sc, bool is_stderr, const void *buf, int len)
{
struct ssh2_channel *c = container_of(sc, struct ssh2_channel, sc);
assert(!(c->closes & CLOSES_SENT_EOF));
@ -1522,19 +1522,19 @@ static void ssh2_send_packet_from_downstream(
pq_push(s->ppl.out_pq, pkt);
}
static int ssh2_agent_forwarding_permitted(ConnectionLayer *cl)
static bool ssh2_agent_forwarding_permitted(ConnectionLayer *cl)
{
struct ssh2_connection_state *s =
container_of(cl, struct ssh2_connection_state, cl);
return conf_get_bool(s->conf, CONF_agentfwd) && agent_exists();
}
static int ssh2_connection_get_specials(
static bool ssh2_connection_get_specials(
PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx)
{
struct ssh2_connection_state *s =
container_of(ppl, struct ssh2_connection_state, ppl);
int toret = false;
bool toret = false;
if (s->mainchan) {
mainchan_get_specials(s->mainchan, add_special, ctx);
@ -1608,7 +1608,7 @@ static int ssh2_stdin_backlog(ConnectionLayer *cl)
bufchain_size(&c->outbuffer) + bufchain_size(&c->errbuffer) : 0;
}
static void ssh2_throttle_all_channels(ConnectionLayer *cl, int throttled)
static void ssh2_throttle_all_channels(ConnectionLayer *cl, bool throttled)
{
struct ssh2_connection_state *s =
container_of(cl, struct ssh2_connection_state, cl);
@ -1621,7 +1621,7 @@ static void ssh2_throttle_all_channels(ConnectionLayer *cl, int throttled)
ssh2_channel_check_throttle(c);
}
static int ssh2_ldisc_option(ConnectionLayer *cl, int option)
static bool ssh2_ldisc_option(ConnectionLayer *cl, int option)
{
struct ssh2_connection_state *s =
container_of(cl, struct ssh2_connection_state, cl);
@ -1629,7 +1629,7 @@ static int ssh2_ldisc_option(ConnectionLayer *cl, int option)
return s->ldisc_opts[option];
}
static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, int value)
static void ssh2_set_ldisc_option(ConnectionLayer *cl, int option, bool value)
{
struct ssh2_connection_state *s =
container_of(cl, struct ssh2_connection_state, cl);
@ -1653,7 +1653,7 @@ static void ssh2_enable_agent_fwd(ConnectionLayer *cl)
s->agent_fwd_enabled = true;
}
static void ssh2_set_wants_user_input(ConnectionLayer *cl, int wanted)
static void ssh2_set_wants_user_input(ConnectionLayer *cl, bool wanted)
{
struct ssh2_connection_state *s =
container_of(cl, struct ssh2_connection_state, cl);
@ -1661,7 +1661,7 @@ static void ssh2_set_wants_user_input(ConnectionLayer *cl, int wanted)
s->want_user_input = wanted;
}
static int ssh2_connection_want_user_input(PacketProtocolLayer *ppl)
static bool ssh2_connection_want_user_input(PacketProtocolLayer *ppl)
{
struct ssh2_connection_state *s =
container_of(ppl, struct ssh2_connection_state, ppl);

View File

@ -14,28 +14,28 @@ struct ssh2_connection_state {
mainchan *mainchan;
SshChannel *mainchan_sc;
int ldisc_opts[LD_N_OPTIONS];
bool ldisc_opts[LD_N_OPTIONS];
int session_attempt, session_status;
int term_width, term_height;
int want_user_input;
bool want_user_input;
int ssh_is_simple;
int persistent;
bool ssh_is_simple;
bool persistent;
Conf *conf;
tree234 *channels; /* indexed by local id */
int all_channels_throttled;
bool all_channels_throttled;
int X11_fwd_enabled;
bool X11_fwd_enabled;
tree234 *x11authtree;
int got_pty;
int agent_fwd_enabled;
bool got_pty;
bool agent_fwd_enabled;
tree234 *rportfwds;
PortFwdManager *portfwdmgr;
int portfwdmgr_configured;
bool portfwdmgr_configured;
const SftpServerVtable *sftpserver_vt;
@ -62,7 +62,7 @@ struct ssh2_channel {
unsigned remoteid, localid;
int type;
/* True if we opened this channel but server hasn't confirmed. */
int halfopen;
bool halfopen;
/* Bitmap of whether we've sent/received CHANNEL_EOF and
* CHANNEL_CLOSE. */
@ -80,13 +80,13 @@ struct ssh2_channel {
* we set this flag instead to remind us to do so once our buffer
* is clear.
*/
int pending_eof;
bool pending_eof;
/*
* True if this channel is causing the underlying connection to be
* throttled.
*/
int throttling_conn;
bool throttling_conn;
/*
* True if we currently have backed-up data on the direction of
@ -94,7 +94,7 @@ struct ssh2_channel {
* would prefer the 'Channel' implementation not to read further
* local input if possible.
*/
int throttled_by_backlog;
bool throttled_by_backlog;
bufchain outbuffer, errbuffer;
unsigned remwindow, remmaxpkt;
@ -172,28 +172,28 @@ SshChannel *ssh2_serverside_agent_open(ConnectionLayer *cl, Channel *chan);
void ssh2channel_send_exit_status(SshChannel *c, int status);
void ssh2channel_send_exit_signal(
SshChannel *c, ptrlen signame, int core_dumped, ptrlen msg);
SshChannel *c, ptrlen signame, bool core_dumped, ptrlen msg);
void ssh2channel_send_exit_signal_numeric(
SshChannel *c, int signum, int core_dumped, ptrlen msg);
SshChannel *c, int signum, bool core_dumped, ptrlen msg);
void ssh2channel_request_x11_forwarding(
SshChannel *c, int want_reply, const char *authproto,
const char *authdata, int screen_number, int oneshot);
void ssh2channel_request_agent_forwarding(SshChannel *c, int want_reply);
SshChannel *c, bool want_reply, const char *authproto,
const char *authdata, int screen_number, bool oneshot);
void ssh2channel_request_agent_forwarding(SshChannel *c, bool want_reply);
void ssh2channel_request_pty(
SshChannel *c, int want_reply, Conf *conf, int w, int h);
int ssh2channel_send_env_var(
SshChannel *c, int want_reply, const char *var, const char *value);
void ssh2channel_start_shell(SshChannel *c, int want_reply);
SshChannel *c, bool want_reply, Conf *conf, int w, int h);
bool ssh2channel_send_env_var(
SshChannel *c, bool want_reply, const char *var, const char *value);
void ssh2channel_start_shell(SshChannel *c, bool want_reply);
void ssh2channel_start_command(
SshChannel *c, int want_reply, const char *command);
int ssh2channel_start_subsystem(
SshChannel *c, int want_reply, const char *subsystem);
int ssh2channel_send_env_var(
SshChannel *c, int want_reply, const char *var, const char *value);
int ssh2channel_send_serial_break(
SshChannel *c, int want_reply, int length);
int ssh2channel_send_signal(
SshChannel *c, int want_reply, const char *signame);
SshChannel *c, bool want_reply, const char *command);
bool ssh2channel_start_subsystem(
SshChannel *c, bool want_reply, const char *subsystem);
bool ssh2channel_send_env_var(
SshChannel *c, bool want_reply, const char *var, const char *value);
bool ssh2channel_send_serial_break(
SshChannel *c, bool want_reply, int length);
bool ssh2channel_send_signal(
SshChannel *c, bool want_reply, const char *signame);
void ssh2channel_send_terminal_size_change(SshChannel *c, int w, int h);
#define CHANOPEN_RETURN_FAILURE(code, msgparams) do \
@ -225,7 +225,7 @@ ChanopenResult ssh2_connection_parse_channel_open(
struct ssh2_connection_state *s, ptrlen type,
PktIn *pktin, SshChannel *sc);
int ssh2_connection_parse_global_request(
bool ssh2_connection_parse_global_request(
struct ssh2_connection_state *s, ptrlen type, PktIn *pktin);
#endif /* PUTTY_SSH2CONNECTION_H */

View File

@ -230,8 +230,8 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s)
ptrlen data;
s->ppl.bpp->pls->kctx = SSH2_PKTCTX_GSSKEX;
s->init_token_sent = 0;
s->complete_rcvd = 0;
s->init_token_sent = false;
s->complete_rcvd = false;
s->hkey = NULL;
s->fingerprint = NULL;
s->keystr = NULL;
@ -349,7 +349,7 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s)
s->gss_stat == SSH_GSS_S_CONTINUE_NEEDED);
if (!s->init_token_sent) {
s->init_token_sent = 1;
s->init_token_sent = true;
pktout = ssh_bpp_new_pktout(s->ppl.bpp,
SSH2_MSG_KEXGSS_INIT);
if (s->gss_sndtok.length == 0) {
@ -385,7 +385,7 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s)
s->gss_rcvtok.length = data.len;
continue;
case SSH2_MSG_KEXGSS_COMPLETE:
s->complete_rcvd = 1;
s->complete_rcvd = true;
s->f = get_mp_ssh2(pktin);
data = get_string(pktin);
s->mic.value = (char *)data.ptr;

View File

@ -87,11 +87,11 @@ void ssh_transient_hostkey_cache_add(
assert(retd == ent);
}
int ssh_transient_hostkey_cache_verify(
bool ssh_transient_hostkey_cache_verify(
ssh_transient_hostkey_cache *thc, ssh_key *key)
{
struct ssh_transient_hostkey_cache_entry *ent;
int toret = false;
bool toret = false;
if ((ent = find234(thc->cache, (void *)ssh_key_alg(key),
ssh_transient_hostkey_cache_find)) != NULL) {
@ -109,7 +109,7 @@ int ssh_transient_hostkey_cache_verify(
return toret;
}
int ssh_transient_hostkey_cache_has(
bool ssh_transient_hostkey_cache_has(
ssh_transient_hostkey_cache *thc, const ssh_keyalg *alg)
{
struct ssh_transient_hostkey_cache_entry *ent =
@ -118,7 +118,7 @@ int ssh_transient_hostkey_cache_has(
return ent != NULL;
}
int ssh_transient_hostkey_cache_non_empty(ssh_transient_hostkey_cache *thc)
bool ssh_transient_hostkey_cache_non_empty(ssh_transient_hostkey_cache *thc)
{
return count234(thc->cache) > 0;
}

View File

@ -44,11 +44,11 @@ static void ssh_comp_none_block(ssh_compressor *handle,
int minlen)
{
}
static int ssh_decomp_none_block(ssh_decompressor *handle,
unsigned char *block, int len,
unsigned char **outblock, int *outlen)
static bool ssh_decomp_none_block(ssh_decompressor *handle,
unsigned char *block, int len,
unsigned char **outblock, int *outlen)
{
return 0;
return false;
}
const static struct ssh_compression_alg ssh_comp_none = {
"none", NULL,
@ -62,11 +62,11 @@ const static struct ssh_compression_alg *const compressions[] = {
static void ssh2_transport_free(PacketProtocolLayer *);
static void ssh2_transport_process_queue(PacketProtocolLayer *);
static int ssh2_transport_get_specials(
static bool ssh2_transport_get_specials(
PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx);
static void ssh2_transport_special_cmd(PacketProtocolLayer *ppl,
SessionSpecialCode code, int arg);
static int ssh2_transport_want_user_input(PacketProtocolLayer *ppl);
static bool ssh2_transport_want_user_input(PacketProtocolLayer *ppl);
static void ssh2_transport_got_user_input(PacketProtocolLayer *ppl);
static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf);
@ -87,11 +87,11 @@ static const struct PacketProtocolLayerVtable ssh2_transport_vtable = {
#ifndef NO_GSSAPI
static void ssh2_transport_gss_update(struct ssh2_transport_state *s,
int definitely_rekeying);
bool definitely_rekeying);
#endif
static int ssh2_transport_timer_update(struct ssh2_transport_state *s,
unsigned long rekey_time);
static bool ssh2_transport_timer_update(struct ssh2_transport_state *s,
unsigned long rekey_time);
static const char *const kexlist_descr[NKEXLIST] = {
"key exchange algorithm",
@ -109,7 +109,7 @@ PacketProtocolLayer *ssh2_transport_new(
const char *client_greeting, const char *server_greeting,
struct ssh_connection_shared_gss_state *shgss,
struct DataTransferStats *stats, PacketProtocolLayer *higher_layer,
int is_server)
bool is_server)
{
struct ssh2_transport_state *s = snew(struct ssh2_transport_state);
memset(s, 0, sizeof(*s));
@ -298,7 +298,7 @@ static struct kexinit_algorithm *ssh2_kexinit_addalg(struct kexinit_algorithm
return NULL;
}
int ssh2_common_filter_queue(PacketProtocolLayer *ppl)
bool ssh2_common_filter_queue(PacketProtocolLayer *ppl)
{
static const char *const ssh2_disconnect_reasons[] = {
NULL,
@ -359,7 +359,7 @@ int ssh2_common_filter_queue(PacketProtocolLayer *ppl)
return false;
}
static int ssh2_transport_filter_queue(struct ssh2_transport_state *s)
static bool ssh2_transport_filter_queue(struct ssh2_transport_state *s)
{
PktIn *pktin;
@ -407,9 +407,10 @@ static void ssh2_write_kexinit_lists(
const char *hk_host, int hk_port, const ssh_keyalg *hk_prev,
ssh_transient_hostkey_cache *thc,
ssh_key *const *our_hostkeys, int our_nhostkeys,
int first_time, int can_gssapi_keyex, int transient_hostkey_mode)
bool first_time, bool can_gssapi_keyex, bool transient_hostkey_mode)
{
int i, j, k, warn;
int i, j, k;
bool warn;
int n_preferred_kex;
const struct ssh_kexes *preferred_kex[KEX_MAX + 1]; /* +1 for GSSAPI */
@ -735,18 +736,18 @@ static void ssh2_write_kexinit_lists(
put_stringz(pktout, "");
}
static int ssh2_scan_kexinits(
static bool ssh2_scan_kexinits(
ptrlen client_kexinit, ptrlen server_kexinit,
struct kexinit_algorithm kexlists[NKEXLIST][MAXKEXLIST],
const struct ssh_kex **kex_alg, const ssh_keyalg **hostkey_alg,
transport_direction *cs, transport_direction *sc,
int *warn_kex, int *warn_hk, int *warn_cscipher, int *warn_sccipher,
Ssh *ssh, int *ignore_guess_cs_packet, int *ignore_guess_sc_packet,
bool *warn_kex, bool *warn_hk, bool *warn_cscipher, bool *warn_sccipher,
Ssh *ssh, bool *ignore_guess_cs_packet, bool *ignore_guess_sc_packet,
int *n_server_hostkeys, int server_hostkeys[MAXKEXLIST])
{
BinarySource client[1], server[1];
int i;
int guess_correct;
bool guess_correct;
ptrlen clists[NKEXLIST], slists[NKEXLIST];
const struct kexinit_algorithm *selected[NKEXLIST];
@ -763,7 +764,8 @@ static int ssh2_scan_kexinits(
* kexinit_algorithm structure. */
for (i = 0; i < NKEXLIST; i++) {
ptrlen clist, slist, cword, sword, found;
int cfirst, sfirst, j;
bool cfirst, sfirst;
int j;
clists[i] = get_string(client);
slists[i] = get_string(server);
@ -1025,7 +1027,7 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
* fresh ones.
*/
if (!s->got_session_id && (s->gss_status & GSS_CTXT_MAYFAIL) != 0)
s->can_gssapi_keyex = 0;
s->can_gssapi_keyex = false;
s->gss_delegate = conf_get_bool(s->conf, CONF_gssapifwd);
} else {
s->can_gssapi_keyex = false;
@ -1147,7 +1149,7 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
for (j = 0; j < s->n_uncert_hostkeys; j++) {
const struct ssh_signkey_with_user_pref_id *hktype =
&ssh2_hostkey_algs[s->uncert_hostkeys[j]];
int better = false;
bool better = false;
for (k = 0; k < HK_MAX; k++) {
int id = conf_get_int_int(s->conf, CONF_ssh_hklist, k);
if (id == HK_WARN) {
@ -1575,11 +1577,12 @@ static void ssh2_transport_timer(void *ctx, unsigned long now)
/*
* The rekey_time is zero except when re-configuring.
*
* We either schedule the next timer and return 0, or return 1 to run the
* callback now, which will call us again to re-schedule on completion.
* We either schedule the next timer and return false, or return true
* to run the callback now, which will call us again to re-schedule on
* completion.
*/
static int ssh2_transport_timer_update(struct ssh2_transport_state *s,
unsigned long rekey_time)
static bool ssh2_transport_timer_update(struct ssh2_transport_state *s,
unsigned long rekey_time)
{
unsigned long mins;
unsigned long ticks;
@ -1598,7 +1601,7 @@ static int ssh2_transport_timer_update(struct ssh2_transport_state *s,
/* If overdue, caller will rekey synchronously now */
if (now - s->last_rekey > ticks)
return 1;
return true;
ticks = next - now;
}
@ -1633,7 +1636,7 @@ static int ssh2_transport_timer_update(struct ssh2_transport_state *s,
/* Schedule the next timer */
s->next_rekey = schedule_timer(ticks, ssh2_transport_timer, s);
return 0;
return false;
}
void ssh2_transport_dialog_callback(void *loginv, int ret)
@ -1658,7 +1661,7 @@ void ssh2_transport_dialog_callback(void *loginv, int ret)
* newly obtained context as a proxy for the expiration of the TGT.
*/
static void ssh2_transport_gss_update(struct ssh2_transport_state *s,
int definitely_rekeying)
bool definitely_rekeying)
{
PacketProtocolLayer *ppl = &s->ppl; /* for ppl_logevent */
int gss_stat;
@ -1754,7 +1757,7 @@ static void ssh2_transport_gss_update(struct ssh2_transport_state *s,
* refresh them. We must avoid setting GSS_CRED_UPDATED or
* GSS_CTXT_EXPIRES when credential delegation is disabled.
*/
if (conf_get_bool(s->conf, CONF_gssapifwd) == 0)
if (!conf_get_bool(s->conf, CONF_gssapifwd))
return;
if (s->gss_cred_expiry != GSS_NO_EXPIRATION &&
@ -1792,13 +1795,13 @@ void ssh2_transport_notify_auth_done(PacketProtocolLayer *ppl)
#endif /* NO_GSSAPI */
static int ssh2_transport_get_specials(
static bool ssh2_transport_get_specials(
PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx)
{
struct ssh2_transport_state *s =
container_of(ppl, struct ssh2_transport_state, ppl);
int need_separator = false;
int toret;
bool need_separator = false;
bool toret;
if (ssh_ppl_get_specials(s->higher_layer, add_special, ctx)) {
need_separator = true;
@ -1884,7 +1887,7 @@ static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf)
{
struct ssh2_transport_state *s;
const char *rekey_reason = NULL;
int rekey_mandatory = false;
bool rekey_mandatory = false;
unsigned long old_max_data_size, rekey_time;
int i;
@ -1905,8 +1908,8 @@ static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf)
/* We must decrement both counters, so avoid short-circuit
* evaluation skipping one */
int out_expired = DTS_CONSUME(s->stats, out, diff) != 0;
int in_expired = DTS_CONSUME(s->stats, in, diff) != 0;
bool out_expired = DTS_CONSUME(s->stats, out, diff);
bool in_expired = DTS_CONSUME(s->stats, in, diff);
if (out_expired || in_expired)
rekey_reason = "data limit lowered";
} else {
@ -1953,7 +1956,7 @@ static void ssh2_transport_reconfigure(PacketProtocolLayer *ppl, Conf *conf)
ssh_ppl_reconfigure(s->higher_layer, conf);
}
static int ssh2_transport_want_user_input(PacketProtocolLayer *ppl)
static bool ssh2_transport_want_user_input(PacketProtocolLayer *ppl)
{
struct ssh2_transport_state *s =
container_of(ppl, struct ssh2_transport_state, ppl);

View File

@ -29,23 +29,23 @@ struct kexinit_algorithm {
union {
struct {
const struct ssh_kex *kex;
int warn;
bool warn;
} kex;
struct {
const ssh_keyalg *hostkey;
int warn;
bool warn;
} hk;
struct {
const struct ssh2_cipheralg *cipher;
int warn;
bool warn;
} cipher;
struct {
const struct ssh2_macalg *mac;
int etm;
bool etm;
} mac;
struct {
const struct ssh_compression_alg *comp;
int delayed;
bool delayed;
} comp;
} u;
};
@ -105,9 +105,9 @@ typedef enum RekeyClass {
typedef struct transport_direction {
const struct ssh2_cipheralg *cipher;
const struct ssh2_macalg *mac;
int etm_mode;
bool etm_mode;
const struct ssh_compression_alg *comp;
int comp_delayed;
bool comp_delayed;
int mkkey_adjust;
} transport_direction;
@ -132,7 +132,8 @@ struct ssh2_transport_state {
char *hostkey_str; /* string representation, for easy checking in rekeys */
unsigned char session_id[SSH2_KEX_MAX_HASH_LEN];
int session_id_len;
int dh_min_size, dh_max_size, dh_got_size_bounds;
int dh_min_size, dh_max_size;
bool dh_got_size_bounds;
struct dh_ctx *dh_ctx;
ssh_hash *exhash;
@ -140,10 +141,10 @@ struct ssh2_transport_state {
char *client_greeting, *server_greeting;
int kex_in_progress;
bool kex_in_progress;
unsigned long next_rekey, last_rekey;
const char *deferred_rekey_reason;
int higher_layer_ok;
bool higher_layer_ok;
/*
* Fully qualified host name, which we need if doing GSSAPI.
@ -161,9 +162,10 @@ struct ssh2_transport_state {
#endif
ssh_transient_hostkey_cache *thc;
int gss_kex_used;
bool gss_kex_used;
int nbits, pbits, warn_kex, warn_hk, warn_cscipher, warn_sccipher;
int nbits, pbits;
bool warn_kex, warn_hk, warn_cscipher, warn_sccipher;
Bignum p, g, e, f, K;
strbuf *outgoing_kexinit, *incoming_kexinit;
strbuf *client_kexinit, *server_kexinit; /* aliases to the above */
@ -176,22 +178,22 @@ struct ssh2_transport_state {
struct RSAKey *rsa_kex_key; /* for RSA kex */
struct ec_key *ecdh_key; /* for ECDH kex */
unsigned char exchange_hash[SSH2_KEX_MAX_HASH_LEN];
int can_gssapi_keyex;
int need_gss_transient_hostkey;
int warned_about_no_gss_transient_hostkey;
int got_session_id;
bool can_gssapi_keyex;
bool need_gss_transient_hostkey;
bool warned_about_no_gss_transient_hostkey;
bool got_session_id;
int dlgret;
int guessok;
int ignorepkt;
bool guessok;
bool ignorepkt;
struct kexinit_algorithm kexlists[NKEXLIST][MAXKEXLIST];
#ifndef NO_GSSAPI
Ssh_gss_buf gss_buf;
Ssh_gss_buf gss_rcvtok, gss_sndtok;
Ssh_gss_stat gss_stat;
Ssh_gss_buf mic;
int init_token_sent;
int complete_rcvd;
int gss_delegate;
bool init_token_sent;
bool complete_rcvd;
bool gss_delegate;
#endif
/*
@ -205,7 +207,7 @@ struct ssh2_transport_state {
* Flag indicating that the current rekey is intended to finish
* with a newly cross-certified host key.
*/
int cross_certifying;
bool cross_certifying;
ssh_key *const *hostkeys;
int nhostkeys;

View File

@ -27,7 +27,7 @@ struct ssh2_userauth_server_state {
ptrlen username, service, method;
unsigned methods, this_method;
int partial_success;
bool partial_success;
AuthKbdInt *aki;
@ -162,7 +162,7 @@ static void ssh2_userauth_server_process_queue(PacketProtocolLayer *ppl)
if (!auth_none(s->authpolicy, s->username))
goto failure;
} else if (ptrlen_eq_string(s->method, "password")) {
int changing;
bool changing;
ptrlen password, new_password, *new_password_ptr;
s->this_method = AUTHMETHOD_PASSWORD;
@ -192,7 +192,7 @@ static void ssh2_userauth_server_process_queue(PacketProtocolLayer *ppl)
goto failure;
}
} else if (ptrlen_eq_string(s->method, "publickey")) {
int has_signature, success;
bool has_signature, success;
ptrlen algorithm, blob, signature;
const ssh_keyalg *keyalg;
ssh_key *key;

View File

@ -23,10 +23,10 @@ struct ssh2_userauth_state {
PacketProtocolLayer *transport_layer, *successor_layer;
Filename *keyfile;
int tryagent, change_username;
bool tryagent, change_username;
char *hostname, *fullhostname;
char *default_username;
int try_ki_auth, try_gssapi_auth, try_gssapi_kex_auth, gssapi_fwd;
bool try_ki_auth, try_gssapi_auth, try_gssapi_kex_auth, gssapi_fwd;
ptrlen session_id;
enum {
@ -39,28 +39,28 @@ struct ssh2_userauth_state {
AUTH_TYPE_KEYBOARD_INTERACTIVE,
AUTH_TYPE_KEYBOARD_INTERACTIVE_QUIET
} type;
int need_pw, can_pubkey, can_passwd, can_keyb_inter;
bool need_pw, can_pubkey, can_passwd, can_keyb_inter;
int userpass_ret;
int tried_pubkey_config, done_agent;
bool tried_pubkey_config, done_agent;
struct ssh_connection_shared_gss_state *shgss;
#ifndef NO_GSSAPI
int can_gssapi;
int can_gssapi_keyex_auth;
int tried_gssapi;
int tried_gssapi_keyex_auth;
bool can_gssapi;
bool can_gssapi_keyex_auth;
bool tried_gssapi;
bool tried_gssapi_keyex_auth;
time_t gss_cred_expiry;
Ssh_gss_buf gss_buf;
Ssh_gss_buf gss_rcvtok, gss_sndtok;
Ssh_gss_stat gss_stat;
#endif
int kbd_inter_refused;
bool kbd_inter_refused;
prompts_t *cur_prompt;
int num_prompts;
char *username;
char *password;
int got_username;
bool got_username;
strbuf *publickey_blob;
int privatekey_available, privatekey_encrypted;
bool privatekey_available, privatekey_encrypted;
char *publickey_algorithm;
char *publickey_comment;
void *agent_response_to_free;
@ -71,7 +71,7 @@ struct ssh2_userauth_state {
ptrlen pk, alg, comment;
int len;
PktOut *pktout;
int want_user_input;
bool want_user_input;
agent_pending_query *auth_agent_query;
bufchain banner;
@ -81,11 +81,11 @@ struct ssh2_userauth_state {
static void ssh2_userauth_free(PacketProtocolLayer *);
static void ssh2_userauth_process_queue(PacketProtocolLayer *);
static int ssh2_userauth_get_specials(
static bool ssh2_userauth_get_specials(
PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx);
static void ssh2_userauth_special_cmd(PacketProtocolLayer *ppl,
SessionSpecialCode code, int arg);
static int ssh2_userauth_want_user_input(PacketProtocolLayer *ppl);
static bool ssh2_userauth_want_user_input(PacketProtocolLayer *ppl);
static void ssh2_userauth_got_user_input(PacketProtocolLayer *ppl);
static void ssh2_userauth_reconfigure(PacketProtocolLayer *ppl, Conf *conf);
@ -114,11 +114,10 @@ static const struct PacketProtocolLayerVtable ssh2_userauth_vtable = {
PacketProtocolLayer *ssh2_userauth_new(
PacketProtocolLayer *successor_layer,
const char *hostname, const char *fullhostname,
Filename *keyfile, int tryagent,
const char *default_username, int change_username,
int try_ki_auth,
int try_gssapi_auth, int try_gssapi_kex_auth,
int gssapi_fwd, struct ssh_connection_shared_gss_state *shgss)
Filename *keyfile, bool tryagent,
const char *default_username, bool change_username,
bool try_ki_auth, bool try_gssapi_auth, bool try_gssapi_kex_auth,
bool gssapi_fwd, struct ssh_connection_shared_gss_state *shgss)
{
struct ssh2_userauth_state *s = snew(struct ssh2_userauth_state);
memset(s, 0, sizeof(*s));
@ -1101,7 +1100,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
s->num_prompts = get_uint32(pktin);
for (i = 0; i < s->num_prompts; i++) {
ptrlen prompt;
int echo;
bool echo;
static char noprompt[] =
"<server failed to send prompt>: ";
@ -1213,7 +1212,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
/*
* Plain old password authentication.
*/
int changereq_first_time; /* not live over crReturn */
bool changereq_first_time; /* not live over crReturn */
s->ppl.bpp->pls->actx = SSH2_PKTCTX_PASSWORD;
@ -1296,7 +1295,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
* Loop until the server accepts it.
*/
int got_new = false; /* not live over crReturn */
bool got_new = false; /* not live over crReturn */
ptrlen prompt; /* not live over crReturn */
{
@ -1634,7 +1633,7 @@ static PktOut *ssh2_userauth_gss_packet(
}
#endif
static int ssh2_userauth_get_specials(
static bool ssh2_userauth_get_specials(
PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx)
{
/* No specials provided by this layer. */
@ -1647,7 +1646,7 @@ static void ssh2_userauth_special_cmd(PacketProtocolLayer *ppl,
/* No specials provided by this layer. */
}
static int ssh2_userauth_want_user_input(PacketProtocolLayer *ppl)
static bool ssh2_userauth_want_user_input(PacketProtocolLayer *ppl)
{
struct ssh2_userauth_state *s =
container_of(ppl, struct ssh2_userauth_state, ppl);

View File

@ -57,14 +57,14 @@ struct AESContext {
void (*encrypt_cbc)(unsigned char*, int, AESContext*);
void (*decrypt_cbc)(unsigned char*, int, AESContext*);
void (*sdctr)(unsigned char*, int, AESContext*);
int isNI;
bool isNI;
};
static void aes_encrypt_cbc_sw(unsigned char*, int, AESContext*);
static void aes_decrypt_cbc_sw(unsigned char*, int, AESContext*);
static void aes_sdctr_sw(unsigned char*, int, AESContext*);
INLINE static int supports_aes_ni();
INLINE static bool supports_aes_ni();
static void aes_setup_ni(AESContext * ctx,
const unsigned char *key, int keylen);
@ -1219,7 +1219,7 @@ const struct ssh2_ciphers ssh2_aes = {
#if defined(__clang__) || defined(__GNUC__)
#include <cpuid.h>
INLINE static int supports_aes_ni()
INLINE static bool supports_aes_ni()
{
unsigned int CPUInfo[4];
__cpuid(1, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
@ -1228,7 +1228,7 @@ INLINE static int supports_aes_ni()
#else /* defined(__clang__) || defined(__GNUC__) */
INLINE static int supports_aes_ni()
INLINE static bool supports_aes_ni()
{
unsigned int CPUInfo[4];
__cpuid(CPUInfo, 1);
@ -1755,9 +1755,9 @@ static void aes_setup_ni(AESContext * ctx, const unsigned char *key, int keylen)
assert(0);
}
INLINE static int supports_aes_ni()
INLINE static bool supports_aes_ni()
{
return 0;
return false;
}
#endif /* COMPILER_SUPPORTS_AES_NI */

View File

@ -2085,7 +2085,8 @@ Bignum modinv(Bignum number, Bignum modulus)
char *bignum_decimal(Bignum x)
{
int ndigits, ndigit;
int i, iszero;
int i;
bool iszero;
BignumInt carry;
char *ret;
BignumInt *workspace;
@ -2130,7 +2131,7 @@ char *bignum_decimal(Bignum x)
ndigit = ndigits - 1;
ret[ndigit] = '\0';
do {
iszero = 1;
iszero = true;
carry = 0;
for (i = 0; i < (int)x[0]; i++) {
/*
@ -2159,7 +2160,7 @@ char *bignum_decimal(Bignum x)
carry = r;
if (workspace[i])
iszero = 0;
iszero = false;
}
ret[--ndigit] = (char) (carry + '0');
} while (!iszero);

View File

@ -17,7 +17,7 @@ struct BinaryPacketProtocolVtable {
struct BinaryPacketProtocol {
const struct BinaryPacketProtocolVtable *vt;
bufchain *in_raw, *out_raw;
int input_eof; /* set this if in_raw will never be added to again */
bool input_eof; /* set this if in_raw will never be added to again */
PktInQueue in_pq;
PktOutQueue out_pq;
PacketLogSettings *pls;
@ -39,7 +39,7 @@ struct BinaryPacketProtocol {
* error message (either because it's not to be treated as an
* error at all, or because some other error message has already
* been emitted). */
int expect_close;
bool expect_close;
};
#define ssh_bpp_handle_input(bpp) ((bpp)->vt->handle_input(bpp))
@ -68,7 +68,7 @@ void ssh_bpp_common_setup(BinaryPacketProtocol *);
/* Common helper functions between the SSH-2 full and bare BPPs */
void ssh2_bpp_queue_disconnect(BinaryPacketProtocol *bpp,
const char *msg, int category);
int ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin);
bool ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin);
/* Convenience macro for BPPs to send formatted strings to the Event
* Log. Assumes a function parameter called 'bpp' is in scope, and
@ -92,7 +92,7 @@ int ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin);
*/
struct DataTransferStats {
struct {
int running;
bool running;
unsigned long remaining;
} in, out;
};
@ -103,17 +103,17 @@ struct DataTransferStats {
((stats)->direction.remaining -= (size), false))
BinaryPacketProtocol *ssh2_bpp_new(
LogContext *logctx, struct DataTransferStats *stats, int is_server);
LogContext *logctx, struct DataTransferStats *stats, bool is_server);
void ssh2_bpp_new_outgoing_crypto(
BinaryPacketProtocol *bpp,
const struct ssh2_cipheralg *cipher, const void *ckey, const void *iv,
const struct ssh2_macalg *mac, int etm_mode, const void *mac_key,
const struct ssh_compression_alg *compression, int delayed_compression);
const struct ssh2_macalg *mac, bool etm_mode, const void *mac_key,
const struct ssh_compression_alg *compression, bool delayed_compression);
void ssh2_bpp_new_incoming_crypto(
BinaryPacketProtocol *bpp,
const struct ssh2_cipheralg *cipher, const void *ckey, const void *iv,
const struct ssh2_macalg *mac, int etm_mode, const void *mac_key,
const struct ssh_compression_alg *compression, int delayed_compression);
const struct ssh2_macalg *mac, bool etm_mode, const void *mac_key,
const struct ssh_compression_alg *compression, bool delayed_compression);
/*
* A query method specific to the interface between ssh2transport and
@ -124,7 +124,7 @@ void ssh2_bpp_new_incoming_crypto(
* to start a rekey because then we'd stop responding to anything
* _other_ than transport-layer packets and deadlock the protocol.
*/
int ssh2_bpp_rekey_inadvisable(BinaryPacketProtocol *bpp);
bool ssh2_bpp_rekey_inadvisable(BinaryPacketProtocol *bpp);
BinaryPacketProtocol *ssh2_bare_bpp_new(LogContext *logctx);
@ -139,9 +139,9 @@ struct ssh_version_receiver {
int major_version);
};
BinaryPacketProtocol *ssh_verstring_new(
Conf *conf, LogContext *logctx, int bare_connection_mode,
Conf *conf, LogContext *logctx, bool bare_connection_mode,
const char *protoversion, struct ssh_version_receiver *rcv,
int server_mode, const char *impl_name);
bool server_mode, const char *impl_name);
const char *ssh_verstring_get_remote(BinaryPacketProtocol *);
const char *ssh_verstring_get_local(BinaryPacketProtocol *);
int ssh_verstring_get_bugs(BinaryPacketProtocol *);

110
sshchan.h
View File

@ -19,42 +19,42 @@ struct ChannelVtable {
void (*open_confirmation)(Channel *);
void (*open_failed)(Channel *, const char *error_text);
int (*send)(Channel *, int is_stderr, const void *buf, int len);
int (*send)(Channel *, bool is_stderr, const void *buf, int len);
void (*send_eof)(Channel *);
void (*set_input_wanted)(Channel *, int wanted);
void (*set_input_wanted)(Channel *, bool wanted);
char *(*log_close_msg)(Channel *);
int (*want_close)(Channel *, int sent_local_eof, int rcvd_remote_eof);
bool (*want_close)(Channel *, bool sent_local_eof, bool rcvd_remote_eof);
/* A method for every channel request we know of. All of these
* return true for success or false for failure. */
int (*rcvd_exit_status)(Channel *, int status);
int (*rcvd_exit_signal)(
Channel *chan, ptrlen signame, int core_dumped, ptrlen msg);
int (*rcvd_exit_signal_numeric)(
Channel *chan, int signum, int core_dumped, ptrlen msg);
int (*run_shell)(Channel *chan);
int (*run_command)(Channel *chan, ptrlen command);
int (*run_subsystem)(Channel *chan, ptrlen subsys);
int (*enable_x11_forwarding)(
Channel *chan, int oneshot, ptrlen authproto, ptrlen authdata,
bool (*rcvd_exit_status)(Channel *, int status);
bool (*rcvd_exit_signal)(
Channel *chan, ptrlen signame, bool core_dumped, ptrlen msg);
bool (*rcvd_exit_signal_numeric)(
Channel *chan, int signum, bool core_dumped, ptrlen msg);
bool (*run_shell)(Channel *chan);
bool (*run_command)(Channel *chan, ptrlen command);
bool (*run_subsystem)(Channel *chan, ptrlen subsys);
bool (*enable_x11_forwarding)(
Channel *chan, bool oneshot, ptrlen authproto, ptrlen authdata,
unsigned screen_number);
int (*enable_agent_forwarding)(Channel *chan);
int (*allocate_pty)(
bool (*enable_agent_forwarding)(Channel *chan);
bool (*allocate_pty)(
Channel *chan, ptrlen termtype, unsigned width, unsigned height,
unsigned pixwidth, unsigned pixheight, struct ssh_ttymodes modes);
int (*set_env)(Channel *chan, ptrlen var, ptrlen value);
int (*send_break)(Channel *chan, unsigned length);
int (*send_signal)(Channel *chan, ptrlen signame);
int (*change_window_size)(
bool (*set_env)(Channel *chan, ptrlen var, ptrlen value);
bool (*send_break)(Channel *chan, unsigned length);
bool (*send_signal)(Channel *chan, ptrlen signame);
bool (*change_window_size)(
Channel *chan, unsigned width, unsigned height,
unsigned pixwidth, unsigned pixheight);
/* A method for signalling success/failure responses to channel
* requests initiated from the SshChannel vtable with want_reply
* true. */
void (*request_response)(Channel *, int success);
void (*request_response)(Channel *, bool success);
};
struct Channel {
@ -111,31 +111,31 @@ void chan_remotely_opened_failure(Channel *chan, const char *errtext);
/* want_close for any channel that wants the default behaviour of not
* closing until both directions have had an EOF */
int chan_default_want_close(Channel *, int, int);
bool chan_default_want_close(Channel *, bool, bool);
/* default implementations that refuse all the channel requests */
int chan_no_exit_status(Channel *, int);
int chan_no_exit_signal(Channel *, ptrlen, int, ptrlen);
int chan_no_exit_signal_numeric(Channel *, int, int, ptrlen);
int chan_no_run_shell(Channel *chan);
int chan_no_run_command(Channel *chan, ptrlen command);
int chan_no_run_subsystem(Channel *chan, ptrlen subsys);
int chan_no_enable_x11_forwarding(
Channel *chan, int oneshot, ptrlen authproto, ptrlen authdata,
bool chan_no_exit_status(Channel *, int);
bool chan_no_exit_signal(Channel *, ptrlen, bool, ptrlen);
bool chan_no_exit_signal_numeric(Channel *, int, bool, ptrlen);
bool chan_no_run_shell(Channel *chan);
bool chan_no_run_command(Channel *chan, ptrlen command);
bool chan_no_run_subsystem(Channel *chan, ptrlen subsys);
bool chan_no_enable_x11_forwarding(
Channel *chan, bool oneshot, ptrlen authproto, ptrlen authdata,
unsigned screen_number);
int chan_no_enable_agent_forwarding(Channel *chan);
int chan_no_allocate_pty(
bool chan_no_enable_agent_forwarding(Channel *chan);
bool chan_no_allocate_pty(
Channel *chan, ptrlen termtype, unsigned width, unsigned height,
unsigned pixwidth, unsigned pixheight, struct ssh_ttymodes modes);
int chan_no_set_env(Channel *chan, ptrlen var, ptrlen value);
int chan_no_send_break(Channel *chan, unsigned length);
int chan_no_send_signal(Channel *chan, ptrlen signame);
int chan_no_change_window_size(
bool chan_no_set_env(Channel *chan, ptrlen var, ptrlen value);
bool chan_no_send_break(Channel *chan, unsigned length);
bool chan_no_send_signal(Channel *chan, ptrlen signame);
bool chan_no_change_window_size(
Channel *chan, unsigned width, unsigned height,
unsigned pixwidth, unsigned pixheight);
/* default implementation that never expects to receive a response */
void chan_no_request_response(Channel *, int);
void chan_no_request_response(Channel *, bool);
/*
* Constructor for a trivial do-nothing implementation of
@ -156,7 +156,7 @@ Channel *zombiechan_new(void);
*/
struct SshChannelVtable {
int (*write)(SshChannel *c, int is_stderr, const void *, int);
int (*write)(SshChannel *c, bool is_stderr, const void *, int);
void (*write_eof)(SshChannel *c);
void (*initiate_close)(SshChannel *c, const char *err);
void (*unthrottle)(SshChannel *c, int bufsize);
@ -174,7 +174,7 @@ struct SshChannelVtable {
* want_reply flag, which will cause a callback to
* chan_request_response when the result is available.
*
* The ones that return 'int' use it to indicate that the SSH
* The ones that return 'bool' use it to indicate that the SSH
* protocol in use doesn't support this request at all.
*
* (It's also intentional that not all of them have a want_reply
@ -185,28 +185,28 @@ struct SshChannelVtable {
*/
void (*send_exit_status)(SshChannel *c, int status);
void (*send_exit_signal)(
SshChannel *c, ptrlen signame, int core_dumped, ptrlen msg);
SshChannel *c, ptrlen signame, bool core_dumped, ptrlen msg);
void (*send_exit_signal_numeric)(
SshChannel *c, int signum, int core_dumped, ptrlen msg);
SshChannel *c, int signum, bool core_dumped, ptrlen msg);
void (*request_x11_forwarding)(
SshChannel *c, int want_reply, const char *authproto,
const char *authdata, int screen_number, int oneshot);
SshChannel *c, bool want_reply, const char *authproto,
const char *authdata, int screen_number, bool oneshot);
void (*request_agent_forwarding)(
SshChannel *c, int want_reply);
SshChannel *c, bool want_reply);
void (*request_pty)(
SshChannel *c, int want_reply, Conf *conf, int w, int h);
int (*send_env_var)(
SshChannel *c, int want_reply, const char *var, const char *value);
SshChannel *c, bool want_reply, Conf *conf, int w, int h);
bool (*send_env_var)(
SshChannel *c, bool want_reply, const char *var, const char *value);
void (*start_shell)(
SshChannel *c, int want_reply);
SshChannel *c, bool want_reply);
void (*start_command)(
SshChannel *c, int want_reply, const char *command);
int (*start_subsystem)(
SshChannel *c, int want_reply, const char *subsystem);
int (*send_serial_break)(
SshChannel *c, int want_reply, int length); /* length=0 for default */
int (*send_signal)(
SshChannel *c, int want_reply, const char *signame);
SshChannel *c, bool want_reply, const char *command);
bool (*start_subsystem)(
SshChannel *c, bool want_reply, const char *subsystem);
bool (*send_serial_break)(
SshChannel *c, bool want_reply, int length); /* length=0 for default */
bool (*send_signal)(
SshChannel *c, bool want_reply, const char *signame);
void (*send_terminal_size_change)(
SshChannel *c, int w, int h);
void (*hint_channel_is_simple)(SshChannel *c);
@ -265,7 +265,7 @@ struct SshChannel {
mainchan *mainchan_new(
PacketProtocolLayer *ppl, ConnectionLayer *cl, Conf *conf,
int term_width, int term_height, int is_simple, SshChannel **sc_out);
int term_width, int term_height, bool is_simple, SshChannel **sc_out);
void mainchan_get_specials(
mainchan *mc, add_special_fn_t add_special, void *ctx);
void mainchan_special_cmd(mainchan *mc, SessionSpecialCode code, int arg);

View File

@ -72,7 +72,7 @@ static IdempotentCallback ic_pktin_free = {
};
static PktIn *pq_in_after(PacketQueueBase *pqb,
PacketQueueNode *prev, int pop)
PacketQueueNode *prev, bool pop)
{
PacketQueueNode *node = prev->next;
if (node == &pqb->end)
@ -94,7 +94,7 @@ static PktIn *pq_in_after(PacketQueueBase *pqb,
}
static PktOut *pq_out_after(PacketQueueBase *pqb,
PacketQueueNode *prev, int pop)
PacketQueueNode *prev, bool pop)
{
PacketQueueNode *node = prev->next;
if (node == &pqb->end)
@ -261,11 +261,11 @@ void ssh_free_pktout(PktOut *pkt)
*/
static void zombiechan_free(Channel *chan);
static int zombiechan_send(Channel *chan, int is_stderr, const void *, int);
static void zombiechan_set_input_wanted(Channel *chan, int wanted);
static int zombiechan_send(Channel *chan, bool is_stderr, const void *, int);
static void zombiechan_set_input_wanted(Channel *chan, bool wanted);
static void zombiechan_do_nothing(Channel *chan);
static void zombiechan_open_failure(Channel *chan, const char *);
static int zombiechan_want_close(Channel *chan, int sent_eof, int rcvd_eof);
static bool zombiechan_want_close(Channel *chan, bool sent_eof, bool rcvd_eof);
static char *zombiechan_log_close_msg(Channel *chan) { return NULL; }
static const struct ChannelVtable zombiechan_channelvt = {
@ -317,19 +317,19 @@ static void zombiechan_open_failure(Channel *chan, const char *errtext)
assert(chan->vt == &zombiechan_channelvt);
}
static int zombiechan_send(Channel *chan, int is_stderr,
static int zombiechan_send(Channel *chan, bool is_stderr,
const void *data, int length)
{
assert(chan->vt == &zombiechan_channelvt);
return 0;
}
static void zombiechan_set_input_wanted(Channel *chan, int enable)
static void zombiechan_set_input_wanted(Channel *chan, bool enable)
{
assert(chan->vt == &zombiechan_channelvt);
}
static int zombiechan_want_close(Channel *chan, int sent_eof, int rcvd_eof)
static bool zombiechan_want_close(Channel *chan, bool sent_eof, bool rcvd_eof)
{
return true;
}
@ -349,8 +349,8 @@ void chan_remotely_opened_failure(Channel *chan, const char *errtext)
assert(0 && "this channel type should never receive OPEN_FAILURE");
}
int chan_default_want_close(
Channel *chan, int sent_local_eof, int rcvd_remote_eof)
bool chan_default_want_close(
Channel *chan, bool sent_local_eof, bool rcvd_remote_eof)
{
/*
* Default close policy: we start initiating the CHANNEL_CLOSE
@ -359,80 +359,80 @@ int chan_default_want_close(
return sent_local_eof && rcvd_remote_eof;
}
int chan_no_exit_status(Channel *chan, int status)
bool chan_no_exit_status(Channel *chan, int status)
{
return false;
}
int chan_no_exit_signal(
Channel *chan, ptrlen signame, int core_dumped, ptrlen msg)
bool chan_no_exit_signal(
Channel *chan, ptrlen signame, bool core_dumped, ptrlen msg)
{
return false;
}
int chan_no_exit_signal_numeric(
Channel *chan, int signum, int core_dumped, ptrlen msg)
bool chan_no_exit_signal_numeric(
Channel *chan, int signum, bool core_dumped, ptrlen msg)
{
return false;
}
int chan_no_run_shell(Channel *chan)
bool chan_no_run_shell(Channel *chan)
{
return false;
}
int chan_no_run_command(Channel *chan, ptrlen command)
bool chan_no_run_command(Channel *chan, ptrlen command)
{
return false;
}
int chan_no_run_subsystem(Channel *chan, ptrlen subsys)
bool chan_no_run_subsystem(Channel *chan, ptrlen subsys)
{
return false;
}
int chan_no_enable_x11_forwarding(
Channel *chan, int oneshot, ptrlen authproto, ptrlen authdata,
bool chan_no_enable_x11_forwarding(
Channel *chan, bool oneshot, ptrlen authproto, ptrlen authdata,
unsigned screen_number)
{
return false;
}
int chan_no_enable_agent_forwarding(Channel *chan)
bool chan_no_enable_agent_forwarding(Channel *chan)
{
return false;
}
int chan_no_allocate_pty(
bool chan_no_allocate_pty(
Channel *chan, ptrlen termtype, unsigned width, unsigned height,
unsigned pixwidth, unsigned pixheight, struct ssh_ttymodes modes)
{
return false;
}
int chan_no_set_env(Channel *chan, ptrlen var, ptrlen value)
bool chan_no_set_env(Channel *chan, ptrlen var, ptrlen value)
{
return false;
}
int chan_no_send_break(Channel *chan, unsigned length)
bool chan_no_send_break(Channel *chan, unsigned length)
{
return false;
}
int chan_no_send_signal(Channel *chan, ptrlen signame)
bool chan_no_send_signal(Channel *chan, ptrlen signame)
{
return false;
}
int chan_no_change_window_size(
bool chan_no_change_window_size(
Channel *chan, unsigned width, unsigned height,
unsigned pixwidth, unsigned pixheight)
{
return false;
}
void chan_no_request_response(Channel *chan, int success)
void chan_no_request_response(Channel *chan, bool success)
{
assert(0 && "this channel type should never send a want-reply request");
}
@ -687,12 +687,12 @@ unsigned alloc_channel_id_general(tree234 *channels, size_t localid_offset)
* lists of protocol identifiers in SSH-2.
*/
int first_in_commasep_string(char const *needle, char const *haystack,
int haylen)
bool first_in_commasep_string(char const *needle, char const *haystack,
int haylen)
{
int needlen;
if (!needle || !haystack) /* protect against null pointers */
return 0;
return false;
needlen = strlen(needle);
if (haylen >= needlen && /* haystack is long enough */
@ -700,11 +700,11 @@ int first_in_commasep_string(char const *needle, char const *haystack,
(haylen == needlen || haystack[needlen] == ',')
/* either , or EOS follows */
)
return 1;
return 0;
return true;
return false;
}
int in_commasep_string(char const *needle, char const *haystack, int haylen)
bool in_commasep_string(char const *needle, char const *haystack, int haylen)
{
char *p;
@ -733,7 +733,7 @@ void add_to_commasep(strbuf *buf, const char *data)
put_data(buf, data, strlen(data));
}
int get_commasep_word(ptrlen *list, ptrlen *word)
bool get_commasep_word(ptrlen *list, ptrlen *word)
{
const char *comma;
@ -905,7 +905,7 @@ void ssh2_bpp_queue_disconnect(BinaryPacketProtocol *bpp,
(0 SSH2_MESSAGE_TYPES(BITMAP_UNIVERSAL, BITMAP_CONDITIONAL, \
BITMAP_CONDITIONAL, (32*y)))
int ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin)
bool ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin)
{
static const unsigned valid_bitmap[] = {
SSH2_BITMAP_WORD(0),
@ -992,7 +992,7 @@ int verify_ssh_manual_host_key(
* Common functions shared between SSH-1 layers.
*/
int ssh1_common_get_specials(
bool ssh1_common_get_specials(
PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx)
{
/*
@ -1008,7 +1008,7 @@ int ssh1_common_get_specials(
return false;
}
int ssh1_common_filter_queue(PacketProtocolLayer *ppl)
bool ssh1_common_filter_queue(PacketProtocolLayer *ppl)
{
PktIn *pktin;
ptrlen msg;

View File

@ -75,7 +75,7 @@ static void crc_update(uint32_t *a, void *b)
}
/* detect if a block is used in a particular pattern */
static int check_crc(uint8_t *S, uint8_t *buf, uint32_t len, uint8_t *IV)
static bool check_crc(uint8_t *S, uint8_t *buf, uint32_t len, uint8_t *IV)
{
uint32_t crc;
uint8_t *c;
@ -98,7 +98,7 @@ static int check_crc(uint8_t *S, uint8_t *buf, uint32_t len, uint8_t *IV)
}
/* Detect a crc32 compensation attack on a packet */
int detect_attack(
bool detect_attack(
struct crcda_ctx *ctx, uint8_t *buf, uint32_t len, uint8_t *IV)
{
register uint32_t i, j;
@ -125,20 +125,20 @@ int detect_attack(
for (c = buf; c < buf + len; c += SSH_BLOCKSIZE) {
if (IV && (!CMP(c, IV))) {
if ((check_crc(c, buf, len, IV)))
return 1; /* attack detected */
return true; /* attack detected */
else
break;
}
for (d = buf; d < c; d += SSH_BLOCKSIZE) {
if (!CMP(c, d)) {
if ((check_crc(c, buf, len, IV)))
return 1; /* attack detected */
return true; /* attack detected */
else
break;
}
}
}
return 0; /* ok */
return false; /* ok */
}
memset(ctx->h, HASH_UNUSEDCHAR, ctx->n * HASH_ENTRYSIZE);
@ -151,18 +151,18 @@ int detect_attack(
if (ctx->h[i] == HASH_IV) {
if (!CMP(c, IV)) {
if (check_crc(c, buf, len, IV))
return 1; /* attack detected */
return true; /* attack detected */
else
break;
}
} else if (!CMP(c, buf + ctx->h[i] * SSH_BLOCKSIZE)) {
if (check_crc(c, buf, len, IV))
return 1; /* attack detected */
return true; /* attack detected */
else
break;
}
}
ctx->h[i] = j;
}
return 0; /* ok */
return false; /* ok */
}

View File

@ -178,7 +178,7 @@ static void dh_init(struct dh_ctx *ctx)
ctx->x = ctx->e = NULL;
}
int dh_is_gex(const struct ssh_kex *kex)
bool dh_is_gex(const struct ssh_kex *kex)
{
const struct dh_extra *extra = (const struct dh_extra *)kex->extra;
return extra->pdata == NULL;

View File

@ -104,16 +104,16 @@ static char *dss_cache_str(ssh_key *key)
return p;
}
static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
static bool dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
{
struct dss_key *dss = container_of(key, struct dss_key, sshk);
BinarySource src[1];
unsigned char hash[20];
Bignum r, s, w, gu1p, yu2p, gu1yu2p, u1, u2, sha, v;
int ret;
bool toret;
if (!dss->p)
return 0;
return false;
BinarySource_BARE_INIT(src, sig.ptr, sig.len);
@ -134,7 +134,7 @@ static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
if (get_err(src) || !ptrlen_eq_string(type, "ssh-dss") ||
sig.len != 40)
return 0;
return false;
}
/* Now we're sitting on a 40-byte string for sure. */
@ -145,13 +145,13 @@ static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
freebn(r);
if (s)
freebn(s);
return 0;
return false;
}
if (!bignum_cmp(s, Zero)) {
freebn(r);
freebn(s);
return 0;
return false;
}
/*
@ -161,7 +161,7 @@ static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
if (!w) {
freebn(r);
freebn(s);
return 0;
return false;
}
/*
@ -188,7 +188,7 @@ static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
* Step 5. v should now be equal to r.
*/
ret = !bignum_cmp(v, r);
toret = !bignum_cmp(v, r);
freebn(w);
freebn(sha);
@ -201,7 +201,7 @@ static int dss_verify(ssh_key *key, ptrlen sig, ptrlen data)
freebn(r);
freebn(s);
return ret;
return toret;
}
static void dss_public_blob(ssh_key *key, BinarySink *bs)

221
sshecc.c
View File

@ -64,7 +64,7 @@ static void initialise_wcurve(struct ec_curve *curve, int bits,
curve->w.G.x = bignum_from_bytes(Gx, length);
curve->w.G.y = bignum_from_bytes(Gy, length);
curve->w.G.curve = curve;
curve->w.G.infinity = 0;
curve->w.G.infinity = false;
}
static void initialise_mcurve(struct ec_curve *curve, int bits,
@ -89,7 +89,7 @@ static void initialise_mcurve(struct ec_curve *curve, int bits,
curve->m.G.y = NULL;
curve->m.G.z = NULL;
curve->m.G.curve = curve;
curve->m.G.infinity = 0;
curve->m.G.infinity = false;
}
static void initialise_ecurve(struct ec_curve *curve, int bits,
@ -113,13 +113,13 @@ static void initialise_ecurve(struct ec_curve *curve, int bits,
curve->e.B.x = bignum_from_bytes(Bx, length);
curve->e.B.y = bignum_from_bytes(By, length);
curve->e.B.curve = curve;
curve->e.B.infinity = 0;
curve->e.B.infinity = false;
}
static struct ec_curve *ec_p256(void)
{
static struct ec_curve curve = { 0 };
static unsigned char initialised = 0;
static bool initialised = false;
if (!initialised)
{
@ -164,7 +164,7 @@ static struct ec_curve *ec_p256(void)
curve.textname = curve.name = "nistp256";
/* Now initialised, no need to do it again */
initialised = 1;
initialised = true;
}
return &curve;
@ -173,7 +173,7 @@ static struct ec_curve *ec_p256(void)
static struct ec_curve *ec_p384(void)
{
static struct ec_curve curve = { 0 };
static unsigned char initialised = 0;
static bool initialised = false;
if (!initialised)
{
@ -230,7 +230,7 @@ static struct ec_curve *ec_p384(void)
curve.textname = curve.name = "nistp384";
/* Now initialised, no need to do it again */
initialised = 1;
initialised = true;
}
return &curve;
@ -239,7 +239,7 @@ static struct ec_curve *ec_p384(void)
static struct ec_curve *ec_p521(void)
{
static struct ec_curve curve = { 0 };
static unsigned char initialised = 0;
static bool initialised = false;
if (!initialised)
{
@ -314,7 +314,7 @@ static struct ec_curve *ec_p521(void)
curve.textname = curve.name = "nistp521";
/* Now initialised, no need to do it again */
initialised = 1;
initialised = true;
}
return &curve;
@ -323,7 +323,7 @@ static struct ec_curve *ec_p521(void)
static struct ec_curve *ec_curve25519(void)
{
static struct ec_curve curve = { 0 };
static unsigned char initialised = 0;
static bool initialised = false;
if (!initialised)
{
@ -359,7 +359,7 @@ static struct ec_curve *ec_curve25519(void)
curve.textname = "Curve25519";
/* Now initialised, no need to do it again */
initialised = 1;
initialised = true;
}
return &curve;
@ -368,7 +368,7 @@ static struct ec_curve *ec_curve25519(void)
static struct ec_curve *ec_ed25519(void)
{
static struct ec_curve curve = { 0 };
static unsigned char initialised = 0;
static bool initialised = false;
if (!initialised)
{
@ -411,7 +411,7 @@ static struct ec_curve *ec_ed25519(void)
curve.textname = "Ed25519";
/* Now initialised, no need to do it again */
initialised = 1;
initialised = true;
}
return &curve;
@ -419,13 +419,13 @@ static struct ec_curve *ec_ed25519(void)
/* Return 1 if a is -3 % p, otherwise return 0
* This is used because there are some maths optimisations */
static int ec_aminus3(const struct ec_curve *curve)
static bool ec_aminus3(const struct ec_curve *curve)
{
int ret;
bool ret;
Bignum _p;
if (curve->type != EC_WEIERSTRASS) {
return 0;
return false;
}
_p = bignum_add_long(curve->w.a, 3);
@ -512,20 +512,20 @@ void ec_point_free(struct ec_point *point)
if (point->x) freebn(point->x);
if (point->y) freebn(point->y);
if (point->z) freebn(point->z);
point->infinity = 0;
point->infinity = false;
sfree(point);
}
static struct ec_point *ec_point_new(const struct ec_curve *curve,
const Bignum x, const Bignum y, const Bignum z,
unsigned char infinity)
bool infinity)
{
struct ec_point *point = snewn(1, struct ec_point);
point->curve = curve;
point->x = x;
point->y = y;
point->z = z;
point->infinity = infinity ? 1 : 0;
point->infinity = infinity;
return point;
}
@ -539,14 +539,14 @@ static struct ec_point *ec_point_copy(const struct ec_point *a)
a->infinity);
}
static int ec_point_verify(const struct ec_point *a)
static bool ec_point_verify(const struct ec_point *a)
{
if (a->infinity) {
return 1;
return true;
} else if (a->curve->type == EC_EDWARDS) {
/* Check y^2 - x^2 - 1 - d * x^2 * y^2 == 0 */
Bignum y2, x2, tmp, tmp2, tmp3;
int ret;
bool ret;
y2 = ecf_square(a->y, a->curve);
x2 = ecf_square(a->x, a->curve);
@ -564,7 +564,7 @@ static int ec_point_verify(const struct ec_point *a)
return ret;
} else if (a->curve->type == EC_WEIERSTRASS) {
/* Verify y^2 = x^3 + ax + b */
int ret = 0;
bool ret = false;
Bignum lhs = NULL, x3 = NULL, ax = NULL, x3ax = NULL, x3axm = NULL, x3axb = NULL, rhs = NULL;
@ -586,13 +586,13 @@ static int ec_point_verify(const struct ec_point *a)
rhs = bigmod(x3axb, a->curve->p);
freebn(x3axb);
ret = bignum_cmp(lhs, rhs) ? 0 : 1;
ret = !bignum_cmp(lhs, rhs);
freebn(lhs);
freebn(rhs);
return ret;
} else {
return 0;
return false;
}
}
@ -600,17 +600,17 @@ static int ec_point_verify(const struct ec_point *a)
* Elliptic curve point maths
*/
/* Returns 1 on success and 0 on memory error */
static int ecp_normalise(struct ec_point *a)
/* Returns true on success and false on memory error */
static bool ecp_normalise(struct ec_point *a)
{
if (!a) {
/* No point */
return 0;
return false;
}
if (a->infinity) {
/* Point is at infinity - i.e. normalised */
return 1;
return true;
}
if (a->curve->type == EC_WEIERSTRASS) {
@ -621,17 +621,17 @@ static int ecp_normalise(struct ec_point *a)
if (!a->x || !a->y) {
/* No point defined */
return 0;
return false;
} else if (!a->z) {
/* Already normalised */
return 1;
return true;
}
Z2 = ecf_square(a->z, a->curve);
Z2inv = modinv(Z2, a->curve->p);
if (!Z2inv) {
freebn(Z2);
return 0;
return false;
}
tx = modmul(a->x, Z2inv, a->curve->p);
freebn(Z2inv);
@ -642,7 +642,7 @@ static int ecp_normalise(struct ec_point *a)
freebn(Z3);
if (!Z3inv) {
freebn(tx);
return 0;
return false;
}
ty = modmul(a->y, Z3inv, a->curve->p);
freebn(Z3inv);
@ -653,7 +653,7 @@ static int ecp_normalise(struct ec_point *a)
a->y = ty;
freebn(a->z);
a->z = NULL;
return 1;
return true;
} else if (a->curve->type == EC_MONTGOMERY) {
/* In Montgomery (X : Z) represents the x co-ord (X / Z, ?) */
@ -661,15 +661,15 @@ static int ecp_normalise(struct ec_point *a)
if (!a->x) {
/* No point defined */
return 0;
return false;
} else if (!a->z) {
/* Already normalised */
return 1;
return true;
}
tmp = modinv(a->z, a->curve->p);
if (!tmp) {
return 0;
return false;
}
tmp2 = modmul(a->x, tmp, a->curve->p);
freebn(tmp);
@ -678,23 +678,23 @@ static int ecp_normalise(struct ec_point *a)
a->z = NULL;
freebn(a->x);
a->x = tmp2;
return 1;
return true;
} else if (a->curve->type == EC_EDWARDS) {
/* Always normalised */
return 1;
return true;
} else {
return 0;
return false;
}
}
static struct ec_point *ecp_doublew(const struct ec_point *a, const int aminus3)
static struct ec_point *ecp_doublew(const struct ec_point *a, bool aminus3)
{
Bignum S, M, outx, outy, outz;
if (bignum_cmp(a->y, Zero) == 0)
{
/* Identity */
return ec_point_new(a->curve, NULL, NULL, NULL, 1);
return ec_point_new(a->curve, NULL, NULL, NULL, true);
}
/* S = 4*X*Y^2 */
@ -802,7 +802,7 @@ static struct ec_point *ecp_doublew(const struct ec_point *a, const int aminus3)
freebn(YZ);
}
return ec_point_new(a->curve, outx, outy, outz, 0);
return ec_point_new(a->curve, outx, outy, outz, false);
}
static struct ec_point *ecp_doublem(const struct ec_point *a)
@ -865,20 +865,20 @@ static struct ec_point *ecp_doublem(const struct ec_point *a)
freebn(tmp);
}
return ec_point_new(a->curve, outx, NULL, outz, 0);
return ec_point_new(a->curve, outx, NULL, outz, false);
}
/* Forward declaration for Edwards curve doubling */
static struct ec_point *ecp_add(const struct ec_point *a,
const struct ec_point *b,
const int aminus3);
bool aminus3);
static struct ec_point *ecp_double(const struct ec_point *a, const int aminus3)
static struct ec_point *ecp_double(const struct ec_point *a, bool aminus3)
{
if (a->infinity)
{
/* Identity */
return ec_point_new(a->curve, NULL, NULL, NULL, 1);
return ec_point_new(a->curve, NULL, NULL, NULL, true);
}
if (a->curve->type == EC_EDWARDS)
@ -897,7 +897,7 @@ static struct ec_point *ecp_double(const struct ec_point *a, const int aminus3)
static struct ec_point *ecp_addw(const struct ec_point *a,
const struct ec_point *b,
const int aminus3)
bool aminus3)
{
Bignum U1, U2, S1, S2, outx, outy, outz;
@ -949,7 +949,7 @@ static struct ec_point *ecp_addw(const struct ec_point *a,
freebn(S1);
freebn(S2);
/* Infinity */
return ec_point_new(a->curve, NULL, NULL, NULL, 1);
return ec_point_new(a->curve, NULL, NULL, NULL, true);
}
}
@ -1019,7 +1019,7 @@ static struct ec_point *ecp_addw(const struct ec_point *a,
}
}
return ec_point_new(a->curve, outx, outy, outz, 0);
return ec_point_new(a->curve, outx, outy, outz, false);
}
static struct ec_point *ecp_addm(const struct ec_point *a,
@ -1070,7 +1070,7 @@ static struct ec_point *ecp_addm(const struct ec_point *a,
freebn(tmp2);
}
return ec_point_new(a->curve, outx, NULL, outz, 0);
return ec_point_new(a->curve, outx, NULL, outz, false);
}
static struct ec_point *ecp_adde(const struct ec_point *a,
@ -1135,12 +1135,12 @@ static struct ec_point *ecp_adde(const struct ec_point *a,
freebn(tmp2);
}
return ec_point_new(a->curve, outx, outy, NULL, 0);
return ec_point_new(a->curve, outx, outy, NULL, false);
}
static struct ec_point *ecp_add(const struct ec_point *a,
const struct ec_point *b,
const int aminus3)
bool aminus3)
{
if (a->curve != b->curve) {
return NULL;
@ -1163,13 +1163,14 @@ static struct ec_point *ecp_add(const struct ec_point *a,
return NULL;
}
static struct ec_point *ecp_mul_(const struct ec_point *a, const Bignum b, int aminus3)
static struct ec_point *ecp_mul_(
const struct ec_point *a, const Bignum b, bool aminus3)
{
struct ec_point *A, *ret;
int bits, i;
A = ec_point_copy(a);
ret = ec_point_new(a->curve, NULL, NULL, NULL, 1);
ret = ec_point_new(a->curve, NULL, NULL, NULL, true);
bits = bignum_bitcount(b);
for (i = 0; i < bits; ++i)
@ -1209,18 +1210,18 @@ static struct ec_point *ecp_mule(const struct ec_point *a, const Bignum b)
int i;
struct ec_point *ret;
ret = ec_point_new(a->curve, NULL, NULL, NULL, 1);
ret = ec_point_new(a->curve, NULL, NULL, NULL, true);
for (i = bignum_bitcount(b); i >= 0 && ret; --i)
{
{
struct ec_point *tmp = ecp_double(ret, 0);
struct ec_point *tmp = ecp_double(ret, false);
ec_point_free(ret);
ret = tmp;
}
if (ret && bignum_bit(b, i))
{
struct ec_point *tmp = ecp_add(ret, a, 0);
struct ec_point *tmp = ecp_add(ret, a, false);
ec_point_free(ret);
ret = tmp;
}
@ -1235,7 +1236,7 @@ static struct ec_point *ecp_mulm(const struct ec_point *p, const Bignum n)
int bits, i;
/* P1 <- P and P2 <- [2]P */
P2 = ecp_double(p, 0);
P2 = ecp_double(p, false);
P1 = ec_point_copy(p);
/* for i = bits 2 down to 0 */
@ -1250,7 +1251,7 @@ static struct ec_point *ecp_mulm(const struct ec_point *p, const Bignum n)
P2 = tmp;
/* P1 <- [2]P1 */
tmp = ecp_double(P1, 0);
tmp = ecp_double(P1, false);
ec_point_free(P1);
P1 = tmp;
}
@ -1262,7 +1263,7 @@ static struct ec_point *ecp_mulm(const struct ec_point *p, const Bignum n)
P1 = tmp;
/* P2 <- [2]P2 */
tmp = ecp_double(P2, 0);
tmp = ecp_double(P2, false);
ec_point_free(P2);
P2 = tmp;
}
@ -1294,7 +1295,7 @@ static struct ec_point *ecp_summul(const Bignum a, const Bignum b,
const struct ec_point *point)
{
struct ec_point *aG, *bP, *ret;
int aminus3;
bool aminus3;
if (point->curve->type != EC_WEIERSTRASS) {
return NULL;
@ -1446,23 +1447,23 @@ struct ec_point *ec_public(const Bignum privateKey, const struct ec_curve *curve
* Basic sign and verify routines
*/
static int _ecdsa_verify(const struct ec_point *publicKey,
const unsigned char *data, const int dataLen,
const Bignum r, const Bignum s)
static bool _ecdsa_verify(const struct ec_point *publicKey,
const unsigned char *data, const int dataLen,
const Bignum r, const Bignum s)
{
int z_bits, n_bits;
Bignum z;
int valid = 0;
bool valid = false;
if (publicKey->curve->type != EC_WEIERSTRASS) {
return 0;
return false;
}
/* Sanity checks */
if (bignum_cmp(r, Zero) == 0 || bignum_cmp(r, publicKey->curve->w.n) >= 0
|| bignum_cmp(s, Zero) == 0 || bignum_cmp(s, publicKey->curve->w.n) >= 0)
{
return 0;
return false;
}
/* z = left most bitlen(curve->n) of data */
@ -1491,7 +1492,7 @@ static int _ecdsa_verify(const struct ec_point *publicKey,
w = modinv(s, publicKey->curve->w.n);
if (!w) {
freebn(z);
return 0;
return false;
}
u1 = modmul(z, w, publicKey->curve->w.n);
u2 = modmul(r, w, publicKey->curve->w.n);
@ -1502,13 +1503,13 @@ static int _ecdsa_verify(const struct ec_point *publicKey,
freebn(u2);
if (!tmp) {
freebn(z);
return 0;
return false;
}
x = bigmod(tmp->x, publicKey->curve->w.n);
ec_point_free(tmp);
valid = (bignum_cmp(r, x) == 0) ? 1 : 0;
valid = (bignum_cmp(r, x) == 0);
freebn(x);
}
@ -1597,16 +1598,16 @@ static Bignum BinarySource_get_mp_le(BinarySource *src)
}
#define get_mp_le(src) BinarySource_get_mp_le(BinarySource_UPCAST(src))
static int decodepoint_ed(const char *p, int length, struct ec_point *point)
static bool decodepoint_ed(const char *p, int length, struct ec_point *point)
{
/* Got some conversion to do, first read in the y co-ord */
int negative;
bool negative;
point->y = bignum_from_bytes_le((const unsigned char*)p, length);
if ((unsigned)bignum_bitcount(point->y) > point->curve->fieldBits) {
freebn(point->y);
point->y = NULL;
return 0;
return false;
}
/* Read x bit and then reset it */
negative = bignum_bit(point->y, point->curve->fieldBits - 1);
@ -1618,7 +1619,7 @@ static int decodepoint_ed(const char *p, int length, struct ec_point *point)
if (!point->x) {
freebn(point->y);
point->y = NULL;
return 0;
return false;
}
if (negative) {
Bignum tmp = modsub(point->curve->p, point->x, point->curve->p);
@ -1632,20 +1633,20 @@ static int decodepoint_ed(const char *p, int length, struct ec_point *point)
point->x = NULL;
freebn(point->y);
point->y = NULL;
return 0;
return false;
}
return 1;
return true;
}
static int decodepoint(const char *p, int length, struct ec_point *point)
static bool decodepoint(const char *p, int length, struct ec_point *point)
{
if (point->curve->type == EC_EDWARDS) {
return decodepoint_ed(p, length, point);
}
if (length < 1 || p[0] != 0x04) /* Only support uncompressed point */
return 0;
return false;
/* Skip compression flag */
++p;
--length;
@ -1654,7 +1655,7 @@ static int decodepoint(const char *p, int length, struct ec_point *point)
point->x = NULL;
point->y = NULL;
point->z = NULL;
return 0;
return false;
}
length = length / 2;
point->x = bignum_from_bytes(p, length);
@ -1668,16 +1669,16 @@ static int decodepoint(const char *p, int length, struct ec_point *point)
point->x = NULL;
freebn(point->y);
point->y = NULL;
return 0;
return false;
}
return 1;
return true;
}
static int BinarySource_get_point(BinarySource *src, struct ec_point *point)
static bool BinarySource_get_point(BinarySource *src, struct ec_point *point)
{
ptrlen str = get_string(src);
if (get_err(src)) return 0;
if (get_err(src)) return false;
return decodepoint(str.ptr, str.len, point);
}
#define get_point(src, pt) BinarySource_get_point(BinarySource_UPCAST(src), pt)
@ -1737,7 +1738,7 @@ static ssh_key *ecdsa_new_pub(const ssh_keyalg *self, ptrlen data)
ec->sshk = self;
ec->publicKey.curve = curve;
ec->publicKey.infinity = 0;
ec->publicKey.infinity = false;
ec->publicKey.x = NULL;
ec->publicKey.y = NULL;
ec->publicKey.z = NULL;
@ -1925,7 +1926,7 @@ static ssh_key *ed25519_new_priv_openssh(const ssh_keyalg *self,
ec->sshk = self;
ec->publicKey.curve = ec_ed25519();
ec->publicKey.infinity = 0;
ec->publicKey.infinity = false;
ec->privateKey = NULL;
ec->publicKey.x = NULL;
ec->publicKey.z = NULL;
@ -2019,7 +2020,7 @@ static ssh_key *ecdsa_new_priv_openssh(const ssh_keyalg *self,
ec->sshk = self;
ec->publicKey.curve = curve;
ec->publicKey.infinity = 0;
ec->publicKey.infinity = false;
ec->publicKey.x = NULL;
ec->publicKey.y = NULL;
ec->publicKey.z = NULL;
@ -2106,27 +2107,27 @@ static int ecdsa_pubkey_bits(const ssh_keyalg *self, ptrlen blob)
return ret;
}
static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
static bool ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
{
struct ec_key *ec = container_of(key, struct ec_key, sshk);
const struct ecsign_extra *extra =
(const struct ecsign_extra *)ec->sshk->extra;
BinarySource src[1];
ptrlen sigstr;
int ret;
bool ret;
if (!ec->publicKey.x || !ec->publicKey.y || !ec->publicKey.curve)
return 0;
return false;
BinarySource_BARE_INIT(src, sig.ptr, sig.len);
/* Check the signature starts with the algorithm name */
if (!ptrlen_eq_string(get_string(src), ec->sshk->ssh_id))
return 0;
return false;
sigstr = get_string(src);
if (get_err(src))
return 0;
return false;
if (ec->publicKey.curve->type == EC_EDWARDS) {
struct ec_point *r;
@ -2135,22 +2136,22 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
/* Check that the signature is two times the length of a point */
if (sigstr.len != pointlen * 2) {
return 0;
return false;
}
/* Check it's the 256 bit field so that SHA512 is the correct hash */
if (ec->publicKey.curve->fieldBits != 256) {
return 0;
return false;
}
/* Get the signature */
r = ec_point_new(ec->publicKey.curve, NULL, NULL, NULL, 0);
r = ec_point_new(ec->publicKey.curve, NULL, NULL, NULL, false);
if (!r) {
return 0;
return false;
}
if (!decodepoint(sigstr.ptr, pointlen, r)) {
ec_point_free(r);
return 0;
return false;
}
s = bignum_from_bytes_le(
(const char *)sigstr.ptr + pointlen, pointlen);
@ -2193,7 +2194,7 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
if (!lhs) {
ec_point_free(r);
freebn(h);
return 0;
return false;
}
/* rhs = r + h*publicKey */
@ -2202,14 +2203,14 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
if (!tmp) {
ec_point_free(lhs);
ec_point_free(r);
return 0;
return false;
}
rhs = ecp_add(r, tmp, 0);
rhs = ecp_add(r, tmp, false);
ec_point_free(r);
ec_point_free(tmp);
if (!rhs) {
ec_point_free(lhs);
return 0;
return false;
}
/* Check the point is the same */
@ -2217,7 +2218,7 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
if (ret) {
ret = !bignum_cmp(lhs->y, rhs->y);
if (ret) {
ret = 1;
ret = true;
}
}
ec_point_free(lhs);
@ -2236,7 +2237,7 @@ static int ecdsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
if (get_err(src)) {
freebn(r);
freebn(s);
return 0;
return false;
}
digestLen = extra->hash->hlen;
@ -2643,7 +2644,7 @@ Bignum ssh_ecdhkex_getkey(struct ec_key *ec,
if (ec->publicKey.curve->type == EC_WEIERSTRASS) {
remote.curve = ec->publicKey.curve;
remote.infinity = 0;
remote.infinity = false;
if (!decodepoint(remoteKey, remoteKeyLen, &remote)) {
return NULL;
}
@ -2654,7 +2655,7 @@ Bignum ssh_ecdhkex_getkey(struct ec_key *ec,
}
remote.curve = ec->publicKey.curve;
remote.infinity = 0;
remote.infinity = false;
remote.x = bignum_from_bytes_le((const unsigned char *)remoteKey,
remoteKeyLen);
remote.y = NULL;
@ -2746,9 +2747,8 @@ const unsigned char *ec_alg_oid(const ssh_keyalg *alg,
const int ec_nist_curve_lengths[] = { 256, 384, 521 };
const int n_ec_nist_curve_lengths = lenof(ec_nist_curve_lengths);
int ec_nist_alg_and_curve_by_bits(int bits,
const struct ec_curve **curve,
const ssh_keyalg **alg)
bool ec_nist_alg_and_curve_by_bits(
int bits, const struct ec_curve **curve, const ssh_keyalg **alg)
{
switch (bits) {
case 256: *alg = &ssh_ecdsa_nistp256; break;
@ -2760,9 +2760,8 @@ int ec_nist_alg_and_curve_by_bits(int bits,
return true;
}
int ec_ed_alg_and_curve_by_bits(int bits,
const struct ec_curve **curve,
const ssh_keyalg **alg)
bool ec_ed_alg_and_curve_by_bits(
int bits, const struct ec_curve **curve, const ssh_keyalg **alg)
{
switch (bits) {
case 256: *alg = &ssh_ecdsa_ed25519; break;

View File

@ -7,10 +7,10 @@
#include "ssh.h"
int ssh2_mac_verresult(ssh2_mac *mac, const void *candidate)
bool ssh2_mac_verresult(ssh2_mac *mac, const void *candidate)
{
unsigned char correct[64]; /* at least as big as all known MACs */
int toret;
bool toret;
assert(mac->vt->len <= sizeof(correct));
ssh2_mac_genresult(mac, correct);
@ -35,7 +35,8 @@ void ssh2_mac_generate(ssh2_mac *mac, void *blk, int len, unsigned long seq)
return ssh2_mac_genresult(mac, (unsigned char *)blk + len);
}
int ssh2_mac_verify(ssh2_mac *mac, const void *blk, int len, unsigned long seq)
bool ssh2_mac_verify(
ssh2_mac *mac, const void *blk, int len, unsigned long seq)
{
ssh2_mac_prepare(mac, blk, len, seq);
return ssh2_mac_verresult(mac, (const unsigned char *)blk + len);

View File

@ -12,11 +12,11 @@ typedef void (*packet_handler_fn_t)(PacketProtocolLayer *ppl, PktIn *pktin);
struct PacketProtocolLayerVtable {
void (*free)(PacketProtocolLayer *);
void (*process_queue)(PacketProtocolLayer *ppl);
int (*get_specials)(
bool (*get_specials)(
PacketProtocolLayer *ppl, add_special_fn_t add_special, void *ctx);
void (*special_cmd)(
PacketProtocolLayer *ppl, SessionSpecialCode code, int arg);
int (*want_user_input)(PacketProtocolLayer *ppl);
bool (*want_user_input)(PacketProtocolLayer *ppl);
void (*got_user_input)(PacketProtocolLayer *ppl);
void (*reconfigure)(PacketProtocolLayer *ppl, Conf *conf);
@ -97,17 +97,17 @@ PacketProtocolLayer *ssh2_transport_new(
const char *client_greeting, const char *server_greeting,
struct ssh_connection_shared_gss_state *shgss,
struct DataTransferStats *stats, PacketProtocolLayer *higher_layer,
int is_server);
bool is_server);
PacketProtocolLayer *ssh2_userauth_new(
PacketProtocolLayer *successor_layer,
const char *hostname, const char *fullhostname,
Filename *keyfile, int tryagent,
const char *default_username, int change_username,
int try_ki_auth,
int try_gssapi_auth, int try_gssapi_kex_auth,
int gssapi_fwd, struct ssh_connection_shared_gss_state *shgss);
Filename *keyfile, bool tryagent,
const char *default_username, bool change_username,
bool try_ki_auth,
bool try_gssapi_auth, bool try_gssapi_kex_auth,
bool gssapi_fwd, struct ssh_connection_shared_gss_state *shgss);
PacketProtocolLayer *ssh2_connection_new(
Ssh *ssh, ssh_sharing_state *connshare, int is_simple,
Ssh *ssh, ssh_sharing_state *connshare, bool is_simple,
Conf *conf, const char *peer_verstring, ConnectionLayer **cl_out);
/* Can't put this in the userauth constructor without having a
@ -139,10 +139,10 @@ void ssh1_connection_set_protoflags(
PacketProtocolLayer *ppl, int local, int remote);
/* Shared get_specials method between the two ssh1 layers */
int ssh1_common_get_specials(PacketProtocolLayer *, add_special_fn_t, void *);
bool ssh1_common_get_specials(PacketProtocolLayer *, add_special_fn_t, void *);
/* Other shared functions between ssh1 layers */
int ssh1_common_filter_queue(PacketProtocolLayer *ppl);
bool ssh1_common_filter_queue(PacketProtocolLayer *ppl);
void ssh1_compute_session_id(
unsigned char *session_id, const unsigned char *cookie,
struct RSAKey *hostkey, struct RSAKey *servkey);

107
sshpubk.c
View File

@ -23,7 +23,7 @@
static int key_type_fp(FILE *fp);
static int rsa_ssh1_load_main(FILE * fp, struct RSAKey *key, int pub_only,
static int rsa_ssh1_load_main(FILE * fp, struct RSAKey *key, bool pub_only,
char **commentptr, const char *passphrase,
const char **error)
{
@ -184,14 +184,14 @@ int rsa_ssh1_loadkey(const Filename *filename, struct RSAKey *key,
* See whether an RSA key is encrypted. Return its comment field as
* well.
*/
int rsa_ssh1_encrypted(const Filename *filename, char **comment)
bool rsa_ssh1_encrypted(const Filename *filename, char **comment)
{
FILE *fp;
char buf[64];
fp = f_open(filename, "rb", false);
if (!fp)
return 0; /* doesn't even exist */
return false; /* doesn't even exist */
/*
* Read the first line of the file and see if it's a v1 private
@ -202,10 +202,10 @@ int rsa_ssh1_encrypted(const Filename *filename, char **comment)
/*
* This routine will take care of calling fclose() for us.
*/
return rsa_ssh1_load_main(fp, NULL, false, comment, NULL, &dummy);
return rsa_ssh1_load_main(fp, NULL, false, comment, NULL, &dummy) == 1;
}
fclose(fp);
return 0; /* wasn't the right kind of file */
return false; /* wasn't the right kind of file */
}
/*
@ -222,7 +222,7 @@ int rsa_ssh1_loadpub(const Filename *filename, BinarySink *bs,
const char *error = NULL;
/* Default return if we fail. */
ret = false;
ret = 0;
fp = f_open(filename, "rb", false);
if (!fp) {
@ -239,7 +239,7 @@ int rsa_ssh1_loadpub(const Filename *filename, BinarySink *bs,
if (rsa_ssh1_load_main(fp, &key, true, commentptr, NULL, &error)) {
rsa_ssh1_public_blob(bs, &key, RSA_SSH1_EXPONENT_FIRST);
freersakey(&key);
ret = true;
ret = 1;
}
fp = NULL; /* rsa_ssh1_load_main unconditionally closes fp */
} else {
@ -291,7 +291,7 @@ int rsa_ssh1_loadpub(const Filename *filename, BinarySink *bs,
freersakey(&key);
sfree(line);
fclose(fp);
return true;
return 1;
not_public_either:
sfree(line);
@ -307,10 +307,10 @@ int rsa_ssh1_loadpub(const Filename *filename, BinarySink *bs,
}
/*
* Save an RSA key file. Return nonzero on success.
* Save an RSA key file. Return true on success.
*/
int rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key,
char *passphrase)
bool rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key,
char *passphrase)
{
strbuf *buf = strbuf_new();
int estart;
@ -377,12 +377,12 @@ int rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key,
*/
fp = f_open(filename, "wb", true);
if (fp) {
int ret = (fwrite(buf->u, 1, buf->len, fp) == (size_t) (buf->len));
bool ret = (fwrite(buf->u, 1, buf->len, fp) == (size_t) (buf->len));
if (fclose(fp))
ret = 0;
ret = false;
return ret;
} else
return 0;
return false;
}
/* ----------------------------------------------------------------------
@ -468,7 +468,7 @@ int rsa_ssh1_savekey(const Filename *filename, struct RSAKey *key,
* an HMAC (this was generated for unencrypted keys).
*/
static int read_header(FILE * fp, char *header)
static bool read_header(FILE * fp, char *header)
{
int len = 39;
int c;
@ -476,20 +476,20 @@ static int read_header(FILE * fp, char *header)
while (1) {
c = fgetc(fp);
if (c == '\n' || c == '\r' || c == EOF)
return 0; /* failure */
return false; /* failure */
if (c == ':') {
c = fgetc(fp);
if (c != ' ')
return 0;
return false;
*header = '\0';
return 1; /* success! */
return true; /* success! */
}
if (len == 0)
return 0; /* failure */
return false; /* failure */
*header++ = c;
len--;
}
return 0; /* failure */
return false; /* failure */
}
static char *read_body(FILE * fp)
@ -523,7 +523,7 @@ static char *read_body(FILE * fp)
}
}
static int read_blob(FILE *fp, int nlines, BinarySink *bs)
static bool read_blob(FILE *fp, int nlines, BinarySink *bs)
{
unsigned char *blob;
char *line;
@ -597,7 +597,8 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
struct ssh2_userkey *ret;
int cipher, cipherblk;
strbuf *public_blob, *private_blob;
int i, is_mac, old_fmt;
int i;
bool is_mac, old_fmt;
int passlen = passphrase ? strlen(passphrase) : 0;
const char *error = NULL;
@ -617,11 +618,11 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
goto error;
}
if (0 == strcmp(header, "PuTTY-User-Key-File-2")) {
old_fmt = 0;
old_fmt = false;
} else if (0 == strcmp(header, "PuTTY-User-Key-File-1")) {
/* this is an old key file; warn and then continue */
old_keyfile_warning();
old_fmt = 1;
old_fmt = true;
} else if (0 == strncmp(header, "PuTTY-User-Key-File-", 20)) {
/* this is a key file FROM THE FUTURE; refuse it, but with a
* more specific error message than the generic one below */
@ -691,11 +692,11 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
if (0 == strcmp(header, "Private-MAC")) {
if ((mac = read_body(fp)) == NULL)
goto error;
is_mac = 1;
is_mac = true;
} else if (0 == strcmp(header, "Private-Hash") && old_fmt) {
if ((mac = read_body(fp)) == NULL)
goto error;
is_mac = 0;
is_mac = false;
} else
goto error;
@ -732,7 +733,7 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
char realmac[41];
unsigned char binary[20];
strbuf *macdata;
int free_macdata;
bool free_macdata;
if (old_fmt) {
/* MAC (or hash) only covers the private blob. */
@ -834,9 +835,9 @@ struct ssh2_userkey *ssh2_load_userkey(const Filename *filename,
return ret;
}
int rfc4716_loadpub(FILE *fp, char **algorithm,
BinarySink *bs,
char **commentptr, const char **errorstr)
bool rfc4716_loadpub(FILE *fp, char **algorithm,
BinarySink *bs,
char **commentptr, const char **errorstr)
{
const char *error;
char *line, *colon, *value;
@ -968,9 +969,9 @@ int rfc4716_loadpub(FILE *fp, char **algorithm,
return false;
}
int openssh_loadpub(FILE *fp, char **algorithm,
BinarySink *bs,
char **commentptr, const char **errorstr)
bool openssh_loadpub(FILE *fp, char **algorithm,
BinarySink *bs,
char **commentptr, const char **errorstr)
{
const char *error;
char *line, *base64;
@ -1044,9 +1045,9 @@ int openssh_loadpub(FILE *fp, char **algorithm,
return false;
}
int ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
BinarySink *bs,
char **commentptr, const char **errorstr)
bool ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
BinarySink *bs,
char **commentptr, const char **errorstr)
{
FILE *fp;
char header[40], *b;
@ -1065,11 +1066,11 @@ int ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
* we'll be asked to read a public blob from one of those. */
type = key_type_fp(fp);
if (type == SSH_KEYTYPE_SSH2_PUBLIC_RFC4716) {
int ret = rfc4716_loadpub(fp, algorithm, bs, commentptr, errorstr);
bool ret = rfc4716_loadpub(fp, algorithm, bs, commentptr, errorstr);
fclose(fp);
return ret;
} else if (type == SSH_KEYTYPE_SSH2_PUBLIC_OPENSSH) {
int ret = openssh_loadpub(fp, algorithm, bs, commentptr, errorstr);
bool ret = openssh_loadpub(fp, algorithm, bs, commentptr, errorstr);
fclose(fp);
return ret;
} else if (type != SSH_KEYTYPE_SSH2) {
@ -1145,49 +1146,49 @@ int ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
return false;
}
int ssh2_userkey_encrypted(const Filename *filename, char **commentptr)
bool ssh2_userkey_encrypted(const Filename *filename, char **commentptr)
{
FILE *fp;
char header[40], *b, *comment;
int ret;
bool ret;
if (commentptr)
*commentptr = NULL;
fp = f_open(filename, "rb", false);
if (!fp)
return 0;
return false;
if (!read_header(fp, header)
|| (0 != strcmp(header, "PuTTY-User-Key-File-2") &&
0 != strcmp(header, "PuTTY-User-Key-File-1"))) {
fclose(fp);
return 0;
return false;
}
if ((b = read_body(fp)) == NULL) {
fclose(fp);
return 0;
return false;
}
sfree(b); /* we don't care about key type here */
/* Read the Encryption header line. */
if (!read_header(fp, header) || 0 != strcmp(header, "Encryption")) {
fclose(fp);
return 0;
return false;
}
if ((b = read_body(fp)) == NULL) {
fclose(fp);
return 0;
return false;
}
/* Read the Comment header line. */
if (!read_header(fp, header) || 0 != strcmp(header, "Comment")) {
fclose(fp);
sfree(b);
return 1;
return true;
}
if ((comment = read_body(fp)) == NULL) {
fclose(fp);
sfree(b);
return 1;
return true;
}
if (commentptr)
@ -1197,9 +1198,9 @@ int ssh2_userkey_encrypted(const Filename *filename, char **commentptr)
fclose(fp);
if (!strcmp(b, "aes256-cbc"))
ret = 1;
ret = true;
else
ret = 0;
ret = false;
sfree(b);
return ret;
}
@ -1233,8 +1234,8 @@ void base64_encode(FILE *fp, const unsigned char *data, int datalen, int cpl)
fputc('\n', fp);
}
int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
char *passphrase)
bool ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
char *passphrase)
{
FILE *fp;
strbuf *pub_blob, *priv_blob;
@ -1329,7 +1330,7 @@ int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
strbuf_free(priv_blob);
smemclr(priv_blob_encrypted, priv_encrypted_len);
sfree(priv_blob_encrypted);
return 0;
return false;
}
fprintf(fp, "PuTTY-User-Key-File-2: %s\n", ssh_key_ssh_id(key->key));
fprintf(fp, "Encryption: %s\n", cipherstr);
@ -1348,7 +1349,7 @@ int ssh2_save_userkey(const Filename *filename, struct ssh2_userkey *key,
strbuf_free(priv_blob);
smemclr(priv_blob_encrypted, priv_encrypted_len);
sfree(priv_blob_encrypted);
return 1;
return true;
}
/* ----------------------------------------------------------------------

View File

@ -42,7 +42,7 @@ struct RandPool {
unsigned char incomingb[HASHINPUT];
int incomingpos;
int stir_pending;
bool stir_pending;
};
int random_active = 0;

View File

@ -42,14 +42,14 @@ void BinarySource_get_rsa_ssh1_priv(
rsa->private_exponent = get_mp_ssh1(src);
}
int rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key)
bool rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key)
{
Bignum b1, b2;
int i;
unsigned char *p;
if (key->bytes < length + 4)
return 0; /* RSA key too short! */
return false; /* RSA key too short! */
memmove(data + key->bytes - length, data, length);
data[0] = 0;
@ -74,7 +74,7 @@ int rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key)
freebn(b1);
freebn(b2);
return 1;
return true;
}
/*
@ -285,10 +285,10 @@ Bignum rsa_ssh1_decrypt(Bignum input, struct RSAKey *key)
return rsa_privkey_op(input, key);
}
int rsa_ssh1_decrypt_pkcs1(Bignum input, struct RSAKey *key, strbuf *outbuf)
bool rsa_ssh1_decrypt_pkcs1(Bignum input, struct RSAKey *key, strbuf *outbuf)
{
strbuf *data = strbuf_new();
int success = false;
bool success = false;
BinarySource src[1];
{
@ -391,7 +391,7 @@ char *rsa_ssh1_fingerprint(struct RSAKey *key)
* data. We also check the private data itself: we ensure that p >
* q and that iqmp really is the inverse of q mod p.
*/
int rsa_verify(struct RSAKey *key)
bool rsa_verify(struct RSAKey *key)
{
Bignum n, ed, pm1, qm1;
int cmp;
@ -401,7 +401,7 @@ int rsa_verify(struct RSAKey *key)
cmp = bignum_cmp(n, key->modulus);
freebn(n);
if (cmp != 0)
return 0;
return false;
/* e * d must be congruent to 1, modulo (p-1) and modulo (q-1). */
pm1 = copybn(key->p);
@ -411,7 +411,7 @@ int rsa_verify(struct RSAKey *key)
cmp = bignum_cmp(ed, One);
freebn(ed);
if (cmp != 0)
return 0;
return false;
qm1 = copybn(key->q);
decbn(qm1);
@ -420,7 +420,7 @@ int rsa_verify(struct RSAKey *key)
cmp = bignum_cmp(ed, One);
freebn(ed);
if (cmp != 0)
return 0;
return false;
/*
* Ensure p > q.
@ -438,7 +438,7 @@ int rsa_verify(struct RSAKey *key)
freebn(key->iqmp);
key->iqmp = modinv(key->q, key->p);
if (!key->iqmp)
return 0;
return false;
}
/*
@ -448,9 +448,9 @@ int rsa_verify(struct RSAKey *key)
cmp = bignum_cmp(n, One);
freebn(n);
if (cmp != 0)
return 0;
return false;
return 1;
return true;
}
void rsa_ssh1_public_blob(BinarySink *bs, struct RSAKey *key,
@ -683,13 +683,14 @@ static const unsigned char asn1_weird_stuff[] = {
#define ASN1_LEN ( (int) sizeof(asn1_weird_stuff) )
static int rsa2_verify(ssh_key *key, ptrlen sig, ptrlen data)
static bool rsa2_verify(ssh_key *key, ptrlen sig, ptrlen data)
{
struct RSAKey *rsa = container_of(key, struct RSAKey, sshk);
BinarySource src[1];
ptrlen type, in_pl;
Bignum in, out;
int bytes, i, j, ret;
int bytes, i, j;
bool toret;
unsigned char hash[20];
BinarySource_BARE_INIT(src, sig.ptr, sig.len);
@ -706,40 +707,40 @@ static int rsa2_verify(ssh_key *key, ptrlen sig, ptrlen data)
*/
in_pl = get_string(src);
if (get_err(src) || !ptrlen_eq_string(type, "ssh-rsa"))
return 0;
return false;
in = bignum_from_bytes(in_pl.ptr, in_pl.len);
out = modpow(in, rsa->exponent, rsa->modulus);
freebn(in);
ret = 1;
toret = true;
bytes = (bignum_bitcount(rsa->modulus)+7) / 8;
/* Top (partial) byte should be zero. */
if (bignum_byte(out, bytes - 1) != 0)
ret = 0;
toret = false;
/* First whole byte should be 1. */
if (bignum_byte(out, bytes - 2) != 1)
ret = 0;
toret = false;
/* Most of the rest should be FF. */
for (i = bytes - 3; i >= 20 + ASN1_LEN; i--) {
if (bignum_byte(out, i) != 0xFF)
ret = 0;
toret = false;
}
/* Then we expect to see the asn1_weird_stuff. */
for (i = 20 + ASN1_LEN - 1, j = 0; i >= 20; i--, j++) {
if (bignum_byte(out, i) != asn1_weird_stuff[j])
ret = 0;
toret = false;
}
/* Finally, we expect to see the SHA-1 hash of the signed data. */
SHA_Simple(data.ptr, data.len, hash);
for (i = 19, j = 0; i >= 0; i--, j++) {
if (bignum_byte(out, i) != hash[j])
ret = 0;
toret = false;
}
freebn(out);
return ret;
return toret;
}
static void rsa2_sign(ssh_key *key, const void *data, int datalen,

View File

@ -33,7 +33,7 @@ struct server {
Socket *socket;
Plug plug;
int conn_throttle_count;
int frozen;
bool frozen;
Conf *conf;
ssh_key *const *hostkeys;
@ -74,7 +74,7 @@ void share_setup_x11_channel(ssh_sharing_connstate *cs, share_channel *chan,
int protomajor, int protominor,
const void *initial_data, int initial_len) {}
Channel *agentf_new(SshChannel *c) { return NULL; }
int agent_exists(void) { return false; }
bool agent_exists(void) { return false; }
void ssh_got_exitcode(Ssh *ssh, int exitcode) {}
mainchan *mainchan_new(
@ -122,7 +122,7 @@ static void server_socket_log(Plug *plug, int type, SockAddr *addr, int port,
}
static void server_closing(Plug *plug, const char *error_msg, int error_code,
int calling_back)
bool calling_back)
{
server *srv = container_of(plug, server, plug);
if (error_msg) {
@ -175,7 +175,7 @@ void ssh_throttle_conn(Ssh *ssh, int adjust)
{
server *srv = container_of(ssh, server, ssh);
int old_count = srv->conn_throttle_count;
int frozen;
bool frozen;
srv->conn_throttle_count += adjust;
assert(srv->conn_throttle_count >= 0);

View File

@ -33,18 +33,18 @@ struct AuthKbdInt {
};
struct AuthKbdIntPrompt {
char *prompt; /* needs freeing */
int echo;
bool echo;
};
unsigned auth_methods(AuthPolicy *);
int auth_none(AuthPolicy *, ptrlen username);
bool auth_none(AuthPolicy *, ptrlen username);
int auth_password(AuthPolicy *, ptrlen username, ptrlen password,
ptrlen *opt_new_password);
/* auth_password returns 1 for 'accepted', 0 for 'rejected', and 2 for
* 'ok but now you need to change your password' */
int auth_publickey(AuthPolicy *, ptrlen username, ptrlen public_blob);
bool auth_publickey(AuthPolicy *, ptrlen username, ptrlen public_blob);
/* auth_publickey_ssh1 must return the whole public key given the modulus,
* because the SSH-1 client never transmits the exponent over the wire.
* The key remains owned by the AuthPolicy. */
@ -59,12 +59,12 @@ int auth_kbdint_responses(AuthPolicy *, const ptrlen *responses);
/* The very similar SSH-1 TIS and CryptoCard methods are combined into
* a single API for AuthPolicy, which takes a method argument */
char *auth_ssh1int_challenge(AuthPolicy *, unsigned method, ptrlen username);
int auth_ssh1int_response(AuthPolicy *, ptrlen response);
bool auth_ssh1int_response(AuthPolicy *, ptrlen response);
struct RSAKey *auth_publickey_ssh1(
AuthPolicy *ap, ptrlen username, Bignum rsa_modulus);
/* auth_successful returns false if further authentication is needed */
int auth_successful(AuthPolicy *, ptrlen username, unsigned method);
bool auth_successful(AuthPolicy *, ptrlen username, unsigned method);
PacketProtocolLayer *ssh2_userauth_server_new(
PacketProtocolLayer *successor_layer, AuthPolicy *authpolicy);
@ -83,7 +83,7 @@ Channel *sesschan_new(SshChannel *c, LogContext *logctx,
Backend *pty_backend_create(
Seat *seat, LogContext *logctx, Conf *conf, char **argv, const char *cmd,
struct ssh_ttymodes ttymodes, int pipes_instead_of_pty);
struct ssh_ttymodes ttymodes, bool pipes_instead_of_pty);
ptrlen pty_backend_exit_signame(Backend *be, char **aux_msg);
/*

View File

@ -436,12 +436,12 @@ const struct ssh2_macalg ssh_hmac_sha1_96_buggy = {
#if defined(__clang__) || defined(__GNUC__)
#include <cpuid.h>
int supports_sha_ni(void)
bool supports_sha_ni(void)
{
unsigned int CPUInfo[4];
__cpuid(0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
if (CPUInfo[0] < 7)
return 0;
return false;
__cpuid_count(7, 0, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
return CPUInfo[1] & (1 << 29); /* SHA */
@ -449,12 +449,12 @@ int supports_sha_ni(void)
#else /* defined(__clang__) || defined(__GNUC__) */
int supports_sha_ni(void)
bool supports_sha_ni(void)
{
unsigned int CPUInfo[4];
__cpuid(CPUInfo, 0);
if (CPUInfo[0] < 7)
return 0;
return false;
__cpuidex(CPUInfo, 7, 0);
return CPUInfo[1] & (1 << 29); /* Check SHA */
@ -686,9 +686,9 @@ static void sha1_ni(SHA_State * s, const unsigned char *q, int len)
assert(0);
}
int supports_sha_ni(void)
bool supports_sha_ni(void)
{
return 0;
return false;
}
#endif /* COMPILER_SUPPORTS_AES_NI */

View File

@ -160,7 +160,8 @@ struct ssh_sharing_connstate {
int crLine; /* coroutine state for share_receive */
int sent_verstring, got_verstring, curr_packetlen;
bool sent_verstring, got_verstring;
int curr_packetlen;
unsigned char recvbuf[0x4010];
int recvlen;
@ -235,13 +236,13 @@ struct share_channel {
int x11_auth_proto;
char *x11_auth_data;
int x11_auth_datalen;
int x11_one_shot;
bool x11_one_shot;
};
struct share_forwarding {
char *host;
int port;
int active; /* has the server sent REQUEST_SUCCESS? */
bool active; /* has the server sent REQUEST_SUCCESS? */
struct ssh_rportfwd *rpf;
};
@ -263,7 +264,7 @@ struct share_xchannel {
* channel messages from the server until such time as the server
* sends us CHANNEL_CLOSE.
*/
int live;
bool live;
/*
* When we receive OPEN_CONFIRMATION, we will need to send a
@ -291,7 +292,7 @@ enum {
struct share_globreq {
struct share_globreq *next;
int type;
int want_reply;
bool want_reply;
struct share_forwarding *fwd;
};
@ -571,7 +572,7 @@ static struct share_channel *share_add_channel
chan->x11_auth_data = NULL;
chan->x11_auth_proto = -1;
chan->x11_auth_datalen = 0;
chan->x11_one_shot = 0;
chan->x11_one_shot = false;
if (add234(cs->channels_by_us, chan) != chan) {
sfree(chan);
return NULL;
@ -936,7 +937,7 @@ static void share_disconnect(struct ssh_sharing_connstate *cs,
}
static void share_closing(Plug *plug, const char *error_msg, int error_code,
int calling_back)
bool calling_back)
{
struct ssh_sharing_connstate *cs = container_of(
plug, struct ssh_sharing_connstate, plug);
@ -997,7 +998,7 @@ void share_dead_xchannel_respond(struct ssh_sharing_connstate *cs,
* Handle queued incoming messages from the server destined for an
* xchannel which is dead (i.e. downstream sent OPEN_FAILURE).
*/
int delete = false;
bool delete = false;
while (xc->msghead) {
struct share_xchannel_message *msg = xc->msghead;
xc->msghead = msg->next;
@ -1157,7 +1158,7 @@ void share_setup_x11_channel(ssh_sharing_connstate *cs, share_channel *chan,
sfree(chan->x11_auth_data);
chan->x11_auth_proto = -1;
chan->x11_auth_datalen = 0;
chan->x11_one_shot = 0;
chan->x11_one_shot = false;
}
}
@ -1312,7 +1313,7 @@ static void share_got_pkt_from_downstream(struct ssh_sharing_connstate *cs,
char *err = NULL;
BinarySource src[1];
size_t wantreplypos;
int orig_wantreply;
bool orig_wantreply;
BinarySource_BARE_INIT(src, pkt, pktlen);
@ -1635,7 +1636,8 @@ static void share_got_pkt_from_downstream(struct ssh_sharing_connstate *cs,
* a downstream, and if the latter, which one.
*/
if (ptrlen_eq_string(request_name, "x11-req")) {
int want_reply, single_connection, screen;
bool want_reply, single_connection;
int screen;
ptrlen auth_data;
int auth_proto;
@ -1844,7 +1846,7 @@ static void share_sent(Plug *plug, int bufsize)
}
static void share_listen_closing(Plug *plug, const char *error_msg,
int error_code, int calling_back)
int error_code, bool calling_back)
{
ssh_sharing_state *sharestate =
container_of(plug, ssh_sharing_state, plug);
@ -1968,8 +1970,8 @@ static int share_listen_accepting(Plug *plug,
/* Per-application overrides for what roles we can take (e.g. pscp
* will never be an upstream) */
extern const int share_can_be_downstream;
extern const int share_can_be_upstream;
extern const bool share_can_be_downstream;
extern const bool share_can_be_upstream;
/*
* Decide on the string used to identify the connection point between
@ -2015,7 +2017,7 @@ char *ssh_share_sockname(const char *host, int port, Conf *conf)
return sockname;
}
int ssh_share_test_for_upstream(const char *host, int port, Conf *conf)
bool ssh_share_test_for_upstream(const char *host, int port, Conf *conf)
{
char *sockname, *logtext, *ds_err, *us_err;
int result;
@ -2071,7 +2073,8 @@ Socket *ssh_connection_sharing_init(
const char *host, int port, Conf *conf, LogContext *logctx,
Plug *sshplug, ssh_sharing_state **state)
{
int result, can_upstream, can_downstream;
int result;
bool can_upstream, can_downstream;
char *logtext, *ds_err, *us_err;
char *sockname;
Socket *sock, *toret = NULL;

View File

@ -21,9 +21,9 @@ struct ssh_verstring_state {
char *our_protoversion;
struct ssh_version_receiver *receiver;
int send_early;
bool send_early;
int found_prefix;
bool found_prefix;
int major_protoversion;
int remote_bugs;
char prefix[PREFIX_MAXLEN];
@ -55,13 +55,13 @@ static const struct BinaryPacketProtocolVtable ssh_verstring_vtable = {
};
static void ssh_detect_bugs(struct ssh_verstring_state *s);
static int ssh_version_includes_v1(const char *ver);
static int ssh_version_includes_v2(const char *ver);
static bool ssh_version_includes_v1(const char *ver);
static bool ssh_version_includes_v2(const char *ver);
BinaryPacketProtocol *ssh_verstring_new(
Conf *conf, LogContext *logctx, int bare_connection_mode,
Conf *conf, LogContext *logctx, bool bare_connection_mode,
const char *protoversion, struct ssh_version_receiver *rcv,
int server_mode, const char *impl_name)
bool server_mode, const char *impl_name)
{
struct ssh_verstring_state *s = snew(struct ssh_verstring_state);
@ -141,12 +141,12 @@ static int ssh_versioncmp(const char *a, const char *b)
return 0;
}
static int ssh_version_includes_v1(const char *ver)
static bool ssh_version_includes_v1(const char *ver)
{
return ssh_versioncmp(ver, "2.0") < 0;
}
static int ssh_version_includes_v2(const char *ver)
static bool ssh_version_includes_v2(const char *ver)
{
return ssh_versioncmp(ver, "1.99") >= 0;
}

View File

@ -94,7 +94,7 @@ static int lz77_init(struct LZ77Context *ctx);
* instead call literal() for everything.
*/
static void lz77_compress(struct LZ77Context *ctx,
unsigned char *data, int len, int compress);
unsigned char *data, int len, bool compress);
/*
* Modifiable parameters.
@ -199,7 +199,7 @@ static void lz77_advance(struct LZ77InternalContext *st,
#define CHARAT(k) ( (k)<0 ? st->data[(st->winpos+k)&(WINSIZE-1)] : data[k] )
static void lz77_compress(struct LZ77Context *ctx,
unsigned char *data, int len, int compress)
unsigned char *data, int len, bool compress)
{
struct LZ77InternalContext *st = ctx->ictx;
int i, distance, off, nmatch, matchlen, advance;
@ -370,7 +370,7 @@ struct Outbuf {
int outlen, outsize;
unsigned long outbits;
int noutbits;
int firstblock;
bool firstblock;
};
static void outbits(struct Outbuf *out, unsigned long bits, int nbits)
@ -614,7 +614,7 @@ ssh_compressor *zlib_compress_init(void)
out = snew(struct Outbuf);
out->outbits = out->noutbits = 0;
out->firstblock = 1;
out->firstblock = true;
comp->ectx.userdata = out;
return &comp->sc;
@ -636,7 +636,7 @@ void zlib_compress_block(ssh_compressor *sc, unsigned char *block, int len,
struct ssh_zlib_compressor *comp =
container_of(sc, struct ssh_zlib_compressor, sc);
struct Outbuf *out = (struct Outbuf *) comp->ectx.userdata;
int in_block;
bool in_block;
out->outbuf = NULL;
out->outlen = out->outsize = 0;
@ -648,7 +648,7 @@ void zlib_compress_block(ssh_compressor *sc, unsigned char *block, int len,
*/
if (out->firstblock) {
outbits(out, 0x9C78, 16);
out->firstblock = 0;
out->firstblock = false;
in_block = false;
} else
@ -967,8 +967,8 @@ static void zlib_emit_char(struct zlib_decompress_ctx *dctx, int c)
#define EATBITS(n) ( dctx->nbits -= (n), dctx->bits >>= (n) )
int zlib_decompress_block(ssh_decompressor *dc, unsigned char *block, int len,
unsigned char **outblock, int *outlen)
bool zlib_decompress_block(ssh_decompressor *dc, unsigned char *block, int len,
unsigned char **outblock, int *outlen)
{
struct zlib_decompress_ctx *dctx =
container_of(dc, struct zlib_decompress_ctx, dc);
@ -1209,13 +1209,13 @@ int zlib_decompress_block(ssh_decompressor *dc, unsigned char *block, int len,
finished:
*outblock = dctx->outblk;
*outlen = dctx->outlen;
return 1;
return true;
decode_error:
sfree(dctx->outblk);
*outblock = dctx->outblk = NULL;
*outlen = 0;
return 0;
return false;
}
#ifdef ZLIB_STANDALONE

View File

@ -171,7 +171,7 @@ static const struct Opt *const opts[] = {
typedef struct Telnet Telnet;
struct Telnet {
Socket *s;
int closed_on_socket_error;
bool closed_on_socket_error;
Seat *seat;
LogContext *logctx;
@ -180,14 +180,14 @@ struct Telnet {
int opt_states[NUM_OPTS];
int echoing, editing;
int activated;
bool echoing, editing;
bool activated;
int bufsize;
int in_synch;
bool in_synch;
int sb_opt, sb_len;
unsigned char *sb_buf;
int sb_size;
int session_started;
bool session_started;
enum {
TOP_LEVEL, SEENIAC, SEENWILL, SEENWONT, SEENDO, SEENDONT,
@ -248,7 +248,8 @@ static void deactivate_option(Telnet *telnet, const struct Opt *o)
/*
* Generate side effects of enabling or disabling an option.
*/
static void option_side_effects(Telnet *telnet, const struct Opt *o, int enabled)
static void option_side_effects(
Telnet *telnet, const struct Opt *o, bool enabled)
{
if (o->option == TELOPT_ECHO && o->send == DO)
telnet->echoing = !enabled;
@ -290,7 +291,7 @@ static void activate_option(Telnet *telnet, const struct Opt *o)
deactivate_option(telnet, o->option ==
TELOPT_NEW_ENVIRON ? &o_oenv : &o_nenv);
}
option_side_effects(telnet, o, 1);
option_side_effects(telnet, o, true);
}
static void refused_option(Telnet *telnet, const struct Opt *o)
@ -300,7 +301,7 @@ static void refused_option(Telnet *telnet, const struct Opt *o)
send_opt(telnet, WILL, TELOPT_OLD_ENVIRON);
telnet->opt_states[o_oenv.index] = REQUESTED;
}
option_side_effects(telnet, o, 0);
option_side_effects(telnet, o, false);
}
static void proc_rec_opt(Telnet *telnet, int cmd, int option)
@ -336,7 +337,7 @@ static void proc_rec_opt(Telnet *telnet, int cmd, int option)
case ACTIVE:
telnet->opt_states[(*o)->index] = INACTIVE;
send_opt(telnet, (*o)->nsend, option);
option_side_effects(telnet, *o, 0);
option_side_effects(telnet, *o, false);
break;
case INACTIVE:
case REALLY_INACTIVE:
@ -542,7 +543,7 @@ static void do_telnet_read(Telnet *telnet, char *buf, int len)
* just stop hiding on the next 0xf2 and hope for the best.
*/
else if (c == DM)
telnet->in_synch = 0;
telnet->in_synch = false;
#endif
if (c == CR && telnet->opt_states[o_they_bin.index] != ACTIVE)
telnet->state = SEENCR;
@ -562,7 +563,7 @@ static void do_telnet_read(Telnet *telnet, char *buf, int len)
else if (c == SB)
telnet->state = SEENSB;
else if (c == DM) {
telnet->in_synch = 0;
telnet->in_synch = false;
telnet->state = TOP_LEVEL;
} else {
/* ignore everything else; print it if it's IAC */
@ -633,7 +634,7 @@ static void telnet_log(Plug *plug, int type, SockAddr *addr, int port,
}
static void telnet_closing(Plug *plug, const char *error_msg, int error_code,
int calling_back)
bool calling_back)
{
Telnet *telnet = container_of(plug, Telnet, plug);
@ -690,7 +691,7 @@ static const PlugVtable Telnet_plugvt = {
static const char *telnet_init(Seat *seat, Backend **backend_handle,
LogContext *logctx, Conf *conf,
const char *host, int port,
char **realhost, int nodelay, int keepalive)
char **realhost, bool nodelay, bool keepalive)
{
SockAddr *addr;
const char *err;
@ -736,8 +737,8 @@ static const char *telnet_init(Seat *seat, Backend **backend_handle,
/*
* Open socket.
*/
telnet->s = new_connection(addr, *realhost, port, 0, 1, nodelay, keepalive,
&telnet->plug, telnet->conf);
telnet->s = new_connection(addr, *realhost, port, false, true, nodelay,
keepalive, &telnet->plug, telnet->conf);
if ((err = sk_socket_error(telnet->s)) != NULL)
return err;
@ -1000,16 +1001,16 @@ static const SessionSpecial *telnet_get_specials(Backend *be)
return specials;
}
static int telnet_connected(Backend *be)
static bool telnet_connected(Backend *be)
{
Telnet *telnet = container_of(be, Telnet, backend);
return telnet->s != NULL;
}
static int telnet_sendok(Backend *be)
static bool telnet_sendok(Backend *be)
{
/* Telnet *telnet = container_of(be, Telnet, backend); */
return 1;
return true;
}
static void telnet_unthrottle(Backend *be, int backlog)
@ -1018,7 +1019,7 @@ static void telnet_unthrottle(Backend *be, int backlog)
sk_set_frozen(telnet->s, backlog > TELNET_MAX_BACKLOG);
}
static int telnet_ldisc(Backend *be, int option)
static bool telnet_ldisc(Backend *be, int option)
{
Telnet *telnet = container_of(be, Telnet, backend);
if (option == LD_ECHO)

View File

@ -22,8 +22,12 @@
#define posPlt(p1,p2) ( (p1).y <= (p2).y && (p1).x < (p2).x )
#define posPle(p1,p2) ( (p1).y <= (p2).y && (p1).x <= (p2).x )
#define incpos(p) ( (p).x == term->cols ? ((p).x = 0, (p).y++, 1) : ((p).x++, 0) )
#define decpos(p) ( (p).x == 0 ? ((p).x = term->cols, (p).y--, 1) : ((p).x--, 0) )
#define incpos(p) ( (p).x == term->cols ? \
((p).x = 0, (p).y++, true) : \
((p).x++, false) )
#define decpos(p) ( (p).x == 0 ? \
((p).x = term->cols, (p).y--, true) : \
((p).x--, false) )
#define VT52_PLUS
@ -102,16 +106,16 @@ static termline *lineptr(Terminal *, int, int, int);
static void unlineptr(termline *);
static void check_line_size(Terminal *, termline *);
static void do_paint(Terminal *);
static void erase_lots(Terminal *, int, int, int);
static void erase_lots(Terminal *, bool, bool, bool);
static int find_last_nonempty_line(Terminal *, tree234 *);
static void swap_screen(Terminal *, int, int, int);
static void swap_screen(Terminal *, int, bool, bool);
static void update_sbar(Terminal *);
static void deselect(Terminal *);
static void term_print_finish(Terminal *);
static void scroll(Terminal *, int, int, int, int);
static void scroll(Terminal *, int, int, int, bool);
static void parse_optionalrgb(optionalrgb *out, unsigned *values);
static termline *newline(Terminal *term, int cols, int bce)
static termline *newline(Terminal *term, int cols, bool bce)
{
termline *line;
int j;
@ -278,8 +282,8 @@ static void clear_cc(termline *line, int col)
* in do_paint() where we override what we expect the chr and attr
* fields to be.
*/
static int termchars_equal_override(termchar *a, termchar *b,
unsigned long bchr, unsigned long battr)
static bool termchars_equal_override(termchar *a, termchar *b,
unsigned long bchr, unsigned long battr)
{
/* FULL-TERMCHAR */
if (!truecolour_equal(a->truecolour, b->truecolour))
@ -299,7 +303,7 @@ static int termchars_equal_override(termchar *a, termchar *b,
return true;
}
static int termchars_equal(termchar *a, termchar *b)
static bool termchars_equal(termchar *a, termchar *b)
{
return termchars_equal_override(a, b, b->chr, b->attr);
}
@ -375,7 +379,8 @@ static void makerle(struct buf *b, termline *ldata,
void (*makeliteral)(struct buf *b, termchar *c,
unsigned long *state))
{
int hdrpos, hdrsize, n, prevlen, prevpos, thislen, thispos, prev2;
int hdrpos, hdrsize, n, prevlen, prevpos, thislen, thispos;
bool prev2;
termchar *c = ldata->chars;
unsigned long state = 0, oldstate;
@ -1132,8 +1137,8 @@ static termline *lineptr(Terminal *term, int y, int lineno, int screen)
return line;
}
#define lineptr(x) (lineptr)(term,x,__LINE__,false)
#define scrlineptr(x) (lineptr)(term,x,__LINE__,true)
#define lineptr(x) (lineptr)(term,x,__LINE__,0)
#define scrlineptr(x) (lineptr)(term,x,__LINE__,1)
/*
* Coerce a termline to the terminal's current width. Unlike the
@ -1157,7 +1162,7 @@ static void term_schedule_cblink(Terminal *term);
static void term_timer(void *ctx, unsigned long now)
{
Terminal *term = (Terminal *)ctx;
int update = false;
bool update = false;
if (term->tblink_pending && now == term->next_tblink) {
term->tblinker = !term->tblinker;
@ -1212,7 +1217,7 @@ static void term_schedule_tblink(Terminal *term)
term->next_tblink = schedule_timer(TBLINK_DELAY, term_timer, term);
term->tblink_pending = true;
} else {
term->tblinker = 1; /* reset when not in use */
term->tblinker = true; /* reset when not in use */
term->tblink_pending = false;
}
}
@ -1227,7 +1232,7 @@ static void term_schedule_cblink(Terminal *term)
term->next_cblink = schedule_timer(CBLINK_DELAY, term_timer, term);
term->cblink_pending = true;
} else {
term->cblinker = 1; /* reset when not in use */
term->cblinker = true; /* reset when not in use */
term->cblink_pending = false;
}
}
@ -1238,7 +1243,7 @@ static void term_schedule_cblink(Terminal *term)
static void term_reset_cblink(Terminal *term)
{
seen_disp_event(term);
term->cblinker = 1;
term->cblinker = true;
term->cblink_pending = false;
term_schedule_cblink(term);
}
@ -1246,7 +1251,7 @@ static void term_reset_cblink(Terminal *term)
/*
* Call to begin a visual bell.
*/
static void term_schedule_vbell(Terminal *term, int already_started,
static void term_schedule_vbell(Terminal *term, bool already_started,
long startpoint)
{
long ticks_already_gone;
@ -1271,7 +1276,7 @@ static void term_schedule_vbell(Terminal *term, int already_started,
* position the cursor below the last non-blank line (scrolling if
* necessary).
*/
static void power_on(Terminal *term, int clear)
static void power_on(Terminal *term, bool clear)
{
term->alt_x = term->alt_y = 0;
term->savecurs.x = term->savecurs.y = 0;
@ -1287,21 +1292,27 @@ static void power_on(Terminal *term, int clear)
term->tabs[i] = (i % 8 == 0 ? true : false);
}
term->alt_om = term->dec_om = conf_get_bool(term->conf, CONF_dec_om);
term->alt_ins = term->insert = false;
term->alt_wnext = term->wrapnext =
term->save_wnext = term->alt_save_wnext = false;
term->alt_ins = false;
term->insert = false;
term->alt_wnext = false;
term->wrapnext = false;
term->save_wnext = false;
term->alt_save_wnext = false;
term->alt_wrap = term->wrap = conf_get_bool(term->conf, CONF_wrap_mode);
term->alt_cset = term->cset = term->save_cset = term->alt_save_cset = 0;
term->alt_utf = term->utf = term->save_utf = term->alt_save_utf = 0;
term->alt_utf = false;
term->utf = false;
term->save_utf = false;
term->alt_save_utf = false;
term->utf_state = 0;
term->alt_sco_acs = term->sco_acs =
term->save_sco_acs = term->alt_save_sco_acs = 0;
term->cset_attr[0] = term->cset_attr[1] =
term->save_csattr = term->alt_save_csattr = CSET_ASCII;
term->rvideo = 0;
term->rvideo = false;
term->in_vbell = false;
term->cursor_on = 1;
term->big_cursor = 0;
term->cursor_on = true;
term->big_cursor = false;
term->default_attr = term->save_attr =
term->alt_save_attr = term->curr_attr = ATTR_DEFAULT;
term->curr_truecolour.fg = term->curr_truecolour.bg = optionalrgb_none;
@ -1315,8 +1326,8 @@ static void power_on(Terminal *term, int clear)
term->alt_which = 0;
term_print_finish(term);
term->xterm_mouse = 0;
term->xterm_extended_mouse = 0;
term->urxvt_extended_mouse = 0;
term->xterm_extended_mouse = false;
term->urxvt_extended_mouse = false;
win_set_raw_mouse_mode(term->win, false);
term->bracketed_paste = false;
{
@ -1351,10 +1362,10 @@ void term_update(Terminal *term)
term->window_update_pending = false;
if (win_setup_draw_ctx(term->win)) {
int need_sbar_update = term->seen_disp_event;
bool need_sbar_update = term->seen_disp_event;
if (term->seen_disp_event && term->scroll_on_disp) {
term->disptop = 0; /* return to main screen */
term->seen_disp_event = 0;
term->seen_disp_event = false;
need_sbar_update = true;
}
@ -1401,7 +1412,7 @@ void term_seen_key_event(Terminal *term)
/*
* Same as power_on(), but an external function.
*/
void term_pwron(Terminal *term, int clear)
void term_pwron(Terminal *term, bool clear)
{
power_on(term, clear);
if (term->ldisc) /* cause ldisc to notice changes */
@ -1509,7 +1520,7 @@ void term_reconfig(Terminal *term, Conf *conf)
* default one. The full list is: Auto wrap mode, DEC Origin
* Mode, BCE, blinking text, character classes.
*/
int reset_wrap, reset_decom, reset_bce, reset_tblink, reset_charclass;
bool reset_wrap, reset_decom, reset_bce, reset_tblink, reset_charclass;
int i;
reset_wrap = (conf_get_bool(term->conf, CONF_wrap_mode) !=
@ -1520,11 +1531,11 @@ void term_reconfig(Terminal *term, Conf *conf)
conf_get_bool(conf, CONF_bce));
reset_tblink = (conf_get_bool(term->conf, CONF_blinktext) !=
conf_get_bool(conf, CONF_blinktext));
reset_charclass = 0;
reset_charclass = false;
for (i = 0; i < 256; i++)
if (conf_get_int_int(term->conf, CONF_wordness, i) !=
conf_get_int_int(conf, CONF_wordness, i))
reset_charclass = 1;
reset_charclass = true;
/*
* If the bidi or shaping settings have changed, flush the bidi
@ -1571,7 +1582,7 @@ void term_reconfig(Terminal *term, Conf *conf)
if (conf_get_bool(term->conf, CONF_no_remote_charset)) {
term->cset_attr[0] = term->cset_attr[1] = CSET_ASCII;
term->sco_acs = term->alt_sco_acs = 0;
term->utf = 0;
term->utf = false;
}
if (!conf_get_str(term->conf, CONF_printer)) {
term_print_finish(term);
@ -1658,10 +1669,11 @@ Terminal *term_init(Conf *myconf, struct unicode_data *ucsdata, TermWin *win)
term->vt52_mode = false;
term->cr_lf_return = false;
term->seen_disp_event = false;
term->mouse_is_down = false;
term->mouse_is_down = 0;
term->reset_132 = false;
term->cblinker = term->tblinker = 0;
term->has_focus = 1;
term->cblinker = false;
term->tblinker = false;
term->has_focus = true;
term->repeat_off = false;
term->termstate = TOPLEVEL;
term->selstate = NO_SELECTION;
@ -1944,7 +1956,8 @@ void term_size(Terminal *term, int newrows, int newcols, int newsavelines)
if (term->alt_x >= newcols)
term->alt_x = newcols - 1;
term->alt_x = term->alt_y = 0;
term->wrapnext = term->alt_wnext = false;
term->wrapnext = false;
term->alt_wnext = false;
term->rows = newrows;
term->cols = newcols;
@ -1993,9 +2006,11 @@ static int find_last_nonempty_line(Terminal * term, tree234 * screen)
* alternate screen completely. (This is even true if we're already
* on it! Blame xterm.)
*/
static void swap_screen(Terminal *term, int which, int reset, int keep_cur_pos)
static void swap_screen(Terminal *term, int which,
bool reset, bool keep_cur_pos)
{
int t;
bool bt;
pos tp;
truecolour ttc;
tree234 *ttr;
@ -2024,24 +2039,24 @@ static void swap_screen(Terminal *term, int which, int reset, int keep_cur_pos)
t = term->marg_b;
if (!reset) term->marg_b = term->alt_b;
term->alt_b = t;
t = term->dec_om;
bt = term->dec_om;
if (!reset) term->dec_om = term->alt_om;
term->alt_om = t;
t = term->wrap;
term->alt_om = bt;
bt = term->wrap;
if (!reset) term->wrap = term->alt_wrap;
term->alt_wrap = t;
t = term->wrapnext;
term->alt_wrap = bt;
bt = term->wrapnext;
if (!reset) term->wrapnext = term->alt_wnext;
term->alt_wnext = t;
t = term->insert;
term->alt_wnext = bt;
bt = term->insert;
if (!reset) term->insert = term->alt_ins;
term->alt_ins = t;
term->alt_ins = bt;
t = term->cset;
if (!reset) term->cset = term->alt_cset;
term->alt_cset = t;
t = term->utf;
bt = term->utf;
if (!reset) term->utf = term->alt_utf;
term->alt_utf = t;
term->alt_utf = bt;
t = term->sco_acs;
if (!reset) term->sco_acs = term->alt_sco_acs;
term->alt_sco_acs = t;
@ -2066,14 +2081,14 @@ static void swap_screen(Terminal *term, int which, int reset, int keep_cur_pos)
if (!reset && !keep_cur_pos)
term->save_truecolour = term->alt_save_truecolour;
term->alt_save_truecolour = ttc;
t = term->save_utf;
bt = term->save_utf;
if (!reset && !keep_cur_pos)
term->save_utf = term->alt_save_utf;
term->alt_save_utf = t;
t = term->save_wnext;
term->alt_save_utf = bt;
bt = term->save_wnext;
if (!reset && !keep_cur_pos)
term->save_wnext = term->alt_save_wnext;
term->alt_save_wnext = t;
term->alt_save_wnext = bt;
t = term->save_sco_acs;
if (!reset && !keep_cur_pos)
term->save_sco_acs = term->alt_save_sco_acs;
@ -2113,7 +2128,8 @@ static void check_selection(Terminal *term, pos from, pos to)
* for backward.) `sb' is true if the scrolling is permitted to
* affect the scrollback buffer.
*/
static void scroll(Terminal *term, int topline, int botline, int lines, int sb)
static void scroll(Terminal *term, int topline, int botline,
int lines, bool sb)
{
termline *line;
int i, seltop, scrollwinsize;
@ -2275,7 +2291,7 @@ static void move(Terminal *term, int x, int y, int marg_clip)
/*
* Save or restore the cursor and SGR mode.
*/
static void save_cursor(Terminal *term, int save)
static void save_cursor(Terminal *term, bool save)
{
if (save) {
term->savecurs = term->curs;
@ -2357,11 +2373,11 @@ static void check_boundary(Terminal *term, int x, int y)
* whole line, or parts thereof.
*/
static void erase_lots(Terminal *term,
int line_only, int from_begin, int to_end)
bool line_only, bool from_begin, bool to_end)
{
pos start, end;
int erase_lattr;
int erasing_lines_from_top = 0;
bool erase_lattr;
bool erasing_lines_from_top = false;
if (line_only) {
start.y = term->curs.y;
@ -2394,7 +2410,7 @@ static void erase_lots(Terminal *term,
/* Lines scrolled away shouldn't be brought back on if the terminal
* resizes. */
if (start.y == 0 && start.x == 0 && end.x == 0 && erase_lattr)
erasing_lines_from_top = 1;
erasing_lines_from_top = true;
if (term->erase_to_scrollback && erasing_lines_from_top) {
/* If it's a whole number of lines, starting at the top, and
@ -2510,9 +2526,9 @@ static void insch(Terminal *term, int n)
* Toggle terminal mode `mode' to state `state'. (`query' indicates
* whether the mode is a DEC private one or a normal one.)
*/
static void toggle_mode(Terminal *term, int mode, int query, int state)
static void toggle_mode(Terminal *term, int mode, int query, bool state)
{
if (query)
if (query == 1) {
switch (mode) {
case 1: /* DECCKM: application cursor keys */
term->app_cursor_keys = state;
@ -2589,10 +2605,10 @@ static void toggle_mode(Terminal *term, int mode, int query, int state)
win_set_raw_mouse_mode(term->win, state);
break;
case 1006: /* xterm extended mouse */
term->xterm_extended_mouse = state ? 1 : 0;
term->xterm_extended_mouse = state;
break;
case 1015: /* urxvt extended mouse */
term->urxvt_extended_mouse = state ? 1 : 0;
term->urxvt_extended_mouse = state;
break;
case 1047: /* alternate screen */
compatibility(OTHER);
@ -2621,7 +2637,8 @@ static void toggle_mode(Terminal *term, int mode, int query, int state)
case 2004: /* xterm bracketed paste */
term->bracketed_paste = state ? true : false;
break;
} else
}
} else if (query == 0) {
switch (mode) {
case 4: /* IRM: set insert mode */
compatibility(VT102);
@ -2639,6 +2656,7 @@ static void toggle_mode(Terminal *term, int mode, int query, int state)
compatibility2(OTHER, VT220);
term->big_cursor = !state;
}
}
}
/*
@ -2676,7 +2694,8 @@ static void do_osc(Terminal *term)
(unsigned)r * 0x0101,
(unsigned)g * 0x0101,
(unsigned)b * 0x0101);
ldisc_send(term->ldisc, reply_buf, strlen(reply_buf), 0);
ldisc_send(term->ldisc, reply_buf, strlen(reply_buf),
false);
sfree(reply_buf);
}
}
@ -3088,7 +3107,7 @@ static void term_out(Terminal *term)
c = 0;
else {
term->termstate = SEEN_ESC;
term->esc_query = false;
term->esc_query = 0;
c = '@' + (c & 0x1F);
}
}
@ -3120,7 +3139,7 @@ static void term_out(Terminal *term)
compatibility(ANSIMIN);
if (term->ldisc) {
lpage_send(term->ldisc, DEFAULT_CODEPAGE,
term->answerback, term->answerbacklen, 0);
term->answerback, term->answerbacklen, false);
}
break;
case '\007': /* BEL: Bell */
@ -3189,8 +3208,7 @@ static void term_out(Terminal *term)
}
break;
case '\b': /* BS: Back space */
if (term->curs.x == 0 &&
(term->curs.y == 0 || term->wrap == 0))
if (term->curs.x == 0 && (term->curs.y == 0 || term->wrap))
/* do nothing */ ;
else if (term->curs.x == 0 && term->curs.y > 0)
term->curs.x = term->cols - 1, term->curs.y--;
@ -3214,7 +3232,7 @@ static void term_out(Terminal *term)
else {
compatibility(ANSIMIN);
term->termstate = SEEN_ESC;
term->esc_query = false;
term->esc_query = 0;
}
break;
case '\015': /* CR: Carriage return */
@ -3313,7 +3331,7 @@ static void term_out(Terminal *term)
term->termstate = SEEN_CSI;
term->esc_nargs = 1;
term->esc_args[0] = ARG_DEFAULT;
term->esc_query = false;
term->esc_query = 0;
break;
case ']': /* OSC: xterm escape sequences */
/* Compatibility is nasty here, xterm, linux, decterm yuk! */
@ -3371,7 +3389,7 @@ static void term_out(Terminal *term)
compatibility(VT100);
if (term->ldisc && term->id_string[0])
ldisc_send(term->ldisc, term->id_string,
strlen(term->id_string), 0);
strlen(term->id_string), false);
break;
case 'c': /* RIS: restore power-on settings */
compatibility(VT100);
@ -3381,7 +3399,7 @@ static void term_out(Terminal *term)
if (term->reset_132) {
if (!term->no_remote_resize)
win_request_resize(term->win, 80, term->rows);
term->reset_132 = 0;
term->reset_132 = false;
}
if (term->scroll_on_disp)
term->disptop = 0;
@ -3494,12 +3512,12 @@ static void term_out(Terminal *term)
case ANSI('G', '%'):
compatibility(OTHER);
if (!term->no_remote_charset)
term->utf = 1;
term->utf = true;
break;
case ANSI('@', '%'):
compatibility(OTHER);
if (!term->no_remote_charset)
term->utf = 0;
term->utf = false;
break;
}
break;
@ -3528,7 +3546,7 @@ static void term_out(Terminal *term)
if (term->esc_query)
term->esc_query = -1;
else if (c == '?')
term->esc_query = true;
term->esc_query = 1;
else
term->esc_query = c;
term->termstate = SEEN_CSI;
@ -3564,7 +3582,8 @@ static void term_out(Terminal *term)
/* this reports xterm version 136 so that VIM can
use the drag messages from the mouse reporting */
if (term->ldisc)
ldisc_send(term->ldisc, "\033[>0;136;0c", 11, 0);
ldisc_send(term->ldisc, "\033[>0;136;0c", 11,
false);
break;
case 'a': /* HPR: move right N cols */
compatibility(ANSI);
@ -3687,7 +3706,7 @@ static void term_out(Terminal *term)
/* This is the response for a VT102 */
if (term->ldisc && term->id_string[0])
ldisc_send(term->ldisc, term->id_string,
strlen(term->id_string), 0);
strlen(term->id_string), false);
break;
case 'n': /* DSR: cursor position query */
if (term->ldisc) {
@ -3695,9 +3714,10 @@ static void term_out(Terminal *term)
char buf[32];
sprintf(buf, "\033[%d;%dR", term->curs.y + 1,
term->curs.x + 1);
ldisc_send(term->ldisc, buf, strlen(buf), 0);
ldisc_send(term->ldisc, buf, strlen(buf),
false);
} else if (term->esc_args[0] == 5) {
ldisc_send(term->ldisc, "\033[0n", 4, 0);
ldisc_send(term->ldisc, "\033[0n", 4, false);
}
}
break;
@ -4088,7 +4108,8 @@ static void term_out(Terminal *term)
if (term->ldisc)
ldisc_send(term->ldisc,
win_is_minimised(term->win) ?
"\033[2t" : "\033[1t", 4, 0);
"\033[2t" : "\033[1t", 4,
false);
break;
case 13:
if (term->ldisc) {
@ -4096,21 +4117,21 @@ static void term_out(Terminal *term)
len = sprintf(buf, "\033[3;%u;%ut",
(unsigned)x,
(unsigned)y);
ldisc_send(term->ldisc, buf, len, 0);
ldisc_send(term->ldisc, buf, len, false);
}
break;
case 14:
if (term->ldisc) {
win_get_pixels(term->win, &x, &y);
len = sprintf(buf, "\033[4;%d;%dt", y, x);
ldisc_send(term->ldisc, buf, len, 0);
ldisc_send(term->ldisc, buf, len, false);
}
break;
case 18:
if (term->ldisc) {
len = sprintf(buf, "\033[8;%d;%dt",
term->rows, term->cols);
ldisc_send(term->ldisc, buf, len, 0);
ldisc_send(term->ldisc, buf, len, false);
}
break;
case 19:
@ -4138,10 +4159,12 @@ static void term_out(Terminal *term)
else
p = EMPTY_WINDOW_TITLE;
len = strlen(p);
ldisc_send(term->ldisc, "\033]L", 3, 0);
ldisc_send(term->ldisc, "\033]L", 3,
false);
if (len > 0)
ldisc_send(term->ldisc, p, len, 0);
ldisc_send(term->ldisc, "\033\\", 2, 0);
ldisc_send(term->ldisc, p, len, false);
ldisc_send(term->ldisc, "\033\\", 2,
false);
}
break;
case 21:
@ -4152,10 +4175,12 @@ static void term_out(Terminal *term)
else
p = EMPTY_WINDOW_TITLE;
len = strlen(p);
ldisc_send(term->ldisc, "\033]l", 3, 0);
ldisc_send(term->ldisc, "\033]l", 3,
false);
if (len > 0)
ldisc_send(term->ldisc, p, len, 0);
ldisc_send(term->ldisc, "\033\\", 2, 0);
ldisc_send(term->ldisc, p, len, false);
ldisc_send(term->ldisc, "\033\\", 2,
false);
}
break;
}
@ -4241,7 +4266,7 @@ static void term_out(Terminal *term)
if (i == 0 || i == 1) {
strcpy(buf, "\033[2;1;1;112;112;1;0x");
buf[2] += i;
ldisc_send(term->ldisc, buf, 20, 0);
ldisc_send(term->ldisc, buf, 20, false);
}
}
break;
@ -4657,7 +4682,7 @@ static void term_out(Terminal *term)
break;
case 'Z':
if (term->ldisc)
ldisc_send(term->ldisc, "\033/Z", 3, 0);
ldisc_send(term->ldisc, "\033/Z", 3, false);
break;
case '=':
term->app_keypad_keys = true;
@ -4748,11 +4773,11 @@ static void term_out(Terminal *term)
break;
case 'v': /* wrap Autowrap on - Wyse style */
/* compatibility(ATARI) */
term->wrap = 1;
term->wrap = true;
break;
case 'w': /* Autowrap off */
/* compatibility(ATARI) */
term->wrap = 0;
term->wrap = false;
break;
case 'R':
@ -4841,8 +4866,8 @@ static void parse_optionalrgb(optionalrgb *out, unsigned *values)
* too many times, we maintain a cache of the last lineful of data
* fed to the algorithm on each line of the display.
*/
static int term_bidi_cache_hit(Terminal *term, int line,
termchar *lbefore, int width)
static bool term_bidi_cache_hit(Terminal *term, int line,
termchar *lbefore, int width)
{
int i;
@ -5115,12 +5140,13 @@ static void do_paint(Terminal *term)
for (i = 0; i < term->rows; i++) {
termline *ldata;
termchar *lchars;
int dirty_line, dirty_run, selected;
bool dirty_line, dirty_run, selected;
unsigned long attr = 0, cset = 0;
int start = 0;
int ccount = 0;
int last_run_dirty = 0;
int laststart, dirtyrect;
bool last_run_dirty = false;
int laststart;
bool dirtyrect;
int *backward;
truecolour tc;
@ -5280,7 +5306,7 @@ static void do_paint(Terminal *term)
tc = term->erase_char.truecolour;
for (j = 0; j < term->cols; j++) {
unsigned long tattr, tchar;
int break_run, do_copy;
bool break_run, do_copy;
termchar *d = lchars + j;
tattr = newline[j].attr;
@ -5458,7 +5484,7 @@ void term_invalidate(Terminal *term)
* Paint the window in response to a WM_PAINT message.
*/
void term_paint(Terminal *term,
int left, int top, int right, int bottom, int immediately)
int left, int top, int right, int bottom, bool immediately)
{
int i, j;
if (left < 0) left = 0;
@ -5558,7 +5584,7 @@ static void clip_addchar(clip_workbuf *b, wchar_t chr, int attr, truecolour tc)
b->bufpos++;
}
static void clipme(Terminal *term, pos top, pos bottom, int rect, int desel,
static void clipme(Terminal *term, pos top, pos bottom, bool rect, bool desel,
const int *clipboards, int n_clipboards)
{
clip_workbuf buf;
@ -5575,7 +5601,7 @@ static void clipme(Terminal *term, pos top, pos bottom, int rect, int desel,
old_top_x = top.x; /* needed for rect==1 */
while (poslt(top, bottom)) {
int nl = false;
bool nl = false;
termline *ldata = lineptr(top.y);
pos nlpos;
@ -5722,7 +5748,7 @@ static void clipme(Terminal *term, pos top, pos bottom, int rect, int desel,
/* Finally, transfer all that to the clipboard(s). */
{
int i;
int clip_local = false;
bool clip_local = false;
for (i = 0; i < n_clipboards; i++) {
if (clipboards[i] == CLIP_LOCAL) {
clip_local = true;
@ -5757,7 +5783,7 @@ void term_copyall(Terminal *term, const int *clipboards, int n_clipboards)
top.x = 0;
bottom.y = find_last_nonempty_line(term, screen);
bottom.x = term->cols;
clipme(term, top, bottom, 0, true, clipboards, n_clipboards);
clipme(term, top, bottom, false, true, clipboards, n_clipboards);
}
static void paste_from_clip_local(void *vterm)
@ -6038,7 +6064,8 @@ static void term_paste_callback(void *vterm)
break;
}
if (term->ldisc)
luni_send(term->ldisc, term->paste_buffer + term->paste_pos, n, 0);
luni_send(term->ldisc, term->paste_buffer + term->paste_pos, n,
false);
term->paste_pos += n;
if (term->paste_pos < term->paste_len) {
@ -6056,7 +6083,7 @@ static void term_paste_callback(void *vterm)
* alen wide characters starting at a has as a prefix the buffer of
* blen characters starting at b.
*/
static int wstartswith(const wchar_t *a, size_t alen,
static bool wstartswith(const wchar_t *a, size_t alen,
const wchar_t *b, size_t blen)
{
return alen >= blen && !wcsncmp(a, b, blen);
@ -6065,7 +6092,7 @@ static int wstartswith(const wchar_t *a, size_t alen,
void term_do_paste(Terminal *term, const wchar_t *data, int len)
{
const wchar_t *p;
int paste_controls = conf_get_bool(term->conf, CONF_paste_controls);
bool paste_controls = conf_get_bool(term->conf, CONF_paste_controls);
/*
* Pasting data into the terminal counts as a keyboard event (for
@ -6142,7 +6169,7 @@ void term_do_paste(Terminal *term, const wchar_t *data, int len)
/* Assume a small paste will be OK in one go. */
if (term->paste_len < 256) {
if (term->ldisc)
luni_send(term->ldisc, term->paste_buffer, term->paste_len, 0);
luni_send(term->ldisc, term->paste_buffer, term->paste_len, false);
if (term->paste_buffer)
sfree(term->paste_buffer);
term->paste_buffer = 0;
@ -6153,13 +6180,13 @@ void term_do_paste(Terminal *term, const wchar_t *data, int len)
}
void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked,
Mouse_Action a, int x, int y, int shift, int ctrl, int alt)
Mouse_Action a, int x, int y, bool shift, bool ctrl, bool alt)
{
pos selpoint;
termline *ldata;
int raw_mouse = (term->xterm_mouse &&
!term->no_mouse_rep &&
!(term->mouse_override && shift));
bool raw_mouse = (term->xterm_mouse &&
!term->no_mouse_rep &&
!(term->mouse_override && shift));
int default_seltype;
if (y < 0) {
@ -6220,7 +6247,8 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked,
*/
if (raw_mouse &&
(term->selstate != ABOUT_TO) && (term->selstate != DRAGGING)) {
int encstate = 0, r, c, wheel;
int encstate = 0, r, c;
bool wheel;
char abuf[32];
int len = 0;
@ -6293,7 +6321,7 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked,
len = sprintf(abuf, "\033[M%c%c%c", encstate + 32, c + 32, r + 32);
}
if (len > 0)
ldisc_send(term->ldisc, abuf, len, 0);
ldisc_send(term->ldisc, abuf, len, false);
}
return;
}
@ -6437,14 +6465,14 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked,
term_update(term);
}
int format_arrow_key(char *buf, Terminal *term, int xkey, int ctrl)
int format_arrow_key(char *buf, Terminal *term, int xkey, bool ctrl)
{
char *p = buf;
if (term->vt52_mode)
p += sprintf((char *) p, "\x1B%c", xkey);
else {
int app_flg = (term->app_cursor_keys && !term->no_applic_c);
bool app_flg = (term->app_cursor_keys && !term->no_applic_c);
#if 0
/*
* RDB: VT100 & VT102 manuals both state the app cursor
@ -6506,7 +6534,7 @@ void term_lost_clipboard_ownership(Terminal *term, int clipboard)
term_out(term);
}
int term_ldisc(Terminal *term, int option)
bool term_ldisc(Terminal *term, int option)
{
if (option == LD_ECHO)
return term->term_echoing;
@ -6531,7 +6559,7 @@ static void term_added_data(Terminal *term)
}
}
int term_data(Terminal *term, int is_stderr, const void *data, int len)
int term_data(Terminal *term, bool is_stderr, const void *data, int len)
{
bufchain_add(&term->inbuf, data, len);
term_added_data(term);
@ -6569,7 +6597,7 @@ void term_provide_logctx(Terminal *term, LogContext *logctx)
term->logctx = logctx;
}
void term_set_focus(Terminal *term, int has_focus)
void term_set_focus(Terminal *term, bool has_focus)
{
term->has_focus = has_focus;
term_schedule_cblink(term);
@ -6594,7 +6622,7 @@ char *term_get_ttymode(Terminal *term, const char *mode)
struct term_userpass_state {
size_t curr_prompt;
int done_prompt; /* printed out prompt yet? */
bool done_prompt; /* printed out prompt yet? */
size_t pos; /* cursor position */
};
@ -6611,7 +6639,7 @@ int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input)
*/
p->data = s = snew(struct term_userpass_state);
s->curr_prompt = 0;
s->done_prompt = 0;
s->done_prompt = false;
/* We only print the `name' caption if we have to... */
if (p->name_reqd && p->name) {
size_t l = strlen(p->name);
@ -6639,11 +6667,11 @@ int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input)
while (s->curr_prompt < p->n_prompts) {
prompt_t *pr = p->prompts[s->curr_prompt];
int finished_prompt = 0;
bool finished_prompt = false;
if (!s->done_prompt) {
term_data_untrusted(term, pr->prompt, strlen(pr->prompt));
s->done_prompt = 1;
s->done_prompt = true;
s->pos = 0;
}
@ -6658,19 +6686,19 @@ int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input)
switch (c) {
case 10:
case 13:
term_data(term, 0, "\r\n", 2);
term_data(term, false, "\r\n", 2);
prompt_ensure_result_size(pr, s->pos + 1);
pr->result[s->pos] = '\0';
/* go to next prompt, if any */
s->curr_prompt++;
s->done_prompt = 0;
finished_prompt = 1; /* break out */
s->done_prompt = false;
finished_prompt = true; /* break out */
break;
case 8:
case 127:
if (s->pos > 0) {
if (pr->echo)
term_data(term, 0, "\b \b", 3);
term_data(term, false, "\b \b", 3);
s->pos--;
}
break;
@ -6678,14 +6706,14 @@ int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input)
case 27:
while (s->pos > 0) {
if (pr->echo)
term_data(term, 0, "\b \b", 3);
term_data(term, false, "\b \b", 3);
s->pos--;
}
break;
case 3:
case 4:
/* Immediate abort. */
term_data(term, 0, "\r\n", 2);
term_data(term, false, "\r\n", 2);
sfree(s);
p->data = NULL;
return 0; /* user abort */
@ -6700,7 +6728,7 @@ int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input)
prompt_ensure_result_size(pr, s->pos + 1);
pr->result[s->pos++] = c;
if (pr->echo)
term_data(term, 0, &c, 1);
term_data(term, false, &c, 1);
}
break;
}

View File

@ -52,7 +52,7 @@ struct termline {
int cols; /* number of real columns on the line */
int size; /* number of allocated termchars
* (cc-lists may make this > cols) */
int temporary; /* true if decompressed from scrollback */
bool temporary; /* true if decompressed from scrollback */
int cc_free; /* offset to first cc in free list */
struct termchar *chars;
};
@ -83,7 +83,7 @@ struct terminal_tag {
struct beeptime *beephead, *beeptail;
int nbeeps;
int beep_overloaded;
bool beep_overloaded;
long lastbeep;
#define TTYPE termchar
@ -97,29 +97,29 @@ struct terminal_tag {
pos curs; /* cursor */
pos savecurs; /* saved cursor position */
int marg_t, marg_b; /* scroll margins */
int dec_om; /* DEC origin mode flag */
int wrap, wrapnext; /* wrap flags */
int insert; /* insert-mode flag */
bool dec_om; /* DEC origin mode flag */
bool wrap, wrapnext; /* wrap flags */
bool insert; /* insert-mode flag */
int cset; /* 0 or 1: which char set */
int save_cset, save_csattr; /* saved with cursor position */
int save_utf, save_wnext; /* saved with cursor position */
int rvideo; /* global reverse video flag */
bool save_utf, save_wnext; /* saved with cursor position */
bool rvideo; /* global reverse video flag */
unsigned long rvbell_startpoint; /* for ESC[?5hESC[?5l vbell */
int cursor_on; /* cursor enabled flag */
int reset_132; /* Flag ESC c resets to 80 cols */
int use_bce; /* Use Background coloured erase */
int cblinker; /* When blinking is the cursor on ? */
int tblinker; /* When the blinking text is on */
int blink_is_real; /* Actually blink blinking text */
int term_echoing; /* Does terminal want local echo? */
int term_editing; /* Does terminal want local edit? */
bool cursor_on; /* cursor enabled flag */
bool reset_132; /* Flag ESC c resets to 80 cols */
bool use_bce; /* Use Background coloured erase */
bool cblinker; /* When blinking is the cursor on ? */
bool tblinker; /* When the blinking text is on */
bool blink_is_real; /* Actually blink blinking text */
bool term_echoing; /* Does terminal want local echo? */
bool term_editing; /* Does terminal want local edit? */
int sco_acs, save_sco_acs; /* CSI 10,11,12m -> OEM charset */
int vt52_bold; /* Force bold on non-bold colours */
int utf; /* Are we in toggleable UTF-8 mode? */
bool vt52_bold; /* Force bold on non-bold colours */
bool utf; /* Are we in toggleable UTF-8 mode? */
int utf_state; /* Is there a pending UTF-8 character */
int utf_char; /* and what is it so far. */
int utf_size; /* The size of the UTF character. */
int printing, only_printing; /* Are we doing ANSI printing? */
bool printing, only_printing; /* Are we doing ANSI printing? */
int print_state; /* state of print-end-sequence scan */
bufchain printer_buf; /* buffered data for printer */
printer_job *print_job;
@ -129,32 +129,36 @@ struct terminal_tag {
int alt_save_attr;
truecolour alt_save_truecolour;
int alt_save_cset, alt_save_csattr;
int alt_save_utf, alt_save_wnext;
bool alt_save_utf;
bool alt_save_wnext;
int alt_save_sco_acs;
int rows, cols, savelines;
int has_focus;
int in_vbell;
bool has_focus;
bool in_vbell;
long vbell_end;
int app_cursor_keys, app_keypad_keys, vt52_mode;
int repeat_off, cr_lf_return;
int seen_disp_event;
int big_cursor;
bool app_cursor_keys, app_keypad_keys, vt52_mode;
bool repeat_off, cr_lf_return;
bool seen_disp_event;
bool big_cursor;
int xterm_mouse; /* send mouse messages to host */
int xterm_extended_mouse;
int urxvt_extended_mouse;
bool xterm_extended_mouse;
bool urxvt_extended_mouse;
int mouse_is_down; /* used while tracking mouse buttons */
int bracketed_paste;
bool bracketed_paste;
int cset_attr[2];
/*
* Saved settings on the alternate screen.
*/
int alt_x, alt_y, alt_om, alt_wrap, alt_wnext, alt_ins;
int alt_cset, alt_sco_acs, alt_utf;
int alt_x, alt_y;
bool alt_wnext, alt_ins;
bool alt_om, alt_wrap;
int alt_cset, alt_sco_acs;
bool alt_utf;
int alt_t, alt_b;
int alt_which;
int alt_sblines; /* # of lines on alternate screen that should be used for scrollback. */
@ -166,12 +170,12 @@ struct terminal_tag {
int esc_nargs;
int esc_query;
#define ANSI(x,y) ((x)+((y)<<8))
#define ANSI_QUE(x) ANSI(x,true)
#define ANSI_QUE(x) ANSI(x,1)
#define OSC_STR_MAX 2048
int osc_strlen;
char osc_string[OSC_STR_MAX + 1];
int osc_w;
bool osc_w;
char id_string[1024];
@ -243,19 +247,19 @@ struct terminal_tag {
* data to the end of the buffer term_out is in the process of
* working through.
*/
int in_term_out;
bool in_term_out;
/*
* We schedule a window update shortly after receiving terminal
* data. This tracks whether one is currently pending.
*/
int window_update_pending;
bool window_update_pending;
long next_update;
/*
* Track pending blinks and tblinks.
*/
int tblink_pending, cblink_pending;
bool tblink_pending, cblink_pending;
long next_tblink, next_cblink;
/*
@ -274,48 +278,48 @@ struct terminal_tag {
* tree234 lookups which would be involved in fetching them from
* the former every time.
*/
int ansi_colour;
bool ansi_colour;
char *answerback;
int answerbacklen;
int arabicshaping;
bool arabicshaping;
int beep;
int bellovl;
bool bellovl;
int bellovl_n;
int bellovl_s;
int bellovl_t;
int bidi;
int bksp_is_delete;
int blink_cur;
int blinktext;
int cjk_ambig_wide;
bool bidi;
bool bksp_is_delete;
bool blink_cur;
bool blinktext;
bool cjk_ambig_wide;
int conf_height;
int conf_width;
int crhaslf;
int erase_to_scrollback;
bool crhaslf;
bool erase_to_scrollback;
int funky_type;
int lfhascr;
int logflush;
bool lfhascr;
bool logflush;
int logtype;
int mouse_override;
int nethack_keypad;
int no_alt_screen;
int no_applic_c;
int no_applic_k;
int no_dbackspace;
int no_mouse_rep;
int no_remote_charset;
int no_remote_resize;
int no_remote_wintitle;
int no_remote_clearscroll;
int rawcnp;
int utf8linedraw;
int rect_select;
bool mouse_override;
bool nethack_keypad;
bool no_alt_screen;
bool no_applic_c;
bool no_applic_k;
bool no_dbackspace;
bool no_mouse_rep;
bool no_remote_charset;
bool no_remote_resize;
bool no_remote_wintitle;
bool no_remote_clearscroll;
bool rawcnp;
bool utf8linedraw;
bool rect_select;
int remote_qtitle_action;
int rxvt_homeend;
int scroll_on_disp;
int scroll_on_key;
int xterm_256_colour;
int true_colour;
bool rxvt_homeend;
bool scroll_on_disp;
bool scroll_on_key;
bool xterm_256_colour;
bool true_colour;
wchar_t *last_selected_text;
int *last_selected_attr;

View File

@ -37,7 +37,7 @@ void queue_idempotent_callback(IdempotentCallback *ic) { assert(0); }
#define fromxdigit(c) ( (c)>'9' ? ((c)&0xDF) - 'A' + 10 : (c) - '0' )
/* For Unix in particular, but harmless if this main() is reused elsewhere */
const int buildinfo_gtk_relevant = false;
const bool buildinfo_gtk_relevant = false;
int main(int argc, char **argv)
{
@ -201,7 +201,7 @@ int main(int argc, char **argv)
freebn(answer);
} else if (!strcmp(buf, "divmod")) {
Bignum n, d, expect_q, expect_r, answer_q, answer_r;
int fail;
bool fail;
if (ptrnum != 4) {
printf("%d: divmod with %d parameters, expected 4\n", line, ptrnum);

View File

@ -164,7 +164,7 @@ unsigned long timing_last_clock(void)
* Returns the time (in ticks) expected until the next timer after
* that triggers.
*/
int run_timers(unsigned long anow, unsigned long *next)
bool run_timers(unsigned long anow, unsigned long *next)
{
struct timer *first;

View File

@ -29,6 +29,7 @@
#include <stdlib.h>
#include <assert.h>
#include "defs.h"
#include "tree234.h"
#ifdef TEST
@ -529,7 +530,7 @@ void *findrelpos234(tree234 * t, void *e, cmpfn234 cmp,
search234_state ss;
int reldir = (relation == REL234_LT || relation == REL234_LE ? -1 :
relation == REL234_GT || relation == REL234_GE ? +1 : 0);
int equal_permitted = (relation != REL234_LT && relation != REL234_GT);
bool equal_permitted = (relation != REL234_LT && relation != REL234_GT);
void *toret;
/* Only LT / GT relations are permitted with a null query element. */

View File

@ -88,7 +88,7 @@ https://wiki.gnome.org/Projects/GTK%2B/OSX/Bundling has some links.
char *x_get_default(const char *key) { return NULL; }
const int buildinfo_gtk_relevant = true;
const bool buildinfo_gtk_relevant = true;
#if !GTK_CHECK_VERSION(3,0,0)
/* This front end only works in GTK 3. If that's not what we've got,
@ -107,7 +107,7 @@ void session_window_closed(void) {}
void window_setup_error(const char *errmsg) {}
#else /* GTK_CHECK_VERSION(3,0,0) */
extern const int use_event_log;
extern const bool use_event_log;
static void startup(GApplication *app, gpointer user_data)
{
@ -216,7 +216,7 @@ GtkWidget *make_gtk_toplevel_window(GtkFrontend *frontend)
void launch_duplicate_session(Conf *conf)
{
extern const int dup_check_launchable;
extern const bool dup_check_launchable;
assert(!dup_check_launchable || conf_launchable(conf));
g_application_hold(G_APPLICATION(app));
new_session_window(conf_copy(conf), NULL);
@ -318,7 +318,7 @@ int main(int argc, char **argv)
{
/* Call the function in ux{putty,pterm}.c to do app-type
* specific setup */
extern void setup(int);
extern void setup(bool);
setup(false); /* false means we are not a one-session process */
}

View File

@ -14,6 +14,7 @@
#include <gdk/gdkkeysyms.h>
#endif
#include "defs.h"
#include "gtkfont.h"
#include "gtkcompat.h"
#include "gtkmisc.h"
@ -501,13 +502,13 @@ static void gtk_askpass_cleanup(struct askpass_ctx *ctx)
gtk_widget_destroy(ctx->dialog);
}
static int setup_gtk(const char *display)
static bool setup_gtk(const char *display)
{
static int gtk_initialised = false;
static bool gtk_initialised = false;
int argc;
char *real_argv[3];
char **argv = real_argv;
int ret;
bool ret;
if (gtk_initialised)
return true;
@ -524,10 +525,10 @@ static int setup_gtk(const char *display)
return ret;
}
const int buildinfo_gtk_relevant = true;
const bool buildinfo_gtk_relevant = true;
char *gtk_askpass_main(const char *display, const char *wintitle,
const char *prompt, int *success)
const char *prompt, bool *success)
{
struct askpass_ctx actx, *ctx = &actx;
const char *err;
@ -571,7 +572,8 @@ void modalfatalbox(const char *p, ...)
int main(int argc, char **argv)
{
int success, exitcode;
bool success;
int exitcode;
char *ret;
gtk_init(&argc, &argv);

View File

@ -18,7 +18,7 @@ static void about_handler(union control *ctrl, dlgparam *dlg,
}
}
void gtk_setup_config_box(struct controlbox *b, int midsession, void *win)
void gtk_setup_config_box(struct controlbox *b, bool midsession, void *win)
{
struct controlset *s, *s2;
union control *c;

View File

@ -331,7 +331,7 @@ static void columns_remove(GtkContainer *container, GtkWidget *widget)
ColumnsChild *child;
GtkWidget *childw;
GList *children;
gboolean was_visible;
bool was_visible;
g_return_if_fail(container != NULL);
g_return_if_fail(IS_COLUMNS(container));

View File

@ -41,7 +41,7 @@ struct ColumnsChild_tag {
/* If `widget' is non-NULL, this entry represents an actual widget. */
GtkWidget *widget;
gint colstart, colspan;
gboolean force_left; /* for recalcitrant GtkLabels */
bool force_left; /* for recalcitrant GtkLabels */
ColumnsChild *same_height_as;
/* Otherwise, this entry represents a change in the column setup. */
gint ncols;

View File

@ -199,7 +199,7 @@ void timer_change_notify(unsigned long next)
*/
static guint toplevel_callback_idle_id;
static int idle_fn_scheduled;
static bool idle_fn_scheduled;
static void notify_toplevel_callback(void *);

View File

@ -79,7 +79,10 @@ struct uctrl {
struct dlgparam {
tree234 *byctrl, *bywidget;
void *data;
struct { unsigned char r, g, b, ok; } coloursel_result; /* 0-255 */
struct {
unsigned char r, g, b; /* 0-255 */
bool ok;
} coloursel_result;
/* `flags' are set to indicate when a GTK signal handler is being called
* due to automatic processing and should not flag a user event. */
int flags;
@ -281,14 +284,14 @@ int dlg_radiobutton_get(union control *ctrl, dlgparam *dp)
return 0; /* got to return something */
}
void dlg_checkbox_set(union control *ctrl, dlgparam *dp, int checked)
void dlg_checkbox_set(union control *ctrl, dlgparam *dp, bool checked)
{
struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
assert(uc->ctrl->generic.type == CTRL_CHECKBOX);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(uc->toplevel), checked);
}
int dlg_checkbox_get(union control *ctrl, dlgparam *dp)
bool dlg_checkbox_get(union control *ctrl, dlgparam *dp)
{
struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
assert(uc->ctrl->generic.type == CTRL_CHECKBOX);
@ -707,7 +710,7 @@ int dlg_listbox_index(union control *ctrl, dlgparam *dp)
return -1; /* placate dataflow analysis */
}
int dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index)
bool dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index)
{
struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
@ -748,7 +751,7 @@ int dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index)
if (uc->treeview) {
GtkTreeSelection *treesel;
GtkTreePath *path;
int ret;
bool ret;
assert(uc->treeview != NULL);
treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(uc->treeview));
@ -761,7 +764,7 @@ int dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index)
}
#endif
assert(!"We shouldn't get here");
return -1; /* placate dataflow analysis */
return false; /* placate dataflow analysis */
}
void dlg_listbox_select(union control *ctrl, dlgparam *dp, int index)
@ -790,7 +793,7 @@ void dlg_listbox_select(union control *ctrl, dlgparam *dp, int index)
items = gtk_container_children(GTK_CONTAINER(uc->list));
nitems = g_list_length(items);
if (nitems > 0) {
int modified = false;
bool modified = false;
g_list_free(items);
newtop = uc->adj->lower +
(uc->adj->upper - uc->adj->lower) * index / nitems;
@ -1181,16 +1184,16 @@ void dlg_coloursel_start(union control *ctrl, dlgparam *dp, int r, int g, int b)
gtk_widget_show(coloursel);
}
int dlg_coloursel_results(union control *ctrl, dlgparam *dp,
int *r, int *g, int *b)
bool dlg_coloursel_results(union control *ctrl, dlgparam *dp,
int *r, int *g, int *b)
{
if (dp->coloursel_result.ok) {
*r = dp->coloursel_result.r;
*g = dp->coloursel_result.g;
*b = dp->coloursel_result.b;
return 1;
return true;
} else
return 0;
return false;
}
/* ----------------------------------------------------------------------
@ -1279,7 +1282,7 @@ static gboolean editbox_lostfocus(GtkWidget *ed, GdkEventFocus *event,
*/
static gboolean listitem_key(GtkWidget *item, GdkEventKey *event,
gpointer data, int multiple)
gpointer data, bool multiple)
{
GtkAdjustment *adj = GTK_ADJUSTMENT(data);
@ -1877,7 +1880,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs,
for (i = 0; i < s->ncontrols; i++) {
union control *ctrl = s->ctrls[i];
struct uctrl *uc;
int left = false;
bool left = false;
GtkWidget *w = NULL;
switch (ctrl->generic.type) {
@ -2555,7 +2558,7 @@ static void treeitem_sel(GtkItem *item, gpointer data)
#endif
#if !GTK_CHECK_VERSION(2,0,0)
static int tree_grab_focus(struct dlgparam *dp)
static bool tree_grab_focus(struct dlgparam *dp)
{
int i, f;
@ -2592,7 +2595,7 @@ gint tree_focus(GtkContainer *container, GtkDirectionType direction,
}
#endif
int win_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
gint win_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
struct dlgparam *dp = (struct dlgparam *)data;
@ -2717,7 +2720,7 @@ int win_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
}
#if !GTK_CHECK_VERSION(2,0,0)
int tree_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
gint tree_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
struct dlgparam *dp = (struct dlgparam *)data;
@ -2742,7 +2745,7 @@ int tree_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
*/
{
GtkWidget *w = dp->treeitems[i];
int vis = true;
bool vis = true;
while (w && (GTK_IS_TREE_ITEM(w) || GTK_IS_TREE(w))) {
if (!GTK_WIDGET_VISIBLE(w)) {
vis = false;
@ -2893,7 +2896,7 @@ void treeview_map_event(GtkWidget *tree, gpointer data)
#endif
GtkWidget *create_config_box(const char *title, Conf *conf,
int midsession, int protcfginfo,
bool midsession, int protcfginfo,
post_dialog_fn_t after, void *afterctx)
{
GtkWidget *window, *hbox, *vbox, *cols, *label,
@ -2999,7 +3002,7 @@ GtkWidget *create_config_box(const char *title, Conf *conf,
#else
GtkWidget *treeitem;
#endif
int first;
bool first;
/*
* We expect never to find an implicit path
@ -3213,7 +3216,7 @@ GtkWidget *create_config_box(const char *title, Conf *conf,
*/
for (index = 0; index < dp->ctrlbox->nctrlsets; index++) {
struct controlset *s = dp->ctrlbox->ctrlsets[index];
int done = 0;
bool done = false;
int j;
if (*s->pathname) {
@ -3223,7 +3226,7 @@ GtkWidget *create_config_box(const char *title, Conf *conf,
s->ctrls[j]->generic.type != CTRL_TEXT) {
dlg_set_focus(s->ctrls[j], dp);
dp->lastfocus = s->ctrls[j];
done = 1;
done = true;
break;
}
}
@ -3280,7 +3283,7 @@ const struct message_box_buttons buttons_ok = {
GtkWidget *create_message_box(
GtkWidget *parentwin, const char *title, const char *msg, int minwid,
int selectable, const struct message_box_buttons *buttons,
bool selectable, const struct message_box_buttons *buttons,
post_dialog_fn_t after, void *afterctx)
{
GtkWidget *window, *w0, *w1;
@ -3770,7 +3773,7 @@ struct eventlog_stuff {
int ninitial, ncircular, circular_first;
char *seldata;
int sellen;
int ignore_selchange;
bool ignore_selchange;
};
static void eventlog_destroy(GtkWidget *widget, gpointer data)
@ -3887,7 +3890,7 @@ gint eventlog_selection_clear(GtkWidget *widget, GdkEventSelection *seldata,
* Deselect everything in the list box.
*/
uc = dlg_find_byctrl(&es->dp, es->listctrl);
es->ignore_selchange = 1;
es->ignore_selchange = true;
#if !GTK_CHECK_VERSION(2,0,0)
assert(uc->list);
gtk_list_unselect_all(GTK_LIST(uc->list));
@ -3896,7 +3899,7 @@ gint eventlog_selection_clear(GtkWidget *widget, GdkEventSelection *seldata,
gtk_tree_selection_unselect_all
(gtk_tree_view_get_selection(GTK_TREE_VIEW(uc->treeview)));
#endif
es->ignore_selchange = 0;
es->ignore_selchange = false;
sfree(es->seldata);
es->sellen = 0;

View File

@ -73,22 +73,23 @@ struct UnifontVtable {
/*
* `Methods' of the `class'.
*/
unifont *(*create)(GtkWidget *widget, const char *name, int wide, int bold,
int shadowoffset, int shadowalways);
unifont *(*create_fallback)(GtkWidget *widget, int height, int wide,
int bold, int shadowoffset, int shadowalways);
unifont *(*create)(GtkWidget *widget, const char *name, bool wide,
bool bold, int shadowoffset, bool shadowalways);
unifont *(*create_fallback)(GtkWidget *widget, int height, bool wide,
bool bold, int shadowoffset,
bool shadowalways);
void (*destroy)(unifont *font);
int (*has_glyph)(unifont *font, wchar_t glyph);
bool (*has_glyph)(unifont *font, wchar_t glyph);
void (*draw_text)(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth);
bool wide, bool bold, int cellwidth);
void (*draw_combining)(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth);
bool wide, bool bold, int cellwidth);
void (*enum_fonts)(GtkWidget *widget,
fontsel_add_entry callback, void *callback_ctx);
char *(*canonify_fontname)(GtkWidget *widget, const char *name, int *size,
int *flags, int resolve_aliases);
int *flags, bool resolve_aliases);
char *(*scale_fontname)(GtkWidget *widget, const char *name, int size);
char *(*size_increment)(unifont *font, int increment);
@ -106,22 +107,23 @@ struct UnifontVtable {
* back end other than X).
*/
static int x11font_has_glyph(unifont *font, wchar_t glyph);
static bool x11font_has_glyph(unifont *font, wchar_t glyph);
static void x11font_draw_text(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth);
bool wide, bool bold, int cellwidth);
static void x11font_draw_combining(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string,
int len, int wide, int bold, int cellwidth);
int len, bool wide, bool bold,
int cellwidth);
static unifont *x11font_create(GtkWidget *widget, const char *name,
int wide, int bold,
int shadowoffset, int shadowalways);
bool wide, bool bold,
int shadowoffset, bool shadowalways);
static void x11font_destroy(unifont *font);
static void x11font_enum_fonts(GtkWidget *widget,
fontsel_add_entry callback, void *callback_ctx);
static char *x11font_canonify_fontname(GtkWidget *widget, const char *name,
int *size, int *flags,
int resolve_aliases);
bool resolve_aliases);
static char *x11font_scale_fontname(GtkWidget *widget, const char *name,
int size);
static char *x11font_size_increment(unifont *font, int increment);
@ -147,7 +149,7 @@ typedef struct x11font_individual {
* haven't tried yet from xfs==NULL because we tried and failed,
* so that we don't keep trying and failing subsequently).
*/
int allocated;
bool allocated;
#ifdef DRAW_TEXT_CAIRO
/*
@ -190,13 +192,13 @@ struct x11font {
* values larger than a byte. That is, this flag tells us
* whether we use XDrawString or XDrawString16, etc.
*/
int sixteen_bit;
bool sixteen_bit;
/*
* `variable' is true iff the font is non-fixed-pitch. This
* enables some code which takes greater care over character
* positioning during text drawing.
*/
int variable;
bool variable;
/*
* real_charset is the charset used when translating text into the
* font's internal encoding inside draw_text(). This need not be
@ -208,7 +210,8 @@ struct x11font {
/*
* Data passed in to unifont_create().
*/
int wide, bold, shadowoffset, shadowalways;
int shadowoffset;
bool wide, bold, shadowalways;
unifont u;
};
@ -312,7 +315,7 @@ static char *xlfd_recompose(const struct xlfd_decomposed *dec)
}
static char *x11_guess_derived_font_name(Display *disp, XFontStruct *xfs,
int bold, int wide)
bool bold, bool wide)
{
Atom fontprop = XInternAtom(disp, "FONT", False);
unsigned long ret;
@ -343,7 +346,7 @@ static char *x11_guess_derived_font_name(Display *disp, XFontStruct *xfs,
return NULL;
}
static int x11_font_width(XFontStruct *xfs, int sixteen_bit)
static int x11_font_width(XFontStruct *xfs, bool sixteen_bit)
{
if (sixteen_bit) {
XChar2b space;
@ -406,7 +409,7 @@ static const XCharStruct *x11_char_struct(
return &xfs->per_char[index];
}
static int x11_font_has_glyph(
static bool x11_font_has_glyph(
XFontStruct *xfs, unsigned char byte1, unsigned char byte2)
{
/*
@ -426,15 +429,16 @@ static int x11_font_has_glyph(
}
static unifont *x11font_create(GtkWidget *widget, const char *name,
int wide, int bold,
int shadowoffset, int shadowalways)
bool wide, bool bold,
int shadowoffset, bool shadowalways)
{
struct x11font *xfont;
XFontStruct *xfs;
Display *disp;
Atom charset_registry, charset_encoding, spacing;
unsigned long registry_ret, encoding_ret, spacing_ret;
int pubcs, realcs, sixteen_bit, variable;
int pubcs, realcs;
bool sixteen_bit, variable;
int i;
if ((disp = get_x11_display()) == NULL)
@ -577,7 +581,7 @@ static void x11_alloc_subfont(struct x11font *xfont, int sfid)
/* Note that xfont->fonts[sfid].xfs may still be NULL, if XLQF failed. */
}
static int x11font_has_glyph(unifont *font, wchar_t glyph)
static bool x11font_has_glyph(unifont *font, wchar_t glyph)
{
struct x11font *xfont = container_of(font, struct x11font, u);
@ -851,9 +855,10 @@ static void x11font_really_draw_text(
const struct x11font_drawfuncs *dfns, unifont_drawctx *ctx,
x11font_individual *xfi, Display *disp,
int x, int y, const void *string, int nchars,
int shadowoffset, int fontvariable, int cellwidth)
int shadowoffset, bool fontvariable, int cellwidth)
{
int start = 0, step, nsteps, centre;
int start = 0, step, nsteps;
bool centre;
if (fontvariable) {
/*
@ -891,7 +896,7 @@ static void x11font_really_draw_text(
static void x11font_draw_text(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth)
bool wide, bool bold, int cellwidth)
{
struct x11font *xfont = container_of(font, struct x11font, u);
int sfid;
@ -899,8 +904,8 @@ static void x11font_draw_text(unifont_drawctx *ctx, unifont *font,
int mult = (wide ? 2 : 1);
int index = 2 * (int)ctx->type;
wide -= xfont->wide;
bold -= xfont->bold;
wide = wide && !xfont->wide;
bold = bold && !xfont->bold;
/*
* Decide which subfont we're using, and whether we have to
@ -908,13 +913,13 @@ static void x11font_draw_text(unifont_drawctx *ctx, unifont *font,
*/
if (xfont->shadowalways && bold) {
shadowoffset = xfont->shadowoffset;
bold = 0;
bold = false;
}
sfid = 2 * wide + bold;
if (!xfont->fonts[sfid].allocated)
x11_alloc_subfont(xfont, sfid);
if (bold && !xfont->fonts[sfid].xfs) {
bold = 0;
bold = false;
shadowoffset = xfont->shadowoffset;
sfid = 2 * wide + bold;
if (!xfont->fonts[sfid].allocated)
@ -961,7 +966,8 @@ static void x11font_draw_text(unifont_drawctx *ctx, unifont *font,
static void x11font_draw_combining(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string,
int len, int wide, int bold, int cellwidth)
int len, bool wide, bool bold,
int cellwidth)
{
/*
* For server-side fonts, there's no sophisticated system for
@ -1138,7 +1144,7 @@ static void x11font_enum_fonts(GtkWidget *widget,
static char *x11font_canonify_fontname(GtkWidget *widget, const char *name,
int *size, int *flags,
int resolve_aliases)
bool resolve_aliases)
{
/*
* When given an X11 font name to try to make sense of for a
@ -1298,26 +1304,26 @@ static char *x11font_size_increment(unifont *font, int increment)
#define PANGO_PRE_1POINT6 /* make life easier for pre-1.4 folk */
#endif
static int pangofont_has_glyph(unifont *font, wchar_t glyph);
static bool pangofont_has_glyph(unifont *font, wchar_t glyph);
static void pangofont_draw_text(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth);
bool wide, bool bold, int cellwidth);
static void pangofont_draw_combining(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string,
int len, int wide, int bold,
int len, bool wide, bool bold,
int cellwidth);
static unifont *pangofont_create(GtkWidget *widget, const char *name,
int wide, int bold,
int shadowoffset, int shadowalways);
bool wide, bool bold,
int shadowoffset, bool shadowalways);
static unifont *pangofont_create_fallback(GtkWidget *widget, int height,
int wide, int bold,
int shadowoffset, int shadowalways);
bool wide, bool bold,
int shadowoffset, bool shadowalways);
static void pangofont_destroy(unifont *font);
static void pangofont_enum_fonts(GtkWidget *widget, fontsel_add_entry callback,
void *callback_ctx);
static char *pangofont_canonify_fontname(GtkWidget *widget, const char *name,
int *size, int *flags,
int resolve_aliases);
bool resolve_aliases);
static char *pangofont_scale_fontname(GtkWidget *widget, const char *name,
int size);
static char *pangofont_size_increment(unifont *font, int increment);
@ -1335,7 +1341,8 @@ struct pangofont {
/*
* Data passed in to unifont_create().
*/
int bold, shadowoffset, shadowalways;
int shadowoffset;
bool bold, shadowalways;
/*
* Cache of character widths, indexed by Unicode code point. In
* pixels; -1 means we haven't asked Pango about this character
@ -1374,14 +1381,15 @@ static const struct UnifontVtable pangofont_vtable = {
* if it doesn't. So we check that the font family is actually one
* supported by Pango.
*/
static int pangofont_check_desc_makes_sense(PangoContext *ctx,
PangoFontDescription *desc)
static bool pangofont_check_desc_makes_sense(PangoContext *ctx,
PangoFontDescription *desc)
{
#ifndef PANGO_PRE_1POINT6
PangoFontMap *map;
#endif
PangoFontFamily **families;
int i, nfamilies, matched;
int i, nfamilies;
bool matched;
/*
* Ask Pango for a list of font families, and iterate through
@ -1413,8 +1421,8 @@ static int pangofont_check_desc_makes_sense(PangoContext *ctx,
static unifont *pangofont_create_internal(GtkWidget *widget,
PangoContext *ctx,
PangoFontDescription *desc,
int wide, int bold,
int shadowoffset, int shadowalways)
bool wide, bool bold,
int shadowoffset, bool shadowalways)
{
struct pangofont *pfont;
#ifndef PANGO_PRE_1POINT6
@ -1479,8 +1487,8 @@ static unifont *pangofont_create_internal(GtkWidget *widget,
}
static unifont *pangofont_create(GtkWidget *widget, const char *name,
int wide, int bold,
int shadowoffset, int shadowalways)
bool wide, bool bold,
int shadowoffset, bool shadowalways)
{
PangoContext *ctx;
PangoFontDescription *desc;
@ -1502,8 +1510,8 @@ static unifont *pangofont_create(GtkWidget *widget, const char *name,
}
static unifont *pangofont_create_fallback(GtkWidget *widget, int height,
int wide, int bold,
int shadowoffset, int shadowalways)
bool wide, bool bold,
int shadowoffset, bool shadowalways)
{
PangoContext *ctx;
PangoFontDescription *desc;
@ -1559,7 +1567,7 @@ static int pangofont_char_width(PangoLayout *layout, struct pangofont *pfont,
return pfont->widthcache[uchr];
}
static int pangofont_has_glyph(unifont *font, wchar_t glyph)
static bool pangofont_has_glyph(unifont *font, wchar_t glyph)
{
/* Pango implements font fallback, so assume it has everything */
return true;
@ -1584,15 +1592,15 @@ static void pango_cairo_draw_layout(unifont_drawctx *ctx,
static void pangofont_draw_internal(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string,
int len, int wide, int bold, int cellwidth,
int combining)
int len, bool wide, bool bold,
int cellwidth, bool combining)
{
struct pangofont *pfont = container_of(font, struct pangofont, u);
PangoLayout *layout;
PangoRectangle rect;
char *utfstring, *utfptr;
int utflen;
int shadowbold = false;
bool shadowbold = false;
void (*draw_layout)(unifont_drawctx *ctx,
gint x, gint y, PangoLayout *layout) = NULL;
@ -1614,7 +1622,7 @@ static void pangofont_draw_internal(unifont_drawctx *ctx, unifont *font,
layout = pango_layout_new(gtk_widget_get_pango_context(pfont->widget));
pango_layout_set_font_description(layout, pfont->desc);
if (bold > pfont->bold) {
if (bold && !pfont->bold) {
if (pfont->shadowalways)
shadowbold = true;
else {
@ -1740,7 +1748,7 @@ static void pangofont_draw_internal(unifont_drawctx *ctx, unifont *font,
static void pangofont_draw_text(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth)
bool wide, bool bold, int cellwidth)
{
pangofont_draw_internal(ctx, font, x, y, string, len, wide, bold,
cellwidth, false);
@ -1748,7 +1756,7 @@ static void pangofont_draw_text(unifont_drawctx *ctx, unifont *font,
static void pangofont_draw_combining(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string,
int len, int wide, int bold,
int len, bool wide, bool bold,
int cellwidth)
{
wchar_t *tmpstring = NULL;
@ -1932,7 +1940,7 @@ static void pangofont_enum_fonts(GtkWidget *widget, fontsel_add_entry callback,
static char *pangofont_canonify_fontname(GtkWidget *widget, const char *name,
int *size, int *flags,
int resolve_aliases)
bool resolve_aliases)
{
/*
* When given a Pango font name to try to make sense of for a
@ -2112,8 +2120,8 @@ static const char *unifont_do_prefix(const char *name, int *start, int *end)
}
}
unifont *unifont_create(GtkWidget *widget, const char *name, int wide,
int bold, int shadowoffset, int shadowalways)
unifont *unifont_create(GtkWidget *widget, const char *name, bool wide,
bool bold, int shadowoffset, bool shadowalways)
{
int i, start, end;
@ -2135,14 +2143,14 @@ void unifont_destroy(unifont *font)
void unifont_draw_text(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth)
bool wide, bool bold, int cellwidth)
{
font->vt->draw_text(ctx, font, x, y, string, len, wide, bold, cellwidth);
}
void unifont_draw_combining(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth)
bool wide, bool bold, int cellwidth)
{
font->vt->draw_combining(ctx, font, x, y, string, len, wide, bold,
cellwidth);
@ -2168,10 +2176,10 @@ char *unifont_size_increment(unifont *font, int increment)
static void multifont_draw_text(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth);
bool wide, bool bold, int cellwidth);
static void multifont_draw_combining(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string,
int len, int wide, int bold,
int len, bool wide, bool bold,
int cellwidth);
static void multifont_destroy(unifont *font);
static char *multifont_size_increment(unifont *font, int increment);
@ -2198,8 +2206,8 @@ static const struct UnifontVtable multifont_vtable = {
};
unifont *multifont_create(GtkWidget *widget, const char *name,
int wide, int bold,
int shadowoffset, int shadowalways)
bool wide, bool bold,
int shadowoffset, bool shadowalways)
{
int i;
unifont *font, *fallback;
@ -2253,17 +2261,18 @@ static void multifont_destroy(unifont *font)
typedef void (*unifont_draw_func_t)(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string,
int len, int wide, int bold,
int len, bool wide, bool bold,
int cellwidth);
static void multifont_draw_main(unifont_drawctx *ctx, unifont *font, int x,
int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth,
bool wide, bool bold, int cellwidth,
int cellinc, unifont_draw_func_t draw)
{
struct multifont *mfont = container_of(font, struct multifont, u);
unifont *f;
int ok, i;
bool ok;
int i;
while (len > 0) {
/*
@ -2290,7 +2299,7 @@ static void multifont_draw_main(unifont_drawctx *ctx, unifont *font, int x,
static void multifont_draw_text(unifont_drawctx *ctx, unifont *font, int x,
int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth)
bool wide, bool bold, int cellwidth)
{
multifont_draw_main(ctx, font, x, y, string, len, wide, bold,
cellwidth, cellwidth, unifont_draw_text);
@ -2298,7 +2307,7 @@ static void multifont_draw_text(unifont_drawctx *ctx, unifont *font, int x,
static void multifont_draw_combining(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string,
int len, int wide, int bold,
int len, bool wide, bool bold,
int cellwidth)
{
multifont_draw_main(ctx, font, x, y, string, len, wide, bold,
@ -2335,7 +2344,7 @@ typedef struct unifontsel_internal {
tree234 *fonts_by_realname, *fonts_by_selorder;
fontinfo *selected;
int selsize, intendedsize;
int inhibit_response; /* inhibit callbacks when we change GUI controls */
bool inhibit_response; /* inhibit callbacks when we change GUI controls */
unifontsel u;
} unifontsel_internal;
@ -2529,7 +2538,8 @@ static void unifontsel_setup_stylelist(unifontsel_internal *fs,
int start, int end)
{
GtkTreeIter iter;
int i, listindex, minpos = -1, maxpos = -1, started = false;
int i, listindex, minpos = -1, maxpos = -1;
bool started = false;
char *currcs = NULL, *currstyle = NULL;
fontinfo *info;
@ -2808,7 +2818,7 @@ static void unifontsel_draw_preview_text(unifontsel_internal *fs)
static void unifontsel_select_font(unifontsel_internal *fs,
fontinfo *info, int size, int leftlist,
int size_is_explicit)
bool size_is_explicit)
{
int index;
int minval, maxval;
@ -2946,7 +2956,7 @@ static void unifontsel_select_font(unifontsel_internal *fs,
static void unifontsel_button_toggled(GtkToggleButton *tb, gpointer data)
{
unifontsel_internal *fs = (unifontsel_internal *)data;
int newstate = gtk_toggle_button_get_active(tb);
bool newstate = gtk_toggle_button_get_active(tb);
int newflags;
int flagbit = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(tb),
"user-data"));

View File

@ -74,7 +74,7 @@ typedef struct unifont {
* missing glyphs from other fonts), or whether it would like a
* fallback font to cope with missing glyphs.
*/
int want_fallback;
bool want_fallback;
/*
* Preferred drawing API to use when this class of font is active.
@ -134,18 +134,18 @@ typedef struct unifont_drawctx {
} unifont_drawctx;
unifont *unifont_create(GtkWidget *widget, const char *name,
int wide, int bold,
int shadowoffset, int shadowalways);
bool wide, bool bold,
int shadowoffset, bool shadowalways);
void unifont_destroy(unifont *font);
void unifont_draw_text(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth);
bool wide, bool bold, int cellwidth);
/* Same as unifont_draw_text, but expects 'string' to contain one
* normal char plus combining chars, and overdraws them all in the
* same character cell. */
void unifont_draw_combining(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth);
bool wide, bool bold, int cellwidth);
/* Return a name that will select a bigger/smaller font than this one,
* or NULL if no such name is available. */
char *unifont_size_increment(unifont *font, int increment);
@ -159,8 +159,8 @@ char *unifont_size_increment(unifont *font, int increment);
* as if it were an ordinary unifont.
*/
unifont *multifont_create(GtkWidget *widget, const char *name,
int wide, int bold,
int shadowoffset, int shadowalways);
bool wide, bool bold,
int shadowoffset, bool shadowalways);
/*
* Unified font selector dialog. I can't be bothered to do a

View File

@ -48,7 +48,7 @@ static char *progname, **gtkargvstart;
static int ngtkargs;
extern char **pty_argv; /* declared in pty.c */
extern int use_pty_argv;
extern bool use_pty_argv;
static const char *app_name = "pterm";
@ -312,9 +312,9 @@ void window_setup_error(const char *errmsg)
exit(1);
}
int do_cmdline(int argc, char **argv, int do_everything, Conf *conf)
bool do_cmdline(int argc, char **argv, bool do_everything, Conf *conf)
{
int err = 0;
bool err = false;
char *val;
/*
@ -327,7 +327,7 @@ int do_cmdline(int argc, char **argv, int do_everything, Conf *conf)
*/
#define EXPECTS_ARG { \
if (--argc <= 0) { \
err = 1; \
err = true; \
fprintf(stderr, "%s: %s expects an argument\n", appname, p); \
continue; \
} else \
@ -417,14 +417,14 @@ int do_cmdline(int argc, char **argv, int do_everything, Conf *conf)
{
#if GTK_CHECK_VERSION(3,0,0)
GdkRGBA rgba;
int success = gdk_rgba_parse(&rgba, val);
bool success = gdk_rgba_parse(&rgba, val);
#else
GdkColor col;
int success = gdk_color_parse(val, &col);
bool success = gdk_color_parse(val, &col);
#endif
if (!success) {
err = 1;
err = true;
fprintf(stderr, "%s: unable to parse colour \"%s\"\n",
appname, val);
} else {
@ -467,7 +467,7 @@ int do_cmdline(int argc, char **argv, int do_everything, Conf *conf)
pty_argv[argc] = NULL;
break; /* finished command-line processing */
} else
err = 1, fprintf(stderr, "%s: -e expects an argument\n",
err = true, fprintf(stderr, "%s: -e expects an argument\n",
appname);
} else if (!strcmp(p, "-title")) {
@ -535,13 +535,13 @@ int do_cmdline(int argc, char **argv, int do_everything, Conf *conf)
} else if (p[0] != '-') {
/* Non-option arguments not handled by cmdline.c are errors. */
if (do_everything) {
err = 1;
err = true;
fprintf(stderr, "%s: unexpected non-option argument '%s'\n",
appname, p);
}
} else {
err = 1;
err = true;
fprintf(stderr, "%s: unrecognized option '%s'\n", appname, p);
}
}
@ -554,7 +554,7 @@ GtkWidget *make_gtk_toplevel_window(GtkFrontend *frontend)
return gtk_window_new(GTK_WINDOW_TOPLEVEL);
}
const int buildinfo_gtk_relevant = true;
const bool buildinfo_gtk_relevant = true;
struct post_initial_config_box_ctx {
Conf *conf;
@ -586,14 +586,14 @@ void session_window_closed(void)
int main(int argc, char **argv)
{
Conf *conf;
int need_config_box;
bool need_config_box;
setlocale(LC_CTYPE, "");
{
/* Call the function in ux{putty,pterm}.c to do app-type
* specific setup */
extern void setup(int);
extern void setup(bool);
setup(true); /* true means we are a one-session process */
}
@ -623,10 +623,10 @@ int main(int argc, char **argv)
* terminating the main pterm/PuTTY. However, we'll have to
* unblock it again when pterm forks.
*/
block_signal(SIGPIPE, 1);
block_signal(SIGPIPE, true);
if (argc > 1 && !strncmp(argv[1], "---", 3)) {
extern const int dup_check_launchable;
extern const bool dup_check_launchable;
read_dupsession_data(conf, argv[1]);
/* Splatter this argument so it doesn't clutter a ps listing */
@ -635,10 +635,10 @@ int main(int argc, char **argv)
assert(!dup_check_launchable || conf_launchable(conf));
need_config_box = false;
} else {
if (do_cmdline(argc, argv, 0, conf))
if (do_cmdline(argc, argv, false, conf))
exit(1); /* pre-defaults pass to get -class */
do_defaults(NULL, conf);
if (do_cmdline(argc, argv, 1, conf))
if (do_cmdline(argc, argv, true, conf))
exit(1); /* post-defaults, do everything */
cmdline_run_saved(conf);

Some files were not shown because too many files have changed in this diff Show More