File: chain.c

package info (click to toggle)
courier 0.47-4sarge5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 32,680 kB
  • ctags: 12,265
  • sloc: ansic: 164,045; cpp: 23,863; sh: 19,569; perl: 7,225; makefile: 4,192; yacc: 316; sed: 16
file content (67 lines) | stat: -rw-r--r-- 1,026 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
** Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for
** distribution information.
*/

#if	HAVE_CONFIG_H
#include	"config.h"
#endif
#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>
#if	HAVE_UNISTD_H
#include	<unistd.h>
#endif
#if	HAVE_FCNTL_H
#include	<fcntl.h>
#endif

#include	"auth.h"

static const char rcsid[]="$Id: chain.c,v 1.4 2000/05/14 17:39:10 mrsam Exp $";

void authchain(int argc, char **argv, const char *buf)
{
int	pipes[2];
pid_t	p;
int	l, n;
char	**vec;
char	*prog;

	vec=authcopyargv(argc, argv, &prog);
	close(3);
	if (!prog || open("/dev/null", O_RDONLY) != 3)	authexit(1);

	if (pipe(pipes))
	{
		perror("pipe");
		authexit(1);
	}
	while ((p=fork()) < 0)
	{
		perror("fork");
		sleep(3);
	}
	close(3);

	if (p)
	{
		dup(pipes[0]);
		close(pipes[0]);
		close(pipes[1]);
		execv(prog, vec);
		perror(prog);
		authexit(1);
	}
	l=strlen(buf);
	close(pipes[0]);
	while (l)
	{
		n=write(pipes[1], buf, l);
		if (n <= 0)	break;
		buf += n;
		l -= n;
	}
	close(pipes[1]);
	authexit(1);
}