settings.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  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. { "mlkem-curve25519", KEX_MLKEM_25519_HYBRID, KEX_NTRU_HYBRID, +1 },
  30. { "mlkem-nist", KEX_MLKEM_NIST_HYBRID, KEX_MLKEM_25519_HYBRID, +1 },
  31. { "ecdh", KEX_ECDH, -1, +1 },
  32. /* This name is misleading: it covers both SHA-256 and SHA-1 variants */
  33. { "dh-gex-sha1", KEX_DHGEX, -1, -1 },
  34. /* Again, this covers both SHA-256 and SHA-1, despite the name: */
  35. { "dh-group14-sha1", KEX_DHGROUP14, -1, -1 },
  36. /* This one really is only SHA-1, though: */
  37. { "dh-group1-sha1", KEX_DHGROUP1, KEX_WARN, +1 },
  38. { "rsa", KEX_RSA, KEX_WARN, -1 },
  39. /* Larger fixed DH groups: prefer the larger 15 and 16 over 14,
  40. * but by default the even larger 17 and 18 go below 16.
  41. * Rationale: diminishing returns of improving the DH strength are
  42. * outweighed by increased CPU cost. Group 18 is painful on a slow
  43. * machine. Users can override if they need to. */
  44. { "dh-group15-sha512", KEX_DHGROUP15, KEX_DHGROUP14, -1 },
  45. { "dh-group16-sha512", KEX_DHGROUP16, KEX_DHGROUP15, -1 },
  46. { "dh-group17-sha512", KEX_DHGROUP17, KEX_DHGROUP16, +1 },
  47. { "dh-group18-sha512", KEX_DHGROUP18, KEX_DHGROUP17, +1 },
  48. { "WARN", KEX_WARN, -1, -1 }
  49. };
  50. static const struct keyvalwhere hknames[] = {
  51. { "ed25519", HK_ED25519, -1, +1 },
  52. { "ed448", HK_ED448, -1, +1 },
  53. { "ecdsa", HK_ECDSA, -1, -1 },
  54. { "dsa", HK_DSA, -1, -1 },
  55. { "rsa", HK_RSA, -1, -1 },
  56. { "WARN", HK_WARN, -1, -1 },
  57. };
  58. /*
  59. * All the terminal modes that we know about for the "TerminalModes"
  60. * setting. (Also used by config.c for the drop-down list.)
  61. * This is currently precisely the same as the set in
  62. * ssh/ttymode-list.h, but could in principle differ if other backends
  63. * started to support tty modes (e.g., the pty backend).
  64. * The set of modes in this array is currently significant for
  65. * settings migration from old versions; if they change, review the
  66. * gppmap() invocation for "TerminalModes".
  67. */
  68. const char *const ttymodes[] = {
  69. "INTR", "QUIT", "ERASE", "KILL", "EOF",
  70. "EOL", "EOL2", "START", "STOP", "SUSP",
  71. "DSUSP", "REPRINT", "WERASE", "LNEXT", "FLUSH",
  72. "SWTCH", "STATUS", "DISCARD", "IGNPAR", "PARMRK",
  73. "INPCK", "ISTRIP", "INLCR", "IGNCR", "ICRNL",
  74. "IUCLC", "IXON", "IXANY", "IXOFF", "IMAXBEL",
  75. "IUTF8", "ISIG", "ICANON", "XCASE", "ECHO",
  76. "ECHOE", "ECHOK", "ECHONL", "NOFLSH", "TOSTOP",
  77. "IEXTEN", "ECHOCTL", "ECHOKE", "PENDIN", "OPOST",
  78. "OLCUC", "ONLCR", "OCRNL", "ONOCR", "ONLRET",
  79. "CS7", "CS8", "PARENB", "PARODD", NULL
  80. };
  81. static int default_protocol, default_port;
  82. void settings_set_default_protocol(int newval) { default_protocol = newval; }
  83. void settings_set_default_port(int newval) { default_port = newval; }
  84. /*
  85. * Convenience functions to access the backends[] array
  86. * (which is only present in tools that manage settings).
  87. */
  88. const struct BackendVtable *backend_vt_from_name(const char *name)
  89. {
  90. const struct BackendVtable *const *p;
  91. for (p = backends; *p != NULL; p++)
  92. if (!strcmp((*p)->id, name))
  93. return *p;
  94. return NULL;
  95. }
  96. const struct BackendVtable *backend_vt_from_proto(int proto)
  97. {
  98. const struct BackendVtable *const *p;
  99. for (p = backends; *p != NULL; p++)
  100. if ((*p)->protocol == proto)
  101. return *p;
  102. return NULL;
  103. }
  104. char *get_remote_username(Conf *conf)
  105. {
  106. /* We don't worry about whether the username is stored as UTF-8,
  107. * because SSH wants it as UTF-8 */
  108. char *username = conf_get_str_ambi(conf, CONF_username, NULL);
  109. if (*username) {
  110. return dupstr(username);
  111. } else if (conf_get_bool(conf, CONF_username_from_env)) {
  112. /* Use local username. */
  113. return get_username(); /* might still be NULL */
  114. } else {
  115. return NULL;
  116. }
  117. }
  118. static char *gpps_raw(settings_r *sesskey, const char *name, const char *def)
  119. {
  120. char *ret = read_setting_s(sesskey, name);
  121. if (!ret)
  122. ret = platform_default_s(name);
  123. if (!ret)
  124. ret = def ? dupstr(def) : NULL; /* permit NULL as final fallback */
  125. return ret;
  126. }
  127. static void gpps(settings_r *sesskey, const char *name, const char *def,
  128. Conf *conf, int primary)
  129. {
  130. char *val = gpps_raw(sesskey, name, def);
  131. conf_set_str(conf, primary, val);
  132. sfree(val);
  133. }
  134. /*
  135. * gppfont and gppfile cannot have local defaults, since the very
  136. * format of a Filename or FontSpec is platform-dependent. So the
  137. * platform-dependent functions MUST return some sort of value.
  138. */
  139. static void gppfont(settings_r *sesskey, const char *name,
  140. Conf *conf, int primary)
  141. {
  142. FontSpec *result = read_setting_fontspec(sesskey, name);
  143. if (!result)
  144. result = platform_default_fontspec(name);
  145. conf_set_fontspec(conf, primary, result);
  146. fontspec_free(result);
  147. }
  148. static void gppfile(settings_r *sesskey, const char *name,
  149. Conf *conf, int primary)
  150. {
  151. Filename *result = read_setting_filename(sesskey, name);
  152. if (!result)
  153. result = platform_default_filename(name);
  154. conf_set_filename(conf, primary, result);
  155. filename_free(result);
  156. }
  157. static bool gppb_raw(settings_r *sesskey, const char *name, bool def)
  158. {
  159. def = platform_default_b(name, def);
  160. return read_setting_i(sesskey, name, def) != 0;
  161. }
  162. static void gppb(settings_r *sesskey, const char *name, bool def,
  163. Conf *conf, int primary)
  164. {
  165. conf_set_bool(conf, primary, gppb_raw(sesskey, name, def));
  166. }
  167. static int gppi_raw(settings_r *sesskey, const char *name, int def)
  168. {
  169. def = platform_default_i(name, def);
  170. return read_setting_i(sesskey, name, def);
  171. }
  172. static void gppi(settings_r *sesskey, const char *name, int def,
  173. Conf *conf, int primary)
  174. {
  175. conf_set_int(conf, primary, gppi_raw(sesskey, name, def));
  176. }
  177. /*
  178. * Read a set of name-value pairs in the format we occasionally use:
  179. * NAME\tVALUE\0NAME\tVALUE\0\0 in memory
  180. * NAME=VALUE,NAME=VALUE, in storage
  181. * If there's no "=VALUE" (e.g. just NAME,NAME,NAME) then those keys
  182. * are mapped to the empty string.
  183. */
  184. static bool gppmap(settings_r *sesskey, const char *name,
  185. Conf *conf, int primary)
  186. {
  187. char *buf, *p, *q, *key, *val;
  188. /*
  189. * Start by clearing any existing subkeys of this key from conf.
  190. */
  191. while ((key = conf_get_str_nthstrkey(conf, primary, 0)) != NULL)
  192. conf_del_str_str(conf, primary, key);
  193. /*
  194. * Now read a serialised list from the settings and unmarshal it
  195. * into its components.
  196. */
  197. buf = gpps_raw(sesskey, name, NULL);
  198. if (!buf)
  199. return false;
  200. p = buf;
  201. while (*p) {
  202. q = buf;
  203. val = NULL;
  204. while (*p && *p != ',') {
  205. int c = *p++;
  206. if (c == '=')
  207. c = '\0';
  208. if (c == '\\')
  209. c = *p++;
  210. *q++ = c;
  211. if (!c)
  212. val = q;
  213. }
  214. if (*p == ',')
  215. p++;
  216. if (!val)
  217. val = q;
  218. *q = '\0';
  219. if (primary == CONF_portfwd && strchr(buf, 'D') != NULL) {
  220. /*
  221. * Backwards-compatibility hack: dynamic forwardings are
  222. * indexed in the data store as a third type letter in the
  223. * key, 'D' alongside 'L' and 'R' - but really, they
  224. * should be filed under 'L' with a special _value_,
  225. * because local and dynamic forwardings both involve
  226. * _listening_ on a local port, and are hence mutually
  227. * exclusive on the same port number. So here we translate
  228. * the legacy storage format into the sensible internal
  229. * form, by finding the D and turning it into a L.
  230. */
  231. char *newkey = dupstr(buf);
  232. *strchr(newkey, 'D') = 'L';
  233. conf_set_str_str(conf, primary, newkey, "D");
  234. sfree(newkey);
  235. } else {
  236. conf_set_str_str(conf, primary, buf, val);
  237. }
  238. }
  239. sfree(buf);
  240. return true;
  241. }
  242. /*
  243. * Write a set of name/value pairs in the above format, or just the
  244. * names if include_values is false.
  245. */
  246. static void wmap(settings_w *sesskey, char const *outkey, Conf *conf,
  247. int primary, bool include_values)
  248. {
  249. char *key, *realkey;
  250. const char *val, *q;
  251. strbuf *sb = strbuf_new();
  252. for (val = conf_get_str_strs(conf, primary, NULL, &key);
  253. val != NULL;
  254. val = conf_get_str_strs(conf, primary, key, &key)) {
  255. if (primary == CONF_portfwd && !strcmp(val, "D")) {
  256. /*
  257. * Backwards-compatibility hack, as above: translate from
  258. * the sensible internal representation of dynamic
  259. * forwardings (key "L<port>", value "D") to the
  260. * conceptually incoherent legacy storage format (key
  261. * "D<port>", value empty).
  262. */
  263. char *L;
  264. realkey = key; /* restore it at end of loop */
  265. val = "";
  266. key = dupstr(key);
  267. L = strchr(key, 'L');
  268. if (L) *L = 'D';
  269. } else {
  270. realkey = NULL;
  271. }
  272. if (sb->len)
  273. put_byte(sb, ',');
  274. for (q = key; *q; q++) {
  275. if (*q == '=' || *q == ',' || *q == '\\')
  276. put_byte(sb, '\\');
  277. put_byte(sb, *q);
  278. }
  279. if (include_values) {
  280. put_byte(sb, '=');
  281. for (q = val; *q; q++) {
  282. if (*q == '=' || *q == ',' || *q == '\\')
  283. put_byte(sb, '\\');
  284. put_byte(sb, *q);
  285. }
  286. }
  287. if (realkey) {
  288. free(key);
  289. key = realkey;
  290. }
  291. }
  292. write_setting_s(sesskey, outkey, sb->s);
  293. strbuf_free(sb);
  294. }
  295. static int key2val(const struct keyvalwhere *mapping,
  296. int nmaps, char *key)
  297. {
  298. int i;
  299. for (i = 0; i < nmaps; i++)
  300. if (!strcmp(mapping[i].s, key)) return mapping[i].v;
  301. return -1;
  302. }
  303. static const char *val2key(const struct keyvalwhere *mapping,
  304. int nmaps, int val)
  305. {
  306. int i;
  307. for (i = 0; i < nmaps; i++)
  308. if (mapping[i].v == val) return mapping[i].s;
  309. return NULL;
  310. }
  311. /*
  312. * Helper function to parse a comma-separated list of strings into
  313. * a preference list array of values. Any missing values are added
  314. * to the end and duplicates are weeded.
  315. * XXX: assumes vals in 'mapping' are small +ve integers
  316. */
  317. static void gprefs_from_str(const char *str,
  318. const struct keyvalwhere *mapping, int nvals,
  319. Conf *conf, int primary)
  320. {
  321. char *commalist = dupstr(str);
  322. char *p, *q;
  323. int i, j, n, v, pos;
  324. unsigned long seen = 0; /* bitmap for weeding dups etc */
  325. /*
  326. * Go through that list and convert it into values.
  327. */
  328. n = 0;
  329. p = commalist;
  330. while (1) {
  331. while (*p && *p == ',') p++;
  332. if (!*p)
  333. break; /* no more words */
  334. q = p;
  335. while (*p && *p != ',') p++;
  336. if (*p) *p++ = '\0';
  337. v = key2val(mapping, nvals, q);
  338. if (v != -1 && !(seen & (1 << v))) {
  339. seen |= (1 << v);
  340. conf_set_int_int(conf, primary, n, v);
  341. n++;
  342. }
  343. }
  344. sfree(commalist);
  345. /*
  346. * Now go through 'mapping' and add values that weren't mentioned
  347. * in the list we fetched. We may have to loop over it multiple
  348. * times so that we add values before other values whose default
  349. * positions depend on them.
  350. */
  351. while (n < nvals) {
  352. for (i = 0; i < nvals; i++) {
  353. assert(mapping[i].v >= 0);
  354. assert(mapping[i].v < 32);
  355. if (!(seen & (1 << mapping[i].v))) {
  356. /*
  357. * This element needs adding. But can we add it yet?
  358. */
  359. if (mapping[i].vrel != -1 && !(seen & (1 << mapping[i].vrel)))
  360. continue; /* nope */
  361. /*
  362. * OK, we can work out where to add this element, so
  363. * do so.
  364. */
  365. if (mapping[i].vrel == -1) {
  366. pos = (mapping[i].where < 0 ? n : 0);
  367. } else {
  368. for (j = 0; j < n; j++)
  369. if (conf_get_int_int(conf, primary, j) ==
  370. mapping[i].vrel)
  371. break;
  372. assert(j < n); /* implied by (seen & (1<<vrel)) */
  373. pos = (mapping[i].where < 0 ? j : j+1);
  374. }
  375. /*
  376. * And add it.
  377. */
  378. for (j = n-1; j >= pos; j--)
  379. conf_set_int_int(conf, primary, j+1,
  380. conf_get_int_int(conf, primary, j));
  381. conf_set_int_int(conf, primary, pos, mapping[i].v);
  382. seen |= (1 << mapping[i].v);
  383. n++;
  384. }
  385. }
  386. }
  387. }
  388. /*
  389. * Read a preference list.
  390. */
  391. static void gprefs(settings_r *sesskey, const char *name, const char *def,
  392. const struct keyvalwhere *mapping, int nvals,
  393. Conf *conf, int primary)
  394. {
  395. /*
  396. * Fetch the string which we'll parse as a comma-separated list.
  397. */
  398. char *value = gpps_raw(sesskey, name, def);
  399. gprefs_from_str(value, mapping, nvals, conf, primary);
  400. sfree(value);
  401. }
  402. /*
  403. * Write out a preference list.
  404. */
  405. static void wprefs(settings_w *sesskey, const char *name,
  406. const struct keyvalwhere *mapping, int nvals,
  407. Conf *conf, int primary)
  408. {
  409. strbuf *sb = strbuf_new();
  410. for (int i = 0; i < nvals; i++) {
  411. const char *s = val2key(mapping, nvals,
  412. conf_get_int_int(conf, primary, i));
  413. if (s)
  414. put_fmt(sb, "%s%s", (sb->len ? "," : ""), s);
  415. }
  416. write_setting_s(sesskey, name, sb->s);
  417. strbuf_free(sb);
  418. }
  419. static void write_setting_b(settings_w *handle, const char *key, bool value)
  420. {
  421. write_setting_i(handle, key, value ? 1 : 0);
  422. }
  423. static void write_clip_setting(settings_w *sesskey, const char *savekey,
  424. Conf *conf, int confkey, int strconfkey)
  425. {
  426. int val = conf_get_int(conf, confkey);
  427. switch (val) {
  428. case CLIPUI_NONE:
  429. default:
  430. write_setting_s(sesskey, savekey, "none");
  431. break;
  432. case CLIPUI_IMPLICIT:
  433. write_setting_s(sesskey, savekey, "implicit");
  434. break;
  435. case CLIPUI_EXPLICIT:
  436. write_setting_s(sesskey, savekey, "explicit");
  437. break;
  438. case CLIPUI_CUSTOM: {
  439. char *sval = dupcat("custom:", conf_get_str(conf, strconfkey));
  440. write_setting_s(sesskey, savekey, sval);
  441. sfree(sval);
  442. break;
  443. }
  444. }
  445. }
  446. static void read_clip_setting(settings_r *sesskey, char *savekey,
  447. int def, Conf *conf, int confkey, int strconfkey)
  448. {
  449. char *setting = read_setting_s(sesskey, savekey);
  450. int val;
  451. conf_set_str(conf, strconfkey, "");
  452. if (!setting) {
  453. val = def;
  454. } else if (!strcmp(setting, "implicit")) {
  455. val = CLIPUI_IMPLICIT;
  456. } else if (!strcmp(setting, "explicit")) {
  457. val = CLIPUI_EXPLICIT;
  458. } else if (!strncmp(setting, "custom:", 7)) {
  459. val = CLIPUI_CUSTOM;
  460. conf_set_str(conf, strconfkey, setting + 7);
  461. } else {
  462. val = CLIPUI_NONE;
  463. }
  464. conf_set_int(conf, confkey, val);
  465. sfree(setting);
  466. }
  467. char *save_settings(const char *section, Conf *conf)
  468. {
  469. struct settings_w *sesskey;
  470. char *errmsg;
  471. sesskey = open_settings_w(section, &errmsg);
  472. if (!sesskey)
  473. return errmsg;
  474. save_open_settings(sesskey, conf);
  475. close_settings_w(sesskey);
  476. return NULL;
  477. }
  478. /* Declare extern references to conf_enum_* types */
  479. #define CONF_ENUM(name, ...) extern const ConfSaveEnumType conf_enum_##name;
  480. #include "conf-enums.h"
  481. #undef CONF_ENUM
  482. void save_open_settings(settings_w *sesskey, Conf *conf)
  483. {
  484. int i;
  485. const char *p;
  486. /* Save the settings simple enough to handle automatically */
  487. for (size_t key = 0; key < N_CONFIG_OPTIONS; key++) {
  488. const ConfKeyInfo *info = &conf_key_info[key];
  489. if (!info->save_custom && !info->not_saved) {
  490. /* Mappings are handled individually below */
  491. assert(info->subkey_type == CONF_TYPE_NONE);
  492. switch (info->value_type) {
  493. case CONF_TYPE_STR:
  494. write_setting_s(sesskey, info->save_keyword,
  495. conf_get_str(conf, key));
  496. break;
  497. case CONF_TYPE_STR_AMBI: {
  498. bool orig_is_utf8;
  499. const char *orig = conf_get_str_ambi(conf, key, &orig_is_utf8);
  500. int cp_from, cp_to;
  501. if (orig_is_utf8) {
  502. cp_from = CP_UTF8;
  503. cp_to = DEFAULT_CODEPAGE;
  504. } else {
  505. cp_from = DEFAULT_CODEPAGE;
  506. cp_to = CP_UTF8;
  507. }
  508. size_t wlen;
  509. wchar_t *wide = dup_mb_to_wc_c(
  510. cp_from, orig, strlen(orig), &wlen);
  511. size_t clen;
  512. char *converted = dup_wc_to_mb_c(
  513. cp_to, wide, wlen, "", &clen);
  514. const char *native, *utf8;
  515. if (orig_is_utf8) {
  516. utf8 = orig;
  517. native = converted;
  518. } else {
  519. native = orig;
  520. utf8 = converted;
  521. }
  522. write_setting_s(sesskey, info->save_keyword, native);
  523. (void)utf8; /* FIXME: also save the UTF-8 version */
  524. burnwcs(wide);
  525. burnstr(converted);
  526. break;
  527. }
  528. case CONF_TYPE_INT: {
  529. int ival = conf_get_int(conf, key);
  530. if (info->storage_enum) {
  531. bool success = conf_enum_map_to_storage(
  532. info->storage_enum, ival, &ival);
  533. assert(success && "unmapped integer value");
  534. }
  535. write_setting_i(sesskey, info->save_keyword, ival);
  536. break;
  537. }
  538. case CONF_TYPE_BOOL:
  539. write_setting_b(sesskey, info->save_keyword,
  540. conf_get_bool(conf, key));
  541. break;
  542. case CONF_TYPE_FILENAME:
  543. write_setting_filename(sesskey, info->save_keyword,
  544. conf_get_filename(conf, key));
  545. break;
  546. case CONF_TYPE_FONT:
  547. write_setting_fontspec(sesskey, info->save_keyword,
  548. conf_get_fontspec(conf, key));
  549. break;
  550. default:
  551. unreachable("bad key type in save_open_settings");
  552. }
  553. }
  554. }
  555. write_setting_i(sesskey, "Present", 1);
  556. p = "raw";
  557. {
  558. const struct BackendVtable *vt =
  559. backend_vt_from_proto(conf_get_int(conf, CONF_protocol));
  560. if (vt)
  561. p = vt->id;
  562. }
  563. write_setting_s(sesskey, "Protocol", p);
  564. write_setting_i(sesskey, "PingInterval", conf_get_int(conf, CONF_ping_interval) / 60); /* minutes */
  565. write_setting_i(sesskey, "PingIntervalSecs", conf_get_int(conf, CONF_ping_interval) % 60); /* seconds */
  566. wmap(sesskey, "TerminalModes", conf, CONF_ttymodes, true);
  567. /* proxy settings */
  568. wmap(sesskey, "Environment", conf, CONF_environmt, true);
  569. #ifndef NO_GSSAPI
  570. write_setting_b(sesskey, "GssapiFwd", conf_get_bool(conf, CONF_gssapifwd));
  571. #endif
  572. wprefs(sesskey, "Cipher", ciphernames, CIPHER_MAX, conf, CONF_ssh_cipherlist);
  573. wprefs(sesskey, "KEX", kexnames, KEX_MAX, conf, CONF_ssh_kexlist);
  574. wprefs(sesskey, "HostKey", hknames, HK_MAX, conf, CONF_ssh_hklist);
  575. #ifndef NO_GSSAPI
  576. write_setting_i(sesskey, "GssapiRekey", conf_get_int(conf, CONF_gssapirekey));
  577. #endif
  578. #ifndef NO_GSSAPI
  579. write_setting_b(sesskey, "AuthGSSAPI", conf_get_bool(conf, CONF_try_gssapi_auth));
  580. write_setting_b(sesskey, "AuthGSSAPIKEX", conf_get_bool(conf, CONF_try_gssapi_kex));
  581. wprefs(sesskey, "GSSLibs", gsslibkeywords, ngsslibs, conf, CONF_ssh_gsslist);
  582. write_setting_filename(sesskey, "GSSCustom", conf_get_filename(conf, CONF_ssh_gss_custom));
  583. #endif
  584. #ifdef OSX_META_KEY_CONFIG
  585. write_setting_b(sesskey, "OSXOptionMeta", conf_get_bool(conf, CONF_osx_option_meta));
  586. write_setting_b(sesskey, "OSXCommandMeta", conf_get_bool(conf, CONF_osx_command_meta));
  587. #endif
  588. write_setting_i(sesskey, "BellOverloadT", conf_get_int(conf, CONF_bellovl_t)
  589. #ifdef PUTTY_UNIX_PLATFORM_H
  590. * 1000
  591. #endif
  592. );
  593. write_setting_i(sesskey, "BellOverloadS", conf_get_int(conf, CONF_bellovl_s)
  594. #ifdef PUTTY_UNIX_PLATFORM_H
  595. * 1000
  596. #endif
  597. );
  598. for (i = 0; i < 22; i++) {
  599. char buf[20], buf2[30];
  600. sprintf(buf, "Colour%d", i);
  601. sprintf(buf2, "%d,%d,%d",
  602. conf_get_int_int(conf, CONF_colours, i*3+0),
  603. conf_get_int_int(conf, CONF_colours, i*3+1),
  604. conf_get_int_int(conf, CONF_colours, i*3+2));
  605. write_setting_s(sesskey, buf, buf2);
  606. }
  607. for (i = 0; i < 256; i += 32) {
  608. char buf[20], buf2[256];
  609. int j;
  610. sprintf(buf, "Wordness%d", i);
  611. *buf2 = '\0';
  612. for (j = i; j < i + 32; j++) {
  613. sprintf(buf2 + strlen(buf2), "%s%d",
  614. (*buf2 ? "," : ""),
  615. conf_get_int_int(conf, CONF_wordness, j));
  616. }
  617. write_setting_s(sesskey, buf, buf2);
  618. }
  619. write_clip_setting(sesskey, "MousePaste", conf,
  620. CONF_mousepaste, CONF_mousepaste_custom);
  621. write_clip_setting(sesskey, "CtrlShiftIns", conf,
  622. CONF_ctrlshiftins, CONF_ctrlshiftins_custom);
  623. write_clip_setting(sesskey, "CtrlShiftCV", conf,
  624. CONF_ctrlshiftcv, CONF_ctrlshiftcv_custom);
  625. wmap(sesskey, "PortForwardings", conf, CONF_portfwd, true);
  626. wmap(sesskey, "SSHManualHostKeys", conf, CONF_ssh_manual_hostkeys, false);
  627. }
  628. bool load_settings(const char *section, Conf *conf)
  629. {
  630. settings_r *sesskey;
  631. sesskey = open_settings_r(section);
  632. bool exists = (sesskey != NULL);
  633. load_open_settings(sesskey, conf);
  634. close_settings_r(sesskey);
  635. if (exists && conf_launchable(conf))
  636. add_session_to_jumplist(section);
  637. return exists;
  638. }
  639. void load_open_settings(settings_r *sesskey, Conf *conf)
  640. {
  641. int i;
  642. char *prot;
  643. /* Load the settings simple enough to handle automatically */
  644. for (size_t key = 0; key < N_CONFIG_OPTIONS; key++) {
  645. const ConfKeyInfo *info = &conf_key_info[key];
  646. if (info->not_saved) {
  647. /* Mappings are assumed to default to empty */
  648. if (info->subkey_type == CONF_TYPE_NONE) {
  649. switch (info->value_type) {
  650. case CONF_TYPE_STR:
  651. case CONF_TYPE_STR_AMBI:
  652. conf_set_str(conf, key, info->default_value.sval);
  653. break;
  654. case CONF_TYPE_INT:
  655. conf_set_int(conf, key, info->default_value.ival);
  656. break;
  657. case CONF_TYPE_BOOL:
  658. conf_set_bool(conf, key, info->default_value.bval);
  659. break;
  660. default:
  661. unreachable("bad key type in load_open_settings");
  662. }
  663. }
  664. } else if (!info->load_custom) {
  665. /* Mappings are handled individually below */
  666. assert(info->subkey_type == CONF_TYPE_NONE);
  667. switch (info->value_type) {
  668. case CONF_TYPE_STR:
  669. case CONF_TYPE_STR_AMBI:
  670. gpps(sesskey, info->save_keyword, info->default_value.sval,
  671. conf, key);
  672. break;
  673. case CONF_TYPE_INT:
  674. if (!info->storage_enum) {
  675. gppi(sesskey, info->save_keyword,
  676. info->default_value.ival, conf, key);
  677. } else {
  678. /*
  679. * Because our internal defaults are stored as the
  680. * value we want in Conf, but our API for
  681. * retrieving integers from storage requires a
  682. * default value to fill in if no record is found,
  683. * we must first figure out the default _storage_
  684. * value, ugh.
  685. */
  686. int defstorage;
  687. bool success = conf_enum_map_to_storage(
  688. info->storage_enum, info->default_value.ival,
  689. &defstorage);
  690. assert(success && "unmapped default");
  691. /* Now retrieve the stored value */
  692. int storageval = gppi_raw(sesskey, info->save_keyword,
  693. defstorage);
  694. /* And translate it back to Conf representation,
  695. * replacing it with our Conf-rep default on failure */
  696. int confval;
  697. if (!conf_enum_map_from_storage(
  698. info->storage_enum, storageval, &confval))
  699. confval = info->default_value.ival;
  700. conf_set_int(conf, key, confval);
  701. }
  702. break;
  703. case CONF_TYPE_BOOL:
  704. gppb(sesskey, info->save_keyword, info->default_value.bval,
  705. conf, key);
  706. break;
  707. case CONF_TYPE_FILENAME:
  708. gppfile(sesskey, info->save_keyword, conf, key);
  709. break;
  710. case CONF_TYPE_FONT:
  711. gppfont(sesskey, info->save_keyword, conf, key);
  712. break;
  713. default:
  714. unreachable("bad key type in load_open_settings");
  715. }
  716. }
  717. }
  718. prot = gpps_raw(sesskey, "Protocol", "default");
  719. conf_set_int(conf, CONF_protocol, default_protocol);
  720. conf_set_int(conf, CONF_port, default_port);
  721. {
  722. const struct BackendVtable *vt = backend_vt_from_name(prot);
  723. if (vt) {
  724. conf_set_int(conf, CONF_protocol, vt->protocol);
  725. gppi(sesskey, "PortNumber", default_port, conf, CONF_port);
  726. }
  727. }
  728. sfree(prot);
  729. {
  730. /* This is two values for backward compatibility with 0.50/0.51 */
  731. int pingmin, pingsec;
  732. pingmin = gppi_raw(sesskey, "PingInterval", 0);
  733. pingsec = gppi_raw(sesskey, "PingIntervalSecs", 0);
  734. conf_set_int(conf, CONF_ping_interval, pingmin * 60 + pingsec);
  735. }
  736. if (gppmap(sesskey, "TerminalModes", conf, CONF_ttymodes)) {
  737. /*
  738. * Backwards compatibility with old saved settings.
  739. *
  740. * From the invention of this setting through 0.67, the set of
  741. * terminal modes was fixed, and absence of a mode from this
  742. * setting meant the user had explicitly removed it from the
  743. * UI and we shouldn't send it.
  744. *
  745. * In 0.68, the IUTF8 mode was added, and in handling old
  746. * settings we inadvertently removed the ability to not send
  747. * a mode. Any mode not mentioned was treated as if it was
  748. * set to 'auto' (A).
  749. *
  750. * After 0.68, we added explicit notation to the setting format
  751. * when the user removes a known terminal mode from the list.
  752. *
  753. * So: if any of the modes from the original set is missing, we
  754. * assume this was an intentional removal by the user and add
  755. * an explicit removal ('N'); but if IUTF8 (or any other mode
  756. * added after 0.67) is missing, we assume that its absence is
  757. * due to the setting being old rather than intentional, and
  758. * add it with its default setting.
  759. *
  760. * (This does mean that if a 0.68 user explicitly removed IUTF8,
  761. * we add it back; but removing IUTF8 had no effect in 0.68, so
  762. * we're preserving behaviour, which is the best we can do.)
  763. */
  764. for (i = 0; ttymodes[i]; i++) {
  765. if (!conf_get_str_str_opt(conf, CONF_ttymodes, ttymodes[i])) {
  766. /* Mode not mentioned in setting. */
  767. const char *def;
  768. if (!strcmp(ttymodes[i], "IUTF8")) {
  769. /* Any new modes we add in future should be treated
  770. * this way too. */
  771. def = "A"; /* same as new-setting default below */
  772. } else {
  773. /* One of the original modes. Absence is probably
  774. * deliberate. */
  775. def = "N"; /* don't send */
  776. }
  777. conf_set_str_str(conf, CONF_ttymodes, ttymodes[i], def);
  778. }
  779. }
  780. } else {
  781. /* This hardcodes a big set of defaults in any new saved
  782. * sessions. Let's hope we don't change our mind. */
  783. for (i = 0; ttymodes[i]; i++)
  784. conf_set_str_str(conf, CONF_ttymodes, ttymodes[i], "A");
  785. }
  786. /* proxy settings */
  787. {
  788. int storageval = gppi_raw(sesskey, "ProxyMethod", -1);
  789. int confval;
  790. if (!conf_enum_map_from_storage(&conf_enum_proxy_type,
  791. storageval, &confval)) {
  792. /*
  793. * Fall back to older ProxyType and ProxySOCKSVersion format
  794. */
  795. storageval = gppi_raw(sesskey, "ProxyType", 0);
  796. if (conf_enum_map_from_storage(&conf_enum_old_proxy_type,
  797. storageval, &confval)) {
  798. if (confval == PROXY_SOCKS5 &&
  799. gppi_raw(sesskey, "ProxySOCKSVersion", 5) == 4)
  800. confval = PROXY_SOCKS4;
  801. }
  802. }
  803. conf_set_int(conf, CONF_proxy_type, confval);
  804. }
  805. gppmap(sesskey, "Environment", conf, CONF_environmt);
  806. #ifndef NO_GSSAPI
  807. gppb(sesskey, "GssapiFwd", false, conf, CONF_gssapifwd);
  808. #endif
  809. gprefs(sesskey, "Cipher", "\0",
  810. ciphernames, CIPHER_MAX, conf, CONF_ssh_cipherlist);
  811. {
  812. /* Backward-compatibility: before 0.58 (when the "KEX"
  813. * preference was first added), we had an option to
  814. * disable gex under the "bugs" panel after one report of
  815. * a server which offered it then choked, but we never got
  816. * a server version string or any other reports. */
  817. const char *default_kexes,
  818. *normal_default = "ecdh,dh-gex-sha1,dh-group18-sha512,dh-group17-sha512,dh-group16-sha512,dh-group15-sha512,dh-group14-sha1,rsa,"
  819. "WARN,dh-group1-sha1",
  820. *bugdhgex2_default = "ecdh,dh-group18-sha512,dh-group17-sha512,dh-group16-sha512,dh-group15-sha512,dh-group14-sha1,rsa,"
  821. "WARN,dh-group1-sha1,dh-gex-sha1";
  822. char *raw;
  823. i = 2 - gppi_raw(sesskey, "BugDHGEx2", 0);
  824. if (i == FORCE_ON)
  825. default_kexes = bugdhgex2_default;
  826. else
  827. default_kexes = normal_default;
  828. /* Migration: after 0.67 we decided we didn't like
  829. * dh-group1-sha1. If it looks like the user never changed
  830. * the defaults, quietly upgrade their settings to demote it.
  831. * (If they did, they're on their own.) */
  832. raw = gpps_raw(sesskey, "KEX", default_kexes);
  833. assert(raw != NULL);
  834. /* Lack of 'ecdh' tells us this was saved by 0.58-0.67
  835. * inclusive. If it was saved by a later version, we need
  836. * to leave it alone. */
  837. if (strcmp(raw, "dh-group14-sha1,dh-group1-sha1,rsa,"
  838. "WARN,dh-gex-sha1") == 0) {
  839. /* Previously migrated from BugDHGEx2. */
  840. sfree(raw);
  841. raw = dupstr(bugdhgex2_default);
  842. } else if (strcmp(raw, "dh-gex-sha1,dh-group14-sha1,"
  843. "dh-group1-sha1,rsa,WARN") == 0) {
  844. /* Untouched old default setting. */
  845. sfree(raw);
  846. raw = dupstr(normal_default);
  847. }
  848. /* (For the record: after 0.70, the default algorithm list
  849. * very briefly contained the string 'gss-sha1-krb5'; this was
  850. * never used in any committed version of code, but was left
  851. * over from a pre-commit version of GSS key exchange.
  852. * Mentioned here as it is remotely possible that it will turn
  853. * up in someone's saved settings in future.) */
  854. gprefs_from_str(raw, kexnames, KEX_MAX, conf, CONF_ssh_kexlist);
  855. sfree(raw);
  856. }
  857. gprefs(sesskey, "HostKey", "ed25519,ecdsa,rsa,dsa,WARN",
  858. hknames, HK_MAX, conf, CONF_ssh_hklist);
  859. #ifndef NO_GSSAPI
  860. gppi(sesskey, "GssapiRekey", GSS_DEF_REKEY_MINS, conf, CONF_gssapirekey);
  861. gppb(sesskey, "AuthGSSAPI", true, conf, CONF_try_gssapi_auth);
  862. gppb(sesskey, "AuthGSSAPIKEX", true, conf, CONF_try_gssapi_kex);
  863. gprefs(sesskey, "GSSLibs", "\0",
  864. gsslibkeywords, ngsslibs, conf, CONF_ssh_gsslist);
  865. gppfile(sesskey, "GSSCustom", conf, CONF_ssh_gss_custom);
  866. #endif
  867. {
  868. int storageval = gppi_raw(sesskey, "RemoteQTitleAction", -1);
  869. int confval;
  870. if (!conf_enum_map_from_storage(&conf_enum_remote_qtitle_action,
  871. storageval, &confval)) {
  872. /*
  873. * Fall back to older NoRemoteQTitle format
  874. */
  875. storageval = gppi_raw(sesskey, "NoRemoteQTitle", 1);
  876. /* We deliberately interpret the old setting of "no response" as
  877. * "empty string". This changes the behaviour, but hopefully for
  878. * the better; the user can always recover the old behaviour. */
  879. confval = storageval ? TITLE_EMPTY : TITLE_REAL;
  880. }
  881. conf_set_int(conf, CONF_remote_qtitle_action, confval);
  882. }
  883. #ifdef OSX_META_KEY_CONFIG
  884. gppb(sesskey, "OSXOptionMeta", true, conf, CONF_osx_option_meta);
  885. gppb(sesskey, "OSXCommandMeta", false, conf, CONF_osx_command_meta);
  886. #endif
  887. i = gppi_raw(sesskey, "BellOverloadT", 2*TICKSPERSEC
  888. #ifdef PUTTY_UNIX_PLATFORM_H
  889. *1000
  890. #endif
  891. );
  892. conf_set_int(conf, CONF_bellovl_t, i
  893. #ifdef PUTTY_UNIX_PLATFORM_H
  894. / 1000
  895. #endif
  896. );
  897. i = gppi_raw(sesskey, "BellOverloadS", 5*TICKSPERSEC
  898. #ifdef PUTTY_UNIX_PLATFORM_H
  899. *1000
  900. #endif
  901. );
  902. conf_set_int(conf, CONF_bellovl_s, i
  903. #ifdef PUTTY_UNIX_PLATFORM_H
  904. / 1000
  905. #endif
  906. );
  907. for (i = 0; i < 22; i++) {
  908. static const char *const defaults[] = {
  909. "187,187,187", "255,255,255", "0,0,0", "85,85,85", "0,0,0",
  910. "0,255,0", "0,0,0", "85,85,85", "187,0,0", "255,85,85",
  911. "0,187,0", "85,255,85", "187,187,0", "255,255,85", "0,0,187",
  912. "85,85,255", "187,0,187", "255,85,255", "0,187,187",
  913. "85,255,255", "187,187,187", "255,255,255"
  914. };
  915. char buf[20], *buf2;
  916. int c0, c1, c2;
  917. sprintf(buf, "Colour%d", i);
  918. buf2 = gpps_raw(sesskey, buf, defaults[i]);
  919. if (sscanf(buf2, "%d,%d,%d", &c0, &c1, &c2) == 3) {
  920. conf_set_int_int(conf, CONF_colours, i*3+0, c0);
  921. conf_set_int_int(conf, CONF_colours, i*3+1, c1);
  922. conf_set_int_int(conf, CONF_colours, i*3+2, c2);
  923. }
  924. sfree(buf2);
  925. }
  926. for (i = 0; i < 256; i += 32) {
  927. static const char *const defaults[] = {
  928. "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",
  929. "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",
  930. "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",
  931. "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",
  932. "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",
  933. "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",
  934. "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",
  935. "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"
  936. };
  937. char buf[20], *buf2, *p;
  938. int j;
  939. sprintf(buf, "Wordness%d", i);
  940. buf2 = gpps_raw(sesskey, buf, defaults[i / 32]);
  941. p = buf2;
  942. for (j = i; j < i + 32; j++) {
  943. char *q = p;
  944. while (*p && *p != ',')
  945. p++;
  946. if (*p == ',')
  947. *p++ = '\0';
  948. conf_set_int_int(conf, CONF_wordness, j, atoi(q));
  949. }
  950. sfree(buf2);
  951. }
  952. read_clip_setting(sesskey, "MousePaste", CLIPUI_DEFAULT_MOUSE,
  953. conf, CONF_mousepaste, CONF_mousepaste_custom);
  954. read_clip_setting(sesskey, "CtrlShiftIns", CLIPUI_DEFAULT_INS,
  955. conf, CONF_ctrlshiftins, CONF_ctrlshiftins_custom);
  956. read_clip_setting(sesskey, "CtrlShiftCV", CLIPUI_NONE,
  957. conf, CONF_ctrlshiftcv, CONF_ctrlshiftcv_custom);
  958. /*
  959. * The empty default for LineCodePage will be converted later
  960. * into a plausible default for the locale.
  961. */
  962. gppmap(sesskey, "PortForwardings", conf, CONF_portfwd);
  963. {
  964. int i;
  965. i = gppi_raw(sesskey, "BugHMAC2", 0); conf_set_int(conf, CONF_sshbug_hmac2, 2-i);
  966. if (2-i == AUTO) {
  967. i = gppi_raw(sesskey, "BuggyMAC", 0);
  968. if (i == 1)
  969. conf_set_int(conf, CONF_sshbug_hmac2, FORCE_ON);
  970. }
  971. }
  972. gppmap(sesskey, "SSHManualHostKeys", conf, CONF_ssh_manual_hostkeys);
  973. }
  974. bool do_defaults(const char *session, Conf *conf)
  975. {
  976. return load_settings(session, conf);
  977. }
  978. static int sessioncmp(const void *av, const void *bv)
  979. {
  980. const char *a = *(const char *const *) av;
  981. const char *b = *(const char *const *) bv;
  982. /*
  983. * Alphabetical order, except that "Default Settings" is a
  984. * special case and comes first.
  985. */
  986. if (!strcmp(a, "Default Settings"))
  987. return -1; /* a comes first */
  988. if (!strcmp(b, "Default Settings"))
  989. return +1; /* b comes first */
  990. /*
  991. * FIXME: perhaps we should ignore the first & in determining
  992. * sort order.
  993. */
  994. return strcmp(a, b); /* otherwise, compare normally */
  995. }
  996. bool sesslist_demo_mode = false;
  997. void get_sesslist(struct sesslist *list, bool allocate)
  998. {
  999. int i;
  1000. char *p;
  1001. settings_e *handle;
  1002. if (allocate) {
  1003. strbuf *sb = strbuf_new();
  1004. if (sesslist_demo_mode) {
  1005. put_asciz(sb, "demo-server");
  1006. put_asciz(sb, "demo-server-2");
  1007. } else {
  1008. if ((handle = enum_settings_start()) != NULL) {
  1009. while (enum_settings_next(handle, sb))
  1010. put_byte(sb, '\0');
  1011. enum_settings_finish(handle);
  1012. }
  1013. put_byte(sb, '\0');
  1014. }
  1015. list->buffer = strbuf_to_str(sb);
  1016. /*
  1017. * Now set up the list of sessions. Note that "Default
  1018. * Settings" must always be claimed to exist, even if it
  1019. * doesn't really.
  1020. */
  1021. p = list->buffer;
  1022. list->nsessions = 1; /* "Default Settings" counts as one */
  1023. while (*p) {
  1024. if (strcmp(p, "Default Settings"))
  1025. list->nsessions++;
  1026. while (*p)
  1027. p++;
  1028. p++;
  1029. }
  1030. list->sessions = snewn(list->nsessions + 1, const char *);
  1031. list->sessions[0] = "Default Settings";
  1032. p = list->buffer;
  1033. i = 1;
  1034. while (*p) {
  1035. if (strcmp(p, "Default Settings"))
  1036. list->sessions[i++] = p;
  1037. while (*p)
  1038. p++;
  1039. p++;
  1040. }
  1041. qsort(list->sessions, i, sizeof(const char *), sessioncmp);
  1042. } else {
  1043. sfree(list->buffer);
  1044. sfree(list->sessions);
  1045. list->buffer = NULL;
  1046. list->sessions = NULL;
  1047. }
  1048. }