Home | History | Annotate | Download | only in src

Lines Matching refs:chap

28  * $FreeBSD: src/usr.sbin/ppp/chap.c,v 1.86.26.1 2010/12/21 17:10:29 kensmith Exp $
68 #include "chap.h"
117 log_Printf(LogPHASE, "Chap Output: %s\n", chapcodes[code]);
119 log_Printf(LogPHASE, "Chap Output: %s (%s)\n", chapcodes[code], text);
256 chap_StartChild(struct chap *chap, char *prog, const char *name)
263 if (chap->child.fd != -1) {
264 log_Printf(LogWARN, "Chap: %s: Program already running\n", prog);
269 log_Printf(LogERROR, "Chap: pipe: %s\n", strerror(errno));
274 log_Printf(LogERROR, "Chap: pipe: %s\n", strerror(errno));
281 switch ((chap->child.pid = fork())) {
283 log_Printf(LogERROR, "Chap: fork: %s\n", strerror(errno));
288 chap->child.pid = 0;
296 log_Printf(LogWARN, "CHAP: Invalid command syntax\n");
310 log_Printf(LogALERT, "Chap: Failed to open %s: %s\n",
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;
355 log_Printf(LogERROR, "Chap: wait: %s\n", strerror(errno));
357 log_Printf(LogWARN, "Chap: Child received signal %d\n", WTERMSIG(status));
359 log_Printf(LogERROR, "Chap: Child exited %d\n", WEXITSTATUS(status));
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);
430 log_Printf(LogERROR, "Chap: Read: %s\n", strerror(errno));
431 chap_Cleanup(chap, SIGTERM);
433 log_Printf(LogWARN, "Chap: Read: Child terminated connection\n");
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) {
449 log_Printf(LogWARN, "Chap: Read: Input buffer overflow\n");
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;
512 *cp++ = 16; /* MS-CHAP-V2 does 16 bytes challenges */
516 for (i = 0; i < *chap->challenge.local; i++)
526 struct chap *chap = auth2chap(authp);
529 log_Printf(LogDEBUG, "CHAP%02X: Challenge\n",
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)
721 log_Printf(LogWARN, "Chap Input: Truncated header !\n");
722 else if (chap->auth.in.hdr.code == 0 || chap->auth.in.hdr.code > MAXCHAPCODE)
723 log_Printf(LogPHASE, "Chap Input: %d: Bad CHAP code !\n",
724 chap->auth.in.hdr.code);
729 if (chap->auth.in.hdr.code != CHAP_CHALLENGE &&
730 chap->auth.id != chap->auth.in.hdr.id &&
733 log_Printf(LogPHASE, "Chap Input: %s dropped (got id %d, not %d)\n",
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) {
749 log_Printf(LogERROR, "Chap Input: Truncated challenge !\n");
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);
771 log_Printf(LogERROR, "Chap Input: Truncated response !\n");
776 log_Printf(LogERROR, "Chap Input: Out of memory !\n");
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 */
793 log_Printf(LogERROR, "Chap Input: Out of memory !\n");
802 switch (chap->auth.in.hdr.code) {
805 if (*chap->auth.in.name)
806 log_Printf(LogPHASE, "Chap Input: %s (%d bytes from %s%s)\n",
807 chapcodes[chap->auth.in.hdr.code], alen,
808 chap->auth.in.name,
810 lanman && chap->auth.in.hdr.code == CHAP_RESPONSE ?
815 log_Printf(LogPHASE, "Chap Input: %s (%d bytes%s)\n",
816 chapcodes[chap->auth.in.hdr.code], alen,
818 lanman && chap->auth.in.hdr.code == CHAP_RESPONSE ?
827 log_Printf(LogPHASE, "Chap Input: %s (%s)\n",
828 chapcodes[chap->auth.in.hdr.code], ans);
830 log_Printf(LogPHASE, "Chap Input: %s\n",
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);