File: authmoduser.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 (92 lines) | stat: -rw-r--r-- 1,450 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
** Copyright 1998 - 2000 Double Precision, Inc.  See COPYING for
** distribution information.
*/

#include	"auth.h"
#include	"authmod.h"
#include	"authwait.h"
#include	<sys/types.h>
#include	<stdio.h>
#include	<string.h>
#include	<stdlib.h>
#include	<fcntl.h>
#if	HAVE_UNISTD_H
#include	<unistd.h>
#endif
#include	<signal.h>

static const char rcsid[]="$Id: authmoduser.c,v 1.6 2001/11/29 02:57:15 mrsam Exp $";

void authmod(int argc, char **argv,
	const char *service,
	const char *authtype,
	const char *authdata)
{
int	pipe3fd[2];
pid_t	pid;
char	*buf;
int	waitstat;
char	*p;
int	l;

	signal(SIGCHLD, SIG_DFL);

	while (wait(&waitstat) >= 0)
		;
	alarm(0);
	close(3);
	while (open("/dev/null", O_RDWR) != 3)
		;

	if (pipe(pipe3fd))
	{
		perror("pipe");
		authexit(1);
	}

	while ((pid=fork()) == -1)
	{
		sleep(5);
	}

	if (pid)
	{
	char	*prog;
	char	**argvec=authcopyargv(argc, argv, &prog);

		if (!prog)	authexit(1);
		close(3);
		dup(pipe3fd[0]);
		close(pipe3fd[0]);
		close(pipe3fd[1]);
		execv(prog, argvec);
		perror(prog);
		authexit(1);
	}
	close(3);
	close(pipe3fd[0]);

	buf=malloc(strlen(service)+strlen(authtype)+strlen(authdata)+4);
	if (!buf)
	{
		perror("malloc");
		authexit(1);
	}
	sprintf(buf, "%s\n%s\n%s\n", service, authtype, authdata);

	p=buf;
	l=strlen(p);
	while (l)
	{
	int	n=write(pipe3fd[1], p, l);

		if (n <= 0)	break;
		p += n;
		l -= n;
	}
	free(buf);
	close(pipe3fd[0]);
	close(pipe3fd[1]);
	authexit(1);
}