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

📄 pap.c

📁 PPP协议C语言源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************
*
*      Copyright (c) 1997 - 2001 by Accelerated Technology, Inc.
*
* PROPRIETARY RIGHTS of Accelerated Technology are involved in the subject
* matter of this material.  All manufacturing, reproduction, use and sales
* rights pertaining to this subject matter are governed by the license
* agreement.  The recipient of this software implicity accepts the terms
* of the license.
*
****************************************************************************
****************************************************************************
*
* FILENAME                                              VERSION
*
*       PAP.C                                               2.4
*
* COMPONENT
*
*       The Password Authentication Protocol for PPP.
*
* DESCRIPTION
*
*       This file contains the password authentication protocol that is used
*       to log into a PPP server and authenticate a calling PPP client.
*
* DATA STRUCTURES
*
*       none
*
* FUNCTIONS
*
*       PPP_PAP_Interpret
*       PAP_Send_Authentication
*       PAP_Timer_Expire
*       PAP_Check_Login
*       PAP_Send_Authentication_Ack_Nak
*
* DEPENDENCIES
*
*       nucleus.h
*       externs.h
*       tcp_errs.h"
*       netevent.h
*       target.h
*       data.h
*       ppp.h
*
****************************************************************************/
#include "plus/nucleus.h"
#include "net/inc/externs.h"
#include "net/inc/tcp_errs.h"
#include "net/inc/netevent.h"
#include "net/target.h"
#include "ppp/inc/nu_ppp.h"

/* Import all external variables */
extern struct pw_list           _passwordlist[];

/***************************************************************************
* FUNCTION
*
*       PPP_PAP_Interpret
*
* DESCRIPTION
*
*       This function processes the incoming PAP packet. This envolves
*       responding to an authentication request and informing the upper layer
*       if PAP has succeed or failed.
*
* AUTHOR
*
*       Uriah T. Pollock
*
* INPUTS
*
*       NET_BUFFER              *buf_ptr    Pointer to the incoming PAP
*                                           packet
*
* OUTPUTS
*
*       none
*
*
****************************************************************************/
VOID PPP_PAP_Interpret (NET_BUFFER *buf_ptr)
{
    LCP_LAYER       *lcp;
    LINK_LAYER      *link;
    CHAR            temp_id [PPP_MAX_ID_LENGTH];
    CHAR            temp_pw [PPP_MAX_PW_LENGTH];
    INT             temp_id_len, temp_pw_len, x;
    STATUS          ret_status;
    UINT8   HUGE    *pap_pkt = buf_ptr->data_ptr;

#ifdef NU_DEBUG_PPP
    _PRINT ("\npap interpret\r\n");
#endif

    /* Get a pointer to the LCP structure */
    lcp = &(((LINK_LAYER *)buf_ptr->mem_buf_device->link_layer)->lcp);

    /* Get a pointer to the ppp link structure */
    link = (LINK_LAYER *)buf_ptr->mem_buf_device->link_layer;

    /* Make sure that LCP is done. */
    if (lcp->state == OPENED)
    {
        switch (pap_pkt[0])
        {
            case PAP_AUTHENTICATE_REQUEST :

#ifdef NU_DEBUG_PPP
                _PRINT ("req\r\n");
#endif

                /* We need to pull out the ID and PW, then check them
                   against our internal password list. */

                /* get the id, we know where it starts in the pkt. */

                /* Get the length of the value. */
                temp_id_len = pap_pkt [PAP_ID_LENGTH_OFFSET];

                /* Copy it over. */
                for (x = 0; (x < temp_id_len) && (x < PPP_MAX_ID_LENGTH); x++)
                   temp_id [x] = pap_pkt [PAP_ID_OFFSET + x];

                /* Null terminate it. */
                temp_id [x] = (CHAR)0;

                /* now get the pw. where it starts in the pkt depends on the
                   id length field. */
                temp_pw_len = pap_pkt [PAP_ID_OFFSET + temp_id_len];

                /* Copy it over. */
                for (x = 0; (x < temp_pw_len) && (x < PPP_MAX_PW_LENGTH); x++)
                   temp_pw [x] = pap_pkt [PAP_ID_OFFSET + temp_id_len + 1 + x];

                /* Null terminate it. */
                temp_pw [x] = (CHAR)0;

                /* Now check it against the password list */
                ret_status = PAP_Check_Login (temp_id, temp_pw);

                /* Is it ok */
                if (ret_status == NU_TRUE)
                {
                    /* Let the CLIENT know that everything checked out. */
                    PAP_Send_Authentication_Ack_Nak(buf_ptr, PAP_AUTHENTICATE_ACK,
                                                    pap_pkt [LCP_ID_OFFSET]);

                    /* Move on to the next phase */
                    NU_Set_Events (&link->negotiation_progression, AUTHENTICATION_SUCCESS,
                                                                    NU_OR);
                }
                else
                {
                    /* Stop the echo timer since we are leaving the open state */
                    NU_Control_Timer (&lcp->echo_timer, NU_DISABLE_TIMER);

                    /* tell the CLIENT that they failed to login */
                    PAP_Send_Authentication_Ack_Nak(buf_ptr, PAP_AUTHENTICATE_NAK,
                                                    pap_pkt [LCP_ID_OFFSET]);

                    /* Stop the PPP session. */
                    NU_Set_Events (&link->negotiation_progression, LCP_CONFIG_FAIL, NU_OR);
                }

                break;

            case PAP_AUTHENTICATE_ACK   :
#ifdef NU_DEBUG_PPP
                _PRINT ("ack\r\n");
#endif

                /* We have received a positive response from the server.
                   If NCP is in need of negotiation let it know, otherwise
                   PAP is done. */

                if (((LINK_LAYER *)buf_ptr->mem_buf_device->link_layer)
                                ->ipcp.state != OPENED)
                    NU_Set_Events (&link->negotiation_progression, AUTHENTICATION_SUCCESS,
                                                                    NU_OR);

                break;

            case PAP_AUTHENTICATE_NAK   :
#ifdef NU_DEBUG_PPP
                _PRINT ("nak\r\n");
#endif
                /* Stop the echo timer since we are leaving the open state */
                NU_Control_Timer (&lcp->echo_timer, NU_DISABLE_TIMER);

                /* We have received a negative response from the server,
                   let the upper layer know. */
                NU_Set_Events (&link->negotiation_progression, LCP_CONFIG_FAIL, NU_OR);

                break;
        } /* switch */
    } /* if */

    /* Release the buffer space */
    MEM_Buffer_Chain_Free (&MEM_Buffer_List, &MEM_Buffer_Freelist);


}


