590d18
From c626fcb564404d41cd06db83a299e97959fa3c4e Mon Sep 17 00:00:00 2001
590d18
From: David Kupka <dkupka@redhat.com>
590d18
Date: Thu, 16 Jul 2015 10:15:36 +0200
590d18
Subject: [PATCH] migration: Use api.env variables.
590d18
590d18
Use api.env.basedn instead of anonymously accessing LDAP to get base DN.
590d18
Use api.env.basedn instead of searching filesystem for ldapi socket.
590d18
590d18
https://fedorahosted.org/freeipa/ticket/4953
590d18
590d18
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
590d18
Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
590d18
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
590d18
---
590d18
 install/migration/migration.py | 33 +++++----------------------------
590d18
 1 file changed, 5 insertions(+), 28 deletions(-)
590d18
590d18
diff --git a/install/migration/migration.py b/install/migration/migration.py
590d18
index b629b1c9ff7bd58f1ea64e4c2b2433428a939f28..8c440175a0358b01acba227ea3179318af50fa32 100644
590d18
--- a/install/migration/migration.py
590d18
+++ b/install/migration/migration.py
590d18
@@ -22,14 +22,13 @@ Password migration script
590d18
 
590d18
 import cgi
590d18
 import errno
590d18
-import glob
590d18
 from wsgiref.util import request_uri
590d18
 
590d18
 from ipapython.ipa_log_manager import root_logger
590d18
 from ipapython.ipautil import get_ipa_basedn
590d18
 from ipapython.dn import DN
590d18
 from ipapython.ipaldap import IPAdmin
590d18
-from ipalib import errors
590d18
+from ipalib import errors, create_api
590d18
 from ipaplatform.paths import paths
590d18
 
590d18
 
590d18
@@ -45,23 +44,6 @@ def get_ui_url(environ):
590d18
     return full_url[:index] + "/ipa/ui"
590d18
 
590d18
 
590d18
-def get_base_dn(ldap_uri):
590d18
-    """
590d18
-    Retrieve LDAP server base DN.
590d18
-    """
590d18
-    try:
590d18
-        conn = IPAdmin(ldap_uri=ldap_uri)
590d18
-        conn.do_simple_bind(DN(), '')
590d18
-        base_dn = get_ipa_basedn(conn)
590d18
-    except Exception, e:
590d18
-        root_logger.error('migration context search failed: %s' % e)
590d18
-        return ''
590d18
-    finally:
590d18
-        conn.unbind()
590d18
-
590d18
-    return base_dn
590d18
-
590d18
-
590d18
 def bind(ldap_uri, base_dn, username, password):
590d18
     if not base_dn:
590d18
         root_logger.error('migration unable to get base dn')
590d18
@@ -90,16 +72,11 @@ def application(environ, start_response):
590d18
     if not form_data.has_key('username') or not form_data.has_key('password'):
590d18
         return wsgi_redirect(start_response, 'invalid.html')
590d18
 
590d18
-    slapd_sockets = glob.glob(paths.ALL_SLAPD_INSTANCE_SOCKETS)
590d18
-    if slapd_sockets:
590d18
-        ldap_uri = 'ldapi://%s' % slapd_sockets[0].replace('/', '%2f')
590d18
-    else:
590d18
-        ldap_uri = 'ldaps://localhost:636'
590d18
-
590d18
-    base_dn = get_base_dn(ldap_uri)
590d18
-
590d18
+    # API object only for configuration, finalize() not needed
590d18
+    api = create_api(mode=None)
590d18
+    api.bootstrap(context='server', in_server=True)
590d18
     try:
590d18
-        bind(ldap_uri, base_dn,
590d18
+        bind(api.env.ldap_uri, api.env.basedn,
590d18
              form_data['username'].value, form_data['password'].value)
590d18
     except IOError as err:
590d18
         if err.errno == errno.EPERM:
590d18
-- 
590d18
2.4.3
590d18