Annotation of embedaddon/mpd/src/auth.h, revision 1.1.1.3

1.1       misho       1: 
                      2: /*
                      3:  * auth.h
                      4:  *
                      5:  * Written by Archie Cobbs <archie@freebsd.org>
                      6:  * Copyright (c) 1995-1999 Whistle Communications, Inc. All rights reserved.
                      7:  * See ``COPYRIGHT.whistle''
                      8:  */
                      9: 
                     10: #ifndef _AUTH_H_
                     11: #define        _AUTH_H_
                     12: 
                     13: #include "timer.h"
                     14: #include "ppp.h"
                     15: #include "pap.h"
                     16: #include "chap.h"
                     17: #include "eap.h"
                     18: #include "radius.h"
                     19: 
                     20: #ifdef USE_SYSTEM
                     21: #include <pwd.h>
                     22: #endif
                     23: #ifdef USE_OPIE
                     24: #include <opie.h>
                     25: #endif
                     26: 
                     27: /*
                     28:  * DEFINITIONS
                     29:  */
                     30: 
1.1.1.2   misho      31: #define AUTH_RETRIES           5
1.1       misho      32: 
1.1.1.2   misho      33: #define AUTH_MSG_WELCOME       "Welcome"
                     34: #define AUTH_MSG_INVALID       "Login incorrect"
                     35: #define AUTH_MSG_BAD_PACKET    "Incorrectly formatted packet"
                     36: #define AUTH_MSG_NOT_ALLOWED   "Login not allowed for this account"
                     37: #define AUTH_MSG_NOT_EXPECTED  "Unexpected packet"
                     38: #define AUTH_MSG_ACCT_DISAB    "Account disabled"
                     39: #define AUTH_MSG_RESTR_HOURS   "Login hours restricted"
                     40: 
                     41: #define AUTH_PEER_TO_SELF      0
                     42: #define AUTH_SELF_TO_PEER      1
                     43: 
                     44: #define AUTH_FAIL_INVALID_LOGIN        0
                     45: #define AUTH_FAIL_ACCT_DISABLED        1
                     46: #define AUTH_FAIL_NO_PERMISSION        2
                     47: #define AUTH_FAIL_RESTRICTED_HOURS     3
                     48: #define AUTH_FAIL_INVALID_PACKET       4
                     49: #define AUTH_FAIL_NOT_EXPECTED 5
                     50: 
                     51: #define AUTH_STATUS_UNDEF              0
                     52: #define AUTH_STATUS_FAIL               1
                     53: #define AUTH_STATUS_SUCCESS            2
                     54: #define AUTH_STATUS_BUSY               3
                     55: 
                     56: #define AUTH_PW_HASH_NONE              0
                     57: #define AUTH_PW_HASH_NT                1
                     58: 
                     59: #define AUTH_ACCT_START                1
                     60: #define AUTH_ACCT_STOP         2
                     61: #define AUTH_ACCT_UPDATE               3
                     62: 
                     63: #define MPPE_POLICY_NONE       0
                     64: #define MPPE_POLICY_ALLOWED    1
                     65: #define MPPE_POLICY_REQUIRED   2
                     66: 
                     67: #define MPPE_TYPE_0BIT 0               /* No encryption required */
                     68: #define MPPE_TYPE_40BIT        2
                     69: #define MPPE_TYPE_128BIT       4
                     70: #define MPPE_TYPE_56BIT        8
                     71: 
                     72:  /* Configuration options */
                     73: enum {
                     74:        AUTH_CONF_RADIUS_AUTH = 1,
                     75:        AUTH_CONF_RADIUS_ACCT,
                     76:        AUTH_CONF_INTERNAL,
                     77:        AUTH_CONF_EXT_AUTH,
                     78:        AUTH_CONF_EXT_ACCT,
                     79:        AUTH_CONF_SYSTEM_AUTH,
                     80:        AUTH_CONF_SYSTEM_ACCT,
                     81:        AUTH_CONF_PAM_AUTH,
                     82:        AUTH_CONF_PAM_ACCT,
                     83:        AUTH_CONF_OPIE,
                     84:        AUTH_CONF_ACCT_MANDATORY
                     85: };
1.1       misho      86: 
                     87: #if defined(USE_NG_BPF) || defined(USE_IPFW)
1.1.1.2   misho      88: struct acl {                           /* List of ACLs received from auth */
                     89:        u_short number;                 /* ACL number given by auth server */
                     90:        u_short real_number;            /* ACL number allocated my mpd */
                     91:        struct acl *next;
                     92:        char    name[ACL_NAME_LEN];     /* Name of ACL */
                     93:        char    rule[1];                /* Text of ACL (Dynamically sized!) */
                     94: };
                     95: 
1.1       misho      96: #endif
                     97: 
1.1.1.2   misho      98: struct authparams {
                     99:        char    authname[AUTH_MAX_AUTHNAME];
                    100:        char    password[AUTH_MAX_PASSWORD];
                    101: 
                    102:        struct papparams pap;
                    103:        struct chapparams chap;
                    104: 
                    105:        struct u_range range;           /* IP range allowed to user */
                    106:        u_char  range_valid;            /* range is valid */
                    107:        u_char  netmask;                /* IP Netmask */
                    108:        u_char  vjc_enable;             /* VJC requested by AAA */
                    109: 
                    110:        u_char  ippool_used;
                    111:        char    ippool[LINK_MAX_NAME];
                    112: 
                    113:        struct in_addr peer_dns[2];     /* DNS servers for peer to use */
                    114:        struct in_addr peer_nbns[2];    /* NBNS servers for peer to use */
                    115: 
                    116:        char   *eapmsg;                 /* EAP Msg for forwarding to RADIUS
                    117:                                         * server */
                    118:        int     eapmsg_len;
                    119:        u_char *state;                  /* copy of the state attribute, needed
                    120:                                         * for accounting */
                    121:        int     state_len;
                    122:        u_char *class;                  /* copy of the class attribute, needed
                    123:                                         * for accounting */
                    124:        int     class_len;
                    125: 
                    126:        char   *filter_id;              /* RADIUS Framed-Filter-Id attribute */
1.1       misho     127: 
1.1.1.2   misho     128:        char    action[8 + LINK_MAX_NAME];
1.1       misho     129: 
                    130: #ifdef USE_IPFW
1.1.1.2   misho     131:        struct acl *acl_rule;           /* ipfw rules */
                    132:        struct acl *acl_pipe;           /* ipfw pipes */
                    133:        struct acl *acl_queue;          /* ipfw queues */
                    134:        struct acl *acl_table;          /* ipfw tables */
1.1       misho     135: #endif
                    136: 
                    137: #ifdef USE_NG_BPF
1.1.1.2   misho     138:        struct acl *acl_filters[ACL_FILTERS];   /* mpd's internal bpf filters */
                    139:        struct acl *acl_limits[ACL_DIRS];       /* traffic limits based on
                    140:                                                 * mpd's filters */
                    141: 
                    142:        char    std_acct[ACL_DIRS][ACL_NAME_LEN];       /* Names of ACL rerurned
                    143:                                                         * in standard
                    144:                                                         * accounting */
1.1       misho     145: #endif
                    146: 
1.1.1.2   misho     147:        u_int   session_timeout;        /* Session-Timeout */
                    148:        u_int   idle_timeout;           /* Idle-Timeout */
                    149:        u_int   acct_update;            /* interval for accouting updates */
                    150:        u_int   acct_update_lim_recv;
                    151:        u_int   acct_update_lim_xmit;
                    152:        char   *msdomain;               /* Microsoft domain */
                    153:        SLIST_HEAD (, ifaceroute) routes;
                    154:        u_short mtu;                    /* MTU */
                    155: 
                    156:        u_char  authentic;              /* wich backend was used */
                    157: 
                    158:        char    callingnum[128];        /* hr representation of the calling
                    159:                                         * number */
                    160:        char    callednum[128];         /* hr representation of the called
                    161:                                         * number */
                    162:        char    selfname[64];           /* hr representation of the self name */
                    163:        char    peername[64];           /* hr representation of the peer name */
                    164:        char    selfaddr[64];           /* hr representation of the self
                    165:                                         * address */
                    166:        char    peeraddr[64];           /* hr representation of the peer
                    167:                                         * address */
                    168:        char    peerport[6];            /* hr representation of the peer port */
                    169:        char    peermacaddr[32];        /* hr representation of the peer MAC
                    170:                                         * address */
                    171:        char    peeriface[IFNAMSIZ];    /* hr representation of the peer
                    172:                                         * interface */
                    173: 
                    174:        /* Iface stuff */
                    175:        char    ifname[IFNAMSIZ];       /* Interface name */
1.1       misho     176: #ifdef SIOCSIFDESCR
1.1.1.2   misho     177:        char   *ifdescr;                /* Interface description */
1.1       misho     178: #endif
                    179: #ifdef SIOCAIFGROUP
1.1.1.2   misho     180:        char    ifgroup[IFNAMSIZ];      /* Interface group */
1.1       misho     181: #endif
                    182: 
1.1.1.2   misho     183:        struct {
                    184:                int     policy;         /* MPPE_POLICY_* */
                    185:                int     types;          /* MPPE_TYPE_*BIT bitmask */
                    186:                u_char  lm_hash[16];    /* LM-Hash */
                    187:                u_char  nt_hash[16];    /* NT-Hash */
                    188:                u_char  nt_hash_hash[16];       /* NT-Hash-Hash */
                    189:                u_char  has_lm_hash;
                    190:                u_char  has_nt_hash;
                    191:                u_char  has_keys;
1.1       misho     192: 
1.1.1.2   misho     193:                u_char  chap_alg;       /* Callers's CHAP algorithm */
1.1       misho     194: 
1.1.1.2   misho     195:                u_char  msChal[CHAP_MSOFTv2_CHAL_LEN];  /* MSOFT challng */
                    196:                u_char  ntResp[CHAP_MSOFTv2_RESP_LEN];  /* MSOFT response */
1.1       misho     197: 
                    198: #ifdef CCP_MPPC
1.1.1.2   misho     199:                /* Keys when using MS-CHAPv2 or EAP */
                    200:                u_char  xmit_key[MPPE_KEY_LEN]; /* xmit start key */
                    201:                u_char  recv_key[MPPE_KEY_LEN]; /* recv start key */
1.1       misho     202: #endif
1.1.1.2   misho     203:        }       msoft;
                    204: };
