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