Sebastian Kuschel reports that pfd_closing can be called for a socket
[u/mdw/putty] / settings.c
CommitLineData
a9422f39 1/*
f4ff9455 2 * settings.c: read and write saved sessions. (platform-independent)
a9422f39 3 */
4
5cc5734b 5#include <assert.h>
a9422f39 6#include <stdio.h>
49bad831 7#include <stdlib.h>
a9422f39 8#include "putty.h"
9#include "storage.h"
10
83e7d008 11/* The cipher order given here is the default order. */
4ceef224 12static const struct keyvalwhere ciphernames[] = {
13 { "aes", CIPHER_AES, -1, -1 },
14 { "blowfish", CIPHER_BLOWFISH, -1, -1 },
15 { "3des", CIPHER_3DES, -1, -1 },
16 { "WARN", CIPHER_WARN, -1, -1 },
17 { "arcfour", CIPHER_ARCFOUR, -1, -1 },
18 { "des", CIPHER_DES, -1, -1 }
ca20bfcf 19};
20
4ceef224 21static const struct keyvalwhere kexnames[] = {
22 { "dh-gex-sha1", KEX_DHGEX, -1, -1 },
23 { "dh-group14-sha1", KEX_DHGROUP14, -1, -1 },
24 { "dh-group1-sha1", KEX_DHGROUP1, -1, -1 },
25 { "rsa", KEX_RSA, KEX_WARN, -1 },
26 { "WARN", KEX_WARN, -1, -1 }
83e7d008 27};
28
c6ccd5c2 29/*
30 * All the terminal modes that we know about for the "TerminalModes"
31 * setting. (Also used by config.c for the drop-down list.)
32 * This is currently precisely the same as the set in ssh.c, but could
33 * in principle differ if other backends started to support tty modes
34 * (e.g., the pty backend).
35 */
36const char *const ttymodes[] = {
37 "INTR", "QUIT", "ERASE", "KILL", "EOF",
38 "EOL", "EOL2", "START", "STOP", "SUSP",
39 "DSUSP", "REPRINT", "WERASE", "LNEXT", "FLUSH",
40 "SWTCH", "STATUS", "DISCARD", "IGNPAR", "PARMRK",
41 "INPCK", "ISTRIP", "INLCR", "IGNCR", "ICRNL",
42 "IUCLC", "IXON", "IXANY", "IXOFF", "IMAXBEL",
43 "ISIG", "ICANON", "XCASE", "ECHO", "ECHOE",
44 "ECHOK", "ECHONL", "NOFLSH", "TOSTOP", "IEXTEN",
45 "ECHOCTL", "ECHOKE", "PENDIN", "OPOST", "OLCUC",
46 "ONLCR", "OCRNL", "ONOCR", "ONLRET", "CS7",
47 "CS8", "PARENB", "PARODD", NULL
48};
49
9e164d82 50/*
51 * Convenience functions to access the backends[] array
52 * (which is only present in tools that manage settings).
53 */
54
55Backend *backend_from_name(const char *name)
56{
57 Backend **p;
58 for (p = backends; *p != NULL; p++)
59 if (!strcmp((*p)->name, name))
60 return *p;
61 return NULL;
62}
63
64Backend *backend_from_proto(int proto)
65{
66 Backend **p;
67 for (p = backends; *p != NULL; p++)
68 if ((*p)->protocol == proto)
69 return *p;
70 return NULL;
71}
72
4a693cfc 73char *get_remote_username(Conf *conf)
471c20b0 74{
4a693cfc 75 char *username = conf_get_str(conf, CONF_username);
76 if (*username) {
77 return dupstr(username);
78 } else if (conf_get_int(conf, CONF_username_from_env)) {
79 /* Use local username. */
80 return get_username(); /* might still be NULL */
471c20b0 81 } else {
4a693cfc 82 return NULL;
471c20b0 83 }
471c20b0 84}
85
4a693cfc 86static char *gpps_raw(void *handle, const char *name, const char *def)
32874aea 87{
4a693cfc 88 char *ret = read_setting_s(handle, name);
89 if (!ret)
90 ret = platform_default_s(name);
91 if (!ret)
92 ret = def ? dupstr(def) : NULL; /* permit NULL as final fallback */
93 return ret;
94}
5a9eb105 95
4a693cfc 96static void gpps(void *handle, const char *name, const char *def,
97 Conf *conf, int primary)
98{
99 char *val = gpps_raw(handle, name, def);
100 conf_set_str(conf, primary, val);
101 sfree(val);
a9422f39 102}
103
9a30e26b 104/*
105 * gppfont and gppfile cannot have local defaults, since the very
962468d4 106 * format of a Filename or FontSpec is platform-dependent. So the
9a30e26b 107 * platform-dependent functions MUST return some sort of value.
108 */
4a693cfc 109static void gppfont(void *handle, const char *name, Conf *conf, int primary)
9a30e26b 110{
ae62eaeb 111 FontSpec *result = read_setting_fontspec(handle, name);
112 if (!result)
113 result = platform_default_fontspec(name);
114 conf_set_fontspec(conf, primary, result);
115 fontspec_free(result);
9a30e26b 116}
4a693cfc 117static void gppfile(void *handle, const char *name, Conf *conf, int primary)
9a30e26b 118{
962468d4 119 Filename *result = read_setting_filename(handle, name);
120 if (!result)
4a693cfc 121 result = platform_default_filename(name);
962468d4 122 conf_set_filename(conf, primary, result);
123 filename_free(result);
9a30e26b 124}
125
4a693cfc 126static int gppi_raw(void *handle, char *name, int def)
32874aea 127{
5a9eb105 128 def = platform_default_i(name, def);
4a693cfc 129 return read_setting_i(handle, name, def);
130}
131
132static void gppi(void *handle, char *name, int def, Conf *conf, int primary)
133{
134 conf_set_int(conf, primary, gppi_raw(handle, name, def));
a9422f39 135}
136
b50ee9a8 137/*
138 * Read a set of name-value pairs in the format we occasionally use:
139 * NAME\tVALUE\0NAME\tVALUE\0\0 in memory
140 * NAME=VALUE,NAME=VALUE, in storage
141 * `def' is in the storage format.
142 */
4a693cfc 143static int gppmap(void *handle, char *name, Conf *conf, int primary)
b50ee9a8 144{
4a693cfc 145 char *buf, *p, *q, *key, *val;
146
147 /*
148 * Start by clearing any existing subkeys of this key from conf.
149 */
52112bad 150 while ((key = conf_get_str_nthstrkey(conf, primary, 0)) != NULL)
151 conf_del_str_str(conf, primary, key);
4a693cfc 152
153 /*
154 * Now read a serialised list from the settings and unmarshal it
155 * into its components.
156 */
157 buf = gpps_raw(handle, name, NULL);
158 if (!buf)
159 return FALSE;
160
b50ee9a8 161 p = buf;
b50ee9a8 162 while (*p) {
4a693cfc 163 q = buf;
164 val = NULL;
b50ee9a8 165 while (*p && *p != ',') {
166 int c = *p++;
167 if (c == '=')
4a693cfc 168 c = '\0';
b50ee9a8 169 if (c == '\\')
170 c = *p++;
171 *q++ = c;
4a693cfc 172 if (!c)
173 val = q;
b50ee9a8 174 }
175 if (*p == ',')
176 p++;
4a693cfc 177 if (!val)
178 val = q;
179 *q = '\0';
180
181 if (primary == CONF_portfwd && buf[0] == 'D') {
182 /*
183 * Backwards-compatibility hack: dynamic forwardings are
184 * indexed in the data store as a third type letter in the
185 * key, 'D' alongside 'L' and 'R' - but really, they
186 * should be filed under 'L' with a special _value_,
187 * because local and dynamic forwardings both involve
188 * _listening_ on a local port, and are hence mutually
189 * exclusive on the same port number. So here we translate
190 * the legacy storage format into the sensible internal
191 * form.
192 */
193 char *newkey = dupcat("L", buf+1, NULL);
194 conf_set_str_str(conf, primary, newkey, "D");
195 sfree(newkey);
196 } else {
197 conf_set_str_str(conf, primary, buf, val);
198 }
b50ee9a8 199 }
b50ee9a8 200 sfree(buf);
4a693cfc 201
202 return TRUE;
b50ee9a8 203}
204
205/*
206 * Write a set of name/value pairs in the above format.
207 */
4a693cfc 208static void wmap(void *handle, char const *outkey, Conf *conf, int primary)
b50ee9a8 209{
4a693cfc 210 char *buf, *p, *q, *key, *realkey, *val;
211 int len;
212
213 len = 1; /* allow for NUL */
214
215 for (val = conf_get_str_strs(conf, primary, NULL, &key);
216 val != NULL;
217 val = conf_get_str_strs(conf, primary, key, &key))
218 len += 2 + 2 * (strlen(key) + strlen(val)); /* allow for escaping */
219
220 buf = snewn(len, char);
b50ee9a8 221 p = buf;
4a693cfc 222
223 for (val = conf_get_str_strs(conf, primary, NULL, &key);
224 val != NULL;
225 val = conf_get_str_strs(conf, primary, key, &key)) {
226
227 if (primary == CONF_portfwd && !strcmp(val, "D")) {
228 /*
229 * Backwards-compatibility hack, as above: translate from
230 * the sensible internal representation of dynamic
231 * forwardings (key "L<port>", value "D") to the
232 * conceptually incoherent legacy storage format (key
233 * "D<port>", value empty).
234 */
235 realkey = key; /* restore it at end of loop */
236 val = "";
237 key = dupcat("D", key+1, NULL);
238 } else {
239 realkey = NULL;
240 }
241
242 if (p != buf)
243 *p++ = ',';
244 for (q = key; *q; q++) {
245 if (*q == '=' || *q == ',' || *q == '\\')
b50ee9a8 246 *p++ = '\\';
4a693cfc 247 *p++ = *q;
b50ee9a8 248 }
4a693cfc 249 *p++ = '=';
250 for (q = val; *q; q++) {
251 if (*q == '=' || *q == ',' || *q == '\\')
252 *p++ = '\\';
253 *p++ = *q;
254 }
255
256 if (realkey) {
257 free(key);
258 key = realkey;
259 }
b50ee9a8 260 }
261 *p = '\0';
4a693cfc 262 write_setting_s(handle, outkey, buf);
b50ee9a8 263 sfree(buf);
264}
265
4ceef224 266static int key2val(const struct keyvalwhere *mapping,
267 int nmaps, char *key)
ca20bfcf 268{
269 int i;
270 for (i = 0; i < nmaps; i++)
271 if (!strcmp(mapping[i].s, key)) return mapping[i].v;
272 return -1;
273}
274
4ceef224 275static const char *val2key(const struct keyvalwhere *mapping,
276 int nmaps, int val)
ca20bfcf 277{
278 int i;
279 for (i = 0; i < nmaps; i++)
280 if (mapping[i].v == val) return mapping[i].s;
281 return NULL;
282}
283
284/*
285 * Helper function to parse a comma-separated list of strings into
286 * a preference list array of values. Any missing values are added
287 * to the end and duplicates are weeded.
288 * XXX: assumes vals in 'mapping' are small +ve integers
289 */
290static void gprefs(void *sesskey, char *name, char *def,
4ceef224 291 const struct keyvalwhere *mapping, int nvals,
4a693cfc 292 Conf *conf, int primary)
ca20bfcf 293{
4a693cfc 294 char *commalist;
4ceef224 295 char *p, *q;
296 int i, j, n, v, pos;
ca20bfcf 297 unsigned long seen = 0; /* bitmap for weeding dups etc */
4ceef224 298
299 /*
300 * Fetch the string which we'll parse as a comma-separated list.
301 */
4a693cfc 302 commalist = gpps_raw(sesskey, name, def);
ca20bfcf 303
4ceef224 304 /*
305 * Go through that list and convert it into values.
306 */
ca20bfcf 307 n = 0;
4ceef224 308 p = commalist;
309 while (1) {
310 while (*p && *p == ',') p++;
311 if (!*p)
312 break; /* no more words */
313
314 q = p;
315 while (*p && *p != ',') p++;
316 if (*p) *p++ = '\0';
317
318 v = key2val(mapping, nvals, q);
319 if (v != -1 && !(seen & (1 << v))) {
320 seen |= (1 << v);
4a693cfc 321 conf_set_int_int(conf, primary, n, v);
322 n++;
ca20bfcf 323 }
4ceef224 324 }
325
4a693cfc 326 sfree(commalist);
327
4ceef224 328 /*
329 * Now go through 'mapping' and add values that weren't mentioned
330 * in the list we fetched. We may have to loop over it multiple
331 * times so that we add values before other values whose default
332 * positions depend on them.
333 */
334 while (n < nvals) {
335 for (i = 0; i < nvals; i++) {
5cc5734b 336 assert(mapping[i].v < 32);
4ceef224 337
338 if (!(seen & (1 << mapping[i].v))) {
339 /*
340 * This element needs adding. But can we add it yet?
341 */
342 if (mapping[i].vrel != -1 && !(seen & (1 << mapping[i].vrel)))
343 continue; /* nope */
344
345 /*
346 * OK, we can work out where to add this element, so
347 * do so.
348 */
349 if (mapping[i].vrel == -1) {
350 pos = (mapping[i].where < 0 ? n : 0);
351 } else {
352 for (j = 0; j < n; j++)
4a693cfc 353 if (conf_get_int_int(conf, primary, j) ==
354 mapping[i].vrel)
4ceef224 355 break;
356 assert(j < n); /* implied by (seen & (1<<vrel)) */
357 pos = (mapping[i].where < 0 ? j : j+1);
358 }
359
360 /*
361 * And add it.
362 */
363 for (j = n-1; j >= pos; j--)
4a693cfc 364 conf_set_int_int(conf, primary, j+1,
365 conf_get_int_int(conf, primary, j));
366 conf_set_int_int(conf, primary, pos, mapping[i].v);
4ceef224 367 n++;
368 }
369 }
ca20bfcf 370 }
371}
372
373/*
374 * Write out a preference list.
375 */
376static void wprefs(void *sesskey, char *name,
4ceef224 377 const struct keyvalwhere *mapping, int nvals,
4a693cfc 378 Conf *conf, int primary)
ca20bfcf 379{
4ceef224 380 char *buf, *p;
381 int i, maxlen;
382
383 for (maxlen = i = 0; i < nvals; i++) {
4a693cfc 384 const char *s = val2key(mapping, nvals,
385 conf_get_int_int(conf, primary, i));
ca20bfcf 386 if (s) {
eedb14cc 387 maxlen += (maxlen > 0 ? 1 : 0) + strlen(s);
4ceef224 388 }
389 }
390
eedb14cc 391 buf = snewn(maxlen + 1, char);
4ceef224 392 p = buf;
393
394 for (i = 0; i < nvals; i++) {
4a693cfc 395 const char *s = val2key(mapping, nvals,
396 conf_get_int_int(conf, primary, i));
4ceef224 397 if (s) {
398 p += sprintf(p, "%s%s", (p > buf ? "," : ""), s);
ca20bfcf 399 }
400 }
4ceef224 401
eedb14cc 402 assert(p - buf == maxlen);
403 *p = '\0';
4ceef224 404
ca20bfcf 405 write_setting_s(sesskey, name, buf);
4ceef224 406
407 sfree(buf);
ca20bfcf 408}
409
4a693cfc 410char *save_settings(char *section, Conf *conf)
32874aea 411{
a9422f39 412 void *sesskey;
3f935d5b 413 char *errmsg;
a9422f39 414
3f935d5b 415 sesskey = open_settings_w(section, &errmsg);
a9422f39 416 if (!sesskey)
3f935d5b 417 return errmsg;
4a693cfc 418 save_open_settings(sesskey, conf);
b537dd42 419 close_settings_w(sesskey);
3f935d5b 420 return NULL;
b537dd42 421}
422
4a693cfc 423void save_open_settings(void *sesskey, Conf *conf)
b537dd42 424{
425 int i;
426 char *p;
a9422f39 427
32874aea 428 write_setting_i(sesskey, "Present", 1);
4a693cfc 429 write_setting_s(sesskey, "HostName", conf_get_str(conf, CONF_host));
962468d4 430 write_setting_filename(sesskey, "LogFileName", conf_get_filename(conf, CONF_logfilename));
4a693cfc 431 write_setting_i(sesskey, "LogType", conf_get_int(conf, CONF_logtype));
432 write_setting_i(sesskey, "LogFileClash", conf_get_int(conf, CONF_logxfovr));
433 write_setting_i(sesskey, "LogFlush", conf_get_int(conf, CONF_logflush));
434 write_setting_i(sesskey, "SSHLogOmitPasswords", conf_get_int(conf, CONF_logomitpass));
435 write_setting_i(sesskey, "SSHLogOmitData", conf_get_int(conf, CONF_logomitdata));
348a9ad6 436 p = "raw";
9e164d82 437 {
4a693cfc 438 const Backend *b = backend_from_proto(conf_get_int(conf, CONF_protocol));
9e164d82 439 if (b)
440 p = b->name;
441 }
348a9ad6 442 write_setting_s(sesskey, "Protocol", p);
4a693cfc 443 write_setting_i(sesskey, "PortNumber", conf_get_int(conf, CONF_port));
88103a48 444 /* The CloseOnExit numbers are arranged in a different order from
445 * the standard FORCE_ON / FORCE_OFF / AUTO. */
4a693cfc 446 write_setting_i(sesskey, "CloseOnExit", (conf_get_int(conf, CONF_close_on_exit)+2)%3);
447 write_setting_i(sesskey, "WarnOnClose", !!conf_get_int(conf, CONF_warn_on_close));
448 write_setting_i(sesskey, "PingInterval", conf_get_int(conf, CONF_ping_interval) / 60); /* minutes */
449 write_setting_i(sesskey, "PingIntervalSecs", conf_get_int(conf, CONF_ping_interval) % 60); /* seconds */
450 write_setting_i(sesskey, "TCPNoDelay", conf_get_int(conf, CONF_tcp_nodelay));
451 write_setting_i(sesskey, "TCPKeepalives", conf_get_int(conf, CONF_tcp_keepalives));
452 write_setting_s(sesskey, "TerminalType", conf_get_str(conf, CONF_termtype));
453 write_setting_s(sesskey, "TerminalSpeed", conf_get_str(conf, CONF_termspeed));
454 wmap(sesskey, "TerminalModes", conf, CONF_ttymodes);
8eebd221 455
05581745 456 /* Address family selection */
4a693cfc 457 write_setting_i(sesskey, "AddressFamily", conf_get_int(conf, CONF_addressfamily));
05581745 458
8eebd221 459 /* proxy settings */
4a693cfc 460 write_setting_s(sesskey, "ProxyExcludeList", conf_get_str(conf, CONF_proxy_exclude_list));
461 write_setting_i(sesskey, "ProxyDNS", (conf_get_int(conf, CONF_proxy_dns)+2)%3);
462 write_setting_i(sesskey, "ProxyLocalhost", conf_get_int(conf, CONF_even_proxy_localhost));
463 write_setting_i(sesskey, "ProxyMethod", conf_get_int(conf, CONF_proxy_type));
464 write_setting_s(sesskey, "ProxyHost", conf_get_str(conf, CONF_proxy_host));
465 write_setting_i(sesskey, "ProxyPort", conf_get_int(conf, CONF_proxy_port));
466 write_setting_s(sesskey, "ProxyUsername", conf_get_str(conf, CONF_proxy_username));
467 write_setting_s(sesskey, "ProxyPassword", conf_get_str(conf, CONF_proxy_password));
468 write_setting_s(sesskey, "ProxyTelnetCommand", conf_get_str(conf, CONF_proxy_telnet_command));
469 wmap(sesskey, "Environment", conf, CONF_environmt);
470 write_setting_s(sesskey, "UserName", conf_get_str(conf, CONF_username));
471 write_setting_i(sesskey, "UserNameFromEnvironment", conf_get_int(conf, CONF_username_from_env));
472 write_setting_s(sesskey, "LocalUserName", conf_get_str(conf, CONF_localusername));
473 write_setting_i(sesskey, "NoPTY", conf_get_int(conf, CONF_nopty));
474 write_setting_i(sesskey, "Compression", conf_get_int(conf, CONF_compression));
475 write_setting_i(sesskey, "TryAgent", conf_get_int(conf, CONF_tryagent));
476 write_setting_i(sesskey, "AgentFwd", conf_get_int(conf, CONF_agentfwd));
477 write_setting_i(sesskey, "GssapiFwd", conf_get_int(conf, CONF_gssapifwd));
478 write_setting_i(sesskey, "ChangeUsername", conf_get_int(conf, CONF_change_username));
479 wprefs(sesskey, "Cipher", ciphernames, CIPHER_MAX, conf, CONF_ssh_cipherlist);
480 wprefs(sesskey, "KEX", kexnames, KEX_MAX, conf, CONF_ssh_kexlist);
481 write_setting_i(sesskey, "RekeyTime", conf_get_int(conf, CONF_ssh_rekey_time));
482 write_setting_s(sesskey, "RekeyBytes", conf_get_str(conf, CONF_ssh_rekey_data));
483 write_setting_i(sesskey, "SshNoAuth", conf_get_int(conf, CONF_ssh_no_userauth));
484 write_setting_i(sesskey, "SshBanner", conf_get_int(conf, CONF_ssh_show_banner));
485 write_setting_i(sesskey, "AuthTIS", conf_get_int(conf, CONF_try_tis_auth));
486 write_setting_i(sesskey, "AuthKI", conf_get_int(conf, CONF_try_ki_auth));
487 write_setting_i(sesskey, "AuthGSSAPI", conf_get_int(conf, CONF_try_gssapi_auth));
1e00c92b 488#ifndef NO_GSSAPI
4a693cfc 489 wprefs(sesskey, "GSSLibs", gsslibkeywords, ngsslibs, conf, CONF_ssh_gsslist);
962468d4 490 write_setting_filename(sesskey, "GSSCustom", conf_get_filename(conf, CONF_ssh_gss_custom));
1e00c92b 491#endif
4a693cfc 492 write_setting_i(sesskey, "SshNoShell", conf_get_int(conf, CONF_ssh_no_shell));
493 write_setting_i(sesskey, "SshProt", conf_get_int(conf, CONF_sshprot));
494 write_setting_s(sesskey, "LogHost", conf_get_str(conf, CONF_loghost));
495 write_setting_i(sesskey, "SSH2DES", conf_get_int(conf, CONF_ssh2_des_cbc));
962468d4 496 write_setting_filename(sesskey, "PublicKeyFile", conf_get_filename(conf, CONF_keyfile));
4a693cfc 497 write_setting_s(sesskey, "RemoteCommand", conf_get_str(conf, CONF_remote_cmd));
498 write_setting_i(sesskey, "RFCEnviron", conf_get_int(conf, CONF_rfc_environ));
499 write_setting_i(sesskey, "PassiveTelnet", conf_get_int(conf, CONF_passive_telnet));
500 write_setting_i(sesskey, "BackspaceIsDelete", conf_get_int(conf, CONF_bksp_is_delete));
501 write_setting_i(sesskey, "RXVTHomeEnd", conf_get_int(conf, CONF_rxvt_homeend));
502 write_setting_i(sesskey, "LinuxFunctionKeys", conf_get_int(conf, CONF_funky_type));
503 write_setting_i(sesskey, "NoApplicationKeys", conf_get_int(conf, CONF_no_applic_k));
504 write_setting_i(sesskey, "NoApplicationCursors", conf_get_int(conf, CONF_no_applic_c));
505 write_setting_i(sesskey, "NoMouseReporting", conf_get_int(conf, CONF_no_mouse_rep));
506 write_setting_i(sesskey, "NoRemoteResize", conf_get_int(conf, CONF_no_remote_resize));
507 write_setting_i(sesskey, "NoAltScreen", conf_get_int(conf, CONF_no_alt_screen));
508 write_setting_i(sesskey, "NoRemoteWinTitle", conf_get_int(conf, CONF_no_remote_wintitle));
509 write_setting_i(sesskey, "RemoteQTitleAction", conf_get_int(conf, CONF_remote_qtitle_action));
510 write_setting_i(sesskey, "NoDBackspace", conf_get_int(conf, CONF_no_dbackspace));
511 write_setting_i(sesskey, "NoRemoteCharset", conf_get_int(conf, CONF_no_remote_charset));
512 write_setting_i(sesskey, "ApplicationCursorKeys", conf_get_int(conf, CONF_app_cursor));
513 write_setting_i(sesskey, "ApplicationKeypad", conf_get_int(conf, CONF_app_keypad));
514 write_setting_i(sesskey, "NetHackKeypad", conf_get_int(conf, CONF_nethack_keypad));
515 write_setting_i(sesskey, "AltF4", conf_get_int(conf, CONF_alt_f4));
516 write_setting_i(sesskey, "AltSpace", conf_get_int(conf, CONF_alt_space));
517 write_setting_i(sesskey, "AltOnly", conf_get_int(conf, CONF_alt_only));
518 write_setting_i(sesskey, "ComposeKey", conf_get_int(conf, CONF_compose_key));
519 write_setting_i(sesskey, "CtrlAltKeys", conf_get_int(conf, CONF_ctrlaltkeys));
520 write_setting_i(sesskey, "TelnetKey", conf_get_int(conf, CONF_telnet_keyboard));
521 write_setting_i(sesskey, "TelnetRet", conf_get_int(conf, CONF_telnet_newline));
522 write_setting_i(sesskey, "LocalEcho", conf_get_int(conf, CONF_localecho));
523 write_setting_i(sesskey, "LocalEdit", conf_get_int(conf, CONF_localedit));
524 write_setting_s(sesskey, "Answerback", conf_get_str(conf, CONF_answerback));
525 write_setting_i(sesskey, "AlwaysOnTop", conf_get_int(conf, CONF_alwaysontop));
526 write_setting_i(sesskey, "FullScreenOnAltEnter", conf_get_int(conf, CONF_fullscreenonaltenter));
527 write_setting_i(sesskey, "HideMousePtr", conf_get_int(conf, CONF_hide_mouseptr));
528 write_setting_i(sesskey, "SunkenEdge", conf_get_int(conf, CONF_sunken_edge));
529 write_setting_i(sesskey, "WindowBorder", conf_get_int(conf, CONF_window_border));
530 write_setting_i(sesskey, "CurType", conf_get_int(conf, CONF_cursor_type));
531 write_setting_i(sesskey, "BlinkCur", conf_get_int(conf, CONF_blink_cur));
532 write_setting_i(sesskey, "Beep", conf_get_int(conf, CONF_beep));
533 write_setting_i(sesskey, "BeepInd", conf_get_int(conf, CONF_beep_ind));
962468d4 534 write_setting_filename(sesskey, "BellWaveFile", conf_get_filename(conf, CONF_bell_wavefile));
4a693cfc 535 write_setting_i(sesskey, "BellOverload", conf_get_int(conf, CONF_bellovl));
536 write_setting_i(sesskey, "BellOverloadN", conf_get_int(conf, CONF_bellovl_n));
537 write_setting_i(sesskey, "BellOverloadT", conf_get_int(conf, CONF_bellovl_t)
3c89f872 538#ifdef PUTTY_UNIX_H
539 * 1000
540#endif
541 );
4a693cfc 542 write_setting_i(sesskey, "BellOverloadS", conf_get_int(conf, CONF_bellovl_s)
3c89f872 543#ifdef PUTTY_UNIX_H
544 * 1000
545#endif
546 );
4a693cfc 547 write_setting_i(sesskey, "ScrollbackLines", conf_get_int(conf, CONF_savelines));
548 write_setting_i(sesskey, "DECOriginMode", conf_get_int(conf, CONF_dec_om));
549 write_setting_i(sesskey, "AutoWrapMode", conf_get_int(conf, CONF_wrap_mode));
550 write_setting_i(sesskey, "LFImpliesCR", conf_get_int(conf, CONF_lfhascr));
551 write_setting_i(sesskey, "CRImpliesLF", conf_get_int(conf, CONF_crhaslf));
552 write_setting_i(sesskey, "DisableArabicShaping", conf_get_int(conf, CONF_arabicshaping));
553 write_setting_i(sesskey, "DisableBidi", conf_get_int(conf, CONF_bidi));
554 write_setting_i(sesskey, "WinNameAlways", conf_get_int(conf, CONF_win_name_always));
555 write_setting_s(sesskey, "WinTitle", conf_get_str(conf, CONF_wintitle));
556 write_setting_i(sesskey, "TermWidth", conf_get_int(conf, CONF_width));
557 write_setting_i(sesskey, "TermHeight", conf_get_int(conf, CONF_height));
ae62eaeb 558 write_setting_fontspec(sesskey, "Font", conf_get_fontspec(conf, CONF_font));
4a693cfc 559 write_setting_i(sesskey, "FontQuality", conf_get_int(conf, CONF_font_quality));
560 write_setting_i(sesskey, "FontVTMode", conf_get_int(conf, CONF_vtmode));
561 write_setting_i(sesskey, "UseSystemColours", conf_get_int(conf, CONF_system_colour));
562 write_setting_i(sesskey, "TryPalette", conf_get_int(conf, CONF_try_palette));
563 write_setting_i(sesskey, "ANSIColour", conf_get_int(conf, CONF_ansi_colour));
564 write_setting_i(sesskey, "Xterm256Colour", conf_get_int(conf, CONF_xterm_256_colour));
863c5362 565 write_setting_i(sesskey, "BoldAsColour", conf_get_int(conf, CONF_bold_style)-1);
f0fccd51 566
32874aea 567 for (i = 0; i < 22; i++) {
a9422f39 568 char buf[20], buf2[30];
569 sprintf(buf, "Colour%d", i);
4a693cfc 570 sprintf(buf2, "%d,%d,%d",
571 conf_get_int_int(conf, CONF_colours, i*3+0),
572 conf_get_int_int(conf, CONF_colours, i*3+1),
573 conf_get_int_int(conf, CONF_colours, i*3+2));
32874aea 574 write_setting_s(sesskey, buf, buf2);
a9422f39 575 }
4a693cfc 576 write_setting_i(sesskey, "RawCNP", conf_get_int(conf, CONF_rawcnp));
577 write_setting_i(sesskey, "PasteRTF", conf_get_int(conf, CONF_rtf_paste));
578 write_setting_i(sesskey, "MouseIsXterm", conf_get_int(conf, CONF_mouse_is_xterm));
579 write_setting_i(sesskey, "RectSelect", conf_get_int(conf, CONF_rect_select));
580 write_setting_i(sesskey, "MouseOverride", conf_get_int(conf, CONF_mouse_override));
32874aea 581 for (i = 0; i < 256; i += 32) {
a9422f39 582 char buf[20], buf2[256];
583 int j;
584 sprintf(buf, "Wordness%d", i);
585 *buf2 = '\0';
32874aea 586 for (j = i; j < i + 32; j++) {
587 sprintf(buf2 + strlen(buf2), "%s%d",
4a693cfc 588 (*buf2 ? "," : ""),
589 conf_get_int_int(conf, CONF_wordness, j));
a9422f39 590 }
32874aea 591 write_setting_s(sesskey, buf, buf2);
a9422f39 592 }
4a693cfc 593 write_setting_s(sesskey, "LineCodePage", conf_get_str(conf, CONF_line_codepage));
594 write_setting_i(sesskey, "CJKAmbigWide", conf_get_int(conf, CONF_cjk_ambig_wide));
595 write_setting_i(sesskey, "UTF8Override", conf_get_int(conf, CONF_utf8_override));
596 write_setting_s(sesskey, "Printer", conf_get_str(conf, CONF_printer));
597 write_setting_i(sesskey, "CapsLockCyr", conf_get_int(conf, CONF_xlat_capslockcyr));
598 write_setting_i(sesskey, "ScrollBar", conf_get_int(conf, CONF_scrollbar));
599 write_setting_i(sesskey, "ScrollBarFullScreen", conf_get_int(conf, CONF_scrollbar_in_fullscreen));
600 write_setting_i(sesskey, "ScrollOnKey", conf_get_int(conf, CONF_scroll_on_key));
601 write_setting_i(sesskey, "ScrollOnDisp", conf_get_int(conf, CONF_scroll_on_disp));
602 write_setting_i(sesskey, "EraseToScrollback", conf_get_int(conf, CONF_erase_to_scrollback));
603 write_setting_i(sesskey, "LockSize", conf_get_int(conf, CONF_resize_action));
604 write_setting_i(sesskey, "BCE", conf_get_int(conf, CONF_bce));
605 write_setting_i(sesskey, "BlinkText", conf_get_int(conf, CONF_blinktext));
606 write_setting_i(sesskey, "X11Forward", conf_get_int(conf, CONF_x11_forward));
607 write_setting_s(sesskey, "X11Display", conf_get_str(conf, CONF_x11_display));
608 write_setting_i(sesskey, "X11AuthType", conf_get_int(conf, CONF_x11_auth));
962468d4 609 write_setting_filename(sesskey, "X11AuthFile", conf_get_filename(conf, CONF_xauthfile));
4a693cfc 610 write_setting_i(sesskey, "LocalPortAcceptAll", conf_get_int(conf, CONF_lport_acceptall));
611 write_setting_i(sesskey, "RemotePortAcceptAll", conf_get_int(conf, CONF_rport_acceptall));
612 wmap(sesskey, "PortForwardings", conf, CONF_portfwd);
613 write_setting_i(sesskey, "BugIgnore1", 2-conf_get_int(conf, CONF_sshbug_ignore1));
614 write_setting_i(sesskey, "BugPlainPW1", 2-conf_get_int(conf, CONF_sshbug_plainpw1));
615 write_setting_i(sesskey, "BugRSA1", 2-conf_get_int(conf, CONF_sshbug_rsa1));
616 write_setting_i(sesskey, "BugIgnore2", 2-conf_get_int(conf, CONF_sshbug_ignore2));
617 write_setting_i(sesskey, "BugHMAC2", 2-conf_get_int(conf, CONF_sshbug_hmac2));
618 write_setting_i(sesskey, "BugDeriveKey2", 2-conf_get_int(conf, CONF_sshbug_derivekey2));
619 write_setting_i(sesskey, "BugRSAPad2", 2-conf_get_int(conf, CONF_sshbug_rsapad2));
620 write_setting_i(sesskey, "BugPKSessID2", 2-conf_get_int(conf, CONF_sshbug_pksessid2));
621 write_setting_i(sesskey, "BugRekey2", 2-conf_get_int(conf, CONF_sshbug_rekey2));
622 write_setting_i(sesskey, "BugMaxPkt2", 2-conf_get_int(conf, CONF_sshbug_maxpkt2));
2e0aae4f 623 write_setting_i(sesskey, "BugWinadj", 2-conf_get_int(conf, CONF_sshbug_winadj));
4a693cfc 624 write_setting_i(sesskey, "StampUtmp", conf_get_int(conf, CONF_stamp_utmp));
625 write_setting_i(sesskey, "LoginShell", conf_get_int(conf, CONF_login_shell));
626 write_setting_i(sesskey, "ScrollbarOnLeft", conf_get_int(conf, CONF_scrollbar_on_left));
ae62eaeb 627 write_setting_fontspec(sesskey, "BoldFont", conf_get_fontspec(conf, CONF_boldfont));
628 write_setting_fontspec(sesskey, "WideFont", conf_get_fontspec(conf, CONF_widefont));
629 write_setting_fontspec(sesskey, "WideBoldFont", conf_get_fontspec(conf, CONF_wideboldfont));
4a693cfc 630 write_setting_i(sesskey, "ShadowBold", conf_get_int(conf, CONF_shadowbold));
631 write_setting_i(sesskey, "ShadowBoldOffset", conf_get_int(conf, CONF_shadowboldoffset));
632 write_setting_s(sesskey, "SerialLine", conf_get_str(conf, CONF_serline));
633 write_setting_i(sesskey, "SerialSpeed", conf_get_int(conf, CONF_serspeed));
634 write_setting_i(sesskey, "SerialDataBits", conf_get_int(conf, CONF_serdatabits));
635 write_setting_i(sesskey, "SerialStopHalfbits", conf_get_int(conf, CONF_serstopbits));
636 write_setting_i(sesskey, "SerialParity", conf_get_int(conf, CONF_serparity));
637 write_setting_i(sesskey, "SerialFlowControl", conf_get_int(conf, CONF_serflow));
638 write_setting_s(sesskey, "WindowClass", conf_get_str(conf, CONF_winclass));
a9422f39 639}
640
4a693cfc 641void load_settings(char *section, Conf *conf)
32874aea 642{
a9422f39 643 void *sesskey;
644
645 sesskey = open_settings_r(section);
4a693cfc 646 load_open_settings(sesskey, conf);
ce283213 647 close_settings_r(sesskey);
073e9f42 648
4a693cfc 649 if (conf_launchable(conf))
073e9f42 650 add_session_to_jumplist(section);
ce283213 651}
652
4a693cfc 653void load_open_settings(void *sesskey, Conf *conf)
ce283213 654{
655 int i;
4a693cfc 656 char *prot;
657
658 conf_set_int(conf, CONF_ssh_subsys, 0); /* FIXME: load this properly */
659 conf_set_str(conf, CONF_remote_cmd, "");
660 conf_set_str(conf, CONF_remote_cmd2, "");
661 conf_set_str(conf, CONF_ssh_nc_host, "");
662
663 gpps(sesskey, "HostName", "", conf, CONF_host);
664 gppfile(sesskey, "LogFileName", conf, CONF_logfilename);
665 gppi(sesskey, "LogType", 0, conf, CONF_logtype);
666 gppi(sesskey, "LogFileClash", LGXF_ASK, conf, CONF_logxfovr);
667 gppi(sesskey, "LogFlush", 1, conf, CONF_logflush);
668 gppi(sesskey, "SSHLogOmitPasswords", 1, conf, CONF_logomitpass);
669 gppi(sesskey, "SSHLogOmitData", 0, conf, CONF_logomitdata);
670
671 prot = gpps_raw(sesskey, "Protocol", "default");
672 conf_set_int(conf, CONF_protocol, default_protocol);
673 conf_set_int(conf, CONF_port, default_port);
9e164d82 674 {
675 const Backend *b = backend_from_name(prot);
676 if (b) {
4a693cfc 677 conf_set_int(conf, CONF_protocol, b->protocol);
678 gppi(sesskey, "PortNumber", default_port, conf, CONF_port);
32874aea 679 }
9e164d82 680 }
4a693cfc 681 sfree(prot);
a9422f39 682
05581745 683 /* Address family selection */
4a693cfc 684 gppi(sesskey, "AddressFamily", ADDRTYPE_UNSPEC, conf, CONF_addressfamily);
05581745 685
88103a48 686 /* The CloseOnExit numbers are arranged in a different order from
687 * the standard FORCE_ON / FORCE_OFF / AUTO. */
4a693cfc 688 i = gppi_raw(sesskey, "CloseOnExit", 1); conf_set_int(conf, CONF_close_on_exit, (i+1)%3);
689 gppi(sesskey, "WarnOnClose", 1, conf, CONF_warn_on_close);
edce8e45 690 {
32874aea 691 /* This is two values for backward compatibility with 0.50/0.51 */
692 int pingmin, pingsec;
4a693cfc 693 pingmin = gppi_raw(sesskey, "PingInterval", 0);
694 pingsec = gppi_raw(sesskey, "PingIntervalSecs", 0);
695 conf_set_int(conf, CONF_ping_interval, pingmin * 60 + pingsec);
edce8e45 696 }
4a693cfc 697 gppi(sesskey, "TCPNoDelay", 1, conf, CONF_tcp_nodelay);
698 gppi(sesskey, "TCPKeepalives", 0, conf, CONF_tcp_keepalives);
699 gpps(sesskey, "TerminalType", "xterm", conf, CONF_termtype);
700 gpps(sesskey, "TerminalSpeed", "38400,38400", conf, CONF_termspeed);
701 if (!gppmap(sesskey, "TerminalModes", conf, CONF_ttymodes)) {
c6ccd5c2 702 /* This hardcodes a big set of defaults in any new saved
703 * sessions. Let's hope we don't change our mind. */
4a693cfc 704 for (i = 0; ttymodes[i]; i++)
705 conf_set_str_str(conf, CONF_ttymodes, ttymodes[i], "A");
c6ccd5c2 706 }
8eebd221 707
708 /* proxy settings */
4a693cfc 709 gpps(sesskey, "ProxyExcludeList", "", conf, CONF_proxy_exclude_list);
710 i = gppi_raw(sesskey, "ProxyDNS", 1); conf_set_int(conf, CONF_proxy_dns, (i+1)%3);
711 gppi(sesskey, "ProxyLocalhost", 0, conf, CONF_even_proxy_localhost);
712 gppi(sesskey, "ProxyMethod", -1, conf, CONF_proxy_type);
713 if (conf_get_int(conf, CONF_proxy_type) == -1) {
10068a0b 714 int i;
4a693cfc 715 i = gppi_raw(sesskey, "ProxyType", 0);
10068a0b 716 if (i == 0)
4a693cfc 717 conf_set_int(conf, CONF_proxy_type, PROXY_NONE);
10068a0b 718 else if (i == 1)
4a693cfc 719 conf_set_int(conf, CONF_proxy_type, PROXY_HTTP);
10068a0b 720 else if (i == 3)
4a693cfc 721 conf_set_int(conf, CONF_proxy_type, PROXY_TELNET);
10068a0b 722 else if (i == 4)
4a693cfc 723 conf_set_int(conf, CONF_proxy_type, PROXY_CMD);
10068a0b 724 else {
4a693cfc 725 i = gppi_raw(sesskey, "ProxySOCKSVersion", 5);
10068a0b 726 if (i == 5)
4a693cfc 727 conf_set_int(conf, CONF_proxy_type, PROXY_SOCKS5);
10068a0b 728 else
4a693cfc 729 conf_set_int(conf, CONF_proxy_type, PROXY_SOCKS4);
10068a0b 730 }
731 }
4a693cfc 732 gpps(sesskey, "ProxyHost", "proxy", conf, CONF_proxy_host);
733 gppi(sesskey, "ProxyPort", 80, conf, CONF_proxy_port);
734 gpps(sesskey, "ProxyUsername", "", conf, CONF_proxy_username);
735 gpps(sesskey, "ProxyPassword", "", conf, CONF_proxy_password);
0e8f4cda 736 gpps(sesskey, "ProxyTelnetCommand", "connect %host %port\\n",
4a693cfc 737 conf, CONF_proxy_telnet_command);
738 gppmap(sesskey, "Environment", conf, CONF_environmt);
739 gpps(sesskey, "UserName", "", conf, CONF_username);
740 gppi(sesskey, "UserNameFromEnvironment", 0, conf, CONF_username_from_env);
741 gpps(sesskey, "LocalUserName", "", conf, CONF_localusername);
742 gppi(sesskey, "NoPTY", 0, conf, CONF_nopty);
743 gppi(sesskey, "Compression", 0, conf, CONF_compression);
744 gppi(sesskey, "TryAgent", 1, conf, CONF_tryagent);
745 gppi(sesskey, "AgentFwd", 0, conf, CONF_agentfwd);
746 gppi(sesskey, "ChangeUsername", 0, conf, CONF_change_username);
747 gppi(sesskey, "GssapiFwd", 0, conf, CONF_gssapifwd);
e411be57 748 gprefs(sesskey, "Cipher", "\0",
4a693cfc 749 ciphernames, CIPHER_MAX, conf, CONF_ssh_cipherlist);
83e7d008 750 {
751 /* Backward-compatibility: we used to have an option to
752 * disable gex under the "bugs" panel after one report of
753 * a server which offered it then choked, but we never got
754 * a server version string or any other reports. */
755 char *default_kexes;
4a693cfc 756 i = 2 - gppi_raw(sesskey, "BugDHGEx2", 0);
83e7d008 757 if (i == FORCE_ON)
fae1a71b 758 default_kexes = "dh-group14-sha1,dh-group1-sha1,rsa,WARN,dh-gex-sha1";
83e7d008 759 else
fae1a71b 760 default_kexes = "dh-gex-sha1,dh-group14-sha1,dh-group1-sha1,rsa,WARN";
83e7d008 761 gprefs(sesskey, "KEX", default_kexes,
4a693cfc 762 kexnames, KEX_MAX, conf, CONF_ssh_kexlist);
83e7d008 763 }
4a693cfc 764 gppi(sesskey, "RekeyTime", 60, conf, CONF_ssh_rekey_time);
765 gpps(sesskey, "RekeyBytes", "1G", conf, CONF_ssh_rekey_data);
766 gppi(sesskey, "SshProt", 2, conf, CONF_sshprot);
767 gpps(sesskey, "LogHost", "", conf, CONF_loghost);
768 gppi(sesskey, "SSH2DES", 0, conf, CONF_ssh2_des_cbc);
769 gppi(sesskey, "SshNoAuth", 0, conf, CONF_ssh_no_userauth);
770 gppi(sesskey, "SshBanner", 1, conf, CONF_ssh_show_banner);
771 gppi(sesskey, "AuthTIS", 0, conf, CONF_try_tis_auth);
772 gppi(sesskey, "AuthKI", 1, conf, CONF_try_ki_auth);
773 gppi(sesskey, "AuthGSSAPI", 1, conf, CONF_try_gssapi_auth);
1e00c92b 774#ifndef NO_GSSAPI
63f305ff 775 gprefs(sesskey, "GSSLibs", "\0",
4a693cfc 776 gsslibkeywords, ngsslibs, conf, CONF_ssh_gsslist);
777 gppfile(sesskey, "GSSCustom", conf, CONF_ssh_gss_custom);
1e00c92b 778#endif
4a693cfc 779 gppi(sesskey, "SshNoShell", 0, conf, CONF_ssh_no_shell);
780 gppfile(sesskey, "PublicKeyFile", conf, CONF_keyfile);
781 gpps(sesskey, "RemoteCommand", "", conf, CONF_remote_cmd);
782 gppi(sesskey, "RFCEnviron", 0, conf, CONF_rfc_environ);
783 gppi(sesskey, "PassiveTelnet", 0, conf, CONF_passive_telnet);
784 gppi(sesskey, "BackspaceIsDelete", 1, conf, CONF_bksp_is_delete);
785 gppi(sesskey, "RXVTHomeEnd", 0, conf, CONF_rxvt_homeend);
786 gppi(sesskey, "LinuxFunctionKeys", 0, conf, CONF_funky_type);
787 gppi(sesskey, "NoApplicationKeys", 0, conf, CONF_no_applic_k);
788 gppi(sesskey, "NoApplicationCursors", 0, conf, CONF_no_applic_c);
789 gppi(sesskey, "NoMouseReporting", 0, conf, CONF_no_mouse_rep);
790 gppi(sesskey, "NoRemoteResize", 0, conf, CONF_no_remote_resize);
791 gppi(sesskey, "NoAltScreen", 0, conf, CONF_no_alt_screen);
792 gppi(sesskey, "NoRemoteWinTitle", 0, conf, CONF_no_remote_wintitle);
e65096f2 793 {
794 /* Backward compatibility */
4a693cfc 795 int no_remote_qtitle = gppi_raw(sesskey, "NoRemoteQTitle", 1);
e65096f2 796 /* We deliberately interpret the old setting of "no response" as
797 * "empty string". This changes the behaviour, but hopefully for
798 * the better; the user can always recover the old behaviour. */
799 gppi(sesskey, "RemoteQTitleAction",
800 no_remote_qtitle ? TITLE_EMPTY : TITLE_REAL,
4a693cfc 801 conf, CONF_remote_qtitle_action);
e65096f2 802 }
4a693cfc 803 gppi(sesskey, "NoDBackspace", 0, conf, CONF_no_dbackspace);
804 gppi(sesskey, "NoRemoteCharset", 0, conf, CONF_no_remote_charset);
805 gppi(sesskey, "ApplicationCursorKeys", 0, conf, CONF_app_cursor);
806 gppi(sesskey, "ApplicationKeypad", 0, conf, CONF_app_keypad);
807 gppi(sesskey, "NetHackKeypad", 0, conf, CONF_nethack_keypad);
808 gppi(sesskey, "AltF4", 1, conf, CONF_alt_f4);
809 gppi(sesskey, "AltSpace", 0, conf, CONF_alt_space);
810 gppi(sesskey, "AltOnly", 0, conf, CONF_alt_only);
811 gppi(sesskey, "ComposeKey", 0, conf, CONF_compose_key);
812 gppi(sesskey, "CtrlAltKeys", 1, conf, CONF_ctrlaltkeys);
813 gppi(sesskey, "TelnetKey", 0, conf, CONF_telnet_keyboard);
814 gppi(sesskey, "TelnetRet", 1, conf, CONF_telnet_newline);
815 gppi(sesskey, "LocalEcho", AUTO, conf, CONF_localecho);
816 gppi(sesskey, "LocalEdit", AUTO, conf, CONF_localedit);
817 gpps(sesskey, "Answerback", "PuTTY", conf, CONF_answerback);
818 gppi(sesskey, "AlwaysOnTop", 0, conf, CONF_alwaysontop);
819 gppi(sesskey, "FullScreenOnAltEnter", 0, conf, CONF_fullscreenonaltenter);
820 gppi(sesskey, "HideMousePtr", 0, conf, CONF_hide_mouseptr);
821 gppi(sesskey, "SunkenEdge", 0, conf, CONF_sunken_edge);
822 gppi(sesskey, "WindowBorder", 1, conf, CONF_window_border);
823 gppi(sesskey, "CurType", 0, conf, CONF_cursor_type);
824 gppi(sesskey, "BlinkCur", 0, conf, CONF_blink_cur);
825 /* pedantic compiler tells me I can't use conf, CONF_beep as an int * :-) */
826 gppi(sesskey, "Beep", 1, conf, CONF_beep);
827 gppi(sesskey, "BeepInd", 0, conf, CONF_beep_ind);
828 gppfile(sesskey, "BellWaveFile", conf, CONF_bell_wavefile);
829 gppi(sesskey, "BellOverload", 1, conf, CONF_bellovl);
830 gppi(sesskey, "BellOverloadN", 5, conf, CONF_bellovl_n);
831 i = gppi_raw(sesskey, "BellOverloadT", 2*TICKSPERSEC
d63db2ca 832#ifdef PUTTY_UNIX_H
833 *1000
834#endif
4a693cfc 835 );
836 conf_set_int(conf, CONF_bellovl_t, i
3c89f872 837#ifdef PUTTY_UNIX_H
4a693cfc 838 / 1000
3c89f872 839#endif
4a693cfc 840 );
841 i = gppi_raw(sesskey, "BellOverloadS", 5*TICKSPERSEC
d63db2ca 842#ifdef PUTTY_UNIX_H
843 *1000
844#endif
4a693cfc 845 );
846 conf_set_int(conf, CONF_bellovl_s, i
3c89f872 847#ifdef PUTTY_UNIX_H
4a693cfc 848 / 1000
3c89f872 849#endif
4a693cfc 850 );
8d90b8b2 851 gppi(sesskey, "ScrollbackLines", 2000, conf, CONF_savelines);
4a693cfc 852 gppi(sesskey, "DECOriginMode", 0, conf, CONF_dec_om);
853 gppi(sesskey, "AutoWrapMode", 1, conf, CONF_wrap_mode);
854 gppi(sesskey, "LFImpliesCR", 0, conf, CONF_lfhascr);
855 gppi(sesskey, "CRImpliesLF", 0, conf, CONF_crhaslf);
856 gppi(sesskey, "DisableArabicShaping", 0, conf, CONF_arabicshaping);
857 gppi(sesskey, "DisableBidi", 0, conf, CONF_bidi);
858 gppi(sesskey, "WinNameAlways", 1, conf, CONF_win_name_always);
859 gpps(sesskey, "WinTitle", "", conf, CONF_wintitle);
860 gppi(sesskey, "TermWidth", 80, conf, CONF_width);
861 gppi(sesskey, "TermHeight", 24, conf, CONF_height);
862 gppfont(sesskey, "Font", conf, CONF_font);
863 gppi(sesskey, "FontQuality", FQ_DEFAULT, conf, CONF_font_quality);
864 gppi(sesskey, "FontVTMode", VT_UNICODE, conf, CONF_vtmode);
865 gppi(sesskey, "UseSystemColours", 0, conf, CONF_system_colour);
866 gppi(sesskey, "TryPalette", 0, conf, CONF_try_palette);
867 gppi(sesskey, "ANSIColour", 1, conf, CONF_ansi_colour);
868 gppi(sesskey, "Xterm256Colour", 1, conf, CONF_xterm_256_colour);
d64bb437 869 i = gppi_raw(sesskey, "BoldAsColour", 1); conf_set_int(conf, CONF_bold_style, i+1);
f0fccd51 870
32874aea 871 for (i = 0; i < 22; i++) {
c85623f9 872 static const char *const defaults[] = {
a9422f39 873 "187,187,187", "255,255,255", "0,0,0", "85,85,85", "0,0,0",
874 "0,255,0", "0,0,0", "85,85,85", "187,0,0", "255,85,85",
875 "0,187,0", "85,255,85", "187,187,0", "255,255,85", "0,0,187",
876 "85,85,255", "187,0,187", "255,85,255", "0,187,187",
877 "85,255,255", "187,187,187", "255,255,255"
32874aea 878 };
4a693cfc 879 char buf[20], *buf2;
a9422f39 880 int c0, c1, c2;
881 sprintf(buf, "Colour%d", i);
4a693cfc 882 buf2 = gpps_raw(sesskey, buf, defaults[i]);
32874aea 883 if (sscanf(buf2, "%d,%d,%d", &c0, &c1, &c2) == 3) {
4a693cfc 884 conf_set_int_int(conf, CONF_colours, i*3+0, c0);
885 conf_set_int_int(conf, CONF_colours, i*3+1, c1);
886 conf_set_int_int(conf, CONF_colours, i*3+2, c2);
a9422f39 887 }
4a693cfc 888 sfree(buf2);
a9422f39 889 }
4a693cfc 890 gppi(sesskey, "RawCNP", 0, conf, CONF_rawcnp);
891 gppi(sesskey, "PasteRTF", 0, conf, CONF_rtf_paste);
892 gppi(sesskey, "MouseIsXterm", 0, conf, CONF_mouse_is_xterm);
893 gppi(sesskey, "RectSelect", 0, conf, CONF_rect_select);
894 gppi(sesskey, "MouseOverride", 1, conf, CONF_mouse_override);
32874aea 895 for (i = 0; i < 256; i += 32) {
c85623f9 896 static const char *const defaults[] = {
a9422f39 897 "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",
898 "0,1,2,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1",
899 "1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,2",
900 "1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1",
901 "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1",
902 "1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1",
903 "2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2",
904 "2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2"
905 };
4a693cfc 906 char buf[20], *buf2, *p;
a9422f39 907 int j;
908 sprintf(buf, "Wordness%d", i);
4a693cfc 909 buf2 = gpps_raw(sesskey, buf, defaults[i / 32]);
a9422f39 910 p = buf2;
32874aea 911 for (j = i; j < i + 32; j++) {
a9422f39 912 char *q = p;
32874aea 913 while (*p && *p != ',')
914 p++;
915 if (*p == ',')
916 *p++ = '\0';
4a693cfc 917 conf_set_int_int(conf, CONF_wordness, j, atoi(q));
a9422f39 918 }
4a693cfc 919 sfree(buf2);
a9422f39 920 }
b8ae1f0f 921 /*
922 * The empty default for LineCodePage will be converted later
923 * into a plausible default for the locale.
924 */
4a693cfc 925 gpps(sesskey, "LineCodePage", "", conf, CONF_line_codepage);
926 gppi(sesskey, "CJKAmbigWide", 0, conf, CONF_cjk_ambig_wide);
927 gppi(sesskey, "UTF8Override", 1, conf, CONF_utf8_override);
928 gpps(sesskey, "Printer", "", conf, CONF_printer);
929 gppi(sesskey, "CapsLockCyr", 0, conf, CONF_xlat_capslockcyr);
930 gppi(sesskey, "ScrollBar", 1, conf, CONF_scrollbar);
931 gppi(sesskey, "ScrollBarFullScreen", 0, conf, CONF_scrollbar_in_fullscreen);
932 gppi(sesskey, "ScrollOnKey", 0, conf, CONF_scroll_on_key);
933 gppi(sesskey, "ScrollOnDisp", 1, conf, CONF_scroll_on_disp);
934 gppi(sesskey, "EraseToScrollback", 1, conf, CONF_erase_to_scrollback);
935 gppi(sesskey, "LockSize", 0, conf, CONF_resize_action);
936 gppi(sesskey, "BCE", 1, conf, CONF_bce);
937 gppi(sesskey, "BlinkText", 0, conf, CONF_blinktext);
938 gppi(sesskey, "X11Forward", 0, conf, CONF_x11_forward);
939 gpps(sesskey, "X11Display", "", conf, CONF_x11_display);
940 gppi(sesskey, "X11AuthType", X11_MIT, conf, CONF_x11_auth);
941 gppfile(sesskey, "X11AuthFile", conf, CONF_xauthfile);
942
943 gppi(sesskey, "LocalPortAcceptAll", 0, conf, CONF_lport_acceptall);
944 gppi(sesskey, "RemotePortAcceptAll", 0, conf, CONF_rport_acceptall);
945 gppmap(sesskey, "PortForwardings", conf, CONF_portfwd);
946 i = gppi_raw(sesskey, "BugIgnore1", 0); conf_set_int(conf, CONF_sshbug_ignore1, 2-i);
947 i = gppi_raw(sesskey, "BugPlainPW1", 0); conf_set_int(conf, CONF_sshbug_plainpw1, 2-i);
948 i = gppi_raw(sesskey, "BugRSA1", 0); conf_set_int(conf, CONF_sshbug_rsa1, 2-i);
949 i = gppi_raw(sesskey, "BugIgnore2", 0); conf_set_int(conf, CONF_sshbug_ignore2, 2-i);
2c9c6388 950 {
951 int i;
4a693cfc 952 i = gppi_raw(sesskey, "BugHMAC2", 0); conf_set_int(conf, CONF_sshbug_hmac2, 2-i);
953 if (2-i == AUTO) {
954 i = gppi_raw(sesskey, "BuggyMAC", 0);
2c9c6388 955 if (i == 1)
4a693cfc 956 conf_set_int(conf, CONF_sshbug_hmac2, FORCE_ON);
2c9c6388 957 }
958 }
4a693cfc 959 i = gppi_raw(sesskey, "BugDeriveKey2", 0); conf_set_int(conf, CONF_sshbug_derivekey2, 2-i);
960 i = gppi_raw(sesskey, "BugRSAPad2", 0); conf_set_int(conf, CONF_sshbug_rsapad2, 2-i);
961 i = gppi_raw(sesskey, "BugPKSessID2", 0); conf_set_int(conf, CONF_sshbug_pksessid2, 2-i);
962 i = gppi_raw(sesskey, "BugRekey2", 0); conf_set_int(conf, CONF_sshbug_rekey2, 2-i);
963 i = gppi_raw(sesskey, "BugMaxPkt2", 0); conf_set_int(conf, CONF_sshbug_maxpkt2, 2-i);
2e0aae4f 964 i = gppi_raw(sesskey, "BugWinadj", 0); conf_set_int(conf, CONF_sshbug_winadj, 2-i);
4a693cfc 965 conf_set_int(conf, CONF_ssh_simple, FALSE);
966 gppi(sesskey, "StampUtmp", 1, conf, CONF_stamp_utmp);
967 gppi(sesskey, "LoginShell", 1, conf, CONF_login_shell);
968 gppi(sesskey, "ScrollbarOnLeft", 0, conf, CONF_scrollbar_on_left);
969 gppi(sesskey, "ShadowBold", 0, conf, CONF_shadowbold);
970 gppfont(sesskey, "BoldFont", conf, CONF_boldfont);
971 gppfont(sesskey, "WideFont", conf, CONF_widefont);
972 gppfont(sesskey, "WideBoldFont", conf, CONF_wideboldfont);
973 gppi(sesskey, "ShadowBoldOffset", 1, conf, CONF_shadowboldoffset);
974 gpps(sesskey, "SerialLine", "", conf, CONF_serline);
975 gppi(sesskey, "SerialSpeed", 9600, conf, CONF_serspeed);
976 gppi(sesskey, "SerialDataBits", 8, conf, CONF_serdatabits);
977 gppi(sesskey, "SerialStopHalfbits", 2, conf, CONF_serstopbits);
978 gppi(sesskey, "SerialParity", SER_PAR_NONE, conf, CONF_serparity);
979 gppi(sesskey, "SerialFlowControl", SER_FLOW_XONXOFF, conf, CONF_serflow);
980 gpps(sesskey, "WindowClass", "", conf, CONF_winclass);
a9422f39 981}
982
4a693cfc 983void do_defaults(char *session, Conf *conf)
32874aea 984{
4a693cfc 985 load_settings(session, conf);
a9422f39 986}
987
32874aea 988static int sessioncmp(const void *av, const void *bv)
989{
990 const char *a = *(const char *const *) av;
991 const char *b = *(const char *const *) bv;
a84ca2f5 992
993 /*
994 * Alphabetical order, except that "Default Settings" is a
995 * special case and comes first.
996 */
997 if (!strcmp(a, "Default Settings"))
32874aea 998 return -1; /* a comes first */
a84ca2f5 999 if (!strcmp(b, "Default Settings"))
32874aea 1000 return +1; /* b comes first */
78a8d889 1001 /*
1002 * FIXME: perhaps we should ignore the first & in determining
1003 * sort order.
1004 */
32874aea 1005 return strcmp(a, b); /* otherwise, compare normally */
a84ca2f5 1006}
1007
0b4f0bc0 1008void get_sesslist(struct sesslist *list, int allocate)
32874aea 1009{
0b4f0bc0 1010 char otherbuf[2048];
a9422f39 1011 int buflen, bufsize, i;
1012 char *p, *ret;
1013 void *handle;
1014
1015 if (allocate) {
32874aea 1016
a9422f39 1017 buflen = bufsize = 0;
0b4f0bc0 1018 list->buffer = NULL;
1728c012 1019 if ((handle = enum_settings_start()) != NULL) {
5f2df4d2 1020 do {
1021 ret = enum_settings_next(handle, otherbuf, sizeof(otherbuf));
1022 if (ret) {
1023 int len = strlen(otherbuf) + 1;
1024 if (bufsize < buflen + len) {
1025 bufsize = buflen + len + 2048;
3d88e64d 1026 list->buffer = sresize(list->buffer, bufsize, char);
5f2df4d2 1027 }
0b4f0bc0 1028 strcpy(list->buffer + buflen, otherbuf);
1029 buflen += strlen(list->buffer + buflen) + 1;
32874aea 1030 }
5f2df4d2 1031 } while (ret);
1032 enum_settings_finish(handle);
1033 }
3d88e64d 1034 list->buffer = sresize(list->buffer, buflen + 1, char);
0b4f0bc0 1035 list->buffer[buflen] = '\0';
a9422f39 1036
2221af18 1037 /*
1038 * Now set up the list of sessions. Note that "Default
1039 * Settings" must always be claimed to exist, even if it
1040 * doesn't really.
1041 */
1042
0b4f0bc0 1043 p = list->buffer;
1044 list->nsessions = 1; /* "Default Settings" counts as one */
a9422f39 1045 while (*p) {
32874aea 1046 if (strcmp(p, "Default Settings"))
0b4f0bc0 1047 list->nsessions++;
32874aea 1048 while (*p)
1049 p++;
a9422f39 1050 p++;
1051 }
1052
3d88e64d 1053 list->sessions = snewn(list->nsessions + 1, char *);
0b4f0bc0 1054 list->sessions[0] = "Default Settings";
1055 p = list->buffer;
2221af18 1056 i = 1;
a9422f39 1057 while (*p) {
32874aea 1058 if (strcmp(p, "Default Settings"))
0b4f0bc0 1059 list->sessions[i++] = p;
32874aea 1060 while (*p)
1061 p++;
a9422f39 1062 p++;
1063 }
a84ca2f5 1064
0b4f0bc0 1065 qsort(list->sessions, i, sizeof(char *), sessioncmp);
a9422f39 1066 } else {
0b4f0bc0 1067 sfree(list->buffer);
1068 sfree(list->sessions);
c6fa3909 1069 list->buffer = NULL;
1070 list->sessions = NULL;
a9422f39 1071 }
1072}