removed unneeded files

This commit is contained in:
Kai Kriegel 2021-12-17 15:01:29 +01:00
parent 95e167008a
commit 518b290f6c
1565 changed files with 0 additions and 252948 deletions

8
.idea/.gitignore generated vendored
View File

@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -1,22 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="false" level="WARNING" enabled_by_default="false">
<option name="ignoredPackages">
<value>
<list size="1">
<item index="0" class="java.lang.String" itemvalue="RPi.GPIO" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N802" />
<option value="N806" />
</list>
</option>
</inspection_tool>
</profile>
</component>

View File

@ -1,6 +0,0 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

10
.idea/ldapbodge.iml generated
View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.9 (ldapbodge)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

4
.idea/misc.xml generated
View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (ldapbodge)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated
View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ldapbodge.iml" filepath="$PROJECT_DIR$/.idea/ldapbodge.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated
View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -1,241 +0,0 @@
<#
.Synopsis
Activate a Python virtual environment for the current PowerShell session.
.Description
Pushes the python executable for a virtual environment to the front of the
$Env:PATH environment variable and sets the prompt to signify that you are
in a Python virtual environment. Makes use of the command line switches as
well as the `pyvenv.cfg` file values present in the virtual environment.
.Parameter VenvDir
Path to the directory that contains the virtual environment to activate. The
default value for this is the parent of the directory that the Activate.ps1
script is located within.
.Parameter Prompt
The prompt prefix to display when this virtual environment is activated. By
default, this prompt is the name of the virtual environment folder (VenvDir)
surrounded by parentheses and followed by a single space (ie. '(.venv) ').
.Example
Activate.ps1
Activates the Python virtual environment that contains the Activate.ps1 script.
.Example
Activate.ps1 -Verbose
Activates the Python virtual environment that contains the Activate.ps1 script,
and shows extra information about the activation as it executes.
.Example
Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv
Activates the Python virtual environment located in the specified location.
.Example
Activate.ps1 -Prompt "MyPython"
Activates the Python virtual environment that contains the Activate.ps1 script,
and prefixes the current prompt with the specified string (surrounded in
parentheses) while the virtual environment is active.
.Notes
On Windows, it may be required to enable this Activate.ps1 script by setting the
execution policy for the user. You can do this by issuing the following PowerShell
command:
PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
For more information on Execution Policies:
https://go.microsoft.com/fwlink/?LinkID=135170
#>
Param(
[Parameter(Mandatory = $false)]
[String]
$VenvDir,
[Parameter(Mandatory = $false)]
[String]
$Prompt
)
<# Function declarations --------------------------------------------------- #>
<#
.Synopsis
Remove all shell session elements added by the Activate script, including the
addition of the virtual environment's Python executable from the beginning of
the PATH variable.
.Parameter NonDestructive
If present, do not remove this function from the global namespace for the
session.
#>
function global:deactivate ([switch]$NonDestructive) {
# Revert to original values
# The prior prompt:
if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) {
Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt
Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT
}
# The prior PYTHONHOME:
if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) {
Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME
Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME
}
# The prior PATH:
if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) {
Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH
Remove-Item -Path Env:_OLD_VIRTUAL_PATH
}
# Just remove the VIRTUAL_ENV altogether:
if (Test-Path -Path Env:VIRTUAL_ENV) {
Remove-Item -Path env:VIRTUAL_ENV
}
# Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether:
if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) {
Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force
}
# Leave deactivate function in the global namespace if requested:
if (-not $NonDestructive) {
Remove-Item -Path function:deactivate
}
}
<#
.Description
Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the
given folder, and returns them in a map.
For each line in the pyvenv.cfg file, if that line can be parsed into exactly
two strings separated by `=` (with any amount of whitespace surrounding the =)
then it is considered a `key = value` line. The left hand string is the key,
the right hand is the value.
If the value starts with a `'` or a `"` then the first and last character is
stripped from the value before being captured.
.Parameter ConfigDir
Path to the directory that contains the `pyvenv.cfg` file.
#>
function Get-PyVenvConfig(
[String]
$ConfigDir
) {
Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg"
# Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue).
$pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue
# An empty map will be returned if no config file is found.
$pyvenvConfig = @{ }
if ($pyvenvConfigPath) {
Write-Verbose "File exists, parse `key = value` lines"
$pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath
$pyvenvConfigContent | ForEach-Object {
$keyval = $PSItem -split "\s*=\s*", 2
if ($keyval[0] -and $keyval[1]) {
$val = $keyval[1]
# Remove extraneous quotations around a string value.
if ("'""".Contains($val.Substring(0, 1))) {
$val = $val.Substring(1, $val.Length - 2)
}
$pyvenvConfig[$keyval[0]] = $val
Write-Verbose "Adding Key: '$($keyval[0])'='$val'"
}
}
}
return $pyvenvConfig
}
<# Begin Activate script --------------------------------------------------- #>
# Determine the containing directory of this script
$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
$VenvExecDir = Get-Item -Path $VenvExecPath
Write-Verbose "Activation script is located in path: '$VenvExecPath'"
Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)"
Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)"
# Set values required in priority: CmdLine, ConfigFile, Default
# First, get the location of the virtual environment, it might not be
# VenvExecDir if specified on the command line.
if ($VenvDir) {
Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values"
}
else {
Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir."
$VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/")
Write-Verbose "VenvDir=$VenvDir"
}
# Next, read the `pyvenv.cfg` file to determine any required value such
# as `prompt`.
$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir
# Next, set the prompt from the command line, or the config file, or
# just use the name of the virtual environment folder.
if ($Prompt) {
Write-Verbose "Prompt specified as argument, using '$Prompt'"
}
else {
Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value"
if ($pyvenvCfg -and $pyvenvCfg['prompt']) {
Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'"
$Prompt = $pyvenvCfg['prompt'];
}
else {
Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virutal environment)"
Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'"
$Prompt = Split-Path -Path $venvDir -Leaf
}
}
Write-Verbose "Prompt = '$Prompt'"
Write-Verbose "VenvDir='$VenvDir'"
# Deactivate any currently active virtual environment, but leave the
# deactivate function in place.
deactivate -nondestructive
# Now set the environment variable VIRTUAL_ENV, used by many tools to determine
# that there is an activated venv.
$env:VIRTUAL_ENV = $VenvDir
if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) {
Write-Verbose "Setting prompt to '$Prompt'"
# Set the prompt to include the env name
# Make sure _OLD_VIRTUAL_PROMPT is global
function global:_OLD_VIRTUAL_PROMPT { "" }
Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT
New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt
function global:prompt {
Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) "
_OLD_VIRTUAL_PROMPT
}
}
# Clear PYTHONHOME
if (Test-Path -Path Env:PYTHONHOME) {
Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME
Remove-Item -Path Env:PYTHONHOME
}
# Add the venv to the PATH
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH"

View File

@ -1,66 +0,0 @@
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly
deactivate () {
# reset old environment variables
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
PATH="${_OLD_VIRTUAL_PATH:-}"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r 2> /dev/null
fi
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
PS1="${_OLD_VIRTUAL_PS1:-}"
export PS1
unset _OLD_VIRTUAL_PS1
fi
unset VIRTUAL_ENV
if [ ! "${1:-}" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}
# unset irrelevant variables
deactivate nondestructive
VIRTUAL_ENV="/home/kjk/Documents/FabAccess/ldapbodge/.venv"
export VIRTUAL_ENV
_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH
# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
if [ -n "${PYTHONHOME:-}" ] ; then
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
unset PYTHONHOME
fi
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1:-}"
PS1="(.venv) ${PS1:-}"
export PS1
fi
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r 2> /dev/null
fi

View File

@ -1,25 +0,0 @@
# This file must be used with "source bin/activate.csh" *from csh*.
# You cannot run it directly.
# Created by Davide Di Blasi <davidedb@gmail.com>.
# Ported to Python 3.3 venv by Andrew Svetlov <andrew.svetlov@gmail.com>
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; test "\!:*" != "nondestructive" && unalias deactivate'
# Unset irrelevant variables.
deactivate nondestructive
setenv VIRTUAL_ENV "/home/kjk/Documents/FabAccess/ldapbodge/.venv"
set _OLD_VIRTUAL_PATH="$PATH"
setenv PATH "$VIRTUAL_ENV/bin:$PATH"
set _OLD_VIRTUAL_PROMPT="$prompt"
if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
set prompt = "(.venv) $prompt"
endif
alias pydoc python -m pydoc
rehash

View File

