Lines 1-20
Link Here
|
1 |
--- ./lib/MailScanner/TNEF.pm.orig 2011-08-20 08:32:02.000000000 -0400 |
1 |
--- ./lib/MailScanner/TNEF.pm.orig 2013-06-17 09:29:16.000000000 -0400 |
2 |
+++ ./lib/MailScanner/TNEF.pm 2012-03-15 11:28:31.000000000 -0400 |
2 |
+++ ./lib/MailScanner/TNEF.pm 2014-02-21 04:03:15.000000000 -0500 |
3 |
@@ -229,15 +229,14 @@ |
3 |
@@ -229,18 +229,25 @@ |
4 |
|
4 |
|
5 |
# Create the subdir to unpack it into |
5 |
# Create the subdir to unpack it into |
6 |
#my $unpackdir = "tnef.$$"; |
6 |
#my $unpackdir = "tnef.$$"; |
7 |
- my ($tmpfh, $unpackdir) = tempfile("tnefXXXXXX", TMPDIR => $dir, UNLINK => 0); |
7 |
- my ($tmpfh, $unpackdir) = tempfile("tnefXXXXXX", TMPDIR => $dir, UNLINK => 0); |
8 |
- $dir =~ s,^.*/,,; |
8 |
- # This line shouldn't be here any more! $dir =~ s,^.*/,,; |
9 |
+ my $unpackdir = tempdir("tnefXXXXXX"); |
9 |
- $unpackdir = $message->MakeNameSafe($unpackdir, $dir); |
10 |
$unpackdir = $message->MakeNameSafe($unpackdir, $dir); |
10 |
- unless (mkdir "$dir/$unpackdir", 0777) { |
11 |
unless (mkdir "$dir/$unpackdir", 0777) { |
11 |
+ my $unpackdir = tempdir("tnefXXXXXX", DIR => $dir); |
|
|
12 |
+ unless (-d $unpackdir) { |
12 |
MailScanner::Log::WarnLog("Trying to unpack %s in message %s, could not create subdirectory %s, failed to unpack TNEF message", $tnefname, $message->{id}, |
13 |
MailScanner::Log::WarnLog("Trying to unpack %s in message %s, could not create subdirectory %s, failed to unpack TNEF message", $tnefname, $message->{id}, |
13 |
"$dir/$unpackdir"); |
14 |
- "$dir/$unpackdir"); |
|
|
15 |
+ "$unpackdir"); |
14 |
return 0; |
16 |
return 0; |
15 |
} |
17 |
} |
16 |
- chmod 0700, "$dir/$unpackdir"; |
18 |
- chmod 0700, "$dir/$unpackdir"; |
17 |
+ chmod 0770, "$dir/$unpackdir"; |
19 |
+ # Convert Incoming Work Permissions to an octal value and add search. |
|
|
20 |
+ my $perms = oct(sprintf("%s", MailScanner::Config::Value('workperms'))) |
21 |
+ | 0111; |
22 |
+ chmod $perms, $unpackdir; |
23 |
+ # Try to set Incoming Work User and Group. |
24 |
+ my $uname = MailScanner::Config::Value('workuser'); |
25 |
+ my $gname = MailScanner::Config::Value('workgroup'); |
26 |
+ my $uid = $uname?getpwnam($uname):-1; |
27 |
+ my $gid = $gname?getgrnam($gname):-1; |
28 |
+ chown $uid, $gid, $unpackdir; |
18 |
|
29 |
|
19 |
my $cmd = MailScanner::Config::Value('tnefexpander') . |
30 |
my $cmd = MailScanner::Config::Value('tnefexpander') . |
20 |
" -f $dir/$tnefname -C $dir/$unpackdir --overwrite"; |
31 |
- " -f $dir/$tnefname -C $dir/$unpackdir --overwrite"; |
|
|
32 |
+ " -f $dir/$tnefname -C $unpackdir --overwrite"; |
33 |
|
34 |
my($kid); |
35 |
my($TimedOut, $PipeReturn, $pid); |
36 |
@@ -311,15 +318,15 @@ |
37 |
|
38 |
unless (MailScanner::Config::Value('replacetnef',$message) =~ /[12]/) { |
39 |
# Just need to move all the unpacked files into the main attachments dir |
40 |
- my $dirh = new DirHandle "$dir/$unpackdir"; |
41 |
+ my $dirh = new DirHandle "$$unpackdir"; |
42 |
return 0 unless defined $dirh; |
43 |
while (defined(my $unpacked = $dirh->read)) { |
44 |
- next unless -f "$dir/$unpackdir/$unpacked"; |
45 |
+ next unless -f "$$unpackdir/$unpacked"; |
46 |
# Add a 't' to the safename to mark it as a tnef member. |
47 |
my $safe = $message->MakeNameSafe('t'.$unpacked, $dir); |
48 |
# This will cause big problems as $safe has a type, and shouldn't! |
49 |
$message->{file2parent}{$safe} = $tnefname; |
50 |
- my $name1 = "$dir/$unpackdir/$unpacked"; |
51 |
+ my $name1 = "$unpackdir/$unpacked"; |
52 |
$name1 =~ /(.*)/; |
53 |
$name1 = $1; |
54 |
my $name2 = "$dir/$safe"; |
55 |
@@ -333,19 +340,21 @@ |
56 |
$safe =~ s#^(.*/)([^/])([^/]+)$#$1$3#; # I assert $2 will equal 't'. |
57 |
$message->{file2parent}{$safe} = $tnefname; |
58 |
} |
59 |
- rmdir "$dir/$unpackdir"; # Directory should be empty now |
60 |
+ # The following may result in a warning from a virus scanner that |
61 |
+ # tries to lstat the directory, but it was empty so it can be ignored. |
62 |
+ rmdir "$$unpackdir"; # Directory should be empty now |
63 |
return 1; |
64 |
} |
65 |
#print STDERR "In TNEF External Decoder\n"; |
66 |
|
67 |
- my $dirh = new DirHandle "$dir/$unpackdir"; |
68 |
+ my $dirh = new DirHandle "$unpackdir"; |
69 |
return 0 unless defined $dirh; |
70 |
my($type, $encoding); |
71 |
$message->{entity}->make_multipart; |
72 |
my($safename, @replacements, $unpacked); |
73 |
while (defined($unpacked = $dirh->read)) { |
74 |
- #print STDERR "Directory entry is \"$unpacked\" in \"$dir/$unpackdir\"\n"; |
75 |
- next unless -f "$dir/$unpackdir/$unpacked"; |
76 |
+ #print STDERR "Directory entry is \"$unpacked\" in \"$unpackdir\"\n"; |
77 |
+ next unless -f "$unpackdir/$unpacked"; |
78 |
# Add a 't' to the safename to mark it as a tnef member. |
79 |
$safename = $message->MakeNameSafe('t'.$unpacked, $dir); |
80 |
if (/^msg[\d-]+\.txt$/) { |
81 |
@@ -353,15 +362,15 @@ |
82 |
} else { |
83 |
($type, $encoding) = ("application/octet-stream", "base64"); |
84 |
} |
85 |
- #print STDERR "Renaming '$dir/$unpackdir/$unpacked' to '$dir/$safename'\n"; |
86 |
- my $oldname = "$dir/$unpackdir/$unpacked"; |
87 |
+ #print STDERR "Renaming '$unpackdir/$unpacked' to '$dir/$safename'\n"; |
88 |
+ my $oldname = "$unpackdir/$unpacked"; |
89 |
my $newname = "$dir/$safename"; |
90 |
$oldname =~ /^(.*)$/; |
91 |
$oldname = $1; |
92 |
$newname =~ /^(.*)$/; |
93 |
$newname = $1; |
94 |
rename $oldname, $newname; |
95 |
- #rename "$dir/$unpackdir/$unpacked", "$dir/$safename"; |
96 |
+ #rename "$unpackdir/$unpacked", "$dir/$safename"; |
97 |
# JKF 20090421 CHMOD, then CHOWN and CHGRP it if necessary. |
98 |
chmod $perms, $newname; |
99 |
#chmod $perms, "$dir/$safename"; |
100 |
@@ -381,7 +390,9 @@ |
101 |
$message->{bodymodified} = 1; |
102 |
$message->{foundtnefattachments} = 1; |
103 |
undef $dirh; |
104 |
- rmdir "$dir/$unpackdir"; # Directory should be empty now |
105 |
+ # The following may result in a warning from a virus scanner that |
106 |
+ # tries to lstat the directory, but it was empty so it can be ignored. |
107 |
+ rmdir "$unpackdir"; # Directory should be empty now |
108 |
#$message->{entity}->dump_skeleton(); |
109 |
|
110 |
MailScanner::Log::InfoLog("Message %s added TNEF contents %s", |