Debian Codegraph @

examples/ldap-search

raw
1 # This is an example of a search PDU from the LDAP protocol
2
3 use Convert::ASN1;
4 use Data::Dumper;
5
6 my %scope = qw(base 0 one 1 single 1 sub 2 subtree 2);
7 my %deref = qw(never 0 search 1 find 2 always 3);
8
9 my $search_pdu = Convert::ASN1->new;
10 $search_pdu->prepare(q(
11 SEQUENCE {
12 mesgid INTEGER,
13 [APPLICATION 3] SEQUENCE {
14 base STRING,
15 scope ENUM,
16 deref ENUM,
17 sizeLimit INTEGER,
18 timeLimit INTEGER,
19 typesOnly BOOLEAN,
20 filter STRING, -- for test, should be ANY and the var should hold
21 -- a pre-encoded filter
22 attrs SEQUENCE OF STRING
23 }
24 control [0] SEQUENCE OF SEQUENCE { -- this should be optional but we cannot do that inline
25 type STRING,
26 critical BOOLEAN,
27 value STRING OPTIONAL
28 }
29 }
30 )) or die $search_pdu->error;
31
32 $buf = $search_pdu->encode(
33 mesgid => 3,
34 base => "cn=base",
35 scope => $scope{one},
36 deref => $deref{find},
37 sizeLimit => 0,
38 timeLimit => 0,
39 typesOnly => 0,
40 filter => "A filter",
41 attrs => [qw(cn postalAddress)],
42 control => [
43 {
44 type => "1.2.3.4",
45 critical => 1
46 },
47 {
48 type => "9.8.7.6",
49 critical => 0,
50 value => "abc"
51 }
52 ]
53 );
54
55 $Data::Dumper::Indent = 1;
56 print Dumper( $search_pdu->decode($buf));
57
58 $h = unpack("H*",$buf);
59 $h =~ s/(..)/$1 /g;
60 $h =~ s/(.{47}\s)/$1\n/g;
61 print $h,"\n";