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