File inc/conn.inc.php changed (mode: 100644) (index 8110d34..53d4d9b) |
... |
... |
function rg_conn_shutdown($key, $what) |
28 |
28 |
return; |
return; |
29 |
29 |
|
|
30 |
30 |
if (($what == 0) || ($what == 2)) |
if (($what == 0) || ($what == 2)) |
31 |
|
$rg_conns[$key]['shutdow_read'] = 1; |
|
|
31 |
|
$rg_conns[$key]['shutdown_read'] = 1; |
32 |
32 |
|
|
33 |
33 |
if (($what == 1) || ($what == 2)) |
if (($what == 1) || ($what == 2)) |
34 |
|
$rg_conns[$key]['shutdow_write'] = 1; |
|
|
34 |
|
$rg_conns[$key]['shutdown_write'] = 1; |
35 |
35 |
|
|
36 |
|
@socket_shutdown($rg_conns[$key]['socket'], $what); |
|
37 |
|
rg_log($key . ': shutdown ' . $what); |
|
|
36 |
|
rg_log($key . ': marking socket for shutdown ' . $what); |
38 |
37 |
} |
} |
39 |
38 |
|
|
40 |
39 |
/* |
/* |
|
... |
... |
function rg_conn_destroy($key) |
51 |
50 |
rg_log($key . ': bytes_recv=' . $rg_conns[$key]['bytes_recv'] |
rg_log($key . ': bytes_recv=' . $rg_conns[$key]['bytes_recv'] |
52 |
51 |
. ' bytes_sent=' . $rg_conns[$key]['bytes_sent']); |
. ' bytes_sent=' . $rg_conns[$key]['bytes_sent']); |
53 |
52 |
|
|
54 |
|
if ($rg_conns[$key]['exit_on_close']) { |
|
55 |
|
rg_log($key . ': exit_on_close is set, so exit'); |
|
56 |
|
exit(1); |
|
57 |
|
} |
|
|
53 |
|
@socket_close($rg_conns[$key]['socket']); |
58 |
54 |
|
|
59 |
55 |
if (isset($rg_conns[$key]['func_destroy'])) |
if (isset($rg_conns[$key]['func_destroy'])) |
60 |
56 |
$rg_conns[$key]['func_destroy']($key); |
$rg_conns[$key]['func_destroy']($key); |
|
... |
... |
function rg_conn_destroy($key) |
66 |
62 |
if (isset($rg_conns[$key]['socket'])) |
if (isset($rg_conns[$key]['socket'])) |
67 |
63 |
if (is_resource($rg_conns[$key]['socket'])) |
if (is_resource($rg_conns[$key]['socket'])) |
68 |
64 |
@socket_close($rg_conns[$key]['socket']); |
@socket_close($rg_conns[$key]['socket']); |
|
65 |
|
|
|
66 |
|
if ($rg_conns[$key]['exit_on_close']) { |
|
67 |
|
rg_log($key . ': exit_on_close is set, so exit'); |
|
68 |
|
exit(1); |
|
69 |
|
} |
|
70 |
|
|
69 |
71 |
unset($rg_conns[$key]); |
unset($rg_conns[$key]); |
70 |
72 |
} |
} |
71 |
73 |
|
|
|
... |
... |
function rg_conn_send($key) |
147 |
149 |
} |
} |
148 |
150 |
|
|
149 |
151 |
$s['send'] = substr($s['send'], $r); |
$s['send'] = substr($s['send'], $r); |
150 |
|
if (empty($s['send'])) |
|
|
152 |
|
if (empty($s['send'])) { |
151 |
153 |
unset($rg_events['w'][$key]); |
unset($rg_events['w'][$key]); |
|
154 |
|
if ($s['shutdown_write'] == 1) { |
|
155 |
|
@socket_shutdown($s['socket'], 1 /*writing*/); |
|
156 |
|
rg_log($key . ': shutdown write'); |
|
157 |
|
} |
|
158 |
|
} |
152 |
159 |
|
|
153 |
160 |
$s['bytes_sent'] += $r; |
$s['bytes_sent'] += $r; |
154 |
161 |
|
|
File scripts/rgfs.php changed (mode: 100644) (index 035ac3c..993a56d) |
... |
... |
require_once(__DIR__ . '/../inc/rgfs.inc.php'); |
21 |
21 |
require_once(__DIR__ . '/../inc/user/packages.inc.php'); |
require_once(__DIR__ . '/../inc/user/packages.inc.php'); |
22 |
22 |
|
|
23 |
23 |
define('RGFS_EPERM', 1); |
define('RGFS_EPERM', 1); |
24 |
|
//define('RGFS_EACCESS', ?); |
|
|
24 |
|
//define('RGFS_EACCESS', 2); |
25 |
25 |
define('RGFS_ENOENT', 2); |
define('RGFS_ENOENT', 2); |
26 |
26 |
define('RGFS_EIO', 5); |
define('RGFS_EIO', 5); |
27 |
27 |
define('RGFS_EINVAL', 22); |
define('RGFS_EINVAL', 22); |
|
28 |
|
define('RGFS_ENOTSUP', 95); |
28 |
29 |
|
|
29 |
30 |
$rg_fs_ver = 0x01; |
$rg_fs_ver = 0x01; |
30 |
31 |
|
|
|
... |
... |
function rgfs_validate_and_store_meta($add_path, $remove_path, &$s) |
170 |
171 |
return $ret; |
return $ret; |
171 |
172 |
} |
} |
172 |
173 |
|
|
|
174 |
|
function send_fatal_error(string $key, string $msg) |
|
175 |
|
{ |
|
176 |
|
debug($key, $msg); |
|
177 |
|
$p2 = pack('C', 0xFF); // fatal error |
|
178 |
|
$p = pack('N', strlen($p2)) . $p2; |
|
179 |
|
//debug($key, ' DEBUG: p: ' . $p); |
|
180 |
|
rg_conn_enq($key, $p); |
|
181 |
|
rg_conn_shutdown($key, 2 /* 1=write, 2=read/write */); |
|
182 |
|
} |
|
183 |
|
|
173 |
184 |
/* |
/* |
174 |
185 |
* Dispatch a command from a worker (one json) |
* Dispatch a command from a worker (one json) |
175 |
186 |
*/ |
*/ |
|
... |
... |
function xdispatch_one($key, $tlv) |
220 |
231 |
foreach ($list as $k) { |
foreach ($list as $k) { |
221 |
232 |
// Stupid php |
// Stupid php |
222 |
233 |
if (!isset($a[$k])) { |
if (!isset($a[$k])) { |
223 |
|
debug($key, 'Client did not sent [' . $k . ']!'); |
|
224 |
|
rg_conn_shutdown($key, 2); |
|
|
234 |
|
send_fatal_error($key, |
|
235 |
|
'Client did not sent [' . $k . ']!'); |
225 |
236 |
return; |
return; |
226 |
237 |
} |
} |
227 |
238 |
// Stupid php: 'empty('0') is true'! |
// Stupid php: 'empty('0') is true'! |
228 |
239 |
if (strcmp($a[$k], '0') == 0) |
if (strcmp($a[$k], '0') == 0) |
229 |
240 |
continue; |
continue; |
230 |
241 |
if (empty($a[$k])) { |
if (empty($a[$k])) { |
231 |
|
debug($key, 'Client did sent empty [' . $k . ']!'); |
|
232 |
|
rg_conn_shutdown($key, 2); |
|
|
242 |
|
send_fatal_error($key, |
|
243 |
|
'Client did sent empty [' . $k . ']!'); |
233 |
244 |
return; |
return; |
234 |
245 |
} |
} |
235 |
246 |
} |
} |
|
... |
... |
function xdispatch_one($key, $tlv) |
237 |
248 |
if ($a['uid'] > 0) { |
if ($a['uid'] > 0) { |
238 |
249 |
$job_ui = rg_user_info($s['db'], $a['uid'], '', ''); |
$job_ui = rg_user_info($s['db'], $a['uid'], '', ''); |
239 |
250 |
if ($job_ui['exists'] != 1) { |
if ($job_ui['exists'] != 1) { |
240 |
|
debug($key, 'invalid user id ' . $a['uid']); |
|
241 |
|
rg_conn_shutdown($key, 2); |
|
|
251 |
|
send_fatal_error($key, |
|
252 |
|
'invalid user id ' . $a['uid']); |
242 |
253 |
return; |
return; |
243 |
254 |
} |
} |
244 |
255 |
$a['job_username'] = $job_ui['username']; |
$a['job_username'] = $job_ui['username']; |
|
... |
... |
function xdispatch_one($key, $tlv) |
246 |
257 |
|
|
247 |
258 |
$pri = rg_pkg_repo_info($s['db'], $a['uid'], $a['pkg_repo_id']); |
$pri = rg_pkg_repo_info($s['db'], $a['uid'], $a['pkg_repo_id']); |
248 |
259 |
if ($pri['exists'] != 1) { |
if ($pri['exists'] != 1) { |
249 |
|
debug($key, $pri['errmsg']); |
|
250 |
|
rg_conn_shutdown($key, 2); |
|
|
260 |
|
send_fatal_error($key, $pri['errmsg']); |
251 |
261 |
return; |
return; |
252 |
262 |
} |
} |
253 |
263 |
if (strcmp($pri['rgfs_key'], $a['key']) != 0) { |
if (strcmp($pri['rgfs_key'], $a['key']) != 0) { |
254 |
|
debug($key, 'rgfs key does not match' |
|
|
264 |
|
send_fatal_error($key, |
|
265 |
|
'rgfs key does not match' |
255 |
266 |
. ' [' . substr($pri['rgfs_key'], 0, 1) . ']' |
. ' [' . substr($pri['rgfs_key'], 0, 1) . ']' |
256 |
267 |
. ' != [' . substr($a['key'], 0, 1) . ']!'); |
. ' != [' . substr($a['key'], 0, 1) . ']!'); |
257 |
|
rg_conn_shutdown($key, 2); |
|
258 |
268 |
return; |
return; |
259 |
269 |
} |
} |
260 |
270 |
// If it is a user pkg repo, for now, we allow only the owner. |
// If it is a user pkg repo, for now, we allow only the owner. |
|
... |
... |
function xdispatch_one($key, $tlv) |
262 |
272 |
debug($key, 'uid does not match pri=' . $pri['uid'] |
debug($key, 'uid does not match pri=' . $pri['uid'] |
263 |
273 |
. ' != ' . $a['uid'] . '!'); |
. ' != ' . $a['uid'] . '!'); |
264 |
274 |
/* |
/* |
265 |
|
rg_conn_shutdown($key, 2); |
|
|
275 |
|
send_fatal_error($key, 'invalid pkg repo id'); |
266 |
276 |
return; |
return; |
267 |
277 |
TODO: if a user knows the key of the rgfs, we will allow her! */ |
TODO: if a user knows the key of the rgfs, we will allow her! */ |
268 |
278 |
} |
} |
|
... |
... |
function xdispatch_one($key, $tlv) |
270 |
280 |
|
|
271 |
281 |
$sri = rg_pkg_subrepo_info($s['db'], $a['uid'], $a['pkg_subrepo_id']); |
$sri = rg_pkg_subrepo_info($s['db'], $a['uid'], $a['pkg_subrepo_id']); |
272 |
282 |
if ($sri['exists'] != 1) { |
if ($sri['exists'] != 1) { |
273 |
|
debug($key, $sri['errmsg']); |
|
274 |
|
rg_conn_shutdown($key, 2); |
|
|
283 |
|
send_fatal_error($key, $sri['errmsg']); |
275 |
284 |
return; |
return; |
276 |
285 |
} |
} |
277 |
286 |
if ($sri['pkg_repo_id'] != $a['pkg_repo_id']) { |
if ($sri['pkg_repo_id'] != $a['pkg_repo_id']) { |
278 |
|
debug($key, 'pkg_subrepo_id is not a child of pkg_repo_id!'); |
|
279 |
|
rg_conn_shutdown($key, 2); |
|
|
287 |
|
send_fatal_error($key, |
|
288 |
|
'pkg_subrepo_id is not a child of pkg_repo_id!'); |
280 |
289 |
return; |
return; |
281 |
290 |
} |
} |
282 |
291 |
|
|
|
... |
... |
function xdispatch_one($key, $tlv) |
284 |
293 |
if ($a['repo_id'] > 0) { |
if ($a['repo_id'] > 0) { |
285 |
294 |
$ri = rg_repo_info($s['db'], $a['repo_id'], 0, ''); |
$ri = rg_repo_info($s['db'], $a['repo_id'], 0, ''); |
286 |
295 |
if ($ri['exists'] != 1) { |
if ($ri['exists'] != 1) { |
287 |
|
debug($key, 'non-existing/no access repo id ' . $a['repo_id']); |
|
288 |
|
rg_conn_shutdown($key, 2); |
|
|
296 |
|
send_fatal_error($key, |
|
297 |
|
'non-existing/no access repo id ' . $a['repo_id']); |
289 |
298 |
return; |
return; |
290 |
299 |
} |
} |
291 |
300 |
|
|
|
... |
... |
function xdispatch_one($key, $tlv) |
294 |
303 |
debug($key, 'invalid repo_id: its uid is ' . $ri['uid'] |
debug($key, 'invalid repo_id: its uid is ' . $ri['uid'] |
295 |
304 |
. ' but job\'s uid is ' . $a['uid']); |
. ' but job\'s uid is ' . $a['uid']); |
296 |
305 |
/* |
/* |
297 |
|
rg_conn_shutdown($key, 2); |
|
|
306 |
|
send_fatal_error($key, 'bla'); |
298 |
307 |
return; |
return; |
299 |
308 |
TODO: user is authenticated, we will allow her */ |
TODO: user is authenticated, we will allow her */ |
300 |
309 |
} |
} |
301 |
310 |
|
|
302 |
311 |
$repo_ui = rg_user_info($s['db'], $ri['uid'], '', ''); |
$repo_ui = rg_user_info($s['db'], $ri['uid'], '', ''); |
303 |
312 |
if ($repo_ui['exists'] != 1) { |
if ($repo_ui['exists'] != 1) { |
304 |
|
debug($key, 'invalid user id ' . $ri['uid']); |
|
305 |
|
rg_conn_shutdown($key, 2); |
|
|
313 |
|
send_fatal_error($key, |
|
314 |
|
'invalid user id ' . $ri['uid']); |
306 |
315 |
return; |
return; |
307 |
316 |
} |
} |
308 |
317 |
$a['repo_uid'] = $ri['uid']; // TODO: propagate it to worker script |
$a['repo_uid'] = $ri['uid']; // TODO: propagate it to worker script |
|
... |
... |
function xdispatch_one($key, $tlv) |
349 |
358 |
if (!file_exists($s['dir'])) { |
if (!file_exists($s['dir'])) { |
350 |
359 |
$r = @mkdir($s['dir'], 0700, TRUE); |
$r = @mkdir($s['dir'], 0700, TRUE); |
351 |
360 |
if ($r === FALSE) { |
if ($r === FALSE) { |
352 |
|
debug($key, 'cannot create main dir: ' |
|
|
361 |
|
send_fatal_error($key, |
|
362 |
|
'cannot create main dir: ' |
353 |
363 |
. rg_php_err()); |
. rg_php_err()); |
354 |
|
rg_conn_shutdown($key, 2); |
|
355 |
364 |
return; |
return; |
356 |
365 |
} |
} |
357 |
366 |
} |
} |
|
... |
... |
function xdispatch_one($key, $tlv) |
850 |
859 |
// We will not respect it for now. Ever? |
// We will not respect it for now. Ever? |
851 |
860 |
break; |
break; |
852 |
861 |
|
|
|
862 |
|
// 0x12 is generic variable |
|
863 |
|
|
|
864 |
|
case 0x13: // getxattr |
|
865 |
|
$t = @unpack('ntarget_len/nattr_name_len', $tlv['data']); |
|
866 |
|
if ($t === FALSE) { |
|
867 |
|
debug($key, 'unpack error: ' . rg_php_err()); |
|
868 |
|
$p2 .= pack('CN', 0x00, RGFS_EPERM); |
|
869 |
|
break; |
|
870 |
|
} |
|
871 |
|
|
|
872 |
|
$t = @unpack('a' . $t['target_len'] . 'target/a' |
|
873 |
|
. $t['attr_name_len'] . 'attr_name', $tlv['data'], 2 + 2); |
|
874 |
|
if ($t === FALSE) { |
|
875 |
|
debug($key, 'unpack error: ' . rg_php_err()); |
|
876 |
|
$p2 .= pack('CN', 0x00, RGFS_EPERM); |
|
877 |
|
break; |
|
878 |
|
} |
|
879 |
|
|
|
880 |
|
debug($key, 'getxattr target=[' . $t['target'] . ']' |
|
881 |
|
. ' attr_name=[' . $t['attr_name'] . ']'); |
|
882 |
|
|
|
883 |
|
$r = rgfs_validate($t['target'], $s); |
|
884 |
|
if ($r['ok'] != 1) { |
|
885 |
|
debug($key, $r['errmsg']); |
|
886 |
|
$p2 .= pack('CN', 0x00, RGFS_EPERM); |
|
887 |
|
break; |
|
888 |
|
} |
|
889 |
|
|
|
890 |
|
// For now, we return that they are not supported |
|
891 |
|
$p2 .= pack('CN', 0x00, RGFS_ENOTSUP); |
|
892 |
|
// todo $p2 .= pack('C', 0x01) . len_of_attr; |
|
893 |
|
break; |
|
894 |
|
|
853 |
895 |
default: |
default: |
854 |
896 |
debug($key, 'invalid command: ' . rg_array2string($tlv)); |
debug($key, 'invalid command: ' . rg_array2string($tlv)); |
855 |
|
rg_conn_shutdown($key, 2); |
|
|
897 |
|
send_fatal_error($key, 'invalid command'); |
856 |
898 |
return; |
return; |
857 |
899 |
} |
} |
858 |
900 |
|
|