Take the 2-minute tour ×

I am using a Perl script which deletes the data from mqueue folder for sendmail.

When I setuid to that Perl script and try to run it from user it throws this message:

Insecure dependency in chdir while running setuid at /file/find

How to solve it and succesfully run the script with root priveleges?


use strict;

my $qtool = "/usr/local/bin/qtool.pl";
my $mqueue_directory = "/var/spool/mqueue";
my $messages_removed = 0;

use File::Find;
# Recursively find all files and directories in $mqueue_directory
find(\&wanted, $mqueue_directory);

sub wanted {
   # Is this a qf* file?
   if ( /^qf(\w{14})/ ) {
      my $qf_file = $_;
      my $queue_id = $1;
      my $deferred = 0;
      my $from_postmaster = 0;
      my $delivery_failure = 0;
      my $double_bounce = 0;
      open (QF_FILE, $_);
      while(<QF_FILE>) {
         $deferred = 1 if ( /^MDeferred/ );
         $from_postmaster = 1 if ( /^S<>$/ );
         $delivery_failure = 1 if \
            ( /^H\?\?Subject: DELIVERY FAILURE: (User|Recipient)/ );
         if ( $deferred && $from_postmaster && $delivery_failure ) {
            $double_bounce = 1;
      close (QF_FILE);
      if ($double_bounce) {
         print "Removing $queue_id...\n";
         system "$qtool", "-d", $qf_file;

print "\n$messages_removed total \"double bounce\" message(s) removed from ";
print "mail queue.\n";
share|improve this question
goldilocks has provided a solution. As an aside, avoid setuid executables and use sudo. Your auditors will appreciate your security and you won't be surprised when some software refuses to acquire escalated privileges because the process RUID != EUID. –  JRFerguson May 10 '12 at 18:19

2 Answers 2

up vote 4 down vote accepted

"Insecure dependency" is a Taint thing: http://perldoc.perl.org/perlsec.html.

Taint is being enforced because you have run the script setuid. You need to specify untaint as an %option key to File::Find:


my %options = (
    wanted => \&wanted,
    untaint => 1

find(\%options, $mqueue_directory);

You should also have a look at the untaint_pattern in the POD for File::Find.

share|improve this answer
Thanks goldilocks i have edited my post –  Yagyavalk Bhatt May 10 '12 at 9:41
@YagyavalkBhatt: okay, I edited mine too ;) –  goldilocks May 10 '12 at 9:53
Thanks Goldilocks But i still understand where to use untaint and how in my code,can u help –  Yagyavalk Bhatt May 10 '12 at 10:02
I added an example. Make sure you read the docs about this. –  goldilocks May 10 '12 at 13:30

You should build a program wrapper. On almost any unix system, a script can never get root privileges via the SetUID bit. You can find some usefull example here http://www.tuxation.com/setuid-on-shell-scripts.html

share|improve this answer
The problem is that perl can use it's SUID bit? Great that you explain that... –  DipSwitch May 14 '12 at 8:24
what for build wrapper? it is ant its name is 'sudo' :P It's obvious to configure it. –  Znik Mar 11 '14 at 8:03

Your Answer


