/** /* $Id: orcus.c,v 1.2 1998/02/13 08:56:07 falcon Exp $ /* ORCUS.C Secure icb client /**/ #include "config.h" #include #include #include #include #include #include "orcus.h" #include "defs.h" #include "returns.h" #include "cqueue.h" #include "prototypes.h" #include "show.h" #include "utils.h" #include "oset.h" /* Good lord .. mondo globals totally out of control. */ /* This needs to get fixed up sometime (maybe). */ char *chunkoram; /* input buffer; ugly hack, get around it later */ int s; /* fd for socket to icbd */ int rows = 0; /* height of display, 0 for infinite */ int cols = 72; /* width of display, 0 for infinite */ int spat; /* number of lines issued since last pagebreak */ int nobeep = 0; /* iff set, beeps are silent */ int bmessage = 0;/* iff set, suppressed beeps still display message */ int breturn = 1;/* iff set, suppressed beeps nag sender */ char *bretnag; /* iff !NULL, contains text for nobeep return message */ int widle; /* iff set, verbose "idle" format for /w */ int wdate; /* iff set, login date displayed for /w */ int military; /* iff set, times displayed in military time */ int noidle; /* iff set, runs idlecmd every now and then */ int idletrack; int idleperiod = 1200; /* determines unidle period */ int do_free_idlecmd = 0; char *idlecmd = "/w ."; int *confirm_quit = NO; /* ask if we wish to quit or not. 0 is no. */ int debug = NO; /* realtime changable debug output flag, default is no */ int display_idle_threshold = 10; /* if user idle < 10 seconds, show '---' in wholine */ int first_time = 1; /* first time through main loop */ int server_wrap = 0; /* re-append server commands to top of split /m's */ char commandchar = '/'; /* let the user redefine this */ int nomore = 0; /* character pressed at [=more=] prompt */ lroot squelches; /* list of squelch strings */ int squelch_status = 0; /* determines behaviour of squelching */ int no_tabhistory; /* controls adding /m's to tab history */ int silent_running = 0; /* iff set, no writes to stdout */ int stamping = 0; // timestamp messages as they appear on screen /* session logging: */ int logstate; /* 1 = logging active; 0 = inactive */ int logtimes; /* degree of timestamping */ char *logfname; /* name of session log file */ FILE *logfile; /* session log file */ time_t logtimer; /* time of last timestamp */ main(ac,av) int ac; char *av[]; { int i,j,k; int looper; int sleeper; char ptype; char trailer; char shuttle[300]; char fromwho[256]; char uhandle[64]; char uaccount[64]; char ugroup[64]; char uaccess[64]; char upasswd[64]; char userver[64]; char *pointer; /* pointer into chunkoram */ int commandcode; int counter, rowset; struct passwd *pw; /* passwd entry */ extern char *bigbuf; extern int carrier; extern char stuff[4][255]; extern char *cmdlog[CMDLOGLEN]; extern int index_cl; #ifdef DEBUG /* if -DDEBUG setup output to debug */ debug = YES; #endif // initializing oset variable structure oset_init(); /* initializing command log */ for ( i = 0; i < CMDLOGLEN; i++ ) cmdlog[i] = NULL; index_cl = 0; /* initializeing command queue */ init_command_queue(); /* session logging */ logstate = 0; /* default: no logging */ logtimes = 1; /* default: timestamp beginnings of sessions */ logfname = NULL; logfile = NULL; /* initializing squelch list */ squelches.n = 0; squelches.h = NULL; squelches.t = NULL; sttyinputset(); /* Get term settings and save them for later. Also setup /* term setting for orcus */ /* Let's catch those pesky signals! */ catch_signals(); spat = 0; rowset = 0; noidle = 0; no_tabhistory = 0; bigbuf = NULL; /* get their real username. use -anon if you want the spoofing */ pw=getpwuid(getuid()); sprintf(uhandle,pw->pw_name); strcpy ( uaccount, uhandle ); strcpy ( ugroup, "1" ); strcpy ( uaccess, "login" ); strcpy ( upasswd, "pass" ); strcpy ( userver, "default.icb.net" ); oprint("%s\n",ORCUS_VERSION+5); if ( ac > 1 ) { i = 1; while ( i < ac ) { if ( !strcmp ( av[i], "-anon" ) ) { i++; sprintf ( uaccount, "anon%u", getpid() & 1023 ); /* theres a bug here. this freaks if it's not even-argument aligned. */ /* this should probably use getopts or something. i dunno. wacky code.*/ } else if ( !strcmp ( av[i], "-w" ) ) { strcpy ( uaccess, "w" ); if ( !rows && !rowset ) rows = 22; } else if ( !strcmp ( av[i], "-rows" ) ) { i++; if ( i < ac ) rows = atoi ( av[i] ); rowset = 1; } else if ( !strcmp ( av[i], "-nick" ) || !strcmp ( av[i], "-handle" ) || !strcmp ( av[i], "-name" ) || !strcmp ( av[i], "-han" ) || !strcmp ( av[i], "-n" ) ) { i++; if ( i < ac ) strncpy ( uhandle, av[i], 11 ); } else if ( !strcmp ( av[i], "-account" ) || !strcmp ( av[i], "-spoof" ) || !strcmp ( av[i], "-cheat" ) ) { i++; if ( i < ac ) strncpy ( uaccount, av[i], 11 ); } else if ( !strcmp ( av[i], "-group" ) || !strcmp ( av[i], "-g" ) ) { i++; if ( i < ac ) strncpy ( ugroup, av[i], 11 ); } else if ( !strcmp ( av[i], "-password" ) || !strcmp ( av[i], "-pass" ) || !strcmp ( av[i], "-p" ) ) { i++; if ( i < ac ) strncpy ( upasswd, av[i], 11 ); } else if ( !strcmp ( av[i], "-server" ) || !strcmp ( av[i], "-h" ) || !strcmp ( av[i], "-host" ) ) { i++; if ( i < ac ) strncpy ( userver, av[i], 31 ); } else { char *arg = &((av[i])[1]); char *dat = av[i+1]; int res = 0; if ( i + 1 < ac ) { res = oset ( arg, dat ); i++; } else { res = oset ( arg, "" ); } if ( res < 1 ) { oprint ("options available:\n"); oprint (" -nick set default nickname\n"); oprint (" -group set default group\n"); oprint (" -pass use given password\n"); oprint (" -host
use given host address\n"); oprint (" -rows set inital row count\n"); oprint (" -w don't login, just list; note - sets\n"); oprint (" default row count to 22 unless set \n"); oprint (" otherwise with '-rows' option.\n"); oprint (" - gets passed to the /oset command handler.\n" ); exit(1); } } i++; } /* END of while */ } /* END of if */ init_tabhistory(); /* in readln.c .. initialize tab history table */ oprint ("Making connection to server at %s..\n",userver); s = clientsocket ( userver, 7326 ); if(debug) oprint ("clientsocket() returned %d\n", s ); sleep ( 1 ); if(debug) oprint ("attempting login .. \n"); login ( s, uaccount, uhandle, ugroup, uaccess, upasswd ); if(debug) oprint (".. login attempted\n"); oprint ("Use /help for command list\n"); sleep ( 2 ); chunkoram = (char*) malloc ( REALLYHUGE ); counter = 0; idletrack = time(NULL); load_orcusrc ( NULL ); while ( carrier ) { /* note: I really should only use eof() to check for closure */ sleeper = 1; if ( checkfd ( s ) ) { /* incoming data from server */ if(debug) oprint ("* alpha\n"); ptype = '!'; readpacket ( s, &ptype ); /* in icb1io.c */ if(debug) oprint ("* beta %c\n", ptype); switch ( ptype ) { /* stuff[0] and stuff[1] valid */ case 'b' : go_show_open_message(stuff[0],stuff[1]); break; case 'c' : go_show_pers_message(stuff[0],stuff[1]); break; case 'd' : go_show_status_update(stuff[0],stuff[1]); break; case 'f' : go_announcement(stuff[0],stuff[1]); break; case 'i' : go_show_command_output(stuff[0],stuff[1]); break; /* stuff[] not valid */ case 'a' : go_login_verified(); break; /* in orcusshow.c */ case 'g' : go_we_must_exit(); break; /* in orcusshow.c */ case 'j' : go_protocol_version(); break; /* in orcusshow.c */ /* stuff[0] valid */ case 'e' : go_show_error(stuff[0]); break; case 'k' : go_gotum_beep(stuff[0]); break; case 'l' : go_gotum_ping(stuff[0]); break; case '!' : break; case 0 : orc_quit(); } /* END of switch */ sleeper = 0; if(debug) oprint ("* gamma\n"); } /* END of if ( checkfd(s) ) */ while( fdpoll(0) ) { /* key pressed? */ if(debug) oprint ("enter text:\n"); emacs_readln ( chunkoram ); if(debug) oprint ("text entered [%s].\n", chunkoram ); push_command_queue ( chunkoram ); log_this ( "=> " ); log_this ( chunkoram ); log_this ( "\n" ); chunkoram[0] = 0; } /* end of while keypressed */ while ( got_command_queue() ) { commandcode = analyze_input_string ( pull_command_queue() ); /* puts parts into stuff[] */ /* in orcusutil.c */ switch ( commandcode ) { case NO_CMD: break; /* No action required */ case NOIDLE: break; /* No action required */ case HELP: break; /* No action required */ case SETDEBUG: break; /* No action required */ case CONFIRM: break; /* No action required */ case RELOAD: break; /* No action required */ case PUB_MSG: writepub ( s, bigbuf ); break; /* in icb1io.c */ case PRIVATE_MSG: writepriv ( s, stuff[0], bigbuf ); break; /* in icb1io.c */ case DROP: writecmd ( s, stuff[0], stuff[1], stuff[2] ); break; /* in icb1io.c */ case ECHOBACK: writecmd ( s, stuff[0], stuff[1], NULL ); break; /* in icb1io.c */ case WHO: writecmd ( s, stuff[0], stuff[1], NULL ); break; /* in icb1io.c */ case NAME: writecmd ( s, stuff[0], stuff[1], NULL ); break; /* in icb1io.c */ case NICK: writecmd ( s, stuff[0], stuff[1], NULL ); break; /* in icb1io.c */ case BOOT: writecmd ( s, stuff[0], stuff[1], NULL ); break; /* in icb1io.c */ case BEEP: writecmd ( s, stuff[0], stuff[1], NULL ); break; /* in icb1io.c */ case CMD2: writecmd ( s, stuff[0], stuff[1], NULL ); break; /* in icb1io.c */ case PASSWD: writecmd ( s, stuff[0], stuff[1], NULL ); break; /* in icb1io.c */ case READ: writecmd ( s, stuff[0], NULL, NULL ); break; /* in icb1io.c */ case CHANGE_GRP:gotogroup ( s, stuff[0] ); break; /* in icb1io.c */ case TOPIC: writecmd ( s, stuff[0], stuff[1], NULL ); break; /* in icb1io.c */ case PASS: passmod ( s, stuff[0] ); break; /* in icb1io.c */ case WRITE: writemail ( s, stuff[0], bigbuf ); break; case QUIT: quit(confirm_quit); break; /* in orcusutil.c */ } /* END of switch */ sleeper = 0; server_wrap = 0; } /* END of if got_command_queue() */ if ( sleeper ) { usleep ( 100000 ); if ( noidle ) if ( time(NULL) - idletrack > idleperiod ) { /* writecmd ( s, "w", ".", NULL ); */ push_command_queue ( idlecmd ); idletrack = time(NULL); spat = 0; } /* end of if noidle */ } /* end of if sleeper */ } /* END of while */ /* with quit() being called, this section of code should never be reached. */ orc_quit(); }