mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Convert remaining installer code to LDAPEntry API.
This commit is contained in:
committed by
Petr Viktorin
parent
a5f322cb7b
commit
08051f1651
@@ -62,7 +62,7 @@ try:
|
||||
conn.connect(ccache=ccache)
|
||||
try:
|
||||
syslog.syslog(syslog.LOG_NOTICE, "Updating certificate for %s" % nickname)
|
||||
(entry_dn, entry_attrs) = conn.get_entry(dn, ['usercertificate'])
|
||||
entry_attrs = conn.get_entry(dn, ['usercertificate'])
|
||||
cert = entry_attrs['usercertificate'][0]
|
||||
cert = base64.b64encode(cert)
|
||||
print x509.make_pem(cert)
|
||||
|
||||
@@ -69,13 +69,15 @@ try:
|
||||
conn = ldap2(shared_instance=False, ldap_uri=api.env.ldap_uri)
|
||||
conn.connect(ccache=ccache)
|
||||
try:
|
||||
(entry_dn, entry_attrs) = conn.get_entry(dn, ['usercertificate'])
|
||||
entry_attrs = conn.get_entry(dn, ['usercertificate'])
|
||||
entry_attrs['usercertificate'] = cert
|
||||
conn.update_entry(dn, entry_attrs)
|
||||
conn.update_entry(entry_attrs)
|
||||
except errors.NotFound:
|
||||
entry_attrs = dict(objectclass=['top', 'pkiuser', 'nscontainer'],
|
||||
usercertificate=cert)
|
||||
conn.add_entry(dn, entry_attrs)
|
||||
entry_attrs = conn.make_entry(
|
||||
dn,
|
||||
objectclass=['top', 'pkiuser', 'nscontainer'],
|
||||
usercertificate=[cert])
|
||||
conn.add_entry(entry_attrs)
|
||||
except errors.EmptyModlist:
|
||||
pass
|
||||
conn.disconnect()
|
||||
|
||||
@@ -58,13 +58,15 @@ while attempts < 10:
|
||||
conn = ldap2(shared_instance=False, ldap_uri=api.env.ldap_uri)
|
||||
conn.connect(ccache=ccache)
|
||||
try:
|
||||
(entry_dn, entry_attrs) = conn.get_entry(dn, ['usercertificate'])
|
||||
entry_attrs = conn.get_entry(dn, ['usercertificate'])
|
||||
entry_attrs['usercertificate'] = dercert
|
||||
conn.update_entry(dn, entry_attrs)
|
||||
conn.update_entry(entry_attrs)
|
||||
except errors.NotFound:
|
||||
entry_attrs = dict(objectclass=['top', 'pkiuser', 'nscontainer'],
|
||||
usercertificate=dercert)
|
||||
conn.add_entry(dn, entry_attrs)
|
||||
entry_attrs = conn.make_entry(
|
||||
dn,
|
||||
objectclass=['top', 'pkiuser', 'nscontainer'],
|
||||
usercertificate=[dercert])
|
||||
conn.add_entry(entry_attrs)
|
||||
except errors.EmptyModlist:
|
||||
pass
|
||||
updated = True
|
||||
|
||||
@@ -118,13 +118,13 @@ def set_and_check_netbios_name(netbios_name, unattended):
|
||||
cur_netbios_name = None
|
||||
gen_netbios_name = None
|
||||
reset_netbios_name = False
|
||||
dom_dn = None
|
||||
entry = None
|
||||
|
||||
try:
|
||||
(dom_dn, entry) = api.Backend.ldap2.get_entry(DN(('cn', api.env.domain),
|
||||
api.env.container_cifsdomains,
|
||||
ipautil.realm_to_suffix(api.env.realm)),
|
||||
[flat_name_attr])
|
||||
entry = api.Backend.ldap2.get_entry(
|
||||
DN(('cn', api.env.domain), api.env.container_cifsdomains,
|
||||
ipautil.realm_to_suffix(api.env.realm)),
|
||||
[flat_name_attr])
|
||||
except errors.NotFound:
|
||||
# trust not configured
|
||||
pass
|
||||
@@ -160,7 +160,7 @@ def set_and_check_netbios_name(netbios_name, unattended):
|
||||
if not netbios_name:
|
||||
gen_netbios_name = adtrustinstance.make_netbios_name(api.env.domain)
|
||||
|
||||
if dom_dn:
|
||||
if entry is not None:
|
||||
# Fix existing trust configuration
|
||||
print "Trust is configured but no NetBIOS domain name found, " \
|
||||
"setting it now."
|
||||
|
||||
@@ -73,7 +73,7 @@ def get_entry(dn, conn):
|
||||
"""
|
||||
entry = None
|
||||
try:
|
||||
(dn, entry) = conn.get_entry(dn)
|
||||
entry = conn.get_entry(dn)
|
||||
except errors.NotFound:
|
||||
pass
|
||||
return entry
|
||||
@@ -143,8 +143,8 @@ def main():
|
||||
print "Updating Directory Server failed."
|
||||
retval = 1
|
||||
else:
|
||||
mod = {'nsslapd-pluginenabled': 'on'}
|
||||
conn.update_entry(compat_dn, mod)
|
||||
entry['nsslapd-pluginenabled'] = ['on']
|
||||
conn.update_entry(entry)
|
||||
except errors.ExecutionError, lde:
|
||||
print "An error occurred while talking to the server."
|
||||
print lde
|
||||
@@ -174,8 +174,8 @@ def main():
|
||||
else:
|
||||
print "Disabling plugin"
|
||||
|
||||
mod = {'nsslapd-pluginenabled': 'off'}
|
||||
conn.update_entry(compat_dn, mod)
|
||||
entry['nsslapd-pluginenabled'] = ['off']
|
||||
conn.update_entry(entry)
|
||||
except errors.DatabaseError, dbe:
|
||||
print "An error occurred while talking to the server."
|
||||
print dbe
|
||||
|
||||
@@ -75,7 +75,7 @@ def get_entry(dn, conn):
|
||||
"""
|
||||
entry = None
|
||||
try:
|
||||
(dn, entry) = conn.get_entry(dn)
|
||||
entry = conn.get_entry(dn)
|
||||
except errors.NotFound:
|
||||
pass
|
||||
return entry
|
||||
@@ -165,20 +165,18 @@ def main():
|
||||
elif entry.get('nsslapd-pluginenabled', [''])[0].lower() == 'off':
|
||||
print "Enabling plugin"
|
||||
# Already configured, just enable the plugin
|
||||
mod = {'nsslapd-pluginenabled': 'on'}
|
||||
conn.update_entry(nis_config_dn, mod)
|
||||
entry['nsslapd-pluginenabled'] = ['on']
|
||||
conn.update_entry(entry)
|
||||
else:
|
||||
print "Plugin already Enabled"
|
||||
retval = 2
|
||||
|
||||
elif args[0] == "disable":
|
||||
try:
|
||||
mod = {'nsslapd-pluginenabled': 'off'}
|
||||
conn.update_entry(nis_config_dn, mod)
|
||||
except errors.NotFound:
|
||||
print "Plugin is already disabled"
|
||||
retval = 2
|
||||
except errors.EmptyModlist:
|
||||
entry = conn.get_entry(nis_config_dn, ['nsslapd-pluginenabled'])
|
||||
entry['nsslapd-pluginenabled'] = ['off']
|
||||
conn.update_entry(entry)
|
||||
except (errors.NotFound, errors.EmptyModlist):
|
||||
print "Plugin is already disabled"
|
||||
retval = 2
|
||||
except errors.LDAPError, lde:
|
||||
|
||||
@@ -561,10 +561,10 @@ def set_subject_in_config(realm_name, dm_password, suffix, subject_base):
|
||||
except errors.ExecutionError, e:
|
||||
root_logger.critical("Could not connect to the Directory Server on %s" % realm_name)
|
||||
raise e
|
||||
(dn, entry_attrs) = conn.get_ipa_config()
|
||||
entry_attrs = conn.get_ipa_config()
|
||||
if 'ipacertificatesubjectbase' not in entry_attrs:
|
||||
mod = {'ipacertificatesubjectbase': str(subject_base)}
|
||||
conn.update_entry(dn, mod)
|
||||
entry_attrs['ipacertificatesubjectbase'] = [str(subject_base)]
|
||||
conn.update_entry(entry_attrs)
|
||||
conn.disconnect()
|
||||
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ def get_config(dirsrv):
|
||||
except Exception, e:
|
||||
masters_list.append("No master found because of error: %s" % str(e))
|
||||
else:
|
||||
for dn, master_entry in entries:
|
||||
for master_entry in entries:
|
||||
masters_list.append(master_entry.single_value['cn'])
|
||||
|
||||
masters = "\n".join(masters_list)
|
||||
|
||||
Reference in New Issue
Block a user