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

📄 _radius.c

📁 This directory contains source code for tcpdump, a tool for network monitoring and data acquisition
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * Radius printer routines as specified on:
 *
 * RFC 2865:
 *      "Remote Authentication Dial In User Service (RADIUS)"
 *
 * RFC 2866:
 *      "RADIUS Accounting"
 *
 * RFC 2867:
 *      "RADIUS Accounting Modifications for Tunnel Protocol Support"
 *
 * RFC 2868:
 *      "RADIUS Attributes for Tunnel Protocol Support"
 *
 * RFC 2869:
 *      "RADIUS Extensions"
 *
 * Alfredo Andres Omella (aandres@s21sec.com) v0.1 2000/09/15
 *
 * TODO: Among other things to print ok MacIntosh and Vendor values 
 */

#if 0
static const char rcsid[] = "$Id: print-radius.c,v 1.5 2000/12/18 08:16:58 guy Exp $";
#endif

#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#include <netinet/in.h>

#include "interfac.h"
#include "a2name.h"
#include "extract.h"

#define TAM_SIZE(x) (sizeof(x)/sizeof(x[0]) )

#define PRINT_HEX(bytes_len, ptr_data)   \
           while (bytes_len)             \
           {                             \
              PRINTF ("%02X", *ptr_data);\
              ptr_data++;                \
              bytes_len--;               \
           }


/* Radius packet codes
 */
#define RADCMD_ACCESS_REQ   1   /* Access-Request      */
#define RADCMD_ACCESS_ACC   2   /* Access-Accept       */
#define RADCMD_ACCESS_REJ   3   /* Access-Reject       */
#define RADCMD_ACCOUN_REQ   4   /* Accounting-Request  */
#define RADCMD_ACCOUN_RES   5   /* Accounting-Response */
#define RADCMD_ACCESS_CHA  11   /* Access-Challenge    */
#define RADCMD_STATUS_SER  12   /* Status-Server       */
#define RADCMD_STATUS_CLI  13   /* Status-Client       */
#define RADCMD_RESERVED   255   /* Reserved            */


/* Radius Attribute types
 */
#define SERV_TYPE            6
#define FRM_IPADDR           8
#define LOG_IPHOST          14
#define LOG_SERVICE         15
#define FRM_IPX             23
#define SESSION_TIMEOUT     27
#define IDLE_TIMEOUT        28
#define FRM_ATALK_LINK      37
#define FRM_ATALK_NETWORK   38

#define ACCT_DELAY          41
#define ACCT_SESSION_TIME   46

#define TUNNEL_TYPE         64
#define TUNNEL_MEDIUM       65
#define TUNNEL_CLIENT_END   66
#define TUNNEL_SERVER_END   67
#define TUNNEL_PASS         69

#define ARAP_PASS           70
#define ARAP_FEATURES       71

#define TUNNEL_PRIV_GROUP   81
#define TUNNEL_ASSIGN_ID    82
#define TUNNEL_PREFERENCE   83

#define ARAP_CHALLENGE_RESP 84
#define ACCT_INT_INTERVAL   85

#define TUNNEL_CLIENT_AUTH  90
#define TUNNEL_SERVER_AUTH  91

static void print_attr_string (u_char *, u_int, u_short);
static void print_attr_num    (u_char *, u_int, u_short);
static void print_attr_address(u_char *, u_int, u_short);
static void print_attr_time   (u_char *, u_int, u_short);
static void print_attr_strange(u_char *, u_int, u_short);


struct radius_hdr
{
  u_int8_t code;                /* Radius packet code  */
  u_int8_t id;                  /* Radius packet id    */
  u_int16_t len;                /* Radius total length */
  u_int8_t auth[16];            /* Authenticator   */
};


struct radius_attr
{
  u_int8_t type;                /* Attribute type   */
  u_int8_t len;                 /* Attribute length */
};


/* Service-Type Attribute standard values
 */
static const char *serv_type[] = {
  NULL,
  "Login",
  "Framed",
  "Callback Login",
  "Callback Framed",
  "Outbound",
  "Administrative",
  "NAS Prompt",
  "Authenticate Only",
  "Callback NAS Prompt",
  "Call Check",
  "Callback Administrative",
};

/* Framed-Protocol Attribute standard values
 */
static const char *frm_proto[] = {
  NULL,
  "PPP",
  "SLIP",
  "ARAP",
  "Gandalf proprietary",
  "Xylogics IPX/SLIP",
  "X.75 Synchronous",
};

/* Framed-Routing Attribute standard values
 */
static const char *frm_routing[] = {
  "None",
  "Send",
  "Listen",
  "Send&Listen",
};

/* Framed-Compression Attribute standard values
 */
static const char *frm_comp[] = {
  "None",
  "VJ TCP/IP",
  "IPX",
  "Stac-LZS",
};

