Deleted Added
full compact
auth.c (43525) auth.c (43693)
1/*
2 * PPP Secret Key Module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1994, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
1/*
2 * PPP Secret Key Module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1994, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * $Id: auth.c,v 1.36 1999/02/01 13:42:24 brian Exp $
20 * $Id: auth.c,v 1.37 1999/02/02 09:35:17 brian Exp $
21 *
22 * TODO:
23 * o Implement check against with registered IP addresses.
24 */
25#include <sys/param.h>
26#include <netinet/in.h>
27#include <netinet/in_systm.h>
28#include <netinet/ip.h>

--- 174 unchanged lines hidden (view full) ---

203{
204 /* Used by PAP routines */
205
206 FILE *fp;
207 int n;
208 char *vector[5];
209 char buff[LINE_LEN];
210
21 *
22 * TODO:
23 * o Implement check against with registered IP addresses.
24 */
25#include <sys/param.h>
26#include <netinet/in.h>
27#include <netinet/in_systm.h>
28#include <netinet/ip.h>

--- 174 unchanged lines hidden (view full) ---

203{
204 /* Used by PAP routines */
205
206 FILE *fp;
207 int n;
208 char *vector[5];
209 char buff[LINE_LEN];
210
211#ifndef NORADIUS
212 if (*bundle->radius.cfg.file)
213 return radius_Authenticate(&bundle->radius, bundle, name, key, NULL);
214#endif
215
216 fp = OpenSecret(SECRETFILE);
217 if (fp != NULL) {
218 while (fgets(buff, sizeof buff, fp)) {
219 if (buff[0] == '#')
220 continue;
221 buff[strlen(buff) - 1] = 0;
222 memset(vector, '\0', sizeof vector);
223 n = MakeArgs(buff, vector, VECSIZE(vector));

--- 49 unchanged lines hidden (view full) ---

273
274static void
275AuthTimeout(void *vauthp)
276{
277 struct authinfo *authp = (struct authinfo *)vauthp;
278
279 timer_Stop(&authp->authtimer);
280 if (--authp->retry > 0) {
211 fp = OpenSecret(SECRETFILE);
212 if (fp != NULL) {
213 while (fgets(buff, sizeof buff, fp)) {
214 if (buff[0] == '#')
215 continue;
216 buff[strlen(buff) - 1] = 0;
217 memset(vector, '\0', sizeof vector);
218 n = MakeArgs(buff, vector, VECSIZE(vector));

--- 49 unchanged lines hidden (view full) ---

268
269static void
270AuthTimeout(void *vauthp)
271{
272 struct authinfo *authp = (struct authinfo *)vauthp;
273
274 timer_Stop(&authp->authtimer);
275 if (--authp->retry > 0) {
276 authp->id++;
277 (*authp->fn.req)(authp);
281 timer_Start(&authp->authtimer);
278 timer_Start(&authp->authtimer);
282 (*authp->ChallengeFunc)(authp, ++authp->id, authp->physical);
283 } else {
284 log_Printf(LogPHASE, "Auth: No response from server\n");
285 datalink_AuthNotOk(authp->physical->dl);
286 }
287}
288
289void
279 } else {
280 log_Printf(LogPHASE, "Auth: No response from server\n");
281 datalink_AuthNotOk(authp->physical->dl);
282 }
283}
284
285void
290auth_Init(struct authinfo *authinfo)
286auth_Init(struct authinfo *authp, struct physical *p, auth_func req,
287 auth_func success, auth_func failure)
291{
288{
292 memset(authinfo, '\0', sizeof(struct authinfo));
293 authinfo->cfg.fsmretry = DEF_FSMRETRY;
289 memset(authp, '\0', sizeof(struct authinfo));
290 authp->cfg.fsmretry = DEF_FSMRETRY;
291 authp->fn.req = req;
292 authp->fn.success = success;
293 authp->fn.failure = failure;
294 authp->physical = p;
294}
295
296void
295}
296
297void
297auth_StartChallenge(struct authinfo *authp, struct physical *physical,
298 void (*chal)(struct authinfo *, int, struct physical *))
298auth_StartReq(struct authinfo *authp)
299{
299{
300 authp->ChallengeFunc = chal;
301 authp->physical = physical;
302 timer_Stop(&authp->authtimer);
303 authp->authtimer.func = AuthTimeout;
304 authp->authtimer.name = "auth";
305 authp->authtimer.load = authp->cfg.fsmretry * SECTICKS;
300 timer_Stop(&authp->authtimer);
301 authp->authtimer.func = AuthTimeout;
302 authp->authtimer.name = "auth";
303 authp->authtimer.load = authp->cfg.fsmretry * SECTICKS;
306 authp->authtimer.arg = (void *) authp;
304 authp->authtimer.arg = (void *)authp;
307 authp->retry = 3;
308 authp->id = 1;
305 authp->retry = 3;
306 authp->id = 1;
309 (*authp->ChallengeFunc)(authp, authp->id, physical);
307 (*authp->fn.req)(authp);
310 timer_Start(&authp->authtimer);
311}
312
313void
314auth_StopTimer(struct authinfo *authp)
315{
316 timer_Stop(&authp->authtimer);
308 timer_Start(&authp->authtimer);
309}
310
311void
312auth_StopTimer(struct authinfo *authp)
313{
314 timer_Stop(&authp->authtimer);
317 authp->physical = NULL;
318}
315}
316
317struct mbuf *
318auth_ReadHeader(struct authinfo *authp, struct mbuf *bp)
319{
320 int len;
321
322 len = mbuf_Length(bp);
323 if (len >= sizeof authp->in.hdr) {
324 bp = mbuf_Read(bp, (u_char *)&authp->in.hdr, sizeof authp->in.hdr);
325 if (len >= ntohs(authp->in.hdr.length))
326 return bp;
327 }
328
329 mbuf_Free(bp);
330 return NULL;
331}
332
333struct mbuf *
334auth_ReadName(struct authinfo *authp, struct mbuf *bp, int len)
335{
336 if (len > sizeof authp->in.name - 1)
337 log_Printf(LogERROR, "auth_ReadName: Name too long (%d) !\n", len);
338 else {
339 int mlen = mbuf_Length(bp);
340
341 if (len > mlen)
342 log_Printf(LogERROR, "auth_ReadName: Short packet !\n");
343 else {
344 bp = mbuf_Read(bp, (u_char *)authp->in.name, len);
345 authp->in.name[len] = '\0';
346 return bp;
347 }
348 }
349
350 *authp->in.name = '\0';
351 mbuf_Free(bp);
352 return NULL;
353}