@ -1,64 +0,0 @@
# This file must be used with "source <venv>/bin/activate.fish" *from fish*
# (https://fishshell.com/); you cannot run it directly.
function deactivate -d "Exit virtual environment and return to normal shell environment"
# reset old environment variables
if test -n "$_OLD_VIRTUAL_PATH"
set -gx PATH $_OLD_VIRTUAL_PATH
set -e _OLD_VIRTUAL_PATH
end
if test -n "$_OLD_VIRTUAL_PYTHONHOME"
set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
set -e _OLD_VIRTUAL_PYTHONHOME
end
if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
functions -e fish_prompt
set -e _OLD_FISH_PROMPT_OVERRIDE
functions -c _old_fish_prompt fish_prompt
functions -e _old_fish_prompt
end
set -e VIRTUAL_ENV
if test "$argv[1]" != "nondestructive"
# Self-destruct!
functions -e deactivate
end
end
# Unset irrelevant variables.
deactivate nondestructive
set -gx VIRTUAL_ENV "/home/kjk/Documents/FabAccess/ldapbodge/.venv"
set -gx _OLD_VIRTUAL_PATH $PATH
set -gx PATH "$VIRTUAL_ENV/bin" $PATH
# Unset PYTHONHOME if set.
if set -q PYTHONHOME
set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
set -e PYTHONHOME
end
if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
# fish uses a function instead of an env var to generate the prompt.
# Save the current fish_prompt function as the function _old_fish_prompt.
functions -c fish_prompt _old_fish_prompt
# With the original prompt function renamed, we can override with our own.
function fish_prompt
# Save the return status of the last command.
set -l old_status $status
# Output the venv prompt; color taken from the blue of the Python logo.
printf "%s%s%s" (set_color 4B8BBE) "(.venv) " (set_color normal)
# Restore the return status of the previous command.
echo "exit $old_status" | .
# Output the original/"old" prompt.
_old_fish_prompt
end
set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
end

View File

@ -1,8 +0,0 @@
#!/home/kjk/Documents/FabAccess/ldapbodge/.venv/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())

View File

@ -1,8 +0,0 @@
#!/home/kjk/Documents/FabAccess/ldapbodge/.venv/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())

View File

@ -1,8 +0,0 @@
#!/home/kjk/Documents/FabAccess/ldapbodge/.venv/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())

View File

@ -1 +0,0 @@
/usr/bin/python

View File

@ -1 +0,0 @@
python

View File

@ -1 +0,0 @@
python

View File

@ -1,128 +0,0 @@
import sys
import os
import re
import importlib
import warnings
is_pypy = '__pypy__' in sys.builtin_module_names
warnings.filterwarnings('ignore',
r'.+ distutils\b.+ deprecated',
DeprecationWarning)
def warn_distutils_present():
if 'distutils' not in sys.modules:
return
if is_pypy and sys.version_info < (3, 7):
# PyPy for 3.6 unconditionally imports distutils, so bypass the warning
# https://foss.heptapod.net/pypy/pypy/-/blob/be829135bc0d758997b3566062999ee8b23872b4/lib-python/3/site.py#L250
return
warnings.warn(
"Distutils was imported before Setuptools, but importing Setuptools "
"also replaces the `distutils` module in `sys.modules`. This may lead "
"to undesirable behaviors or errors. To avoid these issues, avoid "
"using distutils directly, ensure that setuptools is installed in the "
"traditional way (e.g. not an editable install), and/or make sure "
"that setuptools is always imported before distutils.")
def clear_distutils():
if 'distutils' not in sys.modules:
return
warnings.warn("Setuptools is replacing distutils.")
mods = [name for name in sys.modules if re.match(r'distutils\b', name)]
for name in mods:
del sys.modules[name]
def enabled():
"""
Allow selection of distutils by environment variable.
"""
which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'stdlib')
return which == 'local'
def ensure_local_distutils():
clear_distutils()
distutils = importlib.import_module('setuptools._distutils')
distutils.__name__ = 'distutils'
sys.modules['distutils'] = distutils
# sanity check that submodules load as expected
core = importlib.import_module('distutils.core')
assert '_distutils' in core.__file__, core.__file__
def do_override():
"""
Ensure that the local copy of distutils is preferred over stdlib.
See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401
for more motivation.
"""
if enabled():
warn_distutils_present()
ensure_local_distutils()
class DistutilsMetaFinder:
def find_spec(self, fullname, path, target=None):
if path is not None:
return
method_name = 'spec_for_{fullname}'.format(**locals())
method = getattr(self, method_name, lambda: None)
return method()
def spec_for_distutils(self):
import importlib.abc
import importlib.util
class DistutilsLoader(importlib.abc.Loader):
def create_module(self, spec):
return importlib.import_module('setuptools._distutils')
def exec_module(self, module):
pass
return importlib.util.spec_from_loader('distutils', DistutilsLoader())
def spec_for_pip(self):
"""
Ensure stdlib distutils when running under pip.
See pypa/pip#8761 for rationale.
"""
if self.pip_imported_during_build():
return
clear_distutils()
self.spec_for_distutils = lambda: None
@staticmethod
def pip_imported_during_build():
"""
Detect if pip is being imported in a build script. Ref #2355.
"""
import traceback
return any(
frame.f_globals['__file__'].endswith('setup.py')
for frame, line in traceback.walk_stack(None)
)
DISTUTILS_FINDER = DistutilsMetaFinder()
def add_shim():
sys.meta_path.insert(0, DISTUTILS_FINDER)
def remove_shim():
try:
sys.meta_path.remove(DISTUTILS_FINDER)
except ValueError:
pass

View File

@ -1 +0,0 @@
__import__('_distutils_hack').do_override()

View File

@ -1 +0,0 @@
import os; var = 'SETUPTOOLS_USE_DISTUTILS'; enabled = os.environ.get(var, 'stdlib') == 'local'; enabled and __import__('_distutils_hack').add_shim();

View File

@ -1,111 +0,0 @@
"""
ldap - base module
See https://www.python-ldap.org/ for details.
"""
# This is also the overall release version number
from ldap.pkginfo import __version__, __author__, __license__
import os
import sys
if __debug__:
# Tracing is only supported in debugging mode
import atexit
import traceback
_trace_level = int(os.environ.get("PYTHON_LDAP_TRACE_LEVEL", 0))
_trace_file = os.environ.get("PYTHON_LDAP_TRACE_FILE")
if _trace_file is None:
_trace_file = sys.stderr
else:
_trace_file = open(_trace_file, 'a')
atexit.register(_trace_file.close)
_trace_stack_limit = None
else:
# Any use of the _trace attributes should be guarded by `if __debug__`,
# so they should not be needed here.
# But, providing different API for debug mode is unnecessarily fragile.
_trace_level = 0
_trace_file = sys.stderr
_trace_stack_limit = None
import _ldap
assert _ldap.__version__==__version__, \
ImportError('ldap %s and _ldap %s version mismatch!' % (__version__,_ldap.__version__))
from _ldap import *
# call into libldap to initialize it right now
LIBLDAP_API_INFO = _ldap.get_option(_ldap.OPT_API_INFO)
OPT_NAMES_DICT = {}
for k,v in vars(_ldap).items():
if k.startswith('OPT_'):
OPT_NAMES_DICT[v]=k
class DummyLock:
"""Define dummy class with methods compatible to threading.Lock"""
def __init__(self):
pass
def acquire(self):
pass
def release(self):
pass
try:
# Check if Python installation was build with thread support
import threading
except ImportError:
LDAPLockBaseClass = DummyLock
else:
LDAPLockBaseClass = threading.Lock
class LDAPLock:
"""
Mainly a wrapper class to log all locking events.
Note that this cumbersome approach with _lock attribute was taken
since threading.Lock is not suitable for sub-classing.
"""
_min_trace_level = 3
def __init__(self,lock_class=None,desc=''):
"""
lock_class
Class compatible to threading.Lock
desc
Description shown in debug log messages
"""
self._desc = desc
self._lock = (lock_class or LDAPLockBaseClass)()
def acquire(self):
if __debug__:
global _trace_level
if _trace_level>=self._min_trace_level:
_trace_file.write('***%s.acquire() %s %s\n' % (self.__class__.__name__,repr(self),self._desc))
return self._lock.acquire()
def release(self):
if __debug__:
global _trace_level
if _trace_level>=self._min_trace_level:
_trace_file.write('***%s.release() %s %s\n' % (self.__class__.__name__,repr(self),self._desc))
return self._lock.release()
# Create module-wide lock for serializing all calls into underlying LDAP lib
_ldap_module_lock = LDAPLock(desc='Module wide')
from ldap.functions import initialize,get_option,set_option,escape_str,strf_secs,strp_secs
from ldap.ldapobject import NO_UNIQUE_ENTRY, LDAPBytesWarning
from ldap.dn import explode_dn,explode_rdn,str2dn,dn2str
del str2dn
del dn2str
# More constants
# For compatibility of 2.3 and 2.4 OpenLDAP API
OPT_DIAGNOSTIC_MESSAGE = OPT_ERROR_STRING

View File

