Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Using Net:LDAP' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Using Net:LDAP
Authored by: redjar on Aug 02, '04 03:07:15PM
We use OpenLDAP in a Linux environment, but I suspect that the Perl-LDAP modules will work just fine under Mac OS X. Using the modules makes manipulating LDAP data very easy. For example, here is a simple script I wrote to create a flat passwd file:

use Net::LDAP;

$ldap = Net::LDAP->new("localhost");

$ldap->bind("cn=admin,dc=domain,dc=com", password=>"secret");

$mesg = $ldap->search(filter=>"(objectclass=posixAccount)", base=>"ou=people,dc=domain,dc=com");

@entries = $mesg->entries;

foreach $entry (@entries) {
        $username = $entry->get_value(uid);
        $uidnumber = $entry->get_value(uidNumber); 
        $gidnumber = $entry->get_value(gidNumber);
        $gecos = $entry->get_value(gecos);
        $homedir = $entry->get_value(homeDirectory);
        $shell = $entry->get_value(loginShell);

	print "$username:x:$uidnumber:$gidnumber:$gecos:$homedir:$shell\n";

[ Reply to This | # ]
escape char got snarfed
Authored by: redjar on Aug 02, '04 03:09:51PM

an escape character got snarfed, the print statement at the end should have a backslash before the n. Hopefully it won't get stripped again:

print "$username:x:$uidnumber:$gidnumber:$gecos:$homedir:$shell\n";

[ Reply to This | # ]