settings.c 62 KB

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