File: authmod.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 (101 lines) | stat: -rw-r--r-- 1,646 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
93
94
95
96
97
98
99
100
101
/*
** Copyright 1998 - 1999 Double Precision, Inc.  See COPYING for
** distribution information.
*/

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

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

static char	authrec[BUFSIZ];
static char	buf[BUFSIZ];

void	authmod_init(
		int argc,
		char **argv,
		const char **service,
		const char **authtype,
		char **authdata)
{
FILE	*fpin;
int	waitstat;
const char *a=getenv("AUTHENTICATED");
char	*p;
int	n;

	if (a && *a)	/* Already a good guy */
		authmod_success(argc, argv, a);

	n=0;
	fpin=fdopen(3, "r");
	if (fpin)
	{
	int	c;

		while ((c=getc(fpin)) != EOF)
			if (n < sizeof(buf)-1)
				buf[n++]=c;
		buf[n]=0;
	}

	if (n == 0)
	{
		write(2, "AUTHFAILURE\n", 12);
		authexit(1);
	}

	fclose(fpin);
	close(3);	/* Insurance */
	strcpy(authrec, buf);

	signal(SIGCHLD, SIG_DFL);

	while (wait(&waitstat) >= 0)
		;

	p=buf;
	*service=p;
	while (*p && *p != '\n')
		++p;
	if (*p)	*p++=0;
	*authtype=p;
	while (*p && *p != '\n')
		++p;
	if (*p)	*p++=0;
	*authdata=p;
}

void authmod_success(int argc, char **argv, const char *a)
{
char	**vec, *prog;
char	*b;

	vec=authcopyargv(argc-1, argv+1, &prog);
	if (!prog)	authexit(1);

	b=malloc(sizeof("AUTHENTICATED=")+strlen(a));
	if (!b)
	{
		perror("malloc");
		authexit(1);
	}
	strcat(strcpy(b, "AUTHENTICATED="), a);
	putenv(b);
	execv(prog, vec);
	perror(prog);
	authexit(1);
}

void authmod_fail(int argc, char **argv)
{
	authchain(argc-1, argv+1, authrec);	/* Next module */
}