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