1.1       misho     205: 
1.1.1.2   misho     206: struct authconf {
                    207:        struct radiusconf radius;       /* RADIUS configuration */
                    208:        char    authname[AUTH_MAX_AUTHNAME];    /* Configured username */
                    209:        char    password[AUTH_MAX_PASSWORD];    /* Configured password */
                    210:        u_int   acct_update;
                    211:        u_int   acct_update_lim_recv;
                    212:        u_int   acct_update_lim_xmit;
                    213:        int     timeout;                /* Authorization timeout in seconds */
                    214:        struct optinfo options;         /* Configured options */
                    215:        char   *extauth_script;         /* External auth script */
                    216:        char   *extacct_script;         /* External acct script */
                    217:        char    ippool[LINK_MAX_NAME];
                    218: };
                    219: typedef struct authconf *AuthConf;
                    220: 
                    221:  /*
                    222:   * State of authorization process during authorization phase, contains
                    223:   * params set by the auth-backend
                    224:   */
                    225: struct auth {
                    226:        u_short peer_to_self;           /* What I need from peer */
                    227:        u_short self_to_peer;           /* What peer needs from me */
                    228:        u_char  peer_to_self_alg;       /* What alg I need from peer */
                    229:        u_char  self_to_peer_alg;       /* What alg peer needs from me */
                    230:        struct pppTimer timer;          /* Max time to spend doing auth */
                    231:        struct pppTimer acct_timer;     /* Timer for accounting updates */
                    232:        struct papinfo pap;             /* PAP state */
                    233:        struct chapinfo chap;           /* CHAP state */
                    234:        struct eapinfo eap;             /* EAP state */
                    235:        struct paction *thread;         /* async auth thread */
                    236:        struct paction *acct_thread;    /* async accounting auth thread */
                    237:        struct authconf conf;           /* Auth backends, RADIUS, etc. */
                    238:        struct authparams params;       /* params to pass to from auth backend */
                    239:        struct ng_ppp_link_stat64 prev_stats;   /* Previous link statistics */
                    240: };
                    241: typedef struct auth *Auth;
                    242: 
                    243:  /*
                    244:   * Interface between the auth-backend (secret file, RADIUS, etc.) and Mpd's
                    245:   * internal structs.
                    246:   */
                    247: struct authdata {
                    248:        struct authconf conf;           /* a copy of bundle's authconf */
                    249:        u_short proto;                  /* wich proto are we using, PAP, CHAP,
                    250:                                         * ... */
                    251:        u_char  alg;                    /* proto specific algoruthm */
                    252:        u_int   id;                     /* Actual, packet id */
                    253:        u_int   code;                   /* Proto specific code */
                    254:        u_char  acct_type;              /* Accounting type, Start, Stop,
                    255:                                         * Update */
                    256:        u_char  eap_radius;
                    257:        u_char  status;
                    258:        u_char  why_fail;
                    259:        char   *reply_message;          /* Text wich may displayed to the user */
                    260:        char   *mschap_error;           /* MSCHAP Error Message */
                    261:        char   *mschapv2resp;           /* Response String for MSCHAPv2 */
                    262:        void    (*finish) (Link l, struct authdata *auth);      /* Finish handler */
                    263:        int     drop_user;              /* RAD_MPD_DROP_USER value sent by
                    264:                                         * RADIUS server */
                    265:        struct {
                    266:                struct rad_handle *handle;      /* the RADIUS handle */
                    267:        }       radius;
1.1       misho     268: #ifdef USE_OPIE
1.1.1.2   misho     269:        struct {
                    270:                struct opie data;
                    271:        }       opie;
1.1       misho     272: #endif
1.1.1.2   misho     273:        struct {                        /* informational (read-only) data
                    274:                                         * needed for e.g. accouting */
                    275:                char    msession_id[AUTH_MAX_SESSIONID];        /* multi-session-id */
                    276:                char    session_id[AUTH_MAX_SESSIONID]; /* session-id */
                    277:                char    ifname[IFNAMSIZ];       /* interface name */
                    278:                uint    ifindex;        /* System interface index */
                    279:                char    bundname[LINK_MAX_NAME];        /* name of the bundle */
                    280:                char    lnkname[LINK_MAX_NAME]; /* name of the link */
                    281:                struct ng_ppp_link_stat64 stats;        /* Current link
                    282:                                                         * statistics */
1.1       misho     283: #ifdef USE_NG_BPF
1.1.1.2   misho     284:                struct svcstat ss;
1.1       misho     285: #endif
1.1.1.2   misho     286:                char   *downReason;     /* Reason for link going down */
                    287:                time_t  last_up;        /* Time this link last got up */
1.1.1.3 ! misho     288:                const struct phystype *phys_type; /* Device type descriptor */
1.1.1.2   misho     289:                int     linkID;         /* Absolute link number */
                    290:                char    peer_ident[64]; /* LCP ident received from peer */
                    291:                struct in_addr peer_addr;       /* currently assigned
                    292:                                                 * IP-Address of the client */
                    293:                struct in6_addr peer_addr6;     /* currently assigned
                    294:                                                 * IPv6-Address of the client */
                    295:                short   n_links;        /* number of links in the bundle */
                    296:                u_char  originate;      /* Who originated the connection */
                    297:        }       info;
                    298:        struct authparams params;       /* params to pass to from auth backend */
                    299: };
                    300: typedef struct authdata *AuthData;
                    301: 
                    302: extern const struct cmdtab AuthSetCmds[];
