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"
53 #include "citadel_dirs.h"
57 #define IFEXPERT if (userflags&US_EXPERT)
58 #define IFNEXPERT if ((userflags&US_EXPERT)==0)
59 #define IFAIDE if (axlevel>=6)
60 #define IFNAIDE if (axlevel<6)
62 struct march *march = NULL;
64 /* globals associated with the client program */
65 char temp[PATH_MAX]; /* Name of general-purpose temp file */
66 char temp2[PATH_MAX]; /* Name of general-purpose temp file */
67 char tempdir[PATH_MAX]; /* Name of general-purpose temp directory */
68 char editor_paths[MAX_EDITORS][SIZ]; /* paths to external editors */
69 char printcmd[SIZ]; /* print command */
70 int editor_pid = (-1);
71 char fullname[USERNAME_SIZE];
75 char room_name[ROOMNAMELEN];
76 char *uglist[UGLISTLEN]; /* size of the ungoto list */
77 long uglistlsn[UGLISTLEN]; /* current read position for all the ungoto's. Not going to make any friends with this one. */
79 char is_mail = 0; /* nonzero when we're in a mail room */
80 char axlevel = 0; /* access level */
81 char is_room_aide = 0; /* boolean flag, 1 if room aide */
85 long usernum = 0L; /* user number */
86 time_t lastcall = 0L; /* Date/time of previous login */
88 long highest_msg_read; /* used for <A>bandon room cmd */
89 long maxmsgnum; /* used for <G>oto */
91 char have_xterm = 0; /* are we running on an xterm? */
92 char rc_username[USERNAME_SIZE];
98 char curr_floor = 0; /* number of current floor */
99 char floorlist[128][SIZ]; /* names of floors */
100 int termn8 = 0; /* Set to nonzero to cause a logoff */
101 int secure; /* Set to nonzero when wire is encrypted */
102 int can_do_msg4 = 0; /* Set to nonzero if the server can handle MSG4 commands */
104 extern char instant_msgs; /* instant messages waiting! */
105 extern int rc_ansi_color; /* ansi color value from citadel.rc */
106 extern int next_lazy_cmd;
108 CtdlIPC *ipc_for_signal_handlers; /* KLUDGE cover your eyes */
111 * here is our 'clean up gracefully and exit' routine
113 void ctdl_logoff(char *file, int line, CtdlIPC *ipc, int code)
117 if (editor_pid > 0) { /* kill the editor if it's running */
118 kill(editor_pid, SIGHUP);
121 /* Free the ungoto list */
122 for (lp = 0; lp < uglistsize; lp++) {
126 /* Shut down the server connection ... but not if the logoff code is 3,
127 * because that means we're exiting because we already lost the server.
134 * now clean up various things
142 /* Violently kill off any child processes if Citadel is
145 if (getppid() == 1) {
146 kill(0 - getpgrp(), SIGTERM);
148 kill(0 - getpgrp(), SIGKILL);
150 color(ORIGINAL_PAIR); /* Restore the old color settings */
151 stty_ctdl(SB_RESTORE); /* return the old terminal settings */
153 * uncomment the following if you need to know why Citadel exited
154 printf("*** Exit code %d at %s:%d\n", code, file, line);
157 exit(code); /* exit with the proper exit code */
163 * signal catching function for hangups...
165 void dropcarr(int signum)
167 logoff(NULL, 3); /* No IPC when server's already gone! */
173 * catch SIGCONT to reset terminal modes when were are put back into the
176 void catch_sigcont(int signum)
179 signal(SIGCONT, catch_sigcont);
183 /* general purpose routines */
186 void formout(CtdlIPC *ipc, char *name)
188 int r; /* IPC return code */
192 r = CtdlIPCSystemMessage(ipc, name, &text, buf);
194 scr_printf("%s\n", buf);
198 fmout(screenwidth, NULL, text, NULL,
199 ((userflags & US_PAGINATOR) ? 1 : 0),
206 void userlist(CtdlIPC *ipc, char *patn)
212 int r; /* IPC response code */
213 char *listing = NULL;
215 r = CtdlIPCUserListing(ipc, patn, &listing, buf);
217 pprintf("%s\n", buf);
221 pprintf(" User Name Num L LastCall Calls Posts\n");
222 pprintf("------------------------- ----- - ---------- ----- -----\n");
223 if (listing != NULL) while (strlen(listing) > 0) {
224 extract_token(buf, listing, 0, '\n', sizeof buf);
225 remove_token(listing, 0, '\n');
227 if (sigcaught == 0) {
228 extract_token(fl, buf, 0, '|', sizeof fl);
229 if (pattern(fl, patn) >= 0) {
230 pprintf("%-25s ", fl);
231 pprintf("%5ld %d ", extract_long(buf, 2),
232 extract_int(buf, 1));
233 lc = extract_long(buf, 3);
234 localtime_r(&lc, &tmbuf);
235 pprintf("%02d/%02d/%04d ",
238 (tmbuf.tm_year + 1900));
239 pprintf("%5ld %5ld\n", extract_long(buf, 4), extract_long(buf, 5));
250 * grab assorted info about the user...
252 void load_user_info(char *params)
254 extract_token(fullname, params, 0, '|', sizeof fullname);
255 axlevel = extract_int(params, 1);
256 timescalled = extract_int(params, 2);
257 posted = extract_int(params, 3);
258 userflags = extract_int(params, 4);
259 usernum = extract_long(params, 5);
260 lastcall = extract_long(params, 6);
265 * Remove a room from the march list. 'floornum' is ignored unless
266 * 'roomname' is set to _FLOOR_, in which case all rooms on the requested
267 * floor will be removed from the march list.
269 void remove_march(char *roomname, int floornum)
271 struct march *mptr, *mptr2;
276 if ((!strcasecmp(march->march_name, roomname))
277 || ((!strcasecmp(roomname, "_FLOOR_")) && (march->march_floor == floornum))) {
284 for (mptr = march; mptr != NULL; mptr = mptr->next) {
286 if ((!strcasecmp(mptr->march_name, roomname))
287 || ((!strcasecmp(roomname, "_FLOOR_"))
288 && (mptr->march_floor == floornum))) {
290 mptr2->next = mptr->next;
301 * Locate the room on the march list which we most want to go to. Each room
302 * is measured given a "weight" of preference based on various factors.
304 char *pop_march(int desired_floor)
306 static char TheRoom[ROOMNAMELEN];
308 int TheOrder = 32767;
311 struct march *mptr = NULL;
313 strcpy(TheRoom, "_BASEROOM_");
317 for (mptr = march; mptr != NULL; mptr = mptr->next) {
319 if ((strcasecmp(mptr->march_name, "_BASEROOM_")))
320 weight = weight + 10000;
321 if (mptr->march_floor == desired_floor)
322 weight = weight + 5000;
324 weight = weight + ((128 - (mptr->march_floor)) * 128);
325 weight = weight + (128 - (mptr->march_order));
327 if (weight > TheWeight) {
329 strcpy(TheRoom, mptr->march_name);
330 TheFloor = mptr->march_floor;
331 TheOrder = mptr->march_order;
339 * jump directly to a room
341 void dotgoto(CtdlIPC *ipc, char *towhere, int display_name, int fromungoto)
343 char aaa[SIZ], bbb[SIZ];
345 int newmailcount = 0;
346 int partial_match, best_match;
348 int ugpos = uglistsize;
349 int r; /* IPC result code */
350 struct ctdlipcroom *room = NULL;
352 /* store ungoto information */
353 if (fromungoto == 0) {
354 /* sloppy slide them all down, hey it's the client, who cares. :-) */
355 if (uglistsize >= (UGLISTLEN-1)) {
358 for (lp = 0; lp < (UGLISTLEN-1); lp++) {
359 uglist[lp] = uglist[lp+1];
360 uglistlsn[lp] = uglistlsn[lp+1];
367 uglist[ugpos] = malloc(strlen(room_name)+1);
368 strcpy(uglist[ugpos], room_name);
369 uglistlsn[ugpos] = ls;
372 /* first try an exact match */
373 r = CtdlIPCGotoRoom(ipc, towhere, "", &room, aaa);
375 newprompt("Enter room password: ", bbb, 9);
376 r = CtdlIPCGotoRoom(ipc, towhere, bbb, &room, aaa);
378 scr_printf("Wrong password.\n");
384 * If a match is not found, try a partial match.
385 * Partial matches anywhere in the string carry a weight of 1,
386 * left-aligned matches carry a weight of 2. Pick the room that
387 * has the highest-weighted match. Do not match on forgotten
391 struct march *march = NULL;
396 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, AllFloors, &march, aaa);
398 /* Run the roomlist; free the data as we go */
399 struct march *mp = march; /* Current */
403 if (pattern(mp->march_name, towhere) >= 0) {
406 if (!strncasecmp(mp->march_name, towhere, strlen(towhere))) {
409 if (partial_match > best_match) {
410 strcpy(bbb, mp->march_name);
411 best_match = partial_match;
413 /* Both pointers are NULL at end of list */
420 if (strlen(bbb) == 0) {
421 scr_printf("No room '%s'.\n", towhere);
425 r = CtdlIPCGotoRoom(ipc, bbb, "", &room, aaa);
427 if (r / 100 != 1 && r / 100 != 2) {
428 scr_printf("%s\n", aaa);
431 safestrncpy(room_name, room->RRname, ROOMNAMELEN);
432 room_flags = room->RRflags;
433 from_floor = curr_floor;
434 curr_floor = room->RRfloor;
436 remove_march(room_name, 0);
437 if (!strcasecmp(towhere, "_BASEROOM_"))
438 remove_march(towhere, 0);
440 next_lazy_cmd = 5; /* Don't read new if no new msgs */
441 if ((from_floor != curr_floor) && (display_name > 0) && (floor_mode == 1)) {
442 if (floorlist[(int) curr_floor][0] == 0)
444 scr_printf("(Entering floor: %s)\n", &floorlist[(int) curr_floor][0]);
446 if (display_name == 1) {
448 scr_printf("%s ", room_name);
452 if (display_name != 2) {
453 color(BRIGHT_YELLOW);
454 scr_printf("%d ", room->RRunread);
456 scr_printf("new of ");
457 color(BRIGHT_YELLOW);
458 scr_printf("%d ", room->RRtotal);
460 scr_printf("messages.\n");
462 highest_msg_read = room->RRlastread;
463 maxmsgnum = room->RRhighest;
464 is_mail = room->RRismailbox;
465 is_room_aide = room->RRaide;
466 ls = room->RRlastread;
468 /* read info file if necessary */
469 if (room->RRinfoupdated > 0)
472 /* check for newly arrived mail if we can */
473 newmailcount = room->RRnewmail;
474 if (newmailcount > 0) {
476 if (newmailcount == 1) {
477 scr_printf("*** A new mail message has arrived.\n");
480 scr_printf("*** %d new mail messages have arrived.\n",
484 if (strlen(rc_gotmail_cmd) > 0) {
485 system(rc_gotmail_cmd);
488 status_line(ipc->ServInfo.humannode, ipc->ServInfo.site_location,
489 room_name, secure, newmailcount);
492 /* Goto next room having unread messages.
493 * We want to skip over rooms that the user has already been to, and take the
494 * user back to the lobby when done. The room we end up in is placed in
495 * newroom - which is set to 0 (the lobby) initially.
497 void gotonext(CtdlIPC *ipc)
500 struct march *mptr, *mptr2;
501 char next_room[ROOMNAMELEN];
502 int r; /* IPC response code */
504 /* Check to see if the march-mode list is already allocated.
505 * If it is, pop the first room off the list and go there.
508 r = CtdlIPCKnownRooms(ipc, SubscribedRoomsWithNewMessages,
509 AllFloors, &march, buf);
511 /* add _BASEROOM_ to the end of the march list, so the user will end up
512 * in the system base room (usually the Lobby>) at the end of the loop
514 mptr = (struct march *) malloc(sizeof(struct march));
516 strcpy(mptr->march_name, "_BASEROOM_");
521 while (mptr2->next != NULL)
526 * ...and remove the room we're currently in, so a <G>oto doesn't make us
527 * walk around in circles
529 remove_march(room_name, 0);
532 strcpy(next_room, pop_march(curr_floor));
534 strcpy(next_room, "_BASEROOM_");
536 remove_march(next_room, 0);
537 dotgoto(ipc, next_room, 1, 0);
541 * forget all rooms on a given floor
543 void forget_all_rooms_on(CtdlIPC *ipc, int ffloor)
546 struct march *flist = NULL;
547 struct march *fptr = NULL;
548 struct ctdlipcroom *room = NULL;
549 int r; /* IPC response code */
551 scr_printf("Forgetting all rooms on %s...\n", &floorlist[ffloor][0]);
553 remove_march("_FLOOR_", ffloor);
554 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, ffloor, &flist, buf);
556 scr_printf("Error %d: %s\n", r, buf);
560 r = CtdlIPCGotoRoom(ipc, flist->march_name, "", &room, buf);
562 r = CtdlIPCForgetRoom(ipc, buf);
564 scr_printf("Error %d: %s\n", r, buf);
576 * routine called by gotofloor() to move to a new room on a new floor
578 void gf_toroom(CtdlIPC *ipc, char *towhere, int mode)
580 int floor_being_left;
582 floor_being_left = curr_floor;
584 if (mode == GF_GOTO) { /* <;G>oto mode */
586 dotgoto(ipc, towhere, 1, 0);
588 else if (mode == GF_SKIP) { /* <;S>kip mode */
589 dotgoto(ipc, towhere, 1, 0);
590 remove_march("_FLOOR_", floor_being_left);
592 else if (mode == GF_ZAP) { /* <;Z>ap mode */
593 dotgoto(ipc, towhere, 1, 0);
594 remove_march("_FLOOR_", floor_being_left);
595 forget_all_rooms_on(ipc, floor_being_left);
603 void gotofloor(CtdlIPC *ipc, char *towhere, int mode)
606 int r; /* IPC response code */
608 char buf[SIZ], targ[SIZ];
610 if (floorlist[0][0] == 0)
613 for (a = 0; a < 128; ++a)
614 if (!strcasecmp(&floorlist[a][0], towhere))
618 for (a = 0; a < 128; ++a) {
619 if (!strncasecmp(&floorlist[a][0], towhere, strlen(towhere))) {
625 for (a = 0; a < 128; ++a)
626 if (pattern(towhere, &floorlist[a][0]) > 0)
630 scr_printf("No floor '%s'.\n", towhere);
633 for (mptr = march; mptr != NULL; mptr = mptr->next) {
634 if ((mptr->march_floor) == tofloor) {
635 gf_toroom(ipc, mptr->march_name, mode);
640 /* Find first known room on the floor */
644 r = CtdlIPCKnownRooms(ipc, SubscribedRooms, tofloor, &mptr, buf);
646 struct march *tmp = mptr;
648 /* TODO: room order is being ignored? */
650 strncpy(targ, mptr->march_name, ROOMNAMELEN);
657 if (strlen(targ) > 0) {
658 gf_toroom(ipc, targ, mode);
662 /* No known rooms on the floor; unzap the first one then */
666 r = CtdlIPCKnownRooms(ipc, AllAccessibleRooms, tofloor, &mptr, buf);
668 struct march *tmp = mptr;
670 /* TODO: room order is being ignored? */
672 strncpy(targ, mptr->march_name, ROOMNAMELEN);
679 if (strlen(targ) > 0) {
680 gf_toroom(ipc, targ, mode);
682 scr_printf("There are no rooms on '%s'.\n", &floorlist[tofloor][0]);
688 * forget all rooms on current floor
690 void forget_this_floor(CtdlIPC *ipc)
692 if (curr_floor == 0) {
693 scr_printf("Can't forget this floor.\n");
696 if (floorlist[0][0] == 0) {
699 scr_printf("Are you sure you want to forget all rooms on %s? ",
700 &floorlist[(int) curr_floor][0]);
705 gf_toroom(ipc, "_BASEROOM_", GF_ZAP);
710 * Figure out the physical screen dimensions, if we can
711 * WARNING: this is now called from a signal handler!
713 void check_screen_dims(void)
717 unsigned short height; /* rows */
718 unsigned short width; /* columns */
719 unsigned short xpixels;
720 unsigned short ypixels; /* pixels */
723 if (have_xterm) { /* dynamically size screen if on an xterm */
724 if (ioctl(0, TIOCGWINSZ, &xwinsz) == 0) {
726 screenheight = is_curses_enabled() ? (int)xwinsz.height - 1 : (int) xwinsz.height;
728 screenwidth = (int) xwinsz.width;
736 * set floor mode depending on client, server, and user settings
738 void set_floor_mode(CtdlIPC* ipc)
740 if (ipc->ServInfo.ok_floors == 0) {
741 floor_mode = 0; /* Don't use floors if the server */
743 /* doesn't support them! */
745 if (rc_floor_mode == RC_NO) { /* never use floors */
748 if (rc_floor_mode == RC_YES) { /* always use floors */
751 if (rc_floor_mode == RC_DEFAULT) { /* user choice */
752 floor_mode = ((userflags & US_FLOORS) ? 1 : 0);
758 * Set or change the user's password
760 int set_password(CtdlIPC *ipc)
766 if (strlen(rc_password) > 0) {
767 strcpy(pass1, rc_password);
768 strcpy(pass2, rc_password);
770 IFNEXPERT formout(ipc, "changepw");
771 newprompt("Enter a new password: ", pass1, -19);
772 newprompt("Enter it again to confirm: ", pass2, -19);
776 if (!strcasecmp(pass1, pass2)) {
777 CtdlIPCChangePassword(ipc, pass1, buf);
778 scr_printf("%s\n", buf);
779 offer_to_remember_password(ipc, hostbuf, portbuf, fullname, pass1);
782 scr_printf("*** They don't match... try again.\n");
790 * get info about the server we've connected to
792 void get_serv_info(CtdlIPC *ipc, char *supplied_hostname)
796 CtdlIPCServerInfo(ipc, buf);
798 /* be nice and identify ourself to the server */
799 CtdlIPCIdentifySoftware(ipc, SERVER_TYPE, 0, REV_LEVEL,
800 (ipc->isLocal ? "local" : CITADEL),
801 (supplied_hostname) ? supplied_hostname :
802 /* Look up the , in the bible if you're confused */
803 (locate_host(ipc, buf), buf), buf);
805 /* Tell the server what our preferred content formats are */
806 if ((CtdlIPCSpecifyPreferredFormats(ipc, buf, "text/html|text/plain") / 100 )== 2) {
814 * Record compare function for SortOnlineUsers()
816 int idlecmp(const void *rec1, const void *rec2) {
819 i1 = extract_long(rec1, 5);
820 i2 = extract_long(rec2, 5);
822 if (i1 < i2) return(1);
823 if (i1 > i2) return(-1);
829 * Sort the list of online users by idle time.
830 * This function frees the supplied buffer, and returns a new one
831 * to the caller. The caller is responsible for freeing the returned buffer.
833 char *SortOnlineUsers(char *listing) {
840 rows = num_tokens(listing, '\n');
841 sortbuf = malloc(rows * SIZ);
842 if (sortbuf == NULL) return(listing);
843 retbuf = malloc(rows * SIZ);
844 if (retbuf == NULL) {
849 /* Copy the list into a fixed-record-size array for sorting */
850 for (i=0; i<rows; ++i) {
852 extract_token(buf, listing, i, '\n', sizeof buf);
853 memcpy(&sortbuf[i*SIZ], buf, (size_t)SIZ);
857 qsort(sortbuf, rows, SIZ, idlecmp);
859 /* Copy back to a \n delimited list */
861 for (i=0; i<rows; ++i) {
862 strcat(retbuf, &sortbuf[i*SIZ]);
863 if (i<(rows-1)) strcat(retbuf, "\n");
871 * Display list of users currently logged on to the server
873 void who_is_online(CtdlIPC *ipc, int longlist)
875 char buf[SIZ], username[SIZ], roomname[SIZ], fromhost[SIZ];
877 char actual_user[SIZ], actual_room[SIZ], actual_host[SIZ];
878 char clientsoft[SIZ];
880 time_t idletime, idlehours, idlemins, idlesecs;
881 int last_session = (-1);
883 char *listing = NULL;
884 int r; /* IPC response code */
893 pprintf(" User Name Room Idle From host\n");
895 pprintf(" ------------------------- -------------------- ---- ------------------------\n");
897 r = CtdlIPCOnlineUsers(ipc, &listing, &timenow, buf);
898 listing = SortOnlineUsers(listing);
900 while (strlen(listing) > 0) {
903 /* Get another line */
904 extract_token(buf, listing, 0, '\n', sizeof buf);
905 remove_token(listing, 0, '\n');
907 extract_token(username, buf, 1, '|', sizeof username);
908 extract_token(roomname, buf, 2, '|', sizeof roomname);
909 extract_token(fromhost, buf, 3, '|', sizeof fromhost);
910 extract_token(clientsoft, buf, 4, '|', sizeof clientsoft);
911 extract_token(flags, buf, 7, '|', sizeof flags);
913 idletime = timenow - extract_long(buf, 5);
914 idlehours = idletime / 3600;
915 idlemins = (idletime - (idlehours * 3600)) / 60;
916 idlesecs = (idletime - (idlehours * 3600) - (idlemins * 60));
918 if (idletime > rc_idle_threshold) {
920 while (strlen(roomname) < 20) {
921 strcat(roomname, " ");
923 strcpy(&roomname[14], "[idle]");
930 extract_token(actual_user, buf, 8, '|', sizeof actual_user);
931 extract_token(actual_room, buf, 9, '|', sizeof actual_room);
932 extract_token(actual_host, buf, 10, '|', sizeof actual_host);
934 pprintf(" Flags: %s\n", flags);
935 pprintf("Session: %d\n", extract_int(buf, 0));
936 pprintf(" Name: %s\n", username);
937 pprintf("In room: %s\n", roomname);
938 pprintf(" Host: %s\n", fromhost);
939 pprintf(" Client: %s\n", clientsoft);
940 pprintf(" Idle: %ld:%02ld:%02ld\n",
945 if ( (strlen(actual_user)+strlen(actual_room)+strlen(actual_host)) > 0) {
947 if (strlen(actual_user)>0) pprintf("<%s> ", actual_user);
948 if (strlen(actual_room)>0) pprintf("in <%s> ", actual_room);
949 if (strlen(actual_host)>0) pprintf("from <%s> ", actual_host);
956 if (extract_int(buf, 0) == last_session) {
959 color(BRIGHT_MAGENTA);
960 pprintf("%-3s", flags);
962 last_session = extract_int(buf, 0);
964 pprintf("%-25s ", username);
965 color(BRIGHT_MAGENTA);
967 pprintf("%-20s ", roomname);
968 if (idletime > rc_idle_threshold) {
969 /* over 1000d, must be gone fishing */
970 if (idlehours > 23999) {
973 } else if (idlehours > 239) {
977 } else if (idlehours > 9) {
978 pprintf("%1ldd%02ld",
981 /* less than 10 hours */
983 pprintf("%1ld:%02ld",
984 idlehours, idlemins);
993 pprintf("%-24s\n", fromhost);
1002 void enternew(CtdlIPC *ipc, char *desc, char *buf, int maxlen)
1005 snprintf(bbb, sizeof bbb, "Enter in your new %s: ", desc);
1006 newprompt(bbb, buf, maxlen);
1011 int shift(int argc, char **argv, int start, int count) {
1014 for (i=start; i<(argc-count); ++i) {
1015 argv[i] = argv[i+count];
1017 argc = argc - count;
1021 static void statusHook(char *s) {
1029 int main(int argc, char **argv)
1032 char aaa[100], bbb[100];/* general purpose variables */
1033 char argbuf[32]; /* command line buf */
1034 char nonce[NONCE_SIZE];
1035 char *telnet_client_host = NULL;
1036 char *sptr, *sptr2; /* USed to extract the nonce */
1037 char hexstring[MD5_HEXSTRING_SIZE];
1038 int stored_password = 0;
1040 struct ctdlipcmisc chek;
1041 struct ctdluser *myself = NULL;
1042 CtdlIPC* ipc; /* Our server connection */
1043 int r; /* IPC result code */
1047 char relhome[PATH_MAX]="";
1048 char ctdldir[PATH_MAX]=CTDLDIR;
1052 calc_dirs_n_files(relh, home, relhome, ctdldir);
1054 setIPCDeathHook(screen_delete);
1055 setIPCErrorPrintf(err_printf);
1056 setCryptoStatusHook(statusHook);
1058 /* Permissions sanity check - don't run citadel setuid/setgid */
1059 if (getuid() != geteuid()) {
1060 err_printf("Please do not run citadel setuid!\n");
1062 } else if (getgid() != getegid()) {
1063 err_printf("Please do not run citadel setgid!\n");
1067 stty_ctdl(SB_SAVE); /* Store the old terminal parameters */
1068 load_command_set(); /* parse the citadel.rc file */
1069 stty_ctdl(SB_NO_INTR); /* Install the new ones */
1070 /* signal(SIGHUP, dropcarr);FIXME */ /* Cleanup gracefully if carrier is dropped */
1071 signal(SIGPIPE, dropcarr); /* Cleanup gracefully if local conn. dropped */
1072 signal(SIGTERM, dropcarr); /* Cleanup gracefully if terminated */
1073 signal(SIGCONT, catch_sigcont); /* Catch SIGCONT so we can reset terminal */
1075 signal(SIGWINCH, scr_winch); /* Window resize signal */
1079 arg_encrypt = RC_DEFAULT;
1081 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1082 arg_screen = RC_DEFAULT;
1086 * Handle command line options as if we were called like /bin/login
1087 * (i.e. from in.telnetd)
1089 for (a=0; a<argc; ++a) {
1090 if ((argc > a+1) && (!strcmp(argv[a], "-h")) ) {
1091 telnet_client_host = argv[a+1];
1092 argc = shift(argc, argv, a, 2);
1094 if (!strcmp(argv[a], "-x")) {
1096 arg_encrypt = RC_NO;
1098 argc = shift(argc, argv, a, 1);
1100 if (!strcmp(argv[a], "-X")) {
1102 arg_encrypt = RC_YES;
1103 argc = shift(argc, argv, a, 1);
1105 fprintf(stderr, "Not compiled with encryption support");
1109 if (!strcmp(argv[a], "-s")) {
1110 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1113 argc = shift(argc, argv, a, 1);
1115 if (!strcmp(argv[a], "-S")) {
1116 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1117 arg_screen = RC_YES;
1119 argc = shift(argc, argv, a, 1);
1121 if (!strcmp(argv[a], "-p")) {
1124 if (chdir(CTDLDIR) < 0) {
1125 perror("can't change to " CTDLDIR);
1130 * Drop privileges if necessary. We stat
1131 * citadel.config to get the uid/gid since it's
1132 * guaranteed to have the uid/gid we want.
1134 if (!getuid() || !getgid()) {
1135 if (stat(file_citadel_config, &st) < 0) {
1136 perror("couldn't stat citadel.config");
1139 if (!getgid() && (setgid(st.st_gid) < 0)) {
1140 perror("couldn't change gid");
1143 if (!getuid() && (setuid(st.st_uid) < 0)) {
1144 perror("couldn't change uid");
1148 scr_printf("Privileges changed to uid %d gid %d\n",
1149 getuid(), getgid());
1152 argc = shift(argc, argv, a, 1);
1160 newprompt("Connect to (return for local server): ", hostbuf, 64);
1163 sln_printf("Attaching to server... \r");
1165 ipc = CtdlIPC_new(argc, argv, hostbuf, portbuf);
1168 error_printf("Can't connect: %s\n", strerror(errno));
1171 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
1172 CtdlIPC_SetNetworkStatusCallback(ipc, wait_indicator);
1174 ipc_for_signal_handlers = ipc; /* KLUDGE cover your eyes */
1176 CtdlIPC_chat_recv(ipc, aaa);
1177 if (aaa[0] != '2') {
1178 scr_printf("%s\n", &aaa[4]);
1179 logoff(ipc, atoi(aaa));
1182 /* If there is a [nonce] at the end, put the nonce in <nonce>, else nonce
1186 if ((sptr = strchr(aaa, '<')) == NULL)
1192 if ((sptr2 = strchr(sptr, '>')) == NULL)
1200 strncpy(nonce, sptr, (size_t)NONCE_SIZE);
1205 /* Evaluate encryption preferences */
1206 if (arg_encrypt != RC_NO && rc_encrypt != RC_NO) {
1207 if (!ipc->isLocal || arg_encrypt == RC_YES || rc_encrypt == RC_YES) {
1208 secure = (CtdlIPCStartEncryption(ipc, aaa) / 100 == 2) ? 1 : 0;
1210 error_printf("Can't encrypt: %s\n", aaa);
1215 get_serv_info(ipc, telnet_client_host);
1216 scr_printf("%-24s\n%s\n%s\n", ipc->ServInfo.software, ipc->ServInfo.humannode,
1217 ipc->ServInfo.site_location);
1220 status_line(ipc->ServInfo.humannode, ipc->ServInfo.site_location, NULL,
1223 screenwidth = 80; /* default screen dimensions */
1226 scr_printf(" pause next stop\n");
1227 scr_printf(" ctrl-s ctrl-o ctrl-c\n\n");
1228 formout(ipc, "hello"); /* print the opening greeting */
1231 GSTA: /* See if we have a username and password on disk */
1232 if (rc_remember_passwords) {
1233 get_stored_password(hostbuf, portbuf, fullname, password);
1234 if (strlen(fullname) > 0) {
1235 r = CtdlIPCTryLogin(ipc, fullname, aaa);
1238 r = CtdlIPCTryApopPassword(ipc, make_apop_string(password, nonce, hexstring, sizeof hexstring), aaa);
1240 r = CtdlIPCTryPassword(ipc, password, aaa);
1245 load_user_info(aaa);
1246 stored_password = 1;
1249 set_stored_password(hostbuf, portbuf, "", "");
1257 if (strlen(rc_username) > 0) {
1258 strcpy(fullname, rc_username);
1260 newprompt("Enter your name: ", fullname, 29);
1263 if (!strcasecmp(fullname, "new")) { /* just in case */
1264 scr_printf("Please enter the name you wish to log in with.\n");
1267 (!strcasecmp(fullname, "bbs"))
1268 || (!strcasecmp(fullname, "new"))
1269 || (strlen(fullname) == 0));
1271 if (!strcasecmp(fullname, "off")) {
1275 /* sign on to the server */
1276 r = CtdlIPCTryLogin(ipc, fullname, aaa);
1280 /* password authentication */
1281 if (strlen(rc_password) > 0) {
1282 strcpy(password, rc_password);
1284 newprompt("\rPlease enter your password: ", password, -19);
1289 r = CtdlIPCTryApopPassword(ipc, make_apop_string(password, nonce, hexstring, sizeof hexstring), aaa);
1291 r = CtdlIPCTryPassword(ipc, password, aaa);
1295 load_user_info(aaa);
1296 offer_to_remember_password(ipc, hostbuf, portbuf,
1297 fullname, password);
1300 scr_printf("<< wrong password >>\n");
1301 if (strlen(rc_password) > 0)
1305 NEWUSR: if (strlen(rc_password) == 0) {
1306 scr_printf("'%s' not found.\n"
1307 "Do you want to create a new account with this name? ",
1313 r = CtdlIPCCreateUser(ipc, fullname, 1, aaa);
1315 scr_printf("%s\n", aaa);
1318 load_user_info(aaa);
1320 while (set_password(ipc) != 0);
1323 enter_config(ipc, 1);
1326 /* Switch color support on or off if we're in user mode */
1327 if (rc_ansi_color == 3) {
1328 if (userflags & US_COLOR)
1334 color(BRIGHT_WHITE);
1335 scr_printf("\n%s\nAccess level: %d (%s)\n"
1336 "User #%ld / Login #%d",
1337 fullname, axlevel, axdefs[(int) axlevel],
1338 usernum, timescalled);
1339 if (lastcall > 0L) {
1340 scr_printf(" / Last login: %s",
1341 asctime(localtime(&lastcall)));
1345 r = CtdlIPCMiscCheck(ipc, &chek, aaa);
1351 scr_printf("*** You have a new private message in Mail>\n");
1353 scr_printf("*** You have %d new private messages in Mail>\n", b);
1355 if (strlen(rc_gotmail_cmd) > 0) {
1356 system(rc_gotmail_cmd);
1359 if ((axlevel >= 6) && (chek.needvalid > 0)) {
1360 scr_printf("*** Users need validation\n");
1362 if (chek.needregis > 0) {
1363 scr_printf("*** Please register.\n");
1364 formout(ipc, "register");
1368 /* Make up some temporary filenames for use in various parts of the
1369 * program. Don't mess with these once they've been set, because we
1370 * will be unlinking them later on in the program and we don't
1371 * want to delete something that we didn't create. */
1372 CtdlMakeTempFileName(temp, sizeof temp);
1373 CtdlMakeTempFileName(temp2, sizeof temp2);
1374 CtdlMakeTempFileName(tempdir, sizeof tempdir);
1376 /* Get screen dimensions. First we go to a default of 80x24. Then
1377 * we try to get the user's actual screen dimensions off the server.
1378 * However, if we're running on an xterm, all this stuff is
1379 * irrelevant because we're going to dynamically size the screen
1380 * during the session.
1384 r = CtdlIPCGetConfig(ipc, &myself, aaa);
1386 screenwidth = myself->USscreenwidth;
1387 screenheight = myself->USscreenheight;
1389 if (getenv("TERM") != NULL)
1390 if (!strcmp(getenv("TERM"), "xterm")) {
1394 check_screen_dims();
1397 set_floor_mode(ipc);
1399 /* Enter the lobby */
1400 dotgoto(ipc, "_BASEROOM_", 1, 0);
1402 /* Main loop for the system... user is logged in. */
1406 readmsgs(ipc, LastMessages, ReadForward, 5);
1408 readmsgs(ipc, NewMessages, ReadForward, 0);
1410 /* MAIN COMMAND LOOP */
1412 mcmd = getcmd(ipc, argbuf); /* Get keyboard command */
1415 check_screen_dims(); /* if xterm, get screen size */
1421 formout(ipc, "help");
1424 entmsg(ipc, 0, ((userflags & US_EXTEDIT) ? 2 : 0));
1434 /* Only m.author is used */
1435 struct ctdlipcmessage m;
1436 newprompt("What do you want your username to be? ",
1437 m.author, USERNAME_SIZE - 1);
1439 r = CtdlIPCPostMessage(ipc, 2, &m, aaa);
1441 scr_printf("%s\n", aaa);
1446 case 5: /* <G>oto */
1450 case 47: /* <A>bandon */
1451 if (!rc_alt_semantics) {
1456 case 90: /* <.A>bandon */
1457 if (!rc_alt_semantics)
1459 dotgoto(ipc, argbuf, 0, 0);
1461 case 58: /* <M>ail */
1463 dotgoto(ipc, "_MAIL_", 1, 0);
1466 if (strlen(argbuf) > 0) {
1468 dotgoto(ipc, argbuf, 0, 0);
1472 if (strlen(argbuf) > 0) {
1473 if (rc_alt_semantics) {
1476 dotgoto(ipc, argbuf, 0, 0);
1479 case 95: /* what exactly is the numbering scheme supposed to be anyway? --Ford, there isn't one. -IO */
1480 dotungoto(ipc, argbuf);
1483 readmsgs(ipc, AllMessages, ReadForward, 0);
1486 readmsgs(ipc, LastMessages, ReadForward, 5);
1489 readmsgs(ipc, NewMessages, ReadForward, 0);
1492 readmsgs(ipc, AllMessages, ReadReverse, 0);
1495 readmsgs(ipc, OldMessages, ReadReverse, 0);
1498 readmsgs(ipc, LastMessages, ReadForward,
1515 userlist(ipc, argbuf);
1573 if (!rc_alt_semantics) {
1585 cli_image_upload(ipc, "_userpic_");
1588 cli_image_upload(ipc, "_roompic_");
1592 snprintf(aaa, sizeof aaa, "_floorpic_|%d", curr_floor);
1593 cli_image_upload(ipc, aaa);
1597 enternew(ipc, "roomname", aaa, 20);
1598 r = CtdlIPCChangeRoomname(ipc, aaa, bbb);
1600 scr_printf("\n%s\n", bbb);
1603 enternew(ipc, "hostname", aaa, 25);
1604 r = CtdlIPCChangeHostname(ipc, aaa, bbb);
1606 scr_printf("\n%s\n", bbb);
1609 enternew(ipc, "username", aaa, 32);
1610 r = CtdlIPCChangeUsername(ipc, aaa, bbb);
1612 scr_printf("\n%s\n", bbb);
1622 display_help(ipc, argbuf);
1626 formout(ipc, "register");
1631 scr_printf("Are you sure (y/n)? ");
1633 if (!rc_alt_semantics)
1641 scr_printf("All users will be disconnected! "
1642 "Really terminate the server? ");
1644 if (!rc_alt_semantics)
1646 r = CtdlIPCTerminateServerNow(ipc, aaa);
1647 scr_printf("%s\n", aaa);
1656 scr_printf("Do you really want to schedule a "
1657 "server shutdown? ");
1659 r = CtdlIPCTerminateServerScheduled(ipc, 1, aaa);
1663 "The Citadel server will terminate when all users are logged off.\n"
1667 "The Citadel server will not terminate.\n"
1675 network_config_management(ipc, "listrecp",
1676 "Message-by-message mailing list recipients");
1680 network_config_management(ipc, "digestrecp",
1681 "Digest mailing list recipients");
1685 network_config_management(ipc, "ignet_push_share",
1686 "Nodes with which we share this room");
1690 do_ignet_configuration(ipc);
1694 do_filterlist_configuration(ipc);
1698 if (rc_alt_semantics) {
1711 stty_ctdl(SB_RESTORE);
1712 snprintf(aaa, sizeof aaa, "USERNAME=\042%s\042; export USERNAME;"
1713 "exec ./subsystem %ld %d %d", fullname,
1714 usernum, screenwidth, axlevel);
1716 stty_ctdl(SB_NO_INTR);
1719 scr_printf("*** Can't run doors when server is not local.\n");
1724 who_is_online(ipc, 0);
1728 who_is_online(ipc, 1);
1732 who_is_online(ipc, 2);
1736 do_system_configuration(ipc);
1740 do_internet_configuration(ipc);
1744 check_message_base(ipc);
1756 enter_config(ipc, 2);
1760 enter_config(ipc, 0);
1761 set_floor_mode(ipc);
1765 enter_config(ipc, 3);
1766 set_floor_mode(ipc);
1770 gotofloor(ipc, argbuf, GF_GOTO);
1774 gotofloor(ipc, argbuf, GF_SKIP);
1778 forget_this_floor(ipc);
1810 knrooms(ipc, floor_mode);
1820 misc_server_cmd(ipc, argbuf);
1824 edit_system_message(ipc, argbuf);
1848 default: /* allow some math on the command */
1849 /* commands 100... to 100+MAX_EDITORS-1 will
1850 call the appropriate editor... in other
1851 words, command numbers 100+ will match
1852 the citadel.rc keys editor0, editor1, etc.*/
1853 if (mcmd >= 100 && mcmd < (100+MAX_EDITORS))
1855 /* entmsg mode >=2 select editor */
1856 entmsg(ipc, 0, mcmd - 100 + 2);
1860 } while (termn8 == 0);
1862 TERMN8: scr_printf("%s logged out.", fullname);
1864 color(ORIGINAL_PAIR);
1866 while (march != NULL) {
1867 remove_march(march->march_name, 0);
1870 sln_printf("\n\nType 'off' to disconnect, or next user...\n");
1873 if ((mcmd == 29) || (mcmd == 15)) {
1875 stty_ctdl(SB_RESTORE);
1876 formout(ipc, "goodbye");