1--TEST--
2Test symlink(), linkinfo(), link() and is_link() functions : usage variations - link & dir perms.
3--SKIPIF--
4<?php
5if ( substr(PHP_OS, 0, 3) == 'WIN' ) {
6    die('skip no symlinks on Windows');
7}
8if ( substr(PHP_OS, 0, 3) == 'MAC' ) {
9    die('skip Not valid for MacOS');
10}
11if (PHP_INT_SIZE != 4) {
12  die("skip this test is for 32bit platform only");
13}
14
15// Skip if being run by root (files are always readable, writeable and executable)
16$filename = dirname(__FILE__)."/symlink_link_linkinfo_is_link6_check_root.tmp";
17$fp = fopen($filename, 'w');
18fclose($fp);
19if(fileowner($filename) == 0) {
20        unlink ($filename);
21        die('skip cannot be run as root');
22}
23
24unlink($filename);
25?>
26--FILE--
27<?php
28/* Prototype: bool symlink ( string $target, string $link );
29   Description: creates a symbolic link to the existing target with the specified name link
30
31   Prototype: bool is_link ( string $filename );
32   Description: Tells whether the given file is a symbolic link.
33
34   Prototype: bool link ( string $target, string $link );
35   Description: Create a hard link
36
37   Prototype: int linkinfo ( string $path );
38   Description: Gets information about a link
39*/
40
41/* Variation 6 : Change permission of directory and try creating links inside that directory */
42$file_path = dirname(__FILE__);
43
44echo "*** Creating links in a directory without permission to allow the operation ***\n";
45// temp file used
46$dirname = "$file_path/symlink_link_linkinfo_is_link_variation6";
47mkdir($dirname);
48$filename = "$dirname/symlink_link_linkinfo_is_link_variation6.tmp";
49
50// remove all permissions from dir
51var_dump( chmod($dirname, 0000) );
52
53echo "\n-- Working with soft links --\n";
54$linkname = "$dirname/non_existent_link_variation5.tmp";
55
56// expected: false
57var_dump( symlink($filename, $linkname) ); // this link won't get created
58var_dump( linkinfo($linkname) );
59var_dump( is_link($linkname) );
60// clear the cache
61clearstatcache();
62
63echo "\n-- Working with hard links --\n";
64// expected: false
65var_dump( link($filename, $linkname) );
66var_dump( linkinfo($linkname) );
67var_dump( is_link($linkname) );
68// clear the cache
69clearstatcache();
70
71chmod($dirname, 0777);  // to enable dir deletion
72echo "Done\n";
73?>
74--CLEAN--
75<?php
76$file_path = dirname(__FILE__);
77$dirname = "$file_path/symlink_link_linkinfo_is_link_variation6";
78$filename = "$dirname/symlink_link_linkinfo_is_link_variation6.tmp";
79if(file_exists($filename)) {
80unlink($filename);
81}
82if(file_exists($dirname)) {
83rmdir($dirname);
84}
85?>
86--EXPECTF--
87*** Creating links in a directory without permission to allow the operation ***
88bool(true)
89
90-- Working with soft links --
91
92Warning: symlink(): Permission denied in %s on line %d
93bool(false)
94
95Warning: linkinfo(): Permission denied in %s on line %d
96int(-1)
97bool(false)
98
99-- Working with hard links --
100
101Warning: link(): Permission denied in %s on line %d
102bool(false)
103
104Warning: linkinfo(): Permission denied in %s on line %d
105int(-1)
106bool(false)
107Done
108