Commit adbce1cd authored by Marvin S. Addison's avatar Marvin S. Addison
Browse files

Add existing Perl ED usage sample.


git-svn-id: https://svn.middleware.vt.edu/svn/ed/edsamples@9918 fa4a4108-76f2-0310-9f0d-ba9fffaf4ff6
parent 11f64453
#!/usr/bin/perl
use Net::LDAP;
use Authen::SASL;
use strict;
my $server = "id.directory.vt.edu";
my $port = 389;
my $dn = "";
my $cafile = "/PATH/TO/ED_ID/CA_file.pem";
my $clientcert = "/PATH/TO/ED_ID/clientcert.pem";
my $clientkey = "/PATH/TO/ED_ID/clientkey.pem";
my $base = "ou=people,dc=vt,dc=edu";
my $filter = "(uupid=UUPID)";
my $attr = "eduPersonAffiliation";
my $value = "VT-ACTIVE-MEMBER";
my $sasl = Authen::SASL->new(mechanism => 'EXTERNAL',
callback => { pass => '', user => ''});
my $ldap = Net::LDAP->new($server, port => $port, version => 3) or die $@;
my $mesg = $ldap->start_tls(verify => 'require',
cafile => $cafile,
ciphers => 'RC4-SHA',
clientcert => $clientcert,
clientkey => $clientkey);
$mesg->code && die $mesg->error;
$mesg = $ldap->bind(dn => '',
sasl => $sasl);
$mesg->code && die $mesg->error;
$mesg = $ldap->search(base => $base, filter => $filter);
$mesg->code && die $mesg->error;
# print specific attribute
#$entry = $mesg->entry(0);
#if($entry)
#{
# print $entry->get_value('edupersonprimaryaffiliation')."\n";
# my $ref = $entry->get_value('edupersonaffiliation', asref => 1);
# foreach(@{$ref}){ print $_."\n"; }
#}
# print all attributes for the entry
foreach my $entry ($mesg->all_entries) { $entry->dump; }
my $entry = $mesg->entry(0);
$mesg = $ldap->compare($entry,
attr => $attr,
value => $value);
if($mesg->code == 6) # error code 6 is LDAP_COMPARE_TRUE
{
print $entry->dn.": $attr == $value\n";
}
else
{
print $entry->dn.": $attr != $value\n";
}
$ldap->unbind;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment