summaryrefslogtreecommitdiffstats
path: root/perl-install/diskdrake
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mageia.org>2013-04-23 19:28:05 +0000
committerThierry Vignaud <tv@mageia.org>2013-04-23 19:28:05 +0000
commit9a85819bad00420ca8cb5965021f0dd76ec565ad (patch)
tree5e1b5f5afe81ecb4720b7a00ffb808e509de2a06 /perl-install/diskdrake
parent3980ebfd98fe7be5cce63bdfba0c567a052d996a (diff)
downloaddrakx-9a85819bad00420ca8cb5965021f0dd76ec565ad.tar
drakx-9a85819bad00420ca8cb5965021f0dd76ec565ad.tar.gz
drakx-9a85819bad00420ca8cb5965021f0dd76ec565ad.tar.bz2
drakx-9a85819bad00420ca8cb5965021f0dd76ec565ad.tar.xz
drakx-9a85819bad00420ca8cb5965021f0dd76ec565ad.zip
fix a crash when reloading partition table (mga#9838)
Diffstat (limited to 'perl-install/diskdrake')
-rw-r--r--perl-install/diskdrake/interactive.pm1
1 files changed, 1 insertions, 0 deletions
diff --git a/perl-install/diskdrake/interactive.pm b/perl-install/diskdrake/interactive.pm
index 02ab8bdb1..011d61422 100644
--- a/perl-install/diskdrake/interactive.pm
+++ b/perl-install/diskdrake/interactive.pm
@@ -961,6 +961,7 @@ sub dmcrypt_open {
sub detect_lvms_on_dmcrypt {
my ($all_hds) = @_,
require File::Temp;
+ require fs::dmcrypt;
my (undef, $tmp_file) = File::Temp::mkstemp('/tmp/crypttab.XXXXXXX');
fs::dmcrypt::save_crypttab_($all_hds, $tmp_file);
$all_hds->{lvms} = [ fsedit::lvms($all_hds) ];
='#n277'>277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Bugzilla Bug Tracking System.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):    Myk Melez <myk@mozilla.org>
#                    Frédéric Buclin <LpSolit@gmail.com>

################################################################################
# Module Initialization
################################################################################

# Make it harder for us to do dangerous things in Perl.
use strict;

# Bundle the functions in this file together into the "Bugzilla::Token" package.
package Bugzilla::Token;

use Bugzilla::Constants;
use Bugzilla::Error;
use Bugzilla::Mailer;
use Bugzilla::Util;
use Bugzilla::User;

use Date::Format;
use Date::Parse;
use File::Basename;
use Digest::MD5 qw(md5_hex);

use base qw(Exporter);

@Bugzilla::Token::EXPORT = qw(issue_session_token check_token_data delete_token
                              issue_hash_token check_hash_token);

################################################################################
# Public Functions
################################################################################

# Creates and sends a token to create a new user account.
# It assumes that the login has the correct format and is not already in use.
sub issue_new_user_account_token {
    my $login_name = shift;
    my $dbh = Bugzilla->dbh;
    my $template = Bugzilla->template;
    my $vars = {};

    # Is there already a pending request for this login name? If yes, do not throw
    # an error because the user may have lost his email with the token inside.
    # But to prevent using this way to mailbomb an email address, make sure
    # the last request is at least 10 minutes old before sending a new email.

    my $pending_requests = $dbh->selectrow_array(
        'SELECT COUNT(*)
           FROM tokens
          WHERE tokentype = ?
                AND ' . $dbh->sql_istrcmp('eventdata', '?') . '
                AND issuedate > '
                    . $dbh->sql_date_math('NOW()', '-', 10, 'MINUTE'),
        undef, ('account', $login_name));

    ThrowUserError('too_soon_for_new_token', {'type' => 'account'}) if $pending_requests;

    my ($token, $token_ts) = _create_token(undef, 'account', $login_name);

    $vars->{'email'} = $login_name . Bugzilla->params->{'emailsuffix'};
    $vars->{'expiration_ts'} = ctime($token_ts + MAX_TOKEN_AGE * 86400);
    $vars->{'token'} = $token;

    my $message;
    $template->process('account/email/request-new.txt.tmpl', $vars, \$message)
      || ThrowTemplateError($template->error());

    # In 99% of cases, the user getting the confirmation email is the same one
    # who made the request, and so it is reasonable to send the email in the same
    # language used to view the "Create a New Account" page (we cannot use his
    # user prefs as the user has no account yet!).
    MessageToMTA($message);
}

sub IssueEmailChangeToken {
    my ($user, $old_email, $new_email) = @_;
    my $email_suffix = Bugzilla->params->{'emailsuffix'};

    my ($token, $token_ts) = _create_token($user->id, 'emailold', $old_email . ":" . $new_email);

    my $newtoken = _create_token($user->id, 'emailnew', $old_email . ":" . $new_email);

    # Mail the user the token along with instructions for using it.

    my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'});
    my $vars = {};

    $vars->{'oldemailaddress'} = $old_email . $email_suffix;
    $vars->{'newemailaddress'} = $new_email . $email_suffix;
    $vars->{'expiration_ts'} = ctime($token_ts + MAX_TOKEN_AGE * 86400);
    $vars->{'token'} = $token;
    $vars->{'emailaddress'} = $old_email . $email_suffix;

    my $message;
    $template->process("account/email/change-old.txt.tmpl", $vars, \$message)
      || ThrowTemplateError($template->error());

    MessageToMTA($message);

    $vars->{'token'} = $newtoken;
    $vars->{'emailaddress'} = $new_email . $email_suffix;

    $message = "";
    $template->process("account/email/change-new.txt.tmpl", $vars, \$message)
      || ThrowTemplateError($template->error());

    MessageToMTA($message);
}

# Generates a random token, adds it to the tokens table, and sends it
# to the user with instructions for using it to change their password.
sub IssuePasswordToken {
    my $user = shift;
    my $dbh = Bugzilla->dbh;

    my $too_soon = $dbh->selectrow_array(
        'SELECT 1 FROM tokens
          WHERE userid = ? AND tokentype = ?
                AND issuedate > ' 
                    . $dbh->sql_date_math('NOW()', '-', 10, 'MINUTE'),
        undef, ($user->id, 'password'));

    ThrowUserError('too_soon_for_new_token', {'type' => 'password'}) if $too_soon;

    my ($token, $token_ts) = _create_token($user->id, 'password', remote_ip());

    # Mail the user the token along with instructions for using it.
    my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'});
    my $vars = {};

    $vars->{'token'} = $token;
    $vars->{'emailaddress'} = $user->email;
    $vars->{'expiration_ts'} = ctime($token_ts + MAX_TOKEN_AGE * 86400);
    # The user is not logged in (else he wouldn't request a new password).
    # So we have to pass this information to the template.
    $vars->{'timezone'} = $user->timezone;

    my $message = "";
    $template->process("account/password/forgotten-password.txt.tmpl", 
                                                               $vars, \$message)
      || ThrowTemplateError($template->error());

    MessageToMTA($message);
}

sub issue_session_token {
    # Generates a random token, adds it to the tokens table, and returns
    # the token to the caller.

    my $data = shift;
    return _create_token(Bugzilla->user->id, 'session', $data);
}

sub issue_hash_token {
    my ($data, $time) = @_;
    $data ||= [];
    $time ||= time();

    # The concatenated string is of the form
    # token creation time + site-wide secret + user ID + data
    my @args = ($time, Bugzilla->localconfig->{'site_wide_secret'}, Bugzilla->user->id, @$data);

    my $token = join('*', @args);
    # Wide characters cause md5_hex() to die.
    if (Bugzilla->params->{'utf8'}) {
        utf8::encode($token) if utf8::is_utf8($token);
    }
    $token = md5_hex($token);

    # Prepend the token creation time, unencrypted, so that the token
    # lifetime can be validated.
    return $time . '-' . $token;
}

sub check_hash_token {
    my ($token, $data) = @_;
    $data ||= [];
    my ($time, $expected_token);

    if ($token) {
        ($time, undef) = split(/-/, $token);
        # Regenerate the token based on the information we have.
        $expected_token = issue_hash_token($data, $time);
    }

    if (!$token
        || $expected_token ne $token
        || time() - $time > MAX_TOKEN_AGE * 86400)
    {
        my $template = Bugzilla->template;
        my $vars = {};
        $vars->{'script_name'} = basename($0);
        $vars->{'token'} = issue_hash_token($data);
        $vars->{'reason'} = (!$token) ?                   'missing_token' :
                            ($expected_token ne $token) ? 'invalid_token' :
                                                          'expired_token';
        print Bugzilla->cgi->header();
        $template->process('global/confirm-action.html.tmpl', $vars)
          || ThrowTemplateError($template->error());
        exit;
    }

    # If we come here, then the token is valid and not too old.
    return 1;
}

sub CleanTokenTable {
    my $dbh = Bugzilla->dbh;
    $dbh->do('DELETE FROM tokens
              WHERE ' . $dbh->sql_to_days('NOW()') . ' - ' .
                        $dbh->sql_to_days('issuedate') . ' >= ?',
              undef, MAX_TOKEN_AGE);
}

sub GenerateUniqueToken {
    # Generates a unique random token.  Uses generate_random_password 
    # for the tokens themselves and checks uniqueness by searching for
    # the token in the "tokens" table.  Gives up if it can't come up
    # with a token after about one hundred tries.
    my ($table, $column) = @_;

    my $token;
    my $duplicate = 1;
    my $tries = 0;
    $table ||= "tokens";
    $column ||= "token";

    my $dbh = Bugzilla->dbh;
    my $sth = $dbh->prepare("SELECT userid FROM $table WHERE $column = ?");

    while ($duplicate) {
        ++$tries;
        if ($tries > 100) {
            ThrowCodeError("token_generation_error");
        }
        $token = generate_random_password();
        $sth->execute($token);
        $duplicate = $sth->fetchrow_array;
    }
    return $token;
}

# Cancels a previously issued token and notifies the user.
# This should only happen when the user accidentally makes a token request
# or when a malicious hacker makes a token request on behalf of a user.
sub Cancel {
    my ($token, $cancelaction, $vars) = @_;
    my $dbh = Bugzilla->dbh;
    $vars ||= {};

    # Get information about the token being canceled.
    trick_taint($token);
    my ($issuedate, $tokentype, $eventdata, $userid) =
        $dbh->selectrow_array('SELECT ' . $dbh->sql_date_format('issuedate') . ',
                                      tokentype, eventdata, userid
                                 FROM tokens
                                WHERE token = ?',
                                undef, $token);

    # If we are canceling the creation of a new user account, then there
    # is no entry in the 'profiles' table.
    my $user = new Bugzilla::User($userid);

    $vars->{'emailaddress'} = $userid ? $user->email : $eventdata;
    $vars->{'remoteaddress'} = remote_ip();
    $vars->{'token'} = $token;
    $vars->{'tokentype'} = $tokentype;
    $vars->{'issuedate'} = $issuedate;
    # The user is probably not logged in.
    # So we have to pass this information to the template.
    $vars->{'timezone'} = $user->timezone;
    $vars->{'eventdata'} = $eventdata;
    $vars->{'cancelaction'} = $cancelaction;

    # Notify the user via email about the cancellation.
    my $template = Bugzilla->template_inner($user->settings->{'lang'}->{'value'});

    my $message;
    $template->process("account/cancel-token.txt.tmpl", $vars, \$message)
      || ThrowTemplateError($template->error());

    MessageToMTA($message);

    # Delete the token from the database.
    delete_token($token);
}

sub DeletePasswordTokens {
    my ($userid, $reason) = @_;
    my $dbh = Bugzilla->dbh;

    detaint_natural($userid);
    my $tokens = $dbh->selectcol_arrayref('SELECT token FROM tokens