@ -1,15 +0,0 @@
"""
ldap.asyncsearch - handle async LDAP search operations
See https://www.python-ldap.org/ for details.
"""
import warnings
from ldap.asyncsearch import *
from ldap.asyncsearch import __version__
warnings.warn(
"'ldap.async module' is deprecated, import 'ldap.asyncsearch' instead.",
DeprecationWarning,
stacklevel=2
)

View File

@ -1,284 +0,0 @@
"""
ldap.asyncsearch - handle async LDAP search operations
See https://www.python-ldap.org/ for details.
"""
import ldap
from ldap import __version__
import ldif
SEARCH_RESULT_TYPES = {
ldap.RES_SEARCH_ENTRY,
ldap.RES_SEARCH_RESULT,
ldap.RES_SEARCH_REFERENCE,
}
ENTRY_RESULT_TYPES = {
ldap.RES_SEARCH_ENTRY,
ldap.RES_SEARCH_RESULT,
}
class WrongResultType(Exception):
def __init__(self,receivedResultType,expectedResultTypes):
self.receivedResultType = receivedResultType
self.expectedResultTypes = expectedResultTypes
Exception.__init__(self)
def __str__(self):
return 'Received wrong result type %s (expected one of %s).' % (
self.receivedResultType,
', '.join(self.expectedResultTypes),
)
class AsyncSearchHandler:
"""
Class for stream-processing LDAP search results
Arguments:
l
LDAPObject instance
"""
def __init__(self,l):
self._l = l
self._msgId = None
self._afterFirstResult = 1
def startSearch(
self,
searchRoot,
searchScope,
filterStr,
attrList=None,
attrsOnly=0,
timeout=-1,
sizelimit=0,
serverctrls=None,
clientctrls=None
):
"""
searchRoot
See parameter base of method LDAPObject.search()
searchScope
See parameter scope of method LDAPObject.search()
filterStr
See parameter filter of method LDAPObject.search()
attrList=None
See parameter attrlist of method LDAPObject.search()
attrsOnly
See parameter attrsonly of method LDAPObject.search()
timeout
Maximum time the server shall use for search operation
sizelimit
Maximum number of entries a server should return
(request client-side limit)
serverctrls
list of server-side LDAP controls
clientctrls
list of client-side LDAP controls
"""
self._msgId = self._l.search_ext(
searchRoot,searchScope,filterStr,
attrList,attrsOnly,serverctrls,clientctrls,timeout,sizelimit
)
self._afterFirstResult = 1
return # startSearch()
def preProcessing(self):
"""
Do anything you want after starting search but
before receiving and processing results
"""
def afterFirstResult(self):
"""
Do anything you want right after successfully receiving but before
processing first result
"""
def postProcessing(self):
"""
Do anything you want after receiving and processing all results
"""
def processResults(self,ignoreResultsNumber=0,processResultsCount=0,timeout=-1):
"""
ignoreResultsNumber
Don't process the first ignoreResultsNumber results.
processResultsCount
If non-zero this parameters indicates the number of results
processed is limited to processResultsCount.
timeout
See parameter timeout of ldap.LDAPObject.result()
"""
self.preProcessing()
result_counter = 0
end_result_counter = ignoreResultsNumber+processResultsCount
go_ahead = 1
partial = 0
self.beginResultsDropped = 0
self.endResultBreak = result_counter
try:
result_type,result_list = None,None
while go_ahead:
while result_type is None and not result_list:
result_type,result_list,result_msgid,result_serverctrls = self._l.result3(self._msgId,0,timeout)
if self._afterFirstResult:
self.afterFirstResult()
self._afterFirstResult = 0
if not result_list:
break
if result_type not in SEARCH_RESULT_TYPES:
raise WrongResultType(result_type,SEARCH_RESULT_TYPES)
# Loop over list of search results
for result_item in result_list:
if result_counter<ignoreResultsNumber:
self.beginResultsDropped = self.beginResultsDropped+1
elif processResultsCount==0 or result_counter<end_result_counter:
self._processSingleResult(result_type,result_item)
else:
go_ahead = 0 # break-out from while go_ahead
partial = 1
break # break-out from this for-loop
result_counter = result_counter+1
result_type,result_list = None,None
self.endResultBreak = result_counter
finally:
if partial and self._msgId!=None:
self._l.abandon(self._msgId)
self.postProcessing()
return partial # processResults()
def _processSingleResult(self,resultType,resultItem):
"""
Process single entry
resultType
result type
resultItem
Single item of a result list
"""
pass
class List(AsyncSearchHandler):
"""
Class for collecting all search results.
This does not seem to make sense in the first place but think
of retrieving exactly a certain portion of the available search
results.
"""
def __init__(self,l):
AsyncSearchHandler.__init__(self,l)
self.allResults = []
def _processSingleResult(self,resultType,resultItem):
self.allResults.append((resultType,resultItem))
class Dict(AsyncSearchHandler):
"""
Class for collecting all search results into a dictionary {dn:entry}
"""
def __init__(self,l):
AsyncSearchHandler.__init__(self,l)
self.allEntries = {}
def _processSingleResult(self,resultType,resultItem):
if resultType in ENTRY_RESULT_TYPES:
# Search continuations are ignored
dn,entry = resultItem
self.allEntries[dn] = entry
class IndexedDict(Dict):
"""
Class for collecting all search results into a dictionary {dn:entry}
and maintain case-sensitive equality indexes to entries
"""
def __init__(self,l,indexed_attrs=None):
Dict.__init__(self,l)
self.indexed_attrs = indexed_attrs or ()
self.index = {}.fromkeys(self.indexed_attrs,{})
def _processSingleResult(self,resultType,resultItem):
if resultType in ENTRY_RESULT_TYPES:
# Search continuations are ignored
dn,entry = resultItem
self.allEntries[dn] = entry
for a in self.indexed_attrs:
if a in entry:
for v in entry[a]:
try:
self.index[a][v].append(dn)
except KeyError:
self.index[a][v] = [ dn ]
class FileWriter(AsyncSearchHandler):
"""
Class for writing a stream of LDAP search results to a file object
Arguments:
l
LDAPObject instance
f
File object instance where the LDIF data is written to
"""
def __init__(self,l,f,headerStr='',footerStr=''):
AsyncSearchHandler.__init__(self,l)
self._f = f
self.headerStr = headerStr
self.footerStr = footerStr
def preProcessing(self):
"""
The headerStr is written to output after starting search but
before receiving and processing results.
"""
self._f.write(self.headerStr)
def postProcessing(self):
"""
The footerStr is written to output after receiving and
processing results.
"""
self._f.write(self.footerStr)
class LDIFWriter(FileWriter):
"""
Class for writing a stream LDAP search results to a LDIF file
Arguments:
l
LDAPObject instance
writer_obj
Either a file-like object or a ldif.LDIFWriter instance used for output
"""
def __init__(self,l,writer_obj,headerStr='',footerStr=''):
if isinstance(writer_obj,ldif.LDIFWriter):
self._ldif_writer = writer_obj
else:
self._ldif_writer = ldif.LDIFWriter(writer_obj)
FileWriter.__init__(self,l,self._ldif_writer._output_file,headerStr,footerStr)
def _processSingleResult(self,resultType,resultItem):
if resultType in ENTRY_RESULT_TYPES:
# Search continuations are ignored
dn,entry = resultItem
self._ldif_writer.unparse(dn,entry)

View File

@ -1,129 +0,0 @@
"""
This is a convenience wrapper for dictionaries
returned from LDAP servers containing attribute
names of variable case.
See https://www.python-ldap.org/ for details.
"""
import warnings
from ldap.compat import MutableMapping
from ldap import __version__
class cidict(MutableMapping):
"""
Case-insensitive but case-respecting dictionary.
"""
__slots__ = ('_keys', '_data')
def __init__(self, default=None):
self._keys = {}
self._data = {}
if default:
self.update(default)
# MutableMapping abstract methods
def __getitem__(self, key):
return self._data[key.lower()]
def __setitem__(self, key, value):
lower_key = key.lower()
self._keys[lower_key] = key
self._data[lower_key] = value
def __delitem__(self, key):
lower_key = key.lower()
del self._keys[lower_key]
del self._data[lower_key]
def __iter__(self):
return iter(self._keys.values())
def __len__(self):
return len(self._keys)
# Specializations for performance
def __contains__(self, key):
return key.lower() in self._keys
def clear(self):
self._keys.clear()
self._data.clear()
# Backwards compatibility
def has_key(self, key):
"""Compatibility with python-ldap 2.x"""
return key in self
@property
def data(self):
"""Compatibility with older IterableUserDict-based implementation"""
warnings.warn(
'ldap.cidict.cidict.data is an internal attribute; it may be ' +
'removed at any time',
category=DeprecationWarning,
stacklevel=2,
)
return self._data
def strlist_minus(a,b):
"""
Return list of all items in a which are not in b (a - b).
a,b are supposed to be lists of case-insensitive strings.
"""
warnings.warn(
"strlist functions are deprecated and will be removed in 3.4",
category=DeprecationWarning,
stacklevel=2,
)
temp = cidict()
for elt in b:
temp[elt] = elt
result = [
elt
for elt in a
if elt not in temp
]
return result
def strlist_intersection(a,b):
"""
Return intersection of two lists of case-insensitive strings a,b.
"""
warnings.warn(
"strlist functions are deprecated and will be removed in 3.4",
category=DeprecationWarning,
stacklevel=2,
)
temp = cidict()
for elt in a:
temp[elt] = elt
result = [
temp[elt]
for elt in b
if elt in temp
]
return result
def strlist_union(a,b):
"""
Return union of two lists of case-insensitive strings a,b.
"""
warnings.warn(
"strlist functions are deprecated and will be removed in 3.4",
category=DeprecationWarning,
stacklevel=2,
)
temp = cidict()
for elt in a:
temp[elt] = elt
for elt in b:
temp[elt] = elt
return temp.values()

