4 * Main source module for the client program.
15 #if TIME_WITH_SYS_TIME
16 # include <sys/time.h>
20 # include <sys/time.h>
27 #include <sys/types.h>
30 #include <sys/ioctl.h>
38 #include "serv_info.h"
40 #include "routines2.h"
45 #include "client_chat.h"
46 #include "client_passwords.h"
47 #include "citadel_decls.h"
50 #include "client_crypto.h"
60 char march_name[ROOMNAMELEN];
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)
70 struct march *march = NULL;
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);
81 struct CtdlServInfo serv_info; /* Info on the server connected */
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. */
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 */
95 long usernum = 0L; /* user number */
96 time_t lastcall = 0L; /* Date/time of previous login */
98 long highest_msg_read; /* used for <A>bandon room cmd */
99 long maxmsgnum; /* used for <G>oto */
101 char have_xterm = 0; /* are we running on an xterm? */
102 char rc_username[32];
103 char rc_password[32];
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 */
114 extern int rc_ansi_color; /* ansi color value from citadel.rc */
115 extern int next_lazy_cmd;
118 * here is our 'clean up gracefully and exit' routine
120 void logoff(int code)
123 if (editor_pid > 0) { /* kill the editor if it's running */
124 kill(editor_pid, SIGHUP);
127 /* Free the ungoto list */
128 for (lp = 0; lp < uglistsize; lp++)
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
138 * now clean up various things
147 /* Violently kill off any child processes if Citadel is
150 if (getppid() == 1) {
151 kill(0 - getpgrp(), SIGTERM);
153 kill(0 - getpgrp(), SIGKILL);
155 sttybbs(SB_RESTORE); /* return the old terminal settings */
156 exit(code); /* exit with the proper exit code */
162 * signal catching function for hangups...
164 void dropcarr(int signum)
172 * catch SIGCONT to reset terminal modes when were are put back into the
175 void catch_sigcont(int signum)
178 signal(SIGCONT, catch_sigcont);
183 /* general purpose routines */
185 void formout(char *name)
186 { /* display a file */
188 snprintf(cmd, sizeof cmd, "MESG %s", name);
192 scr_printf("%s\n", &cmd[4]);
195 fmout(screenwidth, NULL, NULL,
196 ((userflags & US_PAGINATOR) ? 1 : 0),
201 void userlist(char *patn)
211 pprintf("%s\n", &buf[4]);
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) {
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 ",
228 (tmbuf->tm_year + 1900));
229 pprintf("%5ld %5ld\n", extract_long(buf, 4), extract_long(buf, 5));
239 * grab assorted info about the user...
241 void load_user_info(char *params)
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);
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.
258 void remove_march(char *roomname, int floornum)
260 struct march *mptr, *mptr2;
265 if ((!strcasecmp(march->march_name, roomname))
266 || ((!strcasecmp(roomname, "_FLOOR_")) && (march->march_floor == floornum))) {
273 for (mptr = march; mptr != NULL; mptr = mptr->next) {
275 if ((!strcasecmp(mptr->march_name, roomname))
276 || ((!strcasecmp(roomname, "_FLOOR_"))
277 && (mptr->march_floor == floornum))) {
279 mptr2->next = mptr->next;
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.
293 char *pop_march(int desired_floor)
295 static char TheRoom[ROOMNAMELEN];
297 int TheOrder = 32767;
300 struct march *mptr = NULL;
302 strcpy(TheRoom, "_BASEROOM_");
306 for (mptr = march; mptr != NULL; mptr = mptr->next) {
308 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
309 weight = weight + 10000;
310 if (mptr->march_floor == desired_floor)
311 weight = weight + 5000;
313 weight = weight + ((128 - (mptr->march_floor)) * 128);
314 weight = weight + (128 - (mptr->march_order));
316 if (weight > TheWeight) {
318 strcpy(TheRoom, mptr->march_name);
319 TheFloor = mptr->march_floor;
320 TheOrder = mptr->march_order;
328 * jump directly to a room
330 void dotgoto(char *towhere, int display_name, int fromungoto)
332 char aaa[SIZ], bbb[SIZ], psearch[SIZ];
334 int newmailcount = 0;
335 int partial_match, best_match;
337 int ugpos = uglistsize;
339 /* store ungoto information */
342 if (uglistsize >= (UGLISTLEN-1))
343 { /* sloppy slide them all down, hey it's the client, who cares. :-) */
346 for (lp = 0; lp < (UGLISTLEN-1); lp++)
348 uglist[lp] = uglist[lp+1];
349 uglistlsn[lp] = uglistlsn[lp+1];
356 uglist[ugpos] = malloc(strlen(room_name)+1);
357 strcpy(uglist[ugpos], room_name);
358 uglistlsn[ugpos] = ls;
361 /* first try an exact match */
362 snprintf(aaa, sizeof aaa, "GOTO %s", towhere);
367 if (!strncmp(aaa, "54", 2)) {
368 newprompt("Enter room password: ", bbb, 9);
369 snprintf(aaa, sizeof aaa, "GOTO %s|%s", towhere, bbb);
375 if (!strncmp(aaa, "54", 2)) {
376 scr_printf("Wrong password.\n");
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.
391 while (serv_gets(aaa), strcmp(aaa, "000")) {
392 extract(psearch, aaa, 0);
394 if (pattern(psearch, towhere) >= 0) {
397 if (!strncasecmp(towhere, psearch, strlen(towhere))) {
400 if (partial_match > best_match) {
401 strcpy(bbb, psearch);
402 best_match = partial_match;
405 if (strlen(bbb) == 0) {
406 scr_printf("No room '%s'.\n", towhere);
409 snprintf(aaa, sizeof aaa, "GOTO %s", bbb);
416 scr_printf("%s\n", aaa);
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);
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)
432 scr_printf("(Entering floor: %s)\n", &floorlist[(int) curr_floor][0]);
434 if (display_name == 1) {
436 scr_printf("%s ", room_name);
440 if (display_name != 2) {
441 color(BRIGHT_YELLOW);
442 scr_printf("%d ", extract_int(&aaa[4], 1));
444 scr_printf("new of ");
445 color(BRIGHT_YELLOW);
446 scr_printf("%d ", extract_int(&aaa[4], 2));
448 scr_printf("messages.\n");
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);
456 /* read info file if necessary */
457 if (extract_int(&aaa[4], 3) > 0)
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) {
465 scr_printf("*** You have new mail\n");
468 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city,
469 room_name, secure, newmailcount);
471 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city,
472 room_name, secure, -1);
476 /* Goto next room having unread messages.
477 * We want to skip over rooms that the user has already been to, and take the
478 * user back to the lobby when done. The room we end up in is placed in
479 * newroom - which is set to 0 (the lobby) initially.
484 struct march *mptr, *mptr2;
485 char next_room[ROOMNAMELEN];
487 /* Check to see if the march-mode list is already allocated.
488 * If it is, pop the first room off the list and go there.
494 while (serv_gets(buf), strcmp(buf, "000")) {
495 mptr = (struct march *) malloc(sizeof(struct march));
497 extract(mptr->march_name, buf, 0);
498 mptr->march_floor = (char) (extract_int(buf, 2) & 0x7F);
499 mptr->march_order = (char) (extract_int(buf, 3) & 0x7F);
504 while (mptr2->next != NULL)
509 /* add _BASEROOM_ to the end of the march list, so the user will end up
510 * in the system base room (usually the Lobby>) at the end of the loop
512 mptr = (struct march *) malloc(sizeof(struct march));
514 strcpy(mptr->march_name, "_BASEROOM_");
519 while (mptr2->next != NULL)
524 * ...and remove the room we're currently in, so a <G>oto doesn't make us
525 * walk around in circles
527 remove_march(room_name, 0);
530 strcpy(next_room, pop_march(curr_floor));
532 strcpy(next_room, "_BASEROOM_");
534 remove_march(next_room, 0);
535 dotgoto(next_room, 1, 0);
539 * forget all rooms on a given floor
541 void forget_all_rooms_on(int ffloor)
544 struct march *flist, *fptr;
546 scr_printf("Forgetting all rooms on %s...\r", &floorlist[ffloor][0]);
548 snprintf(buf, sizeof buf, "LKRA %d", ffloor);
552 scr_printf("%-72s\n", &buf[4]);
556 while (serv_gets(buf), strcmp(buf, "000")) {
557 fptr = (struct march *) malloc(sizeof(struct march));
560 extract(fptr->march_name, buf, 0);
562 while (flist != NULL) {
563 snprintf(buf, sizeof buf, "GOTO %s", flist->march_name);
574 scr_printf("%-72s\r", "");
579 * routine called by gotofloor() to move to a new room on a new floor
581 void gf_toroom(char *towhere, int mode)
583 int floor_being_left;
585 floor_being_left = curr_floor;
587 if (mode == GF_GOTO) { /* <;G>oto mode */
589 dotgoto(towhere, 1, 0);
591 if (mode == GF_SKIP) { /* <;S>kip mode */
592 dotgoto(towhere, 1, 0);
593 remove_march("_FLOOR_", floor_being_left);
595 if (mode == GF_ZAP) { /* <;Z>ap mode */
596 dotgoto(towhere, 1, 0);
597 remove_march("_FLOOR_", floor_being_left);
598 forget_all_rooms_on(floor_being_left);
606 void gotofloor(char *towhere, int mode)
610 char buf[SIZ], targ[SIZ];
612 if (floorlist[0][0] == 0)
615 for (a = 0; a < 128; ++a)
616 if (!strcasecmp(&floorlist[a][0], towhere))
620 for (a = 0; a < 128; ++a) {
621 if (!strncasecmp(&floorlist[a][0], towhere, strlen(towhere))) {
627 for (a = 0; a < 128; ++a)
628 if (pattern(towhere, &floorlist[a][0]) > 0)
632 scr_printf("No floor '%s'.\n", towhere);
635 for (mptr = march; mptr != NULL; mptr = mptr->next) {
636 if ((mptr->march_floor) == tofloor)
637 gf_toroom(mptr->march_name, mode);
642 snprintf(buf, sizeof buf, "LKRA %d", tofloor);
646 while (serv_gets(buf), strcmp(buf, "000")) {
647 if ((extract_int(buf, 2) == tofloor) && (strlen(targ) == 0))
648 extract(targ, buf, 0);
650 if (strlen(targ) > 0) {
651 gf_toroom(targ, mode);
653 scr_printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
659 * forget all rooms on current floor
661 void forget_this_floor(void)
664 if (curr_floor == 0) {
665 scr_printf("Can't forget this floor.\n");
668 if (floorlist[0][0] == 0)
670 scr_printf("Are you sure you want to forget all rooms on %s? ",
671 &floorlist[(int) curr_floor][0]);
675 gf_toroom("_BASEROOM_", GF_ZAP);
680 * Figure out the physical screen dimensions, if we can
681 * WARNING: this is now called from a signal handler!
683 void check_screen_dims(void)
687 unsigned short height; /* rows */
688 unsigned short width; /* columns */
689 unsigned short xpixels;
690 unsigned short ypixels; /* pixels */
693 if (have_xterm) { /* dynamically size screen if on an xterm */
694 if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
696 screenheight = is_curses_enabled() ? (int)xwinsz.height - 1 : (int) xwinsz.height;
698 screenwidth = (int) xwinsz.width;
706 * set floor mode depending on client, server, and user settings
708 void set_floor_mode(void)
710 if (serv_info.serv_ok_floors == 0) {
711 floor_mode = 0; /* Don't use floors if the server */
713 /* doesn't support them! */
715 if (rc_floor_mode == RC_NO) { /* never use floors */
718 if (rc_floor_mode == RC_YES) { /* always use floors */
721 if (rc_floor_mode == RC_DEFAULT) { /* user choice */
722 floor_mode = ((userflags & US_FLOORS) ? 1 : 0);
728 * Set or change the user's password
730 int set_password(void)
736 if (strlen(rc_password) > 0) {
737 strcpy(pass1, rc_password);
738 strcpy(pass2, rc_password);
740 IFNEXPERT formout("changepw");
741 newprompt("Enter a new password: ", pass1, -19);
742 newprompt("Enter it again to confirm: ", pass2, -19);
746 if (!strcasecmp(pass1, pass2)) {
747 snprintf(buf, sizeof buf, "SETP %s", pass1);
750 scr_printf("%s\n", &buf[4]);
751 offer_to_remember_password(hostbuf, portbuf, fullname, pass1);
754 scr_printf("*** They don't match... try again.\n");
762 * get info about the server we've connected to
764 void get_serv_info(char *supplied_hostname)
768 CtdlInternalGetServInfo(&serv_info);
770 /* be nice and identify ourself to the server */
771 snprintf(buf, sizeof buf, "IDEN %d|%d|%d|%s|",
772 SERVER_TYPE, 0, REV_LEVEL,
773 (server_is_local ? "local" : CITADEL));
775 /* Append a hostname */
776 if (supplied_hostname != NULL) {
777 strcat(buf, supplied_hostname);
780 locate_host(&buf[strlen(buf)]); /* append to the end */
784 serv_gets(buf); /* we don't care about the result code */
792 * Display list of users currently logged on to the server
794 void who_is_online(int longlist)
796 char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ];
798 char actual_user[SIZ], actual_room[SIZ], actual_host[SIZ];
799 char tbuf[SIZ], clientsoft[SIZ];
801 time_t idletime, idlehours, idlemins, idlesecs;
802 int last_session = (-1);
813 if (tbuf[0] == '2') {
814 timenow = extract_long(&tbuf[4], 0);
822 pprintf("FLG ### User Name Room From host\n");
824 pprintf("--- --- ------------------------- -------------------- ------------------------\n");
829 while (serv_gets(buf), strcmp(buf, "000")) {
831 extract(username, buf, 1);
832 extract(roomname, buf, 2);
833 extract(fromhost, buf, 3);
834 extract(clientsoft, buf, 4);
835 extract(flags, buf, 7);
837 idletime = timenow - extract_long(buf, 5);
838 idlehours = idletime / 3600;
839 idlemins = (idletime - (idlehours * 3600)) / 60;
840 idlesecs = (idletime - (idlehours * 3600) - (idlemins * 60));
842 if (idletime > rc_idle_threshold) {
843 while (strlen(roomname) < 20) {
844 strcat(roomname, " ");
846 strcpy(&roomname[14], "[idle]");
853 extract(actual_user, buf, 8);
854 extract(actual_room, buf, 9);
855 extract(actual_host, buf, 10);
857 pprintf(" Flags: %s\n", flags);
858 pprintf("Session: %d\n", extract_int(buf, 0));
859 pprintf(" Name: %s\n", username);
860 pprintf("In room: %s\n", roomname);
861 pprintf(" Host: %s\n", fromhost);
862 pprintf(" Client: %s\n", clientsoft);
863 pprintf(" Idle: %ld:%02ld:%02ld\n",
868 if ( (strlen(actual_user)+strlen(actual_room)+strlen(actual_host)) > 0) {
870 if (strlen(actual_user)>0) pprintf("<%s> ", actual_user);
871 if (strlen(actual_room)>0) pprintf("in <%s> ", actual_room);
872 if (strlen(actual_host)>0) pprintf("from <%s> ", actual_host);
879 if (extract_int(buf, 0) == last_session) {
882 color(BRIGHT_MAGENTA);
883 pprintf("%-3s ", flags);
885 pprintf("%-3d ", extract_int(buf, 0));
887 last_session = extract_int(buf, 0);
889 pprintf("%-25s ", username);
890 color(BRIGHT_MAGENTA);
892 pprintf("%-20s ", roomname);
895 pprintf("%-24s\n", fromhost);
903 void enternew(char *desc, char *buf, int maxlen)
906 snprintf(bbb, sizeof bbb, "Enter in your new %s: ", desc);
907 newprompt(bbb, buf, maxlen);
912 int shift(int argc, char **argv, int start, int count) {
915 for (i=start; i<(argc-count); ++i) {
916 argv[i] = argv[i+count];
922 static void statusHook(char *s) {
930 int main(int argc, char **argv)
933 char aaa[100], bbb[100];/* general purpose variables */
934 char argbuf[32]; /* command line buf */
935 char nonce[NONCE_SIZE];
936 char *telnet_client_host = NULL;
937 char *sptr, *sptr2; /* USed to extract the nonce */
938 char hexstring[MD5_HEXSTRING_SIZE];
939 int stored_password = 0;
942 setIPCDeathHook(screen_delete);
943 setIPCErrorPrintf(err_printf);
944 setCryptoStatusHook(statusHook);
946 /* Permissions sanity check - don't run citadel setuid/setgid */
947 if (getuid() != geteuid()) {
948 err_printf("Please do not run citadel setuid!\n");
950 } else if (getgid() != getegid()) {
951 err_printf("Please do not run citadel setgid!\n");
955 sttybbs(SB_SAVE); /* Store the old terminal parameters */
956 load_command_set(); /* parse the citadel.rc file */
957 sttybbs(SB_NO_INTR); /* Install the new ones */
958 signal(SIGHUP, dropcarr); /* Cleanup gracefully if carrier is dropped */
959 signal(SIGTERM, dropcarr); /* Cleanup gracefully if terminated */
960 signal(SIGCONT, catch_sigcont); /* Catch SIGCONT so we can reset terminal */
962 signal(SIGWINCH, scr_winch); /* Window resize signal */
966 arg_encrypt = RC_DEFAULT;
969 arg_screen = RC_DEFAULT;
973 * Handle command line options as if we were called like /bin/login
974 * (i.e. from in.telnetd)
976 for (a=0; a<argc; ++a) {
977 if ((argc > a+1) && (!strcmp(argv[a], "-h")) ) {
978 telnet_client_host = argv[a+1];
979 argc = shift(argc, argv, a, 2);
981 if (!strcmp(argv[a], "-x")) {
985 argc = shift(argc, argv, a, 1);
987 if (!strcmp(argv[a], "-X")) {
989 arg_encrypt = RC_YES;
990 argc = shift(argc, argv, a, 1);
992 fprintf(stderr, "Not compiled with encryption support");
996 if (!strcmp(argv[a], "-s")) {
1000 argc = shift(argc, argv, a, 1);
1002 if (!strcmp(argv[a], "-S")) {
1003 #ifdef HAVE_CURSES_H
1004 arg_screen = RC_YES;
1006 argc = shift(argc, argv, a, 1);
1008 if (!strcmp(argv[a], "-p")) {
1011 if (chdir(BBSDIR) < 0) {
1012 perror("can't change to " BBSDIR);
1017 * Drop privileges if necessary. We stat
1018 * citadel.config to get the uid/gid since it's
1019 * guaranteed to have the uid/gid we want.
1021 if (!getuid() || !getgid()) {
1022 if (stat(BBSDIR "/citadel.config", &st) < 0) {
1023 perror("couldn't stat citadel.config");
1026 if (!getgid() && (setgid(st.st_gid) < 0)) {
1027 perror("couldn't change gid");
1030 if (!getuid() && (setuid(st.st_uid) < 0)) {
1031 perror("couldn't change uid");
1035 scr_printf("Privileges changed to uid %d gid %d\n",
1036 getuid(), getgid());
1039 argc = shift(argc, argv, a, 1);
1045 sln_printf("Attaching to server... \r");
1047 attach_to_server(argc, argv, hostbuf, portbuf);
1050 if (aaa[0] != '2') {
1051 scr_printf("%s\n", &aaa[4]);
1055 /* If there is a [nonce] at the end, put the nonce in <nonce>, else nonce
1059 if ((sptr = strchr(aaa, '<')) == NULL)
1065 if ((sptr2 = strchr(sptr, '>')) == NULL)
1073 strncpy(nonce, sptr, NONCE_SIZE);
1077 get_serv_info(telnet_client_host);
1079 scr_printf("%-24s\n%s\n%s\n", serv_info.serv_software, serv_info.serv_humannode,
1080 serv_info.serv_bbs_city);
1083 secure = starttls();
1084 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city, NULL,
1087 screenwidth = 80; /* default screen dimensions */
1090 scr_printf(" pause next stop\n");
1091 scr_printf(" ctrl-s ctrl-o ctrl-c\n\n");
1092 formout("hello"); /* print the opening greeting */
1095 GSTA: /* See if we have a username and password on disk */
1096 if (rc_remember_passwords) {
1097 get_stored_password(hostbuf, portbuf, fullname, password);
1098 if (strlen(fullname) > 0) {
1099 snprintf(aaa, sizeof(aaa)-1, "USER %s", fullname);
1104 snprintf(aaa, sizeof aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring, sizeof hexstring));
1106 else /* Else no APOP */
1108 snprintf(aaa, sizeof(aaa)-1, "PASS %s", password);
1113 if (aaa[0] == '2') {
1114 load_user_info(&aaa[4]);
1115 stored_password = 1;
1119 set_stored_password(hostbuf, portbuf, "", "");
1127 if (strlen(rc_username) > 0) {
1128 strcpy(fullname, rc_username);
1130 newprompt("Enter your name: ", fullname, 29);
1133 if (!strcasecmp(fullname, "new")) { /* just in case */
1134 scr_printf("Please enter the name you wish to log in with.\n");
1137 (!strcasecmp(fullname, "bbs"))
1138 || (!strcasecmp(fullname, "new"))
1139 || (strlen(fullname) == 0));
1141 if (!strcasecmp(fullname, "off")) {
1145 /* sign on to the server */
1146 snprintf(aaa, sizeof aaa, "USER %s", fullname);
1152 /* password authentication */
1153 if (strlen(rc_password) > 0) {
1154 strcpy(password, rc_password);
1156 newprompt("\rPlease enter your password: ", password, -19);
1162 snprintf(aaa, sizeof aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring, sizeof hexstring));
1164 else /* Else no APOP */
1166 snprintf(aaa, sizeof aaa, "PASS %s", password);
1171 if (aaa[0] == '2') {
1172 load_user_info(&aaa[4]);
1173 offer_to_remember_password(hostbuf, portbuf,
1174 fullname, password);
1177 scr_printf("<< wrong password >>\n");
1178 if (strlen(rc_password) > 0)
1182 NEWUSR: if (strlen(rc_password) == 0) {
1183 scr_printf("No record. Enter as new user? ");
1187 snprintf(aaa, sizeof aaa, "NEWU %s", fullname);
1190 if (aaa[0] != '2') {
1191 scr_printf("%s\n", aaa);
1194 load_user_info(&aaa[4]);
1196 while (set_password() != 0);;
1202 /* Switch color support on or off if we're in user mode */
1203 if (rc_ansi_color == 3) {
1204 if (userflags & US_COLOR)
1210 scr_printf("%s\nAccess level: %d (%s)\n"
1211 "User #%ld / Login #%d",
1212 fullname, axlevel, axdefs[(int) axlevel],
1213 usernum, timescalled);
1214 if (lastcall > 0L) {
1215 scr_printf(" / Last login: %s\n",
1216 asctime(localtime(&lastcall)) );
1222 if (aaa[0] == '2') {
1223 b = extract_int(&aaa[4], 0);
1227 scr_printf("*** You have a new private message in Mail>\n");
1229 scr_printf("*** You have %d new private messages in Mail>\n", b);
1232 if ((axlevel >= 6) && (extract_int(&aaa[4], 2) > 0)) {
1233 scr_printf("*** Users need validation\n");
1235 if (extract_int(&aaa[4], 1) > 0) {
1236 scr_printf("*** Please register.\n");
1237 formout("register");
1241 /* Make up some temporary filenames for use in various parts of the
1242 * program. Don't mess with these once they've been set, because we
1243 * will be unlinking them later on in the program and we don't
1244 * want to delete something that we didn't create. */
1245 snprintf(temp, sizeof temp, tmpnam(NULL));
1246 snprintf(temp2, sizeof temp2, tmpnam(NULL));
1247 snprintf(tempdir, sizeof tempdir, tmpnam(NULL));
1249 /* Get screen dimensions. First we go to a default of 80x24. Then
1250 * we try to get the user's actual screen dimensions off the server.
1251 * However, if we're running on an xterm, all this stuff is
1252 * irrelevant because we're going to dynamically size the screen
1253 * during the session.
1259 if (aaa[0] == '2') {
1260 screenwidth = extract_int(&aaa[4], 0);
1261 screenheight = extract_int(&aaa[4], 1);
1263 if (getenv("TERM") != NULL)
1264 if (!strcmp(getenv("TERM"), "xterm")) {
1268 check_screen_dims();
1274 /* Enter the lobby */
1275 dotgoto("_BASEROOM_", 1, 0);
1277 /* Main loop for the system... user is logged in. */
1285 /* MAIN COMMAND LOOP */
1287 mcmd = getcmd(argbuf); /* Get keyboard command */
1290 check_screen_dims(); /* if xterm, get screen size */
1308 newprompt("What do you want your username to be? ", aaa, 32);
1309 snprintf(bbb, sizeof bbb, "ENT0 2|0|0|0|%s", aaa);
1312 if (strncmp("200", aaa, 3))
1313 scr_printf("\n%s\n", aaa);
1322 if (!rc_alt_semantics)
1327 if (!rc_alt_semantics)
1329 dotgoto(argbuf, 0, 0);
1333 dotgoto("_MAIL_", 1, 0);
1337 dotgoto(argbuf, 0, 0);
1340 if (rc_alt_semantics)
1342 dotgoto(argbuf, 0, 0);
1354 readmsgs(0, (-1), 0);
1357 readmsgs(2, (-1), 0);
1360 readmsgs(3, 1, atoi(argbuf));
1433 if (!rc_alt_semantics)
1438 if (!rc_alt_semantics)
1449 cli_image_upload("_userpic_");
1452 cli_image_upload("_roompic_");
1456 snprintf(aaa, sizeof aaa, "_floorpic_|%d", curr_floor);
1457 cli_image_upload(aaa);
1461 enternew("roomname", aaa, 20);
1462 snprintf(bbb, sizeof bbb, "RCHG %s", aaa);
1465 if (strncmp("200", aaa, 3))
1466 scr_printf("\n%s\n", aaa);
1469 enternew("hostname", aaa, 25);
1470 snprintf(bbb, sizeof bbb, "HCHG %s", aaa);
1473 if (strncmp("200", aaa, 3))
1474 scr_printf("\n%s\n", aaa);
1477 enternew("username", aaa, 32);
1478 snprintf(bbb, sizeof bbb, "UCHG %s", aaa);
1481 if (strncmp("200", aaa, 3))
1482 scr_printf("\n%s\n", aaa);
1492 display_help(argbuf);
1496 formout("register");
1501 scr_printf("Are you sure (y/n)? ");
1510 scr_printf("All users will be disconnected! "
1511 "Really terminate the server? ");
1515 scr_printf("%s\n", &aaa[4]);
1525 scr_printf("Do you really want to schedule a "
1526 "server shutdown? ");
1528 serv_puts("SCDN 1");
1531 if (atoi(&aaa[4])) {
1533 "The Citadel server will terminate when all users are logged off.\n"
1538 "The Citadel server will not terminate.\n"
1546 network_config_management("listrecp",
1547 "Mailing list recipients");
1551 network_config_management("ignet_push_share",
1552 "Nodes with which we share this room");
1556 do_ignet_configuration();
1560 do_filterlist_configuration();
1564 if (rc_alt_semantics)
1574 if (server_is_local) {
1576 sttybbs(SB_RESTORE);
1577 snprintf(aaa, sizeof aaa, "USERNAME=\042%s\042; export USERNAME;"
1578 "exec ./subsystem %ld %d %d", fullname,
1579 usernum, screenwidth, axlevel);
1581 sttybbs(SB_NO_INTR);
1584 scr_printf("*** Can't run doors when server is not local.\n");
1601 do_system_configuration();
1605 do_internet_configuration();
1609 check_message_base();
1635 gotofloor(argbuf, GF_GOTO);
1639 gotofloor(argbuf, GF_SKIP);
1643 forget_this_floor();
1671 knrooms(floor_mode);
1681 misc_server_cmd(argbuf);
1685 edit_system_message(argbuf);
1710 } while (termn8 == 0);
1712 TERMN8: scr_printf("%s logged out.\n", fullname);
1713 while (march != NULL) {
1714 remove_march(march->march_name, 0);
1717 sln_printf("\n\nType 'off' to disconnect, or next user...\n");
1719 snprintf(aaa, sizeof aaa, "LOUT");
1723 sttybbs(SB_RESTORE);
1724 if ((mcmd == 29) || (mcmd == 15)) {