/* Login-Service Attribute standard values
 */
static const char *login_serv[] = {
  "Telnet",
  "Rlogin",
  "TCP Clear",
  "PortMaster(proprietary)",
  "LAT",
  "X.25-PAD",
  "X.25-T3POS",
  "Unassigned",
  "TCP Clear Quiet",
};


/* Termination-Action Attribute standard values
 */
static const char *term_action[] = {
  "Default",
  "RADIUS-Request",
};

/* NAS-Port-Type Attribute standard values
 */
static const char *nas_port_type[] = {
  "Async",
  "Sync",
  "ISDN Sync",
  "ISDN Async V.120",
  "ISDN Async V.110",
  "Virtual",
  "PIAFS",
  "HDLC Clear Channel",
  "X.25",
  "X.75",
  "G.3 Fax",
  "SDSL",
  "ADSL-CAP",
  "ADSL-DMT",
  "ISDN-DSL",
  "Ethernet",
  "xDSL",
  "Cable",
  "Wireless - Other",
  "Wireless - IEEE 802.11",
};

/* Acct-Status-Type Accounting Attribute standard values
 */
static const char *acct_status[] = {
  NULL,
  "Start",
  "Stop",
  "Interim-Update",
  "Unassigned",
  "Unassigned",
  "Unassigned",
  "Accounting-On",
  "Accounting-Off",
  "Tunnel-Start",
  "Tunnel-Stop",
  "Tunnel-Reject",
  "Tunnel-Link-Start",
  "Tunnel-Link-Stop",
  "Tunnel-Link-Reject",
  "Failed",
};

/* Acct-Authentic Accounting Attribute standard values
 */
static const char *acct_auth[] = {
  NULL,
  "RADIUS",
  "Local",
  "Remote",
};

/* Acct-Terminate-Cause Accounting Attribute standard values
 */
static const char *acct_term[] = {
  NULL,
  "User Request",
  "Lost Carrier",
  "Lost Service",
  "Idle Timeout",
  "Session Timeout",
  "Admin Reset",
  "Admin Reboot",
  "Port Error",
  "NAS Error",
  "NAS Request",
  "NAS Reboot",
  "Port Unneeded",
  "Port Preempted",
  "Port Suspended",
  "Service Unavailable",
  "Callback",
  "User Error",
  "Host Request",
};

/* Tunnel-Type Attribute standard values
 */
static const char *tunnel_type[] = {
  NULL,
  "PPTP",
  "L2F",
  "L2TP",
  "ATMP",
  "VTP",
  "AH",
  "IP-IP",
  "MIN-IP-IP",
  "ESP",
  "GRE",
  "DVS",
  "IP-in-IP Tunneling",
};

/* Tunnel-Medium-Type Attribute standard values
 */
static const char *tunnel_medium[] = {
  NULL,
  "IPv4",
  "IPv6",
  "NSAP",
  "HDLC",
  "BBN 1822",
  "802",
  "E.163",
  "E.164",
  "F.69",
  "X.121",
  "IPX",
  "Appletalk",
  "Decnet IV",
  "Banyan Vines",
  "E.164 with NSAP subaddress",
};

/* ARAP-Zone-Access Attribute standard values
 */
static const char *arap_zone[] = {
  NULL,
  "Only access to dfl zone",
  "Use zone filter inc.",
  "Not used",
  "Use zone filter exc.",
};

static const char *prompt[] = {
  "No Echo",
  "Echo",
};


