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

📄 rlm_preprocess.c

📁 使用最广泛的radius的linux的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
		 */		if (((strcmp(i->name, "DEFAULT") == 0) ||		     (strcmp(i->name, name) == 0)) &&		    (paircompare(request, request_pairs, i->check, NULL) == 0)) {			DEBUG2("  hints: Matched %s at %d",			       i->name, i->lineno);			/*			 *	Now add all attributes to the request list,			 *	except PW_STRIP_USER_NAME and PW_FALL_THROUGH			 *	and xlat them.			 */			add = paircopy(i->reply);			ft = fallthrough(add);			pairdelete(&add, PW_STRIP_USER_NAME);			pairdelete(&add, PW_FALL_THROUGH);			pairxlatmove(request, &request->packet->vps, &add);			pairfree(&add);			updated = 1;			if (!ft) break;		}	}	if (updated == 0) return RLM_MODULE_NOOP;	return RLM_MODULE_UPDATED;}/* *	See if we have access to the huntgroup. */static int huntgroup_access(REQUEST *request, PAIR_LIST *huntgroups){	PAIR_LIST	*i;	int		r = RLM_MODULE_OK;	VALUE_PAIR	*request_pairs = request->packet->vps;	/*	 *	We're not controlling access by huntgroups:	 *	Allow them in.	 */	if (huntgroups == NULL)		return RLM_MODULE_OK;	for(i = huntgroups; i; i = i->next) {		/*		 *	See if this entry matches.		 */		if (paircompare(request, request_pairs, i->check, NULL) != 0)			continue;		/*		 *	Now check for access.		 */		r = RLM_MODULE_REJECT;		if (hunt_paircmp(request, request_pairs, i->reply) == 0) {			VALUE_PAIR *vp;			/*			 *  We've matched the huntgroup, so add it in			 *  to the list of request pairs.			 */			vp = pairfind(request_pairs, PW_HUNTGROUP_NAME);			if (!vp) {				vp = radius_paircreate(request,						       &request->packet->vps,						       PW_HUNTGROUP_NAME,						       PW_TYPE_STRING);				strlcpy(vp->vp_strvalue, i->name,					sizeof(vp->vp_strvalue));				vp->length = strlen(vp->vp_strvalue);			}			r = RLM_MODULE_OK;		}		break;	}	return r;}/* *	If the NAS wasn't smart enought to add a NAS-IP-Address *	to the request, then add it ourselves. */static int add_nas_attr(REQUEST *request){	VALUE_PAIR *nas;	switch (request->packet->src_ipaddr.af) {	case AF_INET:		nas = pairfind(request->packet->vps, PW_NAS_IP_ADDRESS);		if (!nas) {			nas = radius_paircreate(request, &request->packet->vps,						PW_NAS_IP_ADDRESS,						PW_TYPE_IPADDR);			nas->vp_ipaddr = request->packet->src_ipaddr.ipaddr.ip4addr.s_addr;		}		break;	case AF_INET6:		nas = pairfind(request->packet->vps, PW_NAS_IPV6_ADDRESS);		if (!nas) {			nas = radius_paircreate(request, &request->packet->vps,						PW_NAS_IPV6_ADDRESS,						PW_TYPE_IPV6ADDR);			memcpy(nas->vp_strvalue,			       &request->packet->src_ipaddr.ipaddr,			       sizeof(request->packet->src_ipaddr.ipaddr));		}		break;	default:		radlog(L_ERR, "Unknown address family for packet");		return -1;	}	return 0;}/* *	Initialize. */static int preprocess_instantiate(CONF_SECTION *conf, void **instance){	int	rcode;	rlm_preprocess_t *data;	/*	 *	Allocate room to put the module's instantiation data.	 */	data = (rlm_preprocess_t *) rad_malloc(sizeof(*data));	memset(data, 0, sizeof(*data));	/*	 *	Read this modules configuration data.	 */        if (cf_section_parse(conf, data, module_config) < 0) {		free(data);                return -1;        }	data->huntgroups = NULL;	data->hints = NULL;	/*	 *	Read the huntgroups file.	 */	rcode = pairlist_read(data->huntgroup_file, &(data->huntgroups), 0);	if (rcode < 0) {		radlog(L_ERR|L_CONS, "rlm_preprocess: Error reading %s",		       data->huntgroup_file);		return -1;	}	/*	 *	Read the hints file.	 */	rcode = pairlist_read(data->hints_file, &(data->hints), 0);	if (rcode < 0) {		radlog(L_ERR|L_CONS, "rlm_preprocess: Error reading %s",		       data->hints_file);		return -1;	}	/*	 *	Save the instantiation data for later.	 */	*instance = data;	return 0;}/* *	Preprocess a request. */static int preprocess_authorize(void *instance, REQUEST *request){	int r;	rlm_preprocess_t *data = (rlm_preprocess_t *) instance;	/*	 *	Mangle the username, to get rid of stupid implementation	 *	bugs.	 */	rad_mangle(data, request);	if (data->with_ascend_hack) {		/*		 *	If we're using Ascend systems, hack the NAS-Port-Id		 *	in place, to go from Ascend's weird values to something		 *	approaching rationality.		 */		ascend_nasport_hack(pairfind(request->packet->vps,					     PW_NAS_PORT),				    data->ascend_channels_per_line);	}	if (data->with_cisco_vsa_hack) {	 	/*		 *	We need to run this hack because the h323-conf-id		 *	attribute should be used.		 */		cisco_vsa_hack(request->packet->vps);	}	if (data->with_alvarion_vsa_hack) {	 	/*		 *	We need to run this hack because the Alvarion		 *	people are crazy.		 */		alvarion_vsa_hack(request->packet->vps);	}	/*	 *	Note that we add the Request-Src-IP-Address to the request	 *	structure BEFORE checking huntgroup access.  This allows	 *	the Request-Src-IP-Address to be used for huntgroup	 *	comparisons.	 */	if (add_nas_attr(request) < 0) {		return RLM_MODULE_FAIL;	}	hints_setup(data->hints, request);	/*	 *      If there is a PW_CHAP_PASSWORD attribute but there	 *      is PW_CHAP_CHALLENGE we need to add it so that other	 *	modules can use it as a normal attribute.	 */	if (pairfind(request->packet->vps, PW_CHAP_PASSWORD) &&	    pairfind(request->packet->vps, PW_CHAP_CHALLENGE) == NULL) {		VALUE_PAIR *vp;		vp = radius_paircreate(request, &request->packet->vps,				       PW_CHAP_CHALLENGE, PW_TYPE_OCTETS);		vp->length = AUTH_VECTOR_LEN;		memcpy(vp->vp_strvalue, request->packet->vector, AUTH_VECTOR_LEN);	}	if ((r = huntgroup_access(request,				  data->huntgroups)) != RLM_MODULE_OK) {		char buf[1024];		radlog(L_AUTH, "No huntgroup access: [%s] (%s)",		       request->username ? request->username->vp_strvalue : "<NO User-Name>",		       auth_name(buf, sizeof(buf), request, 1));		return r;	}	return RLM_MODULE_OK; /* Meaning: try next authorization module */}/* *	Preprocess a request before accounting */static int preprocess_preaccounting(void *instance, REQUEST *request){	int r;	rlm_preprocess_t *data = (rlm_preprocess_t *) instance;	/*	 *  Ensure that we have the SAME user name for both	 *  authentication && accounting.	 */	rad_mangle(data, request);	if (data->with_cisco_vsa_hack) {	 	/*		 *	We need to run this hack because the h323-conf-id		 *	attribute should be used.		 */		cisco_vsa_hack(request->packet->vps);	}	if (data->with_alvarion_vsa_hack) {	 	/*		 *	We need to run this hack because the Alvarion		 *	people are crazy.		 */		alvarion_vsa_hack(request->packet->vps);	}	/*	 *  Ensure that we log the NAS IP Address in the packet.	 */	if (add_nas_attr(request) < 0) {		return RLM_MODULE_FAIL;	}	r = hints_setup(data->hints, request);	if ((r = huntgroup_access(request,				  data->huntgroups)) != RLM_MODULE_OK) {		char buf[1024];		radlog(L_INFO, "No huntgroup access: [%s] (%s)",		       request->username ? request->username->vp_strvalue : "<NO User-Name>",		       auth_name(buf, sizeof(buf), request, 1));		return r;	}	return r;}/* *      Clean up the module's instance. */static int preprocess_detach(void *instance){	rlm_preprocess_t *data = (rlm_preprocess_t *) instance;	pairlist_free(&(data->huntgroups));	pairlist_free(&(data->hints));	free(data);	return 0;}/* globally exported name */module_t rlm_preprocess = {	RLM_MODULE_INIT,	"preprocess",	RLM_TYPE_CHECK_CONFIG_SAFE,   	/* type */	preprocess_instantiate,	/* instantiation */	preprocess_detach,	/* detach */	{		NULL,			/* authentication */		preprocess_authorize,	/* authorization */		preprocess_preaccounting, /* pre-accounting */		NULL,			/* accounting */		NULL,			/* checksimul */		NULL,			/* pre-proxy */		NULL,			/* post-proxy */		NULL			/* post-auth */	},};

⌨️ 快捷键说明

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