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