| 1 | package Net::LDAP::SimpleServer; | ||||||||||||
| 2 | |||||||||||||
| 3 | 38 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 38 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | # ABSTRACT: Minimal-configuration, read-only LDAP server | ||||||||||||
| 7 | |||||||||||||
| 8 | 38 | our $VERSION = '0.0.21'; # VERSION | |||||||||||
| 9 | |||||||||||||
| 10 | 38 | ▶ | use 5.008; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 38 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | 38 | our $personality = undef; | |||||||||||
| 14 | |||||||||||||
| 15 | 37 | ▶ | sub import { | ||||||||||
|
Subroutine
import: called CC=3 SCAR=11.1
| |||||||||||||
| 16 | 37 | my $pkg = shift; | |||||||||||
| 17 | 37 | ▶ | $personality = shift || 'Fork'; | ||||||||||
|
Condition50%1/2
shift() || 'Fork'
MC/DC0%0/1
shift() || 'Fork'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 18 | |||||||||||||
| 19 | 37 | ▶ | eval "use base qw{Net::Server::$personality}"; ## no critic | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 20 | 37 | ▶ | croak $@ if $@; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 21 | |||||||||||||
| 22 | 37 | push @Net::LDAP::SimpleServer::ISA, qw(Net::Server); | |||||||||||
| 23 | 37 | return; | |||||||||||
| 24 | } | ||||||||||||
| 25 | |||||||||||||
| 26 | 38 | ▶ | use File::Basename; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | 38 | ▶ | use File::HomeDir; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | 38 | ▶ | use File::Spec; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 29 | 38 | ▶ | use File::Path 2.08 qw{make_path}; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 30 | 38 | ▶ | use Scalar::Util qw{reftype}; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 31 | 38 | ▶ | use Net::LDAP::SimpleServer::LDIFStore; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 32 | 38 | ▶ | use Net::LDAP::SimpleServer::ProtocolHandler; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 33 | 38 | ▶ | use Net::LDAP::SimpleServer::Constant; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 34 | |||||||||||||
| 35 | 38 | my $BASEDIR = File::Spec->catfile( home(), '.ldapsimple' ); | |||||||||||
| 36 | 38 | my $DEFAULT_CONFIG_FILE = File::Spec->catfile( $BASEDIR, 'server.conf' ); | |||||||||||
| 37 | 38 | my $DEFAULT_DATA_FILE = File::Spec->catfile( $BASEDIR, 'server.ldif' ); | |||||||||||
| 38 | 38 | my $DEFAULT_LOG_FILE = File::Spec->catfile( $BASEDIR, 'server.log' ); | |||||||||||
| 39 | |||||||||||||
| 40 | 38 | my @LDAP_PRIVATE_OPTIONS = qw/store input output/; | |||||||||||
| 41 | 37 | 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 | 37 | make_path($BASEDIR); | |||||||||||
| 45 | |||||||||||||
| 46 | 61 | ▶ | sub options { | ||||||||||
|
Subroutine
options: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 47 | 61 | my ( $self, $template ) = @_; | |||||||||||
| 48 | 61 | my $prop = $self->{server}; | |||||||||||
| 49 | |||||||||||||
| 50 | ### setup options in the parent classes | ||||||||||||
| 51 | 61 | $self->SUPER::options($template); | |||||||||||
| 52 | |||||||||||||
| 53 | ### add a single value option | ||||||||||||
| 54 | 61 | for (@LDAP_PUBLIC_OPTIONS) { | |||||||||||
| 55 | 488 | ▶ | $prop->{$_} = undef unless exists $prop->{$_}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 56 | 488 | $template->{$_} = \$prop->{$_}; | |||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | #use Data::Dumper; | ||||||||||||
| 60 | #print STDERR Data::Dumper->Dump( [$self->{server}], ['server'] ); | ||||||||||||
| 61 | 61 | return; | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | 55 | ▶ | sub default_values { | ||||||||||
|
Subroutine
default_values: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 65 | 55 | my $self = @_; | |||||||||||
| 66 | |||||||||||||
| 67 | 55 | my $v = {}; | |||||||||||
| 68 | 55 | $v->{port} = 389; | |||||||||||
| 69 | 55 | $v->{log_file} = $DEFAULT_LOG_FILE; | |||||||||||
| 70 | 55 | ▶ | $v->{conf_file} = $DEFAULT_CONFIG_FILE if -r $DEFAULT_CONFIG_FILE; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 71 | $v->{syslog_ident} = | ||||||||||||
| 72 | 55 | 'Net::LDAP::SimpleServer [' . $Net::LDAP::SimpleServer::VERSION . ']'; | |||||||||||
| 73 | |||||||||||||
| 74 | 55 | $v->{allow_anon} = 1; | |||||||||||
| 75 | 55 | $v->{root_dn} = 'cn=root'; | |||||||||||
| 76 | 55 | ▶ | $v->{data_file} = $DEFAULT_DATA_FILE if -r $DEFAULT_DATA_FILE; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 77 | 55 | $v->{user_passwords} = USER_PW_NONE; | |||||||||||
| 78 | 55 | $v->{user_filter} = '(objectClass=person)'; | |||||||||||
| 79 | 55 | $v->{user_id_attr} = 'uid'; | |||||||||||
| 80 | 55 | $v->{user_pw_attr} = 'userPassword'; | |||||||||||
| 81 | |||||||||||||
| 82 | #use Data::Dumper; print STDERR Dumper($v); | ||||||||||||
| 83 | 55 | return $v; | |||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | 29 | ▶ | sub post_configure_hook { | ||||||||||
|
Subroutine
post_configure_hook: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 87 | 29 | my $self = shift; | |||||||||||
| 88 | 29 | my $prop = $self->{server}; | |||||||||||
| 89 | |||||||||||||
| 90 | # create server directory in home dir | ||||||||||||
| 91 | 29 | make_path($BASEDIR); | |||||||||||
| 92 | |||||||||||||
| 93 | #use Data::Dumper; print STDERR '# ' . Dumper( $prop ); | ||||||||||||
| 94 | croak q{Configuration has no "data_file" file!} | ||||||||||||
| 95 | 29 | ▶ | unless $prop->{data_file}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 96 | croak qq{Cannot read data_file file (} . $prop->{data_file} . q{)} | ||||||||||||
| 97 | 25 | ▶ | unless -r $prop->{data_file}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | 24 | ▶ | || croak q{Cannot create data store!}; | ||||||||||
|
Condition50%1/2
'Net::LDAP::SimpleServer::LDIFStore'->new($prop->{'data_file'}) || croak('Cannot create data store!')
MC/DC0%0/1
'Net::LDAP::SimpleServer::LDIFStore'->new($prop->{'data_file'}) || croak('Cannot create data store!')
'Net::LDAP::SimpleServer::LDIFStore'->new($prop->{'data_file'})
Truth table50%1/2
A
A= 'Net::LDAP::SimpleServer::LDIFStore'->new($prop->{'data_file'})
| |||||||||||||
| 103 | |||||||||||||
| 104 | 24 | return; | |||||||||||
| 105 | } | ||||||||||||
| 106 | |||||||||||||
| 107 | 12 | ▶ | sub process_request { | ||||||||||
|
Subroutine
process_request: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 108 | 12 | my $self = shift; | |||||||||||
| 109 | 12 | my $prop = $self->{server}; | |||||||||||
| 110 | |||||||||||||
| 111 | 12 | my $params = { map { ( $_ => $prop->{$_} ) } @LDAP_PUBLIC_OPTIONS }; | |||||||||||
| 112 | 12 | for (@LDAP_PRIVATE_OPTIONS) { | |||||||||||
| 113 | 36 | ▶ | $params->{$_} = $prop->{$_} if $prop->{$_}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 114 | } | ||||||||||||
| 115 | 12 | $params->{sock} = $self->{server}->{client}; | |||||||||||
| 116 | 13 | my $handler = Net::LDAP::SimpleServer::ProtocolHandler->new($params); | |||||||||||
| 117 | |||||||||||||
| 118 | 13 | ▶ | until ( $handler->handle ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 119 | |||||||||||||
| 120 | # intentionally empty loop | ||||||||||||
| 121 | } | ||||||||||||
| 122 | 13 | return; | |||||||||||
| 123 | } | ||||||||||||
| 124 | |||||||||||||
| 125 | 37 | 1; # Magic true value required at end of module | |||||||||||
| 126 | |||||||||||||
| 127 | __END__ | ||||||||||||