| 1 | #ifndef lint |
| 2 | static char sccsid[] = "@(#)shio.c 5.1 (Berkeley) %G%"; |
| 3 | #endif |
| 4 | |
| 5 | #include "uucp.h" |
| 6 | #include <signal.h> |
| 7 | |
| 8 | |
| 9 | /******* |
| 10 | * shio(cmd, fi, fo, user) execute shell of command with |
| 11 | * char *cmd, *fi, *fo; fi and fo as standard input/output |
| 12 | * char *user; user name |
| 13 | * |
| 14 | * return codes: |
| 15 | * 0 - ok |
| 16 | * non zero - failed - status from child |
| 17 | */ |
| 18 | |
| 19 | shio(cmd, fi, fo, user) |
| 20 | char *cmd, *fi, *fo, *user; |
| 21 | { |
| 22 | int status, f; |
| 23 | int uid, pid, ret; |
| 24 | char path[MAXFULLNAME]; |
| 25 | |
| 26 | if (fi == NULL) |
| 27 | fi = "/dev/null"; |
| 28 | if (fo == NULL) |
| 29 | fo = "/dev/null"; |
| 30 | |
| 31 | DEBUG(3, "shio - %s\n", cmd); |
| 32 | if ((pid = fork()) == 0) { |
| 33 | signal(SIGINT, SIG_IGN); |
| 34 | signal(SIGHUP, SIG_IGN); |
| 35 | signal(SIGQUIT, SIG_IGN); |
| 36 | signal(SIGKILL, SIG_IGN); |
| 37 | close(Ifn); |
| 38 | close(Ofn); |
| 39 | close(0); |
| 40 | if (user == NULL |
| 41 | || (gninfo(user, &uid, path) != 0) |
| 42 | || setuid(uid)) |
| 43 | setuid(getuid()); |
| 44 | f = open(subfile(fi), 0); |
| 45 | if (f != 0) |
| 46 | exit(f); |
| 47 | close(1); |
| 48 | f = creat(subfile(fo), 0666); |
| 49 | if (f != 1) |
| 50 | exit(f); |
| 51 | execl(SHELL, "sh", "-c", cmd, (char *)0); |
| 52 | exit(100); |
| 53 | } |
| 54 | while ((ret = wait(&status)) != pid && ret != -1); |
| 55 | DEBUG(3, "status %d\n", status); |
| 56 | return(status); |
| 57 | } |