Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use Net::LDAP;
- use Net::LDAP::LDIF; # LDAP & LDIF module
- $ldap = Net::LDAP->new('ldap.id.kent.ac.uk') or die "$@";
- $ldif = Net::LDAP::LDIF->new("userinfo.ldif", "a") or die $!;
- # begin session
- $reply = $ldap->bind;
- open USERLIST, "userlist.txt" or die $!;
- while(<USERLIST>)
- {
- my $userid = $_;
- # search ldap server for users information
- $result = $ldap->search(base => "o=uni", filter => "(uid=$userid)");
- foreach $entry ($result->entries)
- {
- $localldap = Net::LDAP->new("localhost") or die "$@";
- $localreply = $localldap->bind("cn=admin,dc=cs,dc=kent,dc=ac,dc=uk", password => "x1Nr7Hra");
- $localresult = $localldap->search(base => "o=students", filter => "(uid=$userid)");
- @results = $localresult->entries;
- if(@results)
- {
- # ->modify to local instead of add
- last;
- }
- else
- {
- # ldapadd to local
- $localadd = $localldap->add("uid=".$userid.",ou=students,dc=cs,dc=kent,dc=ac,dc=uk",
- attr => [
- "cn" => $entry->get_value("cn"),
- "sn" => $entry->get_value("sn"),
- "objectClass" => "top",
- "objectClass" => "inetOrgPerson",
- "objectClass" => "organizationalPerson",
- "objectClass" => "posixAccount",
- "gidnumber" => "1000",
- "uidnumber" => "1000"
- ]);
- $ldif->write_entry($entry);
- }
- $localldap->unbind;
- }
- }
- # end session
- $reply = $ldap->unbind;
Add Comment
Please, Sign In to add comment