]> code.citadel.org Git - citadel.git/blob - citadel/citadel.c
added a nested ungoto list, so you can ungoto 100 times.
[citadel.git] / citadel / citadel.c
1 /*
2  * $Id$
3  *
4  * Main source module for the client program.
5  */
6
7 #include "sysdep.h"
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <fcntl.h>
11 #include <stdio.h>
12 #include <ctype.h>
13 #include <string.h>
14
15 #if TIME_WITH_SYS_TIME
16 # include <sys/time.h>
17 # include <time.h>
18 #else
19 # if HAVE_SYS_TIME_H
20 #  include <sys/time.h>
21 # else
22 #  include <time.h>
23 # endif
24 #endif
25
26 #include <limits.h>
27 #include <sys/types.h>
28 #include <sys/wait.h>
29 #include <sys/stat.h>
30 #include <sys/ioctl.h>
31 #include <signal.h>
32 #include <pwd.h>
33 #include <setjmp.h>
34 #include <stdarg.h>
35
36 #include "citadel.h"
37 #include "axdefs.h"
38 #include "serv_info.h"
39 #include "routines.h"
40 #include "routines2.h"
41 #include "rooms.h"
42 #include "messages.h"
43 #include "commands.h"
44 #include "ipc.h"
45 #include "client_chat.h"
46 #include "client_passwords.h"
47 #include "citadel_decls.h"
48 #include "tools.h"
49 #include "acconfig.h"
50 #include "client_crypto.h"
51 #ifndef HAVE_SNPRINTF
52 #include "snprintf.h"
53 #endif
54 #include "screen.h"
55
56 #include "md5.h"
57
58 struct march {
59         struct march *next;
60         char march_name[ROOMNAMELEN];
61         char march_floor;
62         char march_order;
63         };
64
65 #define IFEXPERT if (userflags&US_EXPERT)
66 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
67 #define IFAIDE if (axlevel>=6)
68 #define IFNAIDE if (axlevel<6)
69
70 struct march *march = NULL;
71
72 /* globals associated with the client program */
73 char temp[PATH_MAX];            /* Name of general temp file */
74 char temp2[PATH_MAX];           /* Name of general temp file */
75 char tempdir[PATH_MAX];         /* Name of general temp dir */
76 char editor_path[SIZ];          /* path to external editor */
77 char printcmd[SIZ];             /* print command */
78 int editor_pid = (-1);
79 char fullname[32];
80 jmp_buf nextbuf;
81 struct CtdlServInfo serv_info;  /* Info on the server connected */
82 int screenwidth;
83 int screenheight;
84 unsigned room_flags;
85 char room_name[ROOMNAMELEN];
86 char *uglist[UGLISTLEN]; /* size of the ungoto list */
87 long uglistlsn[UGLISTLEN]; /* current read position for all the ungoto's. Not going to make any friends with this one. */
88 int uglistsize = 0;
89 char is_mail = 0;               /* nonzero when we're in a mail room */
90 char axlevel = 0;               /* access level */
91 char is_room_aide = 0;          /* boolean flag, 1 if room aide */
92 int timescalled;
93 int posted;
94 unsigned userflags;
95 long usernum = 0L;              /* user number */
96 time_t lastcall = 0L;           /* Date/time of previous login */
97 char newnow;
98 long highest_msg_read;          /* used for <A>bandon room cmd */
99 long maxmsgnum;                 /* used for <G>oto */
100 char sigcaught = 0;
101 char have_xterm = 0;            /* are we running on an xterm? */
102 char rc_username[32];
103 char rc_password[32];
104 char hostbuf[SIZ];
105 char portbuf[SIZ];
106 char rc_floor_mode;
107 char floor_mode;
108 char curr_floor = 0;            /* number of current floor */
109 char floorlist[128][SIZ];       /* names of floors */
110 char express_msgs = 0;          /* express messages waiting! */
111 int termn8 = 0;                 /* Set to nonzero to cause a logoff */
112 int secure;                     /* Set to nonzero when wire is encrypted */
113
114 extern int rc_ansi_color;       /* ansi color value from citadel.rc */
115
116 /*
117  * here is our 'clean up gracefully and exit' routine
118  */
119 void logoff(int code)
120 {
121     int lp;
122         if (editor_pid > 0) {   /* kill the editor if it's running */
123                 kill(editor_pid, SIGHUP);
124         }
125
126     /* Free the ungoto list */
127     for (lp = 0; lp < uglistsize; lp++)
128       free (uglist[lp]);
129
130 /* shut down the server... but not if the logoff code is 3, because
131  * that means we're exiting because we already lost the server
132  */
133         if (code != 3)
134                 serv_puts("QUIT");
135
136 /*
137  * now clean up various things
138  */
139
140         screen_delete();
141
142         unlink(temp);
143         unlink(temp2);
144         nukedir(tempdir);
145
146         /* Violently kill off any child processes if Citadel is
147          * the login shell. 
148          */
149         if (getppid() == 1) {
150                 kill(0 - getpgrp(), SIGTERM);
151                 sleep(1);
152                 kill(0 - getpgrp(), SIGKILL);
153         }
154         sttybbs(SB_RESTORE);    /* return the old terminal settings */
155         exit(code);             /* exit with the proper exit code */
156 }
157
158
159
160 /*
161  * signal catching function for hangups...
162  */
163 void dropcarr(int signum)
164 {
165         logoff(SIGHUP);
166 }
167
168
169
170 /*
171  * catch SIGCONT to reset terminal modes when were are put back into the
172  * foreground.
173  */
174 void catch_sigcont(int signum)
175 {
176         sttybbs(SB_LAST);
177         signal(SIGCONT, catch_sigcont);
178 }
179
180
181
182 /* general purpose routines */
183
184 void formout(char *name)
185 {                               /* display a file */
186         char cmd[SIZ];
187         snprintf(cmd, sizeof cmd, "MESG %s", name);
188         serv_puts(cmd);
189         serv_gets(cmd);
190         if (cmd[0] != '1') {
191                 scr_printf("%s\n", &cmd[4]);
192                 return;
193         }
194         fmout(screenwidth, NULL, NULL,
195               ((userflags & US_PAGINATOR) ? 1 : 0),
196               screenheight, 1, 1);
197 }
198
199
200 void userlist(char *patn)
201 {
202         char buf[SIZ];
203         char fl[SIZ];
204         struct tm *tmbuf;
205         time_t lc;
206
207         serv_puts("LIST");
208         serv_gets(buf);
209         if (buf[0] != '1') {
210                 pprintf("%s\n", &buf[4]);
211                 return;
212         }
213         pprintf("       User Name           Num  L  LastCall  Calls Posts\n");
214         pprintf("------------------------- ----- - ---------- ----- -----\n");
215         while (serv_gets(buf), strcmp(buf, "000")) {
216                 if (sigcaught == 0) {
217                     extract(fl, buf, 0);
218                     if (pattern(fl, patn) >= 0) {
219                         pprintf("%-25s ", fl);
220                         pprintf("%5ld %d ", extract_long(buf, 2),
221                                extract_int(buf, 1));
222                         lc = extract_long(buf, 3);
223                         tmbuf = (struct tm *) localtime(&lc);
224                         pprintf("%02d/%02d/%04d ",
225                                (tmbuf->tm_mon + 1),
226                                tmbuf->tm_mday,
227                                (tmbuf->tm_year + 1900));
228                         pprintf("%5ld %5ld\n", extract_long(buf, 4), extract_long(buf, 5));
229                     }
230
231                 }
232         }
233         pprintf("\n");
234 }
235
236
237 /*
238  * grab assorted info about the user...
239  */
240 void load_user_info(char *params)
241 {
242         extract(fullname, params, 0);
243         axlevel = extract_int(params, 1);
244         timescalled = extract_int(params, 2);
245         posted = extract_int(params, 3);
246         userflags = extract_int(params, 4);
247         usernum = extract_long(params, 5);
248         lastcall = extract_long(params, 6);
249 }
250
251
252 /*
253  * Remove a room from the march list.  'floornum' is ignored unless
254  * 'roomname' is set to _FLOOR_, in which case all rooms on the requested
255  * floor will be removed from the march list.
256  */
257 void remove_march(char *roomname, int floornum)
258 {
259         struct march *mptr, *mptr2;
260
261         if (march == NULL)
262                 return;
263
264         if ((!strcasecmp(march->march_name, roomname))
265             || ((!strcasecmp(roomname, "_FLOOR_")) && (march->march_floor == floornum))) {
266                 mptr = march->next;
267                 free(march);
268                 march = mptr;
269                 return;
270         }
271         mptr2 = march;
272         for (mptr = march; mptr != NULL; mptr = mptr->next) {
273
274                 if ((!strcasecmp(mptr->march_name, roomname))
275                     || ((!strcasecmp(roomname, "_FLOOR_"))
276                         && (mptr->march_floor == floornum))) {
277
278                         mptr2->next = mptr->next;
279                         free(mptr);
280                         mptr = mptr2;
281                 } else {
282                         mptr2 = mptr;
283                 }
284         }
285 }
286
287
288 /*
289  * Locate the room on the march list which we most want to go to.  Each room
290  * is measured given a "weight" of preference based on various factors.
291  */
292 char *pop_march(int desired_floor)
293 {
294         static char TheRoom[ROOMNAMELEN];
295         int TheFloor = 0;
296         int TheOrder = 32767;
297         int TheWeight = 0;
298         int weight;
299         struct march *mptr = NULL;
300
301         strcpy(TheRoom, "_BASEROOM_");
302         if (march == NULL)
303                 return (TheRoom);
304
305         for (mptr = march; mptr != NULL; mptr = mptr->next) {
306                 weight = 0;
307                 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
308                         weight = weight + 10000;
309                 if (mptr->march_floor == desired_floor)
310                         weight = weight + 5000;
311
312                 weight = weight + ((128 - (mptr->march_floor)) * 128);
313                 weight = weight + (128 - (mptr->march_order));
314
315                 if (weight > TheWeight) {
316                         TheWeight = weight;
317                         strcpy(TheRoom, mptr->march_name);
318                         TheFloor = mptr->march_floor;
319                         TheOrder = mptr->march_order;
320                 }
321         }
322         return (TheRoom);
323 }
324
325
326 /*
327  * jump directly to a room
328  */
329 void dotgoto(char *towhere, int display_name, int fromungoto)
330 {
331         char aaa[SIZ], bbb[SIZ], psearch[SIZ];
332         static long ls = 0L;
333         int newmailcount = 0;
334         static int oldmailcount = (-1);
335         int partial_match, best_match;
336         char from_floor;
337     int ugpos = uglistsize;
338
339         /* store ungoto information */
340     if (fromungoto == 0)
341       {
342         if (uglistsize >= (UGLISTLEN-1))
343           {  /* sloppy slide them all down, hey it's the client, who cares. :-) */
344             int lp;
345             free (uglist[0]);
346             for (lp = 0; lp < (UGLISTLEN-1); lp++)
347               {
348                 uglist[lp] = uglist[lp+1];
349                 uglistlsn[lp] = uglistlsn[lp+1];
350               }
351             ugpos--;
352           }
353         else
354           uglistsize++;
355         
356         uglist[ugpos] = malloc(strlen(room_name)+1);
357         strcpy(uglist[ugpos], room_name);
358         uglistlsn[ugpos] = ls;
359       }
360       
361         /* first try an exact match */
362         snprintf(aaa, sizeof aaa, "GOTO %s", towhere);
363         serv_puts(aaa);
364         serv_gets(aaa);
365         if (aaa[3] == '*')
366                 express_msgs = 1;
367         if (!strncmp(aaa, "54", 2)) {
368                 newprompt("Enter room password: ", bbb, 9);
369                 snprintf(aaa, sizeof aaa, "GOTO %s|%s", towhere, bbb);
370                 serv_puts(aaa);
371                 serv_gets(aaa);
372                 if (aaa[3] == '*')
373                         express_msgs = 1;
374         }
375         if (!strncmp(aaa, "54", 2)) {
376                 scr_printf("Wrong password.\n");
377                 return;
378         }
379         /*
380          * If a match is not found, try a partial match.
381          * Partial matches anywhere in the string carry a weight of 1,
382          * left-aligned matches carry a weight of 2.  Pick the room that
383          * has the highest-weighted match.
384          */
385         if (aaa[0] != '2') {
386                 best_match = 0;
387                 strcpy(bbb, "");
388                 serv_puts("LKRA");
389                 serv_gets(aaa);
390                 if (aaa[0] == '1')
391                         while (serv_gets(aaa), strcmp(aaa, "000")) {
392                                 extract(psearch, aaa, 0);
393                                 partial_match = 0;
394                                 if (pattern(psearch, towhere) >= 0) {
395                                         partial_match = 1;
396                                 }
397                                 if (!strncasecmp(towhere, psearch, strlen(towhere))) {
398                                         partial_match = 2;
399                                 }
400                                 if (partial_match > best_match) {
401                                         strcpy(bbb, psearch);
402                                         best_match = partial_match;
403                                 }
404                         }
405                 if (strlen(bbb) == 0) {
406                         scr_printf("No room '%s'.\n", towhere);
407                         return;
408                 }
409                 snprintf(aaa, sizeof aaa, "GOTO %s", bbb);
410                 serv_puts(aaa);
411                 serv_gets(aaa);
412                 if (aaa[3] == '*')
413                         express_msgs = 1;
414         }
415         if (aaa[0] != '2') {
416                 scr_printf("%s\n", aaa);
417                 return;
418         }
419         extract(room_name, &aaa[4], 0);
420         room_flags = extract_int(&aaa[4], 4);
421         from_floor = curr_floor;
422         curr_floor = extract_int(&aaa[4], 10);
423
424         remove_march(room_name, 0);
425         if (!strcasecmp(towhere, "_BASEROOM_"))
426                 remove_march(towhere, 0);
427         if ((from_floor != curr_floor) && (display_name > 0) && (floor_mode == 1)) {
428                 if (floorlist[(int) curr_floor][0] == 0)
429                         load_floorlist();
430                 scr_printf("(Entering floor: %s)\n", &floorlist[(int) curr_floor][0]);
431         }
432         if (display_name == 1) {
433                 color(BRIGHT_WHITE);
434                 scr_printf("%s ", room_name);
435                 color(DIM_WHITE);
436                 scr_printf("- ");
437         }
438         if (display_name != 2) {
439                 color(BRIGHT_YELLOW);
440                 scr_printf("%d ", extract_int(&aaa[4], 1));
441                 color(DIM_WHITE);
442                 scr_printf("new of ");
443                 color(BRIGHT_YELLOW);
444                 scr_printf("%d ", extract_int(&aaa[4], 2));
445                 color(DIM_WHITE);
446                 scr_printf("messages.\n");
447         }
448         highest_msg_read = extract_int(&aaa[4], 6);
449         maxmsgnum = extract_int(&aaa[4], 5);
450         is_mail = (char) extract_int(&aaa[4], 7);
451         is_room_aide = (char) extract_int(&aaa[4], 8);
452         ls = extract_long(&aaa[4], 6);
453
454         /* read info file if necessary */
455         if (extract_int(&aaa[4], 3) > 0)
456                 readinfo();
457
458         /* check for newly arrived mail if we can */
459         if (num_parms(&aaa[4]) >= 10) {
460                 newmailcount = extract_int(&aaa[4], 9);
461                 if ((oldmailcount >= 0) && (newmailcount > oldmailcount)) {
462                         color(BRIGHT_RED);
463                         scr_printf("*** You have new mail\n");
464                         color(DIM_WHITE);
465                 }
466                 oldmailcount = newmailcount;
467                 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city,
468                                 room_name, secure, newmailcount);
469         } else {
470                 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city,
471                                 room_name, secure, -1);
472         }
473 }
474
475 /* Goto next room having unread messages.
476  * We want to skip over rooms that the user has already been to, and take the
477  * user back to the lobby when done.  The room we end up in is placed in
478  * newroom - which is set to 0 (the lobby) initially.
479  */
480 void gotonext(void)
481 {
482         char buf[SIZ];
483         struct march *mptr, *mptr2;
484         char next_room[ROOMNAMELEN];
485
486         /* Check to see if the march-mode list is already allocated.
487          * If it is, pop the first room off the list and go there.
488          */
489         if (march == NULL) {
490                 serv_puts("LKRN");
491                 serv_gets(buf);
492                 if (buf[0] == '1')
493                         while (serv_gets(buf), strcmp(buf, "000")) {
494                                 mptr = (struct march *) malloc(sizeof(struct march));
495                                 mptr->next = NULL;
496                                 extract(mptr->march_name, buf, 0);
497                                 mptr->march_floor = (char) (extract_int(buf, 2) & 0x7F);
498                                 mptr->march_order = (char) (extract_int(buf, 3) & 0x7F);
499                                 if (march == NULL) {
500                                         march = mptr;
501                                 } else {
502                                         mptr2 = march;
503                                         while (mptr2->next != NULL)
504                                                 mptr2 = mptr2->next;
505                                         mptr2->next = mptr;
506                                 }
507                         }
508 /* add _BASEROOM_ to the end of the march list, so the user will end up
509  * in the system base room (usually the Lobby>) at the end of the loop
510  */
511                 mptr = (struct march *) malloc(sizeof(struct march));
512                 mptr->next = NULL;
513                 strcpy(mptr->march_name, "_BASEROOM_");
514                 if (march == NULL) {
515                         march = mptr;
516                 } else {
517                         mptr2 = march;
518                         while (mptr2->next != NULL)
519                                 mptr2 = mptr2->next;
520                         mptr2->next = mptr;
521                 }
522 /*
523  * ...and remove the room we're currently in, so a <G>oto doesn't make us
524  * walk around in circles
525  */
526                 remove_march(room_name, 0);
527         }
528         if (march != NULL) {
529                 strcpy(next_room, pop_march(curr_floor));
530         } else {
531                 strcpy(next_room, "_BASEROOM_");
532         }
533         remove_march(next_room, 0);
534         dotgoto(next_room, 1, 0);
535 }
536
537 /*
538  * forget all rooms on a given floor
539  */
540 void forget_all_rooms_on(int ffloor)
541 {
542         char buf[SIZ];
543         struct march *flist, *fptr;
544
545         scr_printf("Forgetting all rooms on %s...\r", &floorlist[ffloor][0]);
546         scr_flush();
547         snprintf(buf, sizeof buf, "LKRA %d", ffloor);
548         serv_puts(buf);
549         serv_gets(buf);
550         if (buf[0] != '1') {
551                 scr_printf("%-72s\n", &buf[4]);
552                 return;
553         }
554         flist = NULL;
555         while (serv_gets(buf), strcmp(buf, "000")) {
556                 fptr = (struct march *) malloc(sizeof(struct march));
557                 fptr->next = flist;
558                 flist = fptr;
559                 extract(fptr->march_name, buf, 0);
560         }
561         while (flist != NULL) {
562                 snprintf(buf, sizeof buf, "GOTO %s", flist->march_name);
563                 serv_puts(buf);
564                 serv_gets(buf);
565                 if (buf[0] == '2') {
566                         serv_puts("FORG");
567                         serv_gets(buf);
568                 }
569                 fptr = flist;
570                 flist = flist->next;
571                 free(fptr);
572         }
573         scr_printf("%-72s\r", "");
574 }
575
576
577 /*
578  * routine called by gotofloor() to move to a new room on a new floor
579  */
580 void gf_toroom(char *towhere, int mode)
581 {
582         int floor_being_left;
583
584         floor_being_left = curr_floor;
585
586         if (mode == GF_GOTO) {  /* <;G>oto mode */
587                 updatels();
588                 dotgoto(towhere, 1, 0);
589         }
590         if (mode == GF_SKIP) {  /* <;S>kip mode */
591                 dotgoto(towhere, 1, 0);
592                 remove_march("_FLOOR_", floor_being_left);
593         }
594         if (mode == GF_ZAP) {   /* <;Z>ap mode */
595                 dotgoto(towhere, 1, 0);
596                 remove_march("_FLOOR_", floor_being_left);
597                 forget_all_rooms_on(floor_being_left);
598         }
599 }
600
601
602 /*
603  * go to a new floor
604  */
605 void gotofloor(char *towhere, int mode)
606 {
607         int a, tofloor;
608         struct march *mptr;
609         char buf[SIZ], targ[SIZ];
610
611         if (floorlist[0][0] == 0)
612                 load_floorlist();
613         tofloor = (-1);
614         for (a = 0; a < 128; ++a)
615                 if (!strcasecmp(&floorlist[a][0], towhere))
616                         tofloor = a;
617
618         if (tofloor < 0) {
619                 for (a = 0; a < 128; ++a) {
620                         if (!strncasecmp(&floorlist[a][0], towhere, strlen(towhere))) {
621                                 tofloor = a;
622                         }
623                 }
624         }
625         if (tofloor < 0) {
626                 for (a = 0; a < 128; ++a)
627                         if (pattern(towhere, &floorlist[a][0]) > 0)
628                                 tofloor = a;
629         }
630         if (tofloor < 0) {
631                 scr_printf("No floor '%s'.\n", towhere);
632                 return;
633         }
634         for (mptr = march; mptr != NULL; mptr = mptr->next) {
635                 if ((mptr->march_floor) == tofloor)
636                         gf_toroom(mptr->march_name, mode);
637                 return;
638         }
639
640         strcpy(targ, "");
641         snprintf(buf, sizeof buf, "LKRA %d", tofloor);
642         serv_puts(buf);
643         serv_gets(buf);
644         if (buf[0] == '1')
645                 while (serv_gets(buf), strcmp(buf, "000")) {
646                         if ((extract_int(buf, 2) == tofloor) && (strlen(targ) == 0))
647                                 extract(targ, buf, 0);
648                 }
649         if (strlen(targ) > 0) {
650                 gf_toroom(targ, mode);
651         } else {
652                 scr_printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
653         }
654 }
655
656
657 /*
658  * forget all rooms on current floor
659  */
660 void forget_this_floor(void)
661 {
662
663         if (curr_floor == 0) {
664                 scr_printf("Can't forget this floor.\n");
665                 return;
666         }
667         if (floorlist[0][0] == 0)
668                 load_floorlist();
669         scr_printf("Are you sure you want to forget all rooms on %s? ",
670                &floorlist[(int) curr_floor][0]);
671         if (yesno() == 0)
672                 return;
673
674         gf_toroom("_BASEROOM_", GF_ZAP);
675 }
676
677
678 /* 
679  * Figure out the physical screen dimensions, if we can
680  * WARNING:  this is now called from a signal handler!
681  */
682 void check_screen_dims(void)
683 {
684 #ifdef TIOCGWINSZ
685         struct {
686                 unsigned short height;  /* rows */
687                 unsigned short width;   /* columns */
688                 unsigned short xpixels;
689                 unsigned short ypixels;         /* pixels */
690         } xwinsz;
691
692         if (scr_set_windowsize())
693                 return;
694
695         if (have_xterm) {       /* dynamically size screen if on an xterm */
696                 if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
697                         if (xwinsz.height)
698                                 screenheight = (int) xwinsz.height;
699                         if (xwinsz.width)
700                                 screenwidth = (int) xwinsz.width;
701                 }
702         }
703 #endif
704 }
705
706
707 /*
708  * set floor mode depending on client, server, and user settings
709  */
710 void set_floor_mode(void)
711 {
712         if (serv_info.serv_ok_floors == 0) {
713                 floor_mode = 0; /* Don't use floors if the server */
714         }
715         /* doesn't support them!          */
716         else {
717                 if (rc_floor_mode == RC_NO) {   /* never use floors */
718                         floor_mode = 0;
719                 }
720                 if (rc_floor_mode == RC_YES) {  /* always use floors */
721                         floor_mode = 1;
722                 }
723                 if (rc_floor_mode == RC_DEFAULT) {      /* user choice */
724                         floor_mode = ((userflags & US_FLOORS) ? 1 : 0);
725                 }
726         }
727 }
728
729 /*
730  * Set or change the user's password
731  */
732 int set_password(void)
733 {
734         char pass1[20];
735         char pass2[20];
736         char buf[SIZ];
737
738         if (strlen(rc_password) > 0) {
739                 strcpy(pass1, rc_password);
740                 strcpy(pass2, rc_password);
741         } else {
742                 IFNEXPERT formout("changepw");
743                 newprompt("Enter a new password: ", pass1, -19);
744                 newprompt("Enter it again to confirm: ", pass2, -19);
745         }
746         strproc(pass1);
747         strproc(pass2);
748         if (!strcasecmp(pass1, pass2)) {
749                 snprintf(buf, sizeof buf, "SETP %s", pass1);
750                 serv_puts(buf);
751                 serv_gets(buf);
752                 scr_printf("%s\n", &buf[4]);
753                 offer_to_remember_password(hostbuf, portbuf, fullname, pass1);
754                 return (0);
755         } else {
756                 scr_printf("*** They don't match... try again.\n");
757                 return (1);
758         }
759 }
760
761
762
763 /*
764  * get info about the server we've connected to
765  */
766 void get_serv_info(char *supplied_hostname)
767 {
768         char buf[512];
769
770         CtdlInternalGetServInfo(&serv_info);
771
772         /* be nice and identify ourself to the server */
773         snprintf(buf, sizeof buf, "IDEN %d|%d|%d|%s|",
774                  SERVER_TYPE, 0, REV_LEVEL,
775                  (server_is_local ? "local" : CITADEL));
776
777         /* Append a hostname */
778         if (supplied_hostname != NULL) {
779                 strcat(buf, supplied_hostname);
780         }
781         else {
782                 locate_host(&buf[strlen(buf)]); /* append to the end */
783         }
784
785         serv_puts(buf);
786         serv_gets(buf);         /* we don't care about the result code */
787 }
788
789
790
791
792
793 /*
794  * Display list of users currently logged on to the server
795  */
796 void who_is_online(int longlist)
797 {
798         char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ];
799         char flags[SIZ];
800         char actual_user[SIZ], actual_room[SIZ], actual_host[SIZ];
801         char tbuf[SIZ], clientsoft[SIZ];
802         time_t timenow = 0;
803         time_t idletime, idlehours, idlemins, idlesecs;
804         int last_session = (-1);
805
806         serv_puts("TIME");
807         serv_gets(tbuf);
808         if (tbuf[0] == '2') {
809                 timenow = extract_long(&tbuf[4], 0);
810         }
811         else {
812                 time(&timenow);
813         }
814
815         if (!longlist) {
816                 color(BRIGHT_WHITE);
817                 pprintf("FLG ###        User Name                 Room                 From host\n");
818                 color(DIM_WHITE);
819                 pprintf("--- --- ------------------------- -------------------- ------------------------\n");
820         }
821         serv_puts("RWHO");
822         serv_gets(buf);
823         if (buf[0] == '1') {
824                 while (serv_gets(buf), strcmp(buf, "000")) {
825                         extract(username, buf, 1);
826                         extract(roomname, buf, 2);
827                         extract(fromhost, buf, 3);
828                         extract(clientsoft, buf, 4);
829                         extract(flags, buf, 7);
830
831                         idletime = timenow - extract_long(buf, 5);
832                         idlehours = idletime / 3600;
833                         idlemins = (idletime - (idlehours * 3600)) / 60;
834                         idlesecs = (idletime - (idlehours * 3600) - (idlemins * 60));
835
836                         if (idletime > 900) {
837                                 while (strlen(roomname) < 20) {
838                                         strcat(roomname, " ");
839                                 }
840                                 strcpy(&roomname[14], "[idle]");
841                         }
842
843                         if (longlist) {
844
845                                 extract(actual_user, buf, 8);
846                                 extract(actual_room, buf, 9);
847                                 extract(actual_host, buf, 10);
848
849                                 pprintf("  Flags: %s\n", flags);
850                                 pprintf("Session: %d\n", extract_int(buf, 0));
851                                 pprintf("   Name: %s\n", username);
852                                 pprintf("In room: %s\n", roomname);
853                                 pprintf("   Host: %s\n", fromhost);
854                                 pprintf(" Client: %s\n", clientsoft);
855                                 pprintf("   Idle: %ld:%02ld:%02ld\n",
856                                         (long) idlehours,
857                                         (long) idlemins,
858                                         (long) idlesecs);
859
860                                 if ( (strlen(actual_user)+strlen(actual_room)+strlen(actual_host)) > 0) {
861                                         pprintf("(really ");
862                                         if (strlen(actual_user)>0) pprintf("<%s> ", actual_user);
863                                         if (strlen(actual_room)>0) pprintf("in <%s> ", actual_room);
864                                         if (strlen(actual_host)>0) pprintf("from <%s> ", actual_host);
865                                         pprintf(")\n");
866                                 }
867                                 pprintf("\n");
868
869                         } else {
870                                 if (extract_int(buf, 0) == last_session) {
871                                         pprintf("        ");
872                                 } else {
873                                         color(BRIGHT_MAGENTA);
874                                         pprintf("%-3s ", flags);
875                                         color(DIM_WHITE);
876                                         pprintf("%-3d ", extract_int(buf, 0));
877                                 }
878                                 last_session = extract_int(buf, 0);
879                                 color(BRIGHT_CYAN);
880                                 pprintf("%-25s ", username);
881                                 color(BRIGHT_MAGENTA);
882                                 roomname[20] = 0;
883                                 pprintf("%-20s ", roomname);
884                                 color(BRIGHT_CYAN);
885                                 fromhost[24] = '\0';
886                                 pprintf("%-24s\n", fromhost);
887                                 color(DIM_WHITE);
888                         }
889                 }
890         }
891 }
892
893 void enternew(char *desc, char *buf, int maxlen)
894 {
895         char bbb[128];
896         snprintf(bbb, sizeof bbb, "Enter in your new %s: ", desc);
897         newprompt(bbb, buf, maxlen);
898 }
899
900
901
902 int shift(int argc, char **argv, int start, int count) {
903         int i;
904
905         for (i=start; i<(argc-count); ++i) {
906                 argv[i] = argv[i+count];
907         }
908         argc = argc - count;
909         return argc;
910 }
911
912 /*
913  * main
914  */
915 int main(int argc, char **argv)
916 {
917         int a, b, mcmd;
918         char aaa[100], bbb[100];/* general purpose variables */
919         char argbuf[32];        /* command line buf */
920         char nonce[NONCE_SIZE];
921         char *telnet_client_host = NULL;
922         char *sptr, *sptr2;     /* USed to extract the nonce */
923         char hexstring[MD5_HEXSTRING_SIZE];
924         int stored_password = 0;
925         char password[SIZ];
926         
927         /* Permissions sanity check - don't run citadel setuid/setgid */
928         if (getuid() != geteuid()) {
929                 err_printf("Please do not run citadel setuid!\n");
930                 logoff(3);
931         } else if (getgid() != getegid()) {
932                 err_printf("Please do not run citadel setgid!\n");
933                 logoff(3);
934         }
935
936         sttybbs(SB_SAVE);       /* Store the old terminal parameters */
937         load_command_set();     /* parse the citadel.rc file */
938         sttybbs(SB_NO_INTR);    /* Install the new ones */
939         signal(SIGHUP, dropcarr);       /* Cleanup gracefully if carrier is dropped */
940         signal(SIGTERM, dropcarr);      /* Cleanup gracefully if terminated */
941         signal(SIGCONT, catch_sigcont);         /* Catch SIGCONT so we can reset terminal */
942
943         arg_encrypt = RC_DEFAULT;
944 #ifdef HAVE_CURSES_H
945         arg_screen = RC_DEFAULT;
946 #endif
947
948         /* 
949          * Handle command line options as if we were called like /bin/login
950          * (i.e. from in.telnetd)
951          */
952         for (a=0; a<argc; ++a) {
953                 if ((argc > a+1) && (!strcmp(argv[a], "-h")) ) {
954                         telnet_client_host = argv[a+1];
955                         argc = shift(argc, argv, a, 2);
956                 }
957                 if (!strcmp(argv[a], "-x")) {
958                         arg_encrypt = RC_NO;
959                         argc = shift(argc, argv, a, 1);
960                 }
961                 if (!strcmp(argv[a], "-X")) {
962                         arg_encrypt = RC_YES;
963                         argc = shift(argc, argv, a, 1);
964                 }
965                 if (!strcmp(argv[a], "-s")) {
966 #ifdef HAVE_CURSES_H
967                         arg_screen = RC_NO;
968 #endif
969                         argc = shift(argc, argv, a, 1);
970                 }
971                 if (!strcmp(argv[a], "-S")) {
972 #ifdef HAVE_CURSES_H
973                         arg_screen = RC_YES;
974 #endif
975                         argc = shift(argc, argv, a, 1);
976                 }
977                 if (!strcmp(argv[a], "-p")) {
978                         struct stat st;
979                 
980                         if (chdir(BBSDIR) < 0) {
981                                 perror("can't change to " BBSDIR);
982                                 logoff(3);
983                         }
984
985                         /*
986                          * Drop privileges if necessary. We stat
987                          * citadel.config to get the uid/gid since it's
988                          * guaranteed to have the uid/gid we want.
989                          */
990                         if (!getuid() || !getgid()) {
991                                 if (stat(BBSDIR "/citadel.config", &st) < 0) {
992                                         perror("couldn't stat citadel.config");
993                                         logoff(3);
994                                 }
995                                 if (!getgid() && (setgid(st.st_gid) < 0)) {
996                                         perror("couldn't change gid");
997                                         logoff(3);
998                                 }
999                                 if (!getuid() && (setuid(st.st_uid) < 0)) {
1000                                         perror("couldn't change uid");
1001                                         logoff(3);
1002                                 }
1003                                 /*
1004                                 scr_printf("Privileges changed to uid %d gid %d\n",
1005                                                 getuid(), getgid());
1006                                 */
1007                         }
1008                         argc = shift(argc, argv, a, 1);
1009                 }
1010         }
1011
1012         screen_new();
1013
1014         sln_printf("Attaching to server... \r");
1015         sln_flush();
1016         attach_to_server(argc, argv, hostbuf, portbuf);
1017
1018         serv_gets(aaa);
1019         if (aaa[0] != '2') {
1020                 scr_printf("%s\n", &aaa[4]);
1021                 logoff(atoi(aaa));
1022         }
1023
1024 /* If there is a [nonce] at the end, put the nonce in <nonce>, else nonce
1025  * is zeroized.
1026  */
1027         
1028         if ((sptr = strchr(aaa, '<')) == NULL)
1029         {
1030            nonce[0] = '\0';
1031         }
1032         else
1033         {
1034            if ((sptr2 = strchr(sptr, '>')) == NULL)
1035            {
1036               nonce[0] = '\0';
1037            }
1038            else
1039            {
1040               sptr2++;
1041               *sptr2 = '\0';
1042               strncpy(nonce, sptr, NONCE_SIZE);
1043            }
1044         }
1045
1046         get_serv_info(telnet_client_host);
1047
1048         scr_printf("%-24s\n%s\n%s\n", serv_info.serv_software, serv_info.serv_humannode,
1049                 serv_info.serv_bbs_city);
1050         scr_flush();
1051
1052         secure = starttls();
1053         status_line(serv_info.serv_humannode, serv_info.serv_bbs_city, NULL,
1054                         secure, -1);
1055
1056         screenwidth = 80;       /* default screen dimensions */
1057         screenheight = 24;
1058         
1059         scr_printf(" pause    next    stop\n");
1060         scr_printf(" ctrl-s  ctrl-o  ctrl-c\n\n");
1061         formout("hello");       /* print the opening greeting */
1062         scr_printf("\n");
1063
1064 GSTA:   /* See if we have a username and password on disk */
1065         if (rc_remember_passwords) {
1066                 get_stored_password(hostbuf, portbuf, fullname, password);
1067                 if (strlen(fullname) > 0) {
1068                         snprintf(aaa, sizeof(aaa)-1, "USER %s", fullname);
1069                         serv_puts(aaa);
1070                         serv_gets(aaa);
1071                         if (nonce[0])
1072                         {
1073                                 sprintf(aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring));
1074                         }
1075                         else    /* Else no APOP */
1076                         {
1077                                 snprintf(aaa, sizeof(aaa)-1, "PASS %s", password);
1078                         }
1079                         
1080                         serv_puts(aaa);
1081                         serv_gets(aaa);
1082                         if (aaa[0] == '2') {
1083                                 load_user_info(&aaa[4]);
1084                                 stored_password = 1;
1085                                 goto PWOK;
1086                         }
1087                         else {
1088                                 set_stored_password(hostbuf, portbuf, "", "");
1089                         }
1090                 }
1091         }
1092
1093         termn8 = 0;
1094         newnow = 0;
1095         do {
1096                 if (strlen(rc_username) > 0) {
1097                         strcpy(fullname, rc_username);
1098                 } else {
1099                         newprompt("Enter your name: ", fullname, 29);
1100                 }
1101                 strproc(fullname);
1102                 if (!strcasecmp(fullname, "new")) {     /* just in case */
1103                         scr_printf("Please enter the name you wish to log in with.\n");
1104                 }
1105         } while (
1106                         (!strcasecmp(fullname, "bbs"))
1107                         || (!strcasecmp(fullname, "new"))
1108                         || (strlen(fullname) == 0));
1109
1110         if (!strcasecmp(fullname, "off")) {
1111                 mcmd = 29;
1112                 goto TERMN8;
1113         }
1114         /* sign on to the server */
1115         snprintf(aaa, sizeof aaa, "USER %s", fullname);
1116         serv_puts(aaa);
1117         serv_gets(aaa);
1118         if (aaa[0] != '3')
1119                 goto NEWUSR;
1120
1121         /* password authentication */
1122         if (strlen(rc_password) > 0) {
1123                 strcpy(password, rc_password);
1124         } else {
1125                 newprompt("\rPlease enter your password: ", password, -19);
1126         }
1127         strproc(password);
1128
1129         if (nonce[0])
1130         {
1131                 sprintf(aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring));
1132         }
1133         else    /* Else no APOP */
1134         {
1135                         snprintf(aaa, sizeof(aaa)-1, "PASS %s", password);
1136         }
1137         
1138         serv_puts(aaa);
1139         serv_gets(aaa);
1140         if (aaa[0] == '2') {
1141                 load_user_info(&aaa[4]);
1142                 offer_to_remember_password(hostbuf, portbuf,
1143                                         fullname, password);
1144                 goto PWOK;
1145         }
1146         scr_printf("<< wrong password >>\n");
1147         if (strlen(rc_password) > 0)
1148                 logoff(0);
1149         goto GSTA;
1150
1151 NEWUSR: if (strlen(rc_password) == 0) {
1152                 scr_printf("No record. Enter as new user? ");
1153                 if (yesno() == 0)
1154                         goto GSTA;
1155         }
1156         snprintf(aaa, sizeof aaa, "NEWU %s", fullname);
1157         serv_puts(aaa);
1158         serv_gets(aaa);
1159         if (aaa[0] != '2') {
1160                 scr_printf("%s\n", aaa);
1161                 goto GSTA;
1162         }
1163         load_user_info(&aaa[4]);
1164
1165         while (set_password() != 0);;
1166         newnow = 1;
1167
1168         enter_config(1);
1169
1170 PWOK:
1171         /* Switch color support on or off if we're in user mode */
1172         if (rc_ansi_color == 3) {
1173                 if (userflags & US_COLOR)
1174                         enable_color = 1;
1175                 else
1176                         enable_color = 0;
1177         }
1178
1179         scr_printf("%s\nAccess level: %d (%s)\n"
1180                 "User #%ld / Login #%d",
1181                 fullname, axlevel, axdefs[(int) axlevel],
1182                 usernum, timescalled);
1183         if (lastcall > 0L) {
1184                 scr_printf(" / Last login: %s\n",
1185                         asctime(localtime(&lastcall)) );
1186         }
1187         scr_printf("\n");
1188
1189         serv_puts("CHEK");
1190         serv_gets(aaa);
1191         if (aaa[0] == '2') {
1192                 b = extract_int(&aaa[4], 0);
1193                 if (b > 0) {
1194                         color(BRIGHT_RED);
1195                         if (b == 1)
1196                                 scr_printf("*** You have a new private message in Mail>\n");
1197                         if (b > 1)
1198                                 scr_printf("*** You have %d new private messages in Mail>\n", b);
1199                         color(DIM_WHITE);
1200                 }
1201                 if ((axlevel >= 6) && (extract_int(&aaa[4], 2) > 0)) {
1202                         scr_printf("*** Users need validation\n");
1203                 }
1204                 if (extract_int(&aaa[4], 1) > 0) {
1205                         scr_printf("*** Please register.\n");
1206                         formout("register");
1207                         entregis();
1208                 }
1209         }
1210         /* Make up some temporary filenames for use in various parts of the
1211          * program.  Don't mess with these once they've been set, because we
1212          * will be unlinking them later on in the program and we don't
1213          * want to delete something that we didn't create. */
1214         snprintf(temp, sizeof temp, tmpnam(NULL));
1215         snprintf(temp2, sizeof temp2, tmpnam(NULL));
1216         snprintf(tempdir, sizeof tempdir, tmpnam(NULL));
1217
1218         /* Get screen dimensions.  First we go to a default of 80x24.  Then
1219          * we try to get the user's actual screen dimensions off the server.
1220          * However, if we're running on an xterm, all this stuff is
1221          * irrelevant because we're going to dynamically size the screen
1222          * during the session.
1223          */
1224         screenwidth = 80;
1225         screenheight = 24;
1226         serv_puts("GETU");
1227         serv_gets(aaa);
1228         if (aaa[0] == '2') {
1229                 screenwidth = extract_int(&aaa[4], 0);
1230                 screenheight = extract_int(&aaa[4], 1);
1231         }
1232         if (getenv("TERM") != NULL)
1233                 if (!strcmp(getenv("TERM"), "xterm")) {
1234                         have_xterm = 1;
1235                 }
1236 #ifdef TIOCGWINSZ
1237         check_screen_dims();
1238 #endif
1239
1240         set_floor_mode();
1241
1242
1243         /* Enter the lobby */
1244         dotgoto("_BASEROOM_", 1, 0);
1245
1246 /* Main loop for the system... user is logged in. */
1247     uglistsize = 0;
1248
1249         if (newnow == 1)
1250                 readmsgs(3, 1, 5);
1251         else
1252                 readmsgs(1, 1, 0);
1253
1254         /* MAIN COMMAND LOOP */
1255         do {
1256                 mcmd = getcmd(argbuf);          /* Get keyboard command */
1257
1258 #ifdef TIOCGWINSZ
1259                 check_screen_dims();            /* if xterm, get screen size */
1260 #endif
1261
1262                 if (termn8 == 0)
1263                         switch (mcmd) {
1264                         case 1:
1265                                 formout("help");
1266                                 break;
1267                         case 4:
1268                                 entmsg(0, 0);
1269                                 break;
1270                         case 36:
1271                                 entmsg(0, 1);
1272                                 break;
1273                         case 46:
1274                                 entmsg(0, 2);
1275                                 break;
1276                         case 78:
1277                                 newprompt("What do you want your username to be? ", aaa, 32);
1278                                 snprintf(bbb, sizeof bbb, "ENT0 2|0|0|0|%s", aaa);
1279                                 serv_puts(bbb);
1280                                 serv_gets(aaa);
1281                                 if (strncmp("200", aaa, 3))
1282                                         scr_printf("\n%s\n", aaa);
1283                                 else
1284                                         entmsg(0, 0);
1285                                 break;
1286                         case 5:
1287                                 updatels();
1288                                 gotonext();
1289                                 break;
1290                         case 47:
1291                                 if (!rc_alt_semantics)
1292                                         updatelsa();
1293                                 gotonext();
1294                                 break;
1295                         case 90:
1296                                 if (!rc_alt_semantics)
1297                                         updatelsa();
1298                                 dotgoto(argbuf, 0, 0);
1299                                 break;
1300                         case 58:
1301                                 updatelsa();
1302                                 dotgoto("_MAIL_", 1, 0);
1303                                 break;
1304                         case 20:
1305                                 updatels();
1306                                 dotgoto(argbuf, 0, 0);
1307                                 break;
1308                         case 52:
1309                                 if (rc_alt_semantics)
1310                                         updatelsa();
1311                                 dotgoto(argbuf, 0, 0);
1312                                 break;
1313                         case 10:
1314                                 readmsgs(0, 1, 0);
1315                                 break;
1316                         case 9:
1317                                 readmsgs(3, 1, 5);
1318                                 break;
1319                         case 13:
1320                                 readmsgs(1, 1, 0);
1321                                 break;
1322                         case 11:
1323                                 readmsgs(0, (-1), 0);
1324                                 break;
1325                         case 12:
1326                                 readmsgs(2, (-1), 0);
1327                                 break;
1328                         case 71:
1329                                 readmsgs(3, 1, atoi(argbuf));
1330                                 break;
1331                         case 7:
1332                                 forget();
1333                                 break;
1334                         case 18:
1335                                 subshell();
1336                                 break;
1337                         case 38:
1338                                 updatels();
1339                                 entroom();
1340                                 break;
1341                         case 22:
1342                                 killroom();
1343                                 break;
1344                         case 32:
1345                                 userlist(argbuf);
1346                                 break;
1347                         case 27:
1348                                 invite();
1349                                 break;
1350                         case 28:
1351                                 kickout();
1352                                 break;
1353                         case 23:
1354                                 editthisroom();
1355                                 break;
1356                         case 14:
1357                                 roomdir();
1358                                 break;
1359                         case 33:
1360                                 download(0);
1361                                 break;
1362                         case 34:
1363                                 download(1);
1364                                 break;
1365                         case 31:
1366                                 download(2);
1367                                 break;
1368                         case 43:
1369                                 download(3);
1370                                 break;
1371                         case 45:
1372                                 download(4);
1373                                 break;
1374                         case 55:
1375                                 download(5);
1376                                 break;
1377                         case 39:
1378                                 upload(0);
1379                                 break;
1380                         case 40:
1381                                 upload(1);
1382                                 break;
1383                         case 42:
1384                                 upload(2);
1385                                 break;
1386                         case 44:
1387                                 upload(3);
1388                                 break;
1389                         case 57:
1390                                 cli_upload();
1391                                 break;
1392                         case 16:
1393                                 ungoto();
1394                                 break;
1395                         case 24:
1396                                 whoknows();
1397                                 break;
1398                         case 26:
1399                                 validate();
1400                                 break;
1401                         case 29:
1402                                 if (!rc_alt_semantics)
1403                                         updatels();
1404                                 termn8 = 1;
1405                                 break;
1406                         case 30:
1407                                 if (!rc_alt_semantics)
1408                                         updatels();
1409                                 termn8 = 1;
1410                                 break;
1411                         case 48:
1412                                 enterinfo();
1413                                 break;
1414                         case 49:
1415                                 readinfo();
1416                                 break;
1417                         case 72:
1418                                 cli_image_upload("_userpic_");
1419                                 break;
1420                         case 73:
1421                                 cli_image_upload("_roompic_");
1422                                 break;
1423
1424                         case 74:
1425                                 snprintf(aaa, sizeof aaa, "_floorpic_|%d", curr_floor);
1426                                 cli_image_upload(aaa);
1427                                 break;
1428
1429                         case 75:
1430                                 enternew("roomname", aaa, 20);
1431                                 snprintf(bbb, sizeof bbb, "RCHG %s", aaa);
1432                                 serv_puts(bbb);
1433                                 serv_gets(aaa);
1434                                 if (strncmp("200", aaa, 3))
1435                                         scr_printf("\n%s\n", aaa);
1436                                 break;
1437                         case 76:
1438                                 enternew("hostname", aaa, 25);
1439                                 snprintf(bbb, sizeof bbb, "HCHG %s", aaa);
1440                                 serv_puts(bbb);
1441                                 serv_gets(aaa);
1442                                 if (strncmp("200", aaa, 3))
1443                                         scr_printf("\n%s\n", aaa);
1444                                 break;
1445                         case 77:
1446                                 enternew("username", aaa, 32);
1447                                 snprintf(bbb, sizeof bbb, "UCHG %s", aaa);
1448                                 serv_puts(bbb);
1449                                 serv_gets(aaa);
1450                                 if (strncmp("200", aaa, 3))
1451                                         scr_printf("\n%s\n", aaa);
1452                                 break;
1453
1454                         case 35:
1455                                 set_password();
1456                                 break;
1457
1458                         case 21:
1459                                 if (argbuf[0] == 0)
1460                                         strcpy(aaa, "?");
1461                                 display_help(argbuf);
1462                                 break;
1463
1464                         case 41:
1465                                 formout("register");
1466                                 entregis();
1467                                 break;
1468
1469                         case 15:
1470                                 scr_printf("Are you sure (y/n)? ");
1471                                 if (yesno() == 1) {
1472                                         updatels();
1473                                         a = 0;
1474                                         termn8 = 1;
1475                                 }
1476                                 break;
1477
1478                         case 85:
1479                                 scr_printf("All users will be disconnected!  "
1480                                         "Really terminate the server? ");
1481                                 if (yesno() == 1) {
1482                                         serv_puts("DOWN");
1483                                         serv_gets(aaa);
1484                                         scr_printf("%s\n", &aaa[4]);
1485                                         if (aaa[0]=='2') {
1486                                                 updatels();
1487                                                 a = 0;
1488                                                 termn8 = 1;
1489                                         }
1490                                 }
1491                                 break;
1492
1493                         case 86:
1494                                 scr_printf("Do you really want to schedule a "
1495                                         "server shutdown? ");
1496                                 if (yesno() == 1) {
1497                                         serv_puts("SCDN 1");
1498                                         serv_gets(aaa);
1499                                         if (aaa[0]=='2') {
1500                                                 if (atoi(&aaa[4])) {
1501                                                         scr_printf(
1502 "The Citadel server will terminate when all users are logged off.\n"
1503                                                                 );
1504                                                 }
1505                                                 else {
1506                                                         scr_printf(
1507 "The Citadel server will not terminate.\n"
1508                                                                 );
1509                                                 }
1510                                         }
1511                                 }
1512                                 break;
1513
1514                         case 87:
1515                                 network_config_management("listrecp",
1516                                         "Mailing list recipients");
1517                                 break;
1518
1519                         case 89:
1520                                 network_config_management("ignet_push_share",
1521                                         "Nodes with which we share this room");
1522                                 break;
1523
1524                         case 88:
1525                                 do_ignet_configuration();
1526                                 break;
1527
1528                         case 6:
1529                                 if (rc_alt_semantics)
1530                                         updatelsa();
1531                                 gotonext();
1532                                 break;
1533
1534                         case 3:
1535                                 chatmode();
1536                                 break;
1537
1538                         case 2:
1539                                 if (server_is_local) {
1540                                         screen_reset();
1541                                         sttybbs(SB_RESTORE);
1542                                         snprintf(aaa, sizeof aaa, "USERNAME=\042%s\042; export USERNAME;"
1543                                                  "exec ./subsystem %ld %d %d", fullname,
1544                                           usernum, screenwidth, axlevel);
1545                                         ka_system(aaa);
1546                                         sttybbs(SB_NO_INTR);
1547                                         screen_set();
1548                                 } else {
1549                                         scr_printf("*** Can't run doors when server is not local.\n");
1550                                 }
1551                                 break;
1552
1553                         case 17:
1554                                 who_is_online(0);
1555                                 break;
1556
1557                         case 79:
1558                                 who_is_online(1);
1559                                 break;
1560
1561                         case 80:
1562                                 do_system_configuration();
1563                                 break;
1564
1565                         case 82:
1566                                 do_internet_configuration();
1567                                 break;
1568
1569                         case 83:
1570                                 check_message_base();
1571                                 break;
1572
1573                         case 84:
1574                                 quiet_mode();
1575                                 break;
1576
1577                         case 50:
1578                                 enter_config(2);
1579                                 break;
1580
1581                         case 37:
1582                                 enter_config(0);
1583                                 set_floor_mode();
1584                                 break;
1585
1586                         case 59:
1587                                 enter_config(3);
1588                                 set_floor_mode();
1589                                 break;
1590
1591                         case 60:
1592                                 gotofloor(argbuf, GF_GOTO);
1593                                 break;
1594
1595                         case 61:
1596                                 gotofloor(argbuf, GF_SKIP);
1597                                 break;
1598
1599                         case 62:
1600                                 forget_this_floor();
1601                                 break;
1602
1603                         case 63:
1604                                 create_floor();
1605                                 break;
1606
1607                         case 64:
1608                                 edit_floor();
1609                                 break;
1610
1611                         case 65:
1612                                 kill_floor();
1613                                 break;
1614
1615                         case 66:
1616                                 enter_bio();
1617                                 break;
1618
1619                         case 67:
1620                                 read_bio();
1621                                 break;
1622
1623                         case 25:
1624                                 edituser();
1625                                 break;
1626
1627                         case 8:
1628                                 knrooms(floor_mode);
1629                                 scr_printf("\n");
1630                                 break;
1631
1632                         case 68:
1633                                 knrooms(2);
1634                                 scr_printf("\n");
1635                                 break;
1636
1637                         case 69:
1638                                 misc_server_cmd(argbuf);
1639                                 break;
1640
1641                         case 70:
1642                                 edit_system_message(argbuf);
1643                                 break;
1644
1645                         case 19:
1646                                 listzrooms();
1647                                 scr_printf("\n");
1648                                 break;
1649
1650                         case 51:
1651                                 deletefile();
1652                                 break;
1653
1654                         case 53:
1655                                 netsendfile();
1656                                 break;
1657
1658                         case 54:
1659                                 movefile();
1660                                 break;
1661
1662                         case 56:
1663                                 page_user();
1664                                 break;
1665
1666                         }       /* end switch */
1667         } while (termn8 == 0);
1668
1669 TERMN8: scr_printf("%s logged out.\n", fullname);
1670         while (march != NULL) {
1671                 remove_march(march->march_name, 0);
1672         }
1673         if (mcmd == 30) {
1674                 sln_printf("\n\nType 'off' to disconnect, or next user...\n");
1675         }
1676         snprintf(aaa, sizeof aaa, "LOUT");
1677         serv_puts(aaa);
1678         serv_gets(aaa);
1679         screen_delete();
1680         sttybbs(SB_RESTORE);
1681         if ((mcmd == 29) || (mcmd == 15)) {
1682                 formout("goodbye");
1683                 logoff(0);
1684         }
1685         goto GSTA;
1686
1687 }       /* end main() */