From 09b84bd3cea65020b021e096783780bf1e98be8c Mon Sep 17 00:00:00 2001 From: icewing Date: Fri, 30 May 2008 08:26:40 +0000 Subject: Marcus Povey * Improved callpath_gatekeeper git-svn-id: https://code.elgg.org/elgg/trunk@763 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 92d76d84b..9c287fdb7 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -1050,30 +1050,44 @@ * * @param string $path The full path and filename that this function must have in its call stack * @param bool $include_subdirs Are subdirectories of the path ok, or must you specify an absolute path and filename. + * @param bool $limited_mode If true then the calling method or function must be directly called by something on $path, if false the whole call stack is searched. */ - function callpath_gatekeeper($path, $include_subdirs = true) + function callpath_gatekeeper($path, $include_subdirs = true, $limited_mode = false) { + global $CONFIG; + $path = sanitise_string($path); if ($path) { $callstack = debug_backtrace(); - + foreach ($callstack as $call) { if ($include_subdirs) { if (strpos($call['file'], $path) === 0) - return true; + if ($limited_mode) { + if ($callstack[2] === $call) return true; + } + else + return true; } else { if (strcmp($path, $call['file'])==0) - return true; + if ($limited_mode) { + if ($callstack[2] === $call) return true; + } else + return true; } + } } + if ($CONFIG->debug) + system_message("Gatekeeper'd function called from {$callstack[2]['file']}:{$callstack[2]['line']}\n\nStack trace:\n\n" . print_r($callstack, true)); + return false; } -- cgit v1.2.3