473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

working with ldap files

Hello All,

I am struggling with some ldap files.

I am using the csv module to work with this files (I exported the ldap
to a csv file).
I have this string on a field
CN=pointhairedpeoplethatsux,OU=Groups,OU=Hatepeopl e,OU=HR,DC=fabrika,DC=com;CN=pointhairedboss,OU=Gr oups,OU=Hatepeople,OU=HR,DC=fabrika,DC=com
this string is all the groups one user has membership.
So what I am trying to do.
read this string
and extract only the CNs

like

pointhairdepeoplethatsux,pointhairedboss

Or think in negative way
remove the OU=****** and DC= ******

Any ideas?

Sep 1 '06 #1
3 2363
I have this string on a field
CN=pointhairedpeoplethatsux,OU=Groups,OU=Hatepeopl e,OU=HR,DC=fabrika,DC=com;CN=pointhairedboss,OU=Gr oups,OU=Hatepeople,OU=HR,DC=fabrika,DC=com
this string is all the groups one user has membership.
So what I am trying to do.
read this string
and extract only the CNs

like

pointhairdepeoplethatsux,pointhairedboss
>>s =
"CN=pointhairedpeoplethatsux,OU=Groups,OU=Hatepeop le,OU=HR,DC=fabrika,DC=com;CN=pointhairedboss,OU=G roups,OU=Hatepeople,OU=HR,DC=fabrika,DC=com"
>>pieces = sum([p.split(';') for p in s.split(',')], [])
pieces
['CN=pointhairedpeoplethatsux', 'OU=Groups', 'OU=Hatepeople',
'OU=HR', 'DC=fabrika', 'DC=com', 'CN=pointhairedboss',
'OU=Groups', 'OU=Hatepeople', 'OU=HR', 'DC=fabrika', 'DC=com']
>>pieces = sum([p.split(';') for p in s.split(',')], [])
cns = [piece[3:] for piece in pieces if piece.startswith('CN=')]
cns
['pointhairedpeoplethatsux', 'pointhairedboss']
The process basically splits on commas, then splits each of those
pieces on semi-colons, then flattens the list-of-lists into a
single list of all the pieces (the flattening is done by abusing
sum() so there may be better, more elegant ways of doing that).
Once you have the flattened list of pieces, you can then just
check for the ones that start with "CN=" and extract the bits of
them that you need.

-tkc


Sep 1 '06 #2
>I have this string on a field
>CN=pointhairedpeoplethatsux,OU=Groups,OU=Hatepeop le,OU=HR,DC=fabrika,DC=com;CN=pointhairedboss,OU=G roups,OU=Hatepeople,OU=HR,DC=fabrika,DC=com
this string is all the groups one user has membership.
So what I am trying to do.
read this string
and extract only the CNs

like

pointhairdepeoplethatsux,pointhairedboss
>>s =
"CN=pointhairedpeoplethatsux,OU=Groups,OU=Hatepeop le,OU=HR,DC=fabrika,DC=com;CN=pointhairedboss,OU=G roups,OU=Hatepeople,OU=HR,DC=fabrika,DC=com"
Or, if you're a regexp junkie...
>>import re
r = re.compile('CN=([^;,]*)')
r.findall(s)
['pointhairedpeoplethatsux', 'pointhairedboss']

I'll leave timing comparisons as an exercise to the reader... ;)

Both of these solutions make the assumption that neither a comma
nor a semicolon are permissible in a CN.

-tkc

Sep 1 '06 #3
flit wrote:
>
I am struggling with some ldap files.
More general you are struggling with multiple attribute values of DN
syntax stored in a single field of a CSV file.
I am using the csv module to work with this files (I exported the ldap
to a csv file).
I guess you have MS AD and used MS tools for CSV export.
I have this string on a field
CN=pointhairedpeoplethatsux,OU=Groups,OU=Hatepeopl e,OU=HR,DC=fabrika,DC=com;CN=pointhairedboss,OU=Gr oups,OU=Hatepeople,OU=HR,DC=fabrika,DC=com
this string is all the groups one user has membership.
It seems they are using ; as a delimiter for multi-valued attributes in
a single CSV field. Note that ; is also a special character for
LDAPv2-DNs. So a naive parsing will fail under special circumstances.

I'd recommend to export your data as LDIF and use the module 'ldif' from
python-ldap to extract the entry records. You can use this module
separately simply by placing the file ldif.py under site-packages/ if
you don't need the rest of python-ldap.
So what I am trying to do.
read this string
and extract only the CNs
This is another issue.

Note that in general DN parsing is more complex than simply using
string.split(). If you are sure that all the attribute values used in
your DNs don't have any special chars you could use string.split(). But
you should definitely cross-check with RFC 4514 or use a decent DN parser.

Ciao, Michael.
Sep 4 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Willis Lang | last post by:
I'm getting Access Denied error. I've had this for oci8 and I fixed it by giving IUSER read access to the entire oracle directory. For the ldap problem, I've put the ssleay and the libeay dlls...
1
by: Joe User | last post by:
I have a set of web pages on an AD-authenticated web site that are supposed to allow users to modify their own AD account attributes, limited of course to things like their email address, URL, etc....
3
by: jeremy | last post by:
Hello. I have an asp.net application that resides on a non-DC / BDC Sharepoint Server (although it is logged into the domain). The application will perform lookups based on the current user...
2
by: Jean-Marie Vaneskahian | last post by:
Reading - Parsing Records From An LDAP LDIF File In .Net? I am in need of a .Net class that will allow for the parsing of a LDAP LDIF file. An LDIF file is the standard format for representing...
1
by: rcmn | last post by:
i'm running around in circle trying to to use python/ldap/ on win32(WinXP). I want to write a script that read SQL data(no pbm) and insert member in a AD group(pbm).I used the module...
10
by: Cruelemort | last post by:
All, I am hoping someone would be able to help me with a problem. I have an LDAP server running on a linux box, this LDAP server contains a telephone list in various groupings, the ldif file of...
7
by: MrHelpMe | last post by:
Sorry everyone, NOTE: I have posted this question to another site but unfortunately, am not getting the answers I need only because those helping haven't worked with ASP. I am in desperate...
3
by: thegainer | last post by:
hi all, I am new to this forum. I did some small projects in php using mysql connectivity. I used wamp for this. latform is windows XP and wamp is installed. I have no idea about LDAP. I know only...
0
by: Sells, Fred | last post by:
I'm running python 2.5 (or 2.4) in an XP environment. I downloaded and installed the .dll's from OpenLDAP-2.4.8+OpenSSL-0.9.8g-Win32.zip and copied the .dll's in c:/windows/system32 as instructed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.