]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - settings.c
Document /DNO_SECURITY compile option.
[PuTTY.git] / settings.c
1 /*
2  * settings.c: read and write saved sessions.
3  */
4
5 #include <windows.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include "putty.h"
9 #include "storage.h"
10
11 static void gpps(void *handle, char *name, char *def, char *val, int len)
12 {
13     if (!read_setting_s(handle, name, val, len)) {
14         strncpy(val, def, len);
15         val[len - 1] = '\0';
16     }
17 }
18
19 static void gppi(void *handle, char *name, int def, int *i)
20 {
21     *i = read_setting_i(handle, name, def);
22 }
23
24 void save_settings(char *section, int do_host, Config * cfg)
25 {
26     int i;
27     char *p;
28     void *sesskey;
29
30     sesskey = open_settings_w(section);
31     if (!sesskey)
32         return;
33
34     write_setting_i(sesskey, "Present", 1);
35     if (do_host) {
36         write_setting_s(sesskey, "HostName", cfg->host);
37         write_setting_s(sesskey, "LogFileName", cfg->logfilename);
38         write_setting_i(sesskey, "LogType", cfg->logtype);
39         write_setting_i(sesskey, "LogFileClash", cfg->logxfovr);
40     }
41     p = "raw";
42     for (i = 0; backends[i].name != NULL; i++)
43         if (backends[i].protocol == cfg->protocol) {
44             p = backends[i].name;
45             break;
46         }
47     write_setting_s(sesskey, "Protocol", p);
48     write_setting_i(sesskey, "PortNumber", cfg->port);
49     write_setting_i(sesskey, "CloseOnExit", cfg->close_on_exit);
50     write_setting_i(sesskey, "WarnOnClose", !!cfg->warn_on_close);
51     write_setting_i(sesskey, "PingInterval", cfg->ping_interval / 60);  /* minutes */
52     write_setting_i(sesskey, "PingIntervalSecs", cfg->ping_interval % 60);      /* seconds */
53     write_setting_s(sesskey, "TerminalType", cfg->termtype);
54     write_setting_s(sesskey, "TerminalSpeed", cfg->termspeed);
55     {
56         char buf[2 * sizeof(cfg->environmt)], *p, *q;
57         p = buf;
58         q = cfg->environmt;
59         while (*q) {
60             while (*q) {
61                 int c = *q++;
62                 if (c == '=' || c == ',' || c == '\\')
63                     *p++ = '\\';
64                 if (c == '\t')
65                     c = '=';
66                 *p++ = c;
67             }
68             *p++ = ',';
69             q++;
70         }
71         *p = '\0';
72         write_setting_s(sesskey, "Environment", buf);
73     }
74     write_setting_s(sesskey, "UserName", cfg->username);
75     write_setting_s(sesskey, "LocalUserName", cfg->localusername);
76     write_setting_i(sesskey, "NoPTY", cfg->nopty);
77     write_setting_i(sesskey, "Compression", cfg->compression);
78     write_setting_i(sesskey, "AgentFwd", cfg->agentfwd);
79     write_setting_s(sesskey, "Cipher",
80                     cfg->cipher == CIPHER_BLOWFISH ? "blowfish" :
81                     cfg->cipher == CIPHER_DES ? "des" :
82                     cfg->cipher == CIPHER_AES ? "aes" : "3des");
83     write_setting_i(sesskey, "AuthTIS", cfg->try_tis_auth);
84     write_setting_i(sesskey, "SshProt", cfg->sshprot);
85     write_setting_i(sesskey, "BuggyMAC", cfg->buggymac);
86     write_setting_s(sesskey, "PublicKeyFile", cfg->keyfile);
87     write_setting_s(sesskey, "RemoteCommand", cfg->remote_cmd);
88     write_setting_i(sesskey, "RFCEnviron", cfg->rfc_environ);
89     write_setting_i(sesskey, "PassiveTelnet", cfg->passive_telnet);
90     write_setting_i(sesskey, "BackspaceIsDelete", cfg->bksp_is_delete);
91     write_setting_i(sesskey, "RXVTHomeEnd", cfg->rxvt_homeend);
92     write_setting_i(sesskey, "LinuxFunctionKeys", cfg->funky_type);
93     write_setting_i(sesskey, "NoApplicationKeys", cfg->no_applic_k);
94     write_setting_i(sesskey, "NoApplicationCursors", cfg->no_applic_c);
95     write_setting_i(sesskey, "ApplicationCursorKeys", cfg->app_cursor);
96     write_setting_i(sesskey, "ApplicationKeypad", cfg->app_keypad);
97     write_setting_i(sesskey, "NetHackKeypad", cfg->nethack_keypad);
98     write_setting_i(sesskey, "AltF4", cfg->alt_f4);
99     write_setting_i(sesskey, "AltSpace", cfg->alt_space);
100     write_setting_i(sesskey, "AltOnly", cfg->alt_only);
101     write_setting_i(sesskey, "ComposeKey", cfg->compose_key);
102     write_setting_i(sesskey, "CtrlAltKeys", cfg->ctrlaltkeys);
103     write_setting_i(sesskey, "TelnetKey", cfg->telnet_keyboard);
104     write_setting_i(sesskey, "LocalEcho", cfg->localecho);
105     write_setting_i(sesskey, "LocalEdit", cfg->localedit);
106     write_setting_s(sesskey, "Answerback", cfg->answerback);
107     write_setting_i(sesskey, "AlwaysOnTop", cfg->alwaysontop);
108     write_setting_i(sesskey, "HideMousePtr", cfg->hide_mouseptr);
109     write_setting_i(sesskey, "SunkenEdge", cfg->sunken_edge);
110     write_setting_i(sesskey, "CurType", cfg->cursor_type);
111     write_setting_i(sesskey, "BlinkCur", cfg->blink_cur);
112     write_setting_i(sesskey, "Beep", cfg->beep);
113     write_setting_i(sesskey, "BeepInd", cfg->beep_ind);
114     write_setting_s(sesskey, "BellWaveFile", cfg->bell_wavefile);
115     write_setting_i(sesskey, "BellOverload", cfg->bellovl);
116     write_setting_i(sesskey, "BellOverloadN", cfg->bellovl_n);
117     write_setting_i(sesskey, "BellOverloadT", cfg->bellovl_t);
118     write_setting_i(sesskey, "BellOverloadS", cfg->bellovl_s);
119     write_setting_i(sesskey, "ScrollbackLines", cfg->savelines);
120     write_setting_i(sesskey, "DECOriginMode", cfg->dec_om);
121     write_setting_i(sesskey, "AutoWrapMode", cfg->wrap_mode);
122     write_setting_i(sesskey, "LFImpliesCR", cfg->lfhascr);
123     write_setting_i(sesskey, "WinNameAlways", cfg->win_name_always);
124     write_setting_s(sesskey, "WinTitle", cfg->wintitle);
125     write_setting_i(sesskey, "TermWidth", cfg->width);
126     write_setting_i(sesskey, "TermHeight", cfg->height);
127     write_setting_s(sesskey, "Font", cfg->font);
128     write_setting_i(sesskey, "FontIsBold", cfg->fontisbold);
129     write_setting_i(sesskey, "FontCharSet", cfg->fontcharset);
130     write_setting_i(sesskey, "FontHeight", cfg->fontheight);
131     write_setting_i(sesskey, "FontVTMode", cfg->vtmode);
132     write_setting_i(sesskey, "TryPalette", cfg->try_palette);
133     write_setting_i(sesskey, "BoldAsColour", cfg->bold_colour);
134     for (i = 0; i < 22; i++) {
135         char buf[20], buf2[30];
136         sprintf(buf, "Colour%d", i);
137         sprintf(buf2, "%d,%d,%d", cfg->colours[i][0],
138                 cfg->colours[i][1], cfg->colours[i][2]);
139         write_setting_s(sesskey, buf, buf2);
140     }
141     write_setting_i(sesskey, "RawCNP", cfg->rawcnp);
142     write_setting_i(sesskey, "MouseIsXterm", cfg->mouse_is_xterm);
143     for (i = 0; i < 256; i += 32) {
144         char buf[20], buf2[256];
145         int j;
146         sprintf(buf, "Wordness%d", i);
147         *buf2 = '\0';
148         for (j = i; j < i + 32; j++) {
149             sprintf(buf2 + strlen(buf2), "%s%d",
150                     (*buf2 ? "," : ""), cfg->wordness[j]);
151         }
152         write_setting_s(sesskey, buf, buf2);
153     }
154     write_setting_s(sesskey, "LineCodePage", cfg->line_codepage);
155     write_setting_i(sesskey, "ScrollBar", cfg->scrollbar);
156     write_setting_i(sesskey, "ScrollOnKey", cfg->scroll_on_key);
157     write_setting_i(sesskey, "ScrollOnDisp", cfg->scroll_on_disp);
158     write_setting_i(sesskey, "LockSize", cfg->locksize);
159     write_setting_i(sesskey, "BCE", cfg->bce);
160     write_setting_i(sesskey, "BlinkText", cfg->blinktext);
161     write_setting_i(sesskey, "X11Forward", cfg->x11_forward);
162     write_setting_s(sesskey, "X11Display", cfg->x11_display);
163     write_setting_i(sesskey, "LocalPortAcceptAll", cfg->lport_acceptall);
164     {
165         char buf[2 * sizeof(cfg->portfwd)], *p, *q;
166         p = buf;
167         q = cfg->portfwd;
168         while (*q) {
169             while (*q) {
170                 int c = *q++;
171                 if (c == '=' || c == ',' || c == '\\')
172                     *p++ = '\\';
173                 if (c == '\t')
174                     c = '=';
175                 *p++ = c;
176             }
177             *p++ = ',';
178             q++;
179         }
180         *p = '\0';
181         write_setting_s(sesskey, "PortForwardings", buf);
182     }
183
184     close_settings_w(sesskey);
185 }
186
187 void load_settings(char *section, int do_host, Config * cfg)
188 {
189     int i;
190     char prot[10];
191     void *sesskey;
192
193     sesskey = open_settings_r(section);
194
195     cfg->ssh_subsys = 0;               /* FIXME: load this properly */
196     cfg->remote_cmd_ptr = cfg->remote_cmd;
197
198     gpps(sesskey, "HostName", "", cfg->host, sizeof(cfg->host));
199     gppi(sesskey, "PortNumber", default_port, &cfg->port);
200     gpps(sesskey, "LogFileName", "putty.log",
201          cfg->logfilename, sizeof(cfg->logfilename));
202     gppi(sesskey, "LogType", 0, &cfg->logtype);
203     gppi(sesskey, "LogFileClash", LGXF_ASK, &cfg->logxfovr);
204
205     gpps(sesskey, "Protocol", "default", prot, 10);
206     cfg->protocol = default_protocol;
207     for (i = 0; backends[i].name != NULL; i++)
208         if (!strcmp(prot, backends[i].name)) {
209             cfg->protocol = backends[i].protocol;
210             break;
211         }
212
213     gppi(sesskey, "CloseOnExit", COE_NORMAL, &cfg->close_on_exit);
214     gppi(sesskey, "WarnOnClose", 1, &cfg->warn_on_close);
215     {
216         /* This is two values for backward compatibility with 0.50/0.51 */
217         int pingmin, pingsec;
218         gppi(sesskey, "PingInterval", 0, &pingmin);
219         gppi(sesskey, "PingIntervalSecs", 0, &pingsec);
220         cfg->ping_interval = pingmin * 60 + pingsec;
221     }
222     gpps(sesskey, "TerminalType", "xterm", cfg->termtype,
223          sizeof(cfg->termtype));
224     gpps(sesskey, "TerminalSpeed", "38400,38400", cfg->termspeed,
225          sizeof(cfg->termspeed));
226     {
227         char buf[2 * sizeof(cfg->environmt)], *p, *q;
228         gpps(sesskey, "Environment", "", buf, sizeof(buf));
229         p = buf;
230         q = cfg->environmt;
231         while (*p) {
232             while (*p && *p != ',') {
233                 int c = *p++;
234                 if (c == '=')
235                     c = '\t';
236                 if (c == '\\')
237                     c = *p++;
238                 *q++ = c;
239             }
240             if (*p == ',')
241                 p++;
242             *q++ = '\0';
243         }
244         *q = '\0';
245     }
246     gpps(sesskey, "UserName", "", cfg->username, sizeof(cfg->username));
247     gpps(sesskey, "LocalUserName", "", cfg->localusername,
248          sizeof(cfg->localusername));
249     gppi(sesskey, "NoPTY", 0, &cfg->nopty);
250     gppi(sesskey, "Compression", 0, &cfg->compression);
251     gppi(sesskey, "AgentFwd", 0, &cfg->agentfwd);
252     {
253         char cipher[10];
254         gpps(sesskey, "Cipher", "3des", cipher, 10);
255         if (!strcmp(cipher, "blowfish"))
256             cfg->cipher = CIPHER_BLOWFISH;
257         else if (!strcmp(cipher, "des"))
258             cfg->cipher = CIPHER_DES;
259         else if (!strcmp(cipher, "aes"))
260             cfg->cipher = CIPHER_AES;
261         else
262             cfg->cipher = CIPHER_3DES;
263     }
264     gppi(sesskey, "SshProt", 1, &cfg->sshprot);
265     gppi(sesskey, "BuggyMAC", 0, &cfg->buggymac);
266     gppi(sesskey, "AuthTIS", 0, &cfg->try_tis_auth);
267     gpps(sesskey, "PublicKeyFile", "", cfg->keyfile, sizeof(cfg->keyfile));
268     gpps(sesskey, "RemoteCommand", "", cfg->remote_cmd,
269          sizeof(cfg->remote_cmd));
270     gppi(sesskey, "RFCEnviron", 0, &cfg->rfc_environ);
271     gppi(sesskey, "PassiveTelnet", 0, &cfg->passive_telnet);
272     gppi(sesskey, "BackspaceIsDelete", 1, &cfg->bksp_is_delete);
273     gppi(sesskey, "RXVTHomeEnd", 0, &cfg->rxvt_homeend);
274     gppi(sesskey, "LinuxFunctionKeys", 0, &cfg->funky_type);
275     gppi(sesskey, "NoApplicationKeys", 0, &cfg->no_applic_k);
276     gppi(sesskey, "NoApplicationCursors", 0, &cfg->no_applic_c);
277     gppi(sesskey, "ApplicationCursorKeys", 0, &cfg->app_cursor);
278     gppi(sesskey, "ApplicationKeypad", 0, &cfg->app_keypad);
279     gppi(sesskey, "NetHackKeypad", 0, &cfg->nethack_keypad);
280     gppi(sesskey, "AltF4", 1, &cfg->alt_f4);
281     gppi(sesskey, "AltSpace", 0, &cfg->alt_space);
282     gppi(sesskey, "AltOnly", 0, &cfg->alt_only);
283     gppi(sesskey, "ComposeKey", 0, &cfg->compose_key);
284     gppi(sesskey, "CtrlAltKeys", 1, &cfg->ctrlaltkeys);
285     gppi(sesskey, "TelnetKey", 0, &cfg->telnet_keyboard);
286     gppi(sesskey, "LocalEcho", LD_BACKEND, &cfg->localecho);
287     gppi(sesskey, "LocalEdit", LD_BACKEND, &cfg->localedit);
288     gpps(sesskey, "Answerback", "PuTTY", cfg->answerback,
289          sizeof(cfg->answerback));
290     gppi(sesskey, "AlwaysOnTop", 0, &cfg->alwaysontop);
291     gppi(sesskey, "HideMousePtr", 0, &cfg->hide_mouseptr);
292     gppi(sesskey, "SunkenEdge", 0, &cfg->sunken_edge);
293     gppi(sesskey, "CurType", 0, &cfg->cursor_type);
294     gppi(sesskey, "BlinkCur", 0, &cfg->blink_cur);
295     /* pedantic compiler tells me I can't use &cfg->beep as an int * :-) */
296     gppi(sesskey, "Beep", 1, &i); cfg->beep = i;
297     gppi(sesskey, "BeepInd", 0, &i); cfg->beep_ind = i;
298     gpps(sesskey, "BellWaveFile", "", cfg->bell_wavefile,
299          sizeof(cfg->bell_wavefile));
300     gppi(sesskey, "BellOverload", 1, &cfg->bellovl);
301     gppi(sesskey, "BellOverloadN", 5, &cfg->bellovl_n);
302     gppi(sesskey, "BellOverloadT", 2000, &cfg->bellovl_t);
303     gppi(sesskey, "BellOverloadS", 5000, &cfg->bellovl_s);
304     gppi(sesskey, "ScrollbackLines", 200, &cfg->savelines);
305     gppi(sesskey, "DECOriginMode", 0, &cfg->dec_om);
306     gppi(sesskey, "AutoWrapMode", 1, &cfg->wrap_mode);
307     gppi(sesskey, "LFImpliesCR", 0, &cfg->lfhascr);
308     gppi(sesskey, "WinNameAlways", 0, &cfg->win_name_always);
309     gpps(sesskey, "WinTitle", "", cfg->wintitle, sizeof(cfg->wintitle));
310     gppi(sesskey, "TermWidth", 80, &cfg->width);
311     gppi(sesskey, "TermHeight", 24, &cfg->height);
312     gpps(sesskey, "Font", "Courier", cfg->font, sizeof(cfg->font));
313     gppi(sesskey, "FontIsBold", 0, &cfg->fontisbold);
314     gppi(sesskey, "FontCharSet", ANSI_CHARSET, &cfg->fontcharset);
315     gppi(sesskey, "FontHeight", 10, &cfg->fontheight);
316     if (cfg->fontheight < 0) {
317         int oldh, newh;
318         HDC hdc = GetDC(NULL);
319         int logpix = GetDeviceCaps(hdc, LOGPIXELSY);
320         ReleaseDC(NULL, hdc);
321
322         oldh = -cfg->fontheight;
323         newh = MulDiv(oldh, 72, logpix) + 1;
324         if (MulDiv(newh, logpix, 72) > oldh)
325             newh--;
326         cfg->fontheight = newh;
327     }
328     gppi(sesskey, "FontVTMode", VT_OEMANSI, (int *) &cfg->vtmode);
329     gppi(sesskey, "TryPalette", 0, &cfg->try_palette);
330     gppi(sesskey, "BoldAsColour", 1, &cfg->bold_colour);
331     for (i = 0; i < 22; i++) {
332         static char *defaults[] = {
333             "187,187,187", "255,255,255", "0,0,0", "85,85,85", "0,0,0",
334             "0,255,0", "0,0,0", "85,85,85", "187,0,0", "255,85,85",
335             "0,187,0", "85,255,85", "187,187,0", "255,255,85", "0,0,187",
336             "85,85,255", "187,0,187", "255,85,255", "0,187,187",
337             "85,255,255", "187,187,187", "255,255,255"
338         };
339         char buf[20], buf2[30];
340         int c0, c1, c2;
341         sprintf(buf, "Colour%d", i);
342         gpps(sesskey, buf, defaults[i], buf2, sizeof(buf2));
343         if (sscanf(buf2, "%d,%d,%d", &c0, &c1, &c2) == 3) {
344             cfg->colours[i][0] = c0;
345             cfg->colours[i][1] = c1;
346             cfg->colours[i][2] = c2;
347         }
348     }
349     gppi(sesskey, "RawCNP", 0, &cfg->rawcnp);
350     gppi(sesskey, "MouseIsXterm", 0, &cfg->mouse_is_xterm);
351     for (i = 0; i < 256; i += 32) {
352         static char *defaults[] = {
353             "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",
354             "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",
355             "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",
356             "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",
357             "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",
358             "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",
359             "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",
360             "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"
361         };
362         char buf[20], buf2[256], *p;
363         int j;
364         sprintf(buf, "Wordness%d", i);
365         gpps(sesskey, buf, defaults[i / 32], buf2, sizeof(buf2));
366         p = buf2;
367         for (j = i; j < i + 32; j++) {
368             char *q = p;
369             while (*p && *p != ',')
370                 p++;
371             if (*p == ',')
372                 *p++ = '\0';
373             cfg->wordness[j] = atoi(q);
374         }
375     }
376     gpps(sesskey, "LineCodePage", "ISO-8859-1:1987", cfg->line_codepage,
377          sizeof(cfg->line_codepage));
378     gppi(sesskey, "ScrollBar", 1, &cfg->scrollbar);
379     gppi(sesskey, "ScrollOnKey", 0, &cfg->scroll_on_key);
380     gppi(sesskey, "ScrollOnDisp", 1, &cfg->scroll_on_disp);
381     gppi(sesskey, "LockSize", 0, &cfg->locksize);
382     gppi(sesskey, "BCE", 0, &cfg->bce);
383     gppi(sesskey, "BlinkText", 0, &cfg->blinktext);
384     gppi(sesskey, "X11Forward", 0, &cfg->x11_forward);
385     gpps(sesskey, "X11Display", "localhost:0", cfg->x11_display,
386          sizeof(cfg->x11_display));
387
388     gppi(sesskey, "LocalPortAcceptAll", 0, &cfg->lport_acceptall);
389     {
390         char buf[2 * sizeof(cfg->portfwd)], *p, *q;
391         gpps(sesskey, "PortForwardings", "", buf, sizeof(buf));
392         p = buf;
393         q = cfg->portfwd;
394         while (*p) {
395             while (*p && *p != ',') {
396                 int c = *p++;
397                 if (c == '=')
398                     c = '\t';
399                 if (c == '\\')
400                     c = *p++;
401                 *q++ = c;
402             }
403             if (*p == ',')
404                 p++;
405             *q++ = '\0';
406         }
407         *q = '\0';
408     }
409
410     close_settings_r(sesskey);
411 }
412
413 void do_defaults(char *session, Config * cfg)
414 {
415     if (session)
416         load_settings(session, TRUE, cfg);
417     else
418         load_settings("Default Settings", FALSE, cfg);
419 }
420
421 static int sessioncmp(const void *av, const void *bv)
422 {
423     const char *a = *(const char *const *) av;
424     const char *b = *(const char *const *) bv;
425
426     /*
427      * Alphabetical order, except that "Default Settings" is a
428      * special case and comes first.
429      */
430     if (!strcmp(a, "Default Settings"))
431         return -1;                     /* a comes first */
432     if (!strcmp(b, "Default Settings"))
433         return +1;                     /* b comes first */
434     return strcmp(a, b);               /* otherwise, compare normally */
435 }
436
437 void get_sesslist(int allocate)
438 {
439     static char otherbuf[2048];
440     static char *buffer;
441     int buflen, bufsize, i;
442     char *p, *ret;
443     void *handle;
444
445     if (allocate) {
446
447         if ((handle = enum_settings_start()) == NULL)
448             return;
449
450         buflen = bufsize = 0;
451         buffer = NULL;
452         do {
453             ret = enum_settings_next(handle, otherbuf, sizeof(otherbuf));
454             if (ret) {
455                 int len = strlen(otherbuf) + 1;
456                 if (bufsize < buflen + len) {
457                     bufsize = buflen + len + 2048;
458                     buffer = srealloc(buffer, bufsize);
459                 }
460                 strcpy(buffer + buflen, otherbuf);
461                 buflen += strlen(buffer + buflen) + 1;
462             }
463         } while (ret);
464         enum_settings_finish(handle);
465         buffer = srealloc(buffer, buflen + 1);
466         buffer[buflen] = '\0';
467
468         /*
469          * Now set up the list of sessions. Note that "Default
470          * Settings" must always be claimed to exist, even if it
471          * doesn't really.
472          */
473
474         p = buffer;
475         nsessions = 1;                 /* "Default Settings" counts as one */
476         while (*p) {
477             if (strcmp(p, "Default Settings"))
478                 nsessions++;
479             while (*p)
480                 p++;
481             p++;
482         }
483
484         sessions = smalloc((nsessions + 1) * sizeof(char *));
485         sessions[0] = "Default Settings";
486         p = buffer;
487         i = 1;
488         while (*p) {
489             if (strcmp(p, "Default Settings"))
490                 sessions[i++] = p;
491             while (*p)
492                 p++;
493             p++;
494         }
495
496         qsort(sessions, i, sizeof(char *), sessioncmp);
497     } else {
498         sfree(buffer);
499         sfree(sessions);
500     }
501 }