View File

@ -1,115 +0,0 @@
"""Compatibility wrappers for Py2/Py3."""
import sys
import os
if sys.version_info[0] < 3:
from UserDict import UserDict, IterableUserDict
from urllib import quote
from urllib import quote_plus
from urllib import unquote as urllib_unquote
from urllib import urlopen
from urlparse import urlparse
from collections import MutableMapping
def unquote(uri):
"""Specialized unquote that uses UTF-8 for parsing."""
uri = uri.encode('ascii')
unquoted = urllib_unquote(uri)
return unquoted.decode('utf-8')
# Old-style of re-raising an exception is SyntaxError in Python 3,
# so hide behind exec() so the Python 3 parser doesn't see it
exec('''def reraise(exc_type, exc_value, exc_traceback):
"""Re-raise an exception given information from sys.exc_info()
Note that unlike six.reraise, this does not support replacing the
traceback. All arguments must come from a single sys.exc_info() call.
"""
raise exc_type, exc_value, exc_traceback
''')
else:
from collections import UserDict
IterableUserDict = UserDict
from urllib.parse import quote, quote_plus, unquote, urlparse
from urllib.request import urlopen
from collections.abc import MutableMapping
def reraise(exc_type, exc_value, exc_traceback):
"""Re-raise an exception given information from sys.exc_info()
Note that unlike six.reraise, this does not support replacing the
traceback. All arguments must come from a single sys.exc_info() call.
"""
# In Python 3, all exception info is contained in one object.
raise exc_value
try:
from shutil import which
except ImportError:
# shutil.which() from Python 3.6
# "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012, 2013, 2014, 2015, 2016, 2017 Python Software Foundation;
# All Rights Reserved"
def which(cmd, mode=os.F_OK | os.X_OK, path=None):
"""Given a command, mode, and a PATH string, return the path which
conforms to the given mode on the PATH, or None if there is no such
file.
`mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
of os.environ.get("PATH"), or can be overridden with a custom search
path.
"""
# Check that a given file can be accessed with the correct mode.
# Additionally check that `file` is not a directory, as on Windows
# directories pass the os.access check.
def _access_check(fn, mode):
return (os.path.exists(fn) and os.access(fn, mode)
and not os.path.isdir(fn))
# If we're given a path with a directory part, look it up directly rather
# than referring to PATH directories. This includes checking relative to the
# current directory, e.g. ./script
if os.path.dirname(cmd):
if _access_check(cmd, mode):
return cmd
return None
if path is None:
path = os.environ.get("PATH", os.defpath)
if not path:
return None
path = path.split(os.pathsep)
if sys.platform == "win32":
# The current directory takes precedence on Windows.
if not os.curdir in path:
path.insert(0, os.curdir)
# PATHEXT is necessary to check on Windows.
pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
# See if the given file matches any of the expected path extensions.
# This will allow us to short circuit when given "python.exe".
# If it does match, only test that one, otherwise we have to try
# others.
if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
files = [cmd]
else:
files = [cmd + ext for ext in pathext]
else:
# On other platforms you don't have things like PATHEXT to tell you
# what file suffixes are executable, so just pass on cmd as-is.
files = [cmd]
seen = set()
for dir in path:
normdir = os.path.normcase(dir)
if not normdir in seen:
seen.add(normdir)
for thefile in files:
name = os.path.join(dir, thefile)
if _access_check(name, mode):
return name
return None

View File

