示例#1
0
def execShutdownModules():
	"""Execute all shutdown-capable modules
		Input: none
		Output: none
	"""
	for moduleName, module in loadedModules.items():
		if module.shutdownCapable:
			try:
				module['shutdown_funct']()
			# catch all exceptions, report them to user and shutdown server
			except:
				misc.printException()
				misc.quit('Can not execute shutdown function in module "%s"' % moduleName, 1)
示例#2
0
def loadModules():
	"""Load all configured modules. Shutdown server if loading unsuccessful.
		Input: none
		Output: none
	"""
	global loadedModules
	global authModules
	global acctModules
	if not modulesConfig:
		return
	
	# try to import modules
	for moduleName, tokens in modulesConfig.items():
		debug ('Loading module: ', moduleName)
		mod = BsdRadiusModule(moduleName)
		try:
			if (tokens['startup_module']):
				mod['startup_module'] = __import__(tokens['startup_module'])
				mod['startup_funct'] = loadFunction(mod['startup_module'], tokens['startup_function'])
				mod.startupCapable = True
			if (tokens['authorization_module']):
				mod['authz_module'] = __import__(tokens['authorization_module'])
				mod['authz_funct'] = loadFunction(mod['authz_module'], tokens['authorization_function'])
				mod.authorizationCapable = True
			if (tokens['authentication_module']):
				mod['authc_module'] = __import__(tokens['authentication_module'])
				mod['authc_funct'] = loadFunction(mod['authc_module'], tokens['authentication_function'])
				mod.authenticationCapable = True
			if (tokens['accounting_module']):
				mod['acct_module'] = __import__(tokens['accounting_module'])
				mod['acct_funct'] = loadFunction(mod['acct_module'], tokens['accounting_function'])
				mod.accountingCapable = True
			if (tokens['shutdown_module']):
				mod['shutdown_module'] = __import__(tokens['shutdown_module'])
				mod['shutdown_funct'] = loadFunction(mod['shutdown_module'], tokens['shutdown_function'])
				mod.shutdownCapable = True
		# catch all exceptions, report them to user and shutdown server
		except:
			misc.printException()
			misc.quit('Can not load BSD Radius server modules', 1)
		else:
			loadedModules[moduleName] = mod
			debug (mod)
	
	info ('Setting order of authorization modules')
	# set module executing order in authorization and accounting phases
	authModuleOrder = main_config['AUTHORIZATION']['modules'].split(',')
	for moduleName in authModuleOrder:
		moduleName = moduleName.strip()
		if moduleName not in loadedModules:
			misc.quit('Module "%s" not loaded' % moduleName, 1)
		# make list of authorization module references
		if not loadedModules[moduleName].authorizationCapable:
			misc.quit('Module "%s" not authorization capable' % moduleName, 1)
		authModules.append(loadedModules[moduleName])
	info ('Setting order of accounting modules')
	acctModuleOrder = main_config['ACCOUNTING']['modules'].split(',')
	for moduleName in acctModuleOrder:
		moduleName = moduleName.strip()
		if moduleName not in loadedModules:
			misc.quit('Module "%s" not loaded' % moduleName, 1)
		if not loadedModules[moduleName].accountingCapable:
			misc.quit('Module "%s" not accounting capable' % moduleName, 1)
		acctModules.append(loadedModules[moduleName])
示例#3
0
    if 'log_client' in srvConf and srvConf['log_client']:
        # restrict all threads from logging
        info('--- Enabling threads logging restrictions ---')
        logging.restrictThreads = True
        # add this (main) thread to unrestricted threads to allow print log messages
        misc.addUnrestrictedThread()

info('--- Reading configuration ---')
# get config file path
if 'PATHS' in confCli and 'config_file' in confCli['PATHS']:
    Config.configFiles[0] = confCli['PATHS']['config_file']
# read config file
Config.readFiles = Config.main_config.read(Config.configFiles)
# check if all neccessary files are read
if Config.configFiles != Config.readFiles:
    misc.quit("Can not read required configuration files", 1)

# overwrite configfile attributes with command line ones
confCli.applyOptions()

# print config
main_config = Config.main_config
debug(main_config)

# fork and run as daemon
if not main_config['SERVER']['foreground']:
    info('Daemonizing...')
    childProcId = os.fork()
    if childProcId != 0:
        sys.exit(0)
示例#4
0
	if 'log_client' in srvConf and srvConf['log_client']:
		# restrict all threads from logging
		info ('--- Enabling threads logging restrictions ---')
		logging.restrictThreads = True
		# add this (main) thread to unrestricted threads to allow print log messages
		misc.addUnrestrictedThread()

info ('--- Reading configuration ---')
# get config file path
if 'PATHS' in confCli and 'config_file' in confCli['PATHS']:
	Config.configFiles[0] = confCli['PATHS']['config_file']
# read config file
Config.readFiles = Config.main_config.read(Config.configFiles)
# check if all neccessary files are read
if Config.configFiles != Config.readFiles:
	misc.quit("Can not read required configuration files", 1)

# overwrite configfile attributes with command line ones
confCli.applyOptions()

# print config
main_config = Config.main_config
debug (main_config)

# fork and run as daemon
if not main_config['SERVER']['foreground']:
	info ('Daemonizing...')
	childProcId = os.fork()
	if childProcId != 0:
		sys.exit(0)