/* * new_rsh * Karl Perkins 17/8/95 * * Patches rsh/remsh to use .rhosts to find remote login ID * */ #include #include /* Make sure we use remsh on a HP, else use rsh */ #ifdef __hpux # define RCOM "remsh" #else # define RCOM "rsh" #endif main(argc,argv) int argc; char *argv[]; { char *rcom=RCOM; /* the remote command to use (rsh or remsh) */ char command[512]; /* used to store the final shell command */ char machine[256],userid[10]; FILE *rhosts; /* for opening the .rhosts file */ /* index points the host name in the command line that we wish to contact. I assume that new_rsh has been called via a symbolic link so the host name is the name of the process */ int index=0; if (!strcmp(argv[0],"new_rsh")) /* then not called from a symbolic link */ { if (argc==1) { fprintf(stderr,"usage: new_rsh [ host ] [ parameters to pass to %s ]\n",rcom); exit(1); } index=1; /* index now correctly points to the host name */ } /* Open up .rhosts and find the user ID on the remote machine */ sprintf(command, "%s/.rhosts", getenv("HOME")); if ((rhosts=fopen(command,"r")) == NULL) { fprintf(stderr,"Can't find .rhosts\n"); exit(1); } do { fscanf(rhosts,"%s %s\n",machine,userid); } while (!feof(rhosts) && strcmp(argv[index],machine)); fclose(rhosts); /* If the host was in .rhosts then supply remsh/rsh with the -l parameter, else don't */ if (!strcmp(argv[index],machine)) sprintf(command,"exec %s %s -l %s",rcom,argv[index],userid); else sprintf(command,"exec %s %s",rcom,argv[index]); /* Now put the other arguments that the user typed in after our modified remsh/rsh command, if there are any */ if ((index+1) < argc) { sprintf(command,"%s \"%s",command,argv[++index]); while (++index < argc) sprintf(command,"%s %s",command,argv[index]); sprintf(command,"%s\"",command); } system(command); /* now do it */ }