/* finger.c Provides a finger client services for NCSA 2.3. Reference: RFC 742 By James Nau, College of Engineering, University of Nebraska--Lincoln */ #define FINGER_PORT 79 #define ALARM 128 #ifdef __TURBOC__ #include "turboc.h" #endif #include #include #include #include #include #include #ifdef MSC #include #include #endif #ifdef MEMORY_DEBUG #include "memdebug.h" #endif #include "netevent.h" #include "hostform.h" #include "whatami.h" #include "externs.h" #include "netutils.h" int debug = 0; /* enable with -D option */ int timeout=300; /* timeout period in clicks */ //int bypass_passwd=0; /* whether to bypass the password check, not used */ unsigned char path_name[_MAX_DRIVE+_MAX_DIR], /* character storage for the path name */ temp_str[20],buf[_MAX_DIR],temp_data[30]; /* Function Prototypes */ int main(int argc, char *argv[]); #ifndef __TURBOC__ static void randomize(void ); #endif void usage(void); int index (char *string, char ch); void do_finger(char *host, char *line); void filter(char *buffer, int buffer_len); /* finger [-h filename] [-l | -w] [user]@hostname -h filename is alternative CONFIG.TEL file -l -w implements longer finger (whois) user username to query hostname the NAME (or Number?) of the host to finger */ int main(int argc, char *argv[]) { int i; char userinfo[128]; /* Ought not to be > 128 char usernames */ int longform=0; /* if 1, then try a long finger (whois) */ int gotuser=0; /* if 1, doing lookup on a particular user */ int gothost=0; /* if 1, we've found the host */ int atsign; /* location of @ */ char *ptr=0; /* pointer to CONFIG.TEL file */ char remote_host[256]; /* address of remote host */ #ifdef __TURBOC__ fnsplit(argv[0],path_name,buf,temp_str,temp_data); /* split path up */ #else _splitpath(argv[0],path_name,buf,temp_str,temp_data); /* split path up */ #endif strcat(path_name,buf); /* append the path name */ strcat(path_name,temp_str); /* append filename */ userinfo[0] = '\0'; /* init to a null string */ /* get the command line arguments */ for (i=1; i as per RFC 742*/ if (debug) printf("sending [%s] to [%s]\n",userinfo, remote_host); /* Just Do It */ do_finger(remote_host, userinfo); netshut(); /* shut down all network stuff */ exit(0); return(0); } void do_finger(char *remote_host, char *sendline) { int from_port; int conn_id; struct machinfo *finger_host; char buff[132]; /* text returned from the server */ int bufflen=132; int len; /* length of text read from server */ int i; int theclass, dat; int event; /* pick a source port at random from the set of privileged ports */ randomize(); from_port = rand() % 1023; /* do name lookup for server */ finger_host = gethostinfo(remote_host); if (finger_host == (struct machinfo *)NULL) /* couldn't do it, message in gethostinfo */ { printf("Couldn't lookup host [%s]\n", remote_host); return; } /* print out the IP number of the destination host */ printf("["); for (i=0; i<4; i++) { printf("%d",finger_host->hostip[i]); if (i < 3) printf("."); } printf("]\n"); /* open the connection */ conn_id = connect_sock(finger_host, from_port, FINGER_PORT); if (conn_id < 0) { netshut(); printf("connect_sock returned %d, exiting\n",conn_id); } if (debug) printf("connection ident [%d]\n",conn_id); /* send the request */ netwrite(conn_id, sendline, strlen(sendline)); if (debug) printf("netwrite succeeded--flushing buffer\n"); netpush(conn_id); if (debug) printf("buffer flushing\n"); if (debug) if (!netest(conn_id)) printf("Connection OK\n"); else printf("nettest: %d\n", netest(conn_id)); /* OK, now, we'll attempt to set an alarm to time out in timeout seconds if we get a connection, but no response */ Stimerset(USERCLASS, ALARM, 0, timeout); if (debug) printf("timer set to go off in %d seconds\n", timeout); theclass = 0; event = 0; while ((theclass != USERCLASS || event != ALARM) && !netest(conn_id)) /* no alarm and good connection */ { Stask(); /* I think I have to call this to post my alarm? */ event = Sgetevent(CONCLASS | USERCLASS, &theclass, &dat); if (debug) printf("event[%d] theclass[%d] dat[%d]\n",event, theclass, dat); if (!event) continue; if (conn_id != dat) continue; if (event == CONDATA) { len = netread(conn_id, buff, bufflen); if (len == 0) continue; filter(buff, len); printf("%.*s", len, buff); } } if (theclass == USERCLASS && event == ALARM) { printf("Connection timed out in %d clicks\n", timeout); netshut(); exit (2); } #ifdef OLD_WAY if (debug) printf("returning eof\n"); return (EOF); while ((event = Sgetevent(CONCLASS,&theclass,&dat)) != CONDATA) { printf("event [%d] [%d] [%d]\n",event, theclass, dat); if (conn_id == dat) { } if (debug) printf("got event CONDATA [%d]\n",CONDATA); printf("Event [%d] [%d] [%d]\n",event, theclass, dat); len = netread(conn_id, buff, bufflen); if (debug) printf("len is [%d]\n", len); if (len <=0 ) break; printf("%.*s",len,buff); } } #endif if (debug) printf("Closing Connection\n"); netclose(conn_id); } #ifdef MSC #ifndef __TURBOC__ /****************************************************************** * * randomize() * * replicates the randomize function of Turbo C * MSC 5.1 does not contain it so we have to write it ourselves. * */ static void randomize(void ) { srand((unsigned)time(NULL)); } #endif #endif void filter (char *buffer, int buffer_len) /* filter out control characters, escape sequences, etc keeps from reprogramming keys, ... */ { int i; char ch; for (i=0; i