From f7e70e56e31da8d333aa750b82960c464220a98f Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 3 Jul 2015 21:09:17 +0800 Subject: [PATCH] modify sudo conn timeout bug --- jperm/views.py | 6 ++++-- jumpserver/api.py | 3 --- juser/views.py | 8 ++++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/jperm/views.py b/jperm/views.py index c2bf03a18..4f38f09b9 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -264,8 +264,10 @@ def unicode2str(unicode_list): def sudo_ldap_add(user_group, user_runas, asset_groups_select, cmd_groups_select): - if not LDAP_ENABLE: - return True + if LDAP_ENABLE: + ldap_conn = LDAPMgmt(LDAP_HOST_URL, LDAP_BASE_DN, LDAP_ROOT_DN, LDAP_ROOT_PW) + else: + return assets = [] cmds = [] diff --git a/jumpserver/api.py b/jumpserver/api.py index fa98cc350..4a3a6bde7 100644 --- a/jumpserver/api.py +++ b/jumpserver/api.py @@ -101,9 +101,6 @@ if LDAP_ENABLE: LDAP_BASE_DN = CONF.get('ldap', 'base_dn') LDAP_ROOT_DN = CONF.get('ldap', 'root_dn') LDAP_ROOT_PW = CONF.get('ldap', 'root_pw') - ldap_conn = LDAPMgmt(LDAP_HOST_URL, LDAP_BASE_DN, LDAP_ROOT_DN, LDAP_ROOT_PW) -else: - ldap_conn = None def md5_crypt(string): diff --git a/juser/views.py b/juser/views.py index 054de5e49..22a08499b 100644 --- a/juser/views.py +++ b/juser/views.py @@ -123,6 +123,10 @@ def server_del_user(username): def ldap_add_user(username, ldap_pwd): + if LDAP_ENABLE: + ldap_conn = LDAPMgmt(LDAP_HOST_URL, LDAP_BASE_DN, LDAP_ROOT_DN, LDAP_ROOT_PW) + else: + return user_dn = "uid=%s,ou=People,%s" % (username, LDAP_BASE_DN) password_sha512 = gen_sha512(gen_rand_pwd(6), ldap_pwd) user = User.objects.filter(username=username) @@ -155,6 +159,10 @@ def ldap_add_user(username, ldap_pwd): def ldap_del_user(username): + if LDAP_ENABLE: + ldap_conn = LDAPMgmt(LDAP_HOST_URL, LDAP_BASE_DN, LDAP_ROOT_DN, LDAP_ROOT_PW) + else: + return user_dn = "uid=%s,ou=People,%s" % (username, LDAP_BASE_DN) group_dn = "cn=%s,ou=Group,%s" % (username, LDAP_BASE_DN) sudo_dn = 'cn=%s,ou=Sudoers,%s' % (username, LDAP_BASE_DN)