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