91static option_t chap_option_list[] = {
 
   93      "Set timeout for CHAP" },
 
   95      "Set max #xmits for challenge" },
 
   97      "Set interval for rechallenge" },
 
   99    { 
"ms-lanman", o_bool, &ms_lanman,
 
  100      "Use LanMan passwd when using MS-CHAP", 1 },
 
  109static void ChapInit (
int);
 
  110static void ChapLowerUp (
int);
 
  111static void ChapLowerDown (
int);
 
  112static void ChapInput (
int, u_char *, 
int);
 
  113static void ChapProtocolReject (
int);
 
  114#if PPP_ADDITIONAL_CALLBACKS 
  115static int  ChapPrintPkt (u_char *, 
int, 
void (*) (
void *, 
char *, ...), 
void *);
 
  127#if PPP_ADDITIONAL_CALLBACKS 
  133#if PPP_ADDITIONAL_CALLBACKS 
  142static void ChapChallengeTimeout (
void *);
 
  143static void ChapResponseTimeout (
void *);
 
  144static void ChapReceiveChallenge (
chap_state *, u_char *, u_char, 
int);
 
  145static void ChapRechallenge (
void *);
 
  146static void ChapReceiveResponse (
chap_state *, u_char *, 
int, 
int);
 
  147static void ChapReceiveSuccess(
chap_state *
cstate, u_char *inp, u_char 
id, 
int len);
 
  148static void ChapReceiveFailure(
chap_state *
cstate, u_char *inp, u_char 
id, 
int len);
 
  149static void ChapSendStatus (
chap_state *, 
int);
 
  166  cstate->timeouttime = CHAP_DEFTIMEOUT;
 
  167  cstate->max_transmits = CHAP_DEFTRANSMITS;
 
  181  cstate->resp_name = our_name;
 
  182  cstate->resp_type = digest;
 
  208  cstate->chal_name = our_name;
 
  209  cstate->chal_type = digest;
 
  219  ChapSendChallenge(
cstate);    
 
  228ChapChallengeTimeout(
void *arg)
 
  247  ChapSendChallenge(
cstate); 
 
  255ChapResponseTimeout(
void *arg)
 
  272ChapRechallenge(
void *arg)
 
  282  ChapSendChallenge(
cstate);
 
  307    ChapSendChallenge(
cstate);
 
  319ChapLowerDown(
int unit)
 
  326    UNTIMEOUT(ChapChallengeTimeout, 
cstate);
 
  328      && 
