From: Zhang H. <zhb...@gm...> - 2009-05-14 09:33:24
|
Hi, all. Does anyone has working code snippet of server/client side sorting? I use serverctrls in search_ext_s() like this: search_ext_s(xxxx, serverctrls = [ ldap.controls.LDAPControl('1.2.840.113556.1.4.473',1,None) ],) got error msg: UNAVAILABLE_CRITICAL_EXTENSION: {'info': 'critical extension is not recognized', 'desc': 'Critical extension is unavailable'} * Use clientctrls: search_ext_s(xxxx, clientctrls = [ ldap.controls.LDAPControl('1.2.840.113556.1.4.473',1,None) ],) got error msg: NOT_SUPPORTED: {'info': '', 'desc': 'Not Supported'} My os is Ubuntu 9.04, OpenLDAP-2.4.15-1ubuntu3. -- Best regards. Zhang Huangbin - Open Source Mail Server Solution for RHEL, CentOS, Debian: http://code.google.com/p/iredmail/ |
From: Michael S. <mi...@st...> - 2009-05-14 09:46:38
|
Zhang Huangbin wrote: > > Does anyone has working code snippet of server/client side sorting? > > I use serverctrls in search_ext_s() like this: > > search_ext_s(xxxx, serverctrls = [ > ldap.controls.LDAPControl('1.2.840.113556.1.4.473',1,None) ],) > > got error msg: > > UNAVAILABLE_CRITICAL_EXTENSION: {'info': 'critical extension is not > recognized', 'desc': 'Critical extension is unavailable'} > > * Use clientctrls: > > search_ext_s(xxxx, clientctrls = [ > ldap.controls.LDAPControl('1.2.840.113556.1.4.473',1,None) ],) > > got error msg: > > NOT_SUPPORTED: {'info': '', 'desc': 'Not Supported'} > > My os is Ubuntu 9.04, OpenLDAP-2.4.15-1ubuntu3. The error message is pretty clear: This particular LDAP server does not support server-side sorting. Besides that you should read RFC 2891 to learn how to generate the controlValue which specifies which attribute and matching rule (optional) is used for sorting and whether you want reverse order (optional). You could try to generate the controlValue with module pyasn1. Ciao, Michael. |
From: Zhang H. <zhb...@gm...> - 2009-05-14 12:37:29
|
Michael Ströder wrote: > > The error message is pretty clear: This particular LDAP server does not > support server-side sorting. > I checked the rootdse, neither server side sort nor client side sort is supported: ---- supportedControl: 2.16.840.1.113730.3.4.18 supportedControl: 2.16.840.1.113730.3.4.2 supportedControl: 1.3.6.1.4.1.4203.1.10.1 supportedControl: 1.2.840.113556.1.4.319 supportedControl: 1.2.826.0.1.3344810.2.3 supportedControl: 1.3.6.1.1.13.2 supportedControl: 1.3.6.1.1.13.1 supportedControl: 1.3.6.1.1.12 supportedExtension: 1.3.6.1.4.1.1466.20037 supportedExtension: 1.3.6.1.4.1.4203.1.11.1 supportedExtension: 1.3.6.1.4.1.4203.1.11.3 supportedExtension: 1.3.6.1.1.8 ---- > Besides that you should read RFC 2891 to learn how to generate the > controlValue which specifies which attribute and matching rule > (optional) is used for sorting and whether you want reverse order > (optional). You could try to generate the controlValue with module pyasn1. Got it. Thanks Michael :) -- Best regards. Zhang Huangbin - Open Source Mail Server Solution for RHEL, CentOS, Debian: http://code.google.com/p/iredmail/ |
From: Michael S. <mi...@st...> - 2009-05-14 12:54:35
|
Zhang Huangbin wrote: > Michael Ströder wrote: >> The error message is pretty clear: This particular LDAP server does not >> support server-side sorting. > > I checked the rootdse, neither server side sort nor client side sort is > supported: 1. Client-side sorting is done within the client libs if supported. So it wouldn't be listed in the attribute 'supportedControl' of the DSA's rootDSE anyway. Not sure whether client controls are used in OpenLDAP's libldap at all. 2. One should always try out whether a DSA supports a particular control within a certain naming context. E.g. former versions of OpenLDAP supported the Tree Deletion Control only for naming contexts served by back-sql. Feature detection is not that easy. > supportedControl: 2.16.840.1.113730.3.4.18 > supportedControl: 2.16.840.1.113730.3.4.2 > supportedControl: 1.3.6.1.4.1.4203.1.10.1 > supportedControl: 1.2.840.113556.1.4.319 > supportedControl: 1.2.826.0.1.3344810.2.3 > supportedControl: 1.3.6.1.1.13.2 > supportedControl: 1.3.6.1.1.13.1 > supportedControl: 1.3.6.1.1.12 > supportedExtension: 1.3.6.1.4.1.1466.20037 > supportedExtension: 1.3.6.1.4.1.4203.1.11.1 > supportedExtension: 1.3.6.1.4.1.4203.1.11.3 > supportedExtension: 1.3.6.1.1.8 Everyone tired of looking up the OIDs should use my http://web2ldap.de since it contains a registry of OIDs with descriptions of the meaning which are displayed when displaying the rootDSE. Ciao, Michael. |
From: Zhang H. <zhb...@gm...> - 2009-05-14 13:08:56
|
Michael Ströder wrote: > > 1. Client-side sorting is done within the client libs if supported. So > it wouldn't be listed in the attribute 'supportedControl' of the DSA's > rootDSE anyway. Not sure whether client controls are used in OpenLDAP's > libldap at all. > Any exist python module/function to sort ldap search results? > 2. One should always try out whether a DSA supports a particular control > within a certain naming context. E.g. former versions of OpenLDAP > supported the Tree Deletion Control only for naming contexts served by > back-sql. > > Feature detection is not that easy. > I also need function to delete ldap tree too, and reading your web2ldap/pylib/ldapsession.py now. > Everyone tired of looking up the OIDs should use my http://web2ldap.de > since it contains a registry of OIDs with descriptions of the meaning > which are displayed when displaying the rootDSE. I found it moment ago. :) Tring to learn ldap programing from web2ldap now. Thanks for your great program. :) -- Best regards. Zhang Huangbin - Open Source Mail Server Solution for RHEL, CentOS, Debian: http://code.google.com/p/iredmail/ |
From: Michael S. <mi...@st...> - 2009-05-14 13:18:52
|
Zhang Huangbin wrote: > Michael Ströder wrote: >> 1. Client-side sorting is done within the client libs if supported. So >> it wouldn't be listed in the attribute 'supportedControl' of the DSA's >> rootDSE anyway. Not sure whether client controls are used in OpenLDAP's >> libldap at all. > > Any exist python module/function to sort ldap search results? Well, why do you really need that? I don't have client-side sorting in web2ldap because it won't scale with large search results. Some of my customers have more than 100k person/user entries in their directories. >> 2. One should always try out whether a DSA supports a particular control >> within a certain naming context. E.g. former versions of OpenLDAP >> supported the Tree Deletion Control only for naming contexts served by >> back-sql. >> >> Feature detection is not that easy. > > I also need function to delete ldap tree too, and reading your > web2ldap/pylib/ldapsession.py now. The function DelTree() is in pylib/w2lapp/delete.py. If the tree deletion control cannot or shall not be used it also makes use of some operational attributes (e.g. hasSubordinates etc.) to determine whether a found entry is a leaf-entry. > Tring to learn ldap programing from web2ldap now. Thanks for your great > program. :) Bear in mind that I started learning Python when the first code was written almost 11 years ago. So I have to admit that many parts are really ugly code and not really good programming examples. Ciao, Michael. |
From: Zhang H. <zhb...@gm...> - 2009-05-14 14:02:27
|
Michael Ströder wrote: > Zhang Huangbin wrote: > >> Any exist python module/function to sort ldap search results? > > Well, why do you really need that? I don't have client-side sorting in > web2ldap because it won't scale with large search results. Some of my > customers have more than 100k person/user entries in their directories. > I have 100+ accounts in LDAP, but they are not listed orderly. like this: dn: mail=www2@xxx,---- dn: mail=www5@xxx,---- dn: mail=www3@xxx,---- dn: mail=www@xxx,---- I just want to make them listed orderly like this: dn: mail=www@xxx,---- dn: mail=www2@xxx,---- dn: mail=www3@xxx,---- dn: mail=www5@xxx,---- Do you make them listed in the original order? >> Tring to learn ldap programing from web2ldap now. Thanks for your great >> program. :) >> > > Bear in mind that I started learning Python when the first code was > written almost 11 years ago. So I have to admit that many parts are > really ugly code and not really good programming examples. Got it. thanks for your remind :) -- Best regards. Zhang Huangbin - Open Source Mail Server Solution for RHEL, CentOS, Debian: http://code.google.com/p/iredmail/ |
From: Michael S. <mi...@st...> - 2009-05-14 14:10:43
|
Zhang Huangbin wrote: > Michael Ströder wrote: >> Zhang Huangbin wrote: >> >>> Any exist python module/function to sort ldap search results? >> Well, why do you really need that? I don't have client-side sorting in >> web2ldap because it won't scale with large search results. Some of my >> customers have more than 100k person/user entries in their directories. >> > > I have 100+ accounts in LDAP, but they are not listed orderly. 100+ entries are not so many. So you could try sorting the list of search results retrieved with LDAPObject.ldap_search_ext_s() by invoking list method .sort(). Make sure you understand how to control the comparisons. See item 8. here: http://docs.python.org/library/stdtypes.html#index-591 Ciao, Michael. |
From: Zhang H. <zhb...@gm...> - 2009-05-14 16:17:29
|
Michael Ströder wrote: > > 100+ entries are not so many. So you could try sorting the list of > search results retrieved with LDAPObject.ldap_search_ext_s() by invoking > list method .sort(). Make sure you understand how to control the > comparisons. > > See item 8. here: > http://docs.python.org/library/stdtypes.html#index-591 > No idea yet. Any example? Thanks :) -- Best regards. Zhang Huangbin - Open Source Mail Server Solution for RHEL, CentOS, Debian: http://code.google.com/p/iredmail/ |
From: Michael S. <mi...@st...> - 2009-05-14 17:05:58
|
Zhang Huangbin wrote: > Michael Ströder wrote: >> 100+ entries are not so many. So you could try sorting the list of >> search results retrieved with LDAPObject.ldap_search_ext_s() by invoking >> list method .sort(). Make sure you understand how to control the >> comparisons. >> >> See item 8. here: >> http://docs.python.org/library/stdtypes.html#index-591 >> > > No idea yet. Any example? Bear in mind search results returned by synchronous search methods are in a list of 2-tuples each consisting of the DN string and the entry dictionary like this: [(dn,entry)] Without testing just as food for thought: Compare function for case-insensitive comparison of the DN: cmp=lambda x,y: cmp(x[0].lower(), y[0}.lower()) Compare function for case-insensitive comparison of the first attribute value of 'cn' (this would choke with KeyError exception if there's no attribute 'cn' in the entry): cmp=lambda x,y: cmp(x[1]['cn'][0].lower(), y[1]['cn'][0].lower()) And then results.sort(cmp). I don't know how fast this is though. The rest of the homework is up to you. For various list sorting aspects you should ask in news:comp.lang.python Ciao, Michael. |
From: Zhang H. <zhb...@gm...> - 2009-05-15 03:04:44
|
Michael Ströder wrote: > > Compare function for case-insensitive comparison of the DN: > > cmp=lambda x,y: cmp(x[0].lower(), y[0}.lower()) > > Thanks Michael. :) I tried this compare function, but got this err msg: ---- RuntimeError: maximum recursion depth exceeded ---- The result contains less than 10 records. -- Best regards. Zhang Huangbin - Open Source Mail Server Solution for RHEL, CentOS, Debian: http://code.google.com/p/iredmail/ |
From: Zhang H. <zhb...@gm...> - 2009-05-15 12:45:15
|
Michael Ströder wrote: > > Sorry, there's a typo in there: > > cmp=lambda x,y: cmp(x[0].lower(), y[0}.lower()) > ^ > Should be ] I found that before, but got the same error: >>> alist [('mail=postmaster@a.cn,o=domainAdmins,dc=iredmail,dc=org', {'mail': ['postmaster@a.cn'], 'accountStatus': ['active'], 'enabledService': ['awstats'], 'domainGlobalAdmin': ['yes']}), ('mail=www@a.cn,o=domainAdmins,dc=iredmail,dc=org', {'mail': ['www@a.cn'], 'accountStatus': ['active'], 'domainGlobalAdmin': ['yes']}), ('mail=www5@a.cn,o=domainAdmins,dc=iredmail,dc=org', {'mail': ['www5@a.cn'], 'accountStatus': ['active'], 'domainGlobalAdmin': ['no']}), ('mail=www3@a.cn,o=domainAdmins,dc=iredmail,dc=org', {'mail': ['www3@a.cn'], 'accountStatus': ['active'], 'domainGlobalAdmin': ['no']})] >>> cmp=lambda x,y: cmp(x[0].lower(), y[0].lower()) >>> alist.sort(cmp) Traceback (most recent call last): File "<stdin>", line 1, in ? File "<stdin>", line 1, in <lambda> File "<stdin>", line 1, in <lambda> File "<stdin>", line 1, in <lambda> File "<stdin>", line 1, in <lambda> File "<stdin>", line 1, in <lambda> File "<stdin>", line 1, in <lambda> File "<stdin>", line 1, in <lambda> File "<stdin>", line 1, in <lambda> ...... SKIP MANY LINES HERE ...... File "<stdin>", line 1, in <lambda> File "<stdin>", line 1, in <lambda> File "<stdin>", line 1, in <lambda> File "<stdin>", line 1, in <lambda> RuntimeError: maximum recursion depth exceeded -- Best regards. Zhang Huangbin - Open Source Mail Server Solution for RHEL, CentOS, Debian: http://code.google.com/p/iredmail/ |
From: Michael S. <mi...@st...> - 2009-05-15 13:02:55
|
Zhang Huangbin wrote: > >>> cmp=lambda x,y: cmp(x[0].lower(), y[0].lower()) > > >>> alist.sort(cmp) Ouch! One should probably not mask the standard function name cmp. So try this: mycmp=lambda x,y: cmp(x[0].lower(), y[0].lower()) alist.sort(mycmp) Ciao, Michael. |
From: Zhang H. <zhb...@gm...> - 2009-05-15 14:08:11
|
Michael Ströder wrote: > mycmp=lambda x,y: cmp(x[0].lower(), y[0].lower()) > alist.sort(mycmp) I found this and solved too. Big thanks :) -- Best regards. Zhang Huangbin - Open Source Mail Server Solution for RHEL, CentOS, Debian: http://code.google.com/p/iredmail/ |
From: Michael S. <mi...@st...> - 2009-05-15 08:56:58
|
Zhang Huangbin wrote: > Michael Ströder wrote: >> Compare function for case-insensitive comparison of the DN: >> >> cmp=lambda x,y: cmp(x[0].lower(), y[0}.lower()) > > I tried this compare function, but got this err msg: Sorry, there's a typo in there: cmp=lambda x,y: cmp(x[0].lower(), y[0}.lower()) ^ Should be ] Ciao, Michael. |
From: Russell J. <ra...@cs...> - 2009-05-14 19:10:57
Attachments:
signature.asc
|
Michael Ströder wrote: > Zhang Huangbin wrote: >> Michael Ströder wrote: >> Tring to learn ldap programing from web2ldap now. Thanks for your great >> program. :) > > Bear in mind that I started learning Python when the first code was > written almost 11 years ago. So I have to admit that many parts are > really ugly code and not really good programming examples. Every programmer I've ever talked to always thinks their own code sucks. -- Russell A. Jackson <ra...@cs...> Network Analyst California State University, Bakersfield With a gentleman I try to be a gentleman and a half, and with a fraud I try to be a fraud and a half. -- Otto von Bismarck |