1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
#!/usr/bin/env perl
#
# $FML$
#
use strict;
use Carp;
use Net::LDAP;
# parameters
$| = 1;
my $dn = "dc=fml, dc=org";
my $x = "dc=elena, $dn";
my $address = "fukachan\@home.fml.org";
my $address2 = "rudo\@home.fml.org";
# USAGE: new ( HOST, OPTIONS )
my $ldap = Net::LDAP->new( 'localhost' ) or warn($@);
# USAGE: bind ( DN, OPTIONS ) # bind to a directory with dn and password
my $mesg = $ldap->bind($dn, password => 'uja');
$mesg->code && warn($mesg->error);
_dump();
_add($ldap);
_modify($ldap);
_delete($ldap);
# UNBIND
$mesg = $ldap->unbind;
$mesg->code && warn($mesg->error);
exit 0;
sub _dump
{
my ($attr) = @_;
my $mesg = undef;
print "DUMPED {\n";
# USAGE: search ( OPTIONS )
# base => DN
# filter => FILTER
# attrs => [ ATTR, .. ]
if ($attr) {
$mesg = $ldap->search(base => $dn,
filter => "(objectclass=*)",
);
}
else {
$mesg = $ldap->search(base => $dn,
filter => "(objectclass=*)",
);
}
$mesg->code && warn($mesg->error);
for my $entry ($mesg->entries) {
if ($attr) {
my $r = $entry->get_value($attr, asref => 1) || [];
print "[ @$r ]\n";
}
else {
$entry->dump;
}
}
print "\n}\n\n";
print "=" x60;
print "\n";
}
sub _add
{
my ($ldap) = @_;
print "* add (dn: $x)\n";
my $mesg =
$ldap->add($x,
attr => [
'dc' => "elena",
'ou' => "elena\@home.fml.org",
'fmlmember' => $address,
'fmlrecipient' => $address,
'objectclass' => [
'top',
'dcObject',
'organizationalUnit',
'fml'
]
]
);
$mesg->code && warn($mesg->error);
_dump("fmlmember");
}
sub _modify
{
my ($ldap) = @_;
print "* modify (dn: $x)\n";
my $mesg = $ldap->modify($x,
add => {
'fmlmember' => $address2,
'fmlrecipient' => $address2,
}
);
$mesg->code && warn($mesg->error);
_dump("fmlmember");
}
sub _delete
{
my ($ldap) = @_;
print "* delete (dn: $x)\n";
my $mesg = $ldap->modify($x,
delete => {
'fmlmember' => $address2,
'fmlrecipient' => $address2,
}
);
$mesg->code && warn($mesg->error);
_dump("fmlmember");
return;
my $mesg = $ldap->delete($x);
$mesg->code && warn($mesg->error);
_dump("fmlmember");
}
|