mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
ipaldap: merge external_bind into LDAPClient
* Rename do_external_bind to external_bind * Remove user_name argument in external_bind() and always set it to effective user name https://fedorahosted.org/freeipa/ticket/6461 Reviewed-By: Martin Basti <mbasti@redhat.com> Reviewed-By: Jan Cholasta <jcholast@redhat.com>
This commit is contained in:
parent
de58a5c605
commit
60e38ecc7f
@ -166,7 +166,7 @@ def get_config(dirsrv):
|
|||||||
(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 = IPAdmin(ldap_uri=api.env.ldap_uri)
|
con = IPAdmin(ldap_uri=api.env.ldap_uri)
|
||||||
con.do_external_bind()
|
con.external_bind()
|
||||||
res = con.get_entries(
|
res = con.get_entries(
|
||||||
base,
|
base,
|
||||||
filter=srcfilter,
|
filter=srcfilter,
|
||||||
|
@ -1084,11 +1084,11 @@ class LDAPClient(object):
|
|||||||
self.conn.simple_bind_s(
|
self.conn.simple_bind_s(
|
||||||
bind_dn, bind_password, server_controls, client_controls)
|
bind_dn, bind_password, server_controls, client_controls)
|
||||||
|
|
||||||
def external_bind(self, user_name, server_controls=None,
|
def external_bind(self, server_controls=None, client_controls=None):
|
||||||
client_controls=None):
|
|
||||||
"""
|
"""
|
||||||
Perform SASL bind operation using the SASL EXTERNAL mechanism.
|
Perform SASL bind operation using the SASL EXTERNAL mechanism.
|
||||||
"""
|
"""
|
||||||
|
user_name = pwd.getpwuid(os.geteuid()).pw_name
|
||||||
with self.error_handler():
|
with self.error_handler():
|
||||||
auth_tokens = ldap.sasl.external(user_name)
|
auth_tokens = ldap.sasl.external(user_name)
|
||||||
self._flush_schema()
|
self._flush_schema()
|
||||||
@ -1634,9 +1634,6 @@ class IPAdmin(LDAPClient):
|
|||||||
def do_sasl_gssapi_bind(self):
|
def do_sasl_gssapi_bind(self):
|
||||||
self.gssapi_bind()
|
self.gssapi_bind()
|
||||||
|
|
||||||
def do_external_bind(self, user_name=None):
|
|
||||||
self.external_bind(user_name)
|
|
||||||
|
|
||||||
def do_bind(self, dm_password="", autobind=AUTOBIND_AUTO):
|
def do_bind(self, dm_password="", autobind=AUTOBIND_AUTO):
|
||||||
if dm_password:
|
if dm_password:
|
||||||
self.simple_bind(bind_dn=DIRMAN_DN, bind_password=dm_password)
|
self.simple_bind(bind_dn=DIRMAN_DN, bind_password=dm_password)
|
||||||
@ -1644,8 +1641,7 @@ class IPAdmin(LDAPClient):
|
|||||||
if autobind != AUTOBIND_DISABLED and os.getegid() == 0 and self.ldapi:
|
if autobind != AUTOBIND_DISABLED and os.getegid() == 0 and self.ldapi:
|
||||||
try:
|
try:
|
||||||
# autobind
|
# autobind
|
||||||
pw_name = pwd.getpwuid(os.geteuid()).pw_name
|
self.external_bind()
|
||||||
self.do_external_bind(pw_name)
|
|
||||||
return
|
return
|
||||||
except errors.NotFound:
|
except errors.NotFound:
|
||||||
if autobind == AUTOBIND_ENABLED:
|
if autobind == AUTOBIND_ENABLED:
|
||||||
|
@ -398,7 +398,7 @@ class DogtagInstance(service.Service):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
conn = ipaldap.IPAdmin(self.fqdn, ldapi=True, realm=self.realm)
|
conn = ipaldap.IPAdmin(self.fqdn, ldapi=True, realm=self.realm)
|
||||||
conn.do_external_bind('root')
|
conn.external_bind()
|
||||||
|
|
||||||
entry_attrs = conn.get_entry(self.admin_dn, ['usercertificate'])
|
entry_attrs = conn.get_entry(self.admin_dn, ['usercertificate'])
|
||||||
admin_cert = entry_attrs.get('usercertificate')[0]
|
admin_cert = entry_attrs.get('usercertificate')[0]
|
||||||
|
@ -169,7 +169,7 @@ def create_ds_user():
|
|||||||
|
|
||||||
def get_domain_level(api=api):
|
def get_domain_level(api=api):
|
||||||
conn = ipaldap.IPAdmin(ldapi=True, realm=api.env.realm)
|
conn = ipaldap.IPAdmin(ldapi=True, realm=api.env.realm)
|
||||||
conn.do_external_bind('root')
|
conn.external_bind()
|
||||||
|
|
||||||
dn = DN(('cn', 'Domain Level'),
|
dn = DN(('cn', 'Domain Level'),
|
||||||
('cn', 'ipa'), ('cn', 'etc'), api.env.basedn)
|
('cn', 'ipa'), ('cn', 'etc'), api.env.basedn)
|
||||||
@ -417,7 +417,7 @@ class DsInstance(service.Service):
|
|||||||
|
|
||||||
# Always connect to self over ldapi
|
# Always connect to self over ldapi
|
||||||
conn = ipaldap.IPAdmin(self.fqdn, ldapi=True, realm=self.realm)
|
conn = ipaldap.IPAdmin(self.fqdn, ldapi=True, realm=self.realm)
|
||||||
conn.do_external_bind('root')
|
conn.external_bind()
|
||||||
repl = replication.ReplicationManager(self.realm,
|
repl = replication.ReplicationManager(self.realm,
|
||||||
self.fqdn,
|
self.fqdn,
|
||||||
self.dm_password, conn=conn)
|
self.dm_password, conn=conn)
|
||||||
@ -1258,7 +1258,7 @@ class DsInstance(service.Service):
|
|||||||
|
|
||||||
# Connect to self over ldapi as Directory Manager and configure SSL
|
# Connect to self over ldapi as Directory Manager and configure SSL
|
||||||
conn = ipaldap.IPAdmin(self.fqdn, ldapi=True, realm=self.realm)
|
conn = ipaldap.IPAdmin(self.fqdn, ldapi=True, realm=self.realm)
|
||||||
conn.do_external_bind('root')
|
conn.external_bind()
|
||||||
|
|
||||||
mod = [(ldap.MOD_REPLACE, "nsSSLClientAuth", "allowed"),
|
mod = [(ldap.MOD_REPLACE, "nsSSLClientAuth", "allowed"),
|
||||||
(ldap.MOD_REPLACE, "nsSSL3Ciphers", "default"),
|
(ldap.MOD_REPLACE, "nsSSL3Ciphers", "default"),
|
||||||
|
@ -362,8 +362,7 @@ class Backup(admintool.AdminTool):
|
|||||||
realm=api.env.realm)
|
realm=api.env.realm)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pw_name = pwd.getpwuid(os.geteuid()).pw_name
|
self._conn.external_bind()
|
||||||
self._conn.do_external_bind(pw_name)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log.error("Unable to bind to LDAP server %s: %s" %
|
self.log.error("Unable to bind to LDAP server %s: %s" %
|
||||||
(self._conn.host, e))
|
(self._conn.host, e))
|
||||||
|
@ -441,8 +441,7 @@ class Restore(admintool.AdminTool):
|
|||||||
realm=api.env.realm)
|
realm=api.env.realm)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pw_name = pwd.getpwuid(os.geteuid()).pw_name
|
self._conn.external_bind()
|
||||||
self._conn.do_external_bind(pw_name)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise admintool.ScriptError('Unable to bind to LDAP server: %s'
|
raise admintool.ScriptError('Unable to bind to LDAP server: %s'
|
||||||
% e)
|
% e)
|
||||||
|
@ -51,7 +51,7 @@ UPDATES_DIR=paths.UPDATES_DIR
|
|||||||
UPDATE_SEARCH_TIME_LIMIT = 30 # seconds
|
UPDATE_SEARCH_TIME_LIMIT = 30 # seconds
|
||||||
|
|
||||||
|
|
||||||
def connect(ldapi=False, realm=None, fqdn=None, dm_password=None, pw_name=None):
|
def connect(ldapi=False, realm=None, fqdn=None, dm_password=None):
|
||||||
"""Create a connection for updates"""
|
"""Create a connection for updates"""
|
||||||
if ldapi:
|
if ldapi:
|
||||||
conn = ipaldap.IPAdmin(ldapi=True, realm=realm, decode_attrs=False)
|
conn = ipaldap.IPAdmin(ldapi=True, realm=realm, decode_attrs=False)
|
||||||
@ -64,7 +64,7 @@ def connect(ldapi=False, realm=None, fqdn=None, dm_password=None, pw_name=None):
|
|||||||
elif os.getegid() == 0:
|
elif os.getegid() == 0:
|
||||||
try:
|
try:
|
||||||
# autobind
|
# autobind
|
||||||
conn.do_external_bind(pw_name)
|
conn.external_bind()
|
||||||
except errors.NotFound:
|
except errors.NotFound:
|
||||||
# Fall back
|
# Fall back
|
||||||
conn.do_sasl_gssapi_bind()
|
conn.do_sasl_gssapi_bind()
|
||||||
|
@ -1740,7 +1740,7 @@ class CAReplicationManager(ReplicationManager):
|
|||||||
def __init__(self, realm, hostname):
|
def __init__(self, realm, hostname):
|
||||||
# Always connect to self over ldapi
|
# Always connect to self over ldapi
|
||||||
conn = ipaldap.IPAdmin(hostname, ldapi=True, realm=realm)
|
conn = ipaldap.IPAdmin(hostname, ldapi=True, realm=realm)
|
||||||
conn.do_external_bind('root')
|
conn.external_bind()
|
||||||
super(CAReplicationManager, self).__init__(
|
super(CAReplicationManager, self).__init__(
|
||||||
realm, hostname, None, port=DEFAULT_PORT, conn=conn)
|
realm, hostname, None, port=DEFAULT_PORT, conn=conn)
|
||||||
self.db_suffix = DN(('o', 'ipaca'))
|
self.db_suffix = DN(('o', 'ipaca'))
|
||||||
|
@ -6,7 +6,6 @@ from __future__ import print_function
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import pickle
|
import pickle
|
||||||
import pwd
|
|
||||||
import random
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
@ -991,7 +990,7 @@ def uninstall_check(installer):
|
|||||||
ldapi=True,
|
ldapi=True,
|
||||||
realm=api.env.realm
|
realm=api.env.realm
|
||||||
)
|
)
|
||||||
conn.do_external_bind(pwd.getpwuid(os.geteuid()).pw_name)
|
conn.external_bind()
|
||||||
api.Backend.ldap2.connect(autobind=True)
|
api.Backend.ldap2.connect(autobind=True)
|
||||||
domain_level = dsinstance.get_domain_level(api)
|
domain_level = dsinstance.get_domain_level(api)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -28,7 +28,6 @@ Backend plugin for LDAP.
|
|||||||
# everything except the CrudBackend methods, where dn is part of the entry dict.
|
# everything except the CrudBackend methods, where dn is part of the entry dict.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pwd
|
|
||||||
|
|
||||||
import ldap as _ldap
|
import ldap as _ldap
|
||||||
|
|
||||||
@ -181,9 +180,7 @@ class ldap2(CrudBackend, LDAPClient):
|
|||||||
client_controls=clientctrls)
|
client_controls=clientctrls)
|
||||||
elif autobind != AUTOBIND_DISABLED and os.getegid() == 0 and ldapi:
|
elif autobind != AUTOBIND_DISABLED and os.getegid() == 0 and ldapi:
|
||||||
try:
|
try:
|
||||||
pw_name = pwd.getpwuid(os.geteuid()).pw_name
|
client.external_bind(server_controls=serverctrls,
|
||||||
client.external_bind(pw_name,
|
|
||||||
server_controls=serverctrls,
|
|
||||||
client_controls=clientctrls)
|
client_controls=clientctrls)
|
||||||
except errors.NotFound:
|
except errors.NotFound:
|
||||||
if autobind == AUTOBIND_ENABLED:
|
if autobind == AUTOBIND_ENABLED:
|
||||||
|
Loading…
Reference in New Issue
Block a user