Commit d17d6f9f authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 303697: Eliminate deprecated Bugzilla::DB routines from token.cgi - Patch by…

Bug 303697: Eliminate deprecated Bugzilla::DB routines from token.cgi - Patch by Teemu Mannermaa <wicked@etlicon.fi> r=LpSolit a=justdave
parent c0744a05
...@@ -65,20 +65,20 @@ $::action = $cgi->param('a'); ...@@ -65,20 +65,20 @@ $::action = $cgi->param('a');
if ($cgi->param('t')) { if ($cgi->param('t')) {
# Assign the token and its SQL quoted equivalent to global variables. # Assign the token and its SQL quoted equivalent to global variables.
$::token = $cgi->param('t'); $::token = $cgi->param('t');
$::quotedtoken = SqlQuote($::token);
# Make sure the token contains only valid characters in the right amount. # Make sure the token contains only valid characters in the right amount.
my $validationerror = ValidatePassword($::token); my $validationerror = ValidatePassword($::token);
if ($validationerror) { if ($validationerror) {
ThrowUserError("token_invalid"); ThrowUserError("token_invalid");
} }
trick_taint($::token); # Only used in placeholders
Bugzilla::Token::CleanTokenTable(); Bugzilla::Token::CleanTokenTable();
# Make sure the token exists in the database. # Make sure the token exists in the database.
SendSQL( "SELECT tokentype FROM tokens WHERE token = $::quotedtoken" ); my ($tokentype) = $dbh->selectrow_array('SELECT tokentype FROM tokens
(my $tokentype = FetchSQLData()) || ThrowUserError("token_inexistent"); WHERE token = ?', undef, $::token);
$tokentype || ThrowUserError("token_inexistent");
# Make sure the token is the correct type for the action being taken. # Make sure the token is the correct type for the action being taken.
if ( grep($::action eq $_ , qw(cfmpw cxlpw chgpw)) && $tokentype ne 'password' ) { if ( grep($::action eq $_ , qw(cfmpw cxlpw chgpw)) && $tokentype ne 'password' ) {
...@@ -115,11 +115,12 @@ if ( $::action eq 'reqpw' ) { ...@@ -115,11 +115,12 @@ if ( $::action eq 'reqpw' ) {
|| ThrowUserError('illegal_email_address', || ThrowUserError('illegal_email_address',
{addr => $cgi->param('loginname')}); {addr => $cgi->param('loginname')});
my $quotedloginname = SqlQuote($cgi->param('loginname')); my $loginname = $cgi->param('loginname');
SendSQL("SELECT userid FROM profiles WHERE " . trick_taint($loginname); # Used only in a placeholder
$dbh->sql_istrcmp('login_name', $quotedloginname)); my ($user_id) = $dbh->selectrow_array('SELECT userid FROM profiles WHERE ' .
FetchSQLData() $dbh->sql_istrcmp('login_name', '?'),
|| ThrowUserError("account_inexistent"); undef, $loginname);
$user_id || ThrowUserError("account_inexistent");
} }
# If the user is changing their password, make sure they submitted a new # If the user is changing their password, make sure they submitted a new
...@@ -197,21 +198,22 @@ sub cancelChangePassword { ...@@ -197,21 +198,22 @@ sub cancelChangePassword {
sub changePassword { sub changePassword {
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
# Quote the password and token for inclusion into SQL statements. # Create a crypted version of the new password
my $cryptedpassword = bz_crypt($cgi->param('password')); my $cryptedpassword = bz_crypt($cgi->param('password'));
my $quotedpassword = SqlQuote($cryptedpassword); trick_taint($cryptedpassword); # Used only in a placeholder
# Get the user's ID from the tokens table. # Get the user's ID from the tokens table.
SendSQL("SELECT userid FROM tokens WHERE token = $::quotedtoken"); my ($userid) = $dbh->selectrow_array('SELECT userid FROM tokens
my $userid = FetchSQLData(); WHERE token = ?', undef, $::token);
# Update the user's password in the profiles table and delete the token # Update the user's password in the profiles table and delete the token
# from the tokens table. # from the tokens table.
$dbh->bz_lock_tables('profiles WRITE', 'tokens WRITE'); $dbh->bz_lock_tables('profiles WRITE', 'tokens WRITE');
SendSQL("UPDATE profiles $dbh->do(q{UPDATE profiles
SET cryptpassword = $quotedpassword SET cryptpassword = ?
WHERE userid = $userid"); WHERE userid = ?},
SendSQL("DELETE FROM tokens WHERE token = $::quotedtoken"); undef, ($cryptedpassword, $userid) );
$dbh->do('DELETE FROM tokens WHERE token = ?', undef, $::token);
$dbh->bz_unlock_tables(); $dbh->bz_unlock_tables();
Bugzilla->logout_user_by_id($userid); Bugzilla->logout_user_by_id($userid);
...@@ -237,11 +239,10 @@ sub changeEmail { ...@@ -237,11 +239,10 @@ sub changeEmail {
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
# Get the user's ID from the tokens table. # Get the user's ID from the tokens table.
SendSQL("SELECT userid, eventdata FROM tokens my ($userid, $eventdata) = $dbh->selectrow_array(
WHERE token = $::quotedtoken"); q{SELECT userid, eventdata FROM tokens
my ($userid, $eventdata) = FetchSQLData(); WHERE token = ?}, undef, $::token);
my ($old_email, $new_email) = split(/:/,$eventdata); my ($old_email, $new_email) = split(/:/,$eventdata);
my $quotednewemail = SqlQuote($new_email);
# Check the user entered the correct old email address # Check the user entered the correct old email address
if(lc($cgi->param('email')) ne lc($old_email)) { if(lc($cgi->param('email')) ne lc($old_email)) {
...@@ -258,12 +259,13 @@ sub changeEmail { ...@@ -258,12 +259,13 @@ sub changeEmail {
# Update the user's login name in the profiles table and delete the token # Update the user's login name in the profiles table and delete the token
# from the tokens table. # from the tokens table.
$dbh->bz_lock_tables('profiles WRITE', 'tokens WRITE'); $dbh->bz_lock_tables('profiles WRITE', 'tokens WRITE');
SendSQL("UPDATE profiles $dbh->do(q{UPDATE profiles
SET login_name = $quotednewemail SET login_name = ?
WHERE userid = $userid"); WHERE userid = ?},
SendSQL("DELETE FROM tokens WHERE token = $::quotedtoken"); undef, ($new_email, $userid));
SendSQL("DELETE FROM tokens WHERE userid = $userid $dbh->do('DELETE FROM tokens WHERE token = ?', undef, $::token);
AND tokentype = 'emailnew'"); $dbh->do(q{DELETE FROM tokens WHERE userid = ?
AND tokentype = 'emailnew'}, undef, $userid);
$dbh->bz_unlock_tables(); $dbh->bz_unlock_tables();
# The email address has been changed, so we need to rederive the groups # The email address has been changed, so we need to rederive the groups
...@@ -285,25 +287,25 @@ sub cancelChangeEmail { ...@@ -285,25 +287,25 @@ sub cancelChangeEmail {
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
# Get the user's ID from the tokens table. # Get the user's ID from the tokens table.
SendSQL("SELECT userid, tokentype, eventdata FROM tokens my ($userid, $tokentype, $eventdata) = $dbh->selectrow_array(
WHERE token = $::quotedtoken"); q{SELECT userid, tokentype, eventdata FROM tokens
my ($userid, $tokentype, $eventdata) = FetchSQLData(); WHERE token = ?}, undef, $::token);
my ($old_email, $new_email) = split(/:/,$eventdata); my ($old_email, $new_email) = split(/:/,$eventdata);
if($tokentype eq "emailold") { if($tokentype eq "emailold") {
$vars->{'message'} = "emailold_change_cancelled"; $vars->{'message'} = "emailold_change_cancelled";
SendSQL("SELECT login_name FROM profiles WHERE userid = $userid"); my $actualemail = $dbh->selectrow_array(
my $actualemail = FetchSQLData(); q{SELECT login_name FROM profiles
WHERE userid = ?}, undef, $userid);
# check to see if it has been altered # check to see if it has been altered
if($actualemail ne $old_email) { if($actualemail ne $old_email) {
my $quotedoldemail = SqlQuote($old_email);
$dbh->bz_lock_tables('profiles WRITE'); $dbh->bz_lock_tables('profiles WRITE');
SendSQL("UPDATE profiles $dbh->do(q{UPDATE profiles
SET login_name = $quotedoldemail SET login_name = ?
WHERE userid = $userid"); WHERE userid = ?},
undef, ($old_email, $userid));
$dbh->bz_unlock_tables(); $dbh->bz_unlock_tables();
# email has changed, so rederive groups # email has changed, so rederive groups
...@@ -327,9 +329,9 @@ sub cancelChangeEmail { ...@@ -327,9 +329,9 @@ sub cancelChangeEmail {
Bugzilla::Token::Cancel($::token, $vars->{'message'}); Bugzilla::Token::Cancel($::token, $vars->{'message'});
$dbh->bz_lock_tables('tokens WRITE'); $dbh->bz_lock_tables('tokens WRITE');
SendSQL("DELETE FROM tokens $dbh->do(q{DELETE FROM tokens WHERE userid = ?
WHERE userid = $userid AND tokentype = 'emailold' OR tokentype = 'emailnew'},
AND tokentype = 'emailold' OR tokentype = 'emailnew'"); undef, $userid);
$dbh->bz_unlock_tables(); $dbh->bz_unlock_tables();
# Return HTTP response headers. # Return HTTP response headers.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment