/* rsh.c Provides rsh client services for NCSA 2.3. By James Nau, College of Engineering, University of Nebraska--Lincoln */ #define RSH_PORT 512 #define ALARM 128 #include #include #include #include #include #include #ifdef __TURBOC__ #include "turboc.h" #endif #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 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); void do_rsh(char *host, char *line); int rsh(char *host, int port, char *user, char *passwd, char *cmd,int *errchan); /* rsh [-h filename] [-D] host command -h filename is alternative CONFIG.TEL file -D Debug Flag host the NAME (or Number?) of a machine to execute command command a command to pass to the remote host */ int main(int argc, char *argv[]) { int i; int switchcount=1, /* How many switches and switch args are present */ switchlimit; /* How far into argc am I allowed to find switches */ char command[80], /* Text to send to remote host */ *ptr=0, /* pointer to CONFIG.TEL file */ 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 */ if(argc<3) usage(); /* Oops, they haven't got it right */ /* rsh host cmd [-args] */ /* rsh -h file host cmd [-args] */ /* rrsh -h file -D host cmd [-args] */ /* rrsh -D host cmd [-args] */ // switchlimit = (argc<5 ? argc-2 : 4); switchlimit = 3; /* Assume -D has to come first :) */ if(debug) printf("Switchlimit [%d]\n", switchlimit); /* get the command line arguments */ /* Can't parse entire command line-- what if command is ps -eaf so, this appears to do the job for the number of switches allowed */ for(i=1; iargc) usage(); /* do we have the rest ?? */ strcpy(remote_host,argv[switchcount++]); /* the Host to execute */ strcpy(command,argv[switchcount++]); /* The Command */ for(; switchcounthostip[i]); printf("]\n"); } /* end if */ /* open the connection */ conn_id=connect_sock(host_info, port, RSH_PORT); if(conn_id<0) { netshut(); /* Shut down the network */ printf("connect_sock returned %d, exiting\n",conn_id); return (-2); } /* end if */ if(debug) printf("connection ident [%d]\n",conn_id); /* send the request */ netwrite(conn_id, buff, ubase); if (debug) printf("netwrite succeeded--flushing buffer\n"); netpush(conn_id); 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] [%d]\n",event, theclass, dat, conn_id); if(!event || conn_id!=dat) continue; if(event==CONDATA) { len=netread(conn_id, &nullbyte, 1); if(len==0) continue; if(nullbyte != 0) printf( "Byte != 0 [%d]\n", nullbyte); Stimerunset(USERCLASS,ALARM,0); return(conn_id); } /* end if */ else if(event==CONCLOSE) { printf("Unexpected closing of connection!\n"); netshut(); /* Shut down the network */ return (-3); } /* end if */ else { printf("Unexpected event: [%d]\n", event); } /* end else */ } /* end while */ if(theclass == USERCLASS && event == ALARM) { printf("Connection timed out in %d seconds\n", timeout); netshut(); /* Shut down the network */ return(-4); } /* end if */ netshut(); /* Shut down the network */ return(-5); }