This file is indexed.

/usr/share/pyshared/ldap/controls.py is in python-ldap 2.3.13-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
"""
controls.py - support classes for LDAP controls

See http://www.python-ldap.org/ for details.

\$Id: controls.py,v 1.7 2009/07/26 11:09:58 stroeder Exp $

Description:
The ldap.controls module provides LDAPControl classes.
Each class provides support for a certain control.
"""

from ldap import __version__

__all__ = [
  'LDAPControl',
]


from types import ClassType

import _ldap,ldap


class LDAPControl:
  """
  Base class for all LDAP controls
  """

  def __init__(self,controlType,criticality,controlValue=None,encodedControlValue=None):
    self.controlType = controlType
    self.criticality = criticality
    self.controlValue = controlValue or self.decodeControlValue(encodedControlValue)

  def __repr__(self):
    return '%s(%s,%s,%s)' % (self.__class__.__name__,self.controlType,self.criticality,self.controlValue)

  def encodeControlValue(self,value):
    return value

  def decodeControlValue(self,encodedValue):
    return encodedValue

  def getEncodedTuple(self):
    return (self.controlType,self.criticality,self.encodeControlValue(self.controlValue))


class BooleanControl(LDAPControl):
  """
  Base class for simple controls with booelan control value

  In this base class controlValue has to be passed as
  boolean type (True/False or 1/0).
  """
  boolean2ber = { 1:'\x01\x01\xFF', 0:'\x01\x01\x00' }
  ber2boolean = { '\x01\x01\xFF':1, '\x01\x01\x00':0 }

  def encodeControlValue(self,value):
    return self.boolean2ber[int(value)]

  def decodeControlValue(self,encodedValue):
    return self.ber2boolean[encodedValue]


class SimplePagedResultsControl(LDAPControl):
  """
  LDAP Control Extension for Simple Paged Results Manipulation

  see RFC 2696
  """
  controlType = ldap.LDAP_CONTROL_PAGE_OID

  def __init__(self,controlType,criticality,controlValue=None,encodedControlValue=None):
    LDAPControl.__init__(self,ldap.LDAP_CONTROL_PAGE_OID,criticality,controlValue,encodedControlValue)

  def encodeControlValue(self,value):
    size,cookie = value
    return _ldap.encode_page_control(size,cookie)

  def decodeControlValue(self,encodedValue):
    size,cookie = _ldap.decode_page_control(encodedValue)
    return size,cookie


class MatchedValuesControl(LDAPControl):
  """
  LDAP Matched Values control, as defined in RFC 3876

  from ldap.controls import MatchedValuesControl
  control = MatchedValuesControl(criticality, filter)
  """
  
  controlType = ldap.LDAP_CONTROL_VALUESRETURNFILTER
  
  def __init__(self, criticality, controlValue=None):
    LDAPControl.__init__(self, self.controlType, criticality, controlValue, None) 

  def encodeControlValue(self, value):
    return _ldap.encode_valuesreturnfilter_control(value)


def EncodeControlTuples(ldapControls):
  """
  Return list of readily encoded 3-tuples which can be directly
  passed to C module _ldap
  """
  if ldapControls is None:
    return None
  else:
    result = [
      c.getEncodedTuple()
      for c in ldapControls
    ]
    return result


def DecodeControlTuples(ldapControlTuples):
  """
  Return list of readily encoded 3-tuples which can be directly
  passed to C module _ldap
  """
  return [
    knownLDAPControls.get(controlType,LDAPControl)
      (controlType,criticality,encodedControlValue=encodedControlValue)
    for controlType,criticality,encodedControlValue in ldapControlTuples or []
  ]

# Build a dictionary of known LDAPControls
knownLDAPControls = {}
for symbol_name in dir():
  c = eval(symbol_name)
  if type(c) is ClassType and hasattr(c,'controlType'):
    knownLDAPControls[c.controlType] = c