Esempio n. 1
0
 def __init__(self, cfg_file_name, dbh, do_reload=True):
     self._dbh = dbh
     self._do_reload = do_reload
     I.Server.__init__(self)
     path, name = os.path.split(cfg_file_name)
     if len(name) < 1 or not os.path.isdir(path):
         raise ICore.ConfigError("Bad config file specified", cfg_file_name)
     self._config_file = cfg_file_name
     # enshure server is here and works with actual config file
     self._reload_config()
Esempio n. 2
0
    def getOptions(self, current):
        try:
            return [
                I.ServerOption(*pair)
                for pair in cfgfile.parse(self._config_file)
                if pair[0] in self._supported_options
            ]

        except IOError:
            raise ICore.ConfigError("Failed to read configuration file",
                                    self._config_file)
Esempio n. 3
0
    def reGenerate(self, opts, template_path):
        if not self.enable_deploy:
            raise I.KadminException(-1, "Failed to create new database",
                                    "This function was disabled")

        password = opts.get('password')
        if not password:
            raise C.ConfigError('Mandatory parameter not supplied', 'password')

        _reset_configuration(opts, template_path)
        _run_command(["kdb5_util", "create", "-s", "-P", password],
                     "Failed to create database")
        self.realm = None
Esempio n. 4
0
 def setOptions(self, opts, current):
     try:
         new_opts = [self._convert_option(opt) for opt in opts]
         # save all extra options
         old_opts = [
             pair for pair in cfgfile.parse(self._config_file)
             if pair[0] not in self._supported_options
         ]
         new_opts += old_opts
         cfgfile.gen(self._config_file, new_opts)
     except IOError:
         raise ICore.ConfigError("Failed to alter configuration file",
                                 self._config_file)
     self._reload_config()
Esempio n. 5
0
 def changeOptions(self, opts, current):
     try:
         if len(opts) < 1:
             return
         opts_dict = dict((self._convert_option(opt) for opt in opts))
         new_opts = [
             pair for pair in cfgfile.parse(self._config_file)
             if pair[0] not in opts_dict
         ]
         new_opts.extend(opts_dict.iteritems())
         cfgfile.gen(self._config_file, new_opts)
     except IOError:
         raise ICore.ConfigError("Failed to alter configuration file",
                                 self._config_file)
     self._reload_config()
Esempio n. 6
0
def _ptr_record(ip, fqdn, zone):
    """Make PTR record from ip, host fqdn and reverse zone name.

    zone is in form of [[b.]c.]d.in-addr.arpa (without a terminating dot)
    """
    octets = ip.split('.')
    octets.reverse()
    if len(octets) != 4:
        raise DNS.ConfigError('Invalud IPv4 adress', ip)

    n = zone.count('.')
    if n < 2:
        raise C.ConfigError('Invalid reverse zone name', zone)
    elif n > 4:
        name = octets[0] + '.'
    else:
        name = '.'.join(octets[:(5 - n)]) + '.'

    return DNS.Record(name + zone, DNS.RecordType.PTR, fqdn, -1, -1)
Esempio n. 7
0
def _reset_configuration(opts, template_path, backup=True):
    try:
        path = opts['path']
    except KeyError:
        path = opts['path'] = '/var/lib/kerberos/krb5kdc'

    def _kc(filename):
        return os.path.join(path, filename)

    def _kt(filename):
        return os.path.join(template_path, filename + '.template')

    files = [('/etc/krb5.conf', _kt('krb5.conf')),
             (_kc('kdc.conf'), _kt('kdc.conf')),
             (_kc('kadm5.acl'), _kt('kadm5.acl'))]

    try:
        for n, t in files:
            gen_config_from_file(n, t, opts, backup)
    except KeyError, e:
        raise C.ConfigError("Mandatory option not specified.", e.args[0])