summaryrefslogtreecommitdiff
path: root/accel-pptpd/ppp_auth.c
blob: 1117c2113c80754361b0c86c26a62d3d3f110e94 (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "triton/triton.h"

#include "ppp.h"
#include "ppp_lcp.h"
#include "ppp_fsm.h"
#include "ppp_auth.h"

static LIST_HEAD(drv_list);

int auth_register(struct auth_driver_t *new)
{
	struct auth_driver_t *drv;

	list_for_each_entry(drv,&drv_list,entry)
	{
		if (drv->type==new->type)
			return -1;
	}
	list_add_tail(&new->entry,&drv_list);
	return 0;
}

int auth_get_conf_req(struct ppp_layer_t *l, struct lcp_opt32_t *opt)
{
	int i,n;
	struct auth_driver_t *drv;

	for(i=0; i<AUTH_MAX; i++)
	{
		if (l->ppp->auth[i] && l->options.lcp.neg_auth[i]>0)
			goto cont;
	}
	for(i=0; i<AUTH_MAX; i++)
	{
		if (l->ppp->auth[i] && l->options.lcp.neg_auth[i]==0)
			goto cont;
	}
	return -1;

cont:
	list_for_each_entry(drv,&drv_list,entry)
	{
		if (drv->type==l->ppp->auth[i])
			break;
	}
	n=drv->get_conf_req(drv,l,opt);
	opt->val=l->auth[i];
	opt->hdr.len=6+n;
	return 0;
}
int auth_recv_conf_req(struct ppp_layer_t *l, struct lcp_opt_hdr_t *hdr)
{
	struct lcp_opt32_t *opt=(struct lcp_opt32_t*)hdr;
	struct auth_driver_t *drv;
	int i;

	for(i=0; i<AUTH_MAX; i++)
	{
		if (l->ppp->auth[i]==opt->val)
		{
			list_for_each_entry(drv,&drv_list,entry)
			{
				if (drv->type==l->ppp->auth[i])
				{
					if (drv->recv_conf_req(drv,l->ppp,opt))
						return -1;
					l->options.lcp.neg_auth[i]=1;
					return 0;
				}
			}
			return -1;
		}
	}
	return -1;
}
int auth_recv_conf_rej(struct ppp_layer_t *l, struct lcp_opt_hdr_t *hdr)
{
	struct lcp_opt32_t *opt=(struct lcp_opt32_t*)hdr;
	int i;

	for(i=0; i<AUTH_MAX; i++)
	{
		if (l->ppp->auth[i]==opt->val)
		{
			l->options.lcp.neg_auth[i]=-1;
			break;
		}
	}
	for(i=0; i<AUTH_MAX; i++)
	{
		if (l->ppp->auth[i] && l->options.lcp.neg_auth[i]!=-1)
			return 0;
	}
	return -1;
}
int auth_recv_conf_nak(struct ppp_layer_t *l, struct lcp_opt_hdr_t *hdr)
{
	struct lcp_opt32_t *opt=(struct lcp_opt32_t*)hdr;
	int i;

	for(i=0; i<AUTH_MAX; i++)
	{
		if (l->ppp->auth[i]==opt->val)
		{
			l->options.lcp.neg_auth[i]=2;
			return 0;
		}
	}
	return -1;
}

int auth_start(struct ppp_t *ppp)
{
	int i;
	struct auth_driver_t *drv;

	for(i=0; i<AUTH_MAX; i++)
	{
		if (ppp->lcp_layer->options.lcp.neg_auth[i]==1)
		{
			list_for_each_entry(drv,&drv_list,entry)
			{
				if (drv->type==ppp->auth[i])
					return drv->start(ppp);
			}
			return -1;
		}
	}

	return 0;
}

void auth_finish(struct ppp_t *ppp)
{
	int i;
	struct auth_driver_t *drv;

	for(i=0; i<AUTH_MAX; i++)
	{
		if (ppp->lcp_layer->options.lcp.neg_auth[i]==1)
		{
			list_for_each_entry(drv,&drv_list,entry)
			{
				if (drv->type==ppp->auth[i])
				{
					drv->finish(ppp);
					return;
				}
			}
		}
	}
}

void auth_successed(struct ppp_t *ppp)
{
	ppp_layer_started(ppp);
}

void auth_failed(struct ppp_t *ppp)
{
	ppp_terminate(ppp);
}