home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR3 / KA9Q212.ZIP / PPPPAP.C < prev    next >
C/C++ Source or Header  |  1993-07-16  |  17KB  |  732 lines

  1. /*
  2.  *  PPPPAP.C    -- Password Authentication Protocol for PPP
  3.  *
  4.  *    This implementation of PPP is declared to be in the public domain.
  5.  *
  6.  *    Jan 91    Bill_Simpson@um.cc.umich.edu
  7.  *        Computer Systems Consulting Services
  8.  *
  9.  *    Acknowledgements and correction history may be found in PPP.C
  10.  */
  11.  
  12. /****************************************************************************
  13. *    $Id: ppppap.c 1.2 93/07/16 11:49:26 ROOT_DOS Exp $
  14. *    14 Jul 93    1.2        GT    Fix warnings.                                    *
  15. ****************************************************************************/
  16.  
  17. #include <stdio.h>
  18. #include "global.h"
  19. #include "mbuf.h"
  20. #include "proc.h"
  21. #include "iface.h"
  22. #include "session.h"
  23. #include "socket.h"
  24. #include "ppp.h"
  25. #include "pppfsm.h"
  26. #include "ppplcp.h"
  27. #include "ppppap.h"
  28. #include "cmdparse.h"
  29. #include "files.h"
  30. #include "trace.h"
  31. #include "main.h"
  32. #include "ip.h"
  33.  
  34. static int dopap_user        __ARGS((int argc, char *argv[], void *p));
  35.  
  36. static void pap_monitor __ARGS((int mustask, void *v1, void *v2));
  37. static void pap_pwdlookup __ARGS((struct pap_s *pap_p));
  38.  
  39. static struct mbuf *pap_makereq __ARGS((struct fsm_s *fsm_p));
  40.  
  41. static int pap_verify __ARGS((char *username, char *password));
  42. static void pap_shutdown __ARGS((struct fsm_s *fsm_p));
  43. static void pap_opening __ARGS((struct fsm_s *fsm_p, int flag));
  44.  
  45. static int pap_request    __ARGS((struct fsm_s *fsm_p,
  46.             struct config_hdr *hdr,
  47.             struct mbuf *data));
  48. static int pap_check    __ARGS((struct fsm_s *fsm_p,
  49.             struct config_hdr *hdr,
  50.             struct mbuf *data));
  51. static void pap_timeout    __ARGS((void *vp));
  52.  
  53. static void pap_free    __ARGS((struct fsm_s *fsm_p));
  54.  
  55.  
  56. static struct fsm_constant_s pap_constants = {
  57.     "Pap",
  58.     PPP_PAP_PROTOCOL,
  59.     0x000E,                /* codes 1-3 recognized */
  60.  
  61.     Pap,
  62.     PAP_REQ_TRY,
  63.     PAP_FAIL_MAX,
  64.     0,
  65.     PAP_TIMEOUT * 1000L,
  66.  
  67.     pap_free,
  68.  
  69.     fsm_no_action,        /* pap_reset, */
  70.     fsm_no_action,        /* pap_starting, */
  71.     fsm_no_action,        /* pap_opening, */
  72.     fsm_no_action,        /* pap_closing, */
  73.     fsm_no_action,        /* pap_stopping, */
  74.  
  75.     pap_makereq,
  76.     fsm_no_check,        /* pap_request, */
  77.     fsm_no_check,        /* pap_ack, */
  78.     fsm_no_check,        /* pap_nak, */
  79.     fsm_no_check,        /* pap_reject */
  80. };
  81.  
  82.  
  83. /****************************************************************************/
  84.  
  85. /* "ppp <iface> pap" subcommands */
  86. static struct cmds Papcmds[] = {
  87.     { "timeout",    doppp_timeout,    0,    0,    NULLCHAR },
  88.     { "try",        doppp_try,    0,    0,    NULLCHAR },
  89.     { "user",        dopap_user,    0,    0,    NULLCHAR },
  90.     { NULLCHAR },
  91. };
  92.  
  93.  
  94. int
  95. doppp_pap(argc,argv,p)
  96. int argc;
  97. char *argv[];
  98. void *p;
  99. {
  100.     register struct iface *ifp = p;
  101.     register struct ppp_s *ppp_p = ifp->edv;
  102.  
  103.     return subcmd(Papcmds, argc, argv, &(ppp_p->fsm[Pap]));
  104. }
  105.  
  106.  
  107. /* Set user/password */
  108. int
  109. dopap_user(argc,argv,p)
  110. int argc;
  111. char *argv[];
  112. void *p;
  113. {
  114.     register struct fsm_s *fsm_p = p;
  115.     register struct pap_s *pap_p = fsm_p->pdv;
  116.  
  117.     if (argc < 2) {
  118.         tprintf("%s\n",
  119.             (pap_p->username == NULLCHAR) ? "None" : pap_p->username);
  120.         return 0;
  121.     }
  122.     free(pap_p->username);
  123.     pap_p->username = NULLCHAR;
  124.     free(pap_p->password);
  125.     pap_p->password = NULLCHAR;
  126.  
  127.     if (stricmp(argv[1],"none") != 0) {
  128.         pap_p->username = strdup(argv[1]);
  129.         if (argc > 2) {
  130.             pap_p->password = strdup(argv[2]);
  131.         } else {
  132.             pap_pwdlookup( pap_p );
  133.         }
  134.     }
  135.     return 0;
  136. }
  137.  
  138.  
  139. /****************************************************************************/
  140. /* Bring up a session on the console for for the username/password.
  141.  * Return a NULLCHAR in either username or password if aborted.
  142.  */
  143. static void
  144. pap_monitor(unused, v1, v2)
  145. int unused;
  146. void *v1;
  147. void *v2;
  148. {
  149.     struct iface *iface = v1;
  150.     struct fsm_s *fsm_p = v2;
  151.     struct pap_s *pap_p = fsm_p->pdv;
  152.     char buf[21];
  153.     struct session *sp;
  154.     int wait_code = 0;
  155.  
  156.     /* Allocate a session control block */
  157.     if((sp = newsession("PPP/PAP",PPPPASS)) == NULLSESSION){
  158.         tprintf("Too many sessions\n");
  159.         return;
  160.     }
  161.  
  162.     while ( !main_exit && wait_code == 0 ) {
  163.         /* get user name */
  164.         if (pap_p->username == NULLCHAR) {
  165.             tprintf ("%s: PPP/PAP  Username: ", iface->name);
  166.             usflush(sp->output);
  167.             if (recvline(sp->input,buf,20) > 0) {
  168.                 rip(buf);
  169.                 if (strlen(buf) > 0) {
  170.                     pap_p->username = strdup(buf);
  171.                 }
  172.             }
  173.         } else {
  174.             tprintf ("%s: PPP/PAP  Username: %s\n",
  175.                 iface->name, pap_p->username);
  176.             usflush(sp->output);
  177.         }
  178.  
  179.         /* get pass word */
  180.         if (pap_p->username != NULLCHAR
  181.          && pap_p->password == NULLCHAR) {
  182.             /* turn off echo */
  183.             sp->ttystate.echo = 0;
  184.             tprintf("%s: PPP/PAP  Password: ",iface->name);
  185.             usflush(sp->output);
  186.             if (recvline(sp->input,buf,20) > 0) {
  187.                 rip(buf);
  188.                 if ( strlen(buf) > 0 ) {
  189.                     pap_p->password = strdup(buf);
  190.                 }
  191.             }
  192.             tprintf("\n");
  193.             usflush(sp->output);
  194.             /* Turn echo back on */
  195.             sp->ttystate.echo = 1;
  196.         }
  197.  
  198.         /* send pap request */
  199.         fsm_sendreq(fsm_p);
  200.         wait_code = pwait ( pap_p );
  201.  
  202.         /* show ack/nak reply */
  203.         if ( wait_code != EABORT && pap_p->message != NULLCHAR ) {
  204.             tprintf ("%s: PPP/PAP  %s\n",
  205.                 iface->name, pap_p->message );
  206.         }
  207.         tprintf ( "\n" );
  208.         usflush(sp->output);
  209.  
  210.     }
  211.  
  212.     /* clean up */
  213.     if ( wait_code != EABORT ) {
  214.         pause ( 10000L );
  215.     }
  216.     freesession(sp);
  217.     pap_p->pp = NULLPROC;
  218. }
  219.  
  220.  
  221. /* Check the FTP userfile for this user; get password if available */
  222. static void
  223. pap_pwdlookup(pap_p)
  224. struct pap_s *pap_p;
  225. {
  226.     char *buf;
  227.     char *password;
  228.     int permission;
  229.  
  230.     if ( pap_p->username == NULLCHAR )
  231.         return;
  232.  
  233.     if ( (buf = userlookup( pap_p->username, &password, NULLCHARP,
  234.             &permission, NULL )) == NULLCHAR )
  235.         return;
  236.  
  237.     /* Check permissions for this user */
  238.     if ( (permission & PPP_PWD_LOOKUP) == 0 ) {
  239.         /* Not in ftpuser file for password lookup */
  240.         free(buf);
  241.         return;
  242.     }
  243.  
  244.     /* Save the password from this userfile record */
  245.     if ( strlen(password) != 0 )
  246.         pap_p->password = strdup(password);
  247.     free(buf);
  248. }
  249.  
  250.  
  251. /*******************************************/
  252. /* Verify user and password sent by remote host */
  253. static int
  254. pap_verify(username,password)
  255. char *username;
  256. char *password;
  257. {
  258.     int privs;
  259.     char *path;
  260.     int anony = 0;
  261.  
  262.     /* Use same login as FTP server */
  263.     path = mallocw(128);
  264.     privs = userlogin(username,password,&path,128,&anony);
  265.     free(path);
  266.  
  267.     /* Check privs for this user */
  268.     if (privs == -1) {
  269.         trace_log(PPPiface,"PAP: username/password incorrect or not found: %s",
  270.                 username);
  271.         return -1;
  272.     }
  273.  
  274.     if ((privs & PPP_ACCESS_PRIV) == 0) {
  275.         trace_log(PPPiface,"PAP: no permission for PPP access: %s",
  276.                 username);
  277.         return -1;
  278.     }
  279.     return 0;
  280. }
  281.  
  282.  
  283. /****************************************************************************/
  284. /* Build a request to send to remote host */
  285. static struct mbuf *
  286. pap_makereq(fsm_p)
  287. struct fsm_s *fsm_p;
  288. {
  289.     struct pap_s *pap_p = fsm_p->pdv;
  290.     struct mbuf *req_bp = NULLBUF;
  291.     register char *cp;
  292.     int len;
  293.  
  294.     PPP_DEBUG_ROUTINES("pap_makereq()");
  295.  
  296.     if ( pap_p->username == NULLCHAR
  297.      ||  pap_p->password == NULLCHAR ) {
  298.         fsm_log( fsm_p, "NULL username or password" );
  299.         return NULLBUF;
  300.     }
  301.  
  302. #ifdef PPP_DEBUG_OPTIONS
  303.     if (PPPtrace & PPP_DEBUG_OPTIONS)
  304.         trace_log(PPPiface, "    making user id %s", pap_p->username);
  305. #endif
  306.  
  307.     /* Get buffer for authenticate request packet */
  308.     len = 2 + strlen(pap_p->username) + strlen(pap_p->password);
  309.     if ((req_bp = alloc_mbuf(len)) == NULLBUF)
  310.         return NULLBUF;
  311.  
  312.     /* Load user id and password for authenticate packet */
  313.     cp = req_bp->data;
  314.     *cp++ = (char)strlen(pap_p->username);
  315.     if ( strlen(pap_p->username) > 0 )
  316.         cp = stpcpy(cp, pap_p->username);
  317.  
  318.     *cp++ = (char)strlen(pap_p->password);
  319.     if ( strlen(pap_p->password) > 0 )
  320.         cp = stpcpy(cp, pap_p->password);
  321.  
  322.     req_bp->cnt += len;
  323.     return(req_bp);
  324. }
  325.  
  326.  
  327. /****************************************************************************/
  328.  
  329. /* abandon PAP attempt; shutdown LCP layer */
  330. static void
  331. pap_shutdown(fsm_p)
  332. struct fsm_s *fsm_p;
  333. {
  334.     struct ppp_s *ppp_p = fsm_p->ppp_p;
  335.  
  336.     PPP_DEBUG_ROUTINES("pap_shutdown()");
  337.  
  338.     if (PPPtrace > 1)
  339.         fsm_log( fsm_p, "Failed; close connection" );
  340.  
  341.     fsm_close( &(ppp_p->fsm[Lcp]) );
  342. }
  343.  
  344.  
  345. /* Configuration negotiation complete */
  346. static void
  347. pap_opening(fsm_p, flag)
  348. struct fsm_s *fsm_p;
  349. int flag;
  350. {
  351.     register struct ppp_s *ppp_p = fsm_p->ppp_p;
  352.  
  353.     fsm_log(fsm_p, "Open");
  354.  
  355.     stop_timer(&(fsm_p->timer));
  356.  
  357.     if ( !((fsm_p->flags &= ~flag) & (PPP_AP_LOCAL | PPP_AP_REMOTE)) ) {
  358.         fsm_p->state = fsmOPENED;
  359.     }
  360.     ppp_p->flags &= ~flag;
  361.     ppp_ready(ppp_p);
  362. }
  363.  
  364.  
  365. /****************************************************************************/
  366. /* Check request from remote host */
  367. static int
  368. pap_request(fsm_p, hdr, data)
  369. struct fsm_s *fsm_p;
  370. struct config_hdr *hdr;
  371. struct mbuf *data;
  372. {
  373.     struct mbuf *reply_bp;
  374.     int result;
  375.     char *message;
  376.     int mess_length;
  377.     char *username = NULLCHAR;
  378.     int userlen;
  379.     char *password = NULLCHAR;
  380.     int passwordlen;
  381.  
  382.     PPP_DEBUG_ROUTINES("pap_request()");
  383.  
  384.     /* Extract userID/password sent by remote host */
  385.     if ( (userlen = pullchar(&data)) != -1 ) {
  386.         register int i;
  387.         register char *cp;
  388.  
  389.         cp = username = mallocw(userlen+1);
  390.         for ( i = userlen; i-- > 0; ) {
  391.             *cp++ = PULLCHAR(&data);
  392.         }
  393.         *cp = '\0';
  394.     }
  395.  
  396. #ifdef PPP_DEBUG_OPTIONS
  397.     if (PPPtrace & PPP_DEBUG_OPTIONS)
  398.         trace_log(PPPiface,"    checking user: %s", username);
  399. #endif
  400.  
  401.     if ( (passwordlen = pullchar(&data)) != -1 ) {
  402.         register int i;
  403.         register char *cp;
  404.  
  405.         cp = password = mallocw(passwordlen+1);
  406.         for ( i = passwordlen; i-- > 0; ) {
  407.             *cp++ = PULLCHAR(&data);
  408.         }
  409.         *cp = '\0';
  410.     }
  411.  
  412. #ifdef PPP_DEBUG_OPTIONS
  413.     if (PPPtrace & PPP_DEBUG_OPTIONS)
  414.         trace_log(PPPiface,"    checking password: %s", password);
  415. #endif
  416.  
  417.     if (pap_verify(username,password) == 0) {
  418.         free( fsm_p->ppp_p->peername );
  419.         fsm_p->ppp_p->peername = strdup(username);
  420.         result = CONFIG_ACK;
  421.         message = " Welcome";
  422.     } else {
  423.         result = CONFIG_NAK;
  424.         message = " Invalid username or password";
  425.     }
  426.  
  427.     /* the space at the beginning of the message is crucial */
  428.     /* it is replaced with the length of the message */
  429.     mess_length = strlen(message);
  430.     reply_bp = qdata(message,mess_length);
  431.     reply_bp->data[0] = (char)(mess_length - 1);
  432.  
  433.     fsm_send(fsm_p, result, hdr->id, reply_bp);
  434.  
  435.     if (result == CONFIG_NAK) {
  436.         if ( fsm_p->retry_nak > 0 ) {
  437.             fsm_p->retry_nak--;
  438.         } else {
  439.             pap_shutdown(fsm_p);
  440.         }
  441.     }
  442.     free_p(data);
  443.     free(username);
  444.     free(password);
  445.     return (result != CONFIG_ACK);
  446. }
  447.  
  448.  
  449. /* Check acknowledgement from remote host */
  450. static int
  451. pap_check(fsm_p, hdr, data)
  452. struct fsm_s *fsm_p;
  453. struct config_hdr *hdr;
  454. struct mbuf *data;
  455. {
  456.     struct pap_s *pap_p = fsm_p->pdv;
  457.     char *message;
  458.     int mess_length;
  459.     int full_length;
  460.     int len;
  461.  
  462.     PPP_DEBUG_ROUTINES("pap_check()");
  463.  
  464.     /* ID field must match last request we sent */
  465.     if (hdr->id != fsm_p->lastid) {
  466.         PPP_DEBUG_CHECKS("PAP: wrong ID");
  467.         tprintf ("id mismatch hdrid=%d, lastid=%d\n",
  468.             hdr->id, fsm_p->lastid);
  469.         free_p(data);
  470.         return -1;
  471.     }
  472.  
  473.     /* Log ASCII message from remote host, if any */
  474.     if ( (mess_length = pullchar(&data)) != -1 ) {
  475.         message = mallocw( mess_length+1 );
  476.         full_length = len_p(data);
  477.         len = dqdata(data, message, mess_length);
  478.         message[len] = '\0';
  479.  
  480.         free( pap_p->message );
  481.         pap_p->message = message;
  482.  
  483.         if (PPPtrace) {
  484.             trace_log(PPPiface,"%s PPP/PAP %s %s: %s",
  485.                 fsm_p->ppp_p->iface->name,
  486.                 (len < mess_length) ? "Short"
  487.                    : (mess_length < full_length) ? "Long"
  488.                     : "Valid",
  489.                 (hdr->code == CONFIG_ACK) ? "Ack" : "Nak",
  490.                 message);
  491.         }
  492.         return (len < mess_length  ||  mess_length < full_length);
  493.     }
  494.     free_p(data);
  495.     PPP_DEBUG_CHECKS( "PAP: missing message count" );
  496.     return -1;
  497. }
  498.  
  499.  
  500. /************************************************************************/
  501. /*            E V E N T   P R O C E S S I N G            */
  502. /************************************************************************/
  503.  
  504. /* Process incoming packet */
  505. void
  506. pap_proc(fsm_p,bp)
  507. struct fsm_s *fsm_p;
  508. struct mbuf *bp;
  509. {
  510.     struct pap_s *pap_p = fsm_p->pdv;
  511.     struct config_hdr hdr;
  512.  
  513.     PPPtrace = fsm_p->ppp_p->trace;
  514.     PPPiface = fsm_p->ppp_p->iface;
  515.  
  516.     if ( ntohcnf(&hdr, &bp) == -1 )
  517.         fsm_log( fsm_p, "short authentication packet" );
  518.  
  519.     if (PPPtrace > 1)
  520.         trace_log(PPPiface, "%s PPP/%s Recv,"
  521.             "  option: %s, id: %d, len: %d",
  522.             fsm_p->ppp_p->iface->name,
  523.             fsm_p->pdc->name,
  524.             fsmCodes[hdr.code],
  525.             hdr.id,    hdr.len);
  526.  
  527.     hdr.len -= CONFIG_HDR_LEN;        /* Length includes envelope */
  528.     trim_mbuf(&bp, hdr.len);        /* Trim off padding */
  529.  
  530.     switch(hdr.code) {
  531.     case CONFIG_REQ:
  532.         if ( pap_request(fsm_p, &hdr, bp) == 0) {
  533.             pap_opening(fsm_p, PPP_AP_LOCAL);
  534.         }
  535.         break;
  536.  
  537.     case CONFIG_ACK:
  538.         if (pap_check(fsm_p, &hdr, bp) == 0) {
  539.             alert ( pap_p->pp, -1 );
  540.             pap_opening(fsm_p, PPP_AP_REMOTE);
  541.         }
  542.         break;
  543.  
  544.     case CONFIG_NAK:
  545.         if (pap_check(fsm_p, &hdr, bp) == 0) {
  546.             stop_timer(&(fsm_p->timer));
  547.  
  548.             /* Must have sent a bad username or password */
  549.             free ( pap_p->username );
  550.             pap_p->username = NULLCHAR;
  551.             free ( pap_p->password );
  552.             pap_p->password = NULLCHAR;
  553.  
  554.             psignal ( pap_p, 1 );
  555.         }
  556.         break;
  557.  
  558.     default:
  559.         if (PPPtrace)
  560.             trace_log(PPPiface, "%s PPP/Pap Unknown packet type: %d;"
  561.                 " dropping packet",
  562.                 fsm_p->ppp_p->iface->name,
  563.                 hdr.code);
  564.         free_p(bp);
  565.         break;
  566.     }
  567. }
  568.  
  569.  
  570. /* Timeout while waiting for reply from remote host */
  571. static void
  572. pap_timeout(vp)
  573. void *vp;
  574. {
  575.     struct fsm_s *fsm_p = (struct fsm_s *)vp;
  576.     struct pap_s *pap_p = fsm_p->pdv;
  577.  
  578.     PPPtrace = fsm_p->ppp_p->trace;
  579.     PPPiface = fsm_p->ppp_p->iface;
  580.  
  581.     fsm_log( fsm_p, "Timeout" );
  582.  
  583.     if (fsm_p->retry > 0) {
  584.         free ( pap_p->message );
  585.         pap_p->message = strdup("Request timeout");
  586.         psignal ( pap_p, 1 );
  587.     } else {
  588.         free ( pap_p->message );
  589.         pap_p->message = strdup("Request retry exceeded");
  590.         psignal ( pap_p, 1 );
  591.         pwait ( NULL );
  592.         fsm_log(fsm_p, "Request retry exceeded");
  593.         pap_shutdown(fsm_p);
  594.     }
  595. }
  596.  
  597.  
  598. /************************************************************************/
  599. /*            I N I T I A L I Z A T I O N            */
  600. /************************************************************************/
  601.  
  602. void
  603. pap_down(fsm_p)
  604. struct fsm_s *fsm_p;
  605. {
  606.     struct pap_s *pap_p = fsm_p->pdv;
  607.  
  608.     if ( pap_p == NULL )
  609.         return;
  610.  
  611.     PPPtrace = fsm_p->ppp_p->trace;
  612.     PPPiface = fsm_p->ppp_p->iface;
  613.  
  614.     fsm_log(fsm_p, "Down");
  615.  
  616.     fsm_p->flags = FALSE;
  617.  
  618.     switch ( fsm_p->state ) {
  619.     case fsmREQ_Sent:
  620.         stop_timer(&(fsm_p->timer));
  621.         alert ( pap_p->pp, EABORT );
  622.         /* fallthru */
  623.     case fsmOPENED:
  624.     case fsmLISTEN:
  625.     case fsmTERM_Sent:
  626.         fsm_p->state = fsmCLOSED;
  627.         break;
  628.  
  629.     case fsmCLOSED:
  630.         /* Already closed; nothing to do */
  631.         break;
  632.     };
  633. }
  634.  
  635.  
  636. static void
  637. pap_free(fsm_p)
  638. struct fsm_s *fsm_p;
  639. {
  640.     struct pap_s *pap_p = fsm_p->pdv;
  641.  
  642.     free( pap_p->username );
  643.     free( pap_p->password );
  644.     free( pap_p->message );
  645. }
  646.  
  647.  
  648. /* Initialize configuration structure */
  649. void
  650. pap_init(ppp_p)
  651. struct ppp_s *ppp_p;
  652. {
  653.     struct fsm_s *fsm_p = &(ppp_p->fsm[Pap]);
  654.     struct timer *t;
  655.  
  656.     PPPtrace = ppp_p->trace;
  657.     PPPiface = ppp_p->iface;
  658.  
  659.     PPP_DEBUG_ROUTINES("pap_init()");
  660.  
  661.     if (fsm_p->pdv != NULL)
  662.         return;        /* already initialized */
  663.  
  664.     fsm_p->ppp_p = ppp_p;
  665.     fsm_p->pdc = &pap_constants;
  666.     fsm_p->pdv = callocw(1,sizeof(struct pap_s));
  667.  
  668.     fsm_p->try_req = fsm_p->pdc->try_req;
  669.     fsm_p->try_nak = fsm_p->pdc->try_nak;
  670.     fsm_p->try_terminate = fsm_p->pdc->try_terminate;
  671.  
  672.     fsm_p->state = fsmCLOSED;
  673.     fsm_p->retry = fsm_p->try_req;
  674.     fsm_p->retry_nak = fsm_p->try_nak;
  675.  
  676.     /* Initialize timer */
  677.     t = &(fsm_p->timer);
  678.     t->func = (void (*)())pap_timeout;
  679.     t->arg = (void *)fsm_p;
  680.     set_timer(t, fsm_p->pdc->timeout);
  681.     fsm_timer(fsm_p);
  682.     stop_timer(t);
  683. }
  684.  
  685.  
  686. /* Initialize state machine for local */
  687. int
  688. pap_local(ppp_p)
  689. struct ppp_s *ppp_p;
  690. {
  691.     struct fsm_s *fsm_p = &(ppp_p->fsm[Pap]);
  692.  
  693.     PPPtrace = ppp_p->trace;
  694.  
  695.     PPP_DEBUG_ROUTINES("pap_local()");
  696.  
  697.     fsm_p->state = fsmLISTEN;
  698.     fsm_p->flags |= PPP_AP_LOCAL;
  699.     ppp_p->flags |= PPP_AP_LOCAL;
  700.     fsm_p->retry = fsm_p->try_req;
  701.     return 0;
  702. }
  703.  
  704.  
  705. /* Initialize state machine for remote */
  706. int
  707. pap_remote(ppp_p)
  708. struct ppp_s *ppp_p;
  709. {
  710.     struct fsm_s *fsm_p = &(ppp_p->fsm[Pap]);
  711.     struct pap_s *pap_p = fsm_p->pdv;
  712.     char *ifn;
  713.  
  714.     PPPtrace = ppp_p->trace;
  715.  
  716.     PPP_DEBUG_ROUTINES("pap_remote()");
  717.  
  718.     fsm_p->state = fsmREQ_Sent;
  719.     fsm_p->flags |= PPP_AP_REMOTE;
  720.     ppp_p->flags |= PPP_AP_REMOTE;
  721.  
  722.     /* build a process/session to monitor user/password progress */
  723.     ifn = if_name( ppp_p->iface, " PAP" );
  724.     pap_p->pp = newproc( ifn,
  725.         512, pap_monitor, 0, ppp_p->iface, fsm_p, 0);
  726.     free( ifn );
  727.  
  728.     return 0;
  729. }
  730.  
  731.  
  732.