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>
39 #include "routines2.h"
44 #include "citadel_ipc.h"
45 #include "client_chat.h"
46 #include "client_passwords.h"
47 #include "citadel_decls.h"
50 #include "client_crypto.h"
58 #define IFEXPERT if (userflags&US_EXPERT)
59 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
60 #define IFAIDE if (axlevel>=6)
61 #define IFNAIDE if (axlevel<6)
63 struct march *march = NULL;
65 /* globals associated with the client program */
66 char temp[PATH_MAX]; /* Name of general temp file */
67 char temp2[PATH_MAX]; /* Name of general temp file */
68 char tempdir[PATH_MAX]; /* Name of general temp dir */
69 char editor_path[SIZ]; /* path to external editor */
70 char printcmd[SIZ]; /* print command */
71 int editor_pid = (-1);
74 struct CtdlServInfo serv_info; /* Info on the server connected */
78 char room_name[ROOMNAMELEN];
79 char *uglist[UGLISTLEN]; /* size of the ungoto list */
80 long uglistlsn[UGLISTLEN]; /* current read position for all the ungoto's. Not going to make any friends with this one. */
82 char is_mail = 0; /* nonzero when we're in a mail room */
83 char axlevel = 0; /* access level */
84 char is_room_aide = 0; /* boolean flag, 1 if room aide */
88 long usernum = 0L; /* user number */
89 time_t lastcall = 0L; /* Date/time of previous login */
91 long highest_msg_read; /* used for <A>bandon room cmd */
92 long maxmsgnum; /* used for <G>oto */
94 char have_xterm = 0; /* are we running on an xterm? */
101 char curr_floor = 0; /* number of current floor */
102 char floorlist[128][SIZ]; /* names of floors */
103 int termn8 = 0; /* Set to nonzero to cause a logoff */
104 int secure; /* Set to nonzero when wire is encrypted */
106 extern char express_msgs; /* express messages waiting! */
107 extern int rc_ansi_color; /* ansi color value from citadel.rc */
108 extern int next_lazy_cmd;
111 * here is our 'clean up gracefully and exit' routine
113 void logoff(int code)
116 if (editor_pid > 0) { /* kill the editor if it's running */
117 kill(editor_pid, SIGHUP);
120 /* Free the ungoto list */
121 for (lp = 0; lp < uglistsize; lp++)
124 /* shut down the server... but not if the logoff code is 3, because
125 * that means we're exiting because we already lost the server
131 * now clean up various things
140 /* Violently kill off any child processes if Citadel is
143 if (getppid() == 1) {
144 kill(0 - getpgrp(), SIGTERM);
146 kill(0 - getpgrp(), SIGKILL);
148 sttybbs(SB_RESTORE); /* return the old terminal settings */
149 exit(code); /* exit with the proper exit code */
155 * signal catching function for hangups...
157 void dropcarr(int signum)
165 * catch SIGCONT to reset terminal modes when were are put back into the
168 void catch_sigcont(int signum)
171 signal(SIGCONT, catch_sigcont);
176 /* general purpose routines */
178 void formout(char *name)
180 int r; /* IPC return code */
184 r = CtdlIPCSystemMessage(name, &text, buf);
186 scr_printf("%s\n", buf);
190 fmout(screenwidth, NULL, text, NULL,
191 ((userflags & US_PAGINATOR) ? 1 : 0),
198 void userlist(char *patn)
204 int r; /* IPC response code */
205 char *listing = NULL;
207 r = CtdlIPCUserListing(&listing, buf);
209 pprintf("%s\n", buf);
213 pprintf(" User Name Num L LastCall Calls Posts\n");
214 pprintf("------------------------- ----- - ---------- ----- -----\n");
215 while (strlen(listing) > 0) {
216 extract_token(buf, listing, 0, '\n');
217 remove_token(listing, 0, '\n');
219 if (sigcaught == 0) {
221 if (pattern(fl, patn) >= 0) {
222 pprintf("%-25s ", fl);
223 pprintf("%5ld %d ", extract_long(buf, 2),
224 extract_int(buf, 1));
225 lc = extract_long(buf, 3);
226 tmbuf = (struct tm *) localtime(&lc);
227 pprintf("%02d/%02d/%04d ",
230 (tmbuf->tm_year + 1900));
231 pprintf("%5ld %5ld\n", extract_long(buf, 4), extract_long(buf, 5));
242 * grab assorted info about the user...
244 void load_user_info(char *params)
246 extract(fullname, params, 0);
247 axlevel = extract_int(params, 1);
248 timescalled = extract_int(params, 2);
249 posted = extract_int(params, 3);
250 userflags = extract_int(params, 4);
251 usernum = extract_long(params, 5);
252 lastcall = extract_long(params, 6);
257 * Remove a room from the march list. 'floornum' is ignored unless
258 * 'roomname' is set to _FLOOR_, in which case all rooms on the requested
259 * floor will be removed from the march list.
261 void remove_march(char *roomname, int floornum)
263 struct march *mptr, *mptr2;
268 if ((!strcasecmp(march->march_name, roomname))
269 || ((!strcasecmp(roomname, "_FLOOR_")) && (march->march_floor == floornum))) {
276 for (mptr = march; mptr != NULL; mptr = mptr->next) {
278 if ((!strcasecmp(mptr->march_name, roomname))
279 || ((!strcasecmp(roomname, "_FLOOR_"))
280 && (mptr->march_floor == floornum))) {
282 mptr2->next = mptr->next;
293 * Locate the room on the march list which we most want to go to. Each room
294 * is measured given a "weight" of preference based on various factors.
296 char *pop_march(int desired_floor)
298 static char TheRoom[ROOMNAMELEN];
300 int TheOrder = 32767;
303 struct march *mptr = NULL;
305 strcpy(TheRoom, "_BASEROOM_");
309 for (mptr = march; mptr != NULL; mptr = mptr->next) {
311 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
312 weight = weight + 10000;
313 if (mptr->march_floor == desired_floor)
314 weight = weight + 5000;
316 weight = weight + ((128 - (mptr->march_floor)) * 128);
317 weight = weight + (128 - (mptr->march_order));
319 if (weight > TheWeight) {
321 strcpy(TheRoom, mptr->march_name);
322 TheFloor = mptr->march_floor;
323 TheOrder = mptr->march_order;
331 * jump directly to a room
333 void dotgoto(char *towhere, int display_name, int fromungoto)
335 char aaa[SIZ], bbb[SIZ], psearch[SIZ];
337 int newmailcount = 0;
338 static int oldmailcount = (-1);
339 int partial_match, best_match;
341 int ugpos = uglistsize;
342 int r; /* IPC result code */
343 struct ctdlipcroom *roomrec = NULL;
345 /* store ungoto information */
346 if (fromungoto == 0) {
347 /* sloppy slide them all down, hey it's the client, who cares. :-) */
348 if (uglistsize >= (UGLISTLEN-1)) {
351 for (lp = 0; lp < (UGLISTLEN-1); lp++) {
352 uglist[lp] = uglist[lp+1];
353 uglistlsn[lp] = uglistlsn[lp+1];
359 uglist[ugpos] = malloc(strlen(room_name)+1);
360 strcpy(uglist[ugpos], room_name);
361 uglistlsn[ugpos] = ls;
364 /* first try an exact match */
365 r = CtdlIPCGotoRoom(towhere, "", &roomrec, aaa);
367 newprompt("Enter room password: ", bbb, 9);
368 r = CtdlIPCGotoRoom(towhere, bbb, &roomrec, aaa);
370 scr_printf("Wrong password.\n");
375 * If a match is not found, try a partial match.
376 * Partial matches anywhere in the string carry a weight of 1,
377 * left-aligned matches carry a weight of 2. Pick the room that
378 * has the highest-weighted match.
386 while (serv_gets(aaa), strcmp(aaa, "000")) {
387 extract(psearch, aaa, 0);
389 if (pattern(psearch, towhere) >= 0) {
392 if (!strncasecmp(towhere, psearch, strlen(towhere))) {
395 if (partial_match > best_match) {
396 strcpy(bbb, psearch);
397 best_match = partial_match;
400 if (strlen(bbb) == 0) {
401 scr_printf("No room '%s'.\n", towhere);
404 r = CtdlIPCGotoRoom(bbb, "", &roomrec, aaa);
407 scr_printf("%s\n", aaa);
410 safestrncpy(room_name, roomrec->RRname, ROOMNAMELEN);
411 room_flags = roomrec->RRflags;
412 from_floor = curr_floor;
413 curr_floor = roomrec->RRfloor;
415 remove_march(room_name, 0);
416 if (!strcasecmp(towhere, "_BASEROOM_"))
417 remove_march(towhere, 0);
418 if (!roomrec->RRunread)
419 next_lazy_cmd = 5; /* Don't read new if no new msgs */
420 if ((from_floor != curr_floor) && (display_name > 0) && (floor_mode == 1)) {
421 if (floorlist[(int) curr_floor][0] == 0)
423 scr_printf("(Entering floor: %s)\n", &floorlist[(int) curr_floor][0]);
425 if (display_name == 1) {
427 scr_printf("%s ", room_name);
431 if (display_name != 2) {
432 color(BRIGHT_YELLOW);
433 scr_printf("%d ", roomrec->RRunread);
435 scr_printf("new of ");
436 color(BRIGHT_YELLOW);
437 scr_printf("%d ", roomrec->RRtotal);
439 scr_printf("messages.\n");
441 highest_msg_read = roomrec->RRlastread;
442 maxmsgnum = roomrec->RRhighest;
443 is_mail = roomrec->RRismailbox;
444 is_room_aide = roomrec->RRaide;
445 ls = roomrec->RRlastread;
447 /* read info file if necessary */
448 if (roomrec->RRinfoupdated > 0)
451 /* check for newly arrived mail if we can */
452 newmailcount = roomrec->RRnewmail;
453 if (newmailcount > 0) {
455 scr_printf("*** You have %d new mail message%s\n",
456 newmailcount - oldmailcount,
457 (newmailcount - oldmailcount == 1) ?
461 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city,
462 room_name, secure, newmailcount);
465 /* Goto next room having unread messages.
466 * We want to skip over rooms that the user has already been to, and take the
467 * user back to the lobby when done. The room we end up in is placed in
468 * newroom - which is set to 0 (the lobby) initially.
473 struct march *mptr, *mptr2;
474 char next_room[ROOMNAMELEN];
475 int r; /* IPC response code */
477 /* Check to see if the march-mode list is already allocated.
478 * If it is, pop the first room off the list and go there.
481 r = CtdlIPCKnownRooms(1, -1, &march, buf);
482 /* add _BASEROOM_ to the end of the march list, so the user will end up
483 * in the system base room (usually the Lobby>) at the end of the loop
485 mptr = (struct march *) malloc(sizeof(struct march));
487 strcpy(mptr->march_name, "_BASEROOM_");
492 while (mptr2->next != NULL)
497 * ...and remove the room we're currently in, so a <G>oto doesn't make us
498 * walk around in circles
500 remove_march(room_name, 0);
503 strcpy(next_room, pop_march(curr_floor));
505 strcpy(next_room, "_BASEROOM_");
507 remove_march(next_room, 0);
508 dotgoto(next_room, 1, 0);
512 * forget all rooms on a given floor
514 void forget_all_rooms_on(int ffloor)
517 struct march *flist, *fptr;
519 scr_printf("Forgetting all rooms on %s...\r", &floorlist[ffloor][0]);
521 snprintf(buf, sizeof buf, "LKRA %d", ffloor);
525 scr_printf("%-72s\n", &buf[4]);
529 while (serv_gets(buf), strcmp(buf, "000")) {
530 fptr = (struct march *) malloc(sizeof(struct march));
533 extract(fptr->march_name, buf, 0);
535 while (flist != NULL) {
536 snprintf(buf, sizeof buf, "GOTO %s", flist->march_name);
547 scr_printf("%-72s\r", "");
552 * routine called by gotofloor() to move to a new room on a new floor
554 void gf_toroom(char *towhere, int mode)
556 int floor_being_left;
558 floor_being_left = curr_floor;
560 if (mode == GF_GOTO) { /* <;G>oto mode */
562 dotgoto(towhere, 1, 0);
564 if (mode == GF_SKIP) { /* <;S>kip mode */
565 dotgoto(towhere, 1, 0);
566 remove_march("_FLOOR_", floor_being_left);
568 if (mode == GF_ZAP) { /* <;Z>ap mode */
569 dotgoto(towhere, 1, 0);
570 remove_march("_FLOOR_", floor_being_left);
571 forget_all_rooms_on(floor_being_left);
579 void gotofloor(char *towhere, int mode)
583 char buf[SIZ], targ[SIZ];
585 if (floorlist[0][0] == 0)
588 for (a = 0; a < 128; ++a)
589 if (!strcasecmp(&floorlist[a][0], towhere))
593 for (a = 0; a < 128; ++a) {
594 if (!strncasecmp(&floorlist[a][0], towhere, strlen(towhere))) {
600 for (a = 0; a < 128; ++a)
601 if (pattern(towhere, &floorlist[a][0]) > 0)
605 scr_printf("No floor '%s'.\n", towhere);
608 for (mptr = march; mptr != NULL; mptr = mptr->next) {
609 if ((mptr->march_floor) == tofloor)
610 gf_toroom(mptr->march_name, mode);
615 snprintf(buf, sizeof buf, "LKRA %d", tofloor);
619 while (serv_gets(buf), strcmp(buf, "000")) {
620 if ((extract_int(buf, 2) == tofloor) && (strlen(targ) == 0))
621 extract(targ, buf, 0);
623 if (strlen(targ) > 0) {
624 gf_toroom(targ, mode);
626 scr_printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
632 * forget all rooms on current floor
634 void forget_this_floor(void)
637 if (curr_floor == 0) {
638 scr_printf("Can't forget this floor.\n");
641 if (floorlist[0][0] == 0)
643 scr_printf("Are you sure you want to forget all rooms on %s? ",
644 &floorlist[(int) curr_floor][0]);
648 gf_toroom("_BASEROOM_", GF_ZAP);
653 * Figure out the physical screen dimensions, if we can
654 * WARNING: this is now called from a signal handler!
656 void check_screen_dims(void)
660 unsigned short height; /* rows */
661 unsigned short width; /* columns */
662 unsigned short xpixels;
663 unsigned short ypixels; /* pixels */
666 if (have_xterm) { /* dynamically size screen if on an xterm */
667 if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
669 screenheight = is_curses_enabled() ? (int)xwinsz.height - 1 : (int) xwinsz.height;
671 screenwidth = (int) xwinsz.width;
679 * set floor mode depending on client, server, and user settings
681 void set_floor_mode(void)
683 if (serv_info.serv_ok_floors == 0) {
684 floor_mode = 0; /* Don't use floors if the server */
686 /* doesn't support them! */
688 if (rc_floor_mode == RC_NO) { /* never use floors */
691 if (rc_floor_mode == RC_YES) { /* always use floors */
694 if (rc_floor_mode == RC_DEFAULT) { /* user choice */
695 floor_mode = ((userflags & US_FLOORS) ? 1 : 0);
701 * Set or change the user's password
703 int set_password(void)
709 if (strlen(rc_password) > 0) {
710 strcpy(pass1, rc_password);
711 strcpy(pass2, rc_password);
713 IFNEXPERT formout("changepw");
714 newprompt("Enter a new password: ", pass1, -19);
715 newprompt("Enter it again to confirm: ", pass2, -19);
719 if (!strcasecmp(pass1, pass2)) {
720 CtdlIPCChangePassword(pass1, buf);
721 scr_printf("%s\n", buf);
722 offer_to_remember_password(hostbuf, portbuf, fullname, pass1);
725 scr_printf("*** They don't match... try again.\n");
733 * get info about the server we've connected to
735 void get_serv_info(char *supplied_hostname)
739 CtdlIPCServerInfo(&serv_info, buf);
741 /* be nice and identify ourself to the server */
742 CtdlIPCIdentifySoftware(SERVER_TYPE, 0, REV_LEVEL,
743 (server_is_local ? "local" : CITADEL),
744 (supplied_hostname) ? supplied_hostname : "", buf);
745 /* (locate_host(buf), buf)); */
753 * Display list of users currently logged on to the server
755 void who_is_online(int longlist)
757 char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ];
759 char actual_user[SIZ], actual_room[SIZ], actual_host[SIZ];
760 char tbuf[SIZ], clientsoft[SIZ];
762 time_t idletime, idlehours, idlemins, idlesecs;
763 int last_session = (-1);
765 char *listing = NULL;
766 int r; /* IPC response code */
773 if (!(timenow = CtdlIPCServerTime(tbuf))) {
779 pprintf("FLG ### User Name Room From host\n");
781 pprintf("--- --- ------------------------- -------------------- ------------------------\n");
783 r = CtdlIPCOnlineUsers(&listing, &timenow, buf);
785 while (strlen(listing) > 0) {
788 /* Get another line */
789 extract_token(buf, listing, 0, '\n');
790 remove_token(listing, 0, '\n');
792 extract(username, buf, 1);
793 extract(roomname, buf, 2);
794 extract(fromhost, buf, 3);
795 extract(clientsoft, buf, 4);
796 extract(flags, buf, 7);
798 idletime = timenow - extract_long(buf, 5);
799 idlehours = idletime / 3600;
800 idlemins = (idletime - (idlehours * 3600)) / 60;
801 idlesecs = (idletime - (idlehours * 3600) - (idlemins * 60));
803 if (idletime > rc_idle_threshold) {
804 while (strlen(roomname) < 20) {
805 strcat(roomname, " ");
807 strcpy(&roomname[14], "[idle]");
813 extract(actual_user, buf, 8);
814 extract(actual_room, buf, 9);
815 extract(actual_host, buf, 10);
817 pprintf(" Flags: %s\n", flags);
818 pprintf("Session: %d\n", extract_int(buf, 0));
819 pprintf(" Name: %s\n", username);
820 pprintf("In room: %s\n", roomname);
821 pprintf(" Host: %s\n", fromhost);
822 pprintf(" Client: %s\n", clientsoft);
823 pprintf(" Idle: %ld:%02ld:%02ld\n",
828 if ( (strlen(actual_user)+strlen(actual_room)+strlen(actual_host)) > 0) {
830 if (strlen(actual_user)>0) pprintf("<%s> ", actual_user);
831 if (strlen(actual_room)>0) pprintf("in <%s> ", actual_room);
832 if (strlen(actual_host)>0) pprintf("from <%s> ", actual_host);
839 if (extract_int(buf, 0) == last_session) {
842 color(BRIGHT_MAGENTA);
843 pprintf("%-3s ", flags);
845 pprintf("%-3d ", extract_int(buf, 0));
847 last_session = extract_int(buf, 0);
849 pprintf("%-25s ", username);
850 color(BRIGHT_MAGENTA);
852 pprintf("%-20s ", roomname);
855 pprintf("%-24s\n", fromhost);
864 void enternew(char *desc, char *buf, int maxlen)
867 snprintf(bbb, sizeof bbb, "Enter in your new %s: ", desc);
868 newprompt(bbb, buf, maxlen);
873 int shift(int argc, char **argv, int start, int count) {
876 for (i=start; i<(argc-count); ++i) {
877 argv[i] = argv[i+count];
883 static void statusHook(char *s) {
891 int main(int argc, char **argv)
894 char aaa[100], bbb[100];/* general purpose variables */
895 char argbuf[32]; /* command line buf */
896 char nonce[NONCE_SIZE];
897 char *telnet_client_host = NULL;
898 char *sptr, *sptr2; /* USed to extract the nonce */
899 char hexstring[MD5_HEXSTRING_SIZE];
900 int stored_password = 0;
902 struct ctdlipcmisc chek;
903 struct usersupp *myself = NULL;
904 int r; /* IPC result code */
906 setIPCDeathHook(screen_delete);
907 setIPCErrorPrintf(err_printf);
908 setCryptoStatusHook(statusHook);
910 /* Permissions sanity check - don't run citadel setuid/setgid */
911 if (getuid() != geteuid()) {
912 err_printf("Please do not run citadel setuid!\n");
914 } else if (getgid() != getegid()) {
915 err_printf("Please do not run citadel setgid!\n");
919 sttybbs(SB_SAVE); /* Store the old terminal parameters */
920 load_command_set(); /* parse the citadel.rc file */
921 sttybbs(SB_NO_INTR); /* Install the new ones */
922 signal(SIGHUP, dropcarr); /* Cleanup gracefully if carrier is dropped */
923 signal(SIGTERM, dropcarr); /* Cleanup gracefully if terminated */
924 signal(SIGCONT, catch_sigcont); /* Catch SIGCONT so we can reset terminal */
926 signal(SIGWINCH, scr_winch); /* Window resize signal */
930 arg_encrypt = RC_DEFAULT;
933 arg_screen = RC_DEFAULT;
937 * Handle command line options as if we were called like /bin/login
938 * (i.e. from in.telnetd)
940 for (a=0; a<argc; ++a) {
941 if ((argc > a+1) && (!strcmp(argv[a], "-h")) ) {
942 telnet_client_host = argv[a+1];
943 argc = shift(argc, argv, a, 2);
945 if (!strcmp(argv[a], "-x")) {
949 argc = shift(argc, argv, a, 1);
951 if (!strcmp(argv[a], "-X")) {
953 arg_encrypt = RC_YES;
954 argc = shift(argc, argv, a, 1);
956 fprintf(stderr, "Not compiled with encryption support");
960 if (!strcmp(argv[a], "-s")) {
964 argc = shift(argc, argv, a, 1);
966 if (!strcmp(argv[a], "-S")) {
970 argc = shift(argc, argv, a, 1);
972 if (!strcmp(argv[a], "-p")) {
975 if (chdir(BBSDIR) < 0) {
976 perror("can't change to " BBSDIR);
981 * Drop privileges if necessary. We stat
982 * citadel.config to get the uid/gid since it's
983 * guaranteed to have the uid/gid we want.
985 if (!getuid() || !getgid()) {
986 if (stat(BBSDIR "/citadel.config", &st) < 0) {
987 perror("couldn't stat citadel.config");
990 if (!getgid() && (setgid(st.st_gid) < 0)) {
991 perror("couldn't change gid");
994 if (!getuid() && (setuid(st.st_uid) < 0)) {
995 perror("couldn't change uid");
999 scr_printf("Privileges changed to uid %d gid %d\n",
1000 getuid(), getgid());
1003 argc = shift(argc, argv, a, 1);
1009 sln_printf("Attaching to server... \r");
1011 attach_to_server(argc, argv, hostbuf, portbuf);
1014 if (aaa[0] != '2') {
1015 scr_printf("%s\n", &aaa[4]);
1019 /* If there is a [nonce] at the end, put the nonce in <nonce>, else nonce
1023 if ((sptr = strchr(aaa, '<')) == NULL)
1029 if ((sptr2 = strchr(sptr, '>')) == NULL)
1037 strncpy(nonce, sptr, NONCE_SIZE);
1041 get_serv_info(telnet_client_host);
1043 scr_printf("%-24s\n%s\n%s\n", serv_info.serv_software, serv_info.serv_humannode,
1044 serv_info.serv_bbs_city);
1047 secure = starttls();
1048 status_line(serv_info.serv_humannode, serv_info.serv_bbs_city, NULL,
1051 screenwidth = 80; /* default screen dimensions */
1054 scr_printf(" pause next stop\n");
1055 scr_printf(" ctrl-s ctrl-o ctrl-c\n\n");
1056 formout("hello"); /* print the opening greeting */
1059 GSTA: /* See if we have a username and password on disk */
1060 if (rc_remember_passwords) {
1061 get_stored_password(hostbuf, portbuf, fullname, password);
1062 if (strlen(fullname) > 0) {
1063 snprintf(aaa, sizeof(aaa)-1, "USER %s", fullname);
1068 snprintf(aaa, sizeof aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring, sizeof hexstring));
1070 else /* Else no APOP */
1072 snprintf(aaa, sizeof(aaa)-1, "PASS %s", password);
1077 if (aaa[0] == '2') {
1078 load_user_info(&aaa[4]);
1079 stored_password = 1;
1083 set_stored_password(hostbuf, portbuf, "", "");
1091 if (strlen(rc_username) > 0) {
1092 strcpy(fullname, rc_username);
1094 newprompt("Enter your name: ", fullname, 29);
1097 if (!strcasecmp(fullname, "new")) { /* just in case */
1098 scr_printf("Please enter the name you wish to log in with.\n");
1101 (!strcasecmp(fullname, "bbs"))
1102 || (!strcasecmp(fullname, "new"))
1103 || (strlen(fullname) == 0));
1105 if (!strcasecmp(fullname, "off")) {
1109 /* sign on to the server */
1110 r = CtdlIPCTryLogin(fullname, aaa);
1114 /* password authentication */
1115 if (strlen(rc_password) > 0) {
1116 strcpy(password, rc_password);
1118 newprompt("\rPlease enter your password: ", password, -19);
1124 snprintf(aaa, sizeof aaa, "PAS2 %s", make_apop_string(password, nonce, hexstring, sizeof hexstring));
1126 else /* Else no APOP */
1128 snprintf(aaa, sizeof aaa, "PASS %s", password);
1133 if (aaa[0] == '2') {
1134 load_user_info(&aaa[4]);
1135 offer_to_remember_password(hostbuf, portbuf,
1136 fullname, password);
1139 scr_printf("<< wrong password >>\n");
1140 if (strlen(rc_password) > 0)
1144 NEWUSR: if (strlen(rc_password) == 0) {
1145 scr_printf("No record. Enter as new user? ");
1149 snprintf(aaa, sizeof aaa, "NEWU %s", fullname);
1152 if (aaa[0] != '2') {
1153 scr_printf("%s\n", aaa);
1156 load_user_info(&aaa[4]);
1158 while (set_password() != 0);;
1164 /* Switch color support on or off if we're in user mode */
1165 if (rc_ansi_color == 3) {
1166 if (userflags & US_COLOR)
1172 scr_printf("%s\nAccess level: %d (%s)\n"
1173 "User #%ld / Login #%d",
1174 fullname, axlevel, axdefs[(int) axlevel],
1175 usernum, timescalled);
1176 if (lastcall > 0L) {
1177 scr_printf(" / Last login: %s\n",
1178 asctime(localtime(&lastcall)) );
1182 r = CtdlIPCMiscCheck(&chek, aaa);
1188 scr_printf("*** You have a new private message in Mail>\n");
1190 scr_printf("*** You have %d new private messages in Mail>\n", b);
1193 if ((axlevel >= 6) && (chek.needvalid > 0)) {
1194 scr_printf("*** Users need validation\n");
1196 if (chek.needregis > 0) {
1197 scr_printf("*** Please register.\n");
1198 formout("register");
1202 /* Make up some temporary filenames for use in various parts of the
1203 * program. Don't mess with these once they've been set, because we
1204 * will be unlinking them later on in the program and we don't
1205 * want to delete something that we didn't create. */
1206 snprintf(temp, sizeof temp, tmpnam(NULL));
1207 snprintf(temp2, sizeof temp2, tmpnam(NULL));
1208 snprintf(tempdir, sizeof tempdir, tmpnam(NULL));
1210 /* Get screen dimensions. First we go to a default of 80x24. Then
1211 * we try to get the user's actual screen dimensions off the server.
1212 * However, if we're running on an xterm, all this stuff is
1213 * irrelevant because we're going to dynamically size the screen
1214 * during the session.
1218 r = CtdlIPCGetConfig(&myself, aaa);
1220 screenwidth = myself->USscreenwidth;
1221 screenheight = myself->USscreenheight;
1223 if (getenv("TERM") != NULL)
1224 if (!strcmp(getenv("TERM"), "xterm")) {
1228 check_screen_dims();
1234 /* Enter the lobby */
1235 dotgoto("_BASEROOM_", 1, 0);
1237 /* Main loop for the system... user is logged in. */
1245 /* MAIN COMMAND LOOP */
1247 mcmd = getcmd(argbuf); /* Get keyboard command */
1250 check_screen_dims(); /* if xterm, get screen size */
1268 newprompt("What do you want your username to be? ", aaa, 32);
1269 snprintf(bbb, sizeof bbb, "ENT0 2|0|0|0|%s", aaa);
1272 if (strncmp("200", aaa, 3))
1273 scr_printf("\n%s\n", aaa);
1282 if (!rc_alt_semantics)
1287 if (!rc_alt_semantics)
1289 dotgoto(argbuf, 0, 0);
1293 dotgoto("_MAIL_", 1, 0);
1297 dotgoto(argbuf, 0, 0);
1300 if (rc_alt_semantics)
1302 dotgoto(argbuf, 0, 0);
1314 readmsgs(0, (-1), 0);
1317 readmsgs(2, (-1), 0);
1320 readmsgs(3, 1, atoi(argbuf));
1393 if (!rc_alt_semantics)
1398 if (!rc_alt_semantics)
1409 cli_image_upload("_userpic_");
1412 cli_image_upload("_roompic_");
1416 snprintf(aaa, sizeof aaa, "_floorpic_|%d", curr_floor);
1417 cli_image_upload(aaa);
1421 enternew("roomname", aaa, 20);
1422 r = CtdlIPCChangeRoomname(aaa, bbb);
1424 scr_printf("\n%s\n", aaa);
1427 enternew("hostname", aaa, 25);
1428 r = CtdlIPCChangeHostname(aaa, bbb);
1430 scr_printf("\n%s\n", aaa);
1433 enternew("username", aaa, 32);
1434 r = CtdlIPCChangeUsername(aaa, bbb);
1436 scr_printf("\n%s\n", aaa);
1446 display_help(argbuf);
1450 formout("register");
1455 scr_printf("Are you sure (y/n)? ");
1464 scr_printf("All users will be disconnected! "
1465 "Really terminate the server? ");
1467 r = CtdlIPCTerminateServerNow(aaa);
1468 scr_printf("%s\n", aaa);
1478 scr_printf("Do you really want to schedule a "
1479 "server shutdown? ");
1481 r = CtdlIPCTerminateServerScheduled(1, aaa);
1485 "The Citadel server will terminate when all users are logged off.\n"
1489 "The Citadel server will not terminate.\n"
1497 network_config_management("listrecp",
1498 "Mailing list recipients");
1502 network_config_management("ignet_push_share",
1503 "Nodes with which we share this room");
1507 do_ignet_configuration();
1511 do_filterlist_configuration();
1515 if (rc_alt_semantics)
1525 if (server_is_local) {
1527 sttybbs(SB_RESTORE);
1528 snprintf(aaa, sizeof aaa, "USERNAME=\042%s\042; export USERNAME;"
1529 "exec ./subsystem %ld %d %d", fullname,
1530 usernum, screenwidth, axlevel);
1532 sttybbs(SB_NO_INTR);
1535 scr_printf("*** Can't run doors when server is not local.\n");
1552 do_system_configuration();
1556 do_internet_configuration();
1560 check_message_base();
1586 gotofloor(argbuf, GF_GOTO);
1590 gotofloor(argbuf, GF_SKIP);
1594 forget_this_floor();
1622 knrooms(floor_mode);
1632 misc_server_cmd(argbuf);
1636 edit_system_message(argbuf);
1661 } while (termn8 == 0);
1663 TERMN8: scr_printf("%s logged out.\n", fullname);
1664 while (march != NULL) {
1665 remove_march(march->march_name, 0);
1668 sln_printf("\n\nType 'off' to disconnect, or next user...\n");
1672 sttybbs(SB_RESTORE);
1673 if ((mcmd == 29) || (mcmd == 15)) {