]> git.sur5r.net Git - openldap/blob - servers/slapd/back-sock/searchexample.pl
adbd40a3ab2c61a2a0d34ff21b2482825892da11
[openldap] / servers / slapd / back-sock / searchexample.pl
1 #!/usr/bin/perl -w -T
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 2007-2017 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
11 ##
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
15 ##
16 ## ACKNOWLEDGEMENTS:
17 ## This work was initially developed by Brian Candler for inclusion
18 ## in OpenLDAP Software.
19
20 # See: http://search.cpan.org/dist/Net-Server/
21
22 package ExampleDB;
23
24 use strict;
25 use vars qw(@ISA);
26 use Net::Server::PreFork; # any personality will do
27
28 @ISA = qw(Net::Server::PreFork);
29
30 ExampleDB->run(
31   port=>"/tmp/example.sock|unix"
32   #conf_file=>"/etc/example.conf"
33 );
34 exit;
35
36 ### over-ridden subs below
37 # The protocol is the same as back-shell
38
39 sub process_request {
40   my $self = shift;
41
42   eval {
43
44     local $SIG{ALRM} = sub { die "Timed Out!\n" };
45     my $timeout = 30; # give the user 30 seconds to type a line
46     alarm($timeout);
47
48     my $request = <STDIN>;
49     
50     if ($request eq "SEARCH\n") {
51       my %req = ();
52       while (my $line = <STDIN>) {
53         chomp($line);
54         last if $line eq "";
55         if ($line =~ /^([^:]+):\s*(.*)$/) { # FIXME: handle base64 encoded
56           $req{$1} = $2;
57         }
58       }
59       #sleep(2);  # to test concurrency
60       print "dn: cn=test, dc=example, dc=com\n";
61       print "cn: test\n";
62       print "objectclass: cnobject\n";
63       print "\n";
64       print "RESULT\n";
65       print "code: 0\n";
66       print "info: answered by process $$\n";      
67     }
68     else {
69       print "RESULT\n";
70       print "code: 53\n";  # unwillingToPerform
71       print "info: I don't implement $request";
72     }
73
74   };
75
76   return unless $@;
77   if( $@=~/timed out/i ){
78     print "RESULT\n";
79     print "code: 3\n"; # timeLimitExceeded
80     print "info: Timed out\n";
81   }
82   else {
83     print "RESULT\n";
84     print "code: 1\n"; # operationsError
85     print "info: $@\n"; # FIXME: remove CR/LF
86   }
87
88 }
89
90 1;