File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / mpd / src / auth.h
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Nov 1 09:56:12 2016 UTC (7 years, 8 months ago) by misho
Branches: mpd, MAIN
CVS tags: v5_8p7, v5_8p1_cross, v5_8p1, v5_8, HEAD
mpd 5.8

    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: 
   31: #define AUTH_RETRIES		5
   32: 
   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: };
   86: 
   87: #if defined(USE_NG_BPF) || defined(USE_IPFW)
   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: 
   96: #endif
   97: 
   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 */
  127: 
  128: 	char	action[8 + LINK_MAX_NAME];
  129: 
  130: #ifdef USE_IPFW
  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 */
  135: #endif
  136: 
  137: #ifdef USE_NG_BPF
  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 */
  145: #endif
  146: 
  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 */
  176: #ifdef SIOCSIFDESCR
  177: 	char   *ifdescr;		/* Interface description */
  178: #endif
  179: #ifdef SIOCAIFGROUP
  180: 	char	ifgroup[IFNAMSIZ];	/* Interface group */
  181: #endif
  182: 
  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;
  192: 
  193: 		u_char	chap_alg;	/* Callers's CHAP algorithm */
  194: 
  195: 		u_char	msChal[CHAP_MSOFTv2_CHAL_LEN];	/* MSOFT challng */
  196: 		u_char	ntResp[CHAP_MSOFTv2_RESP_LEN];	/* MSOFT response */
  197: 
  198: #ifdef CCP_MPPC
  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 */
  202: #endif
  203: 	}	msoft;
  204: };
  205: 
  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: struct radiusconf radius;		/* RADIUS configuration */
  244: 
  245:  /*
  246:   * Interface between the auth-backend (secret file, RADIUS, etc.) and Mpd's
  247:   * internal structs.
  248:   */
  249: struct authdata {
  250: 	struct authconf conf;		/* a copy of bundle's authconf */
  251: 	u_short	proto;			/* wich proto are we using, PAP, CHAP,
  252: 					 * ... */
  253: 	u_char	alg;			/* proto specific algoruthm */
  254: 	u_int	id;			/* Actual, packet id */
  255: 	u_int	code;			/* Proto specific code */
  256: 	u_char	acct_type;		/* Accounting type, Start, Stop,
  257: 					 * Update */
  258: 	u_char	eap_radius;
  259: 	u_char	status;
  260: 	u_char	why_fail;
  261: 	char   *reply_message;		/* Text wich may displayed to the user */
  262: 	char   *mschap_error;		/* MSCHAP Error Message */
  263: 	char   *mschapv2resp;		/* Response String for MSCHAPv2 */
  264: 	void    (*finish) (Link l, struct authdata *auth);	/* Finish handler */
  265: 	int	drop_user;		/* RAD_MPD_DROP_USER value sent by
  266: 					 * RADIUS server */
  267: 	struct {
  268: 		struct rad_handle *handle;	/* the RADIUS handle */
  269: 	}	radius;
  270: #ifdef USE_OPIE
  271: 	struct {
  272: 		struct opie data;
  273: 	}	opie;
  274: #endif
  275: 	struct {			/* informational (read-only) data
  276: 					 * needed for e.g. accouting */
  277: 		char	msession_id[AUTH_MAX_SESSIONID];	/* multi-session-id */
  278: 		char	session_id[AUTH_MAX_SESSIONID];	/* session-id */
  279: 		char	ifname[IFNAMSIZ];	/* interface name */
  280: 		uint	ifindex;	/* System interface index */
  281: 		char	bundname[LINK_MAX_NAME];	/* name of the bundle */
  282: 		char	lnkname[LINK_MAX_NAME];	/* name of the link */
  283: 		struct ng_ppp_link_stat64 stats;	/* Current link
  284: 							 * statistics */
  285: #ifdef USE_NG_BPF
  286: 		struct svcstat ss;
  287: #endif
  288: 		char   *downReason;	/* Reason for link going down */
  289: 		time_t	last_up;	/* Time this link last got up */
  290: 		PhysType phys_type;	/* Device type descriptor */
  291: 		int	linkID;		/* Absolute link number */
  292: 		char	peer_ident[64];	/* LCP ident received from peer */
  293: 		struct in_addr peer_addr;	/* currently assigned
  294: 						 * IP-Address of the client */
  295: 		struct in6_addr peer_addr6;	/* currently assigned
  296: 						 * IPv6-Address of the client */
  297: 		short	n_links;	/* number of links in the bundle */
  298: 		u_char	originate;	/* Who originated the connection */
  299: 	}	info;
  300: 	struct authparams params;	/* params to pass to from auth backend */
  301: };
  302: typedef struct authdata *AuthData;
  303: 
  304: extern const struct cmdtab AuthSetCmds[];
  305: 
  306: /*
  307:  * GLOBAL VARIABLES
  308:  */
  309: extern const u_char gMsoftZeros[32];
  310: extern int gMaxLogins;			/* max number of concurrent logins per
  311: 					 * user */
  312: extern int gMaxLoginsCI;
  313: 
  314: /*
  315:  * FUNCTIONS
  316:  */
  317: 
  318: extern void AuthInit(Link l);
  319: extern void AuthInst(Auth auth, Auth autht);
  320: extern void AuthShutdown(Link l);
  321: extern void AuthStart(Link l);
  322: extern void AuthStop(Link l);
  323: extern void AuthInput(Link l, int proto, Mbuf bp);
  324: extern void 
  325: AuthOutput(Link l, int proto, u_int code, u_int id,
  326:     const u_char *ptr, int len, int add_len,
  327:     u_char eap_type);
  328: extern void AuthFinish(Link l, int which, int ok);
  329: extern void AuthCleanup(Link l);
  330: extern int AuthStat(Context ctx, int ac, char *av[], void *arg);
  331: extern void AuthAccountStart(Link l, int type);
  332: extern void AuthAccountTimeout(void *arg);
  333: extern AuthData AuthDataNew(Link l);
  334: extern void AuthDataDestroy(AuthData auth);
  335: extern int 
  336: AuthGetData(char *authname, char *password, size_t passlen,
  337:     struct u_range *range, u_char *range_valid);
  338: extern void AuthAsyncStart(Link l, AuthData auth);
  339: extern const char *AuthFailMsg(AuthData auth, char *buf, size_t len);
  340: extern const char *AuthStatusText(int status);
  341: extern const char *AuthMPPEPolicyname(int policy);
  342: extern const char *AuthMPPETypesname(int types, char *buf, size_t len);
  343: 
  344: #if defined(USE_NG_BPF) || defined(USE_IPFW)
  345: extern void ACLCopy(struct acl *src, struct acl **dst);
  346: extern void ACLDestroy(struct acl *acl);
  347: 
  348: #endif
  349: extern void authparamsInit(struct authparams *ap);
  350: extern void authparamsCopy(struct authparams *src, struct authparams *dst);
  351: extern void authparamsMove(struct authparams *src, struct authparams *dst);
  352: extern void authparamsDestroy(struct authparams *ap);
  353: 
  354: #endif

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