removed all references to sprintf from several files (not all files yet)
[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     int skipidle = 0;
806     
807     if (longlist == 2)
808       {
809         longlist = 0;
810         skipidle = 1;
811       }
812
813         serv_puts("TIME");
814         serv_gets(tbuf);
815         if (tbuf[0] == '2') {
816                 timenow = extract_long(&tbuf[4], 0);
817         }
818         else {
819                 time(&timenow);
820         }
821
822         if (!longlist) {
823                 color(BRIGHT_WHITE);
824                 pprintf("FLG ###        User Name                 Room                 From host\n");
825                 color(DIM_WHITE);
826                 pprintf("--- --- ------------------------- -------------------- ------------------------\n");
827         }
828         serv_puts("RWHO");
829         serv_gets(buf);
830         if (buf[0] == '1') {
831                 while (serv_gets(buf), strcmp(buf, "000")) {
832                 int isidle = 0;
833                         extract(username, buf, 1);
834                         extract(roomname, buf, 2);
835                         extract(fromhost, buf, 3);
836                         extract(clientsoft, buf, 4);
837                         extract(flags, buf, 7);
838
839                         idletime = timenow - extract_long(buf, 5);
840                         idlehours = idletime / 3600;
841                         idlemins = (idletime - (idlehours * 3600)) / 60;
842                         idlesecs = (idletime - (idlehours * 3600) - (idlemins * 60));
843
844                         if (idletime > 900) {
845                                 while (strlen(roomname) < 20) {
846                                         strcat(roomname, " ");
847                                 }
848                                 strcpy(&roomname[14], "[idle]");
849                         if (skipidle)
850                   isidle = 1;
851                         }
852
853                         if (longlist) {
854
855                                 extract(actual_user, buf, 8);
856                                 extract(actual_room, buf, 9);
857                                 extract(actual_host, buf, 10);
858
859                                 pprintf("  Flags: %s\n", flags);
860                                 pprintf("Session: %d\n", extract_int(buf, 0));
861                                 pprintf("   Name: %s\n", username);
862                                 pprintf("In room: %s\n", roomname);
863                                 pprintf("   Host: %s\n", fromhost);
864                                 pprintf(" Client: %s\n", clientsoft);
865                                 pprintf("   Idle: %ld:%02ld:%02ld\n",
866                                         (long) idlehours,
867                                         (long) idlemins,
868                                         (long) idlesecs);
869
870                                 if ( (strlen(actual_user)+strlen(actual_room)+strlen(actual_host)) > 0) {
871                                         pprintf("(really ");
872                                         if (strlen(actual_user)>0) pprintf("<%s> ", actual_user);
873                                         if (strlen(actual_room)>0) pprintf("in <%s> ", actual_room);
874                                         if (strlen(actual_host)>0) pprintf("from <%s> ", actual_host);
875                                         pprintf(")\n");
876                                 }
877                                 pprintf("\n");
878
879                         } else {
880                     if (isidle == 0) {
881                                 if (extract_int(buf, 0) == last_session) {
882                                         pprintf("        ");
883                                 } else {
884                                         color(BRIGHT_MAGENTA);
885                                         pprintf("%-3s ", flags);
886                                         color(DIM_WHITE);
887                                         pprintf("%-3d ", extract_int(buf, 0));
888                                 }
889                                 last_session = extract_int(buf, 0);
890                                 color(BRIGHT_CYAN);
891                                 pprintf("%-25s ", username);
892                                 color(BRIGHT_MAGENTA);
893                                 roomname[20] = 0;
894                                 pprintf("%-20s ", roomname);
895                                 color(BRIGHT_CYAN);
896                                 fromhost[24] = '\0';
897                                 pprintf("%-24s\n", fromhost);
898                                 color(DIM_WHITE);
899                         }
900                         }
901                 }
902         }
903 }
904
905 void enternew(char *desc, char *buf, int maxlen)
906 {
907         char bbb[128];
908         snprintf(bbb, sizeof bbb, "Enter in your new %s: ", desc);
909         newprompt(bbb, buf, maxlen);
910 }
911
912
913
914 int shift(int argc, char **argv, int start, int count) {
915         int i;
916
917         for (i=start; i<(argc-count); ++i) {
918                 argv[i] = argv[i+count];
919         }
920         argc = argc - count;
921         return argc;
922 }
923
924 /*
925  * main
926  */
927 int main(int argc, char **argv)
928 {
929         int a, b, mcmd;
930         char aaa[100], bbb[100];/* general purpose variables */
931         char argbuf[32];        /* command line buf */
932         char nonce[NONCE_SIZE];
933         char *telnet_client_host = NULL;
934         char *sptr, *sptr2;     /* USed to extract the nonce */
935         char hexstring[MD5_HEXSTRING_SIZE];
936         int stored_password = 0;
937         char password[SIZ];
938         
939         /* Permissions sanity check - don't run citadel setuid/setgid */
940         if (getuid() != geteuid()) {
941                 err_printf("Please do not run citadel setuid!\n");
942                 logoff(3);
943         } else if (getgid() != getegid()) {
944                 err_printf("Please do not run citadel setgid!\n");
945                 logoff(3);
946         }
947
948         sttybbs(SB_SAVE);       /* Store the old terminal parameters */
949         load_command_set();     /* parse the citadel.rc file */
950         sttybbs(SB_NO_INTR);    /* Install the new ones */
951         signal(SIGHUP, dropcarr);       /* Cleanup gracefully if carrier is dropped */
952         signal(SIGTERM, dropcarr);      /* Cleanup gracefully if terminated */
953         signal(SIGCONT, catch_sigcont);         /* Catch SIGCONT so we can reset terminal */
954
955 #ifdef HAVE_OPENSSL
956         arg_encrypt = RC_DEFAULT;
957 #endif
958 #ifdef HAVE_CURSES_H
959         arg_screen = RC_DEFAULT;
960 #endif
961
962         /* 
963          * Handle command line options as if we were called like /bin/login
964          * (i.e. from in.telnetd)
965          */
966         for (a=0; a<argc; ++a) {
967                 if ((argc > a+1) && (!strcmp(argv[a], "-h")) ) {
968                         telnet_client_host = argv[a+1];
969                         argc = shift(argc, argv, a, 2);
970                 }
971                 if (!strcmp(argv[a], "-x")) {
972 #ifdef HAVE_OPENSSL
973                         arg_encrypt = RC_NO;
974 #endif
975                         argc = shift(argc, argv, a, 1);
976                 }
977                 if (!strcmp(argv[a], "-X")) {
978 #ifdef HAVE_OPENSSL
979                         arg_encrypt = RC_YES;
980                         argc = shift(argc, argv, a, 1);
981 #else
982                         fprintf(stderr, "Not compiled with encryption support");
983                         return 1;
984 #endif
985                 }
986                 if (!strcmp(argv[a], "-s")) {
987 #ifdef HAVE_CURSES_H
988                         arg_screen = RC_NO;
989 #endif
990                         argc = shift(argc, argv, a, 1);
991                 }
992                 if (!strcmp(argv[a], "-S")) {
993 #ifdef HAVE_CURSES_H
994                         arg_screen = RC_YES;
995 #endif
996                         argc = shift(argc, argv, a, 1);
997                 }
998                 if (!strcmp(argv[a], "-p")) {
999                         struct stat st;
1000                 
1001                         if (chdir(BBSDIR) < 0) {
1002                                 perror("can't change to " BBSDIR);
1003                                 logoff(3);
1004                         }
1005
1006                         /*
1007                          * Drop privileges if necessary. We stat
1008                          * citadel.config to get the uid/gid since it's
1009                          * guaranteed to have the uid/gid we want.
1010                          */
1011                         if (!getuid() || !getgid()) {
1012                                 if (stat(BBSDIR "/citadel.config", &st) < 0) {
1013                                         perror("couldn't stat citadel.config");
1014                                         logoff(3);
1015                                 }
1016                                 if (!getgid() && (setgid(st.st_gid) < 0)) {
1017                                         perror("couldn't change gid");
1018                                         logoff(3);
1019                                 }
1020                                 if (!getuid() && (setuid(st.st_uid) < 0)) {
1021                                         perror("couldn't change uid");
1022                                         logoff(3);
1023                                 }
1024                                 /*
1025                                 scr_printf("Privileges changed to uid %d gid %d\n",
1026                                                 getuid(), getgid());
1027                                 */
1028                         }
1029                         argc = shift(argc, argv, a, 1);
1030                 }
1031         }
1032
1033         screen_new();
1034
1035         sln_printf("Attaching to server... \r");
1036         sln_flush();
1037         attach_to_server(argc, argv, hostbuf, portbuf);
1038
1039         serv_gets(aaa);
1040         if (aaa[0] != '2') {
1041                 scr_printf("%s\n", &aaa[4]);
1042                 logoff(atoi(aaa));
1043         }
1044
1045 /* If there is a [nonce] at the end, put the nonce in <nonce>, else nonce
1046  * is zeroized.
1047  */
1048         
1049         if ((sptr = strchr(aaa, '<')) == NULL)
1050         {
1051            nonce[0] = '\0';
1052         }
1053         else
1054         {
1055            if ((sptr2 = strchr(sptr, '>')) == NULL)
1056            {
1057               nonce[0] = '\0';
1058            }
1059            else
1060            {
1061               sptr2++;
1062               *sptr2 = '\0';
1063               strncpy(nonce, sptr, NONCE_SIZE);
1064            }
1065         }
1066
1067         get_serv_info(telnet_client_host);
1068
1069         scr_printf("%-24s\n%s\n%s\n", serv_info.serv_software, serv_info.serv_humannode,
1070                 serv_info.serv_bbs_city);
1071         scr_flush();
1072
1073         secure = starttls();
1074         status_line(serv_info.serv_humannode, serv_info.serv_bbs_city, NULL,
1075                         secure, -1);
1076
1077         screenwidth = 80;       /* default screen dimensions */
1078         screenheight = 24;
1079         
1080         scr_printf(" pause    next    stop\n");
1081         scr_printf(" ctrl-s  ctrl-o  ctrl-c\n\n");
1082         formout("hello");       /* print the opening greeting */
1083         scr_printf("\n");
1084
1085 GSTA:   /* See if we have a username and password on disk */
1086         if (rc_remember_passwords) {
1087                 get_stored_password(hostbuf, portbuf, fullname, password);
1088                 if (strlen(fullname) > 0) {
1089                         snprintf(aaa, sizeof(aaa)-1, "USER %s", fullname);
1090                         serv_puts(aaa);
1091                         serv_gets(aaa);
1092                         if (nonce[0])
1093                         {
1094                                 snprintf(aaa, sizeof aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring, sizeof hexstring));
1095                         }
1096                         else    /* Else no APOP */
1097                         {
1098                                 snprintf(aaa, sizeof(aaa)-1, "PASS %s", password);
1099                         }
1100                         
1101                         serv_puts(aaa);
1102                         serv_gets(aaa);
1103                         if (aaa[0] == '2') {
1104                                 load_user_info(&aaa[4]);
1105                                 stored_password = 1;
1106                                 goto PWOK;
1107                         }
1108                         else {
1109                                 set_stored_password(hostbuf, portbuf, "", "");
1110                         }
1111                 }
1112         }
1113
1114         termn8 = 0;
1115         newnow = 0;
1116         do {
1117                 if (strlen(rc_username) > 0) {
1118                         strcpy(fullname, rc_username);
1119                 } else {
1120                         newprompt("Enter your name: ", fullname, 29);
1121                 }
1122                 strproc(fullname);
1123                 if (!strcasecmp(fullname, "new")) {     /* just in case */
1124                         scr_printf("Please enter the name you wish to log in with.\n");
1125                 }
1126         } while (
1127                         (!strcasecmp(fullname, "bbs"))
1128                         || (!strcasecmp(fullname, "new"))
1129                         || (strlen(fullname) == 0));
1130
1131         if (!strcasecmp(fullname, "off")) {
1132                 mcmd = 29;
1133                 goto TERMN8;
1134         }
1135         /* sign on to the server */
1136         snprintf(aaa, sizeof aaa, "USER %s", fullname);
1137         serv_puts(aaa);
1138         serv_gets(aaa);
1139         if (aaa[0] != '3')
1140                 goto NEWUSR;
1141
1142         /* password authentication */
1143         if (strlen(rc_password) > 0) {
1144                 strcpy(password, rc_password);
1145         } else {
1146                 newprompt("\rPlease enter your password: ", password, -19);
1147         }
1148         strproc(password);
1149
1150         if (nonce[0])
1151         {
1152                 snprintf(aaa, sizeof aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring, sizeof hexstring));
1153         }
1154         else    /* Else no APOP */
1155         {
1156                 snprintf(aaa, sizeof aaa, "PASS %s", password);
1157         }
1158         
1159         serv_puts(aaa);
1160         serv_gets(aaa);
1161         if (aaa[0] == '2') {
1162                 load_user_info(&aaa[4]);
1163                 offer_to_remember_password(hostbuf, portbuf,
1164                                         fullname, password);
1165                 goto PWOK;
1166         }
1167         scr_printf("<< wrong password >>\n");
1168         if (strlen(rc_password) > 0)
1169                 logoff(0);
1170         goto GSTA;
1171
1172 NEWUSR: if (strlen(rc_password) == 0) {
1173                 scr_printf("No record. Enter as new user? ");
1174                 if (yesno() == 0)
1175                         goto GSTA;
1176         }
1177         snprintf(aaa, sizeof aaa, "NEWU %s", fullname);
1178         serv_puts(aaa);
1179         serv_gets(aaa);
1180         if (aaa[0] != '2') {
1181                 scr_printf("%s\n", aaa);
1182                 goto GSTA;
1183         }
1184         load_user_info(&aaa[4]);
1185
1186         while (set_password() != 0);;
1187         newnow = 1;
1188
1189         enter_config(1);
1190
1191 PWOK:
1192         /* Switch color support on or off if we're in user mode */
1193         if (rc_ansi_color == 3) {
1194                 if (userflags & US_COLOR)
1195                         enable_color = 1;
1196                 else
1197                         enable_color = 0;
1198         }
1199
1200         scr_printf("%s\nAccess level: %d (%s)\n"
1201                 "User #%ld / Login #%d",
1202                 fullname, axlevel, axdefs[(int) axlevel],
1203                 usernum, timescalled);
1204         if (lastcall > 0L) {
1205                 scr_printf(" / Last login: %s\n",
1206                         asctime(localtime(&lastcall)) );
1207         }
1208         scr_printf("\n");
1209
1210         serv_puts("CHEK");
1211         serv_gets(aaa);
1212         if (aaa[0] == '2') {
1213                 b = extract_int(&aaa[4], 0);
1214                 if (b > 0) {
1215                         color(BRIGHT_RED);
1216                         if (b == 1)
1217                                 scr_printf("*** You have a new private message in Mail>\n");
1218                         if (b > 1)
1219                                 scr_printf("*** You have %d new private messages in Mail>\n", b);
1220                         color(DIM_WHITE);
1221                 }
1222                 if ((axlevel >= 6) && (extract_int(&aaa[4], 2) > 0)) {
1223                         scr_printf("*** Users need validation\n");
1224                 }
1225                 if (extract_int(&aaa[4], 1) > 0) {
1226                         scr_printf("*** Please register.\n");
1227                         formout("register");
1228                         entregis();
1229                 }
1230         }
1231         /* Make up some temporary filenames for use in various parts of the
1232          * program.  Don't mess with these once they've been set, because we
1233          * will be unlinking them later on in the program and we don't
1234          * want to delete something that we didn't create. */
1235         snprintf(temp, sizeof temp, tmpnam(NULL));
1236         snprintf(temp2, sizeof temp2, tmpnam(NULL));
1237         snprintf(tempdir, sizeof tempdir, tmpnam(NULL));
1238
1239         /* Get screen dimensions.  First we go to a default of 80x24.  Then
1240          * we try to get the user's actual screen dimensions off the server.
1241          * However, if we're running on an xterm, all this stuff is
1242          * irrelevant because we're going to dynamically size the screen
1243          * during the session.
1244          */
1245         screenwidth = 80;
1246         screenheight = 24;
1247         serv_puts("GETU");
1248         serv_gets(aaa);
1249         if (aaa[0] == '2') {
1250                 screenwidth = extract_int(&aaa[4], 0);
1251                 screenheight = extract_int(&aaa[4], 1);
1252         }
1253         if (getenv("TERM") != NULL)
1254                 if (!strcmp(getenv("TERM"), "xterm")) {
1255                         have_xterm = 1;
1256                 }
1257 #ifdef TIOCGWINSZ
1258         check_screen_dims();
1259 #endif
1260
1261         set_floor_mode();
1262
1263
1264         /* Enter the lobby */
1265         dotgoto("_BASEROOM_", 1, 0);
1266
1267 /* Main loop for the system... user is logged in. */
1268     uglistsize = 0;
1269
1270         if (newnow == 1)
1271                 readmsgs(3, 1, 5);
1272         else
1273                 readmsgs(1, 1, 0);
1274
1275         /* MAIN COMMAND LOOP */
1276         do {
1277                 mcmd = getcmd(argbuf);          /* Get keyboard command */
1278
1279 #ifdef TIOCGWINSZ
1280                 check_screen_dims();            /* if xterm, get screen size */
1281 #endif
1282
1283                 if (termn8 == 0)
1284                         switch (mcmd) {
1285                         case 1:
1286                                 formout("help");
1287                                 break;
1288                         case 4:
1289                                 entmsg(0, 0);
1290                                 break;
1291                         case 36:
1292                                 entmsg(0, 1);
1293                                 break;
1294                         case 46:
1295                                 entmsg(0, 2);
1296                                 break;
1297                         case 78:
1298                                 newprompt("What do you want your username to be? ", aaa, 32);
1299                                 snprintf(bbb, sizeof bbb, "ENT0 2|0|0|0|%s", aaa);
1300                                 serv_puts(bbb);
1301                                 serv_gets(aaa);
1302                                 if (strncmp("200", aaa, 3))
1303                                         scr_printf("\n%s\n", aaa);
1304                                 else
1305                                         entmsg(0, 0);
1306                                 break;
1307                         case 5:
1308                                 updatels();
1309                                 gotonext();
1310                                 break;
1311                         case 47:
1312                                 if (!rc_alt_semantics)
1313                                         updatelsa();
1314                                 gotonext();
1315                                 break;
1316                         case 90:
1317                                 if (!rc_alt_semantics)
1318                                         updatelsa();
1319                                 dotgoto(argbuf, 0, 0);
1320                                 break;
1321                         case 58:
1322                                 updatelsa();
1323                                 dotgoto("_MAIL_", 1, 0);
1324                                 break;
1325                         case 20:
1326                                 updatels();
1327                                 dotgoto(argbuf, 0, 0);
1328                                 break;
1329                         case 52:
1330                                 if (rc_alt_semantics)
1331                                         updatelsa();
1332                                 dotgoto(argbuf, 0, 0);
1333                                 break;
1334                         case 10:
1335                                 readmsgs(0, 1, 0);
1336                                 break;
1337                         case 9:
1338                                 readmsgs(3, 1, 5);
1339                                 break;
1340                         case 13:
1341                                 readmsgs(1, 1, 0);
1342                                 break;
1343                         case 11:
1344                                 readmsgs(0, (-1), 0);
1345                                 break;
1346                         case 12:
1347                                 readmsgs(2, (-1), 0);
1348                                 break;
1349                         case 71:
1350                                 readmsgs(3, 1, atoi(argbuf));
1351                                 break;
1352                         case 7:
1353                                 forget();
1354                                 break;
1355                         case 18:
1356                                 subshell();
1357                                 break;
1358                         case 38:
1359                                 updatels();
1360                                 entroom();
1361                                 break;
1362                         case 22:
1363                                 killroom();
1364                                 break;
1365                         case 32:
1366                                 userlist(argbuf);
1367                                 break;
1368                         case 27:
1369                                 invite();
1370                                 break;
1371                         case 28:
1372                                 kickout();
1373                                 break;
1374                         case 23:
1375                                 editthisroom();
1376                                 break;
1377                         case 14:
1378                                 roomdir();
1379                                 break;
1380                         case 33:
1381                                 download(0);
1382                                 break;
1383                         case 34:
1384                                 download(1);
1385                                 break;
1386                         case 31:
1387                                 download(2);
1388                                 break;
1389                         case 43:
1390                                 download(3);
1391                                 break;
1392                         case 45:
1393                                 download(4);
1394                                 break;
1395                         case 55:
1396                                 download(5);
1397                                 break;
1398                         case 39:
1399                                 upload(0);
1400                                 break;
1401                         case 40:
1402                                 upload(1);
1403                                 break;
1404                         case 42:
1405                                 upload(2);
1406                                 break;
1407                         case 44:
1408                                 upload(3);
1409                                 break;
1410                         case 57:
1411                                 cli_upload();
1412                                 break;
1413                         case 16:
1414                                 ungoto();
1415                                 break;
1416                         case 24:
1417                                 whoknows();
1418                                 break;
1419                         case 26:
1420                                 validate();
1421                                 break;
1422                         case 29:
1423                                 if (!rc_alt_semantics)
1424                                         updatels();
1425                                 termn8 = 1;
1426                                 break;
1427                         case 30:
1428                                 if (!rc_alt_semantics)
1429                                         updatels();
1430                                 termn8 = 1;
1431                                 break;
1432                         case 48:
1433                                 enterinfo();
1434                                 break;
1435                         case 49:
1436                                 readinfo();
1437                                 break;
1438                         case 72:
1439                                 cli_image_upload("_userpic_");
1440                                 break;
1441                         case 73:
1442                                 cli_image_upload("_roompic_");
1443                                 break;
1444
1445                         case 74:
1446                                 snprintf(aaa, sizeof aaa, "_floorpic_|%d", curr_floor);
1447                                 cli_image_upload(aaa);
1448                                 break;
1449
1450                         case 75:
1451                                 enternew("roomname", aaa, 20);
1452                                 snprintf(bbb, sizeof bbb, "RCHG %s", aaa);
1453                                 serv_puts(bbb);
1454                                 serv_gets(aaa);
1455                                 if (strncmp("200", aaa, 3))
1456                                         scr_printf("\n%s\n", aaa);
1457                                 break;
1458                         case 76:
1459                                 enternew("hostname", aaa, 25);
1460                                 snprintf(bbb, sizeof bbb, "HCHG %s", aaa);
1461                                 serv_puts(bbb);
1462                                 serv_gets(aaa);
1463                                 if (strncmp("200", aaa, 3))
1464                                         scr_printf("\n%s\n", aaa);
1465                                 break;
1466                         case 77:
1467                                 enternew("username", aaa, 32);
1468                                 snprintf(bbb, sizeof bbb, "UCHG %s", aaa);
1469                                 serv_puts(bbb);
1470                                 serv_gets(aaa);
1471                                 if (strncmp("200", aaa, 3))
1472                                         scr_printf("\n%s\n", aaa);
1473                                 break;
1474
1475                         case 35:
1476                                 set_password();
1477                                 break;
1478
1479                         case 21:
1480                                 if (argbuf[0] == 0)
1481                                         strcpy(aaa, "?");
1482                                 display_help(argbuf);
1483                                 break;
1484
1485                         case 41:
1486                                 formout("register");
1487                                 entregis();
1488                                 break;
1489
1490                         case 15:
1491                                 scr_printf("Are you sure (y/n)? ");
1492                                 if (yesno() == 1) {
1493                                         updatels();
1494                                         a = 0;
1495                                         termn8 = 1;
1496                                 }
1497                                 break;
1498
1499                         case 85:
1500                                 scr_printf("All users will be disconnected!  "
1501                                         "Really terminate the server? ");
1502                                 if (yesno() == 1) {
1503                                         serv_puts("DOWN");
1504                                         serv_gets(aaa);
1505                                         scr_printf("%s\n", &aaa[4]);
1506                                         if (aaa[0]=='2') {
1507                                                 updatels();
1508                                                 a = 0;
1509                                                 termn8 = 1;
1510                                         }
1511                                 }
1512                                 break;
1513
1514                         case 86:
1515                                 scr_printf("Do you really want to schedule a "
1516                                         "server shutdown? ");
1517                                 if (yesno() == 1) {
1518                                         serv_puts("SCDN 1");
1519                                         serv_gets(aaa);
1520                                         if (aaa[0]=='2') {
1521                                                 if (atoi(&aaa[4])) {
1522                                                         scr_printf(
1523 "The Citadel server will terminate when all users are logged off.\n"
1524                                                                 );
1525                                                 }
1526                                                 else {
1527                                                         scr_printf(
1528 "The Citadel server will not terminate.\n"
1529                                                                 );
1530                                                 }
1531                                         }
1532                                 }
1533                                 break;
1534
1535                         case 87:
1536                                 network_config_management("listrecp",
1537                                         "Mailing list recipients");
1538                                 break;
1539
1540                         case 89:
1541                                 network_config_management("ignet_push_share",
1542                                         "Nodes with which we share this room");
1543                                 break;
1544
1545                         case 88:
1546                                 do_ignet_configuration();
1547                                 break;
1548
1549                         case 92:
1550                                 do_filterlist_configuration();
1551                                 break;
1552
1553                         case 6:
1554                                 if (rc_alt_semantics)
1555                                         updatelsa();
1556                                 gotonext();
1557                                 break;
1558
1559                         case 3:
1560                                 chatmode();
1561                                 break;
1562
1563                         case 2:
1564                                 if (server_is_local) {
1565                                         screen_reset();
1566                                         sttybbs(SB_RESTORE);
1567                                         snprintf(aaa, sizeof aaa, "USERNAME=\042%s\042; export USERNAME;"
1568                                                  "exec ./subsystem %ld %d %d", fullname,
1569                                           usernum, screenwidth, axlevel);
1570                                         ka_system(aaa);
1571                                         sttybbs(SB_NO_INTR);
1572                                         screen_set();
1573                                 } else {
1574                                         scr_printf("*** Can't run doors when server is not local.\n");
1575                                 }
1576                                 break;
1577
1578                         case 17:
1579                                 who_is_online(0);
1580                                 break;
1581
1582                         case 79:
1583                                 who_is_online(1);
1584                                 break;
1585
1586             case 91:
1587                 who_is_online(2);
1588                 break;
1589                 
1590                         case 80:
1591                                 do_system_configuration();
1592                                 break;
1593
1594                         case 82:
1595                                 do_internet_configuration();
1596                                 break;
1597
1598                         case 83:
1599                                 check_message_base();
1600                                 break;
1601
1602                         case 84:
1603                                 quiet_mode();
1604                                 break;
1605
1606                         case 50:
1607                                 enter_config(2);
1608                                 break;
1609
1610                         case 37:
1611                                 enter_config(0);
1612                                 set_floor_mode();
1613                                 break;
1614
1615                         case 59:
1616                                 enter_config(3);
1617                                 set_floor_mode();
1618                                 break;
1619
1620                         case 60:
1621                                 gotofloor(argbuf, GF_GOTO);
1622                                 break;
1623
1624                         case 61:
1625                                 gotofloor(argbuf, GF_SKIP);
1626                                 break;
1627
1628                         case 62:
1629                                 forget_this_floor();
1630                                 break;
1631
1632                         case 63:
1633                                 create_floor();
1634                                 break;
1635
1636                         case 64:
1637                                 edit_floor();
1638                                 break;
1639
1640                         case 65:
1641                                 kill_floor();
1642                                 break;
1643
1644                         case 66:
1645                                 enter_bio();
1646                                 break;
1647
1648                         case 67:
1649                                 read_bio();
1650                                 break;
1651
1652                         case 25:
1653                                 edituser();
1654                                 break;
1655
1656                         case 8:
1657                                 knrooms(floor_mode);
1658                                 scr_printf("\n");
1659                                 break;
1660
1661                         case 68:
1662                                 knrooms(2);
1663                                 scr_printf("\n");
1664                                 break;
1665
1666                         case 69:
1667                                 misc_server_cmd(argbuf);
1668                                 break;
1669
1670                         case 70:
1671                                 edit_system_message(argbuf);
1672                                 break;
1673
1674                         case 19:
1675                                 listzrooms();
1676                                 scr_printf("\n");
1677                                 break;
1678
1679                         case 51:
1680                                 deletefile();
1681                                 break;
1682
1683                         case 53:
1684                                 netsendfile();
1685                                 break;
1686
1687                         case 54:
1688                                 movefile();
1689                                 break;
1690
1691                         case 56:
1692                                 page_user();
1693                                 break;
1694
1695                         }       /* end switch */
1696         } while (termn8 == 0);
1697
1698 TERMN8: scr_printf("%s logged out.\n", fullname);
1699         while (march != NULL) {
1700                 remove_march(march->march_name, 0);
1701         }
1702         if (mcmd == 30) {
1703                 sln_printf("\n\nType 'off' to disconnect, or next user...\n");
1704         }
1705         snprintf(aaa, sizeof aaa, "LOUT");
1706         serv_puts(aaa);
1707         serv_gets(aaa);
1708         screen_delete();
1709         sttybbs(SB_RESTORE);
1710         if ((mcmd == 29) || (mcmd == 15)) {
1711                 formout("goodbye");
1712                 logoff(0);
1713         }
1714         goto GSTA;
1715
1716 }       /* end main() */