1.1       misho     303: 
                    304: /*
                    305:  * GLOBAL VARIABLES
                    306:  */
1.1.1.2   misho     307: extern const u_char gMsoftZeros[32];
1.1       misho     308: 
                    309: /*
                    310:  * FUNCTIONS
                    311:  */
                    312: 
1.1.1.2   misho     313: extern void AuthInit(Link l);
                    314: extern void AuthInst(Auth auth, Auth autht);
                    315: extern void AuthShutdown(Link l);
                    316: extern void AuthStart(Link l);
                    317: extern void AuthStop(Link l);
                    318: extern void AuthInput(Link l, int proto, Mbuf bp);
                    319: extern void 
                    320: AuthOutput(Link l, int proto, u_int code, u_int id,
                    321:     const u_char *ptr, int len, int add_len,
                    322:     u_char eap_type);
                    323: extern void AuthFinish(Link l, int which, int ok);
                    324: extern void AuthCleanup(Link l);
1.1.1.3 ! misho     325: extern int AuthStat(Context ctx, int ac, const char *const av[], const void *arg);
1.1.1.2   misho     326: extern void AuthAccountStart(Link l, int type);
                    327: extern void AuthAccountTimeout(void *arg);
                    328: extern AuthData AuthDataNew(Link l);
                    329: extern void AuthDataDestroy(AuthData auth);
                    330: extern int 
                    331: AuthGetData(char *authname, char *password, size_t passlen,
                    332:     struct u_range *range, u_char *range_valid);
                    333: extern void AuthAsyncStart(Link l, AuthData auth);
                    334: extern const char *AuthFailMsg(AuthData auth, char *buf, size_t len);
                    335: extern const char *AuthStatusText(int status);
                    336: extern const char *AuthMPPEPolicyname(int policy);
                    337: extern const char *AuthMPPETypesname(int types, char *buf, size_t len);
1.1       misho     338: 
                    339: #if defined(USE_NG_BPF) || defined(USE_IPFW)
1.1.1.2   misho     340: extern void ACLCopy(struct acl *src, struct acl **dst);
                    341: extern void ACLDestroy(struct acl *acl);
                    342: 
1.1       misho     343: #endif
1.1.1.2   misho     344: extern void authparamsInit(struct authparams *ap);
                    345: extern void authparamsCopy(struct authparams *src, struct authparams *dst);
                    346: extern void authparamsMove(struct authparams *src, struct authparams *dst);
                    347: extern void authparamsDestroy(struct authparams *ap);
1.1       misho     348: 
                    349: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>