Readjust checklist, because actually the section on updating the
[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
471c20b0 73int get_remote_username(Config *cfg, char *user, size_t len)
74{
75 if (*cfg->username) {
76 strncpy(user, cfg->username, len);
77 user[len-1] = '\0';
78 } else {
79 if (cfg->username_from_env) {
80 /* Use local username. */
81 char *luser = get_username();
4c26bb50 82 if (luser) {
83 strncpy(user, luser, len);
84 user[len-1] = '\0';
85 sfree(luser);
86 } else {
87 *user = '\0';
88 }
471c20b0 89 } else {
90 *user = '\0';
91 }
92 }
93 return (*user != '\0');
94}
95
c85623f9 96static void gpps(void *handle, const char *name, const char *def,
97 char *val, int len)
32874aea 98{
a9422f39 99 if (!read_setting_s(handle, name, val, len)) {
5a9eb105 100 char *pdef;
101
102 pdef = platform_default_s(name);
103 if (pdef) {
104 strncpy(val, pdef, len);
799dfcfa 105 sfree(pdef);
5a9eb105 106 } else {
107 strncpy(val, def, len);
108 }
109
32874aea 110 val[len - 1] = '\0';
a9422f39 111 }
112}
113
9a30e26b 114/*
115 * gppfont and gppfile cannot have local defaults, since the very
116 * format of a Filename or Font is platform-dependent. So the
117 * platform-dependent functions MUST return some sort of value.
118 */
119static void gppfont(void *handle, const char *name, FontSpec *result)
120{
121 if (!read_setting_fontspec(handle, name, result))
122 *result = platform_default_fontspec(name);
123}
124static void gppfile(void *handle, const char *name, Filename *result)
125{
126 if (!read_setting_filename(handle, name, result))
127 *result = platform_default_filename(name);
128}
129
32874aea 130static void gppi(void *handle, char *name, int def, int *i)
131{
5a9eb105 132 def = platform_default_i(name, def);
a9422f39 133 *i = read_setting_i(handle, name, def);
134}
135
b50ee9a8 136/*
137 * Read a set of name-value pairs in the format we occasionally use:
138 * NAME\tVALUE\0NAME\tVALUE\0\0 in memory
139 * NAME=VALUE,NAME=VALUE, in storage
140 * `def' is in the storage format.
141 */
142static void gppmap(void *handle, char *name, char *def, char *val, int len)
143{
144 char *buf = snewn(2*len, char), *p, *q;
145 gpps(handle, name, def, buf, 2*len);
146 p = buf;
147 q = val;
148 while (*p) {
149 while (*p && *p != ',') {
150 int c = *p++;
151 if (c == '=')
152 c = '\t';
153 if (c == '\\')
154 c = *p++;
155 *q++ = c;
156 }
157 if (*p == ',')
158 p++;
159 *q++ = '\0';
160 }
161 *q = '\0';
162 sfree(buf);
163}
164
165/*
166 * Write a set of name/value pairs in the above format.
167 */
168static void wmap(void *handle, char const *key, char const *value, int len)
169{
170 char *buf = snewn(2*len, char), *p;
171 const char *q;
172 p = buf;
173 q = value;
174 while (*q) {
175 while (*q) {
176 int c = *q++;
177 if (c == '=' || c == ',' || c == '\\')
178 *p++ = '\\';
179 if (c == '\t')
180 c = '=';
181 *p++ = c;
182 }
183 *p++ = ',';
184 q++;
185 }
186 *p = '\0';
187 write_setting_s(handle, key, buf);
188 sfree(buf);
189}
190
4ceef224 191static int key2val(const struct keyvalwhere *mapping,
192 int nmaps, char *key)
ca20bfcf 193{
194 int i;
195 for (i = 0; i < nmaps; i++)
196 if (!strcmp(mapping[i].s, key)) return mapping[i].v;
197 return -1;
198}
199
4ceef224 200static const char *val2key(const struct keyvalwhere *mapping,
201 int nmaps, int val)
ca20bfcf 202{
203 int i;
204 for (i = 0; i < nmaps; i++)
205 if (mapping[i].v == val) return mapping[i].s;
206 return NULL;
207}
208
209/*
210 * Helper function to parse a comma-separated list of strings into
211 * a preference list array of values. Any missing values are added
212 * to the end and duplicates are weeded.
213 * XXX: assumes vals in 'mapping' are small +ve integers
214 */
215static void gprefs(void *sesskey, char *name, char *def,
4ceef224 216 const struct keyvalwhere *mapping, int nvals,
ca20bfcf 217 int *array)
218{
4ceef224 219 char commalist[256];
220 char *p, *q;
221 int i, j, n, v, pos;
ca20bfcf 222 unsigned long seen = 0; /* bitmap for weeding dups etc */
4ceef224 223
224 /*
225 * Fetch the string which we'll parse as a comma-separated list.
226 */
ca20bfcf 227 gpps(sesskey, name, def, commalist, sizeof(commalist));
228
4ceef224 229 /*
230 * Go through that list and convert it into values.
231 */
ca20bfcf 232 n = 0;
4ceef224 233 p = commalist;
234 while (1) {
235 while (*p && *p == ',') p++;
236 if (!*p)
237 break; /* no more words */
238
239 q = p;
240 while (*p && *p != ',') p++;
241 if (*p) *p++ = '\0';
242
243 v = key2val(mapping, nvals, q);
244 if (v != -1 && !(seen & (1 << v))) {
245 seen |= (1 << v);
246 array[n++] = v;
ca20bfcf 247 }
4ceef224 248 }
249
250 /*
251 * Now go through 'mapping' and add values that weren't mentioned
252 * in the list we fetched. We may have to loop over it multiple
253 * times so that we add values before other values whose default
254 * positions depend on them.
255 */
256 while (n < nvals) {
257 for (i = 0; i < nvals; i++) {
5cc5734b 258 assert(mapping[i].v < 32);
4ceef224 259
260 if (!(seen & (1 << mapping[i].v))) {
261 /*
262 * This element needs adding. But can we add it yet?
263 */
264 if (mapping[i].vrel != -1 && !(seen & (1 << mapping[i].vrel)))
265 continue; /* nope */
266
267 /*
268 * OK, we can work out where to add this element, so
269 * do so.
270 */
271 if (mapping[i].vrel == -1) {
272 pos = (mapping[i].where < 0 ? n : 0);
273 } else {
274 for (j = 0; j < n; j++)
275 if (array[j] == mapping[i].vrel)
276 break;
277 assert(j < n); /* implied by (seen & (1<<vrel)) */
278 pos = (mapping[i].where < 0 ? j : j+1);
279 }
280
281 /*
282 * And add it.
283 */
284 for (j = n-1; j >= pos; j--)
285 array[j+1] = array[j];
286 array[pos] = mapping[i].v;
287 n++;
288 }
289 }
ca20bfcf 290 }
291}
292
293/*
294 * Write out a preference list.
295 */
296static void wprefs(void *sesskey, char *name,
4ceef224 297 const struct keyvalwhere *mapping, int nvals,
ca20bfcf 298 int *array)
299{
4ceef224 300 char *buf, *p;
301 int i, maxlen;
302
303 for (maxlen = i = 0; i < nvals; i++) {
ca20bfcf 304 const char *s = val2key(mapping, nvals, array[i]);
305 if (s) {
4ceef224 306 maxlen += 1 + strlen(s);
307 }
308 }
309
310 buf = snewn(maxlen, char);
311 p = buf;
312
313 for (i = 0; i < nvals; i++) {
314 const char *s = val2key(mapping, nvals, array[i]);
315 if (s) {
316 p += sprintf(p, "%s%s", (p > buf ? "," : ""), s);
ca20bfcf 317 }
318 }
4ceef224 319
320 assert(p - buf == maxlen - 1); /* maxlen counted the NUL */
321
ca20bfcf 322 write_setting_s(sesskey, name, buf);
4ceef224 323
324 sfree(buf);
ca20bfcf 325}
326
47b5a6ae 327char *save_settings(char *section, Config * cfg)
32874aea 328{
a9422f39 329 void *sesskey;
3f935d5b 330 char *errmsg;
a9422f39 331
3f935d5b 332 sesskey = open_settings_w(section, &errmsg);
a9422f39 333 if (!sesskey)
3f935d5b 334 return errmsg;
47b5a6ae 335 save_open_settings(sesskey, cfg);
b537dd42 336 close_settings_w(sesskey);
3f935d5b 337 return NULL;
b537dd42 338}
339
47b5a6ae 340void save_open_settings(void *sesskey, Config *cfg)
b537dd42 341{
342 int i;
343 char *p;
a9422f39 344
32874aea 345 write_setting_i(sesskey, "Present", 1);
47b5a6ae 346 write_setting_s(sesskey, "HostName", cfg->host);
c98aef5d 347 write_setting_filename(sesskey, "LogFileName", cfg->logfilename);
348 write_setting_i(sesskey, "LogType", cfg->logtype);
349 write_setting_i(sesskey, "LogFileClash", cfg->logxfovr);
6d60c791 350 write_setting_i(sesskey, "LogFlush", cfg->logflush);
9a10ecf4 351 write_setting_i(sesskey, "SSHLogOmitPasswords", cfg->logomitpass);
352 write_setting_i(sesskey, "SSHLogOmitData", cfg->logomitdata);
348a9ad6 353 p = "raw";
9e164d82 354 {
355 const Backend *b = backend_from_proto(cfg->protocol);
356 if (b)
357 p = b->name;
358 }
348a9ad6 359 write_setting_s(sesskey, "Protocol", p);
360 write_setting_i(sesskey, "PortNumber", cfg->port);
88103a48 361 /* The CloseOnExit numbers are arranged in a different order from
362 * the standard FORCE_ON / FORCE_OFF / AUTO. */
363 write_setting_i(sesskey, "CloseOnExit", (cfg->close_on_exit+2)%3);
32874aea 364 write_setting_i(sesskey, "WarnOnClose", !!cfg->warn_on_close);
365 write_setting_i(sesskey, "PingInterval", cfg->ping_interval / 60); /* minutes */
366 write_setting_i(sesskey, "PingIntervalSecs", cfg->ping_interval % 60); /* seconds */
2184a5d9 367 write_setting_i(sesskey, "TCPNoDelay", cfg->tcp_nodelay);
79bf227b 368 write_setting_i(sesskey, "TCPKeepalives", cfg->tcp_keepalives);
32874aea 369 write_setting_s(sesskey, "TerminalType", cfg->termtype);
370 write_setting_s(sesskey, "TerminalSpeed", cfg->termspeed);
c6ccd5c2 371 wmap(sesskey, "TerminalModes", cfg->ttymodes, lenof(cfg->ttymodes));
8eebd221 372
05581745 373 /* Address family selection */
374 write_setting_i(sesskey, "AddressFamily", cfg->addressfamily);
375
8eebd221 376 /* proxy settings */
377 write_setting_s(sesskey, "ProxyExcludeList", cfg->proxy_exclude_list);
88103a48 378 write_setting_i(sesskey, "ProxyDNS", (cfg->proxy_dns+2)%3);
b804e1e5 379 write_setting_i(sesskey, "ProxyLocalhost", cfg->even_proxy_localhost);
10068a0b 380 write_setting_i(sesskey, "ProxyMethod", cfg->proxy_type);
8eebd221 381 write_setting_s(sesskey, "ProxyHost", cfg->proxy_host);
382 write_setting_i(sesskey, "ProxyPort", cfg->proxy_port);
383 write_setting_s(sesskey, "ProxyUsername", cfg->proxy_username);
384 write_setting_s(sesskey, "ProxyPassword", cfg->proxy_password);
385 write_setting_s(sesskey, "ProxyTelnetCommand", cfg->proxy_telnet_command);
b50ee9a8 386 wmap(sesskey, "Environment", cfg->environmt, lenof(cfg->environmt));
32874aea 387 write_setting_s(sesskey, "UserName", cfg->username);
471c20b0 388 write_setting_i(sesskey, "UserNameFromEnvironment", cfg->username_from_env);
32874aea 389 write_setting_s(sesskey, "LocalUserName", cfg->localusername);
390 write_setting_i(sesskey, "NoPTY", cfg->nopty);
391 write_setting_i(sesskey, "Compression", cfg->compression);
973612f5 392 write_setting_i(sesskey, "TryAgent", cfg->tryagent);
32874aea 393 write_setting_i(sesskey, "AgentFwd", cfg->agentfwd);
42af6a67 394 write_setting_i(sesskey, "GssapiFwd", cfg->gssapifwd);
5bb641e1 395 write_setting_i(sesskey, "ChangeUsername", cfg->change_username);
e411be57 396 wprefs(sesskey, "Cipher", ciphernames, CIPHER_MAX,
ca20bfcf 397 cfg->ssh_cipherlist);
83e7d008 398 wprefs(sesskey, "KEX", kexnames, KEX_MAX, cfg->ssh_kexlist);
d57f70af 399 write_setting_i(sesskey, "RekeyTime", cfg->ssh_rekey_time);
400 write_setting_s(sesskey, "RekeyBytes", cfg->ssh_rekey_data);
a1a1fae4 401 write_setting_i(sesskey, "SshNoAuth", cfg->ssh_no_userauth);
adb6167a 402 write_setting_i(sesskey, "SshBanner", cfg->ssh_show_banner);
32874aea 403 write_setting_i(sesskey, "AuthTIS", cfg->try_tis_auth);
f091e308 404 write_setting_i(sesskey, "AuthKI", cfg->try_ki_auth);
42af6a67 405 write_setting_i(sesskey, "AuthGSSAPI", cfg->try_gssapi_auth);
1e00c92b 406#ifndef NO_GSSAPI
b3d375b2 407 wprefs(sesskey, "GSSLibs", gsslibkeywords, ngsslibs,
408 cfg->ssh_gsslist);
1e00c92b 409 write_setting_filename(sesskey, "GSSCustom", cfg->ssh_gss_custom);
410#endif
0ed48730 411 write_setting_i(sesskey, "SshNoShell", cfg->ssh_no_shell);
32874aea 412 write_setting_i(sesskey, "SshProt", cfg->sshprot);
881da168 413 write_setting_s(sesskey, "LogHost", cfg->loghost);
cb4d4768 414 write_setting_i(sesskey, "SSH2DES", cfg->ssh2_des_cbc);
9a30e26b 415 write_setting_filename(sesskey, "PublicKeyFile", cfg->keyfile);
32874aea 416 write_setting_s(sesskey, "RemoteCommand", cfg->remote_cmd);
417 write_setting_i(sesskey, "RFCEnviron", cfg->rfc_environ);
8faa456c 418 write_setting_i(sesskey, "PassiveTelnet", cfg->passive_telnet);
32874aea 419 write_setting_i(sesskey, "BackspaceIsDelete", cfg->bksp_is_delete);
420 write_setting_i(sesskey, "RXVTHomeEnd", cfg->rxvt_homeend);
421 write_setting_i(sesskey, "LinuxFunctionKeys", cfg->funky_type);
422 write_setting_i(sesskey, "NoApplicationKeys", cfg->no_applic_k);
423 write_setting_i(sesskey, "NoApplicationCursors", cfg->no_applic_c);
c0d36a72 424 write_setting_i(sesskey, "NoMouseReporting", cfg->no_mouse_rep);
0d2086c5 425 write_setting_i(sesskey, "NoRemoteResize", cfg->no_remote_resize);
426 write_setting_i(sesskey, "NoAltScreen", cfg->no_alt_screen);
427 write_setting_i(sesskey, "NoRemoteWinTitle", cfg->no_remote_wintitle);
e65096f2 428 write_setting_i(sesskey, "RemoteQTitleAction", cfg->remote_qtitle_action);
0d2086c5 429 write_setting_i(sesskey, "NoDBackspace", cfg->no_dbackspace);
430 write_setting_i(sesskey, "NoRemoteCharset", cfg->no_remote_charset);
32874aea 431 write_setting_i(sesskey, "ApplicationCursorKeys", cfg->app_cursor);
432 write_setting_i(sesskey, "ApplicationKeypad", cfg->app_keypad);
433 write_setting_i(sesskey, "NetHackKeypad", cfg->nethack_keypad);
434 write_setting_i(sesskey, "AltF4", cfg->alt_f4);
435 write_setting_i(sesskey, "AltSpace", cfg->alt_space);
436 write_setting_i(sesskey, "AltOnly", cfg->alt_only);
437 write_setting_i(sesskey, "ComposeKey", cfg->compose_key);
438 write_setting_i(sesskey, "CtrlAltKeys", cfg->ctrlaltkeys);
a5f3e637 439 write_setting_i(sesskey, "TelnetKey", cfg->telnet_keyboard);
eee63b77 440 write_setting_i(sesskey, "TelnetRet", cfg->telnet_newline);
32874aea 441 write_setting_i(sesskey, "LocalEcho", cfg->localecho);
442 write_setting_i(sesskey, "LocalEdit", cfg->localedit);
443 write_setting_s(sesskey, "Answerback", cfg->answerback);
444 write_setting_i(sesskey, "AlwaysOnTop", cfg->alwaysontop);
8f57d753 445 write_setting_i(sesskey, "FullScreenOnAltEnter", cfg->fullscreenonaltenter);
32874aea 446 write_setting_i(sesskey, "HideMousePtr", cfg->hide_mouseptr);
447 write_setting_i(sesskey, "SunkenEdge", cfg->sunken_edge);
5a73255e 448 write_setting_i(sesskey, "WindowBorder", cfg->window_border);
32874aea 449 write_setting_i(sesskey, "CurType", cfg->cursor_type);
450 write_setting_i(sesskey, "BlinkCur", cfg->blink_cur);
451 write_setting_i(sesskey, "Beep", cfg->beep);
f8a28d1f 452 write_setting_i(sesskey, "BeepInd", cfg->beep_ind);
9a30e26b 453 write_setting_filename(sesskey, "BellWaveFile", cfg->bell_wavefile);
32874aea 454 write_setting_i(sesskey, "BellOverload", cfg->bellovl);
455 write_setting_i(sesskey, "BellOverloadN", cfg->bellovl_n);
3c89f872 456 write_setting_i(sesskey, "BellOverloadT", cfg->bellovl_t
457#ifdef PUTTY_UNIX_H
458 * 1000
459#endif
460 );
461 write_setting_i(sesskey, "BellOverloadS", cfg->bellovl_s
462#ifdef PUTTY_UNIX_H
463 * 1000
464#endif
465 );
32874aea 466 write_setting_i(sesskey, "ScrollbackLines", cfg->savelines);
467 write_setting_i(sesskey, "DECOriginMode", cfg->dec_om);
468 write_setting_i(sesskey, "AutoWrapMode", cfg->wrap_mode);
469 write_setting_i(sesskey, "LFImpliesCR", cfg->lfhascr);
7612f22f 470 write_setting_i(sesskey, "CRImpliesLF", cfg->crhaslf);
f0fccd51 471 write_setting_i(sesskey, "DisableArabicShaping", cfg->arabicshaping);
472 write_setting_i(sesskey, "DisableBidi", cfg->bidi);
32874aea 473 write_setting_i(sesskey, "WinNameAlways", cfg->win_name_always);
474 write_setting_s(sesskey, "WinTitle", cfg->wintitle);
475 write_setting_i(sesskey, "TermWidth", cfg->width);
476 write_setting_i(sesskey, "TermHeight", cfg->height);
9a30e26b 477 write_setting_fontspec(sesskey, "Font", cfg->font);
17c7fed1 478 write_setting_i(sesskey, "FontQuality", cfg->font_quality);
32874aea 479 write_setting_i(sesskey, "FontVTMode", cfg->vtmode);
26d1da7b 480 write_setting_i(sesskey, "UseSystemColours", cfg->system_colour);
32874aea 481 write_setting_i(sesskey, "TryPalette", cfg->try_palette);
c6f1b8ed 482 write_setting_i(sesskey, "ANSIColour", cfg->ansi_colour);
cecb13f6 483 write_setting_i(sesskey, "Xterm256Colour", cfg->xterm_256_colour);
32874aea 484 write_setting_i(sesskey, "BoldAsColour", cfg->bold_colour);
f0fccd51 485
32874aea 486 for (i = 0; i < 22; i++) {
a9422f39 487 char buf[20], buf2[30];
488 sprintf(buf, "Colour%d", i);
489 sprintf(buf2, "%d,%d,%d", cfg->colours[i][0],
490 cfg->colours[i][1], cfg->colours[i][2]);
32874aea 491 write_setting_s(sesskey, buf, buf2);
a9422f39 492 }
32874aea 493 write_setting_i(sesskey, "RawCNP", cfg->rawcnp);
a7419ea4 494 write_setting_i(sesskey, "PasteRTF", cfg->rtf_paste);
32874aea 495 write_setting_i(sesskey, "MouseIsXterm", cfg->mouse_is_xterm);
6908fed7 496 write_setting_i(sesskey, "RectSelect", cfg->rect_select);
b90840c3 497 write_setting_i(sesskey, "MouseOverride", cfg->mouse_override);
32874aea 498 for (i = 0; i < 256; i += 32) {
a9422f39 499 char buf[20], buf2[256];
500 int j;
501 sprintf(buf, "Wordness%d", i);
502 *buf2 = '\0';
32874aea 503 for (j = i; j < i + 32; j++) {
504 sprintf(buf2 + strlen(buf2), "%s%d",
a9422f39 505 (*buf2 ? "," : ""), cfg->wordness[j]);
506 }
32874aea 507 write_setting_s(sesskey, buf, buf2);
a9422f39 508 }
4eeb7d09 509 write_setting_s(sesskey, "LineCodePage", cfg->line_codepage);
74790953 510 write_setting_i(sesskey, "CJKAmbigWide", cfg->cjk_ambig_wide);
6ac7f054 511 write_setting_i(sesskey, "UTF8Override", cfg->utf8_override);
b44b307a 512 write_setting_s(sesskey, "Printer", cfg->printer);
a9c02454 513 write_setting_i(sesskey, "CapsLockCyr", cfg->xlat_capslockcyr);
32874aea 514 write_setting_i(sesskey, "ScrollBar", cfg->scrollbar);
a401e5f3 515 write_setting_i(sesskey, "ScrollBarFullScreen", cfg->scrollbar_in_fullscreen);
32874aea 516 write_setting_i(sesskey, "ScrollOnKey", cfg->scroll_on_key);
517 write_setting_i(sesskey, "ScrollOnDisp", cfg->scroll_on_disp);
876e5d5e 518 write_setting_i(sesskey, "EraseToScrollback", cfg->erase_to_scrollback);
ad5c93cc 519 write_setting_i(sesskey, "LockSize", cfg->resize_action);
32874aea 520 write_setting_i(sesskey, "BCE", cfg->bce);
521 write_setting_i(sesskey, "BlinkText", cfg->blinktext);
522 write_setting_i(sesskey, "X11Forward", cfg->x11_forward);
523 write_setting_s(sesskey, "X11Display", cfg->x11_display);
b3ebaa28 524 write_setting_i(sesskey, "X11AuthType", cfg->x11_auth);
8def70c3 525 write_setting_filename(sesskey, "X11AuthFile", cfg->xauthfile);
d74d141c 526 write_setting_i(sesskey, "LocalPortAcceptAll", cfg->lport_acceptall);
beefa433 527 write_setting_i(sesskey, "RemotePortAcceptAll", cfg->rport_acceptall);
b50ee9a8 528 wmap(sesskey, "PortForwardings", cfg->portfwd, lenof(cfg->portfwd));
88103a48 529 write_setting_i(sesskey, "BugIgnore1", 2-cfg->sshbug_ignore1);
530 write_setting_i(sesskey, "BugPlainPW1", 2-cfg->sshbug_plainpw1);
531 write_setting_i(sesskey, "BugRSA1", 2-cfg->sshbug_rsa1);
cf6ddb95 532 write_setting_i(sesskey, "BugIgnore2", 2-cfg->sshbug_ignore2);
88103a48 533 write_setting_i(sesskey, "BugHMAC2", 2-cfg->sshbug_hmac2);
534 write_setting_i(sesskey, "BugDeriveKey2", 2-cfg->sshbug_derivekey2);
535 write_setting_i(sesskey, "BugRSAPad2", 2-cfg->sshbug_rsapad2);
dda87a28 536 write_setting_i(sesskey, "BugPKSessID2", 2-cfg->sshbug_pksessid2);
e111b81f 537 write_setting_i(sesskey, "BugRekey2", 2-cfg->sshbug_rekey2);
c9739dba 538 write_setting_i(sesskey, "BugMaxPkt2", 2-cfg->sshbug_maxpkt2);
c8ee61b9 539 write_setting_i(sesskey, "StampUtmp", cfg->stamp_utmp);
540 write_setting_i(sesskey, "LoginShell", cfg->login_shell);
239b3b36 541 write_setting_i(sesskey, "ScrollbarOnLeft", cfg->scrollbar_on_left);
9a30e26b 542 write_setting_fontspec(sesskey, "BoldFont", cfg->boldfont);
2331d513 543 write_setting_fontspec(sesskey, "WideFont", cfg->widefont);
544 write_setting_fontspec(sesskey, "WideBoldFont", cfg->wideboldfont);
bf133a73 545 write_setting_i(sesskey, "ShadowBold", cfg->shadowbold);
12994a99 546 write_setting_i(sesskey, "ShadowBoldOffset", cfg->shadowboldoffset);
7374c779 547 write_setting_s(sesskey, "SerialLine", cfg->serline);
548 write_setting_i(sesskey, "SerialSpeed", cfg->serspeed);
549 write_setting_i(sesskey, "SerialDataBits", cfg->serdatabits);
550 write_setting_i(sesskey, "SerialStopHalfbits", cfg->serstopbits);
551 write_setting_i(sesskey, "SerialParity", cfg->serparity);
552 write_setting_i(sesskey, "SerialFlowControl", cfg->serflow);
3e4a1fd7 553 write_setting_s(sesskey, "WindowClass", cfg->winclass);
a9422f39 554}
555
47b5a6ae 556void load_settings(char *section, Config * cfg)
32874aea 557{
a9422f39 558 void *sesskey;
559
560 sesskey = open_settings_r(section);
47b5a6ae 561 load_open_settings(sesskey, cfg);
ce283213 562 close_settings_r(sesskey);
073e9f42 563
564 if (cfg_launchable(cfg))
565 add_session_to_jumplist(section);
ce283213 566}
567
47b5a6ae 568void load_open_settings(void *sesskey, Config *cfg)
ce283213 569{
570 int i;
571 char prot[10];
a9422f39 572
32874aea 573 cfg->ssh_subsys = 0; /* FIXME: load this properly */
04c52f10 574 cfg->remote_cmd_ptr = NULL;
fd5e5847 575 cfg->remote_cmd_ptr2 = NULL;
7f5749db 576 cfg->ssh_nc_host[0] = '\0';
a9100732 577
47b5a6ae 578 gpps(sesskey, "HostName", "", cfg->host, sizeof(cfg->host));
9a30e26b 579 gppfile(sesskey, "LogFileName", &cfg->logfilename);
32874aea 580 gppi(sesskey, "LogType", 0, &cfg->logtype);
581 gppi(sesskey, "LogFileClash", LGXF_ASK, &cfg->logxfovr);
6d60c791 582 gppi(sesskey, "LogFlush", 1, &cfg->logflush);
9a10ecf4 583 gppi(sesskey, "SSHLogOmitPasswords", 1, &cfg->logomitpass);
584 gppi(sesskey, "SSHLogOmitData", 0, &cfg->logomitdata);
a9422f39 585
32874aea 586 gpps(sesskey, "Protocol", "default", prot, 10);
a9422f39 587 cfg->protocol = default_protocol;
1ff52e17 588 cfg->port = default_port;
9e164d82 589 {
590 const Backend *b = backend_from_name(prot);
591 if (b) {
592 cfg->protocol = b->protocol;
1ff52e17 593 gppi(sesskey, "PortNumber", default_port, &cfg->port);
32874aea 594 }
9e164d82 595 }
a9422f39 596
05581745 597 /* Address family selection */
598 gppi(sesskey, "AddressFamily", ADDRTYPE_UNSPEC, &cfg->addressfamily);
599
88103a48 600 /* The CloseOnExit numbers are arranged in a different order from
601 * the standard FORCE_ON / FORCE_OFF / AUTO. */
602 gppi(sesskey, "CloseOnExit", 1, &i); cfg->close_on_exit = (i+1)%3;
32874aea 603 gppi(sesskey, "WarnOnClose", 1, &cfg->warn_on_close);
edce8e45 604 {
32874aea 605 /* This is two values for backward compatibility with 0.50/0.51 */
606 int pingmin, pingsec;
607 gppi(sesskey, "PingInterval", 0, &pingmin);
608 gppi(sesskey, "PingIntervalSecs", 0, &pingsec);
609 cfg->ping_interval = pingmin * 60 + pingsec;
edce8e45 610 }
2184a5d9 611 gppi(sesskey, "TCPNoDelay", 1, &cfg->tcp_nodelay);
79bf227b 612 gppi(sesskey, "TCPKeepalives", 0, &cfg->tcp_keepalives);
32874aea 613 gpps(sesskey, "TerminalType", "xterm", cfg->termtype,
614 sizeof(cfg->termtype));
615 gpps(sesskey, "TerminalSpeed", "38400,38400", cfg->termspeed,
616 sizeof(cfg->termspeed));
c6ccd5c2 617 {
618 /* This hardcodes a big set of defaults in any new saved
619 * sessions. Let's hope we don't change our mind. */
620 int i;
621 char *def = dupstr("");
622 /* Default: all set to "auto" */
623 for (i = 0; ttymodes[i]; i++) {
624 char *def2 = dupprintf("%s%s=A,", def, ttymodes[i]);
625 sfree(def);
626 def = def2;
627 }
628 gppmap(sesskey, "TerminalModes", def,
629 cfg->ttymodes, lenof(cfg->ttymodes));
630 sfree(def);
631 }
8eebd221 632
633 /* proxy settings */
634 gpps(sesskey, "ProxyExcludeList", "", cfg->proxy_exclude_list,
635 sizeof(cfg->proxy_exclude_list));
88103a48 636 gppi(sesskey, "ProxyDNS", 1, &i); cfg->proxy_dns = (i+1)%3;
b804e1e5 637 gppi(sesskey, "ProxyLocalhost", 0, &cfg->even_proxy_localhost);
10068a0b 638 gppi(sesskey, "ProxyMethod", -1, &cfg->proxy_type);
639 if (cfg->proxy_type == -1) {
640 int i;
d14b9ab2 641 gppi(sesskey, "ProxyType", 0, &i);
10068a0b 642 if (i == 0)
643 cfg->proxy_type = PROXY_NONE;
644 else if (i == 1)
645 cfg->proxy_type = PROXY_HTTP;
646 else if (i == 3)
647 cfg->proxy_type = PROXY_TELNET;
648 else if (i == 4)
649 cfg->proxy_type = PROXY_CMD;
650 else {
651 gppi(sesskey, "ProxySOCKSVersion", 5, &i);
652 if (i == 5)
653 cfg->proxy_type = PROXY_SOCKS5;
654 else
655 cfg->proxy_type = PROXY_SOCKS4;
656 }
657 }
8eebd221 658 gpps(sesskey, "ProxyHost", "proxy", cfg->proxy_host,
659 sizeof(cfg->proxy_host));
660 gppi(sesskey, "ProxyPort", 80, &cfg->proxy_port);
661 gpps(sesskey, "ProxyUsername", "", cfg->proxy_username,
662 sizeof(cfg->proxy_username));
663 gpps(sesskey, "ProxyPassword", "", cfg->proxy_password,
664 sizeof(cfg->proxy_password));
0e8f4cda 665 gpps(sesskey, "ProxyTelnetCommand", "connect %host %port\\n",
8eebd221 666 cfg->proxy_telnet_command, sizeof(cfg->proxy_telnet_command));
b50ee9a8 667 gppmap(sesskey, "Environment", "", cfg->environmt, lenof(cfg->environmt));
471c20b0 668 gpps(sesskey, "UserName", "", cfg->username, sizeof(cfg->username));
669 gppi(sesskey, "UserNameFromEnvironment", 0, &cfg->username_from_env);
32874aea 670 gpps(sesskey, "LocalUserName", "", cfg->localusername,
671 sizeof(cfg->localusername));
672 gppi(sesskey, "NoPTY", 0, &cfg->nopty);
673 gppi(sesskey, "Compression", 0, &cfg->compression);
973612f5 674 gppi(sesskey, "TryAgent", 1, &cfg->tryagent);
32874aea 675 gppi(sesskey, "AgentFwd", 0, &cfg->agentfwd);
5bb641e1 676 gppi(sesskey, "ChangeUsername", 0, &cfg->change_username);
42af6a67 677 gppi(sesskey, "GssapiFwd", 0, &cfg->gssapifwd);
e411be57 678 gprefs(sesskey, "Cipher", "\0",
679 ciphernames, CIPHER_MAX, cfg->ssh_cipherlist);
83e7d008 680 {
681 /* Backward-compatibility: we used to have an option to
682 * disable gex under the "bugs" panel after one report of
683 * a server which offered it then choked, but we never got
684 * a server version string or any other reports. */
685 char *default_kexes;
686 gppi(sesskey, "BugDHGEx2", 0, &i); i = 2-i;
687 if (i == FORCE_ON)
fae1a71b 688 default_kexes = "dh-group14-sha1,dh-group1-sha1,rsa,WARN,dh-gex-sha1";
83e7d008 689 else
fae1a71b 690 default_kexes = "dh-gex-sha1,dh-group14-sha1,dh-group1-sha1,rsa,WARN";
83e7d008 691 gprefs(sesskey, "KEX", default_kexes,
692 kexnames, KEX_MAX, cfg->ssh_kexlist);
693 }
d57f70af 694 gppi(sesskey, "RekeyTime", 60, &cfg->ssh_rekey_time);
695 gpps(sesskey, "RekeyBytes", "1G", cfg->ssh_rekey_data,
696 sizeof(cfg->ssh_rekey_data));
102b17eb 697 gppi(sesskey, "SshProt", 2, &cfg->sshprot);
881da168 698 gpps(sesskey, "LogHost", "", cfg->loghost, sizeof(cfg->loghost));
cb4d4768 699 gppi(sesskey, "SSH2DES", 0, &cfg->ssh2_des_cbc);
a1a1fae4 700 gppi(sesskey, "SshNoAuth", 0, &cfg->ssh_no_userauth);
adb6167a 701 gppi(sesskey, "SshBanner", 1, &cfg->ssh_show_banner);
32874aea 702 gppi(sesskey, "AuthTIS", 0, &cfg->try_tis_auth);
f091e308 703 gppi(sesskey, "AuthKI", 1, &cfg->try_ki_auth);
42af6a67 704 gppi(sesskey, "AuthGSSAPI", 1, &cfg->try_gssapi_auth);
1e00c92b 705#ifndef NO_GSSAPI
63f305ff 706 gprefs(sesskey, "GSSLibs", "\0",
b3d375b2 707 gsslibkeywords, ngsslibs, cfg->ssh_gsslist);
1e00c92b 708 gppfile(sesskey, "GSSCustom", &cfg->ssh_gss_custom);
709#endif
0ed48730 710 gppi(sesskey, "SshNoShell", 0, &cfg->ssh_no_shell);
9a30e26b 711 gppfile(sesskey, "PublicKeyFile", &cfg->keyfile);
32874aea 712 gpps(sesskey, "RemoteCommand", "", cfg->remote_cmd,
713 sizeof(cfg->remote_cmd));
714 gppi(sesskey, "RFCEnviron", 0, &cfg->rfc_environ);
8faa456c 715 gppi(sesskey, "PassiveTelnet", 0, &cfg->passive_telnet);
32874aea 716 gppi(sesskey, "BackspaceIsDelete", 1, &cfg->bksp_is_delete);
717 gppi(sesskey, "RXVTHomeEnd", 0, &cfg->rxvt_homeend);
718 gppi(sesskey, "LinuxFunctionKeys", 0, &cfg->funky_type);
719 gppi(sesskey, "NoApplicationKeys", 0, &cfg->no_applic_k);
720 gppi(sesskey, "NoApplicationCursors", 0, &cfg->no_applic_c);
c0d36a72 721 gppi(sesskey, "NoMouseReporting", 0, &cfg->no_mouse_rep);
0d2086c5 722 gppi(sesskey, "NoRemoteResize", 0, &cfg->no_remote_resize);
723 gppi(sesskey, "NoAltScreen", 0, &cfg->no_alt_screen);
724 gppi(sesskey, "NoRemoteWinTitle", 0, &cfg->no_remote_wintitle);
e65096f2 725 {
726 /* Backward compatibility */
727 int no_remote_qtitle;
728 gppi(sesskey, "NoRemoteQTitle", 1, &no_remote_qtitle);
729 /* We deliberately interpret the old setting of "no response" as
730 * "empty string". This changes the behaviour, but hopefully for
731 * the better; the user can always recover the old behaviour. */
732 gppi(sesskey, "RemoteQTitleAction",
733 no_remote_qtitle ? TITLE_EMPTY : TITLE_REAL,
734 &cfg->remote_qtitle_action);
735 }
0d2086c5 736 gppi(sesskey, "NoDBackspace", 0, &cfg->no_dbackspace);
737 gppi(sesskey, "NoRemoteCharset", 0, &cfg->no_remote_charset);
32874aea 738 gppi(sesskey, "ApplicationCursorKeys", 0, &cfg->app_cursor);
739 gppi(sesskey, "ApplicationKeypad", 0, &cfg->app_keypad);
740 gppi(sesskey, "NetHackKeypad", 0, &cfg->nethack_keypad);
741 gppi(sesskey, "AltF4", 1, &cfg->alt_f4);
742 gppi(sesskey, "AltSpace", 0, &cfg->alt_space);
743 gppi(sesskey, "AltOnly", 0, &cfg->alt_only);
744 gppi(sesskey, "ComposeKey", 0, &cfg->compose_key);
745 gppi(sesskey, "CtrlAltKeys", 1, &cfg->ctrlaltkeys);
a5f3e637 746 gppi(sesskey, "TelnetKey", 0, &cfg->telnet_keyboard);
eee63b77 747 gppi(sesskey, "TelnetRet", 1, &cfg->telnet_newline);
5ecd7ad0 748 gppi(sesskey, "LocalEcho", AUTO, &cfg->localecho);
749 gppi(sesskey, "LocalEdit", AUTO, &cfg->localedit);
32874aea 750 gpps(sesskey, "Answerback", "PuTTY", cfg->answerback,
751 sizeof(cfg->answerback));
752 gppi(sesskey, "AlwaysOnTop", 0, &cfg->alwaysontop);
8f57d753 753 gppi(sesskey, "FullScreenOnAltEnter", 0, &cfg->fullscreenonaltenter);
32874aea 754 gppi(sesskey, "HideMousePtr", 0, &cfg->hide_mouseptr);
755 gppi(sesskey, "SunkenEdge", 0, &cfg->sunken_edge);
5a73255e 756 gppi(sesskey, "WindowBorder", 1, &cfg->window_border);
32874aea 757 gppi(sesskey, "CurType", 0, &cfg->cursor_type);
758 gppi(sesskey, "BlinkCur", 0, &cfg->blink_cur);
2d466ffd 759 /* pedantic compiler tells me I can't use &cfg->beep as an int * :-) */
5ecd7ad0 760 gppi(sesskey, "Beep", 1, &cfg->beep);
761 gppi(sesskey, "BeepInd", 0, &cfg->beep_ind);
9a30e26b 762 gppfile(sesskey, "BellWaveFile", &cfg->bell_wavefile);
32874aea 763 gppi(sesskey, "BellOverload", 1, &cfg->bellovl);
764 gppi(sesskey, "BellOverloadN", 5, &cfg->bellovl_n);
d63db2ca 765 gppi(sesskey, "BellOverloadT", 2*TICKSPERSEC
766#ifdef PUTTY_UNIX_H
767 *1000
768#endif
769 , &i);
3c89f872 770 cfg->bellovl_t = i
771#ifdef PUTTY_UNIX_H
772 / 1000
773#endif
774 ;
d63db2ca 775 gppi(sesskey, "BellOverloadS", 5*TICKSPERSEC
776#ifdef PUTTY_UNIX_H
777 *1000
778#endif
779 , &i);
3c89f872 780 cfg->bellovl_s = i
781#ifdef PUTTY_UNIX_H
782 / 1000
783#endif
784 ;
32874aea 785 gppi(sesskey, "ScrollbackLines", 200, &cfg->savelines);
786 gppi(sesskey, "DECOriginMode", 0, &cfg->dec_om);
787 gppi(sesskey, "AutoWrapMode", 1, &cfg->wrap_mode);
788 gppi(sesskey, "LFImpliesCR", 0, &cfg->lfhascr);
7612f22f 789 gppi(sesskey, "CRImpliesLF", 0, &cfg->crhaslf);
f0fccd51 790 gppi(sesskey, "DisableArabicShaping", 0, &cfg->arabicshaping);
791 gppi(sesskey, "DisableBidi", 0, &cfg->bidi);
505db88d 792 gppi(sesskey, "WinNameAlways", 1, &cfg->win_name_always);
32874aea 793 gpps(sesskey, "WinTitle", "", cfg->wintitle, sizeof(cfg->wintitle));
794 gppi(sesskey, "TermWidth", 80, &cfg->width);
795 gppi(sesskey, "TermHeight", 24, &cfg->height);
9a30e26b 796 gppfont(sesskey, "Font", &cfg->font);
17c7fed1 797 gppi(sesskey, "FontQuality", FQ_DEFAULT, &cfg->font_quality);
5a73255e 798 gppi(sesskey, "FontVTMode", VT_UNICODE, (int *) &cfg->vtmode);
26d1da7b 799 gppi(sesskey, "UseSystemColours", 0, &cfg->system_colour);
32874aea 800 gppi(sesskey, "TryPalette", 0, &cfg->try_palette);
c6f1b8ed 801 gppi(sesskey, "ANSIColour", 1, &cfg->ansi_colour);
cecb13f6 802 gppi(sesskey, "Xterm256Colour", 1, &cfg->xterm_256_colour);
32874aea 803 gppi(sesskey, "BoldAsColour", 1, &cfg->bold_colour);
f0fccd51 804
32874aea 805 for (i = 0; i < 22; i++) {
c85623f9 806 static const char *const defaults[] = {
a9422f39 807 "187,187,187", "255,255,255", "0,0,0", "85,85,85", "0,0,0",
808 "0,255,0", "0,0,0", "85,85,85", "187,0,0", "255,85,85",
809 "0,187,0", "85,255,85", "187,187,0", "255,255,85", "0,0,187",
810 "85,85,255", "187,0,187", "255,85,255", "0,187,187",
811 "85,255,255", "187,187,187", "255,255,255"
32874aea 812 };
a9422f39 813 char buf[20], buf2[30];
814 int c0, c1, c2;
815 sprintf(buf, "Colour%d", i);
32874aea 816 gpps(sesskey, buf, defaults[i], buf2, sizeof(buf2));
817 if (sscanf(buf2, "%d,%d,%d", &c0, &c1, &c2) == 3) {
a9422f39 818 cfg->colours[i][0] = c0;
819 cfg->colours[i][1] = c1;
820 cfg->colours[i][2] = c2;
821 }
822 }
32874aea 823 gppi(sesskey, "RawCNP", 0, &cfg->rawcnp);
a7419ea4 824 gppi(sesskey, "PasteRTF", 0, &cfg->rtf_paste);
32874aea 825 gppi(sesskey, "MouseIsXterm", 0, &cfg->mouse_is_xterm);
6908fed7 826 gppi(sesskey, "RectSelect", 0, &cfg->rect_select);
b90840c3 827 gppi(sesskey, "MouseOverride", 1, &cfg->mouse_override);
32874aea 828 for (i = 0; i < 256; i += 32) {
c85623f9 829 static const char *const defaults[] = {
a9422f39 830 "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",
831 "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",
832 "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",
833 "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",
834 "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",
835 "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",
836 "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",
837 "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"
838 };
839 char buf[20], buf2[256], *p;
840 int j;
841 sprintf(buf, "Wordness%d", i);
32874aea 842 gpps(sesskey, buf, defaults[i / 32], buf2, sizeof(buf2));
a9422f39 843 p = buf2;
32874aea 844 for (j = i; j < i + 32; j++) {
a9422f39 845 char *q = p;
32874aea 846 while (*p && *p != ',')
847 p++;
848 if (*p == ',')
849 *p++ = '\0';
a9422f39 850 cfg->wordness[j] = atoi(q);
851 }
852 }
b8ae1f0f 853 /*
854 * The empty default for LineCodePage will be converted later
855 * into a plausible default for the locale.
856 */
857 gpps(sesskey, "LineCodePage", "", cfg->line_codepage,
4eeb7d09 858 sizeof(cfg->line_codepage));
74790953 859 gppi(sesskey, "CJKAmbigWide", 0, &cfg->cjk_ambig_wide);
6ac7f054 860 gppi(sesskey, "UTF8Override", 1, &cfg->utf8_override);
b44b307a 861 gpps(sesskey, "Printer", "", cfg->printer, sizeof(cfg->printer));
a9c02454 862 gppi (sesskey, "CapsLockCyr", 0, &cfg->xlat_capslockcyr);
32874aea 863 gppi(sesskey, "ScrollBar", 1, &cfg->scrollbar);
a401e5f3 864 gppi(sesskey, "ScrollBarFullScreen", 0, &cfg->scrollbar_in_fullscreen);
32874aea 865 gppi(sesskey, "ScrollOnKey", 0, &cfg->scroll_on_key);
866 gppi(sesskey, "ScrollOnDisp", 1, &cfg->scroll_on_disp);
876e5d5e 867 gppi(sesskey, "EraseToScrollback", 1, &cfg->erase_to_scrollback);
5ecd7ad0 868 gppi(sesskey, "LockSize", 0, &cfg->resize_action);
102b17eb 869 gppi(sesskey, "BCE", 1, &cfg->bce);
32874aea 870 gppi(sesskey, "BlinkText", 0, &cfg->blinktext);
871 gppi(sesskey, "X11Forward", 0, &cfg->x11_forward);
fc0f17db 872 gpps(sesskey, "X11Display", "", cfg->x11_display,
32874aea 873 sizeof(cfg->x11_display));
b3ebaa28 874 gppi(sesskey, "X11AuthType", X11_MIT, &cfg->x11_auth);
8def70c3 875 gppfile(sesskey, "X11AuthFile", &cfg->xauthfile);
a9422f39 876
d74d141c 877 gppi(sesskey, "LocalPortAcceptAll", 0, &cfg->lport_acceptall);
beefa433 878 gppi(sesskey, "RemotePortAcceptAll", 0, &cfg->rport_acceptall);
b50ee9a8 879 gppmap(sesskey, "PortForwardings", "", cfg->portfwd, lenof(cfg->portfwd));
88103a48 880 gppi(sesskey, "BugIgnore1", 0, &i); cfg->sshbug_ignore1 = 2-i;
881 gppi(sesskey, "BugPlainPW1", 0, &i); cfg->sshbug_plainpw1 = 2-i;
882 gppi(sesskey, "BugRSA1", 0, &i); cfg->sshbug_rsa1 = 2-i;
cf6ddb95 883 gppi(sesskey, "BugIgnore2", 0, &i); cfg->sshbug_ignore2 = 2-i;
2c9c6388 884 {
885 int i;
88103a48 886 gppi(sesskey, "BugHMAC2", 0, &i); cfg->sshbug_hmac2 = 2-i;
5ecd7ad0 887 if (cfg->sshbug_hmac2 == AUTO) {
2c9c6388 888 gppi(sesskey, "BuggyMAC", 0, &i);
889 if (i == 1)
5ecd7ad0 890 cfg->sshbug_hmac2 = FORCE_ON;
2c9c6388 891 }
892 }
88103a48 893 gppi(sesskey, "BugDeriveKey2", 0, &i); cfg->sshbug_derivekey2 = 2-i;
894 gppi(sesskey, "BugRSAPad2", 0, &i); cfg->sshbug_rsapad2 = 2-i;
dda87a28 895 gppi(sesskey, "BugPKSessID2", 0, &i); cfg->sshbug_pksessid2 = 2-i;
f382c87d 896 gppi(sesskey, "BugRekey2", 0, &i); cfg->sshbug_rekey2 = 2-i;
c9739dba 897 gppi(sesskey, "BugMaxPkt2", 0, &i); cfg->sshbug_maxpkt2 = 2-i;
ec9bb1ef 898 cfg->ssh_simple = FALSE;
c8ee61b9 899 gppi(sesskey, "StampUtmp", 1, &cfg->stamp_utmp);
900 gppi(sesskey, "LoginShell", 1, &cfg->login_shell);
239b3b36 901 gppi(sesskey, "ScrollbarOnLeft", 0, &cfg->scrollbar_on_left);
bf133a73 902 gppi(sesskey, "ShadowBold", 0, &cfg->shadowbold);
9a30e26b 903 gppfont(sesskey, "BoldFont", &cfg->boldfont);
be5c5fed 904 gppfont(sesskey, "WideFont", &cfg->widefont);
905 gppfont(sesskey, "WideBoldFont", &cfg->wideboldfont);
623f81b7 906 gppi(sesskey, "ShadowBoldOffset", 1, &cfg->shadowboldoffset);
7374c779 907 gpps(sesskey, "SerialLine", "", cfg->serline, sizeof(cfg->serline));
908 gppi(sesskey, "SerialSpeed", 9600, &cfg->serspeed);
909 gppi(sesskey, "SerialDataBits", 8, &cfg->serdatabits);
910 gppi(sesskey, "SerialStopHalfbits", 2, &cfg->serstopbits);
5fd93688 911 gppi(sesskey, "SerialParity", SER_PAR_NONE, &cfg->serparity);
912 gppi(sesskey, "SerialFlowControl", SER_FLOW_XONXOFF, &cfg->serflow);
3e4a1fd7 913 gpps(sesskey, "WindowClass", "", cfg->winclass, sizeof(cfg->winclass));
a9422f39 914}
915
32874aea 916void do_defaults(char *session, Config * cfg)
917{
47b5a6ae 918 load_settings(session, cfg);
a9422f39 919}
920
32874aea 921static int sessioncmp(const void *av, const void *bv)
922{
923 const char *a = *(const char *const *) av;
924 const char *b = *(const char *const *) bv;
a84ca2f5 925
926 /*
927 * Alphabetical order, except that "Default Settings" is a
928 * special case and comes first.
929 */
930 if (!strcmp(a, "Default Settings"))
32874aea 931 return -1; /* a comes first */
a84ca2f5 932 if (!strcmp(b, "Default Settings"))
32874aea 933 return +1; /* b comes first */
78a8d889 934 /*
935 * FIXME: perhaps we should ignore the first & in determining
936 * sort order.
937 */
32874aea 938 return strcmp(a, b); /* otherwise, compare normally */
a84ca2f5 939}
940
0b4f0bc0 941void get_sesslist(struct sesslist *list, int allocate)
32874aea 942{
0b4f0bc0 943 char otherbuf[2048];
a9422f39 944 int buflen, bufsize, i;
945 char *p, *ret;
946 void *handle;
947
948 if (allocate) {
32874aea 949
a9422f39 950 buflen = bufsize = 0;
0b4f0bc0 951 list->buffer = NULL;
1728c012 952 if ((handle = enum_settings_start()) != NULL) {
5f2df4d2 953 do {
954 ret = enum_settings_next(handle, otherbuf, sizeof(otherbuf));
955 if (ret) {
956 int len = strlen(otherbuf) + 1;
957 if (bufsize < buflen + len) {
958 bufsize = buflen + len + 2048;
3d88e64d 959 list->buffer = sresize(list->buffer, bufsize, char);
5f2df4d2 960 }
0b4f0bc0 961 strcpy(list->buffer + buflen, otherbuf);
962 buflen += strlen(list->buffer + buflen) + 1;
32874aea 963 }
5f2df4d2 964 } while (ret);
965 enum_settings_finish(handle);
966 }
3d88e64d 967 list->buffer = sresize(list->buffer, buflen + 1, char);
0b4f0bc0 968 list->buffer[buflen] = '\0';
a9422f39 969
2221af18 970 /*
971 * Now set up the list of sessions. Note that "Default
972 * Settings" must always be claimed to exist, even if it
973 * doesn't really.
974 */
975
0b4f0bc0 976 p = list->buffer;
977 list->nsessions = 1; /* "Default Settings" counts as one */
a9422f39 978 while (*p) {
32874aea 979 if (strcmp(p, "Default Settings"))
0b4f0bc0 980 list->nsessions++;
32874aea 981 while (*p)
982 p++;
a9422f39 983 p++;
984 }
985
3d88e64d 986 list->sessions = snewn(list->nsessions + 1, char *);
0b4f0bc0 987 list->sessions[0] = "Default Settings";
988 p = list->buffer;
2221af18 989 i = 1;
a9422f39 990 while (*p) {
32874aea 991 if (strcmp(p, "Default Settings"))
0b4f0bc0 992 list->sessions[i++] = p;
32874aea 993 while (*p)
994 p++;
a9422f39 995 p++;
996 }
a84ca2f5 997
0b4f0bc0 998 qsort(list->sessions, i, sizeof(char *), sessioncmp);
a9422f39 999 } else {
0b4f0bc0 1000 sfree(list->buffer);
1001 sfree(list->sessions);
c6fa3909 1002 list->buffer = NULL;
1003 list->sessions = NULL;
a9422f39 1004 }
1005}