Back to index

php5  5.3.10
Enumerations | Functions
common.inc File Reference

Go to the source code of this file.

Enumerations

enum  PHPT_ACL_READ
enum  PHPT_ACL_WRITE
enum  PHPT_ACL_EXEC
enum  PHPT_ACL_NONE
enum  PHPT_ACL_FULL
enum  PHPT_ACL_GRANT
enum  PHPT_ACL_DENY

Functions

 skipif ()
 get_username ()
 get_domainname ()
 icacls_set ($path, $mode, $perm)
 create_dir ($name, $perms)
 create_file ($name, $perms)
 delete_file ($path)
 delete_dir ($path)

Enumeration Type Documentation

Definition at line 10 of file common.inc.

Definition at line 5 of file common.inc.

Definition at line 7 of file common.inc.

Definition at line 9 of file common.inc.

Definition at line 6 of file common.inc.

Definition at line 3 of file common.inc.

Definition at line 4 of file common.inc.


Function Documentation

create_dir ( name,
perms 
)

Definition at line 108 of file common.inc.

                                   {
       if (empty($name)) {
              echo "create_dir: Empty name is not allowed\n";
              return;
       }

       mkdir($name);
       $dst = realpath($name);
       icacls_set($name, PHPT_ACL_GRANT, $perms);
}

Here is the call graph for this function:

create_file ( name,
perms 
)

Definition at line 119 of file common.inc.

                                    {
       if (empty($name)) {
              echo "create_file: Empty name is not allowed\n";
              return;
       }

       touch($name);
       icacls_set($name, PHPT_ACL_GRANT, $perms);
}

Here is the call graph for this function:

delete_dir ( path)

Definition at line 139 of file common.inc.

                           {
       if (is_dir($path)) {
              icacls_set($path, PHPT_ACL_GRANT, PHPT_ACL_FULL);
              rmdir($path);
       } else {
              echo "delete_dir: '$path' is not a directory\n";
              return;
       }
}
if (0) {
$path = __DIR__ . '/a.txt';
create_file($path, PHPT_ACL_NONE);
if (!is_writable($path)) {
       echo "PHPT_ACL_NONE success!!\n";
} else {
       echo "PHPT_ACL_NONE failed!!\n";
}
delete_file($path);

$path = __DIR__ . '/a.txt';
create_file($path, PHPT_ACL_READ);
if (!is_writable($path)) {
       echo "PHPT_ACL_READ success!!\n";
} else {
       echo "PHPT_ACL_READ failed!!\n";
}
delete_file($path);

$path = __DIR__ . '/adir';
create_dir($path, PHPT_ACL_READ);
if (!is_writable($path)) {
       echo "PHPT_ACL_READ dir success!!\n";
} else {
       echo "PHPT_ACL_READ dir failed!!\n";
}
delete_dir($path);

}

Here is the call graph for this function:

delete_file ( path)

Definition at line 129 of file common.inc.

                            {
       icacls_set($path, PHPT_ACL_GRANT, PHPT_ACL_FULL);
       if (is_file($path)) {
              unlink($path);
       } else {
              echo "delete_file: '$path' is not a file\n";
              return;
       }
}

Here is the call graph for this function:

Definition at line 25 of file common.inc.

{
       return getenv('USERDOMAIN');
}

Definition at line 21 of file common.inc.

                       {
       return getenv('USERNAME');
}

Here is the caller graph for this function:

icacls_set ( path,
mode,
perm 
)

Definition at line 30 of file common.inc.

                                         {
       $user = get_username();
       $path_escaped =  '"' . $path . '"';
       $perm_entry = array();

       if ($perm & PHPT_ACL_READ) $perm_entry[]  = 'R';
       if ($perm & PHPT_ACL_WRITE) $perm_entry[] = 'W';
       if ($perm & PHPT_ACL_EXEC) $perm_entry[]  = 'RX';
       if ($perm & PHPT_ACL_FULL) $perm_entry[]  = 'F';

       // Deny all
       $cmd = 'icacls ' . $path_escaped . ' /inheritance:r /deny ' . $user . ':(F,M,R,RX,W)';
       exec($cmd);

       if ($perm & PHPT_ACL_NONE) {
              /*
               This is required to remove all the previously denied
               permission for the USER. Just granting permission doesn't
               remove the previously denied permission.
              */
              $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:d';
              $cmd .= ' ' . $user;
              exec($cmd);
              $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:g';
              $cmd .= ' ' . $user;
              exec($cmd);
              return;
       }

       if ($mode == PHPT_ACL_GRANT) {
              $mode = 'grant';
       } else {
              $mode = 'deny';
       }


       // Deny all
       $cmd = 'icacls ' . $path_escaped . ' /deny ' . $user . ':(F,M,R,RX,W)';
       exec($cmd);

       /*
        This is required to remove all the previously denied
        permission for the USER. Just granting permission doesn't
        remove the previously denied permission.
       */
       $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:d';
       $cmd .= ' ' . $user;
       exec($cmd);
       $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:g';
       $cmd .= ' ' . $user;
       exec($cmd);


       /*
        Required to set no permission and check that is_readable()
        returns false. If the $perm_entry contains 'N' skip this step.
        This will make the file/dir with NO aceess.
       */
       if (!in_array('N', $perm_entry)) {
              /*
               This is required to remove all the previously denied
               permission for the USER. Just granting permission doesn't
               remove the previously denied permission.
              */
              $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:d';
              $cmd .= ' ' . get_username();
              exec($cmd);
              $cmd = 'icacls ' . $path_escaped . ' /' . 'remove:g';
              $cmd .= ' ' . get_username();
              exec($cmd);

              $cmd = 'icacls ' . $path_escaped . ' /' . $mode;
              $cmd .= ' ' . get_username();
              $cmd .= ':' . '(' . implode($perm_entry, ',') . ')';
              exec($cmd);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

skipif ( )

Definition at line 12 of file common.inc.

                  {
       if(substr(PHP_OS, 0, 3) != 'WIN' ) {
              die('skip windows only test');
       }
       if(stripos(php_uname(), 'XP') !== FALSE) {
              die('skip windows 2003 or newer only test');
       }
}

Here is the caller graph for this function: