2 * settings.c: read and write saved sessions. (platform-independent)
12 * Tables of string <-> enum value mappings
14 struct keyval
{ char *s
; int v
; };
16 /* The cipher order given here is the default order. */
17 static const struct keyval ciphernames
[] = {
18 { "aes", CIPHER_AES
},
19 { "blowfish", CIPHER_BLOWFISH
},
20 { "3des", CIPHER_3DES
},
21 { "WARN", CIPHER_WARN
},
22 { "arcfour", CIPHER_ARCFOUR
},
26 static const struct keyval kexnames
[] = {
27 { "dh-gex-sha1", KEX_DHGEX
},
28 { "dh-group14-sha1", KEX_DHGROUP14
},
29 { "dh-group1-sha1", KEX_DHGROUP1
},
35 * All the terminal modes that we know about for the "TerminalModes"
36 * setting. (Also used by config.c for the drop-down list.)
37 * This is currently precisely the same as the set in ssh.c, but could
38 * in principle differ if other backends started to support tty modes
39 * (e.g., the pty backend).
41 const char *const ttymodes
[] = {
42 "INTR", "QUIT", "ERASE", "KILL", "EOF",
43 "EOL", "EOL2", "START", "STOP", "SUSP",
44 "DSUSP", "REPRINT", "WERASE", "LNEXT", "FLUSH",
45 "SWTCH", "STATUS", "DISCARD", "IGNPAR", "PARMRK",
46 "INPCK", "ISTRIP", "INLCR", "IGNCR", "ICRNL",
47 "IUCLC", "IXON", "IXANY", "IXOFF", "IMAXBEL",
48 "ISIG", "ICANON", "XCASE", "ECHO", "ECHOE",
49 "ECHOK", "ECHONL", "NOFLSH", "TOSTOP", "IEXTEN",
50 "ECHOCTL", "ECHOKE", "PENDIN", "OPOST", "OLCUC",
51 "ONLCR", "OCRNL", "ONOCR", "ONLRET", "CS7",
52 "CS8", "PARENB", "PARODD", NULL
56 * Convenience functions to access the backends[] array
57 * (which is only present in tools that manage settings).
60 Backend
*backend_from_name(const char *name
)
63 for (p
= backends
; *p
!= NULL
; p
++)
64 if (!strcmp((*p
)->name
, name
))
69 Backend
*backend_from_proto(int proto
)
72 for (p
= backends
; *p
!= NULL
; p
++)
73 if ((*p
)->protocol
== proto
)
78 int get_remote_username(Config
*cfg
, char *user
, size_t len
)
81 strncpy(user
, cfg
->username
, len
);
84 if (cfg
->username_from_env
) {
85 /* Use local username. */
86 char *luser
= get_username();
88 strncpy(user
, luser
, len
);
98 return (*user
!= '\0');
101 static void gpps(void *handle
, const char *name
, const char *def
,
104 if (!read_setting_s(handle
, name
, val
, len
)) {
107 pdef
= platform_default_s(name
);
109 strncpy(val
, pdef
, len
);
112 strncpy(val
, def
, len
);
120 * gppfont and gppfile cannot have local defaults, since the very
121 * format of a Filename or Font is platform-dependent. So the
122 * platform-dependent functions MUST return some sort of value.
124 static void gppfont(void *handle
, const char *name
, FontSpec
*result
)
126 if (!read_setting_fontspec(handle
, name
, result
))
127 *result
= platform_default_fontspec(name
);
129 static void gppfile(void *handle
, const char *name
, Filename
*result
)
131 if (!read_setting_filename(handle
, name
, result
))
132 *result
= platform_default_filename(name
);
135 static void gppi(void *handle
, char *name
, int def
, int *i
)
137 def
= platform_default_i(name
, def
);
138 *i
= read_setting_i(handle
, name
, def
);
142 * Read a set of name-value pairs in the format we occasionally use:
143 * NAME\tVALUE\0NAME\tVALUE\0\0 in memory
144 * NAME=VALUE,NAME=VALUE, in storage
145 * `def' is in the storage format.
147 static void gppmap(void *handle
, char *name
, char *def
, char *val
, int len
)
149 char *buf
= snewn(2*len
, char), *p
, *q
;
150 gpps(handle
, name
, def
, buf
, 2*len
);
154 while (*p
&& *p
!= ',') {
171 * Write a set of name/value pairs in the above format.
173 static void wmap(void *handle
, char const *key
, char const *value
, int len
)
175 char *buf
= snewn(2*len
, char), *p
;
182 if (c
== '=' || c
== ',' || c
== '\\')
192 write_setting_s(handle
, key
, buf
);
196 static int key2val(const struct keyval
*mapping
, int nmaps
, char *key
)
199 for (i
= 0; i
< nmaps
; i
++)
200 if (!strcmp(mapping
[i
].s
, key
)) return mapping
[i
].v
;
204 static const char *val2key(const struct keyval
*mapping
, int nmaps
, int val
)
207 for (i
= 0; i
< nmaps
; i
++)
208 if (mapping
[i
].v
== val
) return mapping
[i
].s
;
213 * Helper function to parse a comma-separated list of strings into
214 * a preference list array of values. Any missing values are added
215 * to the end and duplicates are weeded.
216 * XXX: assumes vals in 'mapping' are small +ve integers
218 static void gprefs(void *sesskey
, char *name
, char *def
,
219 const struct keyval
*mapping
, int nvals
,
223 char *tokarg
= commalist
;
225 unsigned long seen
= 0; /* bitmap for weeding dups etc */
226 gpps(sesskey
, name
, def
, commalist
, sizeof(commalist
));
228 /* Grotty parsing of commalist. */
233 key
= strtok(tokarg
, ","); /* sorry */
236 if (((v
= key2val(mapping
, nvals
, key
)) != -1) &&
243 /* Add any missing values (backward compatibility ect). */
246 for (i
= 0; i
< nvals
; i
++) {
247 assert(mapping
[i
].v
< 32);
248 if (!(seen
& 1<<mapping
[i
].v
)) {
249 array
[n
] = mapping
[i
].v
;
257 * Write out a preference list.
259 static void wprefs(void *sesskey
, char *name
,
260 const struct keyval
*mapping
, int nvals
,
263 char buf
[80] = ""; /* XXX assumed big enough */
264 int l
= sizeof(buf
)-1, i
;
266 for (i
= 0; l
> 0 && i
< nvals
; i
++) {
267 const char *s
= val2key(mapping
, nvals
, array
[i
]);
271 strncat(buf
, ",", l
);
278 write_setting_s(sesskey
, name
, buf
);
281 char *save_settings(char *section
, Config
* cfg
)
286 sesskey
= open_settings_w(section
, &errmsg
);
289 save_open_settings(sesskey
, cfg
);
290 close_settings_w(sesskey
);
294 void save_open_settings(void *sesskey
, Config
*cfg
)
299 write_setting_i(sesskey
, "Present", 1);
300 write_setting_s(sesskey
, "HostName", cfg
->host
);
301 write_setting_filename(sesskey
, "LogFileName", cfg
->logfilename
);
302 write_setting_i(sesskey
, "LogType", cfg
->logtype
);
303 write_setting_i(sesskey
, "LogFileClash", cfg
->logxfovr
);
304 write_setting_i(sesskey
, "LogFlush", cfg
->logflush
);
305 write_setting_i(sesskey
, "SSHLogOmitPasswords", cfg
->logomitpass
);
306 write_setting_i(sesskey
, "SSHLogOmitData", cfg
->logomitdata
);
309 const Backend
*b
= backend_from_proto(cfg
->protocol
);
313 write_setting_s(sesskey
, "Protocol", p
);
314 write_setting_i(sesskey
, "PortNumber", cfg
->port
);
315 /* The CloseOnExit numbers are arranged in a different order from
316 * the standard FORCE_ON / FORCE_OFF / AUTO. */
317 write_setting_i(sesskey
, "CloseOnExit", (cfg
->close_on_exit
+2)%3);
318 write_setting_i(sesskey
, "WarnOnClose", !!cfg
->warn_on_close
);
319 write_setting_i(sesskey
, "PingInterval", cfg
->ping_interval
/ 60); /* minutes */
320 write_setting_i(sesskey
, "PingIntervalSecs", cfg
->ping_interval
% 60); /* seconds */
321 write_setting_i(sesskey
, "TCPNoDelay", cfg
->tcp_nodelay
);
322 write_setting_i(sesskey
, "TCPKeepalives", cfg
->tcp_keepalives
);
323 write_setting_s(sesskey
, "TerminalType", cfg
->termtype
);
324 write_setting_s(sesskey
, "TerminalSpeed", cfg
->termspeed
);
325 wmap(sesskey
, "TerminalModes", cfg
->ttymodes
, lenof(cfg
->ttymodes
));
327 /* Address family selection */
328 write_setting_i(sesskey
, "AddressFamily", cfg
->addressfamily
);
331 write_setting_s(sesskey
, "ProxyExcludeList", cfg
->proxy_exclude_list
);
332 write_setting_i(sesskey
, "ProxyDNS", (cfg
->proxy_dns
+2)%3);
333 write_setting_i(sesskey
, "ProxyLocalhost", cfg
->even_proxy_localhost
);
334 write_setting_i(sesskey
, "ProxyMethod", cfg
->proxy_type
);
335 write_setting_s(sesskey
, "ProxyHost", cfg
->proxy_host
);
336 write_setting_i(sesskey
, "ProxyPort", cfg
->proxy_port
);
337 write_setting_s(sesskey
, "ProxyUsername", cfg
->proxy_username
);
338 write_setting_s(sesskey
, "ProxyPassword", cfg
->proxy_password
);
339 write_setting_s(sesskey
, "ProxyTelnetCommand", cfg
->proxy_telnet_command
);
340 wmap(sesskey
, "Environment", cfg
->environmt
, lenof(cfg
->environmt
));
341 write_setting_s(sesskey
, "UserName", cfg
->username
);
342 write_setting_i(sesskey
, "UserNameFromEnvironment", cfg
->username_from_env
);
343 write_setting_s(sesskey
, "LocalUserName", cfg
->localusername
);
344 write_setting_i(sesskey
, "NoPTY", cfg
->nopty
);
345 write_setting_i(sesskey
, "Compression", cfg
->compression
);
346 write_setting_i(sesskey
, "TryAgent", cfg
->tryagent
);
347 write_setting_i(sesskey
, "AgentFwd", cfg
->agentfwd
);
348 write_setting_i(sesskey
, "GssapiFwd", cfg
->gssapifwd
);
349 write_setting_i(sesskey
, "ChangeUsername", cfg
->change_username
);
350 wprefs(sesskey
, "Cipher", ciphernames
, CIPHER_MAX
,
351 cfg
->ssh_cipherlist
);
352 wprefs(sesskey
, "KEX", kexnames
, KEX_MAX
, cfg
->ssh_kexlist
);
353 write_setting_i(sesskey
, "RekeyTime", cfg
->ssh_rekey_time
);
354 write_setting_s(sesskey
, "RekeyBytes", cfg
->ssh_rekey_data
);
355 write_setting_i(sesskey
, "SshNoAuth", cfg
->ssh_no_userauth
);
356 write_setting_i(sesskey
, "AuthTIS", cfg
->try_tis_auth
);
357 write_setting_i(sesskey
, "AuthKI", cfg
->try_ki_auth
);
358 write_setting_i(sesskey
, "AuthGSSAPI", cfg
->try_gssapi_auth
);
359 write_setting_i(sesskey
, "SshNoShell", cfg
->ssh_no_shell
);
360 write_setting_i(sesskey
, "SshProt", cfg
->sshprot
);
361 write_setting_s(sesskey
, "LogHost", cfg
->loghost
);
362 write_setting_i(sesskey
, "SSH2DES", cfg
->ssh2_des_cbc
);
363 write_setting_filename(sesskey
, "PublicKeyFile", cfg
->keyfile
);
364 write_setting_s(sesskey
, "RemoteCommand", cfg
->remote_cmd
);
365 write_setting_i(sesskey
, "RFCEnviron", cfg
->rfc_environ
);
366 write_setting_i(sesskey
, "PassiveTelnet", cfg
->passive_telnet
);
367 write_setting_i(sesskey
, "BackspaceIsDelete", cfg
->bksp_is_delete
);
368 write_setting_i(sesskey
, "RXVTHomeEnd", cfg
->rxvt_homeend
);
369 write_setting_i(sesskey
, "LinuxFunctionKeys", cfg
->funky_type
);
370 write_setting_i(sesskey
, "NoApplicationKeys", cfg
->no_applic_k
);
371 write_setting_i(sesskey
, "NoApplicationCursors", cfg
->no_applic_c
);
372 write_setting_i(sesskey
, "NoMouseReporting", cfg
->no_mouse_rep
);
373 write_setting_i(sesskey
, "NoRemoteResize", cfg
->no_remote_resize
);
374 write_setting_i(sesskey
, "NoAltScreen", cfg
->no_alt_screen
);
375 write_setting_i(sesskey
, "NoRemoteWinTitle", cfg
->no_remote_wintitle
);
376 write_setting_i(sesskey
, "RemoteQTitleAction", cfg
->remote_qtitle_action
);
377 write_setting_i(sesskey
, "NoDBackspace", cfg
->no_dbackspace
);
378 write_setting_i(sesskey
, "NoRemoteCharset", cfg
->no_remote_charset
);
379 write_setting_i(sesskey
, "ApplicationCursorKeys", cfg
->app_cursor
);
380 write_setting_i(sesskey
, "ApplicationKeypad", cfg
->app_keypad
);
381 write_setting_i(sesskey
, "NetHackKeypad", cfg
->nethack_keypad
);
382 write_setting_i(sesskey
, "AltF4", cfg
->alt_f4
);
383 write_setting_i(sesskey
, "AltSpace", cfg
->alt_space
);
384 write_setting_i(sesskey
, "AltOnly", cfg
->alt_only
);
385 write_setting_i(sesskey
, "ComposeKey", cfg
->compose_key
);
386 write_setting_i(sesskey
, "CtrlAltKeys", cfg
->ctrlaltkeys
);
387 write_setting_i(sesskey
, "TelnetKey", cfg
->telnet_keyboard
);
388 write_setting_i(sesskey
, "TelnetRet", cfg
->telnet_newline
);
389 write_setting_i(sesskey
, "LocalEcho", cfg
->localecho
);
390 write_setting_i(sesskey
, "LocalEdit", cfg
->localedit
);
391 write_setting_s(sesskey
, "Answerback", cfg
->answerback
);
392 write_setting_i(sesskey
, "AlwaysOnTop", cfg
->alwaysontop
);
393 write_setting_i(sesskey
, "FullScreenOnAltEnter", cfg
->fullscreenonaltenter
);
394 write_setting_i(sesskey
, "HideMousePtr", cfg
->hide_mouseptr
);
395 write_setting_i(sesskey
, "SunkenEdge", cfg
->sunken_edge
);
396 write_setting_i(sesskey
, "WindowBorder", cfg
->window_border
);
397 write_setting_i(sesskey
, "CurType", cfg
->cursor_type
);
398 write_setting_i(sesskey
, "BlinkCur", cfg
->blink_cur
);
399 write_setting_i(sesskey
, "Beep", cfg
->beep
);
400 write_setting_i(sesskey
, "BeepInd", cfg
->beep_ind
);
401 write_setting_filename(sesskey
, "BellWaveFile", cfg
->bell_wavefile
);
402 write_setting_i(sesskey
, "BellOverload", cfg
->bellovl
);
403 write_setting_i(sesskey
, "BellOverloadN", cfg
->bellovl_n
);
404 write_setting_i(sesskey
, "BellOverloadT", cfg
->bellovl_t
409 write_setting_i(sesskey
, "BellOverloadS", cfg
->bellovl_s
414 write_setting_i(sesskey
, "ScrollbackLines", cfg
->savelines
);
415 write_setting_i(sesskey
, "DECOriginMode", cfg
->dec_om
);
416 write_setting_i(sesskey
, "AutoWrapMode", cfg
->wrap_mode
);
417 write_setting_i(sesskey
, "LFImpliesCR", cfg
->lfhascr
);
418 write_setting_i(sesskey
, "CRImpliesLF", cfg
->crhaslf
);
419 write_setting_i(sesskey
, "DisableArabicShaping", cfg
->arabicshaping
);
420 write_setting_i(sesskey
, "DisableBidi", cfg
->bidi
);
421 write_setting_i(sesskey
, "WinNameAlways", cfg
->win_name_always
);
422 write_setting_s(sesskey
, "WinTitle", cfg
->wintitle
);
423 write_setting_i(sesskey
, "TermWidth", cfg
->width
);
424 write_setting_i(sesskey
, "TermHeight", cfg
->height
);
425 write_setting_fontspec(sesskey
, "Font", cfg
->font
);
426 write_setting_i(sesskey
, "FontQuality", cfg
->font_quality
);
427 write_setting_i(sesskey
, "FontVTMode", cfg
->vtmode
);
428 write_setting_i(sesskey
, "UseSystemColours", cfg
->system_colour
);
429 write_setting_i(sesskey
, "TryPalette", cfg
->try_palette
);
430 write_setting_i(sesskey
, "ANSIColour", cfg
->ansi_colour
);
431 write_setting_i(sesskey
, "Xterm256Colour", cfg
->xterm_256_colour
);
432 write_setting_i(sesskey
, "BoldAsColour", cfg
->bold_colour
);
434 for (i
= 0; i
< 22; i
++) {
435 char buf
[20], buf2
[30];
436 sprintf(buf
, "Colour%d", i
);
437 sprintf(buf2
, "%d,%d,%d", cfg
->colours
[i
][0],
438 cfg
->colours
[i
][1], cfg
->colours
[i
][2]);
439 write_setting_s(sesskey
, buf
, buf2
);
441 write_setting_i(sesskey
, "RawCNP", cfg
->rawcnp
);
442 write_setting_i(sesskey
, "PasteRTF", cfg
->rtf_paste
);
443 write_setting_i(sesskey
, "MouseIsXterm", cfg
->mouse_is_xterm
);
444 write_setting_i(sesskey
, "RectSelect", cfg
->rect_select
);
445 write_setting_i(sesskey
, "MouseOverride", cfg
->mouse_override
);
446 for (i
= 0; i
< 256; i
+= 32) {
447 char buf
[20], buf2
[256];
449 sprintf(buf
, "Wordness%d", i
);
451 for (j
= i
; j
< i
+ 32; j
++) {
452 sprintf(buf2
+ strlen(buf2
), "%s%d",
453 (*buf2 ?
"," : ""), cfg
->wordness
[j
]);
455 write_setting_s(sesskey
, buf
, buf2
);
457 write_setting_s(sesskey
, "LineCodePage", cfg
->line_codepage
);
458 write_setting_i(sesskey
, "CJKAmbigWide", cfg
->cjk_ambig_wide
);
459 write_setting_i(sesskey
, "UTF8Override", cfg
->utf8_override
);
460 write_setting_s(sesskey
, "Printer", cfg
->printer
);
461 write_setting_i(sesskey
, "CapsLockCyr", cfg
->xlat_capslockcyr
);
462 write_setting_i(sesskey
, "ScrollBar", cfg
->scrollbar
);
463 write_setting_i(sesskey
, "ScrollBarFullScreen", cfg
->scrollbar_in_fullscreen
);
464 write_setting_i(sesskey
, "ScrollOnKey", cfg
->scroll_on_key
);
465 write_setting_i(sesskey
, "ScrollOnDisp", cfg
->scroll_on_disp
);
466 write_setting_i(sesskey
, "EraseToScrollback", cfg
->erase_to_scrollback
);
467 write_setting_i(sesskey
, "LockSize", cfg
->resize_action
);
468 write_setting_i(sesskey
, "BCE", cfg
->bce
);
469 write_setting_i(sesskey
, "BlinkText", cfg
->blinktext
);
470 write_setting_i(sesskey
, "X11Forward", cfg
->x11_forward
);
471 write_setting_s(sesskey
, "X11Display", cfg
->x11_display
);
472 write_setting_i(sesskey
, "X11AuthType", cfg
->x11_auth
);
473 write_setting_filename(sesskey
, "X11AuthFile", cfg
->xauthfile
);
474 write_setting_i(sesskey
, "LocalPortAcceptAll", cfg
->lport_acceptall
);
475 write_setting_i(sesskey
, "RemotePortAcceptAll", cfg
->rport_acceptall
);
476 wmap(sesskey
, "PortForwardings", cfg
->portfwd
, lenof(cfg
->portfwd
));
477 write_setting_i(sesskey
, "BugIgnore1", 2-cfg
->sshbug_ignore1
);
478 write_setting_i(sesskey
, "BugPlainPW1", 2-cfg
->sshbug_plainpw1
);
479 write_setting_i(sesskey
, "BugRSA1", 2-cfg
->sshbug_rsa1
);
480 write_setting_i(sesskey
, "BugHMAC2", 2-cfg
->sshbug_hmac2
);
481 write_setting_i(sesskey
, "BugDeriveKey2", 2-cfg
->sshbug_derivekey2
);
482 write_setting_i(sesskey
, "BugRSAPad2", 2-cfg
->sshbug_rsapad2
);
483 write_setting_i(sesskey
, "BugPKSessID2", 2-cfg
->sshbug_pksessid2
);
484 write_setting_i(sesskey
, "BugRekey2", 2-cfg
->sshbug_rekey2
);
485 write_setting_i(sesskey
, "BugMaxPkt2", 2-cfg
->sshbug_maxpkt2
);
486 write_setting_i(sesskey
, "StampUtmp", cfg
->stamp_utmp
);
487 write_setting_i(sesskey
, "LoginShell", cfg
->login_shell
);
488 write_setting_i(sesskey
, "ScrollbarOnLeft", cfg
->scrollbar_on_left
);
489 write_setting_fontspec(sesskey
, "BoldFont", cfg
->boldfont
);
490 write_setting_fontspec(sesskey
, "WideFont", cfg
->widefont
);
491 write_setting_fontspec(sesskey
, "WideBoldFont", cfg
->wideboldfont
);
492 write_setting_i(sesskey
, "ShadowBold", cfg
->shadowbold
);
493 write_setting_i(sesskey
, "ShadowBoldOffset", cfg
->shadowboldoffset
);
494 write_setting_s(sesskey
, "SerialLine", cfg
->serline
);
495 write_setting_i(sesskey
, "SerialSpeed", cfg
->serspeed
);
496 write_setting_i(sesskey
, "SerialDataBits", cfg
->serdatabits
);
497 write_setting_i(sesskey
, "SerialStopHalfbits", cfg
->serstopbits
);
498 write_setting_i(sesskey
, "SerialParity", cfg
->serparity
);
499 write_setting_i(sesskey
, "SerialFlowControl", cfg
->serflow
);
502 void load_settings(char *section
, Config
* cfg
)
506 sesskey
= open_settings_r(section
);
507 load_open_settings(sesskey
, cfg
);
508 close_settings_r(sesskey
);
511 void load_open_settings(void *sesskey
, Config
*cfg
)
516 cfg
->ssh_subsys
= 0; /* FIXME: load this properly */
517 cfg
->remote_cmd_ptr
= NULL
;
518 cfg
->remote_cmd_ptr2
= NULL
;
519 cfg
->ssh_nc_host
[0] = '\0';
521 gpps(sesskey
, "HostName", "", cfg
->host
, sizeof(cfg
->host
));
522 gppfile(sesskey
, "LogFileName", &cfg
->logfilename
);
523 gppi(sesskey
, "LogType", 0, &cfg
->logtype
);
524 gppi(sesskey
, "LogFileClash", LGXF_ASK
, &cfg
->logxfovr
);
525 gppi(sesskey
, "LogFlush", 1, &cfg
->logflush
);
526 gppi(sesskey
, "SSHLogOmitPasswords", 1, &cfg
->logomitpass
);
527 gppi(sesskey
, "SSHLogOmitData", 0, &cfg
->logomitdata
);
529 gpps(sesskey
, "Protocol", "default", prot
, 10);
530 cfg
->protocol
= default_protocol
;
531 cfg
->port
= default_port
;
533 const Backend
*b
= backend_from_name(prot
);
535 cfg
->protocol
= b
->protocol
;
536 gppi(sesskey
, "PortNumber", default_port
, &cfg
->port
);
540 /* Address family selection */
541 gppi(sesskey
, "AddressFamily", ADDRTYPE_UNSPEC
, &cfg
->addressfamily
);
543 /* The CloseOnExit numbers are arranged in a different order from
544 * the standard FORCE_ON / FORCE_OFF / AUTO. */
545 gppi(sesskey
, "CloseOnExit", 1, &i
); cfg
->close_on_exit
= (i
+1)%3;
546 gppi(sesskey
, "WarnOnClose", 1, &cfg
->warn_on_close
);
548 /* This is two values for backward compatibility with 0.50/0.51 */
549 int pingmin
, pingsec
;
550 gppi(sesskey
, "PingInterval", 0, &pingmin
);
551 gppi(sesskey
, "PingIntervalSecs", 0, &pingsec
);
552 cfg
->ping_interval
= pingmin
* 60 + pingsec
;
554 gppi(sesskey
, "TCPNoDelay", 1, &cfg
->tcp_nodelay
);
555 gppi(sesskey
, "TCPKeepalives", 0, &cfg
->tcp_keepalives
);
556 gpps(sesskey
, "TerminalType", "xterm", cfg
->termtype
,
557 sizeof(cfg
->termtype
));
558 gpps(sesskey
, "TerminalSpeed", "38400,38400", cfg
->termspeed
,
559 sizeof(cfg
->termspeed
));
561 /* This hardcodes a big set of defaults in any new saved
562 * sessions. Let's hope we don't change our mind. */
564 char *def
= dupstr("");
565 /* Default: all set to "auto" */
566 for (i
= 0; ttymodes
[i
]; i
++) {
567 char *def2
= dupprintf("%s%s=A,", def
, ttymodes
[i
]);
571 gppmap(sesskey
, "TerminalModes", def
,
572 cfg
->ttymodes
, lenof(cfg
->ttymodes
));
577 gpps(sesskey
, "ProxyExcludeList", "", cfg
->proxy_exclude_list
,
578 sizeof(cfg
->proxy_exclude_list
));
579 gppi(sesskey
, "ProxyDNS", 1, &i
); cfg
->proxy_dns
= (i
+1)%3;
580 gppi(sesskey
, "ProxyLocalhost", 0, &cfg
->even_proxy_localhost
);
581 gppi(sesskey
, "ProxyMethod", -1, &cfg
->proxy_type
);
582 if (cfg
->proxy_type
== -1) {
584 gppi(sesskey
, "ProxyType", 0, &i
);
586 cfg
->proxy_type
= PROXY_NONE
;
588 cfg
->proxy_type
= PROXY_HTTP
;
590 cfg
->proxy_type
= PROXY_TELNET
;
592 cfg
->proxy_type
= PROXY_CMD
;
594 gppi(sesskey
, "ProxySOCKSVersion", 5, &i
);
596 cfg
->proxy_type
= PROXY_SOCKS5
;
598 cfg
->proxy_type
= PROXY_SOCKS4
;
601 gpps(sesskey
, "ProxyHost", "proxy", cfg
->proxy_host
,
602 sizeof(cfg
->proxy_host
));
603 gppi(sesskey
, "ProxyPort", 80, &cfg
->proxy_port
);
604 gpps(sesskey
, "ProxyUsername", "", cfg
->proxy_username
,
605 sizeof(cfg
->proxy_username
));
606 gpps(sesskey
, "ProxyPassword", "", cfg
->proxy_password
,
607 sizeof(cfg
->proxy_password
));
608 gpps(sesskey
, "ProxyTelnetCommand", "connect %host %port\\n",
609 cfg
->proxy_telnet_command
, sizeof(cfg
->proxy_telnet_command
));
610 gppmap(sesskey
, "Environment", "", cfg
->environmt
, lenof(cfg
->environmt
));
611 gpps(sesskey
, "UserName", "", cfg
->username
, sizeof(cfg
->username
));
612 gppi(sesskey
, "UserNameFromEnvironment", 0, &cfg
->username_from_env
);
613 gpps(sesskey
, "LocalUserName", "", cfg
->localusername
,
614 sizeof(cfg
->localusername
));
615 gppi(sesskey
, "NoPTY", 0, &cfg
->nopty
);
616 gppi(sesskey
, "Compression", 0, &cfg
->compression
);
617 gppi(sesskey
, "TryAgent", 1, &cfg
->tryagent
);
618 gppi(sesskey
, "AgentFwd", 0, &cfg
->agentfwd
);
619 gppi(sesskey
, "ChangeUsername", 0, &cfg
->change_username
);
620 gppi(sesskey
, "GssapiFwd", 0, &cfg
->gssapifwd
);
621 gprefs(sesskey
, "Cipher", "\0",
622 ciphernames
, CIPHER_MAX
, cfg
->ssh_cipherlist
);
624 /* Backward-compatibility: we used to have an option to
625 * disable gex under the "bugs" panel after one report of
626 * a server which offered it then choked, but we never got
627 * a server version string or any other reports. */
629 gppi(sesskey
, "BugDHGEx2", 0, &i
); i
= 2-i
;
631 default_kexes
= "dh-group14-sha1,dh-group1-sha1,rsa,WARN,dh-gex-sha1";
633 default_kexes
= "dh-gex-sha1,dh-group14-sha1,dh-group1-sha1,rsa,WARN";
634 gprefs(sesskey
, "KEX", default_kexes
,
635 kexnames
, KEX_MAX
, cfg
->ssh_kexlist
);
637 gppi(sesskey
, "RekeyTime", 60, &cfg
->ssh_rekey_time
);
638 gpps(sesskey
, "RekeyBytes", "1G", cfg
->ssh_rekey_data
,
639 sizeof(cfg
->ssh_rekey_data
));
640 gppi(sesskey
, "SshProt", 2, &cfg
->sshprot
);
641 gpps(sesskey
, "LogHost", "", cfg
->loghost
, sizeof(cfg
->loghost
));
642 gppi(sesskey
, "SSH2DES", 0, &cfg
->ssh2_des_cbc
);
643 gppi(sesskey
, "SshNoAuth", 0, &cfg
->ssh_no_userauth
);
644 gppi(sesskey
, "AuthTIS", 0, &cfg
->try_tis_auth
);
645 gppi(sesskey
, "AuthKI", 1, &cfg
->try_ki_auth
);
646 gppi(sesskey
, "AuthGSSAPI", 1, &cfg
->try_gssapi_auth
);
647 gppi(sesskey
, "SshNoShell", 0, &cfg
->ssh_no_shell
);
648 gppfile(sesskey
, "PublicKeyFile", &cfg
->keyfile
);
649 gpps(sesskey
, "RemoteCommand", "", cfg
->remote_cmd
,
650 sizeof(cfg
->remote_cmd
));
651 gppi(sesskey
, "RFCEnviron", 0, &cfg
->rfc_environ
);
652 gppi(sesskey
, "PassiveTelnet", 0, &cfg
->passive_telnet
);
653 gppi(sesskey
, "BackspaceIsDelete", 1, &cfg
->bksp_is_delete
);
654 gppi(sesskey
, "RXVTHomeEnd", 0, &cfg
->rxvt_homeend
);
655 gppi(sesskey
, "LinuxFunctionKeys", 0, &cfg
->funky_type
);
656 gppi(sesskey
, "NoApplicationKeys", 0, &cfg
->no_applic_k
);
657 gppi(sesskey
, "NoApplicationCursors", 0, &cfg
->no_applic_c
);
658 gppi(sesskey
, "NoMouseReporting", 0, &cfg
->no_mouse_rep
);
659 gppi(sesskey
, "NoRemoteResize", 0, &cfg
->no_remote_resize
);
660 gppi(sesskey
, "NoAltScreen", 0, &cfg
->no_alt_screen
);
661 gppi(sesskey
, "NoRemoteWinTitle", 0, &cfg
->no_remote_wintitle
);
663 /* Backward compatibility */
664 int no_remote_qtitle
;
665 gppi(sesskey
, "NoRemoteQTitle", 1, &no_remote_qtitle
);
666 /* We deliberately interpret the old setting of "no response" as
667 * "empty string". This changes the behaviour, but hopefully for
668 * the better; the user can always recover the old behaviour. */
669 gppi(sesskey
, "RemoteQTitleAction",
670 no_remote_qtitle ? TITLE_EMPTY
: TITLE_REAL
,
671 &cfg
->remote_qtitle_action
);
673 gppi(sesskey
, "NoDBackspace", 0, &cfg
->no_dbackspace
);
674 gppi(sesskey
, "NoRemoteCharset", 0, &cfg
->no_remote_charset
);
675 gppi(sesskey
, "ApplicationCursorKeys", 0, &cfg
->app_cursor
);
676 gppi(sesskey
, "ApplicationKeypad", 0, &cfg
->app_keypad
);
677 gppi(sesskey
, "NetHackKeypad", 0, &cfg
->nethack_keypad
);
678 gppi(sesskey
, "AltF4", 1, &cfg
->alt_f4
);
679 gppi(sesskey
, "AltSpace", 0, &cfg
->alt_space
);
680 gppi(sesskey
, "AltOnly", 0, &cfg
->alt_only
);
681 gppi(sesskey
, "ComposeKey", 0, &cfg
->compose_key
);
682 gppi(sesskey
, "CtrlAltKeys", 1, &cfg
->ctrlaltkeys
);
683 gppi(sesskey
, "TelnetKey", 0, &cfg
->telnet_keyboard
);
684 gppi(sesskey
, "TelnetRet", 1, &cfg
->telnet_newline
);
685 gppi(sesskey
, "LocalEcho", AUTO
, &cfg
->localecho
);
686 gppi(sesskey
, "LocalEdit", AUTO
, &cfg
->localedit
);
687 gpps(sesskey
, "Answerback", "PuTTY", cfg
->answerback
,
688 sizeof(cfg
->answerback
));
689 gppi(sesskey
, "AlwaysOnTop", 0, &cfg
->alwaysontop
);
690 gppi(sesskey
, "FullScreenOnAltEnter", 0, &cfg
->fullscreenonaltenter
);
691 gppi(sesskey
, "HideMousePtr", 0, &cfg
->hide_mouseptr
);
692 gppi(sesskey
, "SunkenEdge", 0, &cfg
->sunken_edge
);
693 gppi(sesskey
, "WindowBorder", 1, &cfg
->window_border
);
694 gppi(sesskey
, "CurType", 0, &cfg
->cursor_type
);
695 gppi(sesskey
, "BlinkCur", 0, &cfg
->blink_cur
);
696 /* pedantic compiler tells me I can't use &cfg->beep as an int * :-) */
697 gppi(sesskey
, "Beep", 1, &cfg
->beep
);
698 gppi(sesskey
, "BeepInd", 0, &cfg
->beep_ind
);
699 gppfile(sesskey
, "BellWaveFile", &cfg
->bell_wavefile
);
700 gppi(sesskey
, "BellOverload", 1, &cfg
->bellovl
);
701 gppi(sesskey
, "BellOverloadN", 5, &cfg
->bellovl_n
);
702 gppi(sesskey
, "BellOverloadT", 2*TICKSPERSEC
712 gppi(sesskey
, "BellOverloadS", 5*TICKSPERSEC
722 gppi(sesskey
, "ScrollbackLines", 200, &cfg
->savelines
);
723 gppi(sesskey
, "DECOriginMode", 0, &cfg
->dec_om
);
724 gppi(sesskey
, "AutoWrapMode", 1, &cfg
->wrap_mode
);
725 gppi(sesskey
, "LFImpliesCR", 0, &cfg
->lfhascr
);
726 gppi(sesskey
, "CRImpliesLF", 0, &cfg
->crhaslf
);
727 gppi(sesskey
, "DisableArabicShaping", 0, &cfg
->arabicshaping
);
728 gppi(sesskey
, "DisableBidi", 0, &cfg
->bidi
);
729 gppi(sesskey
, "WinNameAlways", 1, &cfg
->win_name_always
);
730 gpps(sesskey
, "WinTitle", "", cfg
->wintitle
, sizeof(cfg
->wintitle
));
731 gppi(sesskey
, "TermWidth", 80, &cfg
->width
);
732 gppi(sesskey
, "TermHeight", 24, &cfg
->height
);
733 gppfont(sesskey
, "Font", &cfg
->font
);
734 gppi(sesskey
, "FontQuality", FQ_DEFAULT
, &cfg
->font_quality
);
735 gppi(sesskey
, "FontVTMode", VT_UNICODE
, (int *) &cfg
->vtmode
);
736 gppi(sesskey
, "UseSystemColours", 0, &cfg
->system_colour
);
737 gppi(sesskey
, "TryPalette", 0, &cfg
->try_palette
);
738 gppi(sesskey
, "ANSIColour", 1, &cfg
->ansi_colour
);
739 gppi(sesskey
, "Xterm256Colour", 1, &cfg
->xterm_256_colour
);
740 gppi(sesskey
, "BoldAsColour", 1, &cfg
->bold_colour
);
742 for (i
= 0; i
< 22; i
++) {
743 static const char *const defaults
[] = {
744 "187,187,187", "255,255,255", "0,0,0", "85,85,85", "0,0,0",
745 "0,255,0", "0,0,0", "85,85,85", "187,0,0", "255,85,85",
746 "0,187,0", "85,255,85", "187,187,0", "255,255,85", "0,0,187",
747 "85,85,255", "187,0,187", "255,85,255", "0,187,187",
748 "85,255,255", "187,187,187", "255,255,255"
750 char buf
[20], buf2
[30];
752 sprintf(buf
, "Colour%d", i
);
753 gpps(sesskey
, buf
, defaults
[i
], buf2
, sizeof(buf2
));
754 if (sscanf(buf2
, "%d,%d,%d", &c0
, &c1
, &c2
) == 3) {
755 cfg
->colours
[i
][0] = c0
;
756 cfg
->colours
[i
][1] = c1
;
757 cfg
->colours
[i
][2] = c2
;
760 gppi(sesskey
, "RawCNP", 0, &cfg
->rawcnp
);
761 gppi(sesskey
, "PasteRTF", 0, &cfg
->rtf_paste
);
762 gppi(sesskey
, "MouseIsXterm", 0, &cfg
->mouse_is_xterm
);
763 gppi(sesskey
, "RectSelect", 0, &cfg
->rect_select
);
764 gppi(sesskey
, "MouseOverride", 1, &cfg
->mouse_override
);
765 for (i
= 0; i
< 256; i
+= 32) {
766 static const char *const defaults
[] = {
767 "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",
768 "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",
769 "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",
770 "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",
771 "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",
772 "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",
773 "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",
774 "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"
776 char buf
[20], buf2
[256], *p
;
778 sprintf(buf
, "Wordness%d", i
);
779 gpps(sesskey
, buf
, defaults
[i
/ 32], buf2
, sizeof(buf2
));
781 for (j
= i
; j
< i
+ 32; j
++) {
783 while (*p
&& *p
!= ',')
787 cfg
->wordness
[j
] = atoi(q
);
791 * The empty default for LineCodePage will be converted later
792 * into a plausible default for the locale.
794 gpps(sesskey
, "LineCodePage", "", cfg
->line_codepage
,
795 sizeof(cfg
->line_codepage
));
796 gppi(sesskey
, "CJKAmbigWide", 0, &cfg
->cjk_ambig_wide
);
797 gppi(sesskey
, "UTF8Override", 1, &cfg
->utf8_override
);
798 gpps(sesskey
, "Printer", "", cfg
->printer
, sizeof(cfg
->printer
));
799 gppi (sesskey
, "CapsLockCyr", 0, &cfg
->xlat_capslockcyr
);
800 gppi(sesskey
, "ScrollBar", 1, &cfg
->scrollbar
);
801 gppi(sesskey
, "ScrollBarFullScreen", 0, &cfg
->scrollbar_in_fullscreen
);
802 gppi(sesskey
, "ScrollOnKey", 0, &cfg
->scroll_on_key
);
803 gppi(sesskey
, "ScrollOnDisp", 1, &cfg
->scroll_on_disp
);
804 gppi(sesskey
, "EraseToScrollback", 1, &cfg
->erase_to_scrollback
);
805 gppi(sesskey
, "LockSize", 0, &cfg
->resize_action
);
806 gppi(sesskey
, "BCE", 1, &cfg
->bce
);
807 gppi(sesskey
, "BlinkText", 0, &cfg
->blinktext
);
808 gppi(sesskey
, "X11Forward", 0, &cfg
->x11_forward
);
809 gpps(sesskey
, "X11Display", "", cfg
->x11_display
,
810 sizeof(cfg
->x11_display
));
811 gppi(sesskey
, "X11AuthType", X11_MIT
, &cfg
->x11_auth
);
812 gppfile(sesskey
, "X11AuthFile", &cfg
->xauthfile
);
814 gppi(sesskey
, "LocalPortAcceptAll", 0, &cfg
->lport_acceptall
);
815 gppi(sesskey
, "RemotePortAcceptAll", 0, &cfg
->rport_acceptall
);
816 gppmap(sesskey
, "PortForwardings", "", cfg
->portfwd
, lenof(cfg
->portfwd
));
817 gppi(sesskey
, "BugIgnore1", 0, &i
); cfg
->sshbug_ignore1
= 2-i
;
818 gppi(sesskey
, "BugPlainPW1", 0, &i
); cfg
->sshbug_plainpw1
= 2-i
;
819 gppi(sesskey
, "BugRSA1", 0, &i
); cfg
->sshbug_rsa1
= 2-i
;
822 gppi(sesskey
, "BugHMAC2", 0, &i
); cfg
->sshbug_hmac2
= 2-i
;
823 if (cfg
->sshbug_hmac2
== AUTO
) {
824 gppi(sesskey
, "BuggyMAC", 0, &i
);
826 cfg
->sshbug_hmac2
= FORCE_ON
;
829 gppi(sesskey
, "BugDeriveKey2", 0, &i
); cfg
->sshbug_derivekey2
= 2-i
;
830 gppi(sesskey
, "BugRSAPad2", 0, &i
); cfg
->sshbug_rsapad2
= 2-i
;
831 gppi(sesskey
, "BugPKSessID2", 0, &i
); cfg
->sshbug_pksessid2
= 2-i
;
832 gppi(sesskey
, "BugRekey2", 0, &i
); cfg
->sshbug_rekey2
= 2-i
;
833 gppi(sesskey
, "BugMaxPkt2", 0, &i
); cfg
->sshbug_maxpkt2
= 2-i
;
834 cfg
->ssh_simple
= FALSE
;
835 gppi(sesskey
, "StampUtmp", 1, &cfg
->stamp_utmp
);
836 gppi(sesskey
, "LoginShell", 1, &cfg
->login_shell
);
837 gppi(sesskey
, "ScrollbarOnLeft", 0, &cfg
->scrollbar_on_left
);
838 gppi(sesskey
, "ShadowBold", 0, &cfg
->shadowbold
);
839 gppfont(sesskey
, "BoldFont", &cfg
->boldfont
);
840 gppfont(sesskey
, "WideFont", &cfg
->widefont
);
841 gppfont(sesskey
, "WideBoldFont", &cfg
->wideboldfont
);
842 gppi(sesskey
, "ShadowBoldOffset", 1, &cfg
->shadowboldoffset
);
843 gpps(sesskey
, "SerialLine", "", cfg
->serline
, sizeof(cfg
->serline
));
844 gppi(sesskey
, "SerialSpeed", 9600, &cfg
->serspeed
);
845 gppi(sesskey
, "SerialDataBits", 8, &cfg
->serdatabits
);
846 gppi(sesskey
, "SerialStopHalfbits", 2, &cfg
->serstopbits
);
847 gppi(sesskey
, "SerialParity", SER_PAR_NONE
, &cfg
->serparity
);
848 gppi(sesskey
, "SerialFlowControl", SER_FLOW_XONXOFF
, &cfg
->serflow
);
851 void do_defaults(char *session
, Config
* cfg
)
853 load_settings(session
, cfg
);
856 static int sessioncmp(const void *av
, const void *bv
)
858 const char *a
= *(const char *const *) av
;
859 const char *b
= *(const char *const *) bv
;
862 * Alphabetical order, except that "Default Settings" is a
863 * special case and comes first.
865 if (!strcmp(a
, "Default Settings"))
866 return -1; /* a comes first */
867 if (!strcmp(b
, "Default Settings"))
868 return +1; /* b comes first */
870 * FIXME: perhaps we should ignore the first & in determining
873 return strcmp(a
, b
); /* otherwise, compare normally */
876 void get_sesslist(struct sesslist
*list
, int allocate
)
879 int buflen
, bufsize
, i
;
885 buflen
= bufsize
= 0;
887 if ((handle
= enum_settings_start()) != NULL
) {
889 ret
= enum_settings_next(handle
, otherbuf
, sizeof(otherbuf
));
891 int len
= strlen(otherbuf
) + 1;
892 if (bufsize
< buflen
+ len
) {
893 bufsize
= buflen
+ len
+ 2048;
894 list
->buffer
= sresize(list
->buffer
, bufsize
, char);
896 strcpy(list
->buffer
+ buflen
, otherbuf
);
897 buflen
+= strlen(list
->buffer
+ buflen
) + 1;
900 enum_settings_finish(handle
);
902 list
->buffer
= sresize(list
->buffer
, buflen
+ 1, char);
903 list
->buffer
[buflen
] = '\0';
906 * Now set up the list of sessions. Note that "Default
907 * Settings" must always be claimed to exist, even if it
912 list
->nsessions
= 1; /* "Default Settings" counts as one */
914 if (strcmp(p
, "Default Settings"))
921 list
->sessions
= snewn(list
->nsessions
+ 1, char *);
922 list
->sessions
[0] = "Default Settings";
926 if (strcmp(p
, "Default Settings"))
927 list
->sessions
[i
++] = p
;
933 qsort(list
->sessions
, i
, sizeof(char *), sessioncmp
);
936 sfree(list
->sessions
);
938 list
->sessions
= NULL
;