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