|
|
1.1 ! root 1: /* ! 2: * Version of execv that mimics the ! 3: * actions of the shell in using search ! 4: * rules and running a shell file. ! 5: */ ! 6: ! 7: #include <stdio.h> ! 8: #include <errno.h> ! 9: #include <string.h> ! 10: ! 11: #define NFNAME 100 /* Largest filename */ ! 12: ! 13: static char srch[] = ":/bin"; ! 14: static char shell[] = "/bin/sh"; ! 15: ! 16: extern int errno; ! 17: ! 18: execvep(name, argp, envp) ! 19: char *name; ! 20: char *argp[]; ! 21: char *envp[]; ! 22: { ! 23: char *getenv(); ! 24: register char *p1, *p2; ! 25: register char *sp; ! 26: char fname[NFNAME]; ! 27: ! 28: if ((sp = getenv("PATH")) == NULL) ! 29: sp = srch; ! 30: for (;;) { ! 31: p2 = fname; ! 32: while (*sp!='\0' && *sp!=':') ! 33: *p2++ = *sp++; ! 34: p1 = name; ! 35: if (p2 != fname) ! 36: *p2++ = '/'; ! 37: while (*p1 != '\0') ! 38: *p2++ = *p1++; ! 39: *p2 = '\0'; ! 40: if (strchr(name, '/') != NULL) { ! 41: execve(name, argp, envp); ! 42: if (errno != ENOEXEC) ! 43: break; ! 44: } else ! 45: execve(fname, argp, envp); ! 46: if (errno == ENOEXEC) { ! 47: register char *sv1, *sv2; ! 48: ! 49: sv1 = argp[-1]; ! 50: sv2 = argp[0]; ! 51: argp[-1] = shell; ! 52: argp[0] = fname; ! 53: execve(shell, argp-1, envp); ! 54: argp[-1] = sv1; ! 55: argp[0] = sv2; ! 56: break; ! 57: } ! 58: if (*sp == '\0') ! 59: break; ! 60: if (*sp == ':') ! 61: sp++; ! 62: } ! 63: return (-1); ! 64: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.