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