Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / back-sock / searchexample.pl
blob649b3c3e92d3101f054c68b9379301bdac5c986e
1 #!/usr/bin/perl -w -T
2 # $OpenLDAP: pkg/ldap/servers/slapd/back-sock/searchexample.pl,v 1.5.2.1 2008/02/09 00:46:09 quanah Exp $
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 2007-2008 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.
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>.
16 ## ACKNOWLEDGEMENTS:
17 ## This work was initially developed by Brian Candler for inclusion
18 ## in OpenLDAP Software.
20 # See: http://search.cpan.org/dist/Net-Server/
22 package ExampleDB;
24 use strict;
25 use vars qw(@ISA);
26 use Net::Server::PreFork; # any personality will do
28 @ISA = qw(Net::Server::PreFork);
30 ExampleDB->run(
31 port=>"/tmp/example.sock|unix"
32 #conf_file=>"/etc/example.conf"
34 exit;
36 ### over-ridden subs below
37 # The protocol is the same as back-shell
39 sub process_request {
40 my $self = shift;
42 eval {
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);
48 my $request = <STDIN>;
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;
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";
68 else {
69 print "RESULT\n";
70 print "code: 53\n"; # unwillingToPerform
71 print "info: I don't implement $request";
76 return unless $@;
77 if( $@=~/timed out/i ){
78 print "RESULT\n";
79 print "code: 3\n"; # timeLimitExceeded
80 print "info: Timed out\n";
82 else {
83 print "RESULT\n";
84 print "code: 1\n"; # operationsError
85 print "info: $@\n"; # FIXME: remove CR/LF