67static bool hide_password = 1;
 
   72static option_t pap_option_list[] = {
 
   73    { 
"hide-password", o_bool, &hide_password,
 
   74      "Don't output passwords to log", 1 },
 
   75    { 
"show-password", o_bool, &hide_password,
 
   76      "Show password string in debug log messages", 0 },
 
   77    { 
"pap-restart", o_int, &upap[0].us_timeouttime,
 
   78      "Set retransmit timeout for PAP" },
 
   79    { 
"pap-max-authreq", o_int, &upap[0].us_maxtransmits,
 
   80      "Set max number of transmissions for auth-reqs" },
 
   81    { 
"pap-timeout", o_int, &upap[0].us_reqtimeout,
 
   82      "Set time limit for peer PAP authentication" },
 
   90static void upap_init      (
int);
 
   91static void upap_lowerup   (
int);
 
   92static void upap_lowerdown (
int);
 
   93static void upap_input     (
int, u_char *, 
int);
 
   94static void upap_protrej   (
int);
 
   95#if PPP_ADDITIONAL_CALLBACKS 
   96static int  upap_printpkt (u_char *, 
int, 
void (*)(
void *, 
char *, ...), 
void *);
 
   99struct protent pap_protent = {
 
  108#if PPP_ADDITIONAL_CALLBACKS 
  114#if PPP_ADDITIONAL_CALLBACKS 
  121upap_state upap[NUM_PPP]; 
 
  123static void upap_timeout   (
void *);
 
  124static void upap_reqtimeout(
void *);
 
  125static void upap_rauthreq  (upap_state *, u_char *, u_char, 
int);
 
  126static void upap_rauthack  (upap_state *, u_char *, 
int, 
int);
 
  127static void upap_rauthnak  (upap_state *, u_char *, 
int, 
int);
 
  128static void upap_sauthreq  (upap_state *);
 
  129static void upap_sresp     (upap_state *, u_char, u_char, 
char *, 
int);
 
  138  upap_state *u = &upap[unit];
 
  146  u->us_clientstate  = UPAPCS_INITIAL;
 
  147  u->us_serverstate  = UPAPSS_INITIAL;
 
  149  u->us_timeouttime  = UPAP_DEFTIMEOUT;
 
  150  u->us_maxtransmits = 10;
 
  151  u->us_reqtimeout   = UPAP_DEFREQTIME;
 
  160upap_authwithpeer(
int unit, 
char *user, 
char *password)
 
  162  upap_state *u = &upap[unit];
 
  165             unit, user, password, u->us_clientstate));
 
  169  u->us_userlen = (int)strlen(user);
 
  170  u->us_passwd = password;
 
  171  u->us_passwdlen = (int)strlen(password);
 
  176  if (u->us_clientstate == UPAPCS_INITIAL ||
 
  177      u->us_clientstate == UPAPCS_PENDING) {
 
  178    u->us_clientstate = UPAPCS_PENDING;
 
  192upap_authpeer(
int unit)
 
  194  upap_state *u = &upap[unit];
 
  197  if (u->us_serverstate == UPAPSS_INITIAL ||
 
  198      u->us_serverstate == UPAPSS_PENDING) {
 
  199    u->us_serverstate = UPAPSS_PENDING;
 
  203  u->us_serverstate = UPAPSS_LISTEN;
 
  204  if (u->us_reqtimeout > 0) {
 
  205    TIMEOUT(upap_reqtimeout, u, u->us_reqtimeout);
 
  213upap_timeout(
void *arg)
 
  215  upap_state *u = (upap_state *) arg;
 
  218        u->us_unit, u->us_timeouttime, u->us_clientstate));
 
  220  if (u->us_clientstate != UPAPCS_AUTHREQ) {
 
  225  if (u->us_transmits >= u->us_maxtransmits) {
 
  228    u->us_clientstate = UPAPCS_BADAUTH;
 
  241upap_reqtimeout(
void *arg)
 
  243  upap_state *u = (upap_state *) arg;
 
  245  if (u->us_serverstate != UPAPSS_LISTEN) {
 
  250  u->us_serverstate = UPAPSS_BADAUTH;
 
  260upap_lowerup(
int unit)
 
  262  upap_state *u = &upap[unit];
 
  264  UPAPDEBUG(
LOG_INFO, (
"upap_lowerup: init %d clientstate s=%d\n", unit, u->us_clientstate));
 
  266  if (u->us_clientstate == UPAPCS_INITIAL) {
 
  267    u->us_clientstate = UPAPCS_CLOSED;
 
  268  } 
else if (u->us_clientstate == UPAPCS_PENDING) {
 
  273  if (u->us_serverstate == UPAPSS_INITIAL) {
 
  274    u->us_serverstate = UPAPSS_CLOSED;
 
  275  } 
else if (u->us_serverstate == UPAPSS_PENDING) {
 
  276    u->us_serverstate = UPAPSS_LISTEN;
 
  277    if (u->us_reqtimeout > 0) {
 
  278      TIMEOUT(upap_reqtimeout, u, u->us_reqtimeout);
 
  290upap_lowerdown(
int unit)
 
  292  upap_state *u = &upap[unit];
 
  296  if (u->us_clientstate == UPAPCS_AUTHREQ) { 
 
  297    UNTIMEOUT(upap_timeout, u);    
 
  299  if (u->us_serverstate == UPAPSS_LISTEN && u->us_reqtimeout > 0) {
 
  300    UNTIMEOUT(upap_reqtimeout, u);
 
  303  u->us_clientstate = UPAPCS_INITIAL;
 
  304  u->us_serverstate = UPAPSS_INITIAL;
 
  314upap_protrej(
int unit)
 
  316  upap_state *u = &upap[unit];
 
  318  if (u->us_clientstate == UPAPCS_AUTHREQ) {
 
  322  if (u->us_serverstate == UPAPSS_LISTEN) {
 
  323    UPAPDEBUG(
LOG_ERR, (
"PAP authentication of peer failed (protocol-reject)\n"));
 
  326  upap_lowerdown(unit);
 
  334upap_input(
int unit, u_char *inpacket, 
int l)
 
  336  upap_state *u = &upap[unit];
 
  346  if (l < (
int)UPAP_HEADERLEN) {
 
  353  if (len < (
int)UPAP_HEADERLEN) {
 
  361  len -= UPAP_HEADERLEN;
 
  368      upap_rauthreq(u, inp, 
id, len);
 
  372      upap_rauthack(u, inp, 
id, len);
 
  376      upap_rauthnak(u, inp, 
id, len);
 
  390upap_rauthreq(upap_state *u, u_char *inp, u_char 
id, 
int len)
 
  392  u_char ruserlen, rpasswdlen;
 
  393  char *ruser, *rpasswd;
 
  400  if (u->us_serverstate < UPAPSS_LISTEN) {
 
  408  if (u->us_serverstate == UPAPSS_OPEN) {
 
  409    upap_sresp(u, UPAP_AUTHACK, 
id, 
"", 0);  
 
  412  if (u->us_serverstate == UPAPSS_BADAUTH) {
 
  413    upap_sresp(u, UPAP_AUTHNAK, 
id, 
"", 0);  
 
  420  if (len < (
int)
sizeof (u_char)) {
 
  424  GETCHAR(ruserlen, inp);
 
  425  len -= 
sizeof (u_char) + ruserlen + 
sizeof (u_char);
 
  430  ruser = (
char *) inp;
 
  431  INCPTR(ruserlen, inp);
 
  432  GETCHAR(rpasswdlen, inp);
 
  433  if (len < rpasswdlen) {
 
  437  rpasswd = (
char *) inp;
 
  442  retcode = 
check_passwd(u->us_unit, ruser, ruserlen, rpasswd, rpasswdlen, &msg, &msglen);
 
  444  BZERO(rpasswd, rpasswdlen);
 
  446  upap_sresp(u, retcode, 
id, msg, msglen);
 
  448  if (retcode == UPAP_AUTHACK) {
 
  449    u->us_serverstate = UPAPSS_OPEN;
 
  452    u->us_serverstate = UPAPSS_BADAUTH;
 
  456  if (u->us_reqtimeout > 0) {
 
  457    UNTIMEOUT(upap_reqtimeout, u);
 
  466upap_rauthack(upap_state *u, u_char *inp, 
int id, 
int len)
 
  475  if (u->us_clientstate != UPAPCS_AUTHREQ) { 
 
  483  if (len < (
int)
sizeof (u_char)) {
 
  486    GETCHAR(msglen, inp);
 
  488      len -= 
sizeof (u_char);
 
  494      PRINTMSG(msg, msglen);
 
  497  UNTIMEOUT(upap_timeout, u);    
 
  498  u->us_clientstate = UPAPCS_OPEN;
 
  508upap_rauthnak(upap_state *u, u_char *inp, 
int id, 
int len)
 
  517  if (u->us_clientstate != UPAPCS_AUTHREQ) { 
 
  524  if (len < 
sizeof (u_char)) {
 
  527    GETCHAR(msglen, inp);
 
  529      len -= 
sizeof (u_char);
 
  535      PRINTMSG(msg, msglen);
 
  539  u->us_clientstate = UPAPCS_BADAUTH;
 
  550upap_sauthreq(upap_state *u)
 
  555  outlen = UPAP_HEADERLEN + 2 * 
sizeof (u_char) 
 
  556         + u->us_userlen + u->us_passwdlen;
 
  557  outp = outpacket_buf[u->us_unit];
 
  559  MAKEHEADER(outp, PPP_PAP);
 
  561  PUTCHAR(UPAP_AUTHREQ, outp);
 
  562  PUTCHAR(++u->us_id, outp);
 
  563  PUTSHORT(outlen, outp);
 
  564  PUTCHAR(u->us_userlen, outp);
 
  565  BCOPY(u->us_user, outp, u->us_userlen);
 
  566  INCPTR(u->us_userlen, outp);
 
  567  PUTCHAR(u->us_passwdlen, outp);
 
  568  BCOPY(u->us_passwd, outp, u->us_passwdlen);
 
  570  pppWrite(u->us_unit, outpacket_buf[u->us_unit], outlen + PPP_HDRLEN);
 
  574  TIMEOUT(upap_timeout, u, u->us_timeouttime);
 
  576  u->us_clientstate = UPAPCS_AUTHREQ;
 
  584upap_sresp(upap_state *u, u_char 
code, u_char 
id, 
char *msg, 
int msglen)
 
  589  outlen = UPAP_HEADERLEN + 
sizeof (u_char) + msglen;
 
  590  outp = outpacket_buf[u->us_unit];
 
  591  MAKEHEADER(outp, PPP_PAP);
 
  595  PUTSHORT(outlen, outp);
 
  596  PUTCHAR(msglen, outp);
 
  597  BCOPY(msg, outp, msglen);
 
  598  pppWrite(u->us_unit, outpacket_buf[u->us_unit], outlen + PPP_HDRLEN);
 
  603#if PPP_ADDITIONAL_CALLBACKS 
  604static char *upap_codenames[] = {
 
  605    "AuthReq", 
"AuthAck", 
"AuthNak" 
  611static int upap_printpkt(
 
  614  void (*printer) (
void *, 
char *, ...),
 
#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)
 
u_char check_passwd(int, char *, int, char *, int, char **, int *)
 
void auth_withpeer_success(int, u16_t)