source: filezilla/trunk/fuentes/src/putty/settings.c @ 3185

Last change on this file since 3185 was 3185, checked in by jrpelegrina, 3 years ago

Update new version: 3.15.02

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