blob: 029c25386ced6b09d8848708c7765d0747859711 (
plain)
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
|
#!/usr/bin/perl -w -T
# $OpenLDAP$
## This work is part of OpenLDAP Software <http://www.openldap.org/>.
##
## Copyright 2007-2018 The OpenLDAP Foundation.
## All rights reserved.
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted only as authorized by the OpenLDAP
## Public License.
##
## A copy of this license is available in the file LICENSE in the
## top-level directory of the distribution or, alternatively, at
## <http://www.OpenLDAP.org/license.html>.
##
## ACKNOWLEDGEMENTS:
## This work was initially developed by Brian Candler for inclusion
## in OpenLDAP Software.
# See: http://search.cpan.org/dist/Net-Server/
package ExampleDB;
use strict;
use vars qw(@ISA);
use Net::Server::PreFork; # any personality will do
@ISA = qw(Net::Server::PreFork);
ExampleDB->run(
port=>"/tmp/example.sock|unix"
#conf_file=>"/etc/example.conf"
);
exit;
### over-ridden subs below
# The protocol is the same as back-shell
sub process_request {
my $self = shift;
eval {
local $SIG{ALRM} = sub { die "Timed Out!\n" };
my $timeout = 30; # give the user 30 seconds to type a line
alarm($timeout);
my $request = <STDIN>;
if ($request eq "SEARCH\n") {
my %req = ();
while (my $line = <STDIN>) {
chomp($line);
last if $line eq "";
if ($line =~ /^([^:]+):\s*(.*)$/) { # FIXME: handle base64 encoded
$req{$1} = $2;
}
}
#sleep(2); # to test concurrency
print "dn: cn=test, dc=example, dc=com\n";
print "cn: test\n";
print "objectclass: cnobject\n";
print "\n";
print "RESULT\n";
print "code: 0\n";
print "info: answered by process $$\n";
}
else {
print "RESULT\n";
print "code: 53\n"; # unwillingToPerform
print "info: I don't implement $request";
}
};
return unless $@;
if( $@=~/timed out/i ){
print "RESULT\n";
print "code: 3\n"; # timeLimitExceeded
print "info: Timed out\n";
}
else {
print "RESULT\n";
print "code: 1\n"; # operationsError
print "info: $@\n"; # FIXME: remove CR/LF
}
}
1;
|