* settings.c: read and write saved sessions. (platform-independent)
*/
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "putty.h"
{ "blowfish", CIPHER_BLOWFISH },
{ "3des", CIPHER_3DES },
{ "WARN", CIPHER_WARN },
+ { "arcfour", CIPHER_ARCFOUR },
{ "des", CIPHER_DES }
};
{ "WARN", KEX_WARN }
};
+/*
+ * All the terminal modes that we know about for the "TerminalModes"
+ * setting. (Also used by config.c for the drop-down list.)
+ * This is currently precisely the same as the set in ssh.c, but could
+ * in principle differ if other backends started to support tty modes
+ * (e.g., the pty backend).
+ */
+const char *const ttymodes[] = {
+ "INTR", "QUIT", "ERASE", "KILL", "EOF",
+ "EOL", "EOL2", "START", "STOP", "SUSP",
+ "DSUSP", "REPRINT", "WERASE", "LNEXT", "FLUSH",
+ "SWTCH", "STATUS", "DISCARD", "IGNPAR", "PARMRK",
+ "INPCK", "ISTRIP", "INLCR", "IGNCR", "ICRNL",
+ "IUCLC", "IXON", "IXANY", "IXOFF", "IMAXBEL",
+ "ISIG", "ICANON", "XCASE", "ECHO", "ECHOE",
+ "ECHOK", "ECHONL", "NOFLSH", "TOSTOP", "IEXTEN",
+ "ECHOCTL", "ECHOKE", "PENDIN", "OPOST", "OLCUC",
+ "ONLCR", "OCRNL", "ONOCR", "ONLRET", "CS7",
+ "CS8", "PARENB", "PARODD", NULL
+};
+
static void gpps(void *handle, const char *name, const char *def,
char *val, int len)
{
*i = read_setting_i(handle, name, def);
}
+/*
+ * Read a set of name-value pairs in the format we occasionally use:
+ * NAME\tVALUE\0NAME\tVALUE\0\0 in memory
+ * NAME=VALUE,NAME=VALUE, in storage
+ * `def' is in the storage format.
+ */
+static void gppmap(void *handle, char *name, char *def, char *val, int len)
+{
+ char *buf = snewn(2*len, char), *p, *q;
+ gpps(handle, name, def, buf, 2*len);
+ p = buf;
+ q = val;
+ while (*p) {
+ while (*p && *p != ',') {
+ int c = *p++;
+ if (c == '=')
+ c = '\t';
+ if (c == '\\')
+ c = *p++;
+ *q++ = c;
+ }
+ if (*p == ',')
+ p++;
+ *q++ = '\0';
+ }
+ *q = '\0';
+ sfree(buf);
+}
+
+/*
+ * Write a set of name/value pairs in the above format.
+ */
+static void wmap(void *handle, char const *key, char const *value, int len)
+{
+ char *buf = snewn(2*len, char), *p;
+ const char *q;
+ p = buf;
+ q = value;
+ while (*q) {
+ while (*q) {
+ int c = *q++;
+ if (c == '=' || c == ',' || c == '\\')
+ *p++ = '\\';
+ if (c == '\t')
+ c = '=';
+ *p++ = c;
+ }
+ *p++ = ',';
+ q++;
+ }
+ *p = '\0';
+ write_setting_s(handle, key, buf);
+ sfree(buf);
+}
+
static int key2val(const struct keyval *mapping, int nmaps, char *key)
{
int i;
int *array)
{
char commalist[80];
+ char *tokarg = commalist;
int n;
unsigned long seen = 0; /* bitmap for weeding dups etc */
gpps(sesskey, name, def, commalist, sizeof(commalist));
do {
int v;
char *key;
- key = strtok(n==0 ? commalist : NULL, ","); /* sorry */
+ key = strtok(tokarg, ","); /* sorry */
+ tokarg = NULL;
if (!key) break;
if (((v = key2val(mapping, nvals, key)) != -1) &&
!(seen & 1<<v)) {
{
int i;
for (i = 0; i < nvals; i++) {
+ assert(mapping[i].v < 32);
if (!(seen & 1<<mapping[i].v)) {
array[n] = mapping[i].v;
n++;
write_setting_i(sesskey, "TCPKeepalives", cfg->tcp_keepalives);
write_setting_s(sesskey, "TerminalType", cfg->termtype);
write_setting_s(sesskey, "TerminalSpeed", cfg->termspeed);
+ wmap(sesskey, "TerminalModes", cfg->ttymodes, lenof(cfg->ttymodes));
/* Address family selection */
write_setting_i(sesskey, "AddressFamily", cfg->addressfamily);
write_setting_s(sesskey, "ProxyUsername", cfg->proxy_username);
write_setting_s(sesskey, "ProxyPassword", cfg->proxy_password);
write_setting_s(sesskey, "ProxyTelnetCommand", cfg->proxy_telnet_command);
-
- {
- char buf[2 * sizeof(cfg->environmt)], *p, *q;
- p = buf;
- q = cfg->environmt;
- while (*q) {
- while (*q) {
- int c = *q++;
- if (c == '=' || c == ',' || c == '\\')
- *p++ = '\\';
- if (c == '\t')
- c = '=';
- *p++ = c;
- }
- *p++ = ',';
- q++;
- }
- *p = '\0';
- write_setting_s(sesskey, "Environment", buf);
- }
+ wmap(sesskey, "Environment", cfg->environmt, lenof(cfg->environmt));
write_setting_s(sesskey, "UserName", cfg->username);
write_setting_s(sesskey, "LocalUserName", cfg->localusername);
write_setting_i(sesskey, "NoPTY", cfg->nopty);
write_setting_i(sesskey, "Compression", cfg->compression);
+ write_setting_i(sesskey, "TryAgent", cfg->tryagent);
write_setting_i(sesskey, "AgentFwd", cfg->agentfwd);
write_setting_i(sesskey, "ChangeUsername", cfg->change_username);
wprefs(sesskey, "Cipher", ciphernames, CIPHER_MAX,
wprefs(sesskey, "KEX", kexnames, KEX_MAX, cfg->ssh_kexlist);
write_setting_i(sesskey, "RekeyTime", cfg->ssh_rekey_time);
write_setting_s(sesskey, "RekeyBytes", cfg->ssh_rekey_data);
+ write_setting_i(sesskey, "SshNoAuth", cfg->ssh_no_userauth);
write_setting_i(sesskey, "AuthTIS", cfg->try_tis_auth);
write_setting_i(sesskey, "AuthKI", cfg->try_ki_auth);
write_setting_i(sesskey, "SshNoShell", cfg->ssh_no_shell);
write_setting_i(sesskey, "TermWidth", cfg->width);
write_setting_i(sesskey, "TermHeight", cfg->height);
write_setting_fontspec(sesskey, "Font", cfg->font);
+ write_setting_i(sesskey, "FontQuality", cfg->font_quality);
write_setting_i(sesskey, "FontVTMode", cfg->vtmode);
write_setting_i(sesskey, "UseSystemColours", cfg->system_colour);
write_setting_i(sesskey, "TryPalette", cfg->try_palette);
write_setting_i(sesskey, "X11AuthType", cfg->x11_auth);
write_setting_i(sesskey, "LocalPortAcceptAll", cfg->lport_acceptall);
write_setting_i(sesskey, "RemotePortAcceptAll", cfg->rport_acceptall);
- {
- char buf[2 * sizeof(cfg->portfwd)], *p, *q;
- p = buf;
- q = cfg->portfwd;
- while (*q) {
- while (*q) {
- int c = *q++;
- if (c == '=' || c == ',' || c == '\\')
- *p++ = '\\';
- if (c == '\t')
- c = '=';
- *p++ = c;
- }
- *p++ = ',';
- q++;
- }
- *p = '\0';
- write_setting_s(sesskey, "PortForwardings", buf);
- }
+ wmap(sesskey, "PortForwardings", cfg->portfwd, lenof(cfg->portfwd));
write_setting_i(sesskey, "BugIgnore1", 2-cfg->sshbug_ignore1);
write_setting_i(sesskey, "BugPlainPW1", 2-cfg->sshbug_plainpw1);
write_setting_i(sesskey, "BugRSA1", 2-cfg->sshbug_rsa1);
write_setting_i(sesskey, "BugDeriveKey2", 2-cfg->sshbug_derivekey2);
write_setting_i(sesskey, "BugRSAPad2", 2-cfg->sshbug_rsapad2);
write_setting_i(sesskey, "BugPKSessID2", 2-cfg->sshbug_pksessid2);
+ write_setting_i(sesskey, "BugRekey2", 2-cfg->sshbug_rekey2);
write_setting_i(sesskey, "StampUtmp", cfg->stamp_utmp);
write_setting_i(sesskey, "LoginShell", cfg->login_shell);
write_setting_i(sesskey, "ScrollbarOnLeft", cfg->scrollbar_on_left);
write_setting_fontspec(sesskey, "WideBoldFont", cfg->wideboldfont);
write_setting_i(sesskey, "ShadowBold", cfg->shadowbold);
write_setting_i(sesskey, "ShadowBoldOffset", cfg->shadowboldoffset);
+ write_setting_s(sesskey, "SerialLine", cfg->serline);
+ write_setting_i(sesskey, "SerialSpeed", cfg->serspeed);
+ write_setting_i(sesskey, "SerialDataBits", cfg->serdatabits);
+ write_setting_i(sesskey, "SerialStopHalfbits", cfg->serstopbits);
+ write_setting_i(sesskey, "SerialParity", cfg->serparity);
+ write_setting_i(sesskey, "SerialFlowControl", cfg->serflow);
}
void load_settings(char *section, int do_host, Config * cfg)
sizeof(cfg->termtype));
gpps(sesskey, "TerminalSpeed", "38400,38400", cfg->termspeed,
sizeof(cfg->termspeed));
+ {
+ /* This hardcodes a big set of defaults in any new saved
+ * sessions. Let's hope we don't change our mind. */
+ int i;
+ char *def = dupstr("");
+ /* Default: all set to "auto" */
+ for (i = 0; ttymodes[i]; i++) {
+ char *def2 = dupprintf("%s%s=A,", def, ttymodes[i]);
+ sfree(def);
+ def = def2;
+ }
+ gppmap(sesskey, "TerminalModes", def,
+ cfg->ttymodes, lenof(cfg->ttymodes));
+ sfree(def);
+ }
/* proxy settings */
gpps(sesskey, "ProxyExcludeList", "", cfg->proxy_exclude_list,
sizeof(cfg->proxy_password));
gpps(sesskey, "ProxyTelnetCommand", "connect %host %port\\n",
cfg->proxy_telnet_command, sizeof(cfg->proxy_telnet_command));
-
- {
- char buf[2 * sizeof(cfg->environmt)], *p, *q;
- gpps(sesskey, "Environment", "", buf, sizeof(buf));
- p = buf;
- q = cfg->environmt;
- while (*p) {
- while (*p && *p != ',') {
- int c = *p++;
- if (c == '=')
- c = '\t';
- if (c == '\\')
- c = *p++;
- *q++ = c;
- }
- if (*p == ',')
- p++;
- *q++ = '\0';
- }
- *q = '\0';
- }
+ gppmap(sesskey, "Environment", "", cfg->environmt, lenof(cfg->environmt));
gpps(sesskey, "UserName", "", cfg->username, sizeof(cfg->username));
gpps(sesskey, "LocalUserName", "", cfg->localusername,
sizeof(cfg->localusername));
gppi(sesskey, "NoPTY", 0, &cfg->nopty);
gppi(sesskey, "Compression", 0, &cfg->compression);
+ gppi(sesskey, "TryAgent", 1, &cfg->tryagent);
gppi(sesskey, "AgentFwd", 0, &cfg->agentfwd);
gppi(sesskey, "ChangeUsername", 0, &cfg->change_username);
gprefs(sesskey, "Cipher", "\0",
sizeof(cfg->ssh_rekey_data));
gppi(sesskey, "SshProt", 2, &cfg->sshprot);
gppi(sesskey, "SSH2DES", 0, &cfg->ssh2_des_cbc);
+ gppi(sesskey, "SshNoAuth", 0, &cfg->ssh_no_userauth);
gppi(sesskey, "AuthTIS", 0, &cfg->try_tis_auth);
gppi(sesskey, "AuthKI", 1, &cfg->try_ki_auth);
gppi(sesskey, "SshNoShell", 0, &cfg->ssh_no_shell);
gppi(sesskey, "TermWidth", 80, &cfg->width);
gppi(sesskey, "TermHeight", 24, &cfg->height);
gppfont(sesskey, "Font", &cfg->font);
+ gppi(sesskey, "FontQuality", FQ_DEFAULT, &cfg->font_quality);
gppi(sesskey, "FontVTMode", VT_UNICODE, (int *) &cfg->vtmode);
gppi(sesskey, "UseSystemColours", 0, &cfg->system_colour);
gppi(sesskey, "TryPalette", 0, &cfg->try_palette);
gppi(sesskey, "LocalPortAcceptAll", 0, &cfg->lport_acceptall);
gppi(sesskey, "RemotePortAcceptAll", 0, &cfg->rport_acceptall);
- {
- char buf[2 * sizeof(cfg->portfwd)], *p, *q;
- gpps(sesskey, "PortForwardings", "", buf, sizeof(buf));
- p = buf;
- q = cfg->portfwd;
- while (*p) {
- while (*p && *p != ',') {
- int c = *p++;
- if (c == '=')
- c = '\t';
- if (c == '\\')
- c = *p++;
- *q++ = c;
- }
- if (*p == ',')
- p++;
- *q++ = '\0';
- }
- *q = '\0';
- }
+ gppmap(sesskey, "PortForwardings", "", cfg->portfwd, lenof(cfg->portfwd));
gppi(sesskey, "BugIgnore1", 0, &i); cfg->sshbug_ignore1 = 2-i;
gppi(sesskey, "BugPlainPW1", 0, &i); cfg->sshbug_plainpw1 = 2-i;
gppi(sesskey, "BugRSA1", 0, &i); cfg->sshbug_rsa1 = 2-i;
gppfont(sesskey, "WideFont", &cfg->widefont);
gppfont(sesskey, "WideBoldFont", &cfg->wideboldfont);
gppi(sesskey, "ShadowBoldOffset", 1, &cfg->shadowboldoffset);
+ gpps(sesskey, "SerialLine", "", cfg->serline, sizeof(cfg->serline));
+ gppi(sesskey, "SerialSpeed", 9600, &cfg->serspeed);
+ gppi(sesskey, "SerialDataBits", 8, &cfg->serdatabits);
+ gppi(sesskey, "SerialStopHalfbits", 2, &cfg->serstopbits);
+ gppi(sesskey, "SerialParity", 0, &cfg->serparity);
+ gppi(sesskey, "SerialFlowControl", 0, &cfg->serflow);
}
void do_defaults(char *session, Config * cfg)
} else {
sfree(list->buffer);
sfree(list->sessions);
+ list->buffer = NULL;
+ list->sessions = NULL;
}
}