Permalink
Browse files

Use File::Temp::tempdir if tmpdir is not defined in the configuration…

… file.
  • Loading branch information...
1 parent f8ed9cd commit 3414ff277a929316c5dedf1ca1d0addce899acc7 @manitou-mail committed Dec 8, 2012
Showing with 21 additions and 17 deletions.
  1. +21 −17 script/manitou-mdx
View
@@ -49,7 +49,7 @@ use File::stat;
use IO::Handle;
use IPC::Open3;
use Getopt::Long;
-use File::Temp qw(tempfile);
+use File::Temp qw(tempfile tempdir);
use File::Basename qw(basename dirname);
use Time::HiRes qw(gettimeofday tv_interval);
@@ -77,7 +77,6 @@ my $global_end;
my $mail_id; # currently processed
my $verbosity;
-
# hash of mail_id that we failed to send and do not want to retry
my %hsend_blocked;
@@ -910,23 +909,28 @@ sub run_maint_plugin {
sub init_temp_dir {
my $dir = getconf('tmpdir');
- if (!defined($dir)) {
- $dir="/var/tmp/manitou-" . getuid();
- }
- if (! -d $dir) {
- mkdir($dir, 0700) or die "Cannot create $dir: $!\nPlease set the 'tmpdir' configuration parameter to a usable directory for temporary files";
- }
- my $st=stat($dir);
- if (($st->mode & 7) != 0) {
- die "Security check failed: $dir has unsecure permissions: use 0700 permissions.\n" unless (getconf('security_checks') eq "no");
+ if (defined $dir) {
+ if (! -d $dir) {
+ mkdir($dir, 0700) or die "Cannot create $dir: $!\nPlease set the 'tmpdir' configuration parameter to a usable directory for temporary files";
+ }
+ my $st=stat($dir);
+ if (($st->mode & 7) != 0) {
+ die "Security check failed: $dir has unsecure permissions: use 0700 permissions.\n" unless (getconf('security_checks') eq "no");
+ }
+ if ($st->uid != getuid()) {
+ my @pw_me=getpwuid(getuid());
+ my @pw_dir=getpwuid($st->uid);
+ my $msg=sprintf("Security problem: $dir belongs to user '%s' while we are running as user '%s'\n", $pw_dir[0], $pw_me[0]);
+ die $msg unless (getconf('security_checks') eq "no");
+ }
}
- if ($st->uid != getuid()) {
- my @pw_me=getpwuid(getuid());
- my @pw_dir=getpwuid($st->uid);
- my $msg=sprintf("Security problem: $dir belongs to user '%s' while we are running as user '%s'\n", $pw_dir[0], $pw_me[0]);
- die $msg unless (getconf('security_checks') eq "no");
+ else {
+ $dir=File::Temp::tempdir(CLEANUP=>1);
+ if (!$dir) {
+ die "Could not create a temporary directory";
+ }
+ set_common_conf('tmpdir', $dir);
}
- set_common_conf('tmpdir', $dir);
}
sub LogError {

0 comments on commit 3414ff2

Please sign in to comment.