@ -1,404 +0,0 @@
"""Definitions for constants exported by OpenLDAP
This file lists all constants we know about, even those that aren't
available in the OpenLDAP version python-ldap is compiled against.
The information serves two purposes:
- Generate a C header with the constants
- Provide support for building documentation without compiling python-ldap
"""
# This module cannot import anything from ldap.
# When building documentation, it is used to initialize ldap.__init__.
from __future__ import print_function
class Constant(object):
"""Base class for a definition of an OpenLDAP constant
"""
def __init__(self, name, optional=False, requirements=(), doc=None):
self.name = name
if optional:
self_requirement = 'defined(LDAP_{})'.format(self.name)
requirements = list(requirements) + [self_requirement]
self.requirements = requirements
self.doc = self.__doc__ = doc
class Error(Constant):
"""Definition for an OpenLDAP error code
This is a constant at the C level; in Python errors are provided as
exception classes.
"""
c_template = 'add_err({self.name});'
class Int(Constant):
"""Definition for an OpenLDAP integer constant"""
c_template = 'add_int({self.name});'
class TLSInt(Int):
"""Definition for a TLS integer constant -- requires HAVE_TLS"""
def __init__(self, *args, **kwargs):
requrements = list(kwargs.get('requirements', ()))
kwargs['requirements'] = ['HAVE_TLS'] + requrements
super(TLSInt, self).__init__(*args, **kwargs)
class Feature(Constant):
"""Definition for a feature: 0 or 1 based on a C #ifdef
"""
c_template = '\n'.join([
'',
'#ifdef {self.c_feature}',
'if (PyModule_AddIntConstant(m, "{self.name}", 1) != 0) return -1;',
'#else',
'if (PyModule_AddIntConstant(m, "{self.name}", 0) != 0) return -1;',
'#endif',
'',
])
def __init__(self, name, c_feature, **kwargs):
super(Feature, self).__init__(name, **kwargs)
self.c_feature = c_feature
class Str(Constant):
c_template = 'add_string({self.name});'
API_2004 = 'LDAP_API_VERSION >= 2004'
CONSTANTS = (
Error('ADMINLIMIT_EXCEEDED'),
Error('AFFECTS_MULTIPLE_DSAS'),
Error('ALIAS_DEREF_PROBLEM'),
Error('ALIAS_PROBLEM'),
Error('ALREADY_EXISTS'),
Error('AUTH_METHOD_NOT_SUPPORTED'),
Error('AUTH_UNKNOWN'),
Error('BUSY'),
Error('CLIENT_LOOP'),
Error('COMPARE_FALSE'),
Error('COMPARE_TRUE'),
Error('CONFIDENTIALITY_REQUIRED'),
Error('CONNECT_ERROR'),
Error('CONSTRAINT_VIOLATION'),
Error('CONTROL_NOT_FOUND'),
Error('DECODING_ERROR'),
Error('ENCODING_ERROR'),
Error('FILTER_ERROR'),
Error('INAPPROPRIATE_AUTH'),
Error('INAPPROPRIATE_MATCHING'),
Error('INSUFFICIENT_ACCESS'),
Error('INVALID_CREDENTIALS'),
Error('INVALID_DN_SYNTAX'),
Error('INVALID_SYNTAX'),
Error('IS_LEAF'),
Error('LOCAL_ERROR'),
Error('LOOP_DETECT'),
Error('MORE_RESULTS_TO_RETURN'),
Error('NAMING_VIOLATION'),
Error('NO_MEMORY'),
Error('NO_OBJECT_CLASS_MODS'),
Error('NO_OBJECT_CLASS_MODS'),
Error('NO_RESULTS_RETURNED'),
Error('NO_SUCH_ATTRIBUTE'),
Error('NO_SUCH_OBJECT'),
Error('NOT_ALLOWED_ON_NONLEAF'),
Error('NOT_ALLOWED_ON_RDN'),
Error('NOT_SUPPORTED'),
Error('OBJECT_CLASS_VIOLATION'),
Error('OPERATIONS_ERROR'),
Error('OTHER'),
Error('PARAM_ERROR'),
Error('PARTIAL_RESULTS'),
Error('PROTOCOL_ERROR'),
Error('REFERRAL'),
Error('REFERRAL_LIMIT_EXCEEDED'),
Error('RESULTS_TOO_LARGE'),
Error('SASL_BIND_IN_PROGRESS'),
Error('SERVER_DOWN'),
Error('SIZELIMIT_EXCEEDED'),
Error('STRONG_AUTH_NOT_SUPPORTED'),
Error('STRONG_AUTH_REQUIRED'),
Error('SUCCESS'),
Error('TIMELIMIT_EXCEEDED'),
Error('TIMEOUT'),
Error('TYPE_OR_VALUE_EXISTS'),
Error('UNAVAILABLE'),
Error('UNAVAILABLE_CRITICAL_EXTENSION'),
Error('UNDEFINED_TYPE'),
Error('UNWILLING_TO_PERFORM'),
Error('USER_CANCELLED'),
Error('VLV_ERROR'),
Error('X_PROXY_AUTHZ_FAILURE'),
Error('CANCELLED', requirements=['defined(LDAP_API_FEATURE_CANCEL)']),
Error('NO_SUCH_OPERATION', requirements=['defined(LDAP_API_FEATURE_CANCEL)']),
Error('TOO_LATE', requirements=['defined(LDAP_API_FEATURE_CANCEL)']),
Error('CANNOT_CANCEL', requirements=['defined(LDAP_API_FEATURE_CANCEL)']),
Error('ASSERTION_FAILED', optional=True),
Error('PROXIED_AUTHORIZATION_DENIED', optional=True),
# simple constants
Int('API_VERSION'),
Int('VENDOR_VERSION'),
Int('PORT'),
Int('VERSION1'),
Int('VERSION2'),
Int('VERSION3'),
Int('VERSION_MIN'),
Int('VERSION'),
Int('VERSION_MAX'),
Int('TAG_MESSAGE'),
Int('TAG_MSGID'),
Int('REQ_BIND'),
Int('REQ_UNBIND'),
Int('REQ_SEARCH'),
Int('REQ_MODIFY'),
Int('REQ_ADD'),
Int('REQ_DELETE'),
Int('REQ_MODRDN'),
Int('REQ_COMPARE'),
Int('REQ_ABANDON'),
Int('TAG_LDAPDN'),
Int('TAG_LDAPCRED'),
Int('TAG_CONTROLS'),
Int('TAG_REFERRAL'),
Int('REQ_EXTENDED'),
Int('TAG_NEWSUPERIOR', requirements=[API_2004]),
Int('TAG_EXOP_REQ_OID', requirements=[API_2004]),
Int('TAG_EXOP_REQ_VALUE', requirements=[API_2004]),
Int('TAG_EXOP_RES_OID', requirements=[API_2004]),
Int('TAG_EXOP_RES_VALUE', requirements=[API_2004]),
Int('TAG_SASL_RES_CREDS', requirements=[API_2004, 'defined(HAVE_SASL)']),
Int('SASL_AUTOMATIC'),
Int('SASL_INTERACTIVE'),
Int('SASL_QUIET'),
# reversibles
Int('RES_BIND'),
Int('RES_SEARCH_ENTRY'),
Int('RES_SEARCH_RESULT'),
Int('RES_MODIFY'),
Int('RES_ADD'),
Int('RES_DELETE'),
Int('RES_MODRDN'),
Int('RES_COMPARE'),
Int('RES_ANY'),
Int('RES_SEARCH_REFERENCE'),
Int('RES_EXTENDED'),
Int('RES_UNSOLICITED'),
Int('RES_INTERMEDIATE'),
# non-reversibles
Int('AUTH_NONE'),
Int('AUTH_SIMPLE'),
Int('SCOPE_BASE'),
Int('SCOPE_ONELEVEL'),
Int('SCOPE_SUBTREE'),
Int('SCOPE_SUBORDINATE', optional=True),
Int('MOD_ADD'),
Int('MOD_DELETE'),
Int('MOD_REPLACE'),
Int('MOD_INCREMENT'),
Int('MOD_BVALUES'),
Int('MSG_ONE'),
Int('MSG_ALL'),
Int('MSG_RECEIVED'),
# (error constants handled above)
Int('DEREF_NEVER'),
Int('DEREF_SEARCHING'),
Int('DEREF_FINDING'),
Int('DEREF_ALWAYS'),
Int('NO_LIMIT'),
Int('OPT_API_INFO'),
Int('OPT_DEREF'),
Int('OPT_SIZELIMIT'),
Int('OPT_TIMELIMIT'),
Int('OPT_REFERRALS', optional=True),
Int('OPT_ERROR_NUMBER'),
Int('OPT_RESTART'),
Int('OPT_PROTOCOL_VERSION'),
Int('OPT_SERVER_CONTROLS'),
Int('OPT_CLIENT_CONTROLS'),
Int('OPT_API_FEATURE_INFO'),
Int('OPT_HOST_NAME'),
Int('OPT_DESC'),
Int('OPT_DIAGNOSTIC_MESSAGE'),
Int('OPT_ERROR_STRING'),
Int('OPT_MATCHED_DN'),
Int('OPT_DEBUG_LEVEL'),
Int('OPT_TIMEOUT'),
Int('OPT_REFHOPLIMIT'),
Int('OPT_NETWORK_TIMEOUT'),
Int('OPT_URI'),
Int('OPT_DEFBASE', optional=True),
TLSInt('OPT_X_TLS', optional=True),
TLSInt('OPT_X_TLS_CTX'),
TLSInt('OPT_X_TLS_CACERTFILE'),
TLSInt('OPT_X_TLS_CACERTDIR'),
TLSInt('OPT_X_TLS_CERTFILE'),
TLSInt('OPT_X_TLS_KEYFILE'),
TLSInt('OPT_X_TLS_REQUIRE_CERT'),
TLSInt('OPT_X_TLS_CIPHER_SUITE'),
TLSInt('OPT_X_TLS_RANDOM_FILE'),
TLSInt('OPT_X_TLS_DHFILE'),
TLSInt('OPT_X_TLS_NEVER'),
TLSInt('OPT_X_TLS_HARD'),
TLSInt('OPT_X_TLS_DEMAND'),
TLSInt('OPT_X_TLS_ALLOW'),
TLSInt('OPT_X_TLS_TRY'),
TLSInt('OPT_X_TLS_VERSION', optional=True),
TLSInt('OPT_X_TLS_CIPHER', optional=True),
TLSInt('OPT_X_TLS_PEERCERT', optional=True),
# only available if OpenSSL supports it => might cause
# backward compatibility problems
TLSInt('OPT_X_TLS_CRLCHECK', optional=True),
TLSInt('OPT_X_TLS_CRLFILE', optional=True),
TLSInt('OPT_X_TLS_CRL_NONE'),
TLSInt('OPT_X_TLS_CRL_PEER'),
TLSInt('OPT_X_TLS_CRL_ALL'),
TLSInt('OPT_X_TLS_NEWCTX', optional=True),
TLSInt('OPT_X_TLS_PROTOCOL_MIN', optional=True),
TLSInt('OPT_X_TLS_PACKAGE', optional=True),
Int('OPT_X_SASL_MECH'),
Int('OPT_X_SASL_REALM'),
Int('OPT_X_SASL_AUTHCID'),
Int('OPT_X_SASL_AUTHZID'),
Int('OPT_X_SASL_SSF'),
Int('OPT_X_SASL_SSF_EXTERNAL'),
Int('OPT_X_SASL_SECPROPS'),
Int('OPT_X_SASL_SSF_MIN'),
Int('OPT_X_SASL_SSF_MAX'),
Int('OPT_X_SASL_NOCANON', optional=True),
Int('OPT_X_SASL_USERNAME', optional=True),
Int('OPT_CONNECT_ASYNC', optional=True),
Int('OPT_X_KEEPALIVE_IDLE', optional=True),
Int('OPT_X_KEEPALIVE_PROBES', optional=True),
Int('OPT_X_KEEPALIVE_INTERVAL', optional=True),
Int('DN_FORMAT_LDAP'),
Int('DN_FORMAT_LDAPV3'),
Int('DN_FORMAT_LDAPV2'),
Int('DN_FORMAT_DCE'),
Int('DN_FORMAT_UFN'),
Int('DN_FORMAT_AD_CANONICAL'),
# Int('DN_FORMAT_LBER'), # for testing only
Int('DN_FORMAT_MASK'),
Int('DN_PRETTY'),
Int('DN_SKIP'),
Int('DN_P_NOLEADTRAILSPACES'),
Int('DN_P_NOSPACEAFTERRDN'),
Int('DN_PEDANTIC'),
Int('AVA_NULL'),
Int('AVA_STRING'),
Int('AVA_BINARY'),
Int('AVA_NONPRINTABLE'),
Int('OPT_SUCCESS'),
# XXX - these should be errors
Int('URL_ERR_BADSCOPE'),
Int('URL_ERR_MEM'),
# Int('LIBLDAP_R'),
Feature('LIBLDAP_R', 'HAVE_LIBLDAP_R'),
Feature('SASL_AVAIL', 'HAVE_SASL'),
Feature('TLS_AVAIL', 'HAVE_TLS'),
Feature('INIT_FD_AVAIL', 'HAVE_LDAP_INIT_FD'),
Str("CONTROL_MANAGEDSAIT"),
Str("CONTROL_PROXY_AUTHZ"),
Str("CONTROL_SUBENTRIES"),
Str("CONTROL_VALUESRETURNFILTER"),
Str("CONTROL_ASSERT"),
Str("CONTROL_PRE_READ"),
Str("CONTROL_POST_READ"),
Str("CONTROL_SORTREQUEST"),
Str("CONTROL_SORTRESPONSE"),
Str("CONTROL_PAGEDRESULTS"),
Str("CONTROL_SYNC"),
Str("CONTROL_SYNC_STATE"),
Str("CONTROL_SYNC_DONE"),
Str("SYNC_INFO"),
Str("CONTROL_PASSWORDPOLICYREQUEST"),
Str("CONTROL_PASSWORDPOLICYRESPONSE"),
Str("CONTROL_RELAX"),
)
def print_header(): # pragma: no cover
"""Print the C header file to standard output"""
print('/*')
print(' * Generated with:')
print(' * python Lib/ldap/constants.py > Modules/constants_generated.h')
print(' *')
print(' * Please do any modifications there, then re-generate this file')
print(' */')
print('')
current_requirements = []
def pop_requirement():
popped = current_requirements.pop()
print('#endif')
print()
for definition in CONSTANTS:
while not set(current_requirements).issubset(definition.requirements):
pop_requirement()
for requirement in definition.requirements:
if requirement not in current_requirements:
current_requirements.append(requirement)
print()
print('#if {}'.format(requirement))
print(definition.c_template.format(self=definition))
while current_requirements:
pop_requirement()
if __name__ == '__main__':
print_header()

