settings.c 60 KB

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