Bug #27396 Wrong check for root priveledge
Submitted: 23 Mar 2007 12:26 Modified: 18 Jun 2007 16:33
Reporter: Sveta Smirnova Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Tests Severity:S3 (Non-critical)
Version:4.1 bk, 5.0 bk, 5.1 bk OS:Windows (Windows, Mac OS X, possible all)
Assigned to: Magnus BlÄudd CPU Architecture:Any
Tags: Contribution

[23 Mar 2007 12:26] Sveta Smirnova
Description:
Function check_running_as_root in mysql-test-run.pl behaves incorrect if tree is on CIFS file system.

In function check_running_as_root:

my $test_file= "$opt_vardir/test_running_as_root.txt";
  mtr_tofile($test_file, "MySQL");
  chmod(oct("0000"), $test_file);

  my $result="";
  if (open(FILE,"<",$test_file))
  {
    $result= join('', <FILE>);
    close FILE;
  }

  chmod(oct("0755"), $test_file);
  unlink($test_file);

  $ENV{'MYSQL_TEST_ROOT'}= "NO";
  if ($result eq "MySQL")
  {
    mtr_warning("running this script as _root_ will cause some " .
                "tests to be skipped");
    $ENV{'MYSQL_TEST_ROOT'}= "YES";
  }

But if I go to CIFS directory as user without root priveleges I can't set rights 0000 to file.

How to repeat:
Create CIFS directory, login to computer where this directory was created and cd to the diredtory.

apple@apple /Volumes/HOMENET;FUSI
$ls -la temp 
-rwx------   1 apple  admin  4B Mar 22 22:52 temp

apple@apple /Volumes/HOMENET;FUSI
$perl -e 'print chmod(oct("0000"), "temp");'
1
apple@apple /Volumes/HOMENET;FUSI
$ls -la temp 
-rwx------   1 apple  admin  4B Mar 22 22:52 temp

Suggested fix:
my $test_file= "$opt_vardir/test_running_as_root.txt";
  mtr_tofile($test_file, "MySQL");
  chmod(oct("0000"), $test_file);

  my $result="";
  if (open(FILE,"<",$test_file))
  {
    $result= join('', <FILE>);
    close FILE;
  }

  chmod(oct("0755"), $test_file);
  unlink($test_file);

  $ENV{'MYSQL_TEST_ROOT'}= "NO";
  if ($result eq "MySQL" && "0000"== sprintf("%04o", stat($test_file)[2] & 07777))
  {
    mtr_warning("running this script as _root_ will cause some " .
                "tests to be skipped");
    $ENV{'MYSQL_TEST_ROOT'}= "YES";
  }
[23 Mar 2007 12:30] Sveta Smirnova
Suggested fix should be read as:

my $test_file= "$opt_vardir/test_running_as_root.txt";
  mtr_tofile($test_file, "MySQL");
  chmod(oct("0000"), $test_file);

  my $result="";
  if (open(FILE,"<",$test_file))
  {
    $result= join('', <FILE>);
    close FILE;
  }

  $ENV{'MYSQL_TEST_ROOT'}= "NO";
  if ($result eq "MySQL" && "0000"== sprintf("%04o", stat($test_file)[2] &
07777))
  {
    mtr_warning("running this script as _root_ will cause some " .
                "tests to be skipped");
    $ENV{'MYSQL_TEST_ROOT'}= "YES";
  }

  chmod(oct("0755"), $test_file);
  unlink($test_file);
[26 Mar 2007 7:00] Sveta Smirnova
Forgotten bracket:

Should be 'if ($result eq "MySQL" && "0000"== sprintf("%04o", (stat($test_file))[2] & 07777))' instead of 'if ($result eq "MySQL" && "0000"== sprintf("%04o", stat($test_file)[2] & 07777))'
[23 May 2007 10:14] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/27196

ChangeSet@1.2614, 2007-05-23 12:13:49+02:00, msvensson@shellback.(none) +1 -0
  Bug#27396 Wrong check for root priveledge
   - Check that filemode was set to 0000
[6 Jun 2007 16:54] Bugs System
Pushed into 5.1.20-beta
[6 Jun 2007 16:57] Bugs System
Pushed into 5.0.44
[6 Jun 2007 17:01] Bugs System
Pushed into 4.1.24
[18 Jun 2007 16:33] Paul DuBois
Test suite change. No changelog entry needed.