Merge branch 'master' of github.com:web2py/web2py
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import sys
|
||||
import logging
|
||||
|
||||
try:
|
||||
import ldap
|
||||
|
||||
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
|
||||
except Exception as detail:
|
||||
logging.error('missing ldap, try "pip install python-ldap"')
|
||||
raise detail
|
||||
|
||||
|
||||
def freeipa_auth(server, basedn, group):
|
||||
"""
|
||||
custom module for freeIPA auth in web2py
|
||||
server: freeipa ip
|
||||
base_dn: root of ldap tree containing user & groups
|
||||
group: group authing user has to be a member of
|
||||
|
||||
"""
|
||||
logger = logging.getLogger("web2py.auth.freeipa_auth")
|
||||
|
||||
def freeipa_auth_aux(username, password):
|
||||
if password == "" or username == "":
|
||||
logger.warning("blank username / password not allowed")
|
||||
return False
|
||||
|
||||
bind_user_base = "uid=" + username + ",cn=users," + basedn
|
||||
ldap_filter = "memberof=cn=" + group + ",cn=groups," + basedn
|
||||
|
||||
session = ldap.initialize("ldaps://" + server + ":636")
|
||||
try:
|
||||
session.bind_s(bind_user_base, password)
|
||||
except ldap.LDAPError:
|
||||
import traceback
|
||||
|
||||
logger.warning("[%s] Error in ldap bind" % str(username))
|
||||
logger.debug(traceback.format_exc())
|
||||
return False
|
||||
|
||||
try:
|
||||
result = session.search_s(
|
||||
bind_user_base, ldap.SCOPE_SUBTREE, ldap_filter, ["member"]
|
||||
)
|
||||
session.unbind()
|
||||
except ldap.LDAPError as detail:
|
||||
logger.warning(
|
||||
"ldap_auth: searc %s for %s resulted in %s: %s\n"
|
||||
% (bind_user_base, ldap_filter, exc_type, exc_value)
|
||||
)
|
||||
|
||||
try:
|
||||
if result == list():
|
||||
return False
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
return freeipa_auth_aux
|
||||
+16
-6
@@ -596,12 +596,12 @@ class Scheduler(threading.Thread):
|
||||
utc_time(bool): do all datetime calculations assuming UTC as the
|
||||
timezone. Remember to pass `start_time` and `stop_time` to tasks
|
||||
accordingly
|
||||
|
||||
use_spawn(bool): use spawn for subprocess (only useable with python3)
|
||||
"""
|
||||
|
||||
def __init__(self, db, tasks=None, migrate=True,
|
||||
worker_name=None, group_names=None, heartbeat=HEARTBEAT,
|
||||
max_empty_runs=0, discard_results=False, utc_time=False):
|
||||
max_empty_runs=0, discard_results=False, utc_time=False, use_spawn=False):
|
||||
|
||||
threading.Thread.__init__(self)
|
||||
self.setDaemon(True)
|
||||
@@ -639,6 +639,7 @@ class Scheduler(threading.Thread):
|
||||
current._scheduler = self
|
||||
|
||||
self.define_tables(db, migrate=migrate)
|
||||
self.use_spawn = use_spawn
|
||||
|
||||
def execute(self, task):
|
||||
"""Start the background process.
|
||||
@@ -649,10 +650,19 @@ class Scheduler(threading.Thread):
|
||||
Returns:
|
||||
a `TaskReport` object
|
||||
"""
|
||||
outq = multiprocessing.Queue()
|
||||
retq = multiprocessing.Queue(maxsize=1)
|
||||
self.process = p = \
|
||||
multiprocessing.Process(target=executor, args=(retq, task, outq))
|
||||
outq = None
|
||||
retq = None
|
||||
if (self.use_spawn and not PY2):
|
||||
ctx = multiprocessing.get_context('spawn')
|
||||
outq = ctx.Queue()
|
||||
retq = ctx.Queue(maxsize=1)
|
||||
sel.process = p = ctx.Process(target=executor, args=(retq, task, outq))
|
||||
else:
|
||||
outq = multiprocessing.Queue()
|
||||
retq = multiprocessing.Queue(maxsize=1)
|
||||
self.process = p = \
|
||||
multiprocessing.Process(target=executor, args=(retq, task, outq))
|
||||
|
||||
self.process_queues = (retq, outq)
|
||||
|
||||
logger.debug(' task starting')
|
||||
|
||||
Reference in New Issue
Block a user