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

📄 mainconfig.c

📁 新的radius程序
💻 C
📖 第 1 页 / 共 3 页
字号:
	 *	Otherwise, don't do anything.	 */	if (mainconfig.proxy_requests == TRUE) {		int		port = -1;		rad_listen_t	*auth;		int		num_realms = 0;		int		localhost = 0;		int		otherhost = 0;		REALM		*realm;		uint32_t	proxy_ip;		uint32_t	ipaddr;		/*		 *	If there are no realms configured, don't		 *	open the proxy port.		 */		for (realm = mainconfig.realms;		     realm != NULL;		     realm = realm->next) {			/*			 *	Ignore LOCAL realms.			 */			if ((realm->ipaddr == htonl(INADDR_NONE)) &&			    (realm->acct_ipaddr == htonl(INADDR_NONE))) {				continue;			}			num_realms++;			/*			 *	Loopback addresses			 */			if (realm->ipaddr == htonl(INADDR_LOOPBACK)) {				localhost = 1;			} else {				otherhost = 1;			}			if (realm->acct_ipaddr == htonl(INADDR_LOOPBACK)) {				localhost = 1;			} else {				otherhost = 1;			}		}		/*		 *	No external realms.  Don't open another port.		 */		if (num_realms == 0) {			return 0;		}		/*		 *	All of the realms are localhost, don't open		 *	an external port.		 */		if (localhost && !otherhost) {			proxy_ip = htonl(INADDR_LOOPBACK);		} else {			/*			 *	Multiple external realms, listen			 *	on any address that will send packets.			 */			proxy_ip = htonl(INADDR_NONE);		}		/*		 *	Find the first authentication port,		 *	and use it		 */		ipaddr = htonl(INADDR_NONE);		for (auth = *head; auth != NULL; auth = auth->next) {			/*			 *	Listening on ANY, use that.			 */			if (ipaddr != htonl(INADDR_ANY)) {				/*				 *	Not set.  Pick the first one.				 *	Or, ANY, pick that.				 */				if ((ipaddr == htonl(INADDR_NONE)) ||				    (auth->ipaddr == htonl(INADDR_ANY))) {					ipaddr = auth->ipaddr;					/*					 *	Else listening on multiple					 *	IP's, use ANY for proxying.					 */				} else if (ipaddr != auth->ipaddr) {					ipaddr = htonl(INADDR_ANY);				}			}			if (auth->type == RAD_LISTEN_AUTH) {				port = auth->port + 2;				break;			}		}		/*		 *	Not found, pick an accounting port.		 */		if (port < 0) for (auth = *head; auth != NULL; auth = auth->next) {			if (auth->type == RAD_LISTEN_ACCT) {				port = auth->port + 1;				break;			}		}		/*		 *	Still no port.  Don't do anything.		 */		if (port < 0) {			return 0;		}		this = rad_malloc(sizeof(*this));		memset(this, 0, sizeof(*this));		/*		 *	More checks to do the right thing.		 */		if (proxy_ip == htonl(INADDR_NONE)) {			proxy_ip = ipaddr;		}				/*		 *	Create the proxy socket.		 */		this->ipaddr = proxy_ip;		this->type = RAD_LISTEN_PROXY;		/*		 *	Try to find a proxy port (value doesn't matter)		 */		for (this->port = port;		     this->port < 64000;		     this->port++) {			if (listen_bind(this) == 0) {				last_proxy_port = this->port;				*last = this;				return 0;			}		}		radlog(L_ERR|L_CONS, "Failed to open socket for proxying");		free(this);		return -1;	}	return 0;}/* *	Hack the OLD way of listening on a socket. */static int old_listen_init(rad_listen_t **head){	CONF_PAIR	*cp;	rad_listen_t 	*this, **last;	/*	 *	No "bind_address": all listen directives	 *	are in the "listen" clauses.	 */	cp = cf_pair_find(mainconfig.config, "bind_address");	if (!cp) return 0;		last = head;	this = rad_malloc(sizeof(*this));	memset(this, 0, sizeof(*this));	/*	 *	Create the authentication socket.	 */       	this->ipaddr = mainconfig.myip;	this->type = RAD_LISTEN_AUTH;	this->port = auth_port;	if (listen_bind(this) < 0) {		radlog(L_CONS|L_ERR, "There appears to be another RADIUS server running on the authentication port %d", this->port);		free(this);		return -1;	}	auth_port = this->port;	/* may have been updated in listen_bind */	*last = this;	last = &(this->next);	/*	 *  Open Accounting Socket.	 *	 *  If we haven't already gotten acct_port from /etc/services,	 *  then make it auth_port + 1.	 */	this = rad_malloc(sizeof(*this));	memset(this, 0, sizeof(*this));	/*	 *	Create the accounting socket.	 *	 *	The accounting port is always the authentication port + 1	 */       	this->ipaddr = mainconfig.myip;	this->type = RAD_LISTEN_ACCT;	this->port = auth_port + 1;	if (listen_bind(this) < 0) {		radlog(L_CONS|L_ERR, "There appears to be another RADIUS server running on the accounting port %d", this->port);		free(this);		return -1;	}	*last = this;	return 0;}#ifndef RADIUS_CONFIG#define RADIUS_CONFIG "radiusd.conf"#endifCONF_SECTION *read_radius_conf_file(void){	char buffer[256];	CONF_SECTION *cs;	struct stat statbuf;	if (stat(radius_dir, &statbuf) < 0) {		radlog(L_ERR|L_CONS, "Errors reading %s: %s",		       radius_dir, strerror(errno));		return NULL;	}	if ((statbuf.st_mode & S_IWOTH) != 0) {		radlog(L_ERR|L_CONS, "Configuration directory %s is globally writable.  Refusing to start due to insecure configuration.",		       radius_dir);	  return NULL;	}	if (0 && (statbuf.st_mode & S_IROTH) != 0) {		radlog(L_ERR|L_CONS, "Configuration directory %s is globally readable.  Refusing to start due to insecure configuration.",		       radius_dir);		return NULL;	}	/* Lets go look for the new configuration files */	snprintf(buffer, sizeof(buffer), "%.200s/%.50s", radius_dir, RADIUS_CONFIG);	if ((cs = conf_read(NULL, 0, buffer, NULL)) == NULL) {		return NULL;	}	/*	 *	This allows us to figure out where, relative to	 *	radiusd.conf, the other configuration files exist.	 */	cf_section_parse(cs, NULL, server_config);	/* Initialize the dictionary */	DEBUG2("read_config_files:  reading dictionary");	if (dict_init(radius_dir, RADIUS_DICTIONARY) != 0) {		radlog(L_ERR|L_CONS, "Errors reading dictionary: %s",				librad_errstr);		cf_section_free(&cs);		return NULL;	}	return cs;}/* *	Read config files. * *	This function can ONLY be called from the main server process. */int read_mainconfig(int reload){	struct rlimit core_limits;	static int old_debug_level = -1;	char buffer[1024];	CONF_SECTION *cs, *oldcs;	rad_listen_t *listener;	RADCLIENT *c, *tail;	if (!reload) {		radlog(L_INFO, "Starting - reading configuration files ...");	} else {		radlog(L_INFO, "Reloading configuration files.");	}	/* First read radiusd.conf */	DEBUG2("reread_config:  reading radiusd.conf");	if ((cs = read_radius_conf_file()) == NULL) {		if (debug_flag ||		    (radlog_dir == NULL)) {			radlog(L_ERR|L_CONS, "Errors reading radiusd.conf");		} else {			radlog(L_ERR|L_CONS, "Errors reading %s/radiusd.conf: For more information, please read the tail end of %s", radius_dir, mainconfig.log_file);		}		return -1;	}	/*	 *	Free the old configuration items, and replace them	 *	with the new ones.	 *	 *	Note that where possible, we do atomic switch-overs,	 *	to ensure that the pointers are always valid.	 */	oldcs = mainconfig.config;	mainconfig.config = cs;	cf_section_free(&oldcs);	/* old-style naslist file */	snprintf(buffer, sizeof(buffer), "%.200s/%.50s", radius_dir, RADIUS_NASLIST);	DEBUG2("read_config_files:  reading naslist");	if (read_naslist_file(buffer) < 0) {		radlog(L_ERR|L_CONS, "Errors reading naslist");		return -1;	}	/* old-style clients file */	snprintf(buffer, sizeof(buffer), "%.200s/%.50s", radius_dir, RADIUS_CLIENTS);	DEBUG2("read_config_files:  reading clients");	if (read_clients_file(buffer) < 0) {		radlog(L_ERR|L_CONS, "Errors reading clients");		return -1;	}	/*	 *	Add to that, the *new* list of clients.	 */	snprintf(buffer, sizeof(buffer), "%.200s/%.50s", radius_dir, RADIUS_CONFIG);	c = generate_clients(buffer, mainconfig.config);	if (!c) {		return -1;	}	/*	 *	The new list of clients takes precedence over the old one.	 */	for (tail = c; tail->next != NULL; tail = tail->next) {	  /* do nothing */	}	tail->next = mainconfig.clients;	mainconfig.clients = c;		/* old-style realms file */	snprintf(buffer, sizeof(buffer), "%.200s/%.50s", radius_dir, RADIUS_REALMS);	DEBUG2("read_config_files:  reading realms");	if (read_realms_file(buffer) < 0) {		radlog(L_ERR|L_CONS, "Errors reading realms");		return -1;	}	/*	 *	If there isn't any realms it isn't fatal..	 */	snprintf(buffer, sizeof(buffer), "%.200s/%.50s", radius_dir, RADIUS_CONFIG);	if (generate_realms(buffer) < 0) {		return -1;	}	/*	 *  Register the %{config:section.subsection} xlat function.	 */	xlat_register("config", xlat_config, NULL);	/*	 *	Set the libraries debugging flag to whatever the main	 *	flag is.  Note that on a SIGHUP, to turn the debugging	 *	off, we do other magic.	 *	 *	Increase the debug level, if the configuration file	 *	says to, OR, if we're decreasing the debug from what it	 *	was before, allow that, too.	 */	if ((mainconfig.debug_level > debug_flag) ||	    (mainconfig.debug_level <= old_debug_level)) {	  debug_flag = mainconfig.debug_level;	}	librad_debug = debug_flag;	old_debug_level = mainconfig.debug_level;	/*	 *  Go update our behaviour, based on the configuration	 *  changes.	 */	/*  Get the current maximum for core files.  */	if (getrlimit(RLIMIT_CORE, &core_limits) < 0) {		radlog(L_ERR|L_CONS, "Failed to get current core limit:  %s", strerror(errno));		exit(1);	}	if (mainconfig.allow_core_dumps) {		if (setrlimit(RLIMIT_CORE, &core_limits) < 0) {			radlog(L_ERR|L_CONS, "Cannot update core dump limit: %s",					strerror(errno));			exit(1);			/*			 *  If we're running as a daemon, and core			 *  dumps are enabled, log that information.			 */		} else if ((core_limits.rlim_cur != 0) && !debug_flag)			radlog(L_INFO|L_CONS, "Core dumps are enabled.");	} else if (!debug_flag) {		/*		 *  Not debugging.  Set the core size to zero, to		 *  prevent security breaches.  i.e. People		 *  reading passwords from the 'core' file.		 */		struct rlimit limits;		limits.rlim_cur = 0;		limits.rlim_max = core_limits.rlim_max;		if (setrlimit(RLIMIT_CORE, &limits) < 0) {			radlog(L_ERR|L_CONS, "Cannot disable core dumps: %s",					strerror(errno));			exit(1);		}	}	/*	 * 	The first time around, ensure that we can write to the	 *	log directory.	 */	if (!reload) {		/*		 *	We need root to do mkdir() and chown(), so we		 *	do this before giving up root.		 */		radlogdir_iswritable(mainconfig.uid_name);	}	switch_users();#ifdef HAVE_SYS_PRCTL_H#ifdef HAVE_PR_SET_DUMPABLE	if (mainconfig.allow_core_dumps) {		if (prctl(PR_SET_DUMPABLE, 1) < 0) {			radlog(L_ERR|L_CONS,"Cannot enable core dumps: prctl(PR_SET_DUMPABLE) failed: '%s'",			       strerror(errno));		}	}#endif#endif	/*	 *	Sanity check the configuration for internal	 *	consistency.	 */	if (mainconfig.reject_delay > mainconfig.cleanup_delay) {		mainconfig.reject_delay = mainconfig.cleanup_delay;	}	/*	 *	Initialize the old "bind_address" and "port", first.	 */	listener = NULL;	if (old_listen_init(&listener) < 0) {		exit(1);	}	/*	 *	Read the list of listeners.	 */	snprintf(buffer, sizeof(buffer), "%.200s/radiusd.conf", radius_dir);	if (listen_init(buffer, &listener) < 0) {		exit(1);	}	if (!listener) {		radlog(L_ERR|L_CONS, "Server is not configured to listen on any ports.  Exiting.");		exit(1);	}	listen_free(mainconfig.listen);	mainconfig.listen = listener;	return 0;}/* *	Free the configuration. */int free_mainconfig(void){	/*	 *	Clean up the configuration data	 *	structures.	 */	cf_section_free(&mainconfig.config);	realm_free(mainconfig.realms);	clients_free(mainconfig.clients);	read_naslist_file(NULL);	rl_free();	listen_free(mainconfig.listen);	paircompare_builtin_free();	xlat_free();	dict_free();	lt_dlexit();	return 0;}

⌨️ 快捷键说明

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