Captive-Portal
view release on metacpan or search on metacpan
lib/Captive/Portal/Role/Utils.pm view on Meta::CPAN
# delete leading zeros in octets
# (side effect: wrap octets 256 -> 0, ...), should not happen
my $ip_packed_unpacked = join '.', unpack 'C4', pack 'C4', @octets;
return $ip_packed_unpacked;
}
=item $capo->drop_privileges()
Running under root, like normal cronjobs do, should drop to the same uid/gid as the http daemon (and fcgi script). uid/gid is taken from config as RUN_USER/RUN_GROUP.
=cut
sub drop_privileges {
my $self = shift;
my $user = $self->cfg->{RUN_USER}
or LOGDIE "FATAL: missing 'RUN_USER' in cfg file,";
my $group = $self->cfg->{RUN_GROUP}
lib/Captive/Portal/Role/Utils.pm view on Meta::CPAN
else {
$uid = getpwnam($user);
$uname = $user;
}
unless ( defined($uname) and defined($uid) ) {
LOGDIE "user '$user' not known to system\n";
}
########
# resolve group to groupname and/or gid
my ( $gname, $gid );
if ( $group =~ m/^\d+$/ ) {
$gname = getgrgid($group);
$gid = $group;
}
else {
$gid = getgrnam($group);
$gname = $group;
}
unless ( defined($gname) and defined($gid) ) {
LOGDIE "group '$group' not known to system\n";
}
# switch to user:group not needed
# already running under required uid:gid
return if $> == $uid && $) == $gid;
DEBUG "switch GID and EGID to $gid";
$( = $) = $gid;
LOGDIE "cannot change group to '$group': $!\n"
if $) != $gid;
DEBUG "switch UID and EUID to $uid";
$< = $> = $uid;
LOGDIE "cannot change user to '$user': $!\n"
if $> != $uid;
}
=item $capo->spawn_cmd(@cmd_with_options, [$spawn_cmd_options])
t/etc/ok.pl view on Meta::CPAN
use subs qw(TRUE FALSE ON OFF YES NO);
# cfg hash
return {
SESSIONS_DIR => 't/sessions',
MOCK_MAC => 1,
MOCK_AUTHEN => 1,
MOCK_FIREWALL => 1,
RUN_USER => scalar getpwuid($>),
RUN_GROUP => scalar getgrgid($)),
ADMIN_SECRET => 'my-secret',
'IPTABLES' => {
capture_if => 'eth0',
capture_ports => [ 80, ],
redirect_port => 80,
capture_net => '10.10.0.0/16',
throttle => OFF,
open_services => {},
( run in 2.311 seconds using v1.01-cache-2.11-cpan-5735350b133 )