line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::LDAP::SimpleServer; |
2
|
|
|
|
|
|
|
|
3
|
25
|
|
|
25
|
|
4993853
|
use strict; |
|
25
|
|
|
|
|
107
|
|
|
25
|
|
|
|
|
679
|
|
4
|
25
|
|
|
25
|
|
111
|
use warnings; |
|
25
|
|
|
|
|
42
|
|
|
25
|
|
|
|
|
959
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Minimal-configuration, read-only LDAP server |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.0.21'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
25
|
|
|
25
|
|
464
|
use 5.008; |
|
25
|
|
|
|
|
105
|
|
11
|
25
|
|
|
25
|
|
152
|
use Carp; |
|
25
|
|
|
|
|
41
|
|
|
25
|
|
|
|
|
2986
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $personality = undef; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub import { |
16
|
25
|
|
|
25
|
|
290
|
my $pkg = shift; |
17
|
25
|
|
50
|
|
|
172
|
$personality = shift || 'Fork'; |
18
|
|
|
|
|
|
|
|
19
|
25
|
|
|
25
|
|
151
|
eval "use base qw{Net::Server::$personality}"; ## no critic |
|
25
|
|
|
|
|
52
|
|
|
25
|
|
|
|
|
474
|
|
|
25
|
|
|
|
|
1531
|
|
20
|
25
|
50
|
|
|
|
381894
|
croak $@ if $@; |
21
|
|
|
|
|
|
|
|
22
|
25
|
|
|
|
|
206
|
push @Net::LDAP::SimpleServer::ISA, qw(Net::Server); |
23
|
25
|
|
|
|
|
13414
|
return; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
25
|
|
|
25
|
|
153
|
use File::Basename; |
|
25
|
|
|
|
|
48
|
|
|
25
|
|
|
|
|
1590
|
|
27
|
25
|
|
|
25
|
|
6991
|
use File::HomeDir; |
|
25
|
|
|
|
|
90045
|
|
|
25
|
|
|
|
|
1070
|
|
28
|
25
|
|
|
25
|
|
152
|
use File::Spec; |
|
25
|
|
|
|
|
47
|
|
|
25
|
|
|
|
|
534
|
|
29
|
25
|
|
|
25
|
|
120
|
use File::Path 2.08 qw{make_path}; |
|
25
|
|
|
|
|
398
|
|
|
25
|
|
|
|
|
1271
|
|
30
|
25
|
|
|
25
|
|
143
|
use Scalar::Util qw{reftype}; |
|
25
|
|
|
|
|
42
|
|
|
25
|
|
|
|
|
948
|
|
31
|
25
|
|
|
25
|
|
6746
|
use Net::LDAP::SimpleServer::LDIFStore; |
|
25
|
|
|
|
|
68
|
|
|
25
|
|
|
|
|
898
|
|
32
|
25
|
|
|
25
|
|
6819
|
use Net::LDAP::SimpleServer::ProtocolHandler; |
|
25
|
|
|
|
|
83
|
|
|
25
|
|
|
|
|
824
|
|
33
|
25
|
|
|
25
|
|
171
|
use Net::LDAP::SimpleServer::Constant; |
|
25
|
|
|
|
|
52
|
|
|
25
|
|
|
|
|
11718
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $BASEDIR = File::Spec->catfile( home(), '.ldapsimple' ); |
36
|
|
|
|
|
|
|
my $DEFAULT_CONFIG_FILE = File::Spec->catfile( $BASEDIR, 'server.conf' ); |
37
|
|
|
|
|
|
|
my $DEFAULT_DATA_FILE = File::Spec->catfile( $BASEDIR, 'server.ldif' ); |
38
|
|
|
|
|
|
|
my $DEFAULT_LOG_FILE = File::Spec->catfile( $BASEDIR, 'server.log' ); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my @LDAP_PRIVATE_OPTIONS = qw/store input output/; |
41
|
|
|
|
|
|
|
my @LDAP_PUBLIC_OPTIONS = |
42
|
|
|
|
|
|
|
qw/data_file root_dn root_pw allow_anon user_passwords user_id_attr user_pw_attr user_filter/; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
make_path($BASEDIR); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub options { |
47
|
37
|
|
|
37
|
1
|
52118545
|
my ( $self, $template ) = @_; |
48
|
37
|
|
|
|
|
208
|
my $prop = $self->{server}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
### setup options in the parent classes |
51
|
37
|
|
|
|
|
789
|
$self->SUPER::options($template); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
### add a single value option |
54
|
37
|
|
|
|
|
6063
|
for (@LDAP_PUBLIC_OPTIONS) { |
55
|
296
|
100
|
|
|
|
1040
|
$prop->{$_} = undef unless exists $prop->{$_}; |
56
|
296
|
|
|
|
|
975
|
$template->{$_} = \$prop->{$_}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#use Data::Dumper; |
60
|
|
|
|
|
|
|
#print STDERR Data::Dumper->Dump( [$self->{server}], ['server'] ); |
61
|
37
|
|
|
|
|
180
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub default_values { |
65
|
31
|
|
|
31
|
1
|
2394
|
my $self = @_; |
66
|
|
|
|
|
|
|
|
67
|
31
|
|
|
|
|
140
|
my $v = {}; |
68
|
31
|
|
|
|
|
171
|
$v->{port} = 389; |
69
|
31
|
|
|
|
|
212
|
$v->{log_file} = $DEFAULT_LOG_FILE; |
70
|
31
|
50
|
|
|
|
602
|
$v->{conf_file} = $DEFAULT_CONFIG_FILE if -r $DEFAULT_CONFIG_FILE; |
71
|
|
|
|
|
|
|
$v->{syslog_ident} = |
72
|
31
|
|
|
|
|
257
|
'Net::LDAP::SimpleServer [' . $Net::LDAP::SimpleServer::VERSION . ']'; |
73
|
|
|
|
|
|
|
|
74
|
31
|
|
|
|
|
88
|
$v->{allow_anon} = 1; |
75
|
31
|
|
|
|
|
159
|
$v->{root_dn} = 'cn=root'; |
76
|
31
|
50
|
|
|
|
236
|
$v->{data_file} = $DEFAULT_DATA_FILE if -r $DEFAULT_DATA_FILE; |
77
|
31
|
|
|
|
|
117
|
$v->{user_passwords} = USER_PW_NONE; |
78
|
31
|
|
|
|
|
96
|
$v->{user_filter} = '(objectClass=person)'; |
79
|
31
|
|
|
|
|
146
|
$v->{user_id_attr} = 'uid'; |
80
|
31
|
|
|
|
|
121
|
$v->{user_pw_attr} = 'userPassword'; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#use Data::Dumper; print STDERR Dumper($v); |
83
|
31
|
|
|
|
|
147
|
return $v; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub post_configure_hook { |
87
|
17
|
|
|
17
|
1
|
12044
|
my $self = shift; |
88
|
17
|
|
|
|
|
126
|
my $prop = $self->{server}; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# create server directory in home dir |
91
|
17
|
|
|
|
|
2391
|
make_path($BASEDIR); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#use Data::Dumper; print STDERR '# ' . Dumper( $prop ); |
94
|
|
|
|
|
|
|
croak q{Configuration has no "data_file" file!} |
95
|
17
|
100
|
|
|
|
1708
|
unless $prop->{data_file}; |
96
|
|
|
|
|
|
|
croak qq{Cannot read data_file file (} . $prop->{data_file} . q{)} |
97
|
13
|
100
|
|
|
|
886
|
unless -r $prop->{data_file}; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# data_file is not a "public" option in the server, it is created here |
100
|
|
|
|
|
|
|
$prop->{store} = |
101
|
|
|
|
|
|
|
Net::LDAP::SimpleServer::LDIFStore->new( $prop->{data_file} ) |
102
|
12
|
|
33
|
|
|
440
|
|| croak q{Cannot create data store!}; |
103
|
|
|
|
|
|
|
|
104
|
12
|
|
|
|
|
65
|
return; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub process_request { |
108
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
109
|
0
|
|
|
|
|
|
my $prop = $self->{server}; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my $params = { map { ( $_ => $prop->{$_} ) } @LDAP_PUBLIC_OPTIONS }; |
|
0
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
for (@LDAP_PRIVATE_OPTIONS) { |
113
|
0
|
0
|
|
|
|
|
$params->{$_} = $prop->{$_} if $prop->{$_}; |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
|
|
|
$params->{sock} = $self->{server}->{client}; |
116
|
0
|
|
|
|
|
|
my $handler = Net::LDAP::SimpleServer::ProtocolHandler->new($params); |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
until ( $handler->handle ) { |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# intentionally empty loop |
121
|
|
|
|
|
|
|
} |
122
|
0
|
|
|
|
|
|
return; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |