Lines Matching defs:chap

30  * $FreeBSD: stable/11/usr.sbin/ppp/chap.c 330449 2018-03-05 07:26:05Z eadler $
70 #include "chap.h"
258 chap_StartChild(struct chap *chap, char *prog, const char *name)
265 if (chap->child.fd != -1) {
283 switch ((chap->child.pid = fork())) {
290 chap->child.pid = 0;
322 chap->auth.physical->dl->bundle, 0, pid);
330 chap->child.fd = out[0];
331 chap->child.buf.len = 0;
332 write(in[1], chap->auth.in.name, strlen(chap->auth.in.name));
334 write(in[1], chap->challenge.peer + 1, *chap->challenge.peer);
344 chap_Cleanup(struct chap *chap, int sig)
346 if (chap->child.pid) {
349 close(chap->child.fd);
350 chap->child.fd = -1;
352 kill(chap->child.pid, SIGTERM);
353 chap->child.pid = 0;
354 chap->child.buf.len = 0;
363 *chap->challenge.local = *chap->challenge.peer = '\0';
365 chap->peertries = 0;
370 chap_Respond(struct chap *chap, char *name, char *key
378 ans = chap_BuildAnswer(name, key, chap->auth.id, chap->challenge.peer
380 , type, chap->challenge.local, chap->authresponse, lm
385 ChapOutput(chap->auth.physical, CHAP_RESPONSE, chap->auth.id,
388 chap->NTRespSent = !lm;
393 ChapOutput(chap->auth.physical, CHAP_FAILURE, chap->auth.id,
401 struct chap *chap = descriptor2chap(d);
403 if (r && chap && chap->child.fd != -1) {
404 FD_SET(chap->child.fd, r);
405 if (*n < chap->child.fd + 1)
406 *n = chap->child.fd + 1;
407 log_Printf(LogTIMER, "Chap: fdset(r) %d\n", chap->child.fd);
417 struct chap *chap = descriptor2chap(d);
419 return chap && chap->child.fd != -1 && FD_ISSET(chap->child.fd, fdset);
426 struct chap *chap = descriptor2chap(d);
429 got = read(chap->child.fd, chap->child.buf.ptr + chap->child.buf.len,
430 sizeof chap->child.buf.ptr - chap->child.buf.len - 1);
433 chap_Cleanup(chap, SIGTERM);
436 chap_Cleanup(chap, SIGTERM);
440 chap->child.buf.len += got;
441 chap->child.buf.ptr[chap->child.buf.len] = '\0';
442 name = chap->child.buf.ptr;
450 if (chap->child.buf.len == sizeof chap->child.buf.ptr - 1) {
452 chap_Cleanup(chap, SIGTERM);
456 int lanman = chap->auth.physical->link.lcp.his_authtype == 0x80 &&
457 ((chap->NTRespSent &&
458 IsAccepted(chap->auth.physical->link.lcp.cfg.chap80lm)) ||
459 !IsAccepted(chap->auth.physical->link.lcp.cfg.chap80nt));
469 chap_Respond(chap, name, key
471 , chap->auth.physical->link.lcp.his_authtype, lanman
474 chap_Cleanup(chap, 0);
491 struct chap *chap = auth2chap(authp);
497 if (!*chap->challenge.local) {
499 cp = chap->challenge.local;
518 for (i = 0; i < *chap->challenge.local; i++)
528 struct chap *chap = auth2chap(authp);
537 if (!*chap->challenge.local)
543 chap->challenge.local, 1 + *chap->challenge.local, NULL);
547 chap->challenge.local, 1 + *chap->challenge.local + len, NULL);
657 chap_HaveAnotherGo(struct chap *chap)
659 if (++chap->peertries < 3) {
661 *chap->challenge.local = '\0';
662 chap_Challenge(&chap->auth);
671 chap_Init(struct chap *chap, struct physical *p)
673 chap->desc.type = CHAP_DESCRIPTOR;
674 chap->desc.UpdateSet = chap_UpdateSet;
675 chap->desc.IsSet = chap_IsSet;
676 chap->desc.Read = chap_Read;
677 chap->desc.Write = chap_Write;
678 chap->child.pid = 0;
679 chap->child.fd = -1;
680 auth_Init(&chap->auth, p, chap_Challenge, chap_Success, chap_Failure);
681 *chap->challenge.local = *chap->challenge.peer = '\0';
683 chap->NTRespSent = 0;
684 chap->peertries = 0;
689 chap_ReInit(struct chap *chap)
691 chap_Cleanup(chap, SIGTERM);
698 struct chap *chap = &p->dl->chap;
715 log_Printf(LogPHASE, "Unexpected chap input - dropped !\n");
721 if ((bp = auth_ReadHeader(&chap->auth, bp)) == NULL &&
722 ntohs(chap->auth.in.hdr.length) == 0)
724 else if (chap->auth.in.hdr.code == 0 || chap->auth.in.hdr.code > MAXCHAPCODE)
726 chap->auth.in.hdr.code);
731 if (chap->auth.in.hdr.code != CHAP_CHALLENGE &&
732 chap->auth.id != chap->auth.in.hdr.id &&
736 chapcodes[chap->auth.in.hdr.code], chap->auth.in.hdr.id,
737 chap->auth.id);
741 chap->auth.id = chap->auth.in.hdr.id; /* We respond with this id */
746 switch (chap->auth.in.hdr.code) {
755 *chap->challenge.peer = alen;
756 bp = mbuf_Read(bp, chap->challenge.peer + 1, alen);
757 bp = auth_ReadName(&chap->auth, bp, len);
760 ((chap->NTRespSent && IsAccepted(p->link.lcp.cfg.chap80lm)) ||
764 chap_ChallengeInit(&chap->auth);
769 auth_StopTimer(&chap->auth);
782 *ans = chap->auth.id;
784 bp = auth_ReadName(&chap->auth, bp, len);
793 /* chap->auth.in.name is already set up at CHALLENGE time */
804 switch (chap->auth.in.hdr.code) {
807 if (*chap->auth.in.name)
809 chapcodes[chap->auth.in.hdr.code], alen,
810 chap->auth.in.name,
812 lanman && chap->auth.in.hdr.code == CHAP_RESPONSE ?
818 chapcodes[chap->auth.in.hdr.code], alen,
820 lanman && chap->auth.in.hdr.code == CHAP_RESPONSE ?
830 chapcodes[chap->auth.in.hdr.code], ans);
833 chapcodes[chap->auth.in.hdr.code]);
837 switch (chap->auth.in.hdr.code) {
840 chap_StartChild(chap, bundle->cfg.auth.key + 1,
843 chap_Respond(chap, bundle->cfg.auth.name, bundle->cfg.auth.key +
853 name = chap->auth.in.name;
859 chap->challenge.peer[0] = sizeof resp->PeerChallenge;
860 memcpy(chap->challenge.peer + 1, resp->PeerChallenge,
867 if (!radius_Authenticate(&bundle->radius, &chap->auth,
868 chap->auth.in.name, ans, alen + 1,
869 chap->challenge.local + 1,
870 *chap->challenge.local))
871 chap_Failure(&chap->auth);
889 if (chap_HaveAnotherGo(chap))
895 if (chap_HaveAnotherGo(chap))
905 char *myans = chap_BuildAnswer(name, key, chap->auth.id,
906 chap->challenge.local
909 chap->challenge.peer,
910 chap->authresponse, lanman);
930 chap_Success(&chap->auth);
932 chap_Failure(&chap->auth);
943 if (strncasecmp(ans, chap->authresponse, 42)) {
946 " != ans: (%.42s)\n", chap->authresponse, ans);