Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Multiple changes

- Base config directory (BASEDIR) is now {HOME}/.ldapsimpleserver/
- Creates {BASEDIR} if it does not exist
- Moved default config file from
    {HOME}/.ldapsimpleserver.conf    to
    {BASEDIR}/config
- Creates a {LOGDIR} = {BASEDIR}/log to hold log file and pid file
- conf_file is set only if there is a file {BASEDIR}/config
- log_file is set by default to {LOGDIR}/server.log
- pid_file is set by default to {LOGDIR}/server.pid
- Changes reflected in POD
  • Loading branch information...
commit 7a19809d3d2a4abbaccb9648eb9e2fe4b4fed92c 1 parent 19a76e3
@russoz authored
Showing with 21 additions and 8 deletions.
  1. +21 −8 lib/Net/LDAP/SimpleServer.pm
View
29 lib/Net/LDAP/SimpleServer.pm
@@ -18,12 +18,15 @@ sub import {
use File::HomeDir;
use File::Spec;
-use Scalar::Util qw(reftype);
+use File::Path qw{make_path};
+use Scalar::Util qw{reftype};
use Net::LDAP::SimpleServer::LDIFStore;
use Net::LDAP::SimpleServer::ProtocolHandler;
-use constant DEFAULT_CONFIG_FILE =>
- File::Spec->catfile( home(), '.ldapsimpleserver.conf' );
+use constant BASEDIR => File::Spec->catfile( home(), '.ldapsimpleserver' );
+use constant LOGDIR => File::Spec->catfile( BASEDIR, 'log' );
+use constant DEFAULT_CONFIG_FILE => File::Spec->catfile( BASEDIR, 'config' );
+use constant DEFAULT_DATA_FILE => File::Spec->catfile( BASEDIR, 'server.ldif' );
my $_add_option = sub {
my ( $prop, $template, $opt, $initial ) = @_;
@@ -46,13 +49,21 @@ sub options {
}
sub default_values {
+ if ( !-d BASEDIR ) {
+ carp q{ Creating Net::LDAP::SimpleServer basedir: } . BASEDIR;
+ make_path(BASEDIR);
+ make_path(LOGDIR);
+ }
return {
host => '*',
port => 389,
proto => 'tcp',
root_dn => 'cn=root',
root_pw => 'ldappw',
- conf_file => DEFAULT_CONFIG_FILE,
+ log_file => File::Spec->catfile( LOGDIR, 'server.log' ),
+ pid_file => File::Spec->catfile( LOGDIR, 'server.pid' ),
+ conf_file => -r DEFAULT_CONFIG_FILE ? DEFAULT_CONFIG_FILE : undef,
+ data => -r DEFAULT_DATA_FILE ? DEFAULT_DATA_FILE : undef,
syslog_ident => 'Net::LDAP::SimpleServer-'
. $Net::LDAP::SimpleServer::VERSION,
};
@@ -62,9 +73,11 @@ sub post_configure_hook {
my $self = shift;
my $prop = $self->{'ldap'};
+ croak q{Cannot find conf file "} . $self->{server}->{conf_file} . q{"}
+ if $self->{server}->{conf_file} and not -r $self->{server}->{conf_file};
croak q{Configuration has no "data" file!}
unless exists $prop->{data};
- croak q{Cannot read data file "} . $prop->{data} . q{"}
+ croak qq{Cannot read data file "} . $prop->{data} . q{"}
unless -r $prop->{data};
$prop->{store} = LDIFStore->new( $prop->{data} );
@@ -121,7 +134,7 @@ B<< WORK IN PROGRESS!! NOT READY TO USE YET!! >>
The default configuration file is:
- ${HOME}/.ldapsimpleserver.conf
+ ${HOME}/.ldapsimpleserver/config
=head1 DESCRIPTION
@@ -151,7 +164,7 @@ notably we have the two forms below:
=item new()
Attempts to create a server by using the default configuration file,
-C<< ${HOME}/.ldapsimpleserver.conf >>.
+C<< ${HOME}/.ldapsimpleserver/config >>.
=item new( HASHREF )
@@ -248,7 +261,7 @@ L<Net::LDAP::SimpleServer::ProtocolHandler>.
Net::LDAP::SimpleServer may use a configuration file to specify the
server settings. If no file is specified and options are not passed
in a hash, this module will look for a default configuration file named
-C<< ${HOME}/.ldapsimpleserver.conf >>.
+C<< ${HOME}/.ldapsimpleserver/config >>.
data /path/to/a/ldif/file.ldif
#port 389
Please sign in to comment.
Something went wrong with that request. Please try again.