Lines Matching refs:chap

68 #include "chap.h"
256 chap_StartChild(struct chap *chap, char *prog, const char *name)
263 if (chap->child.fd != -1) {
281 switch ((chap->child.pid = fork())) {
288 chap->child.pid = 0;
320 chap->auth.physical->dl->bundle, 0, pid);
328 chap->child.fd = out[0];
329 chap->child.buf.len = 0;
330 write(in[1], chap->auth.in.name, strlen(chap->auth.in.name));
332 write(in[1], chap->challenge.peer + 1, *chap->challenge.peer);
342 chap_Cleanup(struct chap *chap, int sig)
344 if (chap->child.pid) {
347 close(chap->child.fd);
348 chap->child.fd = -1;
350 kill(chap->child.pid, SIGTERM);
351 chap->child.pid = 0;
352 chap->child.buf.len = 0;
361 *chap->challenge.local = *chap->challenge.peer = '\0';
363 chap->peertries = 0;
368 chap_Respond(struct chap *chap, char *name, char *key
376 ans = chap_BuildAnswer(name, key, chap->auth.id, chap->challenge.peer
378 , type, chap->challenge.local, chap->authresponse, lm
383 ChapOutput(chap->auth.physical, CHAP_RESPONSE, chap->auth.id,
386 chap->NTRespSent = !lm;
391 ChapOutput(chap->auth.physical, CHAP_FAILURE, chap->auth.id,
399 struct chap *chap = descriptor2chap(d);
401 if (r && chap && chap->child.fd != -1) {
402 FD_SET(chap->child.fd, r);
403 if (*n < chap->child.fd + 1)
404 *n = chap->child.fd + 1;
405 log_Printf(LogTIMER, "Chap: fdset(r) %d\n", chap->child.fd);
415 struct chap *chap = descriptor2chap(d);
417 return chap && chap->child.fd != -1 && FD_ISSET(chap->child.fd, fdset);
424 struct chap *chap = descriptor2chap(d);
427 got = read(chap->child.fd, chap->child.buf.ptr + chap->child.buf.len,
428 sizeof chap->child.buf.ptr - chap->child.buf.len - 1);
431 chap_Cleanup(chap, SIGTERM);
434 chap_Cleanup(chap, SIGTERM);
438 chap->child.buf.len += got;
439 chap->child.buf.ptr[chap->child.buf.len] = '\0';
440 name = chap->child.buf.ptr;
448 if (chap->child.buf.len == sizeof chap->child.buf.ptr - 1) {
450 chap_Cleanup(chap, SIGTERM);
454 int lanman = chap->auth.physical->link.lcp.his_authtype == 0x80 &&
455 ((chap->NTRespSent &&
456 IsAccepted(chap->auth.physical->link.lcp.cfg.chap80lm)) ||
457 !IsAccepted(chap->auth.physical->link.lcp.cfg.chap80nt));
467 chap_Respond(chap, name, key
469 , chap->auth.physical->link.lcp.his_authtype, lanman
472 chap_Cleanup(chap, 0);
489 struct chap *chap = auth2chap(authp);
495 if (!*chap->challenge.local) {
497 cp = chap->challenge.local;
516 for (i = 0; i < *chap->challenge.local; i++)
526 struct chap *chap = auth2chap(authp);
535 if (!*chap->challenge.local)
541 chap->challenge.local, 1 + *chap->challenge.local, NULL);
545 chap->challenge.local, 1 + *chap->challenge.local + len, NULL);
655 chap_HaveAnotherGo(struct chap *chap)
657 if (++chap->peertries < 3) {
659 *chap->challenge.local = '\0';
660 chap_Challenge(&chap->auth);
669 chap_Init(struct chap *chap, struct physical *p)
671 chap->desc.type = CHAP_DESCRIPTOR;
672 chap->desc.UpdateSet = chap_UpdateSet;
673 chap->desc.IsSet = chap_IsSet;
674 chap->desc.Read = chap_Read;
675 chap->desc.Write = chap_Write;
676 chap->child.pid = 0;
677 chap->child.fd = -1;
678 auth_Init(&chap->auth, p, chap_Challenge, chap_Success, chap_Failure);
679 *chap->challenge.local = *chap->challenge.peer = '\0';
681 chap->NTRespSent = 0;
682 chap->peertries = 0;
687 chap_ReInit(struct chap *chap)
689 chap_Cleanup(chap, SIGTERM);
696 struct chap *chap = &p->dl->chap;
713 log_Printf(LogPHASE, "Unexpected chap input - dropped !\n");
719 if ((bp = auth_ReadHeader(&chap->auth, bp)) == NULL &&
720 ntohs(chap->auth.in.hdr.length) == 0)
722 else if (chap->auth.in.hdr.code == 0 || chap->auth.in.hdr.code > MAXCHAPCODE)
724 chap->auth.in.hdr.code);
729 if (chap->auth.in.hdr.code != CHAP_CHALLENGE &&
730 chap->auth.id != chap->auth.in.hdr.id &&
734 chapcodes[chap->auth.in.hdr.code], chap->auth.in.hdr.id,
735 chap->auth.id);
739 chap->auth.id = chap->auth.in.hdr.id; /* We respond with this id */
744 switch (chap->auth.in.hdr.code) {
753 *chap->challenge.peer = alen;
754 bp = mbuf_Read(bp, chap->challenge.peer + 1, alen);
755 bp = auth_ReadName(&chap->auth, bp, len);
758 ((chap->NTRespSent && IsAccepted(p->link.lcp.cfg.chap80lm)) ||
762 chap_ChallengeInit(&chap->auth);
767 auth_StopTimer(&chap->auth);
780 *ans = chap->auth.id;
782 bp = auth_ReadName(&chap->auth, bp, len);
791 /* chap->auth.in.name is already set up at CHALLENGE time */
802 switch (chap->auth.in.hdr.code) {
805 if (*chap->auth.in.name)
807 chapcodes[chap->auth.in.hdr.code], alen,
808 chap->auth.in.name,
810 lanman && chap->auth.in.hdr.code == CHAP_RESPONSE ?
816 chapcodes[chap->auth.in.hdr.code], alen,
818 lanman && chap->auth.in.hdr.code == CHAP_RESPONSE ?
828 chapcodes[chap->auth.in.hdr.code], ans);
831 chapcodes[chap->auth.in.hdr.code]);
835 switch (chap->auth.in.hdr.code) {
838 chap_StartChild(chap, bundle->cfg.auth.key + 1,
841 chap_Respond(chap, bundle->cfg.auth.name, bundle->cfg.auth.key +
851 name = chap->auth.in.name;
857 chap->challenge.peer[0] = sizeof resp->PeerChallenge;
858 memcpy(chap->challenge.peer + 1, resp->PeerChallenge,
865 if (!radius_Authenticate(&bundle->radius, &chap->auth,
866 chap->auth.in.name, ans, alen + 1,
867 chap->challenge.local + 1,
868 *chap->challenge.local))
869 chap_Failure(&chap->auth);
887 if (chap_HaveAnotherGo(chap))
893 if (chap_HaveAnotherGo(chap))
903 char *myans = chap_BuildAnswer(name, key, chap->auth.id,
904 chap->challenge.local
907 chap->challenge.peer,
908 chap->authresponse, lanman);
928 chap_Success(&chap->auth);
930 chap_Failure(&chap->auth);
941 if (strncasecmp(ans, chap->authresponse, 42)) {
944 " != ans: (%.42s)\n", chap->authresponse, ans);