|
|
1.1 ! root 1: #ifndef lint ! 2: static char sccsid[] = "@(#)gwd.c 5.1 (Berkeley) 7/2/83"; ! 3: #endif ! 4: ! 5: #include "uucp.h" ! 6: ! 7: /******* ! 8: * gwd(wkdir) get working directory ! 9: * ! 10: * return codes 0 | FAIL ! 11: */ ! 12: ! 13: gwd(wkdir) ! 14: register char *wkdir; ! 15: { ! 16: register FILE *fp; ! 17: extern FILE *rpopen(); ! 18: extern int rpclose(); ! 19: register char *c; ! 20: ! 21: *wkdir = '\0'; ! 22: /* PATH added to rpopen. Suggested by Henry Spencer (utzoo!henry) */ ! 23: if ((fp = rpopen("PATH=/bin:/usr/bin;pwd 2>&-", "r")) == NULL) ! 24: return(FAIL); ! 25: if (fgets(wkdir, 100, fp) == NULL) { ! 26: pclose(fp); ! 27: return(FAIL); ! 28: } ! 29: if (*(c = wkdir + strlen(wkdir) - 1) == '\n') ! 30: *c = '\0'; ! 31: rpclose(fp); ! 32: return(0); ! 33: } ! 34: ! 35: /* ! 36: * rti!trt: gwd uses 'reverting' version of popen ! 37: * which runs process with permissions of real gid/uid ! 38: * rather than the effective gid/uid. ! 39: * Bug noted by we13!rjk (Randy King). ! 40: */ ! 41: /* @(#)popen.c 4.1 (Berkeley) 12/21/80 */ ! 42: #include <signal.h> ! 43: #define tst(a,b) (*mode == 'r'? (b) : (a)) ! 44: #define RDR 0 ! 45: #define WTR 1 ! 46: static int popen_pid[20]; ! 47: ! 48: FILE * ! 49: rpopen(cmd,mode) ! 50: char *cmd; ! 51: char *mode; ! 52: { ! 53: int p[2]; ! 54: register myside, hisside, pid; ! 55: ! 56: if(pipe(p) < 0) ! 57: return NULL; ! 58: myside = tst(p[WTR], p[RDR]); ! 59: hisside = tst(p[RDR], p[WTR]); ! 60: if((pid = fork()) == 0) { ! 61: /* myside and hisside reverse roles in child */ ! 62: close(myside); ! 63: dup2(hisside, tst(0, 1)); ! 64: close(hisside); ! 65: /* revert permissions */ ! 66: setgid(getgid()); ! 67: setuid(getuid()); ! 68: execl("/bin/sh", "sh", "-c", cmd, (char *)0); ! 69: _exit(1); ! 70: } ! 71: if(pid == -1) ! 72: return NULL; ! 73: popen_pid[myside] = pid; ! 74: close(hisside); ! 75: return(fdopen(myside, mode)); ! 76: } ! 77: ! 78: rpclose(ptr) ! 79: FILE *ptr; ! 80: { ! 81: register f, r, (*hstat)(), (*istat)(), (*qstat)(); ! 82: int status; ! 83: ! 84: f = fileno(ptr); ! 85: fclose(ptr); ! 86: istat = signal(SIGINT, SIG_IGN); ! 87: qstat = signal(SIGQUIT, SIG_IGN); ! 88: hstat = signal(SIGHUP, SIG_IGN); ! 89: while((r = wait(&status)) != popen_pid[f] && r != -1) ! 90: ; ! 91: if(r == -1) ! 92: status = -1; ! 93: signal(SIGINT, istat); ! 94: signal(SIGQUIT, qstat); ! 95: signal(SIGHUP, hstat); ! 96: return(status); ! 97: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.