Example #1
0
 def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
     assert isinstance(dn, DN)
     if options.get('ip_address') and dns_container_exists(ldap):
         parts = keys[-1].split('.')
         host = parts[0]
         domain = unicode('.'.join(parts[1:]))
         check_reverse = not options.get('no_reverse', False)
         add_records_for_host_validation('ip_address',
                 DNSName(host),
                 DNSName(domain).make_absolute(),
                 options['ip_address'],
                 check_forward=True,
                 check_reverse=check_reverse)
     if not options.get('force', False) and not 'ip_address' in options:
         util.validate_host_dns(self.log, keys[-1])
     if 'locality' in entry_attrs:
         entry_attrs['l'] = entry_attrs['locality']
     entry_attrs['cn'] = keys[-1]
     entry_attrs['serverhostname'] = keys[-1].split('.', 1)[0]
     if not entry_attrs.get('userpassword', False) and not options.get('random', False):
         entry_attrs['krbprincipalname'] = 'host/%s@%s' % (
             keys[-1], self.api.env.realm
         )
         if 'krbprincipalaux' not in entry_attrs['objectclass']:
             entry_attrs['objectclass'].append('krbprincipalaux')
         if 'krbprincipal' not in entry_attrs['objectclass']:
             entry_attrs['objectclass'].append('krbprincipal')
     else:
         if 'krbprincipalaux' in entry_attrs['objectclass']:
             entry_attrs['objectclass'].remove('krbprincipalaux')
         if 'krbprincipal' in entry_attrs['objectclass']:
             entry_attrs['objectclass'].remove('krbprincipal')
     if options.get('random'):
         entry_attrs['userpassword'] = ipa_generate_password(characters=host_pwd_chars)
         # save the password so it can be displayed in post_callback
         setattr(context, 'randompassword', entry_attrs['userpassword'])
     certs = options.get('usercertificate', [])
     certs_der = map(x509.normalize_certificate, certs)
     for cert in certs_der:
         x509.verify_cert_subject(ldap, keys[-1], cert)
     entry_attrs['usercertificate'] = certs_der
     entry_attrs['managedby'] = dn
     entry_attrs['objectclass'].append('ieee802device')
     entry_attrs['objectclass'].append('ipasshhost')
     update_krbticketflags(ldap, entry_attrs, attrs_list, options, False)
     if 'krbticketflags' in entry_attrs:
         entry_attrs['objectclass'].append('krbticketpolicyaux')
     return dn
Example #2
0
 def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
     assert isinstance(dn, DN)
     if options.get('ip_address') and dns_container_exists(ldap):
         parts = keys[-1].split('.')
         host = parts[0]
         domain = unicode('.'.join(parts[1:]))
         check_reverse = not options.get('no_reverse', False)
         add_records_for_host_validation('ip_address', host, domain,
                 options['ip_address'],
                 check_forward=True,
                 check_reverse=check_reverse)
     if not options.get('force', False) and not 'ip_address' in options:
         util.validate_host_dns(self.log, keys[-1])
     if 'locality' in entry_attrs:
         entry_attrs['l'] = entry_attrs['locality']
         del entry_attrs['locality']
     entry_attrs['cn'] = keys[-1]
     entry_attrs['serverhostname'] = keys[-1].split('.', 1)[0]
     if 'userpassword' not in entry_attrs and not options.get('random', False):
         entry_attrs['krbprincipalname'] = 'host/%s@%s' % (
             keys[-1], self.api.env.realm
         )
         if 'krbprincipalaux' not in entry_attrs['objectclass']:
             entry_attrs['objectclass'].append('krbprincipalaux')
         if 'krbprincipal' not in entry_attrs['objectclass']:
             entry_attrs['objectclass'].append('krbprincipal')
     else:
         if 'krbprincipalaux' in entry_attrs['objectclass']:
             entry_attrs['objectclass'].remove('krbprincipalaux')
         if 'krbprincipal' in entry_attrs['objectclass']:
             entry_attrs['objectclass'].remove('krbprincipal')
     if options.get('random'):
         entry_attrs['userpassword'] = ipa_generate_password(characters=host_pwd_chars)
         # save the password so it can be displayed in post_callback
         setattr(context, 'randompassword', entry_attrs['userpassword'])
     cert = options.get('usercertificate')
     if cert:
         cert = x509.normalize_certificate(cert)
         x509.verify_cert_subject(ldap, keys[-1], cert)
         entry_attrs['usercertificate'] = cert
     entry_attrs['managedby'] = dn
     entry_attrs['objectclass'].append('ieee802device')
     entry_attrs['objectclass'].append('ipasshhost')
     return dn
