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