/***************************************************************************
* FUNCTION
*
*       PAP_Send_Authentication
*
* DESCRIPTION
*
*       This function sends an authentication request.
*
* AUTHOR
*
*       Uriah T. Pollock
*
* INPUTS
*
*       none
*
* OUTPUTS
*
*       none
*
****************************************************************************/
VOID PAP_Send_Authentication (DV_DEVICE_ENTRY *dev_ptr)
{
    AUTHENTICATION_LAYER    *auth;
    NET_BUFFER              *buf_ptr;
    LCP_HEADER              *pap_pkt;
    UINT8                   *pap_pkt_ptr;
    UINT16                  len;
    UINT8                   pw_id_len, x;

#ifdef NU_DEBUG_PPP
    _PRINT ("PAP send\r\n");
#endif

    /* Allocate a buffer to send. */
    buf_ptr = MEM_Buffer_Dequeue (&MEM_Buffer_Freelist);

    /* Make sure a buffer was available */
    if (buf_ptr == NU_NULL)
    {
        NERRS_Log_Error (NERR_RECOVERABLE, __FILE__, __LINE__);

        /* Get out */
        return;
    }

    /* Get a pointer to the authentication structure. */
    auth = &(((LINK_LAYER *)dev_ptr->link_layer)->authentication);

    /* Set the data pointer and the reject packet pointer. */
    buf_ptr->data_ptr   = (buf_ptr->mem_parent_packet + dev_ptr->dev_hdrlen);
    pap_pkt             = (LCP_HEADER *) buf_ptr->data_ptr;

⌨️ 快捷键说明

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