View File

@ -1,158 +0,0 @@
# -*- coding: utf-8 -*-
"""
controls.py - support classes for LDAP controls
See https://www.python-ldap.org/ for details.
Description:
The ldap.controls module provides LDAPControl classes.
Each class provides support for a certain control.
"""
from ldap.pkginfo import __version__
import _ldap
assert _ldap.__version__==__version__, \
ImportError('ldap %s and _ldap %s version mismatch!' % (__version__,_ldap.__version__))
import ldap
from pyasn1.error import PyAsn1Error
__all__ = [
'KNOWN_RESPONSE_CONTROLS',
# Classes
'AssertionControl',
'BooleanControl',
'LDAPControl',
'ManageDSAITControl',
'MatchedValuesControl',
'RelaxRulesControl',
'RequestControl',
'ResponseControl',
'SimplePagedResultsControl',
'ValueLessRequestControl',
# Functions
'RequestControlTuples',
'DecodeControlTuples',
]
# response control OID to class registry
KNOWN_RESPONSE_CONTROLS = {}
class RequestControl:
"""
Base class for all request controls
controlType
OID as string of the LDAPv3 extended request control
criticality
sets the criticality of the control (boolean)
encodedControlValue
control value of the LDAPv3 extended request control
(here it is the BER-encoded ASN.1 control value)
"""
def __init__(self,controlType=None,criticality=False,encodedControlValue=None):
self.controlType = controlType
self.criticality = criticality
self.encodedControlValue = encodedControlValue
def encodeControlValue(self):
"""
sets class attribute encodedControlValue to the BER-encoded ASN.1
control value composed by class attributes set before
"""
return self.encodedControlValue
class ResponseControl:
"""
Base class for all response controls
controlType
OID as string of the LDAPv3 extended response control
criticality
sets the criticality of the received control (boolean)
"""
def __init__(self,controlType=None,criticality=False):
self.controlType = controlType
self.criticality = criticality
def decodeControlValue(self,encodedControlValue):
"""
decodes the BER-encoded ASN.1 control value and sets the appropriate
class attributes
"""
self.encodedControlValue = encodedControlValue
class LDAPControl(RequestControl,ResponseControl):
"""
Base class for combined request/response controls mainly
for backward-compatibility to python-ldap 2.3.x
"""
def __init__(self,controlType=None,criticality=False,controlValue=None,encodedControlValue=None):
self.controlType = controlType
self.criticality = criticality
self.controlValue = controlValue
self.encodedControlValue = encodedControlValue
def RequestControlTuples(ldapControls):
"""
Return list of readily encoded 3-tuples which can be directly
passed to C module _ldap
ldapControls
sequence-type of RequestControl objects
"""
if ldapControls is None:
return None
else:
result = [
(c.controlType,c.criticality,c.encodeControlValue())
for c in ldapControls
]
return result
def DecodeControlTuples(ldapControlTuples,knownLDAPControls=None):
"""
Returns list of readily decoded ResponseControl objects
ldapControlTuples
Sequence-type of 3-tuples returned by _ldap.result4() containing
the encoded ASN.1 control values of response controls.
knownLDAPControls
Dictionary mapping extended control's OID to ResponseControl class
of response controls known by the application. If None
ldap.controls.KNOWN_RESPONSE_CONTROLS is used here.
"""
knownLDAPControls = knownLDAPControls or KNOWN_RESPONSE_CONTROLS
result = []
for controlType,criticality,encodedControlValue in ldapControlTuples or []:
try:
control = knownLDAPControls[controlType]()
except KeyError:
if criticality:
raise ldap.UNAVAILABLE_CRITICAL_EXTENSION('Received unexpected critical response control with controlType %s' % (repr(controlType)))
else:
control.controlType,control.criticality = controlType,criticality
try:
control.decodeControlValue(encodedControlValue)
except PyAsn1Error:
if criticality:
raise
else:
result.append(control)
return result
# Import the standard sub-modules
from ldap.controls.simple import *
from ldap.controls.libldap import *

View File

@ -1,119 +0,0 @@
# -*- coding: utf-8 -*-
"""
ldap.controls.deref - classes for
(see https://tools.ietf.org/html/draft-masarati-ldap-deref)
See https://www.python-ldap.org/ for project details.
"""
__all__ = [
'DEREF_CONTROL_OID',
'DereferenceControl',
]
import ldap.controls
from ldap.controls import LDAPControl,KNOWN_RESPONSE_CONTROLS
import pyasn1_modules.rfc2251
from pyasn1.type import namedtype,univ,tag
from pyasn1.codec.ber import encoder,decoder
from pyasn1_modules.rfc2251 import LDAPDN,AttributeDescription,AttributeDescriptionList,AttributeValue
DEREF_CONTROL_OID = '1.3.6.1.4.1.4203.666.5.16'
# Request types
#---------------------------------------------------------------------------
# For compatibility with ASN.1 declaration in I-D
AttributeList = AttributeDescriptionList
class DerefSpec(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType(
'derefAttr',
AttributeDescription()
),
namedtype.NamedType(
'attributes',
AttributeList()
),
)
class DerefSpecs(univ.SequenceOf):
componentType = DerefSpec()
# Response types
#---------------------------------------------------------------------------
class AttributeValues(univ.SetOf):
componentType = AttributeValue()
class PartialAttribute(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('type', AttributeDescription()),
namedtype.NamedType('vals', AttributeValues()),
)
class PartialAttributeList(univ.SequenceOf):
componentType = PartialAttribute()
tagSet = univ.Sequence.tagSet.tagImplicitly(
tag.Tag(tag.tagClassContext,tag.tagFormatConstructed,0)
)
class DerefRes(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('derefAttr', AttributeDescription()),
namedtype.NamedType('derefVal', LDAPDN()),
namedtype.OptionalNamedType('attrVals', PartialAttributeList()),
)
class DerefResultControlValue(univ.SequenceOf):
componentType = DerefRes()
class DereferenceControl(LDAPControl):
controlType = DEREF_CONTROL_OID
def __init__(self,criticality=False,derefSpecs=None):
LDAPControl.__init__(self,self.controlType,criticality)
self.derefSpecs = derefSpecs or {}
def _derefSpecs(self):
deref_specs = DerefSpecs()
i = 0
for deref_attr,deref_attribute_names in self.derefSpecs.items():
deref_spec = DerefSpec()
deref_attributes = AttributeList()
for j in range(len(deref_attribute_names)):
deref_attributes.setComponentByPosition(j,deref_attribute_names[j])
deref_spec.setComponentByName('derefAttr',AttributeDescription(deref_attr))
deref_spec.setComponentByName('attributes',deref_attributes)
deref_specs.setComponentByPosition(i,deref_spec)
i += 1
return deref_specs
def encodeControlValue(self):
return encoder.encode(self._derefSpecs())
def decodeControlValue(self,encodedControlValue):
decodedValue,_ = decoder.decode(encodedControlValue,asn1Spec=DerefResultControlValue())
self.derefRes = {}
for deref_res in decodedValue:
deref_attr,deref_val,deref_vals = deref_res[0],deref_res[1],deref_res[2]
partial_attrs_dict = {
str(tv[0]): [str(v) for v in tv[1]]
for tv in deref_vals or []
}
try:
self.derefRes[str(deref_attr)].append((str(deref_val),partial_attrs_dict))
except KeyError:
self.derefRes[str(deref_attr)] = [(str(deref_val),partial_attrs_dict)]
KNOWN_RESPONSE_CONTROLS[DereferenceControl.controlType] = DereferenceControl

