-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable LDAP module #1204
Open
damluji
wants to merge
1
commit into
SpriteLink:master
Choose a base branch
from
damluji:fix-ldap-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Enable LDAP module #1204
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,8 @@ MAINTAINER Kristian Larsson <[email protected]> | |
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
ARG myrootcert | ||
|
||
# apt update, upgrade & install packages | ||
RUN apt-get update -qy && apt-get upgrade -qy \ | ||
&& apt-get install -qy devscripts \ | ||
|
@@ -49,9 +51,16 @@ RUN apt-get update -qy && apt-get upgrade -qy \ | |
python-docutils \ | ||
python-pip \ | ||
python-dev \ | ||
libldap2-dev \ | ||
libsasl2-dev \ | ||
libssl-dev \ | ||
ca-certificates \ | ||
&& pip --no-input install envtpl \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# install cert | ||
COPY $myrootcert /usr/local/share/ca-certificates | ||
RUN update-ca-certificates | ||
|
||
COPY nipap /nipap | ||
WORKDIR /nipap | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ MAINTAINER Lukas Garberg <[email protected]> | |
|
||
ENV NIPAPD_HOST=nipapd NIPAPD_PORT=1337 WWW_USERNAME=guest WWW_PASSWORD=guest | ||
|
||
ARG myrootcert | ||
|
||
# apt update, upgrade & install packages | ||
RUN apt-get update -qy && apt-get upgrade -qy \ | ||
&& apt-get install -qy apache2 \ | ||
|
@@ -43,9 +45,17 @@ RUN apt-get update -qy && apt-get upgrade -qy \ | |
python-docutils \ | ||
python-pip \ | ||
python-dev \ | ||
libldap2-dev \ | ||
libsasl2-dev \ | ||
libssl-dev \ | ||
ca-certificates \ | ||
&& pip --no-input install envtpl \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# install cert | ||
COPY $myrootcert /usr/local/share/ca-certificates | ||
RUN update-ca-certificates | ||
|
||
# Install pynipap, nipap and nipap-www | ||
COPY pynipap /pynipap | ||
COPY nipap /nipap | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
# | ||
# Set up a wsgi environment for mod_wsgi | ||
# | ||
import os, sys, logging.config | ||
|
||
APP_CONFIG="/etc/nipap/nipap-www.ini" | ||
|
||
logging.config.fileConfig(APP_CONFIG) | ||
|
||
import os, sys | ||
os.environ['PYTHON_EGG_CACHE'] = '/var/cache/nipap-www/eggs' | ||
|
||
from paste.deploy import loadapp | ||
|
||
application = loadapp('config:/etc/nipap/nipap-www.ini') | ||
application = loadapp('config:%s' % APP_CONFIG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,17 +161,22 @@ def get_auth(self, username, password, authoritative_source, auth_options=None): | |
for key in rem: | ||
del(self._auth_cache[key]) | ||
|
||
self._logger.debug("Received username %s" % str(username)) | ||
|
||
user_authbackend = username.rsplit('@', 1) | ||
|
||
# Find out what auth backend to use. | ||
# If no auth backend was specified in username, use default | ||
# Do not use default backend unless you login as localadmin. | ||
backend = "" | ||
if len(user_authbackend) == 1: | ||
if str(username) == "localadmin": | ||
backend = self._config.get('auth', 'default_backend') | ||
self._logger.debug("Using default auth backend %s" % backend) | ||
else: | ||
backend = user_authbackend[1] | ||
|
||
if len(user_authbackend) == 1: | ||
backend = self._config.get('auth', 'secondary_backend') | ||
else: | ||
backend = user_authbackend[1] | ||
|
||
self._logger.debug("Using auth backend %s" % backend) | ||
|
||
# do we have a cached instance? | ||
auth_str = ( str(username) + str(password) + str(authoritative_source) | ||
+ str(auth_options) ) | ||
|
@@ -368,13 +373,16 @@ def authenticate(self): | |
return self._authenticated | ||
|
||
try: | ||
self._logger.debug('username %s formatted _ldap_binddn_fmt username %s' % (self.username, self._ldap_binddn_fmt.format(ldap.dn.escape_dn_chars(self.username)))) | ||
self._ldap_conn.simple_bind_s(self._ldap_binddn_fmt.format(ldap.dn.escape_dn_chars(self.username)), self.password) | ||
except ldap.SERVER_DOWN as exc: | ||
raise AuthError('Could not connect to LDAP server') | ||
self._logger.debug('Could not connect to LDAP server: %s' % exc) | ||
raise AuthError('Could not connect to LDAP server: '+str(exc)) | ||
except (ldap.INVALID_CREDENTIALS, ldap.INVALID_DN_SYNTAX, | ||
ldap.UNWILLING_TO_PERFORM) as exc: | ||
# Auth failed | ||
self._logger.debug('erroneous password for user %s' % self.username) | ||
self._logger.debug(exc) | ||
self._authenticated = False | ||
return self._authenticated | ||
|
||
|
@@ -387,11 +395,13 @@ def authenticate(self): | |
try: | ||
# Create separate connection for search? | ||
if self._ldap_search_conn is not None: | ||
self._ldap_search_conn.simple_bind(self._ldap_search_binddn, self._ldap_search_password) | ||
self._ldap_search_conn.simple_bind_s(self._ldap_search_binddn, self._ldap_search_password) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (106 > 79 characters) |
||
search_conn = self._ldap_search_conn | ||
else: | ||
search_conn = self._ldap_conn | ||
|
||
self._logger.debug('username %s formatted _ldap_search username %s' % (self.username, self._ldap_search.format(ldap.dn.escape_dn_chars(self.username)))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (164 > 79 characters) |
||
|
||
res = search_conn.search_s(self._ldap_basedn, ldap.SCOPE_SUBTREE, self._ldap_search.format(ldap.dn.escape_dn_chars(self.username)), ['cn','memberOf']) | ||
if res[0][1]['cn'][0] is not None: | ||
self.full_name = res[0][1]['cn'][0].decode('utf-8') | ||
|
@@ -417,10 +427,11 @@ def authenticate(self): | |
raise AuthError(exc) | ||
except KeyError: | ||
raise AuthError('LDAP attribute missing') | ||
except IndexError: | ||
except IndexError as exc: | ||
self.full_name = '' | ||
# authentication fails if either ro_group or rw_group are configured | ||
# and the user is not found. | ||
self._logger.debug(exc) | ||
if self._ldap_rw_group or self._ldap_ro_group: | ||
self._authenticated = False | ||
return self._authenticated | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (172 > 79 characters)