2013-03-07 18:37:22 +01:00
|
|
|
#!/usr/bin/perl -w
|
2014-01-23 11:13:35 +01:00
|
|
|
|
2013-03-07 18:37:22 +01:00
|
|
|
use Lemonldap::NG::Manager::Cli;
|
2013-10-06 16:56:57 +02:00
|
|
|
use POSIX qw(setuid setgid);
|
2013-03-07 18:37:22 +01:00
|
|
|
use strict;
|
|
|
|
|
2013-03-10 15:39:41 +01:00
|
|
|
sub giveUpPrivileges {
|
|
|
|
my ( $user, $group ) = @_;
|
|
|
|
|
2014-01-21 17:13:36 +01:00
|
|
|
$user = "nobody" unless defined($user);
|
2014-01-23 16:59:52 +01:00
|
|
|
$group = "nobody" unless defined($group);
|
2013-03-10 15:39:41 +01:00
|
|
|
|
|
|
|
# become $user:$group and give up root privileges
|
2013-10-06 16:56:57 +02:00
|
|
|
setgid( ( getgrnam($group) )[2] );
|
|
|
|
setuid( ( getpwnam($user) )[2] );
|
2013-03-10 15:39:41 +01:00
|
|
|
|
|
|
|
# if we are still root
|
|
|
|
if ( $> == 0 ) {
|
2014-01-21 17:13:36 +01:00
|
|
|
print STDERR
|
|
|
|
"$0 must not be launched as root since local cache can be corrupted.\n";
|
2013-03-10 15:39:41 +01:00
|
|
|
print STDERR "Continue (y/N)? ";
|
|
|
|
my $res = <STDIN>;
|
|
|
|
exit 1 unless ( $res =~ /^y/i );
|
|
|
|
}
|
2013-03-07 18:37:22 +01:00
|
|
|
}
|
|
|
|
|
2014-01-21 17:13:36 +01:00
|
|
|
## main program
|
2013-03-07 18:37:22 +01:00
|
|
|
|
2014-01-21 17:13:36 +01:00
|
|
|
if ( !@ARGV ) {
|
2013-03-10 15:39:41 +01:00
|
|
|
print STDERR "Usage: $0 <action> <params>\n";
|
2014-01-23 14:32:46 +01:00
|
|
|
print STDERR "- help: list available actions\n";
|
|
|
|
print STDERR "- info: view current configuration information\n";
|
2014-01-21 17:13:36 +01:00
|
|
|
exit 1;
|
2013-03-10 15:39:41 +01:00
|
|
|
}
|
|
|
|
|
2014-01-23 16:59:52 +01:00
|
|
|
giveUpPrivileges( "__APACHEUSER__", "__APACHEGROUP__" );
|
2013-11-26 08:54:10 +01:00
|
|
|
|
2014-01-21 17:13:36 +01:00
|
|
|
my ( $cli, $action, $method, $ret );
|
2013-11-26 08:54:10 +01:00
|
|
|
|
2014-01-23 15:05:18 +01:00
|
|
|
$cli = new Lemonldap::NG::Manager::Cli;
|
|
|
|
|
|
|
|
# Do not increment configuration by default
|
|
|
|
$cli->{confAccess}->{cfgNumFixed} = 1;
|
|
|
|
|
2013-11-26 08:54:10 +01:00
|
|
|
$action = shift(@ARGV);
|
|
|
|
$method = $cli->determineMethod($action);
|
2013-03-07 18:37:22 +01:00
|
|
|
|
2014-01-21 17:13:36 +01:00
|
|
|
unless ( $cli->can($method) ) {
|
|
|
|
print STDERR "Action $action unknown\n";
|
|
|
|
print STDERR "Enter $0 help to get more information\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2014-03-07 11:37:01 +01:00
|
|
|
# The config is stored in ASCII
|
|
|
|
foreach(@ARGV){ utf8::decode $_; }
|
|
|
|
binmode(STDOUT, ':utf8');
|
|
|
|
|
2014-01-21 17:13:36 +01:00
|
|
|
@ARGV ? $cli->run( $method, @ARGV ) : $cli->run($method);
|
2014-01-17 23:14:30 +01:00
|
|
|
|
|
|
|
# Display error if any
|
2014-01-21 17:13:36 +01:00
|
|
|
if ( $cli->getError() ) {
|
|
|
|
print $cli->getError() . "\n";
|
|
|
|
exit 1;
|
2014-01-17 23:14:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Save configuration if modified
|
|
|
|
if ( $cli->{confModified} ) {
|
2014-01-21 17:13:36 +01:00
|
|
|
$ret = $cli->saveConf();
|
|
|
|
print "Configuration $ret saved\n";
|
2014-01-17 23:14:30 +01:00
|
|
|
}
|
2013-03-07 18:37:22 +01:00
|
|
|
|
2014-01-17 23:14:30 +01:00
|
|
|
exit 0;
|
2013-03-07 18:37:22 +01:00
|
|
|
|
|
|
|
__END__
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
=encoding utf8
|
|
|
|
|
|
|
|
lemonldap-ng-cli - Command Line Interface to edit LemonLDAP::NG configuration.
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
2014-01-23 11:13:35 +01:00
|
|
|
Do lemonldap-ng-cli help to get list of all commands
|
2013-03-07 18:37:22 +01:00
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
2014-01-23 11:13:35 +01:00
|
|
|
lemonldap-ng-cli allow user to edit the configuration of LemonLDAP::NG via the
|
2013-03-07 18:37:22 +01:00
|
|
|
command line.
|
|
|
|
|
|
|
|
=head1 SEE ALSO
|
|
|
|
|
2014-01-23 11:13:35 +01:00
|
|
|
L<Lemonldap::NG::Manager::Cli>, L<http://lemonldap-ng.org/>
|
2013-03-07 18:37:22 +01:00
|
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
David Delassus E<lt>david.jose.delassus@gmail.comE<gt>
|
2014-01-23 11:13:35 +01:00
|
|
|
Sandro Cazzaniga E<lt>cazzaniga.sandro@gmail.comE<gt>
|
|
|
|
Clement Oudot E<lt>clem.oudot@gmail.comE<gt>
|
2013-03-07 18:37:22 +01:00
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE
|
|
|
|
|
|
|
|
Copyright (C) 2012, by David Delassus
|
2013-11-26 08:54:10 +01:00
|
|
|
Copyright (C) 2013, by Sandro Cazzaniga
|
2013-03-07 18:37:22 +01:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.10.0 or,
|
|
|
|
at your option, any later version of Perl 5 you may have available.
|
|
|
|
|
|
|
|
=cut
|