settings.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  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, 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_H
  628. * 1000
  629. #endif
  630. );
  631. write_setting_i(sesskey, "BellOverloadS", conf_get_int(conf, CONF_bellovl_s)
  632. #ifdef PUTTY_UNIX_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, "BugDropStart", 2-conf_get_int(conf, CONF_sshbug_dropstart));
  726. write_setting_i(sesskey, "BugFilterKexinit", 2-conf_get_int(conf, CONF_sshbug_filter_kexinit));
  727. write_setting_b(sesskey, "StampUtmp", conf_get_bool(conf, CONF_stamp_utmp));
  728. write_setting_b(sesskey, "LoginShell", conf_get_bool(conf, CONF_login_shell));
  729. write_setting_b(sesskey, "ScrollbarOnLeft", conf_get_bool(conf, CONF_scrollbar_on_left));
  730. write_setting_fontspec(sesskey, "BoldFont", conf_get_fontspec(conf, CONF_boldfont));
  731. write_setting_fontspec(sesskey, "WideFont", conf_get_fontspec(conf, CONF_widefont));
  732. write_setting_fontspec(sesskey, "WideBoldFont", conf_get_fontspec(conf, CONF_wideboldfont));
  733. write_setting_b(sesskey, "ShadowBold", conf_get_bool(conf, CONF_shadowbold));
  734. write_setting_i(sesskey, "ShadowBoldOffset", conf_get_int(conf, CONF_shadowboldoffset));
  735. write_setting_s(sesskey, "SerialLine", conf_get_str(conf, CONF_serline));
  736. write_setting_i(sesskey, "SerialSpeed", conf_get_int(conf, CONF_serspeed));
  737. write_setting_i(sesskey, "SerialDataBits", conf_get_int(conf, CONF_serdatabits));
  738. write_setting_i(sesskey, "SerialStopHalfbits", conf_get_int(conf, CONF_serstopbits));
  739. write_setting_i(sesskey, "SerialParity", conf_get_int(conf, CONF_serparity));
  740. write_setting_i(sesskey, "SerialFlowControl", conf_get_int(conf, CONF_serflow));
  741. write_setting_s(sesskey, "WindowClass", conf_get_str(conf, CONF_winclass));
  742. write_setting_b(sesskey, "ConnectionSharing", conf_get_bool(conf, CONF_ssh_connection_sharing));
  743. write_setting_b(sesskey, "ConnectionSharingUpstream", conf_get_bool(conf, CONF_ssh_connection_sharing_upstream));
  744. write_setting_b(sesskey, "ConnectionSharingDownstream", conf_get_bool(conf, CONF_ssh_connection_sharing_downstream));
  745. wmap(sesskey, "SSHManualHostKeys", conf, CONF_ssh_manual_hostkeys, false);
  746. /*
  747. * SUPDUP settings
  748. */
  749. write_setting_s(sesskey, "SUPDUPLocation", conf_get_str(conf, CONF_supdup_location));
  750. write_setting_i(sesskey, "SUPDUPCharset", conf_get_int(conf, CONF_supdup_ascii_set));
  751. write_setting_b(sesskey, "SUPDUPMoreProcessing", conf_get_bool(conf, CONF_supdup_more));
  752. write_setting_b(sesskey, "SUPDUPScrolling", conf_get_bool(conf, CONF_supdup_scroll));
  753. }
  754. bool load_settings(const char *section, Conf *conf)
  755. {
  756. settings_r *sesskey;
  757. sesskey = open_settings_r(section);
  758. { // WINSCP
  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. } // WINSCP
  766. }
  767. void load_open_settings(settings_r *sesskey, Conf *conf)
  768. {
  769. int i;
  770. char *prot;
  771. conf_set_bool(conf, CONF_ssh_subsys, false); /* FIXME: load this properly */
  772. conf_set_str(conf, CONF_remote_cmd, "");
  773. conf_set_str(conf, CONF_remote_cmd2, "");
  774. conf_set_str(conf, CONF_ssh_nc_host, "");
  775. gpps(sesskey, "HostName", "", conf, CONF_host);
  776. gppfile(sesskey, "LogFileName", conf, CONF_logfilename);
  777. gppi(sesskey, "LogType", 0, conf, CONF_logtype);
  778. gppi(sesskey, "LogFileClash", LGXF_ASK, conf, CONF_logxfovr);
  779. gppb(sesskey, "LogFlush", true, conf, CONF_logflush);
  780. gppb(sesskey, "LogHeader", true, conf, CONF_logheader);
  781. gppb(sesskey, "SSHLogOmitPasswords", true, conf, CONF_logomitpass);
  782. gppb(sesskey, "SSHLogOmitData", false, conf, CONF_logomitdata);
  783. prot = gpps_raw(sesskey, "Protocol", "default");
  784. conf_set_int(conf, CONF_protocol, default_protocol);
  785. conf_set_int(conf, CONF_port, default_port);
  786. {
  787. const struct BackendVtable *vt = backend_vt_from_name(prot);
  788. if (vt) {
  789. conf_set_int(conf, CONF_protocol, vt->protocol);
  790. gppi(sesskey, "PortNumber", default_port, conf, CONF_port);
  791. }
  792. }
  793. sfree(prot);
  794. /* Address family selection */
  795. gppi(sesskey, "AddressFamily", ADDRTYPE_UNSPEC, conf, CONF_addressfamily);
  796. /* The CloseOnExit numbers are arranged in a different order from
  797. * the standard FORCE_ON / FORCE_OFF / AUTO. */
  798. i = gppi_raw(sesskey, "CloseOnExit", 1); conf_set_int(conf, CONF_close_on_exit, (i+1)%3);
  799. gppb(sesskey, "WarnOnClose", true, conf, CONF_warn_on_close);
  800. {
  801. /* This is two values for backward compatibility with 0.50/0.51 */
  802. int pingmin, pingsec;
  803. pingmin = gppi_raw(sesskey, "PingInterval", 0);
  804. pingsec = gppi_raw(sesskey, "PingIntervalSecs", 0);
  805. conf_set_int(conf, CONF_ping_interval, pingmin * 60 + pingsec);
  806. }
  807. gppb(sesskey, "TCPNoDelay", true, conf, CONF_tcp_nodelay);
  808. gppb(sesskey, "TCPKeepalives", false, conf, CONF_tcp_keepalives);
  809. gpps(sesskey, "TerminalType", "xterm", conf, CONF_termtype);
  810. gpps(sesskey, "TerminalSpeed", "38400,38400", conf, CONF_termspeed);
  811. if (gppmap(sesskey, "TerminalModes", conf, CONF_ttymodes)) {
  812. /*
  813. * Backwards compatibility with old saved settings.
  814. *
  815. * From the invention of this setting through 0.67, the set of
  816. * terminal modes was fixed, and absence of a mode from this
  817. * setting meant the user had explicitly removed it from the
  818. * UI and we shouldn't send it.
  819. *
  820. * In 0.68, the IUTF8 mode was added, and in handling old
  821. * settings we inadvertently removed the ability to not send
  822. * a mode. Any mode not mentioned was treated as if it was
  823. * set to 'auto' (A).
  824. *
  825. * After 0.68, we added explicit notation to the setting format
  826. * when the user removes a known terminal mode from the list.
  827. *
  828. * So: if any of the modes from the original set is missing, we
  829. * assume this was an intentional removal by the user and add
  830. * an explicit removal ('N'); but if IUTF8 (or any other mode
  831. * added after 0.67) is missing, we assume that its absence is
  832. * due to the setting being old rather than intentional, and
  833. * add it with its default setting.
  834. *
  835. * (This does mean that if a 0.68 user explicitly removed IUTF8,
  836. * we add it back; but removing IUTF8 had no effect in 0.68, so
  837. * we're preserving behaviour, which is the best we can do.)
  838. */
  839. for (i = 0; ttymodes[i]; i++) {
  840. if (!conf_get_str_str_opt(conf, CONF_ttymodes, ttymodes[i])) {
  841. /* Mode not mentioned in setting. */
  842. const char *def;
  843. if (!strcmp(ttymodes[i], "IUTF8")) {
  844. /* Any new modes we add in future should be treated
  845. * this way too. */
  846. def = "A"; /* same as new-setting default below */
  847. } else {
  848. /* One of the original modes. Absence is probably
  849. * deliberate. */
  850. def = "N"; /* don't send */
  851. }
  852. conf_set_str_str(conf, CONF_ttymodes, ttymodes[i], def);
  853. }
  854. }
  855. } else {
  856. /* This hardcodes a big set of defaults in any new saved
  857. * sessions. Let's hope we don't change our mind. */
  858. for (i = 0; ttymodes[i]; i++)
  859. conf_set_str_str(conf, CONF_ttymodes, ttymodes[i], "A");
  860. }
  861. /* proxy settings */
  862. gpps(sesskey, "ProxyExcludeList", "", conf, CONF_proxy_exclude_list);
  863. i = gppi_raw(sesskey, "ProxyDNS", 1); conf_set_int(conf, CONF_proxy_dns, (i+1)%3);
  864. gppb(sesskey, "ProxyLocalhost", false, conf, CONF_even_proxy_localhost);
  865. gppi(sesskey, "ProxyMethod", -1, conf, CONF_proxy_type);
  866. if (conf_get_int(conf, CONF_proxy_type) == -1) {
  867. int i;
  868. i = gppi_raw(sesskey, "ProxyType", 0);
  869. if (i == 0)
  870. conf_set_int(conf, CONF_proxy_type, PROXY_NONE);
  871. else if (i == 1)
  872. conf_set_int(conf, CONF_proxy_type, PROXY_HTTP);
  873. else if (i == 3)
  874. conf_set_int(conf, CONF_proxy_type, PROXY_TELNET);
  875. else if (i == 4)
  876. conf_set_int(conf, CONF_proxy_type, PROXY_CMD);
  877. else {
  878. i = gppi_raw(sesskey, "ProxySOCKSVersion", 5);
  879. if (i == 5)
  880. conf_set_int(conf, CONF_proxy_type, PROXY_SOCKS5);
  881. else
  882. conf_set_int(conf, CONF_proxy_type, PROXY_SOCKS4);
  883. }
  884. }
  885. gpps(sesskey, "ProxyHost", "proxy", conf, CONF_proxy_host);
  886. gppi(sesskey, "ProxyPort", 80, conf, CONF_proxy_port);
  887. gpps(sesskey, "ProxyUsername", "", conf, CONF_proxy_username);
  888. gpps(sesskey, "ProxyPassword", "", conf, CONF_proxy_password);
  889. gpps(sesskey, "ProxyTelnetCommand", "connect %host %port\\n",
  890. conf, CONF_proxy_telnet_command);
  891. gppi(sesskey, "ProxyLogToTerm", FORCE_OFF, conf, CONF_proxy_log_to_term);
  892. gppmap(sesskey, "Environment", conf, CONF_environmt);
  893. gpps(sesskey, "UserName", "", conf, CONF_username);
  894. gppb(sesskey, "UserNameFromEnvironment", false,
  895. conf, CONF_username_from_env);
  896. gpps(sesskey, "LocalUserName", "", conf, CONF_localusername);
  897. gppb(sesskey, "NoPTY", false, conf, CONF_nopty);
  898. gppb(sesskey, "Compression", false, conf, CONF_compression);
  899. gppb(sesskey, "TryAgent", true, conf, CONF_tryagent);
  900. gppb(sesskey, "AgentFwd", false, conf, CONF_agentfwd);
  901. gppb(sesskey, "ChangeUsername", false, conf, CONF_change_username);
  902. #ifndef NO_GSSAPI
  903. gppb(sesskey, "GssapiFwd", false, conf, CONF_gssapifwd);
  904. #endif
  905. gprefs(sesskey, "Cipher", "\0",
  906. ciphernames, CIPHER_MAX, conf, CONF_ssh_cipherlist);
  907. {
  908. /* Backward-compatibility: before 0.58 (when the "KEX"
  909. * preference was first added), we had an option to
  910. * disable gex under the "bugs" panel after one report of
  911. * a server which offered it then choked, but we never got
  912. * a server version string or any other reports. */
  913. const char *default_kexes,
  914. *normal_default = "ecdh,dh-gex-sha1,dh-group18-sha512,dh-group17-sha512,dh-group16-sha512,dh-group15-sha512,dh-group14-sha1,rsa,"
  915. "WARN,dh-group1-sha1",
  916. *bugdhgex2_default = "ecdh,dh-group18-sha512,dh-group17-sha512,dh-group16-sha512,dh-group15-sha512,dh-group14-sha1,rsa,"
  917. "WARN,dh-group1-sha1,dh-gex-sha1";
  918. char *raw;
  919. i = 2 - gppi_raw(sesskey, "BugDHGEx2", 0);
  920. if (i == FORCE_ON)
  921. default_kexes = bugdhgex2_default;
  922. else
  923. default_kexes = normal_default;
  924. /* Migration: after 0.67 we decided we didn't like
  925. * dh-group1-sha1. If it looks like the user never changed
  926. * the defaults, quietly upgrade their settings to demote it.
  927. * (If they did, they're on their own.) */
  928. raw = gpps_raw(sesskey, "KEX", default_kexes);
  929. assert(raw != NULL);
  930. /* Lack of 'ecdh' tells us this was saved by 0.58-0.67
  931. * inclusive. If it was saved by a later version, we need
  932. * to leave it alone. */
  933. if (strcmp(raw, "dh-group14-sha1,dh-group1-sha1,rsa,"
  934. "WARN,dh-gex-sha1") == 0) {
  935. /* Previously migrated from BugDHGEx2. */
  936. sfree(raw);
  937. raw = dupstr(bugdhgex2_default);
  938. } else if (strcmp(raw, "dh-gex-sha1,dh-group14-sha1,"
  939. "dh-group1-sha1,rsa,WARN") == 0) {
  940. /* Untouched old default setting. */
  941. sfree(raw);
  942. raw = dupstr(normal_default);
  943. }
  944. /* (For the record: after 0.70, the default algorithm list
  945. * very briefly contained the string 'gss-sha1-krb5'; this was
  946. * never used in any committed version of code, but was left
  947. * over from a pre-commit version of GSS key exchange.
  948. * Mentioned here as it is remotely possible that it will turn
  949. * up in someone's saved settings in future.) */
  950. gprefs_from_str(raw, kexnames, KEX_MAX, conf, CONF_ssh_kexlist);
  951. sfree(raw);
  952. }
  953. gprefs(sesskey, "HostKey", "ed25519,ecdsa,rsa,dsa,WARN",
  954. hknames, HK_MAX, conf, CONF_ssh_hklist);
  955. gppb(sesskey, "PreferKnownHostKeys", true, conf, CONF_ssh_prefer_known_hostkeys);
  956. gppi(sesskey, "RekeyTime", 60, conf, CONF_ssh_rekey_time);
  957. #ifndef NO_GSSAPI
  958. gppi(sesskey, "GssapiRekey", GSS_DEF_REKEY_MINS, conf, CONF_gssapirekey);
  959. #endif
  960. gpps(sesskey, "RekeyBytes", "1G", conf, CONF_ssh_rekey_data);
  961. {
  962. /* SSH-2 only by default */
  963. int sshprot = gppi_raw(sesskey, "SshProt", 3);
  964. /* Old sessions may contain the values corresponding to the fallbacks
  965. * we used to allow; migrate them */
  966. if (sshprot == 1) sshprot = 0; /* => "SSH-1 only" */
  967. else if (sshprot == 2) sshprot = 3; /* => "SSH-2 only" */
  968. conf_set_int(conf, CONF_sshprot, sshprot);
  969. }
  970. gpps(sesskey, "LogHost", "", conf, CONF_loghost);
  971. gppb(sesskey, "SSH2DES", false, conf, CONF_ssh2_des_cbc);
  972. gppb(sesskey, "SshNoAuth", false, conf, CONF_ssh_no_userauth);
  973. gppb(sesskey, "SshNoTrivialAuth", false, conf, CONF_ssh_no_trivial_userauth);
  974. gppb(sesskey, "SshBanner", true, conf, CONF_ssh_show_banner);
  975. gppb(sesskey, "AuthTIS", false, conf, CONF_try_tis_auth);
  976. gppb(sesskey, "AuthKI", true, conf, CONF_try_ki_auth);
  977. #ifndef NO_GSSAPI
  978. gppb(sesskey, "AuthGSSAPI", true, conf, CONF_try_gssapi_auth);
  979. gppb(sesskey, "AuthGSSAPIKEX", true, conf, CONF_try_gssapi_kex);
  980. gprefs(sesskey, "GSSLibs", "\0",
  981. gsslibkeywords, ngsslibs, conf, CONF_ssh_gsslist);
  982. gppfile(sesskey, "GSSCustom", conf, CONF_ssh_gss_custom);
  983. #endif
  984. gppb(sesskey, "SshNoShell", false, conf, CONF_ssh_no_shell);
  985. gppfile(sesskey, "PublicKeyFile", conf, CONF_keyfile);
  986. gppfile(sesskey, "DetachedCertificate", conf, CONF_detached_cert);
  987. gpps(sesskey, "AuthPlugin", "", conf, CONF_auth_plugin);
  988. gpps(sesskey, "RemoteCommand", "", conf, CONF_remote_cmd);
  989. gppb(sesskey, "RFCEnviron", false, conf, CONF_rfc_environ);
  990. gppb(sesskey, "PassiveTelnet", false, conf, CONF_passive_telnet);
  991. gppb(sesskey, "BackspaceIsDelete", true, conf, CONF_bksp_is_delete);
  992. gppb(sesskey, "RXVTHomeEnd", false, conf, CONF_rxvt_homeend);
  993. gppi(sesskey, "LinuxFunctionKeys", 0, conf, CONF_funky_type);
  994. gppi(sesskey, "ShiftedArrowKeys", SHARROW_APPLICATION, conf,
  995. CONF_sharrow_type);
  996. gppb(sesskey, "NoApplicationKeys", false, conf, CONF_no_applic_k);
  997. gppb(sesskey, "NoApplicationCursors", false, conf, CONF_no_applic_c);
  998. gppb(sesskey, "NoMouseReporting", false, conf, CONF_no_mouse_rep);
  999. gppb(sesskey, "NoRemoteResize", false, conf, CONF_no_remote_resize);
  1000. gppb(sesskey, "NoAltScreen", false, conf, CONF_no_alt_screen);
  1001. gppb(sesskey, "NoRemoteWinTitle", false, conf, CONF_no_remote_wintitle);
  1002. gppb(sesskey, "NoRemoteClearScroll", false,
  1003. conf, CONF_no_remote_clearscroll);
  1004. {
  1005. /* Backward compatibility */
  1006. int no_remote_qtitle = gppi_raw(sesskey, "NoRemoteQTitle", 1);
  1007. /* We deliberately interpret the old setting of "no response" as
  1008. * "empty string". This changes the behaviour, but hopefully for
  1009. * the better; the user can always recover the old behaviour. */
  1010. gppi(sesskey, "RemoteQTitleAction",
  1011. no_remote_qtitle ? TITLE_EMPTY : TITLE_REAL,
  1012. conf, CONF_remote_qtitle_action);
  1013. }
  1014. gppb(sesskey, "NoDBackspace", false, conf, CONF_no_dbackspace);
  1015. gppb(sesskey, "NoRemoteCharset", false, conf, CONF_no_remote_charset);
  1016. gppb(sesskey, "ApplicationCursorKeys", false, conf, CONF_app_cursor);
  1017. gppb(sesskey, "ApplicationKeypad", false, conf, CONF_app_keypad);
  1018. gppb(sesskey, "NetHackKeypad", false, conf, CONF_nethack_keypad);
  1019. gppb(sesskey, "AltF4", true, conf, CONF_alt_f4);
  1020. gppb(sesskey, "AltSpace", false, conf, CONF_alt_space);
  1021. gppb(sesskey, "AltOnly", false, conf, CONF_alt_only);
  1022. gppb(sesskey, "ComposeKey", false, conf, CONF_compose_key);
  1023. gppb(sesskey, "CtrlAltKeys", true, conf, CONF_ctrlaltkeys);
  1024. #ifdef OSX_META_KEY_CONFIG
  1025. gppb(sesskey, "OSXOptionMeta", true, conf, CONF_osx_option_meta);
  1026. gppb(sesskey, "OSXCommandMeta", false, conf, CONF_osx_command_meta);
  1027. #endif
  1028. gppb(sesskey, "TelnetKey", false, conf, CONF_telnet_keyboard);
  1029. gppb(sesskey, "TelnetRet", true, conf, CONF_telnet_newline);
  1030. gppi(sesskey, "LocalEcho", AUTO, conf, CONF_localecho);
  1031. gppi(sesskey, "LocalEdit", AUTO, conf, CONF_localedit);
  1032. gpps(sesskey, "Answerback", "PuTTY", conf, CONF_answerback);
  1033. gppb(sesskey, "AlwaysOnTop", false, conf, CONF_alwaysontop);
  1034. gppb(sesskey, "FullScreenOnAltEnter", false,
  1035. conf, CONF_fullscreenonaltenter);
  1036. gppb(sesskey, "HideMousePtr", false, conf, CONF_hide_mouseptr);
  1037. gppb(sesskey, "SunkenEdge", false, conf, CONF_sunken_edge);
  1038. gppi(sesskey, "WindowBorder", 1, conf, CONF_window_border);
  1039. gppi(sesskey, "CurType", 0, conf, CONF_cursor_type);
  1040. gppb(sesskey, "BlinkCur", false, conf, CONF_blink_cur);
  1041. /* pedantic compiler tells me I can't use conf, CONF_beep as an int * :-) */
  1042. gppi(sesskey, "Beep", 1, conf, CONF_beep);
  1043. gppi(sesskey, "BeepInd", 0, conf, CONF_beep_ind);
  1044. gppfile(sesskey, "BellWaveFile", conf, CONF_bell_wavefile);
  1045. gppb(sesskey, "BellOverload", true, conf, CONF_bellovl);
  1046. gppi(sesskey, "BellOverloadN", 5, conf, CONF_bellovl_n);
  1047. i = gppi_raw(sesskey, "BellOverloadT", 2*TICKSPERSEC
  1048. #ifdef PUTTY_UNIX_H
  1049. *1000
  1050. #endif
  1051. );
  1052. conf_set_int(conf, CONF_bellovl_t, i
  1053. #ifdef PUTTY_UNIX_H
  1054. / 1000
  1055. #endif
  1056. );
  1057. i = gppi_raw(sesskey, "BellOverloadS", 5*TICKSPERSEC
  1058. #ifdef PUTTY_UNIX_H
  1059. *1000
  1060. #endif
  1061. );
  1062. conf_set_int(conf, CONF_bellovl_s, i
  1063. #ifdef PUTTY_UNIX_H
  1064. / 1000
  1065. #endif
  1066. );
  1067. gppi(sesskey, "ScrollbackLines", 2000, conf, CONF_savelines);
  1068. gppb(sesskey, "DECOriginMode", false, conf, CONF_dec_om);
  1069. gppb(sesskey, "AutoWrapMode", true, conf, CONF_wrap_mode);
  1070. gppb(sesskey, "LFImpliesCR", false, conf, CONF_lfhascr);
  1071. gppb(sesskey, "CRImpliesLF", false, conf, CONF_crhaslf);
  1072. gppb(sesskey, "DisableArabicShaping", false, conf, CONF_no_arabicshaping);
  1073. gppb(sesskey, "DisableBidi", false, conf, CONF_no_bidi);
  1074. gppb(sesskey, "WinNameAlways", true, conf, CONF_win_name_always);
  1075. gpps(sesskey, "WinTitle", "", conf, CONF_wintitle);
  1076. gppi(sesskey, "TermWidth", 80, conf, CONF_width);
  1077. gppi(sesskey, "TermHeight", 24, conf, CONF_height);
  1078. gppfont(sesskey, "Font", conf, CONF_font);
  1079. gppi(sesskey, "FontQuality", FQ_DEFAULT, conf, CONF_font_quality);
  1080. gppi(sesskey, "FontVTMode", VT_UNICODE, conf, CONF_vtmode);
  1081. gppb(sesskey, "UseSystemColours", false, conf, CONF_system_colour);
  1082. gppb(sesskey, "TryPalette", false, conf, CONF_try_palette);
  1083. gppb(sesskey, "ANSIColour", true, conf, CONF_ansi_colour);
  1084. gppb(sesskey, "Xterm256Colour", true, conf, CONF_xterm_256_colour);
  1085. gppb(sesskey, "TrueColour", true, conf, CONF_true_colour);
  1086. i = gppi_raw(sesskey, "BoldAsColour", 1); conf_set_int(conf, CONF_bold_style, i+1);
  1087. for (i = 0; i < 22; i++) {
  1088. static const char *const defaults[] = {
  1089. "187,187,187", "255,255,255", "0,0,0", "85,85,85", "0,0,0",
  1090. "0,255,0", "0,0,0", "85,85,85", "187,0,0", "255,85,85",
  1091. "0,187,0", "85,255,85", "187,187,0", "255,255,85", "0,0,187",
  1092. "85,85,255", "187,0,187", "255,85,255", "0,187,187",
  1093. "85,255,255", "187,187,187", "255,255,255"
  1094. };
  1095. char buf[20], *buf2;
  1096. int c0, c1, c2;
  1097. sprintf(buf, "Colour%d", i);
  1098. buf2 = gpps_raw(sesskey, buf, defaults[i]);
  1099. if (sscanf(buf2, "%d,%d,%d", &c0, &c1, &c2) == 3) {
  1100. conf_set_int_int(conf, CONF_colours, i*3+0, c0);
  1101. conf_set_int_int(conf, CONF_colours, i*3+1, c1);
  1102. conf_set_int_int(conf, CONF_colours, i*3+2, c2);
  1103. }
  1104. sfree(buf2);
  1105. }
  1106. gppb(sesskey, "RawCNP", false, conf, CONF_rawcnp);
  1107. gppb(sesskey, "UTF8linedraw", false, conf, CONF_utf8linedraw);
  1108. gppb(sesskey, "PasteRTF", false, conf, CONF_rtf_paste);
  1109. gppi(sesskey, "MouseIsXterm", 0, conf, CONF_mouse_is_xterm);
  1110. gppb(sesskey, "RectSelect", false, conf, CONF_rect_select);
  1111. gppb(sesskey, "PasteControls", false, conf, CONF_paste_controls);
  1112. gppb(sesskey, "MouseOverride", true, conf, CONF_mouse_override);
  1113. for (i = 0; i < 256; i += 32) {
  1114. static const char *const defaults[] = {
  1115. "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",
  1116. "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",
  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,2",
  1118. "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",
  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. "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",
  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. "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"
  1123. };
  1124. char buf[20], *buf2, *p;
  1125. int j;
  1126. sprintf(buf, "Wordness%d", i);
  1127. buf2 = gpps_raw(sesskey, buf, defaults[i / 32]);
  1128. p = buf2;
  1129. for (j = i; j < i + 32; j++) {
  1130. char *q = p;
  1131. while (*p && *p != ',')
  1132. p++;
  1133. if (*p == ',')
  1134. *p++ = '\0';
  1135. conf_set_int_int(conf, CONF_wordness, j, atoi(q));
  1136. }
  1137. sfree(buf2);
  1138. }
  1139. gppb(sesskey, "MouseAutocopy", CLIPUI_DEFAULT_AUTOCOPY,
  1140. conf, CONF_mouseautocopy);
  1141. read_clip_setting(sesskey, "MousePaste", CLIPUI_DEFAULT_MOUSE,
  1142. conf, CONF_mousepaste, CONF_mousepaste_custom);
  1143. read_clip_setting(sesskey, "CtrlShiftIns", CLIPUI_DEFAULT_INS,
  1144. conf, CONF_ctrlshiftins, CONF_ctrlshiftins_custom);
  1145. read_clip_setting(sesskey, "CtrlShiftCV", CLIPUI_NONE,
  1146. conf, CONF_ctrlshiftcv, CONF_ctrlshiftcv_custom);
  1147. /*
  1148. * The empty default for LineCodePage will be converted later
  1149. * into a plausible default for the locale.
  1150. */
  1151. gpps(sesskey, "LineCodePage", "", conf, CONF_line_codepage);
  1152. gppb(sesskey, "CJKAmbigWide", false, conf, CONF_cjk_ambig_wide);
  1153. gppb(sesskey, "UTF8Override", true, conf, CONF_utf8_override);
  1154. gpps(sesskey, "Printer", "", conf, CONF_printer);
  1155. gppb(sesskey, "CapsLockCyr", false, conf, CONF_xlat_capslockcyr);
  1156. gppb(sesskey, "ScrollBar", true, conf, CONF_scrollbar);
  1157. gppb(sesskey, "ScrollBarFullScreen", false,
  1158. conf, CONF_scrollbar_in_fullscreen);
  1159. gppb(sesskey, "ScrollOnKey", false, conf, CONF_scroll_on_key);
  1160. gppb(sesskey, "ScrollOnDisp", true, conf, CONF_scroll_on_disp);
  1161. gppb(sesskey, "EraseToScrollback", true, conf, CONF_erase_to_scrollback);
  1162. gppi(sesskey, "LockSize", 0, conf, CONF_resize_action);
  1163. gppb(sesskey, "BCE", true, conf, CONF_bce);
  1164. gppb(sesskey, "BlinkText", false, conf, CONF_blinktext);
  1165. gppb(sesskey, "X11Forward", false, conf, CONF_x11_forward);
  1166. gpps(sesskey, "X11Display", "", conf, CONF_x11_display);
  1167. gppi(sesskey, "X11AuthType", X11_MIT, conf, CONF_x11_auth);
  1168. gppfile(sesskey, "X11AuthFile", conf, CONF_xauthfile);
  1169. gppb(sesskey, "LocalPortAcceptAll", false, conf, CONF_lport_acceptall);
  1170. gppb(sesskey, "RemotePortAcceptAll", false, conf, CONF_rport_acceptall);
  1171. gppmap(sesskey, "PortForwardings", conf, CONF_portfwd);
  1172. i = gppi_raw(sesskey, "BugIgnore1", 0); conf_set_int(conf, CONF_sshbug_ignore1, 2-i);
  1173. i = gppi_raw(sesskey, "BugPlainPW1", 0); conf_set_int(conf, CONF_sshbug_plainpw1, 2-i);
  1174. i = gppi_raw(sesskey, "BugRSA1", 0); conf_set_int(conf, CONF_sshbug_rsa1, 2-i);
  1175. i = gppi_raw(sesskey, "BugIgnore2", 0); conf_set_int(conf, CONF_sshbug_ignore2, 2-i);
  1176. {
  1177. int i;
  1178. i = gppi_raw(sesskey, "BugHMAC2", 0); conf_set_int(conf, CONF_sshbug_hmac2, 2-i);
  1179. if (2-i == AUTO) {
  1180. i = gppi_raw(sesskey, "BuggyMAC", 0);
  1181. if (i == 1)
  1182. conf_set_int(conf, CONF_sshbug_hmac2, FORCE_ON);
  1183. }
  1184. }
  1185. i = gppi_raw(sesskey, "BugDeriveKey2", 0); conf_set_int(conf, CONF_sshbug_derivekey2, 2-i);
  1186. i = gppi_raw(sesskey, "BugRSAPad2", 0); conf_set_int(conf, CONF_sshbug_rsapad2, 2-i);
  1187. i = gppi_raw(sesskey, "BugPKSessID2", 0); conf_set_int(conf, CONF_sshbug_pksessid2, 2-i);
  1188. i = gppi_raw(sesskey, "BugRekey2", 0); conf_set_int(conf, CONF_sshbug_rekey2, 2-i);
  1189. i = gppi_raw(sesskey, "BugMaxPkt2", 0); conf_set_int(conf, CONF_sshbug_maxpkt2, 2-i);
  1190. i = gppi_raw(sesskey, "BugOldGex2", 0); conf_set_int(conf, CONF_sshbug_oldgex2, 2-i);
  1191. i = gppi_raw(sesskey, "BugWinadj", 0); conf_set_int(conf, CONF_sshbug_winadj, 2-i);
  1192. i = gppi_raw(sesskey, "BugChanReq", 0); conf_set_int(conf, CONF_sshbug_chanreq, 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. }