cstate->chal_interval != 0) {
 
  329    UNTIMEOUT(ChapRechallenge, 
cstate);
 
  332    UNTIMEOUT(ChapResponseTimeout, 
cstate);
 
  343ChapProtocolReject(
int unit)
 
  363ChapInput(
int unit, u_char *inpacket, 
int packet_len)
 
  386  if (len > packet_len) {
 
  397      ChapReceiveChallenge(
cstate, inp, 
id, len);
 
  401      ChapReceiveResponse(
cstate, inp, 
id, len);
 
  405      ChapReceiveFailure(
cstate, inp, 
id, len);
 
  409      ChapReceiveSuccess(
cstate, inp, 
id, len);
 
  428  char secret[MAXSECRETLEN];
 
  446  GETCHAR(rchallenge_len, inp);
 
  447  len -= 
sizeof (u_char) + rchallenge_len;  
 
  453  INCPTR(rchallenge_len, inp);
 
  455  if (len >= (
int)
sizeof(rhostname)) {
 
  456    len = 
sizeof(rhostname) - 1;
 
  458  BCOPY(inp, rhostname, len);
 
  459  rhostname[len] = 
'\000';
 
  465  if (ppp_settings.remote_name[0] != 0 && (ppp_settings.explicit_remote || rhostname[0] == 0)) {
 
  466    strncpy(rhostname, ppp_settings.remote_name, 
sizeof(rhostname));
 
  467    rhostname[
sizeof(rhostname) - 1] = 0;
 
  474                  secret, &secret_len, 0)) {
 
  482    UNTIMEOUT(ChapResponseTimeout, 
cstate);
 
  486  cstate->resp_transmits = 0;
 
  489  switch (
cstate->resp_type) { 
 
  494    MD5Update(&mdContext, (u_char*)secret, secret_len);
 
  495    MD5Update(&mdContext, rchallenge, rchallenge_len);
 
  503    ChapMS(
cstate, rchallenge, rchallenge_len, secret, secret_len);
 
  512  BZERO(secret, 
sizeof(secret));
 
  523  u_char *remmd, remmd_len;
 
  524  int secret_len, old_state;
 
  528  char secret[MAXSECRETLEN];
 
  540  if (
id != 
cstate->chal_id) {
 
  562  GETCHAR(remmd_len, inp); 
 
  564  INCPTR(remmd_len, inp);
 
  566  len -= 
sizeof (u_char) + remmd_len;
 
  572  UNTIMEOUT(ChapChallengeTimeout, 
cstate);
 
  574  if (len >= (
int)
sizeof(rhostname)) {
 
  575    len = 
sizeof(rhostname) - 1;
 
  577  BCOPY(inp, rhostname, len);
 
  578  rhostname[len] = 
'\000';
 
  589                  secret, &secret_len, 1)) {
 
  594    switch (
cstate->chal_type) {
 
  602        MD5Update(&mdContext, (u_char*)secret, secret_len);
 
  617  BZERO(secret, 
sizeof(secret));
 
  621    old_state = 
cstate->serverstate;
 
  626    if (
cstate->chal_interval != 0) {
 
  627      TIMEOUT(ChapRechallenge, 
cstate, 
cstate->chal_interval);
 
  659  UNTIMEOUT(ChapResponseTimeout, 
cstate);
 
  692  UNTIMEOUT(ChapResponseTimeout, 
cstate);
 
  713  int chal_len, name_len;
 
  716  chal_len = 
cstate->chal_len;
 
  717  name_len = (int)strlen(
cstate->chal_name);
 
  719  outp = outpacket_buf[
cstate->unit];
 
  721  MAKEHEADER(outp, PPP_CHAP);    
 
  724  PUTCHAR(
cstate->chal_id, outp);
 
  725  PUTSHORT(outlen, outp);
 
  727  PUTCHAR(chal_len, outp);    
 
  728  BCOPY(
cstate->challenge, outp, chal_len);
 
  729  INCPTR(chal_len, outp);
 
  731  BCOPY(
cstate->chal_name, outp, name_len);  
 
  733  pppWrite(
cstate->unit, outpacket_buf[
cstate->unit], outlen + PPP_HDRLEN);
 
  737  TIMEOUT(ChapChallengeTimeout, 
cstate, 
cstate->timeouttime);
 
  753    strcpy(msg, 
"Welcome!");
 
  755    strcpy(msg, 
"I don't like you.  Go 'way.");
 
  757  msglen = (int)strlen(msg);
 
  760  outp = outpacket_buf[
cstate->unit];
 
  762  MAKEHEADER(outp, PPP_CHAP);    
 
  765  PUTCHAR(
cstate->chal_id, outp);
 
  766  PUTSHORT(outlen, outp);
 
  767  BCOPY(msg, outp, msglen);
 
  768  pppWrite(
cstate->unit, outpacket_buf[
cstate->unit], outlen + PPP_HDRLEN);
 
  794  LWIP_ASSERT(
"chal_len <= 0xff", chal_len <= 0xffff);
 
  795  cstate->chal_len = (u_char)chal_len;
 
  797  cstate->chal_transmits = 0;
 
  800  for (i = 0; i < chal_len; i++ ) {
 
  814  int outlen, md_len, name_len;
 
  816  md_len = 
cstate->resp_length;
 
  817  name_len = (int)strlen(
cstate->resp_name);
 
  819  outp = outpacket_buf[
cstate->unit];
 
  821  MAKEHEADER(outp, PPP_CHAP);
 
  824  PUTCHAR(
cstate->resp_id, outp);  
 
  825  PUTSHORT(outlen, outp);      
 
  827  PUTCHAR(md_len, outp);      
 
  828  BCOPY(
cstate->response, outp, md_len);    
 
  829  INCPTR(md_len, outp);
 
  831  BCOPY(
cstate->resp_name, outp, name_len);  
 
  834  pppWrite(
cstate->unit, outpacket_buf[
cstate->unit], outlen + PPP_HDRLEN);
 
  837  TIMEOUT(ChapResponseTimeout, 
cstate, 
cstate->timeouttime);
 
  841#if PPP_ADDITIONAL_CALLBACKS 
  842static char *ChapCodenames[] = {
 
  843  "Challenge", 
"Response", 
"Success", 
"Failure" 
  849ChapPrintPkt( u_char *p, 
int plen, 
void (*printer) (
void *, 
char *, ...), 
void *arg)
 
  861  if (len < CHAP_HEADERLEN || len > plen) {
 
  865  if (
code >= 1 && 
code <= 
sizeof(ChapCodenames) / 
sizeof(
char *)) {
 
  866    printer(arg, 
" %s", ChapCodenames[
code-1]);
 
  868    printer(arg, 
" code=0x%x", 
code);
 
  870  printer(arg, 
" id=0x%x", 
id);
 
  879      if (len < clen + 1) {
 
  883      nlen = len - clen - 1;
 
  885      for (; clen > 0; --clen) {
 
  887        printer(arg, 
"%.2x", x);
 
  889      printer(arg, 
">, name = %.*Z", nlen, p);
 
  893      printer(arg, 
" %.*Z", len, p);
 
  896      for (clen = len; clen > 0; --clen) {
 
  898        printer(arg, 
" %.2x", x);
 
#define LWIP_UNUSED_ARG(x)
 
void auth_peer_success(int, u16_t, char *, int)
 
void auth_peer_fail(int, u16_t)
 
void auth_withpeer_fail(int, u16_t)
 
int get_secret(int, char *, char *, char *, int *, int)
 
void auth_withpeer_success(int, u16_t)
 
struct protent chap_protent
 
void ChapAuthPeer(int, char *, u_char)
 
#define MIN_CHALLENGE_LENGTH
 
#define CHAPSS_INITIAL_CHAL
 
#define MD5_SIGNATURE_SIZE
 
#define CHAPSS_RECHALLENGE
 
void ChapAuthWithPeer(int, char *, u_char)
 
#define MAX_CHALLENGE_LENGTH
 
void ChapMS(chap_state *, char *, int, char *, int)
 
#define LWIP_ASSERT(message, assertion)
 
void MD5Final(unsigned char hash[], MD5_CTX *mdContext)
 
void MD5Init(MD5_CTX *mdContext)
 
void MD5Update(MD5_CTX *mdContext, unsigned char *inBuf, unsigned int inLen)