settings.c 60 KB

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