/[A3C]/lib/A3C/LDAP/Server.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/A3C/LDAP/Server.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 225 - (show annotations)
Fri Jun 27 11:38:36 2008 UTC (15 years, 10 months ago) by dpavlin
File size: 3055 byte(s)
don't modify changetype, pod
1 package A3C::LDAP::Server;
2
3 use strict;
4 use warnings;
5
6 use Net::LDAP::Constant qw(
7 LDAP_SUCCESS
8 LDAP_STRONG_AUTH_NOT_SUPPORTED
9 LDAP_UNAVAILABLE
10 LDAP_OPERATIONS_ERROR
11 );
12 use Net::LDAP::Server;
13 use Net::LDAP::Filter;
14 use base 'Net::LDAP::Server';
15 use fields qw(upstream);
16
17 use A3C::LDAP;
18 use Data::Dump qw/dump/;
19
20 =head1 NAME
21
22 A3C::LDAP::Server
23
24 =cut
25
26 =head1 DESCRIPTION
27
28 Provide LDAP server functionality for L<A3C> somewhat similar to C<slapo-rwm>
29
30 =cut
31
32 use constant RESULT_OK => {
33 'matchedDN' => '',
34 'errorMessage' => '',
35 'resultCode' => LDAP_SUCCESS
36 };
37
38 # constructor
39 sub new {
40 my ($class, $sock) = @_;
41 my $self = $class->SUPER::new($sock);
42 printf "Accepted connection from: %s\n", $sock->peerhost();
43 return $self;
44 }
45
46 # the bind operation
47 sub bind {
48 my ($self,$req) = @_;
49
50 warn "## bind req = ",dump($req);
51
52 defined($req->{authentication}->{simple}) or return {
53 matchedDN => '',
54 errorMessage => '',
55 resultCode => LDAP_STRONG_AUTH_NOT_SUPPORTED,
56 };
57
58 $self->{upstream} ||= A3C::LDAP->new->ldap or return {
59 matchedDN => '',
60 errorMessage => $@,
61 resultCode => LDAP_UNAVAILABLE,
62 };
63
64 # warn "## upstream = ",dump( $self->{upstream} );
65 # warn "upstream not Net::LDAP but ",ref($self->{upstream}) unless ref($self->{upstream}) eq 'Net::LDAP';
66
67 return RESULT_OK;
68 }
69
70 # the search operation
71 sub search {
72 my ($self,$req) = @_;
73
74 warn "## search req = ",dump( $req );
75
76 if ( ! $self->{upstream} ) {
77 warn "search without bind";
78 return {
79 matchedDN => '',
80 errorMessage => 'dude, bind first',
81 resultCode => LDAP_OPERATIONS_ERROR,
82 };
83 }
84
85 my $filter;
86 if (defined $req->{filter}) {
87 # $req->{filter} is a ASN1-decoded tree; luckily, this is exactly the
88 # internal representation Net::LDAP::Filter uses. [FIXME] Eventually
89 # Net::LDAP::Filter should provide a corresponding constructor.
90 bless($req->{filter}, 'Net::LDAP::Filter');
91 $filter = $req->{filter}->as_string;
92 # $filter = '(&' . $req->{filter}->as_string
93 # . '(objectClass=hrEduPerson)(host=aai.irb.hr))';
94 }
95
96 warn "search upstream for $filter\n";
97
98 my $search = $self->{upstream}->search(
99 base => $req->{baseObject},
100 scope => $req->{scope},
101 deref => $req->{derefAliases},
102 sizelimit => $req->{sizeLimit},
103 timelimit => $req->{timeLimit},
104 typesonly => $req->{typesOnly},
105 filter => $filter,
106 attrs => $req->{attributes},
107 raw => qr/.*/,
108 );
109
110 # warn "# search = ",dump( $search );
111
112 if ( $search->code != LDAP_SUCCESS ) {
113 warn "ERROR: ",$search->code,": ",$search->server_error;
114 return {
115 matchedDN => '',
116 errorMessage => $search->server_error,
117 resultCode => $search->code,
118 };
119 };
120
121 my @entries = $search->entries;
122 warn "## got ", $search->count, " entries for $filter\n";
123 foreach my $entry (@entries) {
124 # $entry->changetype('add'); # Don't record changes.
125 # foreach my $attr ($entry->attributes) {
126 # if ($attr =~ /;lang-en$/) {
127 # $entry->delete($attr);
128 # }
129 # }
130 }
131
132 warn "## entries = ",dump( @entries );
133 return RESULT_OK, @entries;
134 }
135
136 # the rest of the operations will return an "unwilling to perform"
137
138 1;

  ViewVC Help
Powered by ViewVC 1.1.26