]> andersk Git - sql-web.git/blobdiff - lib/security.lib.php
Fix SQL injection vulnerability in DB deletion
[sql-web.git] / lib / security.lib.php
index f7a50b01d9255f2019eb97d542dfd6e4078996f4..1ac28492f3d6fd8dc6f6be2e6026da3cf24e4e86 100644 (file)
@@ -12,9 +12,9 @@ class Login {
                if (empty($u)) return;
                $this->u = $u;
                $this->p = $p;
-               if ((string)intval($u)===(string)$u) {
+               if (is_null($p)) {
                        $this->id = $u;
-                       $opt = sprintf(" Username = '%s' OR UserId = '%s'", mysql_escape_string($u), mysql_escape_string($u));
+                       $opt = sprintf(" UserId = '%s'", mysql_escape_string($u));
                } else {
                        $opt = sprintf(" Username = '%s'", mysql_escape_string($u));
                        $opt .= (is_null($p)?'':sprintf(" AND Password='%s'", mysql_escape_string(base64_encode($p))));
@@ -58,13 +58,6 @@ class Login {
     function expire() {
         $this->info = null;
     }
-    function refresh() {
-               if (!empty($this->id)) {
-                       $this->Login($this->id);
-               } else {
-                       $this->Login($this->u,$this->p);
-               }
-    }
     function update($name=null,$email=null) {
         if (!$this->exists()) return;
         $arr = array();
@@ -281,7 +274,7 @@ function getSSLCert() {
         $email = trim($fu[1]);
     } else {
         $name = isset($_SERVER['SSL_CLIENT_S_DN_CN'])?$_SERVER['SSL_CLIENT_S_DN_CN']:null;
-        $email = isset($_SERVER['SSL_CLIENT_S_DN_Email'])?$_SERVER['SSL_CLIENT_S_DN_Email']:null;
+        $email = isset($_SERVER['REMOTE_USER'])?$_SERVER['REMOTE_USER']:null;
     }
     if (!is_null($email)) {
         $user = explode('@',$email);
@@ -292,6 +285,13 @@ function getSSLCert() {
        }
 }
 
+function getUsernameID($username) {
+       $sql = sprintf("SELECT UserId FROM User USE INDEX (UsernameID) WHERE Username = '%s'", mysql_escape_string($username));
+       $r = fetchRows(DBSelect($sql), 'UserId');
+       $r = array_shift($r);
+       return count($r)?$r['UserId']:null;
+}
+
 ## 302 REDIRECTS
 
 function redirect($target=null,$secure=null) {
@@ -392,7 +392,7 @@ function delDB($dbname) {
        $arr['bEnabled'] = 0;
        $sql = sprintf("UPDATE DB SET %s WHERE DB.Name = '%s'",
                                        buildSQLSet($arr),
-                                       $dbname);
+                                       mysql_escape_string($dbname));
        DBUpdate($sql);
 
        return true;
This page took 0.028731 seconds and 4 git commands to generate.