struct attrtype {
       char         *name;            /* Attribute name                 */
       const char **subtypes;         /* Standard Values (if any)       */
       u_char       siz_subtypes;     /* Size of total standard values  */
       u_char       first_subtype;    /* First standard value is 0 or 1 */
       void       (*print_func) (u_char*,u_int, u_short);
     } attr_type[] = {
  {
  NULL, NULL, 0, 0, NULL}
  ,
  {
  "User", NULL, 0, 0, print_attr_string}
  ,
  {
  "Pass", NULL, 0, 0, NULL}
  ,
  {
  "CHAP-Pass", NULL, 0, 0, NULL}
  ,
  {
  "NAS_ipaddr", NULL, 0, 0, print_attr_address}
  ,
  {
  "NAS_port", NULL, 0, 0, print_attr_num}
  ,
  {
  "Service_type", serv_type, TAM_SIZE (serv_type) - 1, 1, print_attr_num}
  ,
  {
  "Framed_proto", frm_proto, TAM_SIZE (frm_proto) - 1, 1, print_attr_num}
  ,
  {
  "Framed_ipaddr", NULL, 0, 0, print_attr_address}
  ,
  {
  "Framed_ipnet", NULL, 0, 0, print_attr_address}
  ,
  {
  "Framed_routing", frm_routing, TAM_SIZE (frm_routing), 0, print_attr_num}
  ,
  {
  "Filter_id", NULL, 0, 0, print_attr_string}
  ,
  {
  "Framed_mtu", NULL, 0, 0, print_attr_num}
  ,
  {
  "Framed_compress", frm_comp, TAM_SIZE (frm_comp), 0, print_attr_num}
  ,
  {
  "Login_iphost", NULL, 0, 0, print_attr_address}
  ,
  {
  "Login_service", login_serv, TAM_SIZE (login_serv), 0, print_attr_num}
  ,
  {
  "Login_TCP_port", NULL, 0, 0, print_attr_num}
  ,
    /*17 */
  {
  "Unassigned", NULL, 0, 0, NULL}
  ,
  {
  "Reply", NULL, 0, 0, print_attr_string}
  ,
  {
  "Callback-number", NULL, 0, 0, print_attr_string}
  ,
  {
  "Callback-id", NULL, 0, 0, print_attr_string}
  ,
    /*21 */
  {
  "Unassigned", NULL, 0, 0, NULL}
  ,
  {
  "Framed_route", NULL, 0, 0, print_attr_string}
  ,
  {
  "Framed_ipx_net", NULL, 0, 0, print_attr_num}
  ,
  {
  "State", NULL, 0, 0, print_attr_string}
  ,
  {
  "Class", NULL, 0, 0, print_attr_string}
  ,
  {
  "Vendor_specific", NULL, 0, 0, print_attr_string}
  ,
  {
  "Session_timeout", NULL, 0, 0, print_attr_num}
  ,
  {
  "Idle_timeout", NULL, 0, 0, print_attr_num}
  ,
  {
  "Term_action", term_action, TAM_SIZE (term_action), 0, print_attr_num}
  ,
  {
  "Called_station", NULL, 0, 0, print_attr_string}
  ,
  {
  "Calling_station", NULL, 0, 0, print_attr_string}
  ,
  {
  "NAS_id", NULL, 0, 0, print_attr_string}
  ,
  {
  "Proxy_state", NULL, 0, 0, print_attr_string}
  ,
  {
  "Login_LAT_service", NULL, 0, 0, print_attr_string}
  ,
  {
  "Login_LAT_node", NULL, 0, 0, print_attr_string}
  ,
  {
  "Login_LAT_group", NULL, 0, 0, print_attr_string}
  ,
  {
  "Framed_atalk_link", NULL, 0, 0, print_attr_num}
  ,
  {
  "Framed_atalk_net", NULL, 0, 0, print_attr_num}
  ,
  {
  "Framed_atalk_zone", NULL, 0, 0, print_attr_string}
  ,
  {
  "Acct_status", acct_status, TAM_SIZE (acct_status) - 1, 1, print_attr_num}
  ,
  {
  "Acct_delay", NULL, 0, 0, print_attr_num}
  ,
  {
  "Acct_in_octets", NULL, 0, 0, print_attr_num}
  ,
  {
  "Acct_out_octets", NULL, 0, 0, print_attr_num}
  ,
  {
  "Acct_session_id", NULL, 0, 0, print_attr_string}
  ,
  {
  "Acct_authentic", acct_auth, TAM_SIZE (acct_auth) - 1, 1, print_attr_num}
  ,
  {
  "Acct_session_time", NULL, 0, 0, print_attr_num}
  ,
  {
  "Acct_in_packets", NULL, 0, 0, print_attr_num}
  ,
  {
  "Acct_out_packets", NULL, 0, 0, print_attr_num}
  ,
  {
  "Acct_term_cause", acct_term, TAM_SIZE (acct_term) - 1, 1, print_attr_num}
  ,
  {
  "Acct_multi_session_id", NULL, 0, 0, print_attr_string}
  ,
  {
  "Acct_link_count", NULL, 0, 0, print_attr_num}
  ,
  {
  "Acct_in_giga", NULL, 0, 0, print_attr_num}
  ,
  {
  "Acct_out_giga", NULL, 0, 0, print_attr_num}
  ,
    /*54 */
  {
  "Unassigned", NULL, 0, 0, NULL}
  ,
  {
  "Event_timestamp", NULL, 0, 0, print_attr_time}
  ,
    /*56 */
  {
  "Unassigned", NULL, 0, 0, NULL}
  ,
    /*57 */
  {
  "Unassigned", NULL, 0, 0, NULL}
  ,
    /*58 */
  {
  "Unassigned", NULL, 0, 0, NULL}
  ,
    /*59 */
  {
  "Unassigned", NULL, 0, 0, NULL}
  ,
  {
  "CHAP_challenge", NULL, 0, 0, print_attr_string}
  ,
  {
  "NAS_port_type", nas_port_type, TAM_SIZE (nas_port_type), 0, print_attr_num}
  ,
  {

⌨️ 快捷键说明

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