Ejemplo n.º 1
0
    def callback(self,cb_id,challenge,prompt,defresult):
        """ The callback method will be called by the sasl_bind_s()
        method several times. Each time it will provide the id, which
        tells us what kind of information is requested (the CB_ ...
        constants above). The challenge might be a short (english) text
        or some binary string, from which the return value is calculated.
        The prompt argument is always a human-readable description string;
        The defresult is a default value provided by the sasl library

        Currently, we do not use the challenge and prompt information, and
        return only information which is stored in the self.cb_value_dict
        cb_value_dictionary. Note that the current callback interface is not very
        useful for writing generic sasl GUIs, which would need to know all
        the questions to ask, before the answers are returned to the sasl
        lib (in contrast to one question at a time)."""
        
        # The following print command might be useful for debugging
        # new sasl mechanisms. So it is left here
        cb_result = self.cb_value_dict.get(cb_id,defresult) or ''
        if __debug__:
          if _trace_level>=1:
            _trace_file.write("*** id=%d, challenge=%s, prompt=%s, defresult=%s\n-> %s\n" % (
                cb_id, challenge, prompt, repr(defresult), repr(self.cb_value_dict.get(cb_result))
              ))
        return cb_result
Ejemplo n.º 2
0
    def callback(self, cb_id, challenge, prompt, defresult):
        """ The callback method will be called by the sasl_bind_s()
        method several times. Each time it will provide the id, which
        tells us what kind of information is requested (the CB_ ...
        constants above). The challenge might be a short (english) text
        or some binary string, from which the return value is calculated.
        The prompt argument is always a human-readable description string;
        The defresult is a default value provided by the sasl library

        Currently, we do not use the challenge and prompt information, and
        return only information which is stored in the self.cb_value_dict
        cb_value_dictionary. Note that the current callback interface is not very
        useful for writing generic sasl GUIs, which would need to know all
        the questions to ask, before the answers are returned to the sasl
        lib (in contrast to one question at a time)."""

        # The following print command might be useful for debugging
        # new sasl mechanisms. So it is left here
        cb_result = self.cb_value_dict.get(cb_id, defresult) or ''
        if __debug__:
            if _trace_level >= 1:
                _trace_file.write(
                    "*** id=%d, challenge=%s, prompt=%s, defresult=%s\n-> %s\n"
                    % (cb_id, challenge, prompt, repr(defresult),
                       repr(self.cb_value_dict.get(cb_result))))
        return cb_result
Ejemplo n.º 3
0
def _ldap_function_call(func, *args, **kwargs):
    """
    Wrapper function which locks calls to func with via
    module-wide ldap_lock
    """
    if __debug__:
        if _trace_level >= 1:
            _trace_file.write('*** %s.%s (%s,%s)\n' % (
                '_ldap', repr(func),
                repr(args), repr(kwargs)
            ))
            if _trace_level >= 3:
                traceback.print_stack(limit=_trace_stack_limit, file=_trace_file)
    _ldap_module_lock.acquire()
    try:
        try:
            result = func(*args, **kwargs)
        finally:
            _ldap_module_lock.release()
    except LDAPError as e:
        if __debug__ and _trace_level >= 2:
            _trace_file.write('=> LDAPError: %s\n' % (str(e)))
        raise
    if __debug__ and _trace_level >= 2:
        if result != None and result != (None, None):
            _trace_file.write('=> result: %s\n' % (repr(result)))
    return result
Ejemplo n.º 4
0
def _ldap_function_call(func,*args,**kwargs):
  """
  Wrapper function which locks calls to func with via
  module-wide ldap_lock
  """
  if __debug__:
    if _trace_level>=1:
      _trace_file.write('*** %s.%s (%s,%s)\n' % (
        '_ldap',repr(func),
        repr(args),repr(kwargs)
      ))
      if _trace_level>=3:
        traceback.print_stack(limit=_trace_stack_limit,file=_trace_file)
  _ldap_module_lock.acquire()
  try:
    try:
      result = func(*args,**kwargs)
    finally:
      _ldap_module_lock.release()
  except LDAPError,e:
    if __debug__ and _trace_level>=2:
      _trace_file.write('=> LDAPError: %s\n' % (str(e)))
    raise
Ejemplo n.º 5
0
      ))
      if _trace_level>=3:
        traceback.print_stack(limit=_trace_stack_limit,file=_trace_file)
  _ldap_module_lock.acquire()
  try:
    try:
      result = func(*args,**kwargs)
    finally:
      _ldap_module_lock.release()
  except LDAPError,e:
    if __debug__ and _trace_level>=2:
      _trace_file.write('=> LDAPError: %s\n' % (str(e)))
    raise
  if __debug__ and _trace_level>=2:
    if result!=None and result!=(None,None):
      _trace_file.write('=> result: %s\n' % (repr(result)))
  return result


def initialize(uri,trace_level=0,trace_file=sys.stdout,trace_stack_limit=None):
  """
  Return LDAPObject instance by opening LDAP connection to
  LDAP host specified by LDAP URL
  
  Parameters:
  uri
        LDAP URL containing at least connection scheme and hostport,
        e.g. ldap://localhost:389
  trace_level
        If non-zero a trace output of LDAP calls is generated.
  trace_file