]> git.mjollnir.org Git - s9y.git/commitdiff
Fix crashing SQLite. Stupid ***$§*$"**"§$"§
authorgarvinhicking <garvinhicking>
Thu, 15 Sep 2005 10:08:57 +0000 (10:08 +0000)
committergarvinhicking <garvinhicking>
Thu, 15 Sep 2005 10:08:57 +0000 (10:08 +0000)
thing of a DB layer dies unexpectedly in simple WHERE x IN (...) queries.
Also fix some HTTP Port issues, Cookie authentication and category ACL issues.

Thanks a bunch to Mark Kubacki!

include/db/mysql.inc.php
include/db/mysqli.inc.php
include/db/postgres.inc.php
include/db/sqlite.inc.php
include/functions_config.inc.php
include/functions_entries.inc.php
serendipity_config.inc.php

index 51dc47bad5f06cb5472f7979ea34085acfced31c..3144143e9326f7ddb8c0910bf41a5dff95d870bf 100644 (file)
@@ -14,6 +14,10 @@ function serendipity_db_end_transaction($commit){
     }
 }
 
+function serendipity_db_in_sql($col, &$search_ids) {
+    return $col . " IN (" . implode(', ', $search_ids) . ")";
+}
+
 /* Issues a query to the underlying database;
  * returns:
  *   false if there was an error,
index f3549b3f5bcdd7f250c5605c7270b2ba525868df..e2f244186f5724c17f4702428c759355082c2c2f 100644 (file)
@@ -14,6 +14,10 @@ function serendipity_db_end_transaction($commit){
     }
 }
 
+function serendipity_db_in_sql($col, &$search_ids) {
+    return $col . " IN (" . implode(', ', $search_ids) . ")";
+}
+
 /* Issues a query to the underlying database;
  * returns:
  *   false if there was an error,
index b68fb0b21d1610efaa2fc4fa7de13a5914c3dd1a..0c758f1250cce9b3cd4c797cc88123a8872598a2 100644 (file)
@@ -14,6 +14,10 @@ function serendipity_db_end_transaction($commit){
     }
 }
 
+function serendipity_db_in_sql($col, &$search_ids) {
+    return $col . " IN (" . implode(', ', $search_ids) . ")";
+}
+
 function serendipity_db_connect() {
     global $serendipity;
 
index 009d12fd3b8fa885bb11c5c63e8723abc9bf93ff..fe3aa880276bae4a7563a1edb11f9fa05df50e80 100644 (file)
@@ -99,6 +99,20 @@ function serendipity_db_sqlite_fetch_array($res, $type = SQLITE_BOTH)
     return $row;
 }
 
+function serendipity_db_in_sql($col, &$search_ids, $type = ' OR ') {
+    $sql = array();
+    if (!is_array($search_ids)) {
+        return false;
+    }
+    
+    foreach($search_ids AS $id) {
+        $sql[] = $col . ' = ' . $id;
+    }
+    
+    $cond = '(' . implode($type, $sql) . ')';
+    return $cond;
+}
+
 function &serendipity_db_query($sql, $single = false, $result_type = "both", $reportErr = true, $assocKey = false, $assocVal = false, $expectError = false)
 {
     global $serendipity;
@@ -110,8 +124,13 @@ function &serendipity_db_query($sql, $single = false, $result_type = "both", $re
 
     static $debug = false;
 
-    if ($debug) $fp = @fopen('sqlite.log', 'a');
-
+    if ($debug) {
+        // Open file and write directly. In case of crashes, the pointer needs to be killed.
+        $fp = @fopen('sqlite.log', 'a');
+        fwrite($fp, '[' . date('d.m.Y H:i') . '] SQLITE QUERY: ' . $sql . "\n\n");
+        fclose($fp);
+    }
+    
     if ($reportErr && !$expectError) {
         $res = sqlite_query($sql, $serendipity['dbConn']);
     } else {
@@ -124,11 +143,13 @@ function &serendipity_db_query($sql, $single = false, $result_type = "both", $re
             var_dump($sql);
             return "problem with query";
         }
-        if ($debug) fwrite($fp, '[' . date('d.m.Y H:i') . '] [ERROR] SQLITE QUERY: ' . $sql . "\n\n");
+        if ($debug) {
+            $fp = @fopen('sqlite.log', 'a');
+            fwrite($fp, '[' . date('d.m.Y H:i') . '] [ERROR] ' . "\n\n");
+            fclose($fp);
+        }
 
         return false;
-    } elseif ($debug) {
-        fwrite($fp, '[' . date('d.m.Y H:i') . '] SQLITE QUERY: ' . $sql . "\n\n");
     }
 
     if ($res === true) {
@@ -152,8 +173,11 @@ function &serendipity_db_query($sql, $single = false, $result_type = "both", $re
             }
         }
 
-        if ($debug) fwrite($fp, '[' . date('d.m.Y H:i') . '] SQLITE RESULT: ' . print_r($rows, true). "\n\n");
-        if ($debug) fclose($fp);
+        if ($debug) {
+            $fp = @fopen('sqlite.log', 'a');
+            fwrite($fp, '[' . date('d.m.Y H:i') . '] SQLITE RESULT: ' . print_r($rows, true). "\n\n");
+            fclose($fp);
+        }
 
         if ($single && count($rows) == 1) {
             return $rows[0];
index 180284c4d0a3a35e4f661021e87fae093998bd82..8de289d01f88f009d9712063e6ce6ef94d4db8bf 100644 (file)
@@ -219,7 +219,7 @@ function serendipity_login($use_external = true) {
         }
     } elseif ( isset($serendipity['COOKIE']['author_information']) ) {
         $cookie = unserialize(base64_decode($serendipity['COOKIE']['author_information']));
-        if (serendipity_authenticate_author($cookie['username'], $cookie['password'], $use_external)) {
+        if (serendipity_authenticate_author($cookie['username'], $cookie['password'], false, $use_external)) {
             return true;
         } else {
             serendipity_deleteCookie('author_information');
@@ -1050,7 +1050,7 @@ function serendipity_ACL_SQL(&$cond, $append_category = false) {
     if (!isset($serendipity['enableACL']) || $serendipity['enableACL'] == true) {
         if ($_SESSION['serendipityAuthedUser'] === true) {
             $read_id = (int)$serendipity['authorid'];
-            $read_id_sql = 'acl_a.groupid';
+            $read_id_sql = 'acl_a.groupid OR acl_acc.groupid = 0';
         } else {
             // "0" as category property counts as "anonymous viewers" 
             $read_id     = 0;
@@ -1084,7 +1084,7 @@ function serendipity_ACL_SQL(&$cond, $append_category = false) {
         // When in Admin-Mode, apply readership permissions.
         $cond['and'] .= "    (
                                  c.categoryid IS NULL 
-                                 OR ( acl_acc.groupid = " . $read_id_sql . " )
+                                 OR ( acl_acc.groupid = " . $read_id_sql . ")
                                  OR ( acl_acc.artifact_id IS NULL 
                                       " . (isset($serendipity['GET']['adminModule']) && 
                                            $serendipity['GET']['adminModule'] == 'entries' && 
index 836b098f942378fe3cfd005e5414480ad6450ce8..742ecba3dcb627316e64632acc2b0af14c89f98b 100644 (file)
@@ -270,6 +270,8 @@ function serendipity_fetchEntries($range = null, $full = true, $limit = '', $fet
                     ORDER BY {$cond['orderby']}
                     $limit";
 
+    // DEBUG:
+    // die($query);
     $ret = serendipity_db_query($query);
 
     if (is_string($ret)) {
@@ -305,7 +307,7 @@ function serendipity_fetchEntries($range = null, $full = true, $limit = '', $fet
                     FROM {$serendipity['dbPrefix']}category AS c
                LEFT JOIN {$serendipity['dbPrefix']}entrycat AS ec
                       ON ec.categoryid = c.categoryid
-                   WHERE ec.entryid IN (" . implode(', ', $search_ids) . ")";
+                   WHERE " . serendipity_db_in_sql('ec.entryid', $search_ids);
 
         $search_ret = serendipity_db_query($query);
 
index cddd6804ffc042d8c18dcdef5f67a1c6e49f81a3..22ffb0bdf351e184f20e737e8ff40ce9be4323de 100644 (file)
@@ -249,7 +249,7 @@ $serendipity['permissionLevels'] = array(USERLEVEL_EDITOR => USERLEVEL_EDITOR_DE
 
 if ( (isset($serendipity['autodetect_baseURL']) && serendipity_db_bool($serendipity['autodetect_baseURL'])) ||
      (isset($serendipity['embed']) && serendipity_db_bool($serendipity['embed'])) ) {
-    $serendipity['baseURL'] = 'http' . (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != '80' ? ':' . $_SERVER['SERVER_PORT'] : '') . $serendipity['serendipityHTTPPath'];
+    $serendipity['baseURL'] = 'http' . (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . (!strstr($_SERVER['HTTP_HOST'], ':') && !empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != '80' ? ':' . $_SERVER['SERVER_PORT'] : '') . $serendipity['serendipityHTTPPath'];
 }
 
 /*