⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pap.c

📁 lwip-1.4.0
💻 C
📖 第 1 页 / 共 2 页
字号:
  upap_state *u = &upap[unit];  if (u->us_clientstate == UPAPCS_AUTHREQ) {    UPAPDEBUG(LOG_ERR, ("PAP authentication failed due to protocol-reject\n"));    auth_withpeer_fail(unit, PPP_PAP);  }  if (u->us_serverstate == UPAPSS_LISTEN) {    UPAPDEBUG(LOG_ERR, ("PAP authentication of peer failed (protocol-reject)\n"));    auth_peer_fail(unit, PPP_PAP);  }  upap_lowerdown(unit);}/* * upap_input - Input UPAP packet. */static voidupap_input(int unit, u_char *inpacket, int l){  upap_state *u = &upap[unit];  u_char *inp;  u_char code, id;  int len;  /*   * Parse header (code, id and length).   * If packet too short, drop it.   */  inp = inpacket;  if (l < (int)UPAP_HEADERLEN) {    UPAPDEBUG(LOG_INFO, ("pap_input: rcvd short header.\n"));    return;  }  GETCHAR(code, inp);  GETCHAR(id, inp);  GETSHORT(len, inp);  if (len < (int)UPAP_HEADERLEN) {    UPAPDEBUG(LOG_INFO, ("pap_input: rcvd illegal length.\n"));    return;  }  if (len > l) {    UPAPDEBUG(LOG_INFO, ("pap_input: rcvd short packet.\n"));    return;  }  len -= UPAP_HEADERLEN;  /*   * Action depends on code.   */  switch (code) {    case UPAP_AUTHREQ:      upap_rauthreq(u, inp, id, len);      break;    case UPAP_AUTHACK:      upap_rauthack(u, inp, id, len);      break;    case UPAP_AUTHNAK:      upap_rauthnak(u, inp, id, len);      break;    default:        /* XXX Need code reject */      UPAPDEBUG(LOG_INFO, ("pap_input: UNHANDLED default: code: %d, id: %d, len: %d.\n", code, id, len));      break;  }}/* * upap_rauth - Receive Authenticate. */static voidupap_rauthreq(upap_state *u, u_char *inp, u_char id, int len){  u_char ruserlen, rpasswdlen;  char *ruser, *rpasswd;  u_char retcode;  char *msg;  int msglen;  UPAPDEBUG(LOG_INFO, ("pap_rauth: Rcvd id %d.\n", id));  if (u->us_serverstate < UPAPSS_LISTEN) {    return;  }  /*   * If we receive a duplicate authenticate-request, we are   * supposed to return the same status as for the first request.   */  if (u->us_serverstate == UPAPSS_OPEN) {    upap_sresp(u, UPAP_AUTHACK, id, "", 0);  /* return auth-ack */    return;  }  if (u->us_serverstate == UPAPSS_BADAUTH) {    upap_sresp(u, UPAP_AUTHNAK, id, "", 0);  /* return auth-nak */    return;  }  /*   * Parse user/passwd.   */  if (len < (int)sizeof (u_char)) {    UPAPDEBUG(LOG_INFO, ("pap_rauth: rcvd short packet.\n"));    return;  }  GETCHAR(ruserlen, inp);  len -= sizeof (u_char) + ruserlen + sizeof (u_char);  if (len < 0) {    UPAPDEBUG(LOG_INFO, ("pap_rauth: rcvd short packet.\n"));    return;  }  ruser = (char *) inp;  INCPTR(ruserlen, inp);  GETCHAR(rpasswdlen, inp);  if (len < rpasswdlen) {    UPAPDEBUG(LOG_INFO, ("pap_rauth: rcvd short packet.\n"));    return;  }  rpasswd = (char *) inp;  /*   * Check the username and password given.   */  retcode = check_passwd(u->us_unit, ruser, ruserlen, rpasswd, rpasswdlen, &msg, &msglen);  /* lwip: currently retcode is always UPAP_AUTHACK */  BZERO(rpasswd, rpasswdlen);  upap_sresp(u, retcode, id, msg, msglen);  if (retcode == UPAP_AUTHACK) {    u->us_serverstate = UPAPSS_OPEN;    auth_peer_success(u->us_unit, PPP_PAP, ruser, ruserlen);  } else {    u->us_serverstate = UPAPSS_BADAUTH;    auth_peer_fail(u->us_unit, PPP_PAP);  }  if (u->us_reqtimeout > 0) {    UNTIMEOUT(upap_reqtimeout, u);  }}/* * upap_rauthack - Receive Authenticate-Ack. */static voidupap_rauthack(upap_state *u, u_char *inp, int id, int len){  u_char msglen;  char *msg;  LWIP_UNUSED_ARG(id);  UPAPDEBUG(LOG_INFO, ("pap_rauthack: Rcvd id %d s=%d\n", id, u->us_clientstate));  if (u->us_clientstate != UPAPCS_AUTHREQ) { /* XXX */    UPAPDEBUG(LOG_INFO, ("pap_rauthack: us_clientstate != UPAPCS_AUTHREQ\n"));    return;  }  /*   * Parse message.   */  if (len < (int)sizeof (u_char)) {    UPAPDEBUG(LOG_INFO, ("pap_rauthack: ignoring missing msg-length.\n"));  } else {    GETCHAR(msglen, inp);    if (msglen > 0) {      len -= sizeof (u_char);      if (len < msglen) {        UPAPDEBUG(LOG_INFO, ("pap_rauthack: rcvd short packet.\n"));        return;      }      msg = (char *) inp;      PRINTMSG(msg, msglen);    }  }  UNTIMEOUT(upap_timeout, u);    /* Cancel timeout */  u->us_clientstate = UPAPCS_OPEN;  auth_withpeer_success(u->us_unit, PPP_PAP);}/* * upap_rauthnak - Receive Authenticate-Nak. */static voidupap_rauthnak(upap_state *u, u_char *inp, int id, int len){  u_char msglen;  char *msg;  LWIP_UNUSED_ARG(id);  UPAPDEBUG(LOG_INFO, ("pap_rauthnak: Rcvd id %d s=%d\n", id, u->us_clientstate));  if (u->us_clientstate != UPAPCS_AUTHREQ) { /* XXX */    return;  }  /*   * Parse message.   */  if (len < sizeof (u_char)) {    UPAPDEBUG(LOG_INFO, ("pap_rauthnak: ignoring missing msg-length.\n"));  } else {    GETCHAR(msglen, inp);    if(msglen > 0) {      len -= sizeof (u_char);      if (len < msglen) {        UPAPDEBUG(LOG_INFO, ("pap_rauthnak: rcvd short packet.\n"));        return;      }      msg = (char *) inp;      PRINTMSG(msg, msglen);    }  }  u->us_clientstate = UPAPCS_BADAUTH;  UPAPDEBUG(LOG_ERR, ("PAP authentication failed\n"));  auth_withpeer_fail(u->us_unit, PPP_PAP);}/* * upap_sauthreq - Send an Authenticate-Request. */static voidupap_sauthreq(upap_state *u){  u_char *outp;  int outlen;  outlen = UPAP_HEADERLEN + 2 * sizeof (u_char)          + u->us_userlen + u->us_passwdlen;  outp = outpacket_buf[u->us_unit];  MAKEHEADER(outp, PPP_PAP);  PUTCHAR(UPAP_AUTHREQ, outp);  PUTCHAR(++u->us_id, outp);  PUTSHORT(outlen, outp);  PUTCHAR(u->us_userlen, outp);  BCOPY(u->us_user, outp, u->us_userlen);  INCPTR(u->us_userlen, outp);  PUTCHAR(u->us_passwdlen, outp);  BCOPY(u->us_passwd, outp, u->us_passwdlen);  pppWrite(u->us_unit, outpacket_buf[u->us_unit], outlen + PPP_HDRLEN);  UPAPDEBUG(LOG_INFO, ("pap_sauth: Sent id %d\n", u->us_id));  TIMEOUT(upap_timeout, u, u->us_timeouttime);  ++u->us_transmits;  u->us_clientstate = UPAPCS_AUTHREQ;}/* * upap_sresp - Send a response (ack or nak). */static voidupap_sresp(upap_state *u, u_char code, u_char id, char *msg, int msglen){  u_char *outp;  int outlen;  outlen = UPAP_HEADERLEN + sizeof (u_char) + msglen;  outp = outpacket_buf[u->us_unit];  MAKEHEADER(outp, PPP_PAP);  PUTCHAR(code, outp);  PUTCHAR(id, outp);  PUTSHORT(outlen, outp);  PUTCHAR(msglen, outp);  BCOPY(msg, outp, msglen);  pppWrite(u->us_unit, outpacket_buf[u->us_unit], outlen + PPP_HDRLEN);  UPAPDEBUG(LOG_INFO, ("pap_sresp: Sent code %d, id %d s=%d\n", code, id, u->us_clientstate));}#if PPP_ADDITIONAL_CALLBACKSstatic char *upap_codenames[] = {    "AuthReq", "AuthAck", "AuthNak"};/* * upap_printpkt - print the contents of a PAP packet. */static int upap_printpkt(  u_char *p,  int plen,  void (*printer) (void *, char *, ...),  void *arg){  LWIP_UNUSED_ARG(p);  LWIP_UNUSED_ARG(plen);  LWIP_UNUSED_ARG(printer);  LWIP_UNUSED_ARG(arg);  return 0;}#endif /* PPP_ADDITIONAL_CALLBACKS */#endif /* PAP_SUPPORT */#endif /* PPP_SUPPORT */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -