Annotation of embedaddon/php/ext/mysqli/tests/mysqli_set_local_infile_handler_openbasedir.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: mysqli_set_local_infile_handler() - open basedir restrictions
3: --SKIPIF--
4: <?php
5: if (!$fp = @fopen('skipif.inc', 'r'))
6: die("skip open_basedir restrictions forbid opening include files");
7:
8: include_once('skipif.inc');
9: include_once('skipifemb.inc');
10: include_once('skipifconnectfailure.inc');
11:
12: if (!function_exists('mysqli_set_local_infile_handler'))
13: die("skip - function not available.");
14:
15: include_once('connect.inc');
16: if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
17: die("skip Cannot connect to MySQL");
18:
19: if (!$res = mysqli_query($link, 'SHOW VARIABLES LIKE "local_infile"')) {
20: mysqli_close($link);
21: die("skip Cannot check if Server variable 'local_infile' is set to 'ON'");
22: }
23:
24: include_once("local_infile_tools.inc");
25: if ($msg = check_local_infile_support($link, $engine))
26: die(sprintf("skip %s, [%d] %s", $msg, $link->errno, $link->error));
27:
28: mysqli_close($link);
29: ?>
30: --INI--
31: open_basedir="."
32: --FILE--
33: <?php
34: @include('connect.inc');
35: if (!isset($db)) {
36: // stupid run-tests.php - any idea how to set system ini setting dynamically???
37: print "Warning: tempnam(): open_basedir restriction in effect. File(grrr) is not within the allowed path(s): (grrr) in grrr on line 0
38: [005 + 1] Cannot create CVS file ''
39: Callback set to 'callback_simple'
40: [012] LOAD DATA failed, [0] grrr
41: [014/0] [0] ''
42: done!";
43: die();
44: }
45:
46: require_once('connect.inc');
47: require_once('local_infile_tools.inc');
48: require_once('table.inc');
49:
50: function callback_simple($fp, &$buffer, $buflen, &$error) {
51: static $invocation = 0;
52:
53: printf("Callback: %d\n", $invocation);
54:
55: $invocation++;
56: if (!is_resource($fp))
57: printf("[012] First argument passed to callback is not a resource but %s/%s\n",
58: $fp, gettype($fp));
59:
60: if (!$buffer = fread($fp, $buflen)) {
61: if ($invocation == 1) {
62: printf("[013] Cannot read from stream\n");
63: $error = 'Cannot read from stream';
64: } else {
65: return strlen($buffer);
66: }
67: }
68:
69: $lines = explode("\n", $buffer);
70: if (count($lines) != 4 && strlen($buffer) > 0) {
71: printf("[014] Test is too simple to handle a buffer of size %d that cannot hold all lines\n", $buflen);
72: $error = 'Parser too simple';
73: }
74:
75: $buffer = '';
76: foreach ($lines as $k => $line) {
77: if ('' === trim($line))
78: continue;
79:
80: $columns = explode(';', $line);
81: if (empty($columns)) {
82: printf("[015] Cannot parse columns\n");
83: $error = 'Cannot parse columns';
84: }
85:
86: // increase id column value
87: $columns[0] += 1;
88: $buffer .= implode(';', $columns);
89: $buffer .= "\n";
90: }
91:
92: return strlen($buffer);
93: }
94:
95: $file = create_standard_csv(5);
96: $expected = array(
97: array('id' => 98, 'label' => 'x'),
98: array('id' => 99, 'label' => 'y'),
99: array('id' => 100, 'label' => 'z'),
100: );
101: try_handler(10, $link, $file, 'callback_simple', $expected);
102: mysqli_close($link);
103: print "done!";
104: ?>
105: --CLEAN--
106: <?php
107: require_once("clean_table.inc");
108: ?>
109: --EXPECTF--
110: Warning: tempnam(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s) in %s on line %d
111: [005 + 1] Cannot create CVS file ''
112: Callback set to 'callback_simple'
113: [012] LOAD DATA failed, [%d] %s
114: [014/0] [0] ''
115: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>