settings.c 61 KB

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