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