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>
37 #include "citadel_ipc.h"
40 #include "routines2.h"
44 #include "client_chat.h"
45 #include "client_passwords.h"
46 #include "citadel_decls.h"
56 #define IFEXPERT if (userflags&US_EXPERT)
57 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
58 #define IFAIDE if (axlevel>=6)
59 #define IFNAIDE if (axlevel<6)
61 struct march *march = NULL;
63 /* globals associated with the client program */
64 char temp[PATH_MAX]; /* Name of general-purpose temp file */
65 char temp2[PATH_MAX]; /* Name of general-purpose temp file */
66 char tempdir[PATH_MAX]; /* Name of general-purpose temp directory */
67 char editor_paths[MAX_EDITORS][SIZ]; /* paths to external editors */
68 char printcmd[SIZ]; /* print command */
69 int editor_pid = (-1);
70 char fullname[USERNAME_SIZE];
74 char room_name[ROOMNAMELEN];
75 char *uglist[UGLISTLEN]; /* size of the ungoto list */
76 long uglistlsn[UGLISTLEN]; /* current read position for all the ungoto's. Not going to make any friends with this one. */
78 char is_mail = 0; /* nonzero when we're in a mail room */
79 char axlevel = 0; /* access level */
80 char is_room_aide = 0; /* boolean flag, 1 if room aide */
84 long usernum = 0L; /* user number */
85 time_t lastcall = 0L; /* Date/time of previous login */
87 long highest_msg_read; /* used for <A>bandon room cmd */
88 long maxmsgnum; /* used for <G>oto */
90 char have_xterm = 0; /* are we running on an xterm? */
91 char rc_username[USERNAME_SIZE];
97 char curr_floor = 0; /* number of current floor */
98 char floorlist[128][SIZ]; /* names of floors */
99 int termn8 = 0; /* Set to nonzero to cause a logoff */
100 int secure; /* Set to nonzero when wire is encrypted */
101 int can_do_msg4 = 0; /* Set to nonzero if the server can handle MSG4 commands */
103 extern char express_msgs; /* express messages waiting! */
104 extern int rc_ansi_color; /* ansi color value from citadel.rc */
105 extern int next_lazy_cmd;
107 CtdlIPC *ipc_for_signal_handlers; /* KLUDGE cover your eyes */
110 * here is our 'clean up gracefully and exit' routine
112 void logoff(CtdlIPC *ipc, 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++) {
125 /* Shut down the server connection ... but not if the logoff code is 3,
126 * because that means we're exiting because we already lost the server.
133 * now clean up various things
141 /* Violently kill off any child processes if Citadel is
144 if (getppid() == 1) {
145 kill(0 - getpgrp(), SIGTERM);
147 kill(0 - getpgrp(), SIGKILL);
149 color(ORIGINAL_PAIR); /* Restore the old color settings */
150 sttybbs(SB_RESTORE); /* return the old terminal settings */
151 exit(code); /* exit with the proper exit code */
157 * signal catching function for hangups...
159 void dropcarr(int signum)
161 logoff(NULL, 3); /* No IPC when server's already gone! */
167 * catch SIGCONT to reset terminal modes when were are put back into the
170 void catch_sigcont(int signum)
173 signal(SIGCONT, catch_sigcont);
177 /* general purpose routines */
180 void formout(CtdlIPC *ipc, char *name)
182 int r; /* IPC return code */
186 r = CtdlIPCSystemMessage(ipc, name, &text, buf);
188 scr_printf("%s\n", buf);
192 fmout(screenwidth, NULL, text, NULL,
193 ((userflags & US_PAGINATOR) ? 1 : 0),
200 void userlist(CtdlIPC *ipc, char *patn)
206 int r; /* IPC response code */
207 char *listing = NULL;
209 r = CtdlIPCUserListing(ipc, &listing, buf);
211 pprintf("%s\n", buf);
215 pprintf(" User Name Num L LastCall Calls Posts\n");
216 pprintf("------------------------- ----- - ---------- ----- -----\n");
217 while (strlen(listing) > 0) {
218 extract_token(buf, listing, 0, '\n');
219 remove_token(listing, 0, '\n');
221 if (sigcaught == 0) {
223 if (pattern(fl, patn) >= 0) {
224 pprintf("%-25s ", fl);
225 pprintf("%5ld %d ", extract_long(buf, 2),
226 extract_int(buf, 1));
227 lc = extract_long(buf, 3);
228 tmbuf = (struct tm *) localtime(&lc);
229 pprintf("%02d/%02d/%04d ",
232 (tmbuf->tm_year + 1900));
233 pprintf("%5ld %5ld\n", extract_long(buf, 4), extract_long(buf, 5));
244 * grab assorted info about the user...
246 void load_user_info(char *params)
248 extract(fullname, params, 0);
249 axlevel = extract_int(params, 1);
250 timescalled = extract_int(params, 2);
251 posted = extract_int(params, 3);
252 userflags = extract_int(params, 4);
253 usernum = extract_long(params, 5);
254 lastcall = extract_long(params, 6);
259 * Remove a room from the march list. 'floornum' is ignored unless
260 * 'roomname' is set to _FLOOR_, in which case all rooms on the requested
261 * floor will be removed from the march list.
263 void remove_march(char *roomname, int floornum)
265 struct march *mptr, *mptr2;
270 if ((!strcasecmp(march->march_name, roomname))
271 || ((!strcasecmp(roomname, "_FLOOR_")) && (march->march_floor == floornum))) {
278 for (mptr = march; mptr != NULL; mptr = mptr->next) {
280 if ((!strcasecmp(mptr->march_name, roomname))
281 || ((!strcasecmp(roomname, "_FLOOR_"))
282 && (mptr->march_floor == floornum))) {
284 mptr2->next = mptr->next;
295 * Locate the room on the march list which we most want to go to. Each room
296 * is measured given a "weight" of preference based on various factors.
298 char *pop_march(int desired_floor)
300 static char TheRoom[ROOMNAMELEN];
302 int TheOrder = 32767;
305 struct march *mptr = NULL;
307 strcpy(TheRoom, "_BASEROOM_");
311 for (mptr = march; mptr != NULL; mptr = mptr->next) {
313 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
314 weight = weight + 10000;
315 if (mptr->march_floor == desired_floor)
316 weight = weight + 5000;
318 weight = weight + ((128 - (mptr->march_floor)) * 128);
319 weight = weight + (128 - (mptr->march_order));
321 if (weight > TheWeight) {
323 strcpy(TheRoom, mptr->march_name);
324 TheFloor = mptr->march_floor;
325 TheOrder = mptr->march_order;
333 * jump directly to a room
335 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto)
337 char aaa[SIZ], bbb[SIZ];
339 int newmailcount = 0;
340 int partial_match, best_match;
342 int ugpos = uglistsize;
343 int r; /* IPC result code */
344 struct ctdlipcroom *room = NULL;
346 /* store ungoto information */
347 if (fromungoto == 0) {
348 /* sloppy slide them all down, hey it's the client, who cares. :-) */
349 if (uglistsize >= (UGLISTLEN-1)) {
352 for (lp = 0; lp < (UGLISTLEN-1); lp++) {
353 uglist[lp] = uglist[lp+1];
354 uglistlsn[lp] = uglistlsn[lp+1];
361 uglist[ugpos] = malloc(strlen(room_name)+1);
362 strcpy(uglist[ugpos], room_name);
363 uglistlsn[ugpos] = ls;
366 /* first try an exact match */
367 r = CtdlIPCGotoRoom(ipc, towhere, "", &room, aaa);
369 newprompt("Enter room password: ", bbb, 9);
370 r = CtdlIPCGotoRoom(ipc, towhere, bbb, &room, aaa);
372 scr_printf("Wrong password.\n");
378 * If a match is not found, try a partial match.
379 * Partial matches anywhere in the string carry a weight of 1,
380 * left-aligned matches carry a weight of 2. Pick the room that
381 * has the highest-weighted match. Do not match on forgotten
385 struct march *march = NULL;
390 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, AllFloors, &march, aaa);
392 /* Run the roomlist; free the data as we go */
393 struct march *mp = march; /* Current */
397 if (pattern(mp->march_name, towhere) >= 0) {
400 if (!strncasecmp(mp->march_name, towhere, strlen(towhere))) {
403 if (partial_match > best_match) {
404 strcpy(bbb, mp->march_name);
405 best_match = partial_match;
407 /* Both pointers are NULL at end of list */
414 if (strlen(bbb) == 0) {
415 scr_printf("No room '%s'.\n", towhere);
419 r = CtdlIPCGotoRoom(ipc, bbb, "", &room, aaa);
421 if (r / 100 != 1 && r / 100 != 2) {
422 scr_printf("%s\n", aaa);
425 safestrncpy(room_name, room->RRname, ROOMNAMELEN);
426 room_flags = room->RRflags;
427 from_floor = curr_floor;
428 curr_floor = room->RRfloor;
430 remove_march(room_name, 0);
431 if (!strcasecmp(towhere, "_BASEROOM_"))
432 remove_march(towhere, 0);
434 next_lazy_cmd = 5; /* Don't read new if no new msgs */
435 if ((from_floor != curr_floor) && (display_name > 0) && (floor_mode == 1)) {
436 if (floorlist[(int) curr_floor][0] == 0)
438 scr_printf("(Entering floor: %s)\n", &floorlist[(int) curr_floor][0]);
440 if (display_name == 1) {
442 scr_printf("%s ", room_name);
446 if (display_name != 2) {
447 color(BRIGHT_YELLOW);
448 scr_printf("%d ", room->RRunread);
450 scr_printf("new of ");
451 color(BRIGHT_YELLOW);
452 scr_printf("%d ", room->RRtotal);
454 scr_printf("messages.\n");
456 highest_msg_read = room->RRlastread;
457 maxmsgnum = room->RRhighest;
458 is_mail = room->RRismailbox;
459 is_room_aide = room->RRaide;
460 ls = room->RRlastread;
462 /* read info file if necessary */
463 if (room->RRinfoupdated > 0)
466 /* check for newly arrived mail if we can */
467 newmailcount = room->RRnewmail;
468 if (newmailcount > 0) {
470 if (newmailcount == 1) {
471 scr_printf("*** A new mail message has arrived.\n");
474 scr_printf("*** %d new mail messages have arrived.\n",
478 if (strlen(rc_gotmail_cmd) > 0) {
479 system(rc_gotmail_cmd);
482 status_line(ipc->ServInfo.humannode, ipc->ServInfo.bbs_city,
483 room_name, secure, newmailcount);
486 /* Goto next room having unread messages.
487 * We want to skip over rooms that the user has already been to, and take the
488 * user back to the lobby when done. The room we end up in is placed in
489 * newroom - which is set to 0 (the lobby) initially.
491 void gotonext(CtdlIPC *ipc)
494 struct march *mptr, *mptr2;
495 char next_room[ROOMNAMELEN];
496 int r; /* IPC response code */
498 /* Check to see if the march-mode list is already allocated.
499 * If it is, pop the first room off the list and go there.
502 r = CtdlIPCKnownRooms(ipc, SubscribedRoomsWithNewMessages,
503 AllFloors, &march, buf);
505 /* add _BASEROOM_ to the end of the march list, so the user will end up
506 * in the system base room (usually the Lobby>) at the end of the loop
508 mptr = (struct march *) malloc(sizeof(struct march));
510 strcpy(mptr->march_name, "_BASEROOM_");
515 while (mptr2->next != NULL)
520 * ...and remove the room we're currently in, so a <G>oto doesn't make us
521 * walk around in circles
523 remove_march(room_name, 0);
526 strcpy(next_room, pop_march(curr_floor));
528 strcpy(next_room, "_BASEROOM_");
530 remove_march(next_room, 0);
531 dotgoto(ipc, next_room, 1, 0);
535 * forget all rooms on a given floor
537 void forget_all_rooms_on(CtdlIPC *ipc, int ffloor)
540 struct march *flist, *fptr;
541 struct ctdlipcroom *room; /* Ignored */
542 int r; /* IPC response code */
544 scr_printf("Forgetting all rooms on %s...\r", &floorlist[ffloor][0]);
546 remove_march("_FLOOR_", ffloor);
547 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, ffloor, &flist, buf);
549 scr_printf("%-72s\n", buf);
553 r = CtdlIPCGotoRoom(ipc, flist->march_name, "", &room, buf);
555 r = CtdlIPCForgetRoom(ipc, buf);
561 scr_printf("%-72s\r", "");
566 * routine called by gotofloor() to move to a new room on a new floor
568 void gf_toroom(CtdlIPC *ipc, char *towhere, int mode)
570 int floor_being_left;
572 floor_being_left = curr_floor;
574 if (mode == GF_GOTO) { /* <;G>oto mode */
576 dotgoto(ipc, towhere, 1, 0);
578 if (mode == GF_SKIP) { /* <;S>kip mode */
579 dotgoto(ipc, towhere, 1, 0);
580 remove_march("_FLOOR_", floor_being_left);
582 if (mode == GF_ZAP) { /* <;Z>ap mode */
583 dotgoto(ipc, towhere, 1, 0);
584 remove_march("_FLOOR_", floor_being_left);
585 forget_all_rooms_on(ipc, floor_being_left);
593 void gotofloor(CtdlIPC *ipc, char *towhere, int mode)
596 int r; /* IPC response code */
598 char buf[SIZ], targ[SIZ];
600 if (floorlist[0][0] == 0)
603 for (a = 0; a < 128; ++a)
604 if (!strcasecmp(&floorlist[a][0], towhere))
608 for (a = 0; a < 128; ++a) {
609 if (!strncasecmp(&floorlist[a][0], towhere, strlen(towhere))) {
615 for (a = 0; a < 128; ++a)
616 if (pattern(towhere, &floorlist[a][0]) > 0)
620 scr_printf("No floor '%s'.\n", towhere);
623 for (mptr = march; mptr != NULL; mptr = mptr->next) {
624 if ((mptr->march_floor) == tofloor)
625 gf_toroom(ipc, mptr->march_name, mode);
629 /* Find first known room on the floor */
633 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, tofloor, &mptr, buf);
635 struct march *tmp = mptr;
637 /* TODO: room order is being ignored? */
639 strncpy(targ, mptr->march_name, ROOMNAMELEN);
646 if (strlen(targ) > 0) {
647 gf_toroom(ipc, targ, mode);
651 /* No known rooms on the floor; unzap the first one then */
655 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, tofloor, &mptr, buf);
657 struct march *tmp = mptr;
659 /* TODO: room order is being ignored? */
661 strncpy(targ, mptr->march_name, ROOMNAMELEN);
668 if (strlen(targ) > 0) {
669 gf_toroom(ipc, targ, mode);
671 scr_printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
677 * forget all rooms on current floor
679 void forget_this_floor(CtdlIPC *ipc)
682 if (curr_floor == 0) {
683 scr_printf("Can't forget this floor.\n");
686 if (floorlist[0][0] == 0)
688 scr_printf("Are you sure you want to forget all rooms on %s? ",
689 &floorlist[(int) curr_floor][0]);
693 gf_toroom(ipc, "_BASEROOM_", GF_ZAP);
698 * Figure out the physical screen dimensions, if we can
699 * WARNING: this is now called from a signal handler!
701 void check_screen_dims(void)
705 unsigned short height; /* rows */
706 unsigned short width; /* columns */
707 unsigned short xpixels;
708 unsigned short ypixels; /* pixels */
711 if (have_xterm) { /* dynamically size screen if on an xterm */
712 if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
714 screenheight = is_curses_enabled() ? (int)xwinsz.height - 1 : (int) xwinsz.height;
716 screenwidth = (int) xwinsz.width;
724 * set floor mode depending on client, server, and user settings
726 void set_floor_mode(CtdlIPC* ipc)
728 if (ipc->ServInfo.ok_floors == 0) {
729 floor_mode = 0; /* Don't use floors if the server */
731 /* doesn't support them! */
733 if (rc_floor_mode == RC_NO) { /* never use floors */
736 if (rc_floor_mode == RC_YES) { /* always use floors */
739 if (rc_floor_mode == RC_DEFAULT) { /* user choice */
740 floor_mode = ((userflags & US_FLOORS) ? 1 : 0);
746 * Set or change the user's password
748 int set_password(CtdlIPC *ipc)
754 if (strlen(rc_password) > 0) {
755 strcpy(pass1, rc_password);
756 strcpy(pass2, rc_password);
758 IFNEXPERT formout(ipc, "changepw");
759 newprompt("Enter a new password: ", pass1, -19);
760 newprompt("Enter it again to confirm: ", pass2, -19);
764 if (!strcasecmp(pass1, pass2)) {
765 CtdlIPCChangePassword(ipc, pass1, buf);
766 scr_printf("%s\n", buf);
767 offer_to_remember_password(ipc, hostbuf, portbuf, fullname, pass1);
770 scr_printf("*** They don't match... try again.\n");
778 * get info about the server we've connected to
780 void get_serv_info(CtdlIPC *ipc, char *supplied_hostname)
784 CtdlIPCServerInfo(ipc, buf);
786 /* be nice and identify ourself to the server */
787 CtdlIPCIdentifySoftware(ipc, SERVER_TYPE, 0, REV_LEVEL,
788 (ipc->isLocal ? "local" : CITADEL),
789 (supplied_hostname) ? supplied_hostname :
790 /* Look up the , in the bible if you're confused */
791 (locate_host(ipc, buf), buf), buf);
793 /* Tell the server what our preferred content formats are */
794 if ((CtdlIPCSpecifyPreferredFormats(ipc, buf, "text/html|text/plain") / 100 )== 2) {
802 * Record compare function for SortOnlineUsers()
804 int idlecmp(const void *rec1, const void *rec2) {
807 i1 = extract_long(rec1, 5);
808 i2 = extract_long(rec2, 5);
810 if (i1 < i2) return(1);
811 if (i1 > i2) return(-1);
817 * Sort the list of online users by idle time.
818 * This function frees the supplied buffer, and returns a new one
819 * to the caller. The caller is responsible for freeing the returned buffer.
821 char *SortOnlineUsers(char *listing) {
828 rows = num_tokens(listing, '\n');
829 sortbuf = malloc(rows * SIZ);
830 if (sortbuf == NULL) return(listing);
831 retbuf = malloc(rows * SIZ);
832 if (retbuf == NULL) {
837 /* Copy the list into a fixed-record-size array for sorting */
838 for (i=0; i<rows; ++i) {
840 extract_token(buf, listing, i, '\n');
841 memcpy(&sortbuf[i*SIZ], buf, SIZ);
845 qsort(sortbuf, rows, SIZ, idlecmp);
847 /* Copy back to a \n delimited list */
849 for (i=0; i<rows; ++i) {
850 strcat(retbuf, &sortbuf[i*SIZ]);
851 if (i<(rows-1)) strcat(retbuf, "\n");
859 * Display list of users currently logged on to the server
861 void who_is_online(CtdlIPC *ipc, int longlist)
863 char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ];
865 char actual_user[SIZ], actual_room[SIZ], actual_host[SIZ];
866 char clientsoft[SIZ];
868 time_t idletime, idlehours, idlemins, idlesecs;
869 int last_session = (-1);
871 char *listing = NULL;
872 int r; /* IPC response code */
881 pprintf(" User Name Room Idle From host\n");
883 pprintf(" ------------------------- -------------------- ---- ------------------------\n");
885 r = CtdlIPCOnlineUsers(ipc, &listing, &timenow, buf);
886 listing = SortOnlineUsers(listing);
888 while (strlen(listing) > 0) {
891 /* Get another line */
892 extract_token(buf, listing, 0, '\n');
893 remove_token(listing, 0, '\n');
895 extract(username, buf, 1);
896 extract(roomname, buf, 2);
897 extract(fromhost, buf, 3);
898 extract(clientsoft, buf, 4);
899 extract(flags, buf, 7);
901 idletime = timenow - extract_long(buf, 5);
902 idlehours = idletime / 3600;
903 idlemins = (idletime - (idlehours * 3600)) / 60;
904 idlesecs = (idletime - (idlehours * 3600) - (idlemins * 60));
906 if (idletime > rc_idle_threshold) {
908 while (strlen(roomname) < 20) {
909 strcat(roomname, " ");
911 strcpy(&roomname[14], "[idle]");
918 extract(actual_user, buf, 8);
919 extract(actual_room, buf, 9);
920 extract(actual_host, buf, 10);
922 pprintf(" Flags: %s\n", flags);
923 pprintf("Session: %d\n", extract_int(buf, 0));
924 pprintf(" Name: %s\n", username);
925 pprintf("In room: %s\n", roomname);
926 pprintf(" Host: %s\n", fromhost);
927 pprintf(" Client: %s\n", clientsoft);
928 pprintf(" Idle: %ld:%02ld:%02ld\n",
933 if ( (strlen(actual_user)+strlen(actual_room)+strlen(actual_host)) > 0) {
935 if (strlen(actual_user)>0) pprintf("<%s> ", actual_user);
936 if (strlen(actual_room)>0) pprintf("in <%s> ", actual_room);
937 if (strlen(actual_host)>0) pprintf("from <%s> ", actual_host);
944 if (extract_int(buf, 0) == last_session) {
947 color(BRIGHT_MAGENTA);
948 pprintf("%-3s", flags);
950 last_session = extract_int(buf, 0);
952 pprintf("%-25s ", username);
953 color(BRIGHT_MAGENTA);
955 pprintf("%-20s ", roomname);
956 if (idletime > rc_idle_threshold) {
957 /* over 1000d, must be gone fishing */
958 if (idlehours > 23999) {
961 } else if (idlehours > 239) {
965 } else if (idlehours > 9) {
966 pprintf("%1ldd%02ld",
969 /* less than 10 hours */
971 pprintf("%1ld:%02ld",
972 idlehours, idlemins);
981 pprintf("%-24s\n", fromhost);
990 void enternew(CtdlIPC *ipc, char *desc, char *buf, int maxlen)
993 snprintf(bbb, sizeof bbb, "Enter in your new %s: ", desc);
994 newprompt(bbb, buf, maxlen);
999 int shift(int argc, char **argv, int start, int count) {
1002 for (i=start; i<(argc-count); ++i) {
1003 argv[i] = argv[i+count];
1005 argc = argc - count;
1009 static void statusHook(char *s) {
1017 int main(int argc, char **argv)
1020 char aaa[100], bbb[100];/* general purpose variables */
1021 char argbuf[32]; /* command line buf */
1022 char nonce[NONCE_SIZE];
1023 char *telnet_client_host = NULL;
1024 char *sptr, *sptr2; /* USed to extract the nonce */
1025 char hexstring[MD5_HEXSTRING_SIZE];
1026 int stored_password = 0;
1028 struct ctdlipcmisc chek;
1029 struct ctdluser *myself = NULL;
1030 CtdlIPC* ipc; /* Our server connection */
1031 int r; /* IPC result code */
1033 setIPCDeathHook(screen_delete);
1034 setIPCErrorPrintf(err_printf);
1035 setCryptoStatusHook(statusHook);
1037 /* Permissions sanity check - don't run citadel setuid/setgid */
1038 if (getuid() != geteuid()) {
1039 err_printf("Please do not run citadel setuid!\n");
1041 } else if (getgid() != getegid()) {
1042 err_printf("Please do not run citadel setgid!\n");
1046 sttybbs(SB_SAVE); /* Store the old terminal parameters */
1047 load_command_set(); /* parse the citadel.rc file */
1048 sttybbs(SB_NO_INTR); /* Install the new ones */
1049 signal(SIGHUP, dropcarr); /* Cleanup gracefully if carrier is dropped */
1050 signal(SIGPIPE, dropcarr); /* Cleanup gracefully if local conn. dropped */
1051 signal(SIGTERM, dropcarr); /* Cleanup gracefully if terminated */
1052 signal(SIGCONT, catch_sigcont); /* Catch SIGCONT so we can reset terminal */
1054 signal(SIGWINCH, scr_winch); /* Window resize signal */
1058 arg_encrypt = RC_DEFAULT;
1060 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1061 arg_screen = RC_DEFAULT;
1065 * Handle command line options as if we were called like /bin/login
1066 * (i.e. from in.telnetd)
1068 for (a=0; a<argc; ++a) {
1069 if ((argc > a+1) && (!strcmp(argv[a], "-h")) ) {
1070 telnet_client_host = argv[a+1];
1071 argc = shift(argc, argv, a, 2);
1073 if (!strcmp(argv[a], "-x")) {
1075 arg_encrypt = RC_NO;
1077 argc = shift(argc, argv, a, 1);
1079 if (!strcmp(argv[a], "-X")) {
1081 arg_encrypt = RC_YES;
1082 argc = shift(argc, argv, a, 1);
1084 fprintf(stderr, "Not compiled with encryption support");
1088 if (!strcmp(argv[a], "-s")) {
1089 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1092 argc = shift(argc, argv, a, 1);
1094 if (!strcmp(argv[a], "-S")) {
1095 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1096 arg_screen = RC_YES;
1098 argc = shift(argc, argv, a, 1);
1100 if (!strcmp(argv[a], "-p")) {
1103 if (chdir(BBSDIR) < 0) {
1104 perror("can't change to " BBSDIR);
1109 * Drop privileges if necessary. We stat
1110 * citadel.config to get the uid/gid since it's
1111 * guaranteed to have the uid/gid we want.
1113 if (!getuid() || !getgid()) {
1114 if (stat(BBSDIR "/citadel.config", &st) < 0) {
1115 perror("couldn't stat citadel.config");
1118 if (!getgid() && (setgid(st.st_gid) < 0)) {
1119 perror("couldn't change gid");
1122 if (!getuid() && (setuid(st.st_uid) < 0)) {
1123 perror("couldn't change uid");
1127 scr_printf("Privileges changed to uid %d gid %d\n",
1128 getuid(), getgid());
1131 argc = shift(argc, argv, a, 1);
1138 newprompt("Connect to (return for local server): ", hostbuf, 64);
1141 sln_printf("Attaching to server... \r");
1143 ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
1146 error_printf("Can't connect: %s\n", strerror(errno));
1149 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1150 CtdlIPC_SetNetworkStatusCallback(ipc, wait_indicator);
1152 ipc_for_signal_handlers = ipc; /* KLUDGE cover your eyes */
1154 CtdlIPC_chat_recv(ipc, aaa);
1155 if (aaa[0] != '2') {
1156 scr_printf("%s\n", &aaa[4]);
1157 logoff(ipc, atoi(aaa));
1160 /* If there is a [nonce] at the end, put the nonce in <nonce>, else nonce
1164 if ((sptr = strchr(aaa, '<')) == NULL)
1170 if ((sptr2 = strchr(sptr, '>')) == NULL)
1178 strncpy(nonce, sptr, NONCE_SIZE);
1183 /* Evaluate encryption preferences */
1184 if (arg_encrypt != RC_NO && rc_encrypt != RC_NO) {
1185 if (!ipc->isLocal || arg_encrypt == RC_YES || rc_encrypt == RC_YES) {
1186 secure = (CtdlIPCStartEncryption(ipc, aaa) / 100 == 2) ? 1 : 0;
1188 error_printf("Can't encrypt: %s\n", aaa);
1193 get_serv_info(ipc, telnet_client_host);
1194 scr_printf("%-24s\n%s\n%s\n", ipc->ServInfo.software, ipc->ServInfo.humannode,
1195 ipc->ServInfo.bbs_city);
1198 status_line(ipc->ServInfo.humannode, ipc->ServInfo.bbs_city, NULL,
1201 screenwidth = 80; /* default screen dimensions */
1204 scr_printf(" pause next stop\n");
1205 scr_printf(" ctrl-s ctrl-o ctrl-c\n\n");
1206 formout(ipc, "hello"); /* print the opening greeting */
1209 GSTA: /* See if we have a username and password on disk */
1210 if (rc_remember_passwords) {
1211 get_stored_password(hostbuf, portbuf, fullname, password);
1212 if (strlen(fullname) > 0) {
1213 r = CtdlIPCTryLogin(ipc, fullname, aaa);
1216 r = CtdlIPCTryApopPassword(ipc, make_apop_string(password, nonce, hexstring, sizeof hexstring), aaa);
1218 r = CtdlIPCTryPassword(ipc, password, aaa);
1223 load_user_info(aaa);
1224 stored_password = 1;
1227 set_stored_password(hostbuf, portbuf, "", "");
1235 if (strlen(rc_username) > 0) {
1236 strcpy(fullname, rc_username);
1238 newprompt("Enter your name: ", fullname, 29);
1241 if (!strcasecmp(fullname, "new")) { /* just in case */
1242 scr_printf("Please enter the name you wish to log in with.\n");
1245 (!strcasecmp(fullname, "bbs"))
1246 || (!strcasecmp(fullname, "new"))
1247 || (strlen(fullname) == 0));
1249 if (!strcasecmp(fullname, "off")) {
1253 /* sign on to the server */
1254 r = CtdlIPCTryLogin(ipc, fullname, aaa);
1258 /* password authentication */
1259 if (strlen(rc_password) > 0) {
1260 strcpy(password, rc_password);
1262 newprompt("\rPlease enter your password: ", password, -19);
1267 r = CtdlIPCTryApopPassword(ipc, make_apop_string(password, nonce, hexstring, sizeof hexstring), aaa);
1269 r = CtdlIPCTryPassword(ipc, password, aaa);
1273 load_user_info(aaa);
1274 offer_to_remember_password(ipc, hostbuf, portbuf,
1275 fullname, password);
1278 scr_printf("<< wrong password >>\n");
1279 if (strlen(rc_password) > 0)
1283 NEWUSR: if (strlen(rc_password) == 0) {
1284 scr_printf("'%s' not found.\n"
1285 "Do you want to create a new account with this name? ",
1291 r = CtdlIPCCreateUser(ipc, fullname, 1, aaa);
1293 scr_printf("%s\n", aaa);
1296 load_user_info(aaa);
1298 while (set_password(ipc) != 0);
1301 enter_config(ipc, 1);
1304 /* Switch color support on or off if we're in user mode */
1305 if (rc_ansi_color == 3) {
1306 if (userflags & US_COLOR)
1312 color(BRIGHT_WHITE);
1313 scr_printf("\n%s\nAccess level: %d (%s)\n"
1314 "User #%ld / Login #%d",
1315 fullname, axlevel, axdefs[(int) axlevel],
1316 usernum, timescalled);
1317 if (lastcall > 0L) {
1318 scr_printf(" / Last login: %s",
1319 asctime(localtime(&lastcall)));
1323 r = CtdlIPCMiscCheck(ipc, &chek, aaa);
1329 scr_printf("*** You have a new private message in Mail>\n");
1331 scr_printf("*** You have %d new private messages in Mail>\n", b);
1333 if (strlen(rc_gotmail_cmd) > 0) {
1334 system(rc_gotmail_cmd);
1337 if ((axlevel >= 6) && (chek.needvalid > 0)) {
1338 scr_printf("*** Users need validation\n");
1340 if (chek.needregis > 0) {
1341 scr_printf("*** Please register.\n");
1342 formout(ipc, "register");
1346 /* Make up some temporary filenames for use in various parts of the
1347 * program. Don't mess with these once they've been set, because we
1348 * will be unlinking them later on in the program and we don't
1349 * want to delete something that we didn't create. */
1350 snprintf(temp, sizeof temp, tmpnam(NULL));
1351 snprintf(temp2, sizeof temp2, tmpnam(NULL));
1352 snprintf(tempdir, sizeof tempdir, tmpnam(NULL));
1354 /* Get screen dimensions. First we go to a default of 80x24. Then
1355 * we try to get the user's actual screen dimensions off the server.
1356 * However, if we're running on an xterm, all this stuff is
1357 * irrelevant because we're going to dynamically size the screen
1358 * during the session.
1362 r = CtdlIPCGetConfig(ipc, &myself, aaa);
1364 screenwidth = myself->USscreenwidth;
1365 screenheight = myself->USscreenheight;
1367 if (getenv("TERM") != NULL)
1368 if (!strcmp(getenv("TERM"), "xterm")) {
1372 check_screen_dims();
1375 set_floor_mode(ipc);
1377 /* Enter the lobby */
1378 dotgoto(ipc, "_BASEROOM_", 1, 0);
1380 /* Main loop for the system... user is logged in. */
1384 readmsgs(ipc, LastMessages, ReadForward, 5);
1386 readmsgs(ipc, NewMessages, ReadForward, 0);
1388 /* MAIN COMMAND LOOP */
1390 mcmd = getcmd(ipc, argbuf); /* Get keyboard command */
1393 check_screen_dims(); /* if xterm, get screen size */
1399 formout(ipc, "help");
1412 /* Only m.author is used */
1413 struct ctdlipcmessage m;
1414 newprompt("What do you want your username to be? ", m.author, USERNAME_SIZE - 1);
1415 r = CtdlIPCPostMessage(ipc, 2, &m, aaa);
1417 scr_printf("%s\n", aaa);
1422 case 5: /* <G>oto */
1426 case 47: /* <A>bandon */
1427 if (!rc_alt_semantics) {
1432 case 90: /* <.A>bandon */
1433 if (!rc_alt_semantics)
1435 dotgoto(ipc, argbuf, 0, 0);
1437 case 58: /* <M>ail */
1439 dotgoto(ipc, "_MAIL_", 1, 0);
1442 if (strlen(argbuf) > 0) {
1444 dotgoto(ipc, argbuf, 0, 0);
1448 if (strlen(argbuf) > 0) {
1449 if (rc_alt_semantics) {
1452 dotgoto(ipc, argbuf, 0, 0);
1455 case 95: /* what exactly is the numbering scheme supposed to be anyway? */
1456 dotungoto(ipc, argbuf);
1459 readmsgs(ipc, AllMessages, ReadForward, 0);
1462 readmsgs(ipc, LastMessages, ReadForward, 5);
1465 readmsgs(ipc, NewMessages, ReadForward, 0);
1468 readmsgs(ipc, AllMessages, ReadReverse, 0);
1471 readmsgs(ipc, OldMessages, ReadReverse, 0);
1474 readmsgs(ipc, LastMessages, ReadForward,
1491 userlist(ipc, argbuf);
1549 if (!rc_alt_semantics) {
1561 cli_image_upload(ipc, "_userpic_");
1564 cli_image_upload(ipc, "_roompic_");
1568 snprintf(aaa, sizeof aaa, "_floorpic_|%d", curr_floor);
1569 cli_image_upload(ipc, aaa);
1573 enternew(ipc, "roomname", aaa, 20);
1574 r = CtdlIPCChangeRoomname(ipc, aaa, bbb);
1576 scr_printf("\n%s\n", bbb);
1579 enternew(ipc, "hostname", aaa, 25);
1580 r = CtdlIPCChangeHostname(ipc, aaa, bbb);
1582 scr_printf("\n%s\n", bbb);
1585 enternew(ipc, "username", aaa, 32);
1586 r = CtdlIPCChangeUsername(ipc, aaa, bbb);
1588 scr_printf("\n%s\n", bbb);
1598 display_help(ipc, argbuf);
1602 formout(ipc, "register");
1607 scr_printf("Are you sure (y/n)? ");
1609 if (!rc_alt_semantics)
1617 scr_printf("All users will be disconnected! "
1618 "Really terminate the server? ");
1620 if (!rc_alt_semantics)
1622 r = CtdlIPCTerminateServerNow(ipc, aaa);
1623 scr_printf("%s\n", aaa);
1632 scr_printf("Do you really want to schedule a "
1633 "server shutdown? ");
1635 r = CtdlIPCTerminateServerScheduled(ipc, 1, aaa);
1639 "The Citadel server will terminate when all users are logged off.\n"
1643 "The Citadel server will not terminate.\n"
1651 network_config_management(ipc, "listrecp",
1652 "Message-by-message mailing list recipients");
1656 network_config_management(ipc, "digestrecp",
1657 "Digest mailing list recipients");
1661 network_config_management(ipc, "ignet_push_share",
1662 "Nodes with which we share this room");
1666 do_ignet_configuration(ipc);
1670 do_filterlist_configuration(ipc);
1674 if (rc_alt_semantics) {
1687 sttybbs(SB_RESTORE);
1688 snprintf(aaa, sizeof aaa, "USERNAME=\042%s\042; export USERNAME;"
1689 "exec ./subsystem %ld %d %d", fullname,
1690 usernum, screenwidth, axlevel);
1692 sttybbs(SB_NO_INTR);
1695 scr_printf("*** Can't run doors when server is not local.\n");
1700 who_is_online(ipc, 0);
1704 who_is_online(ipc, 1);
1708 who_is_online(ipc, 2);
1712 do_system_configuration(ipc);
1716 do_internet_configuration(ipc);
1720 check_message_base(ipc);
1732 enter_config(ipc, 2);
1736 enter_config(ipc, 0);
1737 set_floor_mode(ipc);
1741 enter_config(ipc, 3);
1742 set_floor_mode(ipc);
1746 gotofloor(ipc, argbuf, GF_GOTO);
1750 gotofloor(ipc, argbuf, GF_SKIP);
1754 forget_this_floor(ipc);
1782 knrooms(ipc, floor_mode);
1792 misc_server_cmd(ipc, argbuf);
1796 edit_system_message(ipc, argbuf);
1820 default: /* allow some math on the command */
1821 /* commands 100... to 100+MAX_EDITORS-1 will
1822 call the appropriate editor... in other
1823 words, command numbers 100+ will match
1824 the citadel.rc keys editor0, editor1, etc.*/
1825 if (mcmd >= 100 && mcmd < (100+MAX_EDITORS))
1827 /* entmsg mode >=2 select editor */
1828 entmsg(ipc, 0, mcmd - 100 + 2);
1832 } while (termn8 == 0);
1834 TERMN8: scr_printf("%s logged out.", fullname);
1836 color(ORIGINAL_PAIR);
1838 while (march != NULL) {
1839 remove_march(march->march_name, 0);
1842 sln_printf("\n\nType 'off' to disconnect, or next user...\n");
1845 if ((mcmd == 29) || (mcmd == 15)) {
1847 sttybbs(SB_RESTORE);
1848 formout(ipc, "goodbye");