PixieLdap - Perl extension for simple ldap functions using Net::LDAP and Net::LDAPS
use PixieLdap; my $config = 'ldap.yml';
my $filter = getInput("Enter Filter i.e uid=* : "); unless (defined $filter) { die "No Filter Specified\n"}; my $base = &GroupOrPeople; my $search = viewSearch($config, $filter, $base); if ($search){ my $answer = getInput("Dump full ldif results to /tmp/dump.ldif Y/N ? "); if ( lc $answer eq 'y'){ my $ldif = Net::LDAP::LDIF->new('/tmp/dump.ldif', 'w'); $ldif->write_entry($search->entries()); $ldif->done(); } else { my $searchstruct = $search->as_struct; foreach my $dn (keys %$searchstruct){ print $dn." "; print $searchstruct->{$dn}{cn}[0],"\n"; } } }
my $group = getInput( "Enter Group: "); unless (defined $group) { die "No Group Specified\n"}; my $uid = getInput( "Enter UserID for adding to group: "); unless (defined $uid) { die "No User ID Specified\n"}; my $add = addMember($config, $group, $uid);
my $uid = getInput("Enter UserID: "); unless (defined $uid) { die "No User ID Specified\n"}; my ($givenName, $passwd) = addUser($config, $uid, '1'); print "New User: " . $uid . " " . $givenName . " with password: " . $passwd . "\n"; You can also call the funcion and supply all the variables to use in non interactive mode if $cli=0.
my $group = getInput("Enter Group: "); unless (defined $group) { die "No Group Specified\n"}; my $gidNumber; $gidNumber = getGIDNumber($config, $group); if (defined $gidNumber){ print "Group: " . $group . " has group ID number: ". $gidNumber . "\n"; } else { print "No Such Group Found\n"; }
my $filter = getInput("Enter Filter: "); unless (defined $filter) { die "No Filter Specified\n"}; my $uid = getInput("Enter UserID: "); unless (defined $uid) { die "No User ID Specified\n"}; my $base = &GroupOrPeople; my $delete = deleteMember($config, $filter, $base, $uid);
my $entry = getInput("Enter User or Group for Removal: "); my ($filter, $delete); my $base = &GroupOrPeople; if ($base !~ m/ou=group/){ $filter = "uid=".$entry; $delete = deleteEntry($config, $filter, $base); } else { $filter = "cn=".$entry; $delete = deleteEntry($config, $filter, $base); }
my $uid = getInput("Enter UserID of User whos password needs to be changed: "); unless (defined $uid) { die "No User ID Specified\n"}; my $passwd = changeUserPasswd( $config, $uid ); if (defined $passwd) { print "New Password for User: " . $uid . " is: " . $passwd . "\n"; } else { print "User: " . $uid . " not found!\n"; }
Exports routines to make the use of Net::LDAP and NET::LDAPS easier for certain repeated functions using a common configuration file to source the connection details from.
It requires a config file in yml format an example is below.
--- server: ldap.test.com basedn: dc=test,dc=com secure: 1 user: - name: root dn: cn=root,dc=test,dc=com password: rootpwd - name: view dn: cn=view,dc=test,dc=com password: teddies
The following properties are exported by this module:
viewSearch - Searchs the ldap server as a view only user deleteMember - Deletes a user from a group deleteEntry - Deletes an entry from the ldap server addMember - Adds a user to a current group addGroup - Adds a group to the system getMaxUID - Gets the current max user id used in the system getMaxGID - Gets the current max group id used in the system getInput - A function to get user input. viewBind - Connect to the ldap server with view only privileges addUser - Add a user to the ldap server getGIDNumber - Get a groups gidNumber changeUserPasswd - Change and LDAP users password to a new random 8 character string
http://search.cpan.org/perldoc?Net::LDAP
My website for a use case script on this module is https://www.pixie79.org.uk/sysadmin/perl/Pixie-Ldap
Mark Olliver, <mark@pixie79.org.uk<gt>
Copyright (C) 2010 by Mark Olliver - Pixie79
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.
To install PixieLdap, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PixieLdap
CPAN shell
perl -MCPAN -e shell install PixieLdap
For more information on module installation, please visit the detailed CPAN module installation guide.