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);
631 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, tofloor, &mptr, buf);
633 struct march *tmp = mptr;
635 /* TODO: room order is being ignored? */
637 strncpy(targ, mptr->march_name, ROOMNAMELEN);
644 if (strlen(targ) > 0) {
645 gf_toroom(ipc, targ, mode);
647 scr_printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
653 * forget all rooms on current floor
655 void forget_this_floor(CtdlIPC *ipc)
658 if (curr_floor == 0) {
659 scr_printf("Can't forget this floor.\n");
662 if (floorlist[0][0] == 0)
664 scr_printf("Are you sure you want to forget all rooms on %s? ",
665 &floorlist[(int) curr_floor][0]);
669 gf_toroom(ipc, "_BASEROOM_", GF_ZAP);
674 * Figure out the physical screen dimensions, if we can
675 * WARNING: this is now called from a signal handler!
677 void check_screen_dims(void)
681 unsigned short height; /* rows */
682 unsigned short width; /* columns */
683 unsigned short xpixels;
684 unsigned short ypixels; /* pixels */
687 if (have_xterm) { /* dynamically size screen if on an xterm */
688 if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
690 screenheight = is_curses_enabled() ? (int)xwinsz.height - 1 : (int) xwinsz.height;
692 screenwidth = (int) xwinsz.width;
700 * set floor mode depending on client, server, and user settings
702 void set_floor_mode(CtdlIPC* ipc)
704 if (ipc->ServInfo.ok_floors == 0) {
705 floor_mode = 0; /* Don't use floors if the server */
707 /* doesn't support them! */
709 if (rc_floor_mode == RC_NO) { /* never use floors */
712 if (rc_floor_mode == RC_YES) { /* always use floors */
715 if (rc_floor_mode == RC_DEFAULT) { /* user choice */
716 floor_mode = ((userflags & US_FLOORS) ? 1 : 0);
722 * Set or change the user's password
724 int set_password(CtdlIPC *ipc)
730 if (strlen(rc_password) > 0) {
731 strcpy(pass1, rc_password);
732 strcpy(pass2, rc_password);
734 IFNEXPERT formout(ipc, "changepw");
735 newprompt("Enter a new password: ", pass1, -19);
736 newprompt("Enter it again to confirm: ", pass2, -19);
740 if (!strcasecmp(pass1, pass2)) {
741 CtdlIPCChangePassword(ipc, pass1, buf);
742 scr_printf("%s\n", buf);
743 offer_to_remember_password(ipc, hostbuf, portbuf, fullname, pass1);
746 scr_printf("*** They don't match... try again.\n");
754 * get info about the server we've connected to
756 void get_serv_info(CtdlIPC *ipc, char *supplied_hostname)
760 CtdlIPCServerInfo(ipc, buf);
762 /* be nice and identify ourself to the server */
763 CtdlIPCIdentifySoftware(ipc, SERVER_TYPE, 0, REV_LEVEL,
764 (ipc->isLocal ? "local" : CITADEL),
765 (supplied_hostname) ? supplied_hostname :
766 /* Look up the , in the bible if you're confused */
767 (locate_host(ipc, buf), buf), buf);
769 /* Tell the server what our preferred content formats are */
770 if ((CtdlIPCSpecifyPreferredFormats(ipc, buf, "text/html|text/plain") / 100 )== 2) {
778 * Record compare function for SortOnlineUsers()
780 int idlecmp(const void *rec1, const void *rec2) {
783 i1 = extract_long(rec1, 5);
784 i2 = extract_long(rec2, 5);
786 if (i1 < i2) return(1);
787 if (i1 > i2) return(-1);
793 * Sort the list of online users by idle time.
794 * This function frees the supplied buffer, and returns a new one
795 * to the caller. The caller is responsible for freeing the returned buffer.
797 char *SortOnlineUsers(char *listing) {
804 rows = num_tokens(listing, '\n');
805 sortbuf = malloc(rows * SIZ);
806 if (sortbuf == NULL) return(listing);
807 retbuf = malloc(rows * SIZ);
808 if (retbuf == NULL) {
813 /* Copy the list into a fixed-record-size array for sorting */
814 for (i=0; i<rows; ++i) {
816 extract_token(buf, listing, i, '\n');
817 memcpy(&sortbuf[i*SIZ], buf, SIZ);
821 qsort(sortbuf, rows, SIZ, idlecmp);
823 /* Copy back to a \n delimited list */
825 for (i=0; i<rows; ++i) {
826 strcat(retbuf, &sortbuf[i*SIZ]);
827 if (i<(rows-1)) strcat(retbuf, "\n");
835 * Display list of users currently logged on to the server
837 void who_is_online(CtdlIPC *ipc, int longlist)
839 char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ];
841 char actual_user[SIZ], actual_room[SIZ], actual_host[SIZ];
842 char clientsoft[SIZ];
844 time_t idletime, idlehours, idlemins, idlesecs;
845 int last_session = (-1);
847 char *listing = NULL;
848 int r; /* IPC response code */
857 pprintf(" User Name Room Idle From host\n");
859 pprintf(" ------------------------- -------------------- ---- ------------------------\n");
861 r = CtdlIPCOnlineUsers(ipc, &listing, &timenow, buf);
862 listing = SortOnlineUsers(listing);
864 while (strlen(listing) > 0) {
867 /* Get another line */
868 extract_token(buf, listing, 0, '\n');
869 remove_token(listing, 0, '\n');
871 extract(username, buf, 1);
872 extract(roomname, buf, 2);
873 extract(fromhost, buf, 3);
874 extract(clientsoft, buf, 4);
875 extract(flags, buf, 7);
877 idletime = timenow - extract_long(buf, 5);
878 idlehours = idletime / 3600;
879 idlemins = (idletime - (idlehours * 3600)) / 60;
880 idlesecs = (idletime - (idlehours * 3600) - (idlemins * 60));
882 if (idletime > rc_idle_threshold) {
884 while (strlen(roomname) < 20) {
885 strcat(roomname, " ");
887 strcpy(&roomname[14], "[idle]");
894 extract(actual_user, buf, 8);
895 extract(actual_room, buf, 9);
896 extract(actual_host, buf, 10);
898 pprintf(" Flags: %s\n", flags);
899 pprintf("Session: %d\n", extract_int(buf, 0));
900 pprintf(" Name: %s\n", username);
901 pprintf("In room: %s\n", roomname);
902 pprintf(" Host: %s\n", fromhost);
903 pprintf(" Client: %s\n", clientsoft);
904 pprintf(" Idle: %ld:%02ld:%02ld\n",
909 if ( (strlen(actual_user)+strlen(actual_room)+strlen(actual_host)) > 0) {
911 if (strlen(actual_user)>0) pprintf("<%s> ", actual_user);
912 if (strlen(actual_room)>0) pprintf("in <%s> ", actual_room);
913 if (strlen(actual_host)>0) pprintf("from <%s> ", actual_host);
920 if (extract_int(buf, 0) == last_session) {
923 color(BRIGHT_MAGENTA);
924 pprintf("%-3s", flags);
926 last_session = extract_int(buf, 0);
928 pprintf("%-25s ", username);
929 color(BRIGHT_MAGENTA);
931 pprintf("%-20s ", roomname);
932 if (idletime > rc_idle_threshold) {
933 /* over 1000d, must be gone fishing */
934 if (idlehours > 23999) {
937 } else if (idlehours > 239) {
941 } else if (idlehours > 9) {
942 pprintf("%1ldd%02ld",
945 /* less than 10 hours */
947 pprintf("%1ld:%02ld",
948 idlehours, idlemins);
957 pprintf("%-24s\n", fromhost);
966 void enternew(CtdlIPC *ipc, char *desc, char *buf, int maxlen)
969 snprintf(bbb, sizeof bbb, "Enter in your new %s: ", desc);
970 newprompt(bbb, buf, maxlen);
975 int shift(int argc, char **argv, int start, int count) {
978 for (i=start; i<(argc-count); ++i) {
979 argv[i] = argv[i+count];
985 static void statusHook(char *s) {
993 int main(int argc, char **argv)
996 char aaa[100], bbb[100];/* general purpose variables */
997 char argbuf[32]; /* command line buf */
998 char nonce[NONCE_SIZE];
999 char *telnet_client_host = NULL;
1000 char *sptr, *sptr2; /* USed to extract the nonce */
1001 char hexstring[MD5_HEXSTRING_SIZE];
1002 int stored_password = 0;
1004 struct ctdlipcmisc chek;
1005 struct ctdluser *myself = NULL;
1006 CtdlIPC* ipc; /* Our server connection */
1007 int r; /* IPC result code */
1009 setIPCDeathHook(screen_delete);
1010 setIPCErrorPrintf(err_printf);
1011 setCryptoStatusHook(statusHook);
1013 /* Permissions sanity check - don't run citadel setuid/setgid */
1014 if (getuid() != geteuid()) {
1015 err_printf("Please do not run citadel setuid!\n");
1017 } else if (getgid() != getegid()) {
1018 err_printf("Please do not run citadel setgid!\n");
1022 sttybbs(SB_SAVE); /* Store the old terminal parameters */
1023 load_command_set(); /* parse the citadel.rc file */
1024 sttybbs(SB_NO_INTR); /* Install the new ones */
1025 signal(SIGHUP, dropcarr); /* Cleanup gracefully if carrier is dropped */
1026 signal(SIGPIPE, dropcarr); /* Cleanup gracefully if local conn. dropped */
1027 signal(SIGTERM, dropcarr); /* Cleanup gracefully if terminated */
1028 signal(SIGCONT, catch_sigcont); /* Catch SIGCONT so we can reset terminal */
1030 signal(SIGWINCH, scr_winch); /* Window resize signal */
1034 arg_encrypt = RC_DEFAULT;
1036 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1037 arg_screen = RC_DEFAULT;
1041 * Handle command line options as if we were called like /bin/login
1042 * (i.e. from in.telnetd)
1044 for (a=0; a<argc; ++a) {
1045 if ((argc > a+1) && (!strcmp(argv[a], "-h")) ) {
1046 telnet_client_host = argv[a+1];
1047 argc = shift(argc, argv, a, 2);
1049 if (!strcmp(argv[a], "-x")) {
1051 arg_encrypt = RC_NO;
1053 argc = shift(argc, argv, a, 1);
1055 if (!strcmp(argv[a], "-X")) {
1057 arg_encrypt = RC_YES;
1058 argc = shift(argc, argv, a, 1);
1060 fprintf(stderr, "Not compiled with encryption support");
1064 if (!strcmp(argv[a], "-s")) {
1065 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1068 argc = shift(argc, argv, a, 1);
1070 if (!strcmp(argv[a], "-S")) {
1071 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1072 arg_screen = RC_YES;
1074 argc = shift(argc, argv, a, 1);
1076 if (!strcmp(argv[a], "-p")) {
1079 if (chdir(BBSDIR) < 0) {
1080 perror("can't change to " BBSDIR);
1085 * Drop privileges if necessary. We stat
1086 * citadel.config to get the uid/gid since it's
1087 * guaranteed to have the uid/gid we want.
1089 if (!getuid() || !getgid()) {
1090 if (stat(BBSDIR "/citadel.config", &st) < 0) {
1091 perror("couldn't stat citadel.config");
1094 if (!getgid() && (setgid(st.st_gid) < 0)) {
1095 perror("couldn't change gid");
1098 if (!getuid() && (setuid(st.st_uid) < 0)) {
1099 perror("couldn't change uid");
1103 scr_printf("Privileges changed to uid %d gid %d\n",
1104 getuid(), getgid());
1107 argc = shift(argc, argv, a, 1);
1114 newprompt("Connect to (return for local server): ", hostbuf, 64);
1117 sln_printf("Attaching to server... \r");
1119 ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
1122 error_printf("Can't connect: %s\n", strerror(errno));
1125 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1126 CtdlIPC_SetNetworkStatusCallback(ipc, wait_indicator);
1128 ipc_for_signal_handlers = ipc; /* KLUDGE cover your eyes */
1130 CtdlIPC_getline(ipc, aaa);
1131 if (aaa[0] != '2') {
1132 scr_printf("%s\n", &aaa[4]);
1133 logoff(ipc, atoi(aaa));
1136 /* If there is a [nonce] at the end, put the nonce in <nonce>, else nonce
1140 if ((sptr = strchr(aaa, '<')) == NULL)
1146 if ((sptr2 = strchr(sptr, '>')) == NULL)
1154 strncpy(nonce, sptr, NONCE_SIZE);
1159 /* Evaluate encryption preferences */
1160 if (arg_encrypt != RC_NO && rc_encrypt != RC_NO) {
1161 if (!ipc->isLocal || arg_encrypt == RC_YES || rc_encrypt == RC_YES) {
1162 secure = (CtdlIPCStartEncryption(ipc, aaa) / 100 == 2) ? 1 : 0;
1164 error_printf("Can't encrypt: %s\n", aaa);
1169 get_serv_info(ipc, telnet_client_host);
1170 scr_printf("%-24s\n%s\n%s\n", ipc->ServInfo.software, ipc->ServInfo.humannode,
1171 ipc->ServInfo.bbs_city);
1174 status_line(ipc->ServInfo.humannode, ipc->ServInfo.bbs_city, NULL,
1177 screenwidth = 80; /* default screen dimensions */
1180 scr_printf(" pause next stop\n");
1181 scr_printf(" ctrl-s ctrl-o ctrl-c\n\n");
1182 formout(ipc, "hello"); /* print the opening greeting */
1185 GSTA: /* See if we have a username and password on disk */
1186 if (rc_remember_passwords) {
1187 get_stored_password(hostbuf, portbuf, fullname, password);
1188 if (strlen(fullname) > 0) {
1189 r = CtdlIPCTryLogin(ipc, fullname, aaa);
1192 r = CtdlIPCTryApopPassword(ipc, make_apop_string(password, nonce, hexstring, sizeof hexstring), aaa);
1194 r = CtdlIPCTryPassword(ipc, password, aaa);
1199 load_user_info(aaa);
1200 stored_password = 1;
1203 set_stored_password(hostbuf, portbuf, "", "");
1211 if (strlen(rc_username) > 0) {
1212 strcpy(fullname, rc_username);
1214 newprompt("Enter your name: ", fullname, 29);
1217 if (!strcasecmp(fullname, "new")) { /* just in case */
1218 scr_printf("Please enter the name you wish to log in with.\n");
1221 (!strcasecmp(fullname, "bbs"))
1222 || (!strcasecmp(fullname, "new"))
1223 || (strlen(fullname) == 0));
1225 if (!strcasecmp(fullname, "off")) {
1229 /* sign on to the server */
1230 r = CtdlIPCTryLogin(ipc, fullname, aaa);
1234 /* password authentication */
1235 if (strlen(rc_password) > 0) {
1236 strcpy(password, rc_password);
1238 newprompt("\rPlease enter your password: ", password, -19);
1243 r = CtdlIPCTryApopPassword(ipc, make_apop_string(password, nonce, hexstring, sizeof hexstring), aaa);
1245 r = CtdlIPCTryPassword(ipc, password, aaa);
1249 load_user_info(aaa);
1250 offer_to_remember_password(ipc, hostbuf, portbuf,
1251 fullname, password);
1254 scr_printf("<< wrong password >>\n");
1255 if (strlen(rc_password) > 0)
1259 NEWUSR: if (strlen(rc_password) == 0) {
1260 scr_printf("'%s' not found.\n"
1261 "Do you want to create a new account with this name? ",
1267 r = CtdlIPCCreateUser(ipc, fullname, 1, aaa);
1269 scr_printf("%s\n", aaa);
1272 load_user_info(aaa);
1274 while (set_password(ipc) != 0);
1277 enter_config(ipc, 1);
1280 /* Switch color support on or off if we're in user mode */
1281 if (rc_ansi_color == 3) {
1282 if (userflags & US_COLOR)
1288 color(BRIGHT_WHITE);
1289 scr_printf("\n%s\nAccess level: %d (%s)\n"
1290 "User #%ld / Login #%d",
1291 fullname, axlevel, axdefs[(int) axlevel],
1292 usernum, timescalled);
1293 if (lastcall > 0L) {
1294 scr_printf(" / Last login: %s",
1295 asctime(localtime(&lastcall)));
1299 r = CtdlIPCMiscCheck(ipc, &chek, aaa);
1305 scr_printf("*** You have a new private message in Mail>\n");
1307 scr_printf("*** You have %d new private messages in Mail>\n", b);
1309 if (strlen(rc_gotmail_cmd) > 0) {
1310 system(rc_gotmail_cmd);
1313 if ((axlevel >= 6) && (chek.needvalid > 0)) {
1314 scr_printf("*** Users need validation\n");
1316 if (chek.needregis > 0) {
1317 scr_printf("*** Please register.\n");
1318 formout(ipc, "register");
1322 /* Make up some temporary filenames for use in various parts of the
1323 * program. Don't mess with these once they've been set, because we
1324 * will be unlinking them later on in the program and we don't
1325 * want to delete something that we didn't create. */
1326 snprintf(temp, sizeof temp, tmpnam(NULL));
1327 snprintf(temp2, sizeof temp2, tmpnam(NULL));
1328 snprintf(tempdir, sizeof tempdir, tmpnam(NULL));
1330 /* Get screen dimensions. First we go to a default of 80x24. Then
1331 * we try to get the user's actual screen dimensions off the server.
1332 * However, if we're running on an xterm, all this stuff is
1333 * irrelevant because we're going to dynamically size the screen
1334 * during the session.
1338 r = CtdlIPCGetConfig(ipc, &myself, aaa);
1340 screenwidth = myself->USscreenwidth;
1341 screenheight = myself->USscreenheight;
1343 if (getenv("TERM") != NULL)
1344 if (!strcmp(getenv("TERM"), "xterm")) {
1348 check_screen_dims();
1351 set_floor_mode(ipc);
1353 /* Enter the lobby */
1354 dotgoto(ipc, "_BASEROOM_", 1, 0);
1356 /* Main loop for the system... user is logged in. */
1360 readmsgs(ipc, LastMessages, ReadForward, 5);
1362 readmsgs(ipc, NewMessages, ReadForward, 0);
1364 /* MAIN COMMAND LOOP */
1366 mcmd = getcmd(ipc, argbuf); /* Get keyboard command */
1369 check_screen_dims(); /* if xterm, get screen size */
1375 formout(ipc, "help");
1387 newprompt("What do you want your username to be? ", aaa, 32);
1388 snprintf(bbb, sizeof bbb, "ENT0 2|0|0|0|%s", aaa);
1389 CtdlIPC_putline(ipc, bbb);
1390 CtdlIPC_getline(ipc, aaa);
1391 if (strncmp("200", aaa, 3))
1392 scr_printf("\n%s\n", aaa);
1396 case 5: /* <G>oto */
1400 case 47: /* <A>bandon */
1401 if (!rc_alt_semantics) {
1406 case 90: /* <.A>bandon */
1407 if (!rc_alt_semantics)
1409 dotgoto(ipc, argbuf, 0, 0);
1411 case 58: /* <M>ail */
1413 dotgoto(ipc, "_MAIL_", 1, 0);
1416 if (strlen(argbuf) > 0) {
1418 dotgoto(ipc, argbuf, 0, 0);
1422 if (strlen(argbuf) > 0) {
1423 if (rc_alt_semantics) {
1426 dotgoto(ipc, argbuf, 0, 0);
1429 case 95: /* what exactly is the numbering scheme supposed to be anyway? */
1430 dotungoto(ipc, argbuf);
1433 readmsgs(ipc, AllMessages, ReadForward, 0);
1436 readmsgs(ipc, LastMessages, ReadForward, 5);
1439 readmsgs(ipc, NewMessages, ReadForward, 0);
1442 readmsgs(ipc, AllMessages, ReadReverse, 0);
1445 readmsgs(ipc, OldMessages, ReadReverse, 0);
1448 readmsgs(ipc, LastMessages, ReadForward,
1465 userlist(ipc, argbuf);
1523 if (!rc_alt_semantics) {
1535 cli_image_upload(ipc, "_userpic_");
1538 cli_image_upload(ipc, "_roompic_");
1542 snprintf(aaa, sizeof aaa, "_floorpic_|%d", curr_floor);
1543 cli_image_upload(ipc, aaa);
1547 enternew(ipc, "roomname", aaa, 20);
1548 r = CtdlIPCChangeRoomname(ipc, aaa, bbb);
1550 scr_printf("\n%s\n", aaa);
1553 enternew(ipc, "hostname", aaa, 25);
1554 r = CtdlIPCChangeHostname(ipc, aaa, bbb);
1556 scr_printf("\n%s\n", aaa);
1559 enternew(ipc, "username", aaa, 32);
1560 r = CtdlIPCChangeUsername(ipc, aaa, bbb);
1562 scr_printf("\n%s\n", aaa);
1572 display_help(ipc, argbuf);
1576 formout(ipc, "register");
1581 scr_printf("Are you sure (y/n)? ");
1583 if (!rc_alt_semantics)
1591 scr_printf("All users will be disconnected! "
1592 "Really terminate the server? ");
1594 if (!rc_alt_semantics)
1596 r = CtdlIPCTerminateServerNow(ipc, aaa);
1597 scr_printf("%s\n", aaa);
1606 scr_printf("Do you really want to schedule a "
1607 "server shutdown? ");
1609 r = CtdlIPCTerminateServerScheduled(ipc, 1, aaa);
1613 "The Citadel server will terminate when all users are logged off.\n"
1617 "The Citadel server will not terminate.\n"
1625 network_config_management(ipc, "listrecp",
1626 "Message-by-message mailing list recipients");
1630 network_config_management(ipc, "digestrecp",
1631 "Digest mailing list recipients");
1635 network_config_management(ipc, "ignet_push_share",
1636 "Nodes with which we share this room");
1640 do_ignet_configuration(ipc);
1644 do_filterlist_configuration(ipc);
1648 if (rc_alt_semantics) {
1661 sttybbs(SB_RESTORE);
1662 snprintf(aaa, sizeof aaa, "USERNAME=\042%s\042; export USERNAME;"
1663 "exec ./subsystem %ld %d %d", fullname,
1664 usernum, screenwidth, axlevel);
1666 sttybbs(SB_NO_INTR);
1669 scr_printf("*** Can't run doors when server is not local.\n");
1674 who_is_online(ipc, 0);
1678 who_is_online(ipc, 1);
1682 who_is_online(ipc, 2);
1686 do_system_configuration(ipc);
1690 do_internet_configuration(ipc);
1694 check_message_base(ipc);
1706 enter_config(ipc, 2);
1710 enter_config(ipc, 0);
1711 set_floor_mode(ipc);
1715 enter_config(ipc, 3);
1716 set_floor_mode(ipc);
1720 gotofloor(ipc, argbuf, GF_GOTO);
1724 gotofloor(ipc, argbuf, GF_SKIP);
1728 forget_this_floor(ipc);
1756 knrooms(ipc, floor_mode);
1766 misc_server_cmd(ipc, argbuf);
1770 edit_system_message(ipc, argbuf);
1794 default: /* allow some math on the command */
1795 /* commands 100... to 100+MAX_EDITORS-1 will
1796 call the appropriate editor... in other
1797 words, command numbers 100+ will match
1798 the citadel.rc keys editor0, editor1, etc.*/
1799 if (mcmd >= 100 && mcmd < (100+MAX_EDITORS))
1801 /* entmsg mode >=2 select editor */
1802 entmsg(ipc, 0, mcmd - 100 + 2);
1806 } while (termn8 == 0);
1808 TERMN8: scr_printf("%s logged out.", fullname);
1810 color(ORIGINAL_PAIR);
1812 while (march != NULL) {
1813 remove_march(march->march_name, 0);
1816 sln_printf("\n\nType 'off' to disconnect, or next user...\n");
1819 if ((mcmd == 29) || (mcmd == 15)) {
1821 sttybbs(SB_RESTORE);
1822 formout(ipc, "goodbye");