Commit edd2817e30bd6e55b5a2e3d434de5ce4604cea18

Authored by rob
1 parent 64ec17ba

Added checks for nulls when retrieived folders and documents from the database. …

… If a folder/document cannot be retrieved, an entry is placed in the log file


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1134 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 19 additions and 1 deletions
lib/security/permission.inc
... ... @@ -27,7 +27,12 @@ class Permission {
27 27 * @return boolean true if the current user has document write permission, false otherwise and set $_SESSION["errorMessage"]
28 28 */
29 29 function userHasDocumentWritePermission($iDocumentID) {
  30 + global $default;
30 31 $oDocument = & Document::get($iDocumentID);
  32 + if ($oDocument == null) {
  33 + $default->log->info("Failed to retrieve document with ID $iDocumentID from database");
  34 + return false;
  35 + }
31 36 if (Permission::userHasFolderWritePermission($oDocument->getFolderID()) ||
32 37 Permission::userHasWriteRoleForDocument($iDocumentID)) {
33 38 return true;
... ... @@ -48,7 +53,12 @@ class Permission {
48 53 * @return boolean true if the current user has document read permission, false otherwise and set $_SESSION["errorMessage"]
49 54 */
50 55 function userHasDocumentReadPermission($iDocumentID) {
  56 + global $default;
51 57 $oDocument = & Document::get($iDocumentID);
  58 + if ($oDocument == null) {
  59 + $default->log->info("Failed to retrieve document with ID $iDocumentID from database");
  60 + return false;
  61 + }
52 62 if (Permission::userHasDocumentWritePermission($iDocumentID) ||
53 63 Permission::userHasReadRoleForDocument($iDocumentID) ||
54 64 Permission::userHasFolderReadPermission($oDocument->getFolderID())) {
... ... @@ -132,6 +142,10 @@ class Permission {
132 142 function userHasGroupWritePermissionForFolder($iFolderID) {
133 143 global $default, $lang_err_user_folder_write;
134 144 $oFolder = Folder::get($iFolderID);
  145 + if ($oFolder == null) {
  146 + $default->log->info("Failed to retrieve folder with ID $iFolderID from database");
  147 + return false;
  148 + }
135 149 $sql = $default->db;
136 150 $sql->query("SELECT GFL.folder_id " .
137 151 "FROM groups_folders_link AS GFL INNER JOIN users_groups_link AS UGL ON GFL.group_id = UGL.group_id " .
... ... @@ -179,6 +193,10 @@ class Permission {
179 193 global $default, $lang_err_user_folder_read;
180 194 $sql = $default->db;
181 195 $oFolder = Folder::get($iFolderID);
  196 + if ($oFolder == null) {
  197 + $default->log->info("Failed to retrieve folder with ID $iFolderID from database");
  198 + return false;
  199 + }
182 200 //$sql->query("SELECT * FROM " . $default->owl_groups_folders_table = "groups_folders_link" . " WHERE folder_id = " . $iFolderID . " AND user_id = " . $_SESSION["userID"] . " AND can_read = 1");
183 201 $sql->query("SELECT GFL.folder_id " .
184 202 "FROM groups_folders_link AS GFL INNER JOIN users_groups_link AS UGL ON GFL.group_id = UGL.group_id " .
... ... @@ -217,7 +235,7 @@ class Permission {
217 235 *
218 236 * @return boolean true if the user is in the group, false otherwise and sets $_SESSION["errorMessage"]
219 237 */
220   - function userIsInGroupName($sGroupName) {
  238 + function userIsInGroupName($sGroupName) {
221 239 global $default, $lang_err_user_group;
222 240 $sql = $default->db;
223 241 $sql->query("SELECT GULT.id FROM " . $default->owl_users_groups_table . " AS GULT INNER JOIN " . $default->owl_groups_table . " AS G ON GULT.group_id = G.ID WHERE G.name = '" . $sGroupName . "' AND user_id = " . $_SESSION["userID"]);
... ...