Example #3
0
    def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
        assert isinstance(dn, DN)
        (service, hostname, realm) = split_principal(keys[-1])
        if service.lower() == 'host' and not options['force']:
            raise errors.HostService()

        try:
            hostresult = api.Command['host_show'](hostname)['result']
        except errors.NotFound:
            raise errors.NotFound(
                reason=_("The host '%s' does not exist to add a service to.") %
                    hostname)

        self.obj.validate_ipakrbauthzdata(entry_attrs)

        certs = options.get('usercertificate', [])
        certs_der = [x509.normalize_certificate(c) for c in certs]
        for dercert in certs_der:
            x509.verify_cert_subject(ldap, hostname, dercert)
        entry_attrs['usercertificate'] = certs_der

        if not options.get('force', False):
             # We know the host exists if we've gotten this far but we
             # really want to discourage creating services for hosts that
             # don't exist in DNS.
             util.validate_host_dns(self.log, hostname)
        if not 'managedby' in entry_attrs:
            entry_attrs['managedby'] = hostresult['dn']

        # Enforce ipaKrbPrincipalAlias to aid case-insensitive searches
        # as krbPrincipalName/krbCanonicalName are case-sensitive in Kerberos
        # schema
        entry_attrs['ipakrbprincipalalias'] = keys[-1]

        # Objectclass ipakrbprincipal providing ipakrbprincipalalias is not in
        # in a list of default objectclasses, add it manually
        entry_attrs['objectclass'].append('ipakrbprincipal')

        update_krbticketflags(ldap, entry_attrs, attrs_list, options, False)

        return dn
Example #4
0
    def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
        assert isinstance(dn, DN)
        (service, hostname, realm) = split_principal(keys[-1])
        if service.lower() == 'host' and not options['force']:
            raise errors.HostService()

        try:
            hostresult = api.Command['host_show'](hostname)['result']
        except errors.NotFound:
            raise errors.NotFound(
                reason=_("The host '%s' does not exist to add a service to.") %
                    hostname)

        self.obj.validate_ipakrbauthzdata(entry_attrs)

        cert = options.get('usercertificate')
        if cert:
            dercert = x509.normalize_certificate(cert)
            x509.verify_cert_subject(ldap, hostname, dercert)
            entry_attrs['usercertificate'] = dercert

        if not options.get('force', False):
             # We know the host exists if we've gotten this far but we
             # really want to discourage creating services for hosts that
             # don't exist in DNS.
             util.validate_host_dns(self.log, hostname)
        if not 'managedby' in entry_attrs:
            entry_attrs['managedby'] = hostresult['dn']

        # Enforce ipaKrbPrincipalAlias to aid case-insensitive searches
        # as krbPrincipalName/krbCanonicalName are case-sensitive in Kerberos
        # schema
        entry_attrs['ipakrbprincipalalias'] = keys[-1]

        # Objectclass ipakrbprincipal providing ipakrbprincipalalias is not in
        # in a list of default objectclasses, add it manually
        entry_attrs['objectclass'].append('ipakrbprincipal')

        update_krbticketflags(ldap, entry_attrs, attrs_list, options, False)

        return dn