mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-10-12 16:32:01 -05:00
Use IPAdmin rather than raw python-ldap in ipactl
Add a new init argument, ldap_uri, to IPAdmin to make this possible. Part of the work for: https://fedorahosted.org/freeipa/ticket/2660
This commit is contained in:
1 parent
fe138877d3
commit
29a02a3530
2 files changed
+33
-42
No files matched your search
+30
-40
@@ -19,33 +19,20 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
try:
|
import os
|
||||||
import os
|
import json
|
||||||
from ipaserver.install import service, installutils
|
|
||||||
from ipapython import services as ipaservices
|
|
||||||
from ipaserver.install.dsinstance import config_dirname, realm_to_serverid
|
|
||||||
from ipaserver.install.installutils import is_ipa_configured, ScriptError
|
|
||||||
from ipapython.ipautil import wait_for_open_ports, wait_for_open_socket
|
|
||||||
from ipalib import api, errors
|
|
||||||
from ipapython import sysrestore
|
|
||||||
from ipapython import config
|
|
||||||
from ipapython import dogtag
|
|
||||||
from ipapython.dn import DN
|
|
||||||
import ldap
|
|
||||||
import ldap.sasl
|
|
||||||
import ldapurl
|
|
||||||
import socket
|
|
||||||
import json
|
|
||||||
except ImportError:
|
|
||||||
print >> sys.stderr, """\
|
|
||||||
There was a problem importing one of the required Python modules. The
|
|
||||||
error was:
|
|
||||||
|
|
||||||
%s
|
import ldapurl
|
||||||
""" % sys.exc_value
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
SASL_EXTERNAL = ldap.sasl.sasl({}, 'EXTERNAL')
|
from ipaserver.install import service, installutils
|
||||||
|
from ipaserver.install.dsinstance import config_dirname, realm_to_serverid
|
||||||
|
from ipaserver.install.installutils import is_ipa_configured, ScriptError
|
||||||
|
from ipaserver.ipaldap import IPAdmin
|
||||||
|
from ipalib import api, errors
|
||||||
|
from ipapython.ipautil import wait_for_open_ports, wait_for_open_socket
|
||||||
|
from ipapython import services as ipaservices
|
||||||
|
from ipapython import config, dogtag
|
||||||
|
from ipapython.dn import DN
|
||||||
|
|
||||||
class IpactlError(ScriptError):
|
class IpactlError(ScriptError):
|
||||||
pass
|
pass
|
||||||
@@ -127,30 +114,33 @@ def get_config(dirsrv):
|
|||||||
if lurl.urlscheme == 'ldapi':
|
if lurl.urlscheme == 'ldapi':
|
||||||
wait_for_open_socket(lurl.hostport, timeout=api.env.startup_timeout)
|
wait_for_open_socket(lurl.hostport, timeout=api.env.startup_timeout)
|
||||||
else:
|
else:
|
||||||
(host,port) = lurl.hostport.split(':')
|
(host, port) = lurl.hostport.split(':')
|
||||||
wait_for_open_ports(host, [int(port)], timeout=api.env.startup_timeout)
|
wait_for_open_ports(host, [int(port)], timeout=api.env.startup_timeout)
|
||||||
con = ldap.initialize(api.env.ldap_uri)
|
con = IPAdmin(ldap_uri=api.env.ldap_uri)
|
||||||
con.sasl_interactive_bind_s('', SASL_EXTERNAL)
|
con.do_external_bind()
|
||||||
res = con.search_st(str(base),
|
res, truncated = con.find_entries(
|
||||||
ldap.SCOPE_SUBTREE,
|
filter=srcfilter,
|
||||||
filterstr=srcfilter,
|
attrs_list=attrs,
|
||||||
attrlist=attrs,
|
base_dn=base,
|
||||||
timeout=10)
|
scope=con.SCOPE_SUBTREE,
|
||||||
except ldap.SERVER_DOWN, e:
|
time_limit=10)
|
||||||
|
if truncated:
|
||||||
|
raise errors.LimitsExceeded()
|
||||||
|
except errors.NetworkError:
|
||||||
# LSB status code 3: program is not running
|
# LSB status code 3: program is not running
|
||||||
raise IpactlError("Failed to get list of services to probe status:\n" +
|
raise IpactlError("Failed to get list of services to probe status:\n" +
|
||||||
"Directory Server is stopped", 3)
|
"Directory Server is stopped", 3)
|
||||||
except ldap.NO_SUCH_OBJECT:
|
except errors.NotFound:
|
||||||
masters_list = []
|
masters_list = []
|
||||||
dn = DN(('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'), api.env.basedn)
|
dn = DN(('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'), api.env.basedn)
|
||||||
attrs = ['cn']
|
attrs = ['cn']
|
||||||
try:
|
try:
|
||||||
entries = con.search_s(str(dn), ldap.SCOPE_ONELEVEL, attrlist=attrs)
|
entries = con.get_entries(dn, con.SCOPE_ONELEVEL, attrs_list=attrs)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
masters_list.append("No master found because of error: %s" % str(e))
|
masters_list.append("No master found because of error: %s" % str(e))
|
||||||
else:
|
else:
|
||||||
for dn,master_entry in entries:
|
for dn, master_entry in entries:
|
||||||
masters_list.append(master_entry.get('cn', [None])[0])
|
masters_list.append(master_entry.single_value('cn'))
|
||||||
|
|
||||||
masters = "\n".join(masters_list)
|
masters = "\n".join(masters_list)
|
||||||
|
|
||||||
@@ -163,8 +153,8 @@ def get_config(dirsrv):
|
|||||||
svc_list = []
|
svc_list = []
|
||||||
|
|
||||||
for entry in res:
|
for entry in res:
|
||||||
name = entry[1]['cn'][0]
|
name = entry.single_value('cn')
|
||||||
for p in entry[1]['ipaConfigString']:
|
for p in entry['ipaConfigString']:
|
||||||
if p.startswith('startOrder '):
|
if p.startswith('startOrder '):
|
||||||
order = p.split()[1]
|
order = p.split()[1]
|
||||||
svc_list.append([order, name])
|
svc_list.append([order, name])
|
||||||
|
|||||||
@@ -1558,7 +1558,7 @@ class IPAdmin(LDAPClient):
|
|||||||
|
|
||||||
def __init__(self, host='', port=389, cacert=None, debug=None, ldapi=False,
|
def __init__(self, host='', port=389, cacert=None, debug=None, ldapi=False,
|
||||||
realm=None, protocol=None, force_schema_updates=True,
|
realm=None, protocol=None, force_schema_updates=True,
|
||||||
start_tls=False):
|
start_tls=False, ldap_uri=None):
|
||||||
self.conn = None
|
self.conn = None
|
||||||
log_mgr.get_logger(self, True)
|
log_mgr.get_logger(self, True)
|
||||||
if debug and debug.lower() == "on":
|
if debug and debug.lower() == "on":
|
||||||
@@ -1573,7 +1573,8 @@ class IPAdmin(LDAPClient):
|
|||||||
self.realm = realm
|
self.realm = realm
|
||||||
self.suffixes = {}
|
self.suffixes = {}
|
||||||
|
|
||||||
ldap_uri = self.__get_ldap_uri(protocol or self.__guess_protocol())
|
if not ldap_uri:
|
||||||
|
ldap_uri = self.__get_ldap_uri(protocol or self.__guess_protocol())
|
||||||
|
|
||||||
LDAPClient.__init__(self, ldap_uri)
|
LDAPClient.__init__(self, ldap_uri)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user