@ -122,9 +122,9 @@ class ConfigReader():
if self . _cfg is not None :
if self . _cfg is not None :
return self . _cfg . merge_section ( * args , * * kwargs )
return self . _cfg . merge_section ( * args , * * kwargs )
def options ( self , * args ) :
def options ( self , section , onlyOwn = False ) :
if self . _cfg is not None :
if self . _cfg is not None :
return self . _cfg . options ( * args )
return self . _cfg . options ( section , onlyOwn )
return { }
return { }
def get ( self , sec , opt , raw = False , vars = { } ) :
def get ( self , sec , opt , raw = False , vars = { } ) :
@ -297,23 +297,35 @@ class DefinitionInitConfigReader(ConfigReader):
self . _create_unshared ( self . _file )
self . _create_unshared ( self . _file )
return SafeConfigParserWithIncludes . read ( self . _cfg , self . _file )
return SafeConfigParserWithIncludes . read ( self . _cfg , self . _file )
def getOptions ( self , pOpts ):
def getOptions ( self , pOpts , all = False ):
# overwrite static definition options with init values, supplied as
# overwrite static definition options with init values, supplied as
# direct parameters from jail-config via action[xtra1="...", xtra2=...]:
# direct parameters from jail-config via action[xtra1="...", xtra2=...]:
if self . _initOpts :
if not pOpts :
if not pOpts :
pOpts = dict ( )
pOpts = dict ( )
if self . _initOpts :
pOpts = _merge_dicts ( pOpts , self . _initOpts )
pOpts = _merge_dicts ( pOpts , self . _initOpts )
self . _opts = ConfigReader . getOptions (
self . _opts = ConfigReader . getOptions (
self , " Definition " , self . _configOpts , pOpts )
self , " Definition " , self . _configOpts , pOpts )
self . _pOpts = pOpts
self . _pOpts = pOpts
if self . has_section ( " Init " ) :
if self . has_section ( " Init " ) :
for opt in self . options ( " Init " ) :
# get only own options (without options from default):
v = self . get ( " Init " , opt )
getopt = lambda opt : self . get ( " Init " , opt )
if not opt . startswith ( ' known/ ' ) and opt != ' __name__ ' :
for opt in self . options ( " Init " , onlyOwn = True ) :
if opt == ' __name__ ' : continue
v = None
if not opt . startswith ( ' known/ ' ) :
if v is None : v = getopt ( opt )
self . _initOpts [ ' known/ ' + opt ] = v
self . _initOpts [ ' known/ ' + opt ] = v
if not opt in self . _initOpts :
if opt not in self . _initOpts :
if v is None : v = getopt ( opt )
self . _initOpts [ opt ] = v
self . _initOpts [ opt ] = v
if all and self . has_section ( " Definition " ) :
# merge with all definition options (and options from default),
# bypass already converted option (so merge only new options):
for opt in self . options ( " Definition " ) :
if opt == ' __name__ ' or opt in self . _opts : continue
self . _opts [ opt ] = self . get ( " Definition " , opt )
def _convert_to_boolean ( self , value ) :
def _convert_to_boolean ( self , value ) :
return value . lower ( ) in ( " 1 " , " yes " , " true " , " on " )
return value . lower ( ) in ( " 1 " , " yes " , " true " , " on " )
@ -336,12 +348,12 @@ class DefinitionInitConfigReader(ConfigReader):
def getCombined ( self , ignore = ( ) ) :
def getCombined ( self , ignore = ( ) ) :
combinedopts = self . _opts
combinedopts = self . _opts
ignore = set ( ignore ) . copy ( )
if self . _initOpts :
if self . _initOpts :
combinedopts = _merge_dicts ( self . _ opts, self . _initOpts )
combinedopts = _merge_dicts ( combined opts, self . _initOpts )
if not len ( combinedopts ) :
if not len ( combinedopts ) :
return { }
return { }
# ignore conditional options:
# ignore conditional options:
ignore = set ( ignore ) . copy ( )
for n in combinedopts :
for n in combinedopts :
cond = SafeConfigParserWithIncludes . CONDITIONAL_RE . match ( n )
cond = SafeConfigParserWithIncludes . CONDITIONAL_RE . match ( n )
if cond :
if cond :