]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 95732 - remove logincookies.cryptpassword, and invalidate cookies from
authorbbaetz%student.usyd.edu.au <>
Mon, 4 Feb 2002 20:23:04 +0000 (20:23 +0000)
committerbbaetz%student.usyd.edu.au <>
Mon, 4 Feb 2002 20:23:04 +0000 (20:23 +0000)
the db when required instead.
(Also fixes bug 58242 as a side effect)

r=myk, kiko

CGI.pl
checksetup.pl
editusers.cgi
globals.pl
relogin.cgi
token.cgi
userprefs.cgi

diff --git a/CGI.pl b/CGI.pl
index f99013e25d720fd003e47163a9be9fb7ef3bcb8b..d1a274680019925e8cd748914fb8d4074d0ba518 100644 (file)
--- a/CGI.pl
+++ b/CGI.pl
@@ -689,8 +689,7 @@ sub quietly_check_login() {
                 "profiles.login_name, " .
                 "profiles.login_name = " .
                 SqlQuote($::COOKIE{"Bugzilla_login"}) .
-                " AND profiles.cryptpassword = logincookies.cryptpassword " .
-                "AND logincookies.hostname = " .
+                " AND logincookies.hostname = " .
                 SqlQuote($ENV{"REMOTE_HOST"}) .
                 ", profiles.disabledtext " .
                 " FROM profiles, logincookies WHERE logincookies.cookie = " .
@@ -979,7 +978,7 @@ sub confirm_login {
        if (!defined $ENV{'REMOTE_HOST'}) {
          $ENV{'REMOTE_HOST'} = $ENV{'REMOTE_ADDR'};
        }
-       SendSQL("insert into logincookies (userid,cryptpassword,hostname) values (@{[DBNameToIdAndCheck($enteredlogin)]}, @{[SqlQuote($realcryptpwd)]}, @{[SqlQuote($ENV{'REMOTE_HOST'})]})");
+       SendSQL("insert into logincookies (userid,hostname) values (@{[DBNameToIdAndCheck($enteredlogin)]}, @{[SqlQuote($ENV{'REMOTE_HOST'})]})");
        SendSQL("select LAST_INSERT_ID()");
        my $logincookie = FetchOneColumn();
 
index 125b18a6cfbe8bce0c5c184bd4e07a29f0c5e321..71e501ffbbe803276b25cd3372bfe81c76be2221 100755 (executable)
@@ -1082,7 +1082,6 @@ $table{groups} =
 $table{logincookies} =
    'cookie mediumint not null auto_increment primary key,
     userid mediumint not null,
-    cryptpassword varchar(34),
     hostname varchar(128),
     lastused timestamp,
 
@@ -2596,6 +2595,29 @@ AddField("bugs", "cclist_accessible", "tinyint not null default 1");
 # using the attachment manager can record changes to attachments.
 AddField("bugs_activity", "attach_id", "mediumint null");
 
+# 2001-01-17 bbaetz@student.usyd.edu.au bug 95732
+# Remove logincookies.cryptpassword, and delete entries which become
+# invalid
+if (GetFieldDef("logincookies", "cryptpassword")) {
+    # We need to delete any cookies which are invalid, before dropping the
+    # column
+
+    print "Removing invalid login cookies...\n";
+
+    # mysql doesn't support DELETE with multi-table queries, so we have
+    # to iterate
+    my $sth = $dbh->prepare("SELECT cookie FROM logincookies, profiles " .
+                            "WHERE logincookies.cryptpassword != " .
+                            "profiles.cryptpassword AND " .
+                            "logincookies.userid = profiles.userid");
+    $sth->execute();
+    while (my ($cookie) = $sth->fetchrow_array()) {
+        $dbh->do("DELETE FROM logincookies WHERE cookie = $cookie");
+    }
+
+    DropField("logincookies", "cryptpassword");
+}
+
 # If you had to change the --TABLE-- definition in any way, then add your
 # differential change code *** A B O V E *** this comment.
 #
index a2a6ee51b7c884d171beace10dc0703094bdcf47..ad00dd9ae0a08616b96629644323331507227998 100755 (executable)
@@ -808,6 +808,11 @@ if ($action eq 'update') {
             SendSQL("UPDATE  profiles
                      SET     cryptpassword = $cryptpassword
                      WHERE   login_name = $loginname");
+            SendSQL("SELECT userid
+                     FROM profiles
+                     WHERE login_name=" . SqlQuote($userold));
+            my $userid = FetchOneColumn();
+            InvalidateLogins($userid);
             print "Updated password.<BR>\n";
         } else {
             print "Did not update password: $passworderror<br>\n";
@@ -827,8 +832,7 @@ if ($action eq 'update') {
                  FROM profiles
                  WHERE login_name=" . SqlQuote($userold));
         my $userid = FetchOneColumn();
-        SendSQL("DELETE FROM logincookies
-                 WHERE userid=" . $userid);
+        InvalidateLogins($userid);
         print "Updated disabled text.<BR>\n";
     }
     if ($editall && $user ne $userold) {
index cc05ae345146fc034ca36a1673dece0e1f4dc493..845e6ed9ab930dfd99039aff4d9ee8a6cd0a2c1a 100644 (file)
@@ -706,6 +706,19 @@ sub InsertNewUser {
     return $password;
 }
 
+# Removes all entries from logincookies for $userid, except for the
+# optional $keep, which refers the logincookies.cookie primary key.
+# (This is useful so that a user changing their password stays logged in)
+sub InvalidateLogins {
+    my ($userid, $keep) = @_;
+
+    my $remove = "DELETE FROM logincookies WHERE userid = $userid";
+    if (defined $keep) {
+        $remove .= " AND cookie != " . SqlQuote($keep);
+    }
+    SendSQL($remove);
+}
+
 sub GenerateRandomPassword {
     my ($size) = @_;
 
index 091a96e8dd73abab58285985068cf8aa4ced3d8a..a0ec4f105fcc3f77eca8db9e30aa1ba3f3e25841 100755 (executable)
@@ -29,6 +29,25 @@ use lib qw(.);
 
 require "CGI.pl";
 
+# We don't want to remove a random logincookie from the db, so
+# call quietly_check_login. If we're logged in after this, then
+# the logincookie must be correct
+
+ConnectToDatabase();
+quietly_check_login();
+
+if ($::userid) {
+    # Even though we know the userid must match, we still check it in the
+    # SQL as a sanity check, since there is no locking here, and if
+    # the user logged out from two machines simulataniously, while someone
+    # else logged in and got the same cookie, we could be logging the
+    # other user out here. Yes, this is very very very unlikely, but why
+    # take chances? - bbaetz
+    SendSQL("DELETE FROM logincookies WHERE cookie = " .
+            SqlQuote($::COOKIE{"Bugzilla_logincookie"}) .
+            "AND userid = $::userid");
+}
+
 my $cookiepath = Param("cookiepath");
 print "Set-Cookie: Bugzilla_login= ; path=$cookiepath; expires=Sun, 30-Jun-80 00:00:00 GMT
 Set-Cookie: Bugzilla_logincookie= ; path=$cookiepath; expires=Sun, 30-Jun-80 00:00:00 GMT
index 81ae29629d926c1dddddbb4fb60924b376bc3976..7e20d7483b7cc0646daa3412ad549098a58fc4fa 100755 (executable)
--- a/token.cgi
+++ b/token.cgi
@@ -227,6 +227,8 @@ sub changePassword {
     SendSQL("DELETE FROM tokens WHERE token = $::quotedtoken");
     SendSQL("UNLOCK TABLES");
 
+    InvalidateLogins($userid);
+
     # Return HTTP response headers.
     print "Content-Type: text/html\n\n";
 
index 531d57c0eedb3a30873ced2b5c971279a25f1f55..eb823326ab6d75a86244759be5dc7107a18b05b3 100755 (executable)
@@ -171,6 +171,8 @@ sub SaveAccount {
         SendSQL("UPDATE  profiles 
                  SET     cryptpassword = $cryptedpassword 
                  WHERE   userid = $userid");
+        # Invalidate all logins except for the current one
+        InvalidateLogins($userid, $::COOKIE{"Bugzilla_logincookie"});
     }
     SendSQL("UPDATE profiles SET " .
             "realname = " . SqlQuote(trim($::FORM{'realname'})) .