equal
deleted
inserted
replaced
|
1 /* |
|
2 ** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for |
|
3 ** distribution information. |
|
4 */ |
|
5 |
|
6 #if HAVE_CONFIG_H |
|
7 #include "config.h" |
|
8 #endif |
|
9 #include <stdio.h> |
|
10 #include <stdlib.h> |
|
11 #include <string.h> |
|
12 #if HAVE_UNISTD_H |
|
13 #include <unistd.h> |
|
14 #endif |
|
15 #if HAVE_FCNTL_H |
|
16 #include <fcntl.h> |
|
17 #endif |
|
18 |
|
19 #include "auth.h" |
|
20 |
|
21 static const char rcsid[]="$Id: chain.c,v 1.1 2000/04/13 17:55:05 bruce Exp $"; |
|
22 |
|
23 void authchain(int argc, char **argv, const char *buf) |
|
24 { |
|
25 int pipes[2]; |
|
26 pid_t p; |
|
27 int l, n; |
|
28 char **vec; |
|
29 char *prog; |
|
30 |
|
31 vec=authcopyargv(argc, argv, &prog); |
|
32 if (!prog || open("/dev/null", O_RDONLY) != 3) authexit(1); |
|
33 |
|
34 if (pipe(pipes)) |
|
35 { |
|
36 perror("pipe"); |
|
37 authexit(1); |
|
38 } |
|
39 while ((p=fork()) < 0) |
|
40 { |
|
41 perror("fork"); |
|
42 sleep(3); |
|
43 } |
|
44 close(3); |
|
45 |
|
46 if (p) |
|
47 { |
|
48 dup(pipes[0]); |
|
49 close(pipes[0]); |
|
50 close(pipes[1]); |
|
51 execv(prog, vec); |
|
52 perror(prog); |
|
53 authexit(1); |
|
54 } |
|
55 l=strlen(buf); |
|
56 close(3); |
|
57 close(pipes[0]); |
|
58 while (l) |
|
59 { |
|
60 n=write(pipes[1], buf, l); |
|
61 if (n <= 0) break; |
|
62 buf += n; |
|
63 l -= n; |
|
64 } |
|
65 close(pipes[1]); |
|
66 authexit(1); |
|
67 } |