View File

@ -1,82 +0,0 @@
# -*- coding: utf-8 -*-
"""
controls.libldap - LDAP controls wrapper classes with en-/decoding done
by OpenLDAP functions
See https://www.python-ldap.org/ for details.
"""
from ldap.pkginfo import __version__
import _ldap
assert _ldap.__version__==__version__, \
ImportError('ldap %s and _ldap %s version mismatch!' % (__version__,_ldap.__version__))
import ldap
from ldap.controls import RequestControl,LDAPControl,KNOWN_RESPONSE_CONTROLS
class AssertionControl(RequestControl):
"""
LDAP Assertion control, as defined in RFC 4528
filterstr
LDAP filter string specifying which assertions have to match
so that the server processes the operation
"""
controlType = ldap.CONTROL_ASSERT
def __init__(self,criticality=True,filterstr='(objectClass=*)'):
self.criticality = criticality
self.filterstr = filterstr
def encodeControlValue(self):
return _ldap.encode_assertion_control(self.filterstr)
KNOWN_RESPONSE_CONTROLS[ldap.CONTROL_ASSERT] = AssertionControl
class MatchedValuesControl(RequestControl):
"""
LDAP Matched Values control, as defined in RFC 3876
filterstr
LDAP filter string specifying which attribute values
should be returned
"""
controlType = ldap.CONTROL_VALUESRETURNFILTER
def __init__(self,criticality=False,filterstr='(objectClass=*)'):
self.criticality = criticality
self.filterstr = filterstr
def encodeControlValue(self):
return _ldap.encode_valuesreturnfilter_control(self.filterstr)
KNOWN_RESPONSE_CONTROLS[ldap.CONTROL_VALUESRETURNFILTER] = MatchedValuesControl
class SimplePagedResultsControl(LDAPControl):
"""
LDAP Control Extension for Simple Paged Results Manipulation
size
Page size requested (number of entries to be returned)
cookie
Cookie string received with last page
"""
controlType = ldap.CONTROL_PAGEDRESULTS
def __init__(self,criticality=False,size=None,cookie=None):
self.criticality = criticality
self.size,self.cookie = size,cookie
def encodeControlValue(self):
return _ldap.encode_page_control(self.size,self.cookie)
def decodeControlValue(self,encodedControlValue):
self.size,self.cookie = _ldap.decode_page_control(encodedControlValue)
KNOWN_RESPONSE_CONTROLS[ldap.CONTROL_PAGEDRESULTS] = SimplePagedResultsControl

View File

@ -1,82 +0,0 @@
# -*- coding: utf-8 -*-
"""
ldap.controls.openldap - classes for OpenLDAP-specific controls
See https://www.python-ldap.org/ for project details.
"""
import ldap.controls
from ldap.controls import ValueLessRequestControl,ResponseControl
from pyasn1.type import univ
from pyasn1.codec.ber import decoder
__all__ = [
'SearchNoOpControl',
'SearchNoOpMixIn',
]
class SearchNoOpControl(ValueLessRequestControl,ResponseControl):
"""
No-op control attached to search operations implementing sort of a
count operation
see https://www.openldap.org/its/index.cgi?findid=6598
"""
controlType = '1.3.6.1.4.1.4203.666.5.18'
def __init__(self,criticality=False):
self.criticality = criticality
class SearchNoOpControlValue(univ.Sequence):
pass
def decodeControlValue(self,encodedControlValue):
decodedValue,_ = decoder.decode(encodedControlValue,asn1Spec=self.SearchNoOpControlValue())
self.resultCode = int(decodedValue[0])
self.numSearchResults = int(decodedValue[1])
self.numSearchContinuations = int(decodedValue[2])
ldap.controls.KNOWN_RESPONSE_CONTROLS[SearchNoOpControl.controlType] = SearchNoOpControl
class SearchNoOpMixIn:
"""
Mix-in class to be used with class LDAPObject and friends.
It adds a convenience method noop_search_st() to LDAPObject
for easily using the no-op search control.
"""
def noop_search_st(self,base,scope=ldap.SCOPE_SUBTREE,filterstr='(objectClass=*)',timeout=-1):
try:
msg_id = self.search_ext(
base,
scope,
filterstr=filterstr,
attrlist=['1.1'],
timeout=timeout,
serverctrls=[SearchNoOpControl(criticality=True)],
)
_,_,_,search_response_ctrls = self.result3(msg_id,all=1,timeout=timeout)
except (
ldap.TIMEOUT,
ldap.TIMELIMIT_EXCEEDED,
ldap.SIZELIMIT_EXCEEDED,
ldap.ADMINLIMIT_EXCEEDED
) as e:
self.abandon(msg_id)
raise e
else:
noop_srch_ctrl = [
c
for c in search_response_ctrls
if c.controlType==SearchNoOpControl.controlType
]
if noop_srch_ctrl:
return noop_srch_ctrl[0].numSearchResults,noop_srch_ctrl[0].numSearchContinuations
else:
return (None,None)

View File

@ -1,50 +0,0 @@
# -*- coding: utf-8 -*-
"""
ldap.controls.paged - classes for Simple Paged control
(see RFC 2696)
See https://www.python-ldap.org/ for project details.
"""
__all__ = [
'SimplePagedResultsControl'
]
# Imports from python-ldap 2.4+
import ldap.controls
from ldap.controls import RequestControl,ResponseControl,KNOWN_RESPONSE_CONTROLS
# Imports from pyasn1
from pyasn1.type import tag,namedtype,univ,constraint
from pyasn1.codec.ber import encoder,decoder
from pyasn1_modules.rfc2251 import LDAPString
class PagedResultsControlValue(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('size',univ.Integer()),
namedtype.NamedType('cookie',LDAPString()),
)
class SimplePagedResultsControl(RequestControl,ResponseControl):
controlType = '1.2.840.113556.1.4.319'
def __init__(self,criticality=False,size=10,cookie=''):
self.criticality = criticality
self.size = size
self.cookie = cookie or ''
def encodeControlValue(self):
pc = PagedResultsControlValue()
pc.setComponentByName('size',univ.Integer(self.size))
pc.setComponentByName('cookie',LDAPString(self.cookie))
return encoder.encode(pc)
def decodeControlValue(self,encodedControlValue):
decodedValue,_ = decoder.decode(encodedControlValue,asn1Spec=PagedResultsControlValue())
self.size = int(decodedValue.getComponentByName('size'))
self.cookie = bytes(decodedValue.getComponentByName('cookie'))
KNOWN_RESPONSE_CONTROLS[SimplePagedResultsControl.controlType] = SimplePagedResultsControl

View File

@ -1,91 +0,0 @@
# -*- coding: utf-8 -*-
"""
ldap.controls.ppolicy - classes for Password Policy controls
(see https://tools.ietf.org/html/draft-behera-ldap-password-policy)
See https://www.python-ldap.org/ for project details.
"""
__all__ = [
'PasswordPolicyControl'
]
# Imports from python-ldap 2.4+
from ldap.controls import (
ResponseControl, ValueLessRequestControl, KNOWN_RESPONSE_CONTROLS
)
# Imports from pyasn1
from pyasn1.type import tag,namedtype,namedval,univ,constraint
from pyasn1.codec.der import decoder
class PasswordPolicyWarning(univ.Choice):
componentType = namedtype.NamedTypes(
namedtype.NamedType('timeBeforeExpiration',univ.Integer().subtype(
implicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatSimple,0)
)),
namedtype.NamedType('graceAuthNsRemaining',univ.Integer().subtype(
implicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatSimple,1)
)),
)
class PasswordPolicyError(univ.Enumerated):
namedValues = namedval.NamedValues(
('passwordExpired',0),
('accountLocked',1),
('changeAfterReset',2),
('passwordModNotAllowed',3),
('mustSupplyOldPassword',4),
('insufficientPasswordQuality',5),
('passwordTooShort',6),
('passwordTooYoung',7),
('passwordInHistory',8)
)
subtypeSpec = univ.Enumerated.subtypeSpec + constraint.SingleValueConstraint(0,1,2,3,4,5,6,7,8)
class PasswordPolicyResponseValue(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.OptionalNamedType(
'warning',
PasswordPolicyWarning().subtype(
implicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatSimple,0)
),
),
namedtype.OptionalNamedType(
'error',PasswordPolicyError().subtype(
implicitTag=tag.Tag(tag.tagClassContext,tag.tagFormatSimple,1)
)
),
)
class PasswordPolicyControl(ValueLessRequestControl,ResponseControl):
controlType = '1.3.6.1.4.1.42.2.27.8.5.1'
def __init__(self,criticality=False):
self.criticality = criticality
def decodeControlValue(self,encodedControlValue):
ppolicyValue,_ = decoder.decode(encodedControlValue,asn1Spec=PasswordPolicyResponseValue())
self.timeBeforeExpiration = None
self.graceAuthNsRemaining = None
self.error = None
warning = ppolicyValue.getComponentByName('warning')
if warning.hasValue():
if 'timeBeforeExpiration' in warning:
self.timeBeforeExpiration = int(
warning.getComponentByName('timeBeforeExpiration'))
if 'graceAuthNsRemaining' in warning:
self.graceAuthNsRemaining = int(
warning.getComponentByName('graceAuthNsRemaining'))
error = ppolicyValue.getComponentByName('error')
if error.hasValue():
self.error = int(error)
KNOWN_RESPONSE_CONTROLS[PasswordPolicyControl.controlType] = PasswordPolicyControl

