[vhffs-dev] [1590] clean environment after fork(), chdir() to home directory |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1590
Author: gradator
Date: 2010-04-08 23:52:31 +0200 (Thu, 08 Apr 2010)
Log Message:
-----------
clean environment after fork(), chdir() to home directory
Modified Paths:
--------------
trunk/vhffs-robots/src/cron_scheduler.pl
Modified: trunk/vhffs-robots/src/cron_scheduler.pl
===================================================================
--- trunk/vhffs-robots/src/cron_scheduler.pl 2010-04-08 20:45:57 UTC (rev 1589)
+++ trunk/vhffs-robots/src/cron_scheduler.pl 2010-04-08 21:52:31 UTC (rev 1590)
@@ -37,6 +37,7 @@
use IO::Select;
use BSD::Resource;
use English;
+use Cwd 'chdir';
#use Data::Dumper;
use constant
@@ -48,7 +49,7 @@
FAIL_TO_RUN_PROCESS_EXIT_CODE => 136,
};
-use lib '%VHFFS_LIB_DIR%';
+use lib '/usr/share/vhffs/api';
use Vhffs::Main;
use Vhffs::Services::Cron;
use Vhffs::Robots::Cron;
@@ -264,11 +265,6 @@
open STDERR, '>&'.$son->fileno;
STDERR->autoflush(1);
- foreach (sort keys(%ENV)) {
- print $son 'ENV:'.$_.'='.$ENV{$_}."\n";
- }
- print $son "\n";
-
foreach my $resource ( keys %{$limits} ) {
my ( $soft , $hard ) = ( $limits->{$resource} =~ /^\s*([\d\w]+)\s+([\d\w]+)\s*$/ );
@@ -280,12 +276,32 @@
}
POSIX::nice $nice;
+ %ENV = ();
chroot $chroot if defined $chroot;
+ my ($username,undef,undef,undef,undef,undef,undef,$homedir,undef,undef) = getpwuid( $cron->get_owner_uid );
+ $ENV{'PATH'} = '/usr/bin:/bin';
+ $ENV{'HOME'} = $homedir;
+ $ENV{'LOGNAME'} = $username;
+ chdir $homedir;
+
+ foreach (sort keys(%ENV)) {
+ print $son 'ENV:'.$_.'='.$ENV{$_}."\n";
+ }
+ print $son "\n";
+
+ if( $ENV{'PWD'} ne $homedir ) {
+ print $son "CRITICAL: Cannot chdir() to home directory\n";
+ _exit(FAIL_TO_RUN_PROCESS_EXIT_CODE);
+ }
+
$GID = $EGID = $cron->get_owner_gid.' '.$cron->get_owner_gid;
$UID = $EUID = $cron->get_owner_uid;
- return 1 unless( POSIX::getuid() == $cron->get_owner_uid && POSIX::getgid() == $cron->get_owner_gid );
+ unless( POSIX::getuid() == $cron->get_owner_uid && POSIX::getgid() == $cron->get_owner_gid ) {
+ print $son "CRITICAL: Error while setting UID and GID\n";
+ _exit(FAIL_TO_RUN_PROCESS_EXIT_CODE);
+ }
my $cronpath = $cron->get_cronpath;