lib/courier-authlib/chain.c
changeset 2 b3afb9f1e801
parent 0 6f7a81934006
equal deleted inserted replaced
1:30113bfbe723 2:b3afb9f1e801
    16 #include	<fcntl.h>
    16 #include	<fcntl.h>
    17 #endif
    17 #endif
    18 
    18 
    19 #include	"auth.h"
    19 #include	"auth.h"
    20 
    20 
    21 static const char rcsid[]="$Id: chain.c,v 1.1 2000/04/13 17:55:05 bruce Exp $";
    21 static const char rcsid[]="$Id: chain.c,v 1.2 2000/12/18 20:20:10 bruce Exp $";
    22 
    22 
    23 void authchain(int argc, char **argv, const char *buf)
    23 void authchain(int argc, char **argv, const char *buf)
    24 {
    24 {
    25 int	pipes[2];
    25 int	pipes[2];
    26 pid_t	p;
    26 pid_t	p;
    27 int	l, n;
    27 int	l, n;
    28 char	**vec;
    28 char	**vec;
    29 char	*prog;
    29 char	*prog;
    30 
    30 
    31 	vec=authcopyargv(argc, argv, &prog);
    31 	vec=authcopyargv(argc, argv, &prog);
       
    32 	close(3);
    32 	if (!prog || open("/dev/null", O_RDONLY) != 3)	authexit(1);
    33 	if (!prog || open("/dev/null", O_RDONLY) != 3)	authexit(1);
    33 
    34 
    34 	if (pipe(pipes))
    35 	if (pipe(pipes))
    35 	{
    36 	{
    36 		perror("pipe");
    37 		perror("pipe");
    51 		execv(prog, vec);
    52 		execv(prog, vec);
    52 		perror(prog);
    53 		perror(prog);
    53 		authexit(1);
    54 		authexit(1);
    54 	}
    55 	}
    55 	l=strlen(buf);
    56 	l=strlen(buf);
    56 	close(3);
       
    57 	close(pipes[0]);
    57 	close(pipes[0]);
    58 	while (l)
    58 	while (l)
    59 	{
    59 	{
    60 		n=write(pipes[1], buf, l);
    60 		n=write(pipes[1], buf, l);
    61 		if (n <= 0)	break;
    61 		if (n <= 0)	break;