View File

@ -1,130 +0,0 @@
# -*- coding: utf-8 -*-
"""
ldap.controls.psearch - classes for Persistent Search Control
(see https://tools.ietf.org/html/draft-ietf-ldapext-psearch)
See https://www.python-ldap.org/ for project details.
"""
__all__ = [
'PersistentSearchControl',
'EntryChangeNotificationControl',
'CHANGE_TYPES_INT',
'CHANGE_TYPES_STR',
]
# Imports from python-ldap 2.4+
import ldap.controls
from ldap.controls import RequestControl,ResponseControl,KNOWN_RESPONSE_CONTROLS
# Imports from pyasn1
from pyasn1.type import namedtype,namedval,univ,constraint
from pyasn1.codec.ber import encoder,decoder
from pyasn1_modules.rfc2251 import LDAPDN
#---------------------------------------------------------------------------
# Constants and classes for Persistent Search Control
#---------------------------------------------------------------------------
CHANGE_TYPES_INT = {
'add':1,
'delete':2,
'modify':4,
'modDN':8,
}
CHANGE_TYPES_STR = {v: k for k,v in CHANGE_TYPES_INT.items()}
class PersistentSearchControl(RequestControl):
"""
Implements the request control for persistent search.
changeTypes
List of strings specifying the types of changes returned by the server.
Setting to None requests all changes.
changesOnly
Boolean which indicates whether only changes are returned by the server.
returnECs
Boolean which indicates whether the server should return an
Entry Change Notification response control
"""
class PersistentSearchControlValue(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('changeTypes',univ.Integer()),
namedtype.NamedType('changesOnly',univ.Boolean()),
namedtype.NamedType('returnECs',univ.Boolean()),
)
controlType = "2.16.840.1.113730.3.4.3"
def __init__(self,criticality=True,changeTypes=None,changesOnly=False,returnECs=True):
self.criticality,self.changesOnly,self.returnECs = \
criticality,changesOnly,returnECs
self.changeTypes = changeTypes or CHANGE_TYPES_INT.values()
def encodeControlValue(self):
if not type(self.changeTypes)==type(0):
# Assume a sequence type of integers to be OR-ed
changeTypes_int = 0
for ct in self.changeTypes:
changeTypes_int = changeTypes_int|CHANGE_TYPES_INT.get(ct,ct)
self.changeTypes = changeTypes_int
p = self.PersistentSearchControlValue()
p.setComponentByName('changeTypes',univ.Integer(self.changeTypes))
p.setComponentByName('changesOnly',univ.Boolean(self.changesOnly))
p.setComponentByName('returnECs',univ.Boolean(self.returnECs))
return encoder.encode(p)
class ChangeType(univ.Enumerated):
namedValues = namedval.NamedValues(
('add',1),
('delete',2),
('modify',4),
('modDN',8),
)
subtypeSpec = univ.Enumerated.subtypeSpec + constraint.SingleValueConstraint(1,2,4,8)
class EntryChangeNotificationValue(univ.Sequence):
componentType = namedtype.NamedTypes(
namedtype.NamedType('changeType',ChangeType()),
namedtype.OptionalNamedType('previousDN', LDAPDN()),
namedtype.OptionalNamedType('changeNumber',univ.Integer()),
)
class EntryChangeNotificationControl(ResponseControl):
"""
Implements the response control for persistent search.
Class attributes with values extracted from the response control:
changeType
String indicating the type of change causing this result to be
returned by the server
previousDN
Old DN of the entry in case of a modrdn change
changeNumber
A change serial number returned by the server (optional).
"""
controlType = "2.16.840.1.113730.3.4.7"
def decodeControlValue(self,encodedControlValue):
ecncValue,_ = decoder.decode(encodedControlValue,asn1Spec=EntryChangeNotificationValue())
self.changeType = int(ecncValue.getComponentByName('changeType'))
previousDN = ecncValue.getComponentByName('previousDN')
if previousDN.hasValue():
self.previousDN = str(previousDN)
else:
self.previousDN = None
changeNumber = ecncValue.getComponentByName('changeNumber')
if changeNumber.hasValue():
self.changeNumber = int(changeNumber)
else:
self.changeNumber = None
return (self.changeType,self.previousDN,self.changeNumber)
KNOWN_RESPONSE_CONTROLS[EntryChangeNotificationControl.controlType] = EntryChangeNotificationControl

View File

@ -1,40 +0,0 @@
# -*- coding: utf-8 -*-
"""
ldap.controls.pwdpolicy - classes for Password Policy controls
(see https://tools.ietf.org/html/draft-vchu-ldap-pwd-policy)
See https://www.python-ldap.org/ for project details.
"""
__all__ = [
'PasswordExpiringControl',
'PasswordExpiredControl',
]
# Imports from python-ldap 2.4+
import ldap.controls
from ldap.controls import RequestControl,ResponseControl,ValueLessRequestControl,KNOWN_RESPONSE_CONTROLS
class PasswordExpiringControl(ResponseControl):
"""
Indicates time in seconds when password will expire
"""
controlType = '2.16.840.1.113730.3.4.5'
def decodeControlValue(self,encodedControlValue):
self.gracePeriod = int(encodedControlValue)
KNOWN_RESPONSE_CONTROLS[PasswordExpiringControl.controlType] = PasswordExpiringControl
class PasswordExpiredControl(ResponseControl):
"""
Indicates that password is expired
"""
controlType = '2.16.840.1.113730.3.4.4'
def decodeControlValue(self,encodedControlValue):
self.passwordExpired = encodedControlValue=='0'
KNOWN_RESPONSE_CONTROLS[PasswordExpiredControl.controlType] = PasswordExpiredControl

View File

@ -1,88 +0,0 @@
# -*- coding: utf-8 -*-
"""
ldap.controls.readentry - classes for the Read Entry controls
(see RFC 4527)
See https://www.python-ldap.org/ for project details.
"""
import ldap
from pyasn1.codec.ber import encoder,decoder
from ldap.controls import LDAPControl,KNOWN_RESPONSE_CONTROLS
from pyasn1_modules.rfc2251 import AttributeDescriptionList,SearchResultEntry
class ReadEntryControl(LDAPControl):
"""
Base class for read entry control described in RFC 4527
attrList
list of attribute type names requested
Class attributes with values extracted from the response control:
dn
string holding the distinguished name of the LDAP entry
entry
dictionary holding the LDAP entry
"""
def __init__(self,criticality=False,attrList=None):
self.criticality,self.attrList,self.entry = criticality,attrList or [],None
def encodeControlValue(self):
attributeSelection = AttributeDescriptionList()
for i in range(len(self.attrList)):
attributeSelection.setComponentByPosition(i,self.attrList[i])
return encoder.encode(attributeSelection)
def decodeControlValue(self,encodedControlValue):
decodedEntry,_ = decoder.decode(encodedControlValue,asn1Spec=SearchResultEntry())
self.dn = str(decodedEntry[0])
self.entry = {}
for attr in decodedEntry[1]:
self.entry[str(attr[0])] = [ str(attr_value) for attr_value in attr[1] ]
class PreReadControl(ReadEntryControl):
"""
Class for pre-read control described in RFC 4527
attrList
list of attribute type names requested
Class attributes with values extracted from the response control:
dn
string holding the distinguished name of the LDAP entry
before the operation was done by the server
entry
dictionary holding the LDAP entry
before the operation was done by the server
"""
controlType = ldap.CONTROL_PRE_READ
KNOWN_RESPONSE_CONTROLS[PreReadControl.controlType] = PreReadControl
class PostReadControl(ReadEntryControl):
"""
Class for post-read control described in RFC 4527
attrList
list of attribute type names requested
Class attributes with values extracted from the response control:
dn
string holding the distinguished name of the LDAP entry
after the operation was done by the server
entry
dictionary holding the LDAP entry
after the operation was done by the server
"""
controlType = ldap.CONTROL_POST_READ
KNOWN_RESPONSE_CONTROLS[PostReadControl.controlType] = PostReadControl

Some files were not shown because too many files have changed in this diff Show More