Skip to content
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

Allow uri and base to be taken from system/user LDAP configuration #164

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sambrightman
Copy link

The aim is to reduce the number of parameters that must be passed to
various functions to the minimal set when LDAP is correctly configured
in the environment. In my case, ldap.conf contains at least the URI
and base, and is deployed externally to relevant machines. Duplicating
the configuration in my code would be both inconvenient and more
fragile. I believe this is the case in many common setups.

I think the ideal situation would actually be to re-order some of the
method parameters. People using defaults from the system configuraiton
probably want to only specify e.g. the filter. Putting it first (with
uri/base towards the end), would allow removing the keyword in
calls. However, that is a minor inconvenience versus breaking backward
compatibility.

This is a prototype pull request - in particular:

  • I'm not familiar with python-ldap (or really with LDAP in general).
  • Docs, Demos, Tests have not been reviewed for potential updates (I
    have the impression that testing could be achieved via environment
    variables and would be willing to add tests).
  • I did not know how to treat urlfetch and am not 100% that I have caught
    all locations that could be defaulted.

@encukou
Copy link
Member

encukou commented Jan 11, 2018

A check failed because of a timeout; I restarted it.

I'm not the best person to review the feature, but if no-one else chimes in, I'll look at it next week.

@codecov
Copy link

codecov bot commented Jan 11, 2018

Codecov Report

Merging #164 into master will increase coverage by <.01%.
The diff coverage is 91.66%.

@@            Coverage Diff             @@
##           master     #164      +/-   ##
==========================================
+ Coverage   70.22%   70.22%   +<.01%     
==========================================
  Files          49       49              
  Lines        4816     4746      -70     
  Branches      810      821      +11     
==========================================
- Hits         3382     3333      -49     
+ Misses       1101     1067      -34     
- Partials      333      346      +13
Impacted Files Coverage Δ
Lib/ldap/asyncsearch.py 27.92% <ø> (ø) ⬆️
Modules/functions.c 61.66% <0%> (-0.41%) ⬇️
Lib/ldap/ldapobject.py 74.4% <100%> (ø) ⬆️
Lib/ldap/syncrepl.py 62.29% <100%> (ø) ⬆️
Modules/LDAPObject.c 67.69% <100%> (+0.84%) ⬆️
Lib/ldap/functions.py 91.11% <100%> (ø) ⬆️
Lib/ldap/controls/openldap.py 53.33% <100%> (ø) ⬆️
Modules/options.c 80.48% <0%> (-6.18%) ⬇️
Modules/ldapcontrol.c 57.69% <0%> (-1.2%) ⬇️
Modules/message.c 32.53% <0%> (-0.41%) ⬇️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9a74c29...d3c06bc. Read the comment docs.

Copy link
Member

@tiran tiran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting idea. Before this patch can land, you must come up with a test plan, some functional tests and documentation update.

Since it's a new feature, the patch is out-of-scope for 3.0 release.

@@ -1162,7 +1162,7 @@ l_ldap_search_ext( LDAPObject* self, PyObject* args )
int msgid;
int ldaperror;

if (!PyArg_ParseTuple( args, "sis|OiOOdi",
if (!PyArg_ParseTuple( args, "zis|OiOOdi",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just move the | to the left and initialize the targets with NULL/0.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's correct - as it stands, filter is stil required in this location (also, z expresses exactly what is required, doesn't it?).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make all arguments optional, too. z is correct to accept None and map it to NULL string.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only called from python-ldap Python code and that will already pass the right arguments in (with a default), so the separator can stay where it is?

@@ -748,13 +748,13 @@ def result4(self,msgid=ldap.RES_ANY,all=1,timeout=None,add_ctrls=0,add_intermedi
resp_data = self._bytesify_results(resp_data, with_ctrls=add_ctrls)
return resp_type, resp_data, resp_msgid, decoded_resp_ctrls, resp_name, resp_value

def search_ext(self,base,scope,filterstr=None,attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1,sizelimit=0):
def search_ext(self,base=None,scope=ldap.SCOPE_SUBTREE,filterstr=None,attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1,sizelimit=0):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you decide to use subtree here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the more general (for searches) and is more common in examples.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The chief example of an interface with a default for scope is ldapsearch and it picks -s sub, so this is being consistent.

@encukou
Copy link
Member

encukou commented Mar 14, 2018

Rebased on current master, as C code was recently re-formatted.

Copy link
Member

@tiran tiran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please provide a test case and a versionchanged entry for your patch?

A test case could work like this:

  • create a temporary ldap.conf file
  • Run a subprocess with an LDAP query with environment variable LDAPCONF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants