コード例 #1
0
static void
chap_Failure(struct authinfo *authp)
{
#ifndef NODES
  char buf[1024], *ptr;
#endif
  const char *msg;

#ifndef NORADIUS
  struct bundle *bundle = authp->physical->link.lcp.fsm.bundle;
  if (*bundle->radius.cfg.file && bundle->radius.errstr)
    msg = bundle->radius.errstr;
  else
#endif
#ifndef NODES
  if (authp->physical->link.lcp.want_authtype == 0x80) {
    snprintf(buf, sizeof buf, "E=691 R=1 M=Invalid!");
    msg = buf;
  } else if (authp->physical->link.lcp.want_authtype == 0x81) {
    int i;

    ptr = buf;
    snprintf(buf, sizeof(buf), "E=691 R=0 C=");
    ptr += strlen(ptr);
    for (i=0; i<16; i++) {
      snprintf(ptr, buf + sizeof buf - ptr, "%02X", *(auth2chap(authp)->challenge.local+1+i));
      ptr += strlen(ptr);
      if (ptr > buf + sizeof buf)
        break;
    }

    snprintf(ptr, buf + sizeof buf - ptr, " V=3 M=Invalid!");
    msg = buf;
  } else
#endif
    msg = "Invalid!!";

  ChapOutput(authp->physical, CHAP_FAILURE, authp->id, msg, strlen(msg) + 1,
             NULL);
  datalink_AuthNotOk(authp->physical->dl);
}
コード例 #2
0
ファイル: chap.c プロジェクト: AhmadTux/DragonFlyBSD
static void
chap_Success(struct authinfo *authp)
{
  struct bundle *bundle = authp->physical->dl->bundle;
  const char *msg;

  datalink_GotAuthname(authp->physical->dl, authp->in.name);
#ifndef NODES
  if (authp->physical->link.lcp.want_authtype == 0x81) {
#ifndef NORADIUS
    if (*bundle->radius.cfg.file && bundle->radius.msrepstr)
      msg = bundle->radius.msrepstr;
    else
#endif
      msg = auth2chap(authp)->authresponse;
    MPPE_MasterKeyValid = 1;		/* XXX Global ! */
  } else
#endif
#ifndef NORADIUS
  if (*bundle->radius.cfg.file && bundle->radius.repstr)
    msg = bundle->radius.repstr;
  else
#endif
    msg = "Welcome!!";

  ChapOutput(authp->physical, CHAP_SUCCESS, authp->id, msg, strlen(msg),
             NULL);

  authp->physical->link.lcp.auth_ineed = 0;
  if (Enabled(bundle, OPT_UTMP))
    physical_Login(authp->physical, authp->in.name);

  if (authp->physical->link.lcp.auth_iwait == 0)
    /*
     * Either I didn't need to authenticate, or I've already been
     * told that I got the answer right.
     */
    datalink_AuthOk(authp->physical->dl);
}
static void
chap_Challenge_old(struct authinfo *authp)
{
    struct chap *chap = auth2chap(authp);
    int len, i;
    char *cp;

    len = strlen(authp->physical->dl->bundle->cfg.auth.name);

    if (!*chap->challenge.local) {    /* as each time, local is NULL, here is always true */
        randinit();
        cp = chap->challenge.local;

#ifndef NORADIUS
        if (*authp->physical->dl->bundle->radius.cfg.file) {
            /* For radius, our challenge is 16 readable NUL terminated bytes :*/
            *cp++ = 16;
            for (i = 0; i < 16; i++)
                *cp++ = (random() % 10) + '0';
        } else
#endif
        {
#ifdef HAVE_DES
            if (authp->physical->link.lcp.want_authtype == 0x80)
                *cp++ = 8;	/* MS does 8 byte callenges :-/ */
            else
#endif
                *cp++ = random() % (CHAPCHALLENGELEN-16) + 16;    /* 随机字串长度本身设为随机值, 放在local的第一个字节 */
            for (i = 0; i < *chap->challenge.local; i++)
                *cp++ = random() & 0xff;    /* 随机字串 */
        }
        memcpy(cp, authp->physical->dl->bundle->cfg.auth.name, len);
    }
    ChapOutput(authp->physical, CHAP_CHALLENGE, authp->id, chap->challenge.local,
               1 + *chap->challenge.local + len, NULL);    /* 1: Value-Size, *local: 随机字串长度, len: Name length */
}
コード例 #4
0
ファイル: chap.c プロジェクト: AhmadTux/DragonFlyBSD
static void
chap_Challenge(struct authinfo *authp)
{
  struct chap *chap = auth2chap(authp);
  int len;

  log_Printf(LogDEBUG, "CHAP%02X: Challenge\n",
             authp->physical->link.lcp.want_authtype);

  len = strlen(authp->physical->dl->bundle->cfg.auth.name);

  /* Generate new local challenge value */
  if (!*chap->challenge.local)
    chap_ChallengeInit(authp);

#ifndef NODES
  if (authp->physical->link.lcp.want_authtype == 0x81)
    ChapOutput(authp->physical, CHAP_CHALLENGE, authp->id,
             chap->challenge.local, 1 + *chap->challenge.local, NULL);
  else
#endif
    ChapOutput(authp->physical, CHAP_CHALLENGE, authp->id,
             chap->challenge.local, 1 + *chap->challenge.local + len, NULL);
}
コード例 #5
0
ファイル: chap.c プロジェクト: AhmadTux/DragonFlyBSD
static void
chap_ChallengeInit(struct authinfo *authp)
{
  struct chap *chap = auth2chap(authp);
  int len, i;
  char *cp;

  len = strlen(authp->physical->dl->bundle->cfg.auth.name);

  if (!*chap->challenge.local) {
    randinit();
    cp = chap->challenge.local;

#ifndef NORADIUS
    if (*authp->physical->dl->bundle->radius.cfg.file) {
      /* For radius, our challenge is 16 readable NUL terminated bytes :*/
      *cp++ = 16;
      for (i = 0; i < 16; i++)
        *cp++ = (random() % 10) + '0';
    } else
#endif
    {
#ifndef NODES
      if (authp->physical->link.lcp.want_authtype == 0x80)
        *cp++ = 8;	/* MS does 8 byte callenges :-/ */
      else if (authp->physical->link.lcp.want_authtype == 0x81)
        *cp++ = 16;	/* MS-CHAP-V2 does 16 bytes challenges */
      else
#endif
        *cp++ = random() % (CHAPCHALLENGELEN-16) + 16;
      for (i = 0; i < *chap->challenge.local; i++)
        *cp++ = random() & 0xff;
    }
    memcpy(cp, authp->physical->dl->bundle->cfg.auth.name, len);
  }
}