4 use constant ERR_PASSWORD    =>   1;
 
   5 use constant ERR_BACKEND     => 100;
 
   7 use constant SESSION_OK      =>   0;
 
   8 use constant SESSION_NONE    =>   1;
 
   9 use constant SESSION_EXPIRED =>   2;
 
  11 use Digest::MD5 qw(md5_hex);
 
  13 use Time::HiRes qw(gettimeofday);
 
  22   $main::lxdebug->enter_sub();
 
  29   $self->{SESSION} = { };
 
  31   $self->_read_auth_config();
 
  33   $main::lxdebug->leave_sub();
 
  41   $self->{dbh}->disconnect() if ($self->{dbh});
 
  44 sub _read_auth_config {
 
  45   $main::lxdebug->enter_sub();
 
  49   my $form   = $main::form;
 
  50   my $locale = $main::locale;
 
  53   my $in = IO::File->new('config/authentication.pl', 'r');
 
  56     $form->error($locale->text('The config file "config/authentication.pl" was not found.'));
 
  67     $form->error($locale->text('The config file "config/authentication.pl" contained invalid Perl code:') . "\n" . $@);
 
  70   if ($self->{module} eq 'DB') {
 
  71     $self->{authenticator} = SL::Auth::DB->new($self);
 
  73   } elsif ($self->{module} eq 'LDAP') {
 
  74     $self->{authenticator} = SL::Auth::LDAP->new($self);
 
  77   if (!$self->{authenticator}) {
 
  78     $form->error($locale->text('No or an unknown authenticantion module specified in "config/authentication.pl".'));
 
  81   my $cfg = $self->{DB_config};
 
  84     $form->error($locale->text('config/authentication.pl: Key "DB_config" is missing.'));
 
  87   if (!$cfg->{host} || !$cfg->{db} || !$cfg->{user}) {
 
  88     $form->error($locale->text('config/authentication.pl: Missing parameters in "DB_config". Required parameters are "host", "db" and "user".'));
 
  91   $self->{authenticator}->verify_config();
 
  93   $self->{session_timeout} *= 1;
 
  94   $self->{session_timeout}  = 8 * 60 if (!$self->{session_timeout});
 
  96   $main::lxdebug->leave_sub();
 
  99 sub authenticate_root {
 
 100   $main::lxdebug->enter_sub();
 
 103   my $password       = shift;
 
 104   my $is_crypted     = shift;
 
 106   $password          = crypt $password, 'ro' if (!$password || !$is_crypted);
 
 107   my $admin_password = crypt "$self->{admin_password}", 'ro';
 
 109   $main::lxdebug->leave_sub();
 
 111   return $password eq $admin_password ? OK : ERR_PASSWORD;
 
 115   $main::lxdebug->enter_sub();
 
 119   $main::lxdebug->leave_sub();
 
 121   return $self->{authenticator}->authenticate(@_);
 
 125   $main::lxdebug->enter_sub();
 
 128   my $may_fail = shift;
 
 131     $main::lxdebug->leave_sub();
 
 135   my $cfg = $self->{DB_config};
 
 136   my $dsn = 'dbi:Pg:dbname=' . $cfg->{db} . ';host=' . $cfg->{host};
 
 139     $dsn .= ';port=' . $cfg->{port};
 
 142   $main::lxdebug->message(LXDebug::DEBUG1, "Auth::dbconnect DSN: $dsn");
 
 144   $self->{dbh} = DBI->connect($dsn, $cfg->{user}, $cfg->{password}, { 'AutoCommit' => 0 });
 
 146   if (!$may_fail && !$self->{dbh}) {
 
 147     $main::form->error($main::locale->text('The connection to the authentication database failed:') . "\n" . $DBI::errstr);
 
 150   $main::lxdebug->leave_sub();
 
 156   $main::lxdebug->enter_sub();
 
 161     $self->{dbh}->disconnect();
 
 165   $main::lxdebug->leave_sub();
 
 169   $main::lxdebug->enter_sub();
 
 173   my $dbh     = $self->dbconnect();
 
 174   my $query   = qq|SELECT COUNT(*) FROM pg_tables WHERE (schemaname = 'auth') AND (tablename = 'user')|;
 
 176   my ($count) = $dbh->selectrow_array($query);
 
 178   $main::lxdebug->leave_sub();
 
 184   $main::lxdebug->enter_sub();
 
 188   my $dbh  = $self->dbconnect(1);
 
 190   $main::lxdebug->leave_sub();
 
 195 sub create_database {
 
 196   $main::lxdebug->enter_sub();
 
 201   my $cfg    = $self->{DB_config};
 
 203   if (!$params{superuser}) {
 
 204     $params{superuser}          = $cfg->{user};
 
 205     $params{superuser_password} = $cfg->{password};
 
 208   $params{template} ||= 'template0';
 
 209   $params{template}   =~ s|[^a-zA-Z0-9_\-]||g;
 
 211   my $dsn = 'dbi:Pg:dbname=template1;host=' . $cfg->{host};
 
 214     $dsn .= ';port=' . $cfg->{port};
 
 217   $main::lxdebug->message(LXDebug::DEBUG1, "Auth::create_database DSN: $dsn");
 
 219   my $dbh = DBI->connect($dsn, $params{superuser}, $params{superuser_password});
 
 222     $main::form->error($main::locale->text('The connection to the template database failed:') . "\n" . $DBI::errstr);
 
 225   my $charset    = $main::dbcharset;
 
 226   $charset     ||= Common::DEFAULT_CHARSET;
 
 227   my $encoding   = $Common::charset_to_db_encoding{$charset};
 
 228   $encoding    ||= 'UNICODE';
 
 230   my $query = qq|CREATE DATABASE "$cfg->{db}" OWNER "$cfg->{user}" TEMPLATE "$params{template}" ENCODING '$encoding'|;
 
 232   $main::lxdebug->message(LXDebug::DEBUG1, "Auth::create_database query: $query");
 
 237     my $error = $dbh->errstr();
 
 239     $query                 = qq|SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = 'template0'|;
 
 240     my ($cluster_encoding) = $dbh->selectrow_array($query);
 
 242     if ($cluster_encoding && ($cluster_encoding =~ m/^(?:UTF-?8|UNICODE)$/i) && ($encoding !~ m/^(?:UTF-?8|UNICODE)$/i)) {
 
 243       $error = $main::locale->text('Your PostgreSQL installationen uses UTF-8 as its encoding. Therefore you have to configure Lx-Office to use UTF-8 as well.');
 
 248     $main::form->error($main::locale->text('The creation of the authentication database failed:') . "\n" . $error);
 
 253   $main::lxdebug->leave_sub();
 
 257   $main::lxdebug->enter_sub();
 
 260   my $dbh  = $self->dbconnect();
 
 262   my $charset    = $main::dbcharset;
 
 263   $charset     ||= Common::DEFAULT_CHARSET;
 
 266   User->process_query($main::form, $dbh, 'sql/auth_db.sql', undef, $charset);
 
 268   $main::lxdebug->leave_sub();
 
 272   $main::lxdebug->enter_sub();
 
 278   my $form   = $main::form;
 
 280   my $dbh    = $self->dbconnect();
 
 282   my ($sth, $query, $user_id);
 
 284   $query     = qq|SELECT id FROM auth."user" WHERE login = ?|;
 
 285   ($user_id) = selectrow_query($form, $dbh, $query, $login);
 
 288     $query     = qq|SELECT nextval('auth.user_id_seq')|;
 
 289     ($user_id) = selectrow_query($form, $dbh, $query);
 
 291     $query     = qq|INSERT INTO auth."user" (id, login) VALUES (?, ?)|;
 
 292     do_query($form, $dbh, $query, $user_id, $login);
 
 295   $query = qq|DELETE FROM auth.user_config WHERE (user_id = ?)|;
 
 296   do_query($form, $dbh, $query, $user_id);
 
 298   $query = qq|INSERT INTO auth.user_config (user_id, cfg_key, cfg_value) VALUES (?, ?, ?)|;
 
 299   $sth   = prepare_query($form, $dbh, $query);
 
 301   while (my ($cfg_key, $cfg_value) = each %params) {
 
 302     next if ($cfg_key eq 'password');
 
 304     do_statement($form, $sth, $query, $user_id, $cfg_key, $cfg_value);
 
 309   $main::lxdebug->leave_sub();
 
 312 sub can_change_password {
 
 315   return $self->{authenticator}->can_change_password();
 
 318 sub change_password {
 
 319   $main::lxdebug->enter_sub();
 
 322   my $result = $self->{authenticator}->change_password(@_);
 
 324   $main::lxdebug->leave_sub();
 
 330   $main::lxdebug->enter_sub();
 
 334   my $dbh   = $self->dbconnect();
 
 335   my $query = qq|SELECT u.id, u.login, cfg.cfg_key, cfg.cfg_value
 
 336                  FROM auth.user_config cfg
 
 337                  LEFT JOIN auth."user" u ON (cfg.user_id = u.id)|;
 
 338   my $sth   = prepare_execute_query($main::form, $dbh, $query);
 
 342   while (my $ref = $sth->fetchrow_hashref()) {
 
 343     $users{$ref->{login}}                    ||= { 'login' => $ref->{login}, 'id' => $ref->{id} };
 
 344     $users{$ref->{login}}->{$ref->{cfg_key}}   = $ref->{cfg_value} if (($ref->{cfg_key} ne 'login') && ($ref->{cfg_key} ne 'id'));
 
 349   $main::lxdebug->leave_sub();
 
 355   $main::lxdebug->enter_sub();
 
 360   my $dbh   = $self->dbconnect();
 
 361   my $query = qq|SELECT cfg.cfg_key, cfg.cfg_value
 
 362                  FROM auth.user_config cfg
 
 363                  LEFT JOIN auth."user" u ON (cfg.user_id = u.id)
 
 364                  WHERE (u.login = ?)|;
 
 365   my $sth   = prepare_execute_query($main::form, $dbh, $query, $login);
 
 369   while (my $ref = $sth->fetchrow_hashref()) {
 
 370     $user_data{$ref->{cfg_key}} = $ref->{cfg_value};
 
 371     $user_data{login}           = $login;
 
 376   $main::lxdebug->leave_sub();
 
 382   $main::lxdebug->enter_sub();
 
 387   my $dbh   = $self->dbconnect();
 
 388   my ($id)  = selectrow_query($main::form, $dbh, qq|SELECT id FROM auth."user" WHERE login = ?|, $login);
 
 390   $main::lxdebug->leave_sub();
 
 396   $main::lxdebug->enter_sub();
 
 401   my $form  = $main::form;
 
 403   my $dbh   = $self->dbconnect();
 
 404   my $query = qq|SELECT id FROM auth."user" WHERE login = ?|;
 
 406   my ($id)  = selectrow_query($form, $dbh, $query, $login);
 
 408   return $main::lxdebug->leave_sub() if (!$id);
 
 410   do_query($form, $dbh, qq|DELETE FROM auth.user_group WHERE user_id = ?|, $id);
 
 411   do_query($form, $dbh, qq|DELETE FROM auth.user_config WHERE user_id = ?|, $id);
 
 415   $main::lxdebug->leave_sub();
 
 418 # --------------------------------------
 
 422 sub restore_session {
 
 423   $main::lxdebug->enter_sub();
 
 427   my $cgi            =  $main::cgi;
 
 428   $cgi             ||=  CGI->new('');
 
 430   $session_id        =  $cgi->cookie($self->get_session_cookie_name());
 
 431   $session_id        =~ s|[^0-9a-f]||g;
 
 433   $self->{SESSION}   = { };
 
 436     $main::lxdebug->leave_sub();
 
 440   my ($dbh, $query, $sth, $cookie, $ref, $form);
 
 444   $dbh    = $self->dbconnect();
 
 445   $query  = qq|SELECT *, (mtime < (now() - '$self->{session_timeout}m'::interval)) AS is_expired FROM auth.session WHERE id = ?|;
 
 447   $cookie = selectfirst_hashref_query($form, $dbh, $query, $session_id);
 
 449   if (!$cookie || $cookie->{is_expired} || ($cookie->{ip_address} ne $ENV{REMOTE_ADDR})) {
 
 450     $self->destroy_session();
 
 451     $main::lxdebug->leave_sub();
 
 452     return SESSION_EXPIRED;
 
 455   $query = qq|SELECT sess_key, sess_value FROM auth.session_content WHERE session_id = ?|;
 
 456   $sth   = prepare_execute_query($form, $dbh, $query, $session_id);
 
 458   while (my $ref = $sth->fetchrow_hashref()) {
 
 459     $self->{SESSION}->{$ref->{sess_key}} = $ref->{sess_value};
 
 460     $form->{$ref->{sess_key}}            = $ref->{sess_value} if (!defined $form->{$ref->{sess_key}});
 
 465   $main::lxdebug->leave_sub();
 
 470 sub destroy_session {
 
 471   $main::lxdebug->enter_sub();
 
 476     my $dbh = $self->dbconnect();
 
 478     do_query($main::form, $dbh, qq|DELETE FROM auth.session_content WHERE session_id = ?|, $session_id);
 
 479     do_query($main::form, $dbh, qq|DELETE FROM auth.session WHERE id = ?|, $session_id);
 
 484     $self->{SESSION} = { };
 
 487   $main::lxdebug->leave_sub();
 
 490 sub expire_sessions {
 
 491   $main::lxdebug->enter_sub();
 
 495   my $dbh   = $self->dbconnect();
 
 497     qq|DELETE FROM auth.session_content
 
 501           WHERE (mtime < (now() - '$self->{session_timeout}m'::interval)))|;
 
 503   do_query($main::form, $dbh, $query);
 
 506     qq|DELETE FROM auth.session
 
 507        WHERE (mtime < (now() - '$self->{session_timeout}m'::interval))|;
 
 509   do_query($main::form, $dbh, $query);
 
 513   $main::lxdebug->leave_sub();
 
 516 sub _create_session_id {
 
 517   $main::lxdebug->enter_sub();
 
 519   my @secs = gettimeofday();
 
 523   map { push @data, int(rand() * 255); } (1..32);
 
 525   my $id = md5_hex(pack 'C*', @data);
 
 527   $main::lxdebug->leave_sub();
 
 532 sub create_or_refresh_session {
 
 533   $main::lxdebug->enter_sub();
 
 537   $session_id ||= $self->_create_session_id();
 
 539   my ($form, $dbh, $query, $sth, $id);
 
 542   $dbh   = $self->dbconnect();
 
 544   $query = qq|SELECT id FROM auth.session WHERE id = ?|;
 
 546   ($id)  = selectrow_query($form, $dbh, $query, $session_id);
 
 549     do_query($form, $dbh, qq|UPDATE auth.session SET mtime = now() WHERE id = ?|, $session_id);
 
 550     do_query($form, $dbh, qq|DELETE FROM auth.session_content WHERE session_id = ?|, $session_id);
 
 553     do_query($form, $dbh, qq|INSERT INTO auth.session (id, ip_address, mtime) VALUES (?, ?, now())|, $session_id, $ENV{REMOTE_ADDR});
 
 557   $query = qq|INSERT INTO auth.session_content (session_id, sess_key, sess_value) VALUES (?, ?, ?)|;
 
 558   $sth   = prepare_query($form, $dbh, $query);
 
 560   foreach my $key (sort keys %{ $self->{SESSION} }) {
 
 561     do_statement($form, $sth, $query, $session_id, $key, $self->{SESSION}->{$key});
 
 567   $main::lxdebug->leave_sub();
 
 570 sub set_session_value {
 
 571   $main::lxdebug->enter_sub();
 
 575   $self->{SESSION} ||= { };
 
 577   while (2 <= scalar @_) {
 
 581     $self->{SESSION}->{$key} = $value;
 
 584   $main::lxdebug->leave_sub();
 
 587 sub set_cookie_environment_variable {
 
 589   $ENV{HTTP_COOKIE} = $self->get_session_cookie_name() . "=${session_id}";
 
 592 sub get_session_cookie_name {
 
 595   return $self->{cookie_name} || 'lx_office_erp_session_id';
 
 602 sub session_tables_present {
 
 603   $main::lxdebug->enter_sub();
 
 606   my $dbh  = $self->dbconnect(1);
 
 609     $main::lxdebug->leave_sub();
 
 616        WHERE (schemaname = 'auth')
 
 617          AND (tablename IN ('session', 'session_content'))|;
 
 619   my ($count) = selectrow_query($main::form, $dbh, $query);
 
 621   $main::lxdebug->leave_sub();
 
 626 # --------------------------------------
 
 628 sub all_rights_full {
 
 629   my $locale = $main::locale;
 
 632     ["--master_data",                  $locale->text("Master Data")],
 
 633     ["customer_vendor_edit",           $locale->text("Create and edit customers and vendors")],
 
 634     ["part_service_assembly_edit",     $locale->text("Create and edit parts, services, assemblies")],
 
 635     ["project_edit",                   $locale->text("Create and edit projects")],
 
 636     ["license_edit",                   $locale->text("Manage license keys")],
 
 637     ["--ar",                           $locale->text("AR")],
 
 638     ["sales_quotation_edit",           $locale->text("Create and edit sales quotations")],
 
 639     ["sales_order_edit",               $locale->text("Create and edit sales orders")],
 
 640     ["sales_delivery_order_edit",      $locale->text("Create and edit sales delivery orders")],
 
 641     ["invoice_edit",                   $locale->text("Create and edit invoices and credit notes")],
 
 642     ["dunning_edit",                   $locale->text("Create and edit dunnings")],
 
 643     ["--ap",                           $locale->text("AP")],
 
 644     ["request_quotation_edit",         $locale->text("Create and edit RFQs")],
 
 645     ["purchase_order_edit",            $locale->text("Create and edit purchase orders")],
 
 646     ["purchase_delivery_order_edit",   $locale->text("Create and edit purchase delivery orders")],
 
 647     ["vendor_invoice_edit",            $locale->text("Create and edit vendor invoices")],
 
 648     ["--warehouse_management",         $locale->text("Warehouse management")],
 
 649     ["warehouse_contents",             $locale->text("View warehouse content")],
 
 650     ["warehouse_management",           $locale->text("Warehouse management")],
 
 651     ["--general_ledger_cash",          $locale->text("General ledger and cash")],
 
 652     ["general_ledger",                 $locale->text("Transactions, AR transactions, AP transactions")],
 
 653     ["datev_export",                   $locale->text("DATEV Export")],
 
 654     ["cash",                           $locale->text("Receipt, payment, reconciliation")],
 
 655     ["--reports",                      $locale->text('Reports')],
 
 656     ["report",                         $locale->text('All reports')],
 
 657     ["advance_turnover_tax_return",    $locale->text('Advance turnover tax return')],
 
 658     ["--others",                       $locale->text("Others")],
 
 659     ["email_bcc",                      $locale->text("May set the BCC field when sending emails")],
 
 660     ["config",                         $locale->text("Change Lx-Office installation settings (all menu entries beneath 'System')")],
 
 667   return grep !/^--/, map { $_->[0] } all_rights_full();
 
 671   $main::lxdebug->enter_sub();
 
 675   my $form   = $main::form;
 
 677   my $dbh    = $self->dbconnect();
 
 679   my $query  = 'SELECT * FROM auth."group"';
 
 680   my $sth    = prepare_execute_query($form, $dbh, $query);
 
 684   while ($row = $sth->fetchrow_hashref()) {
 
 685     $groups->{$row->{id}} = $row;
 
 689   $query = 'SELECT * FROM auth.user_group WHERE group_id = ?';
 
 690   $sth   = prepare_query($form, $dbh, $query);
 
 692   foreach $group (values %{$groups}) {
 
 693     $group->{members} = [];
 
 695     do_statement($form, $sth, $query, $group->{id});
 
 697     while ($row = $sth->fetchrow_hashref()) {
 
 698       push @{$group->{members}}, $row->{user_id};
 
 703   $query = 'SELECT * FROM auth.group_rights WHERE group_id = ?';
 
 704   $sth   = prepare_query($form, $dbh, $query);
 
 706   foreach $group (values %{$groups}) {
 
 707     $group->{rights} = {};
 
 709     do_statement($form, $sth, $query, $group->{id});
 
 711     while ($row = $sth->fetchrow_hashref()) {
 
 712       $group->{rights}->{$row->{right}} |= $row->{granted};
 
 715     map { $group->{rights}->{$_} = 0 if (!defined $group->{rights}->{$_}); } all_rights();
 
 719   $main::lxdebug->leave_sub();
 
 725   $main::lxdebug->enter_sub();
 
 730   my $form  = $main::form;
 
 731   my $dbh   = $self->dbconnect();
 
 733   my ($query, $sth, $row, $rights);
 
 736     ($group->{id}) = selectrow_query($form, $dbh, qq|SELECT nextval('auth.group_id_seq')|);
 
 738     $query = qq|INSERT INTO auth."group" (id, name, description) VALUES (?, '', '')|;
 
 739     do_query($form, $dbh, $query, $group->{id});
 
 742   do_query($form, $dbh, qq|UPDATE auth."group" SET name = ?, description = ? WHERE id = ?|, map { $group->{$_} } qw(name description id));
 
 744   do_query($form, $dbh, qq|DELETE FROM auth.user_group WHERE group_id = ?|, $group->{id});
 
 746   $query  = qq|INSERT INTO auth.user_group (user_id, group_id) VALUES (?, ?)|;
 
 747   $sth    = prepare_query($form, $dbh, $query);
 
 749   foreach my $user_id (@{ $group->{members} }) {
 
 750     do_statement($form, $sth, $query, $user_id, $group->{id});
 
 754   do_query($form, $dbh, qq|DELETE FROM auth.group_rights WHERE group_id = ?|, $group->{id});
 
 756   $query = qq|INSERT INTO auth.group_rights (group_id, "right", granted) VALUES (?, ?, ?)|;
 
 757   $sth   = prepare_query($form, $dbh, $query);
 
 759   foreach my $right (keys %{ $group->{rights} }) {
 
 760     do_statement($form, $sth, $query, $group->{id}, $right, $group->{rights}->{$right} ? 't' : 'f');
 
 766   $main::lxdebug->leave_sub();
 
 770   $main::lxdebug->enter_sub();
 
 775   my $form = $main::from;
 
 777   my $dbh  = $self->dbconnect();
 
 779   do_query($form, $dbh, qq|DELETE FROM auth.user_group WHERE group_id = ?|, $id);
 
 780   do_query($form, $dbh, qq|DELETE FROM auth.group_rights WHERE group_id = ?|, $id);
 
 781   do_query($form, $dbh, qq|DELETE FROM auth."group" WHERE id = ?|, $id);
 
 785   $main::lxdebug->leave_sub();
 
 788 sub evaluate_rights_ary {
 
 789   $main::lxdebug->enter_sub(2);
 
 796   foreach my $el (@{$ary}) {
 
 797     if (ref $el eq "ARRAY") {
 
 798       if ($action eq '|') {
 
 799         $value |= evaluate_rights_ary($el);
 
 801         $value &= evaluate_rights_ary($el);
 
 804     } elsif (($el eq '&') || ($el eq '|')) {
 
 807     } elsif ($action eq '|') {
 
 816   $main::lxdebug->enter_sub(2);
 
 821 sub _parse_rights_string {
 
 822   $main::lxdebug->enter_sub(2);
 
 832   push @stack, $cur_ary;
 
 834   while ($access =~ m/^([a-z_0-9]+|\||\&|\(|\)|\s+)/) {
 
 836     substr($access, 0, length $1) = "";
 
 838     next if ($token =~ /\s/);
 
 841       my $new_cur_ary = [];
 
 842       push @stack, $new_cur_ary;
 
 843       push @{$cur_ary}, $new_cur_ary;
 
 844       $cur_ary = $new_cur_ary;
 
 846     } elsif ($token eq ")") {
 
 850         $main::lxdebug->enter_sub(2);
 
 854       $cur_ary = $stack[-1];
 
 856     } elsif (($token eq "|") || ($token eq "&")) {
 
 857       push @{$cur_ary}, $token;
 
 860       push @{$cur_ary}, $self->{RIGHTS}->{$login}->{$token} * 1;
 
 864   my $result = ($access || (1 < scalar @stack)) ? 0 : evaluate_rights_ary($stack[0]);
 
 866   $main::lxdebug->enter_sub(2);
 
 872   $main::lxdebug->enter_sub(2);
 
 879   $self->{FULL_RIGHTS}           ||= { };
 
 880   $self->{FULL_RIGHTS}->{$login} ||= { };
 
 882   if (!defined $self->{FULL_RIGHTS}->{$login}->{$right}) {
 
 883     $self->{RIGHTS}           ||= { };
 
 884     $self->{RIGHTS}->{$login} ||= $self->load_rights_for_user($login);
 
 886     $self->{FULL_RIGHTS}->{$login}->{$right} = $self->_parse_rights_string($login, $right);
 
 889   my $granted = $self->{FULL_RIGHTS}->{$login}->{$right};
 
 890   $granted    = $default if (!defined $granted);
 
 892   $main::lxdebug->leave_sub(2);
 
 898   $main::lxdebug->enter_sub(2);
 
 902   my $dont_abort = shift;
 
 904   my $form       = $main::form;
 
 906   if ($self->check_right($form->{login}, $right)) {
 
 907     $main::lxdebug->leave_sub(2);
 
 912     delete $form->{title};
 
 913     $form->show_generic_error($main::locale->text("You do not have the permissions to access this function."));
 
 916   $main::lxdebug->leave_sub(2);
 
 921 sub load_rights_for_user {
 
 922   $main::lxdebug->enter_sub();
 
 927   my $form  = $main::form;
 
 928   my $dbh   = $self->dbconnect();
 
 930   my ($query, $sth, $row, $rights);
 
 935     qq|SELECT gr."right", gr.granted
 
 936        FROM auth.group_rights gr
 
 939           FROM auth.user_group ug
 
 940           LEFT JOIN auth."user" u ON (ug.user_id = u.id)
 
 943   $sth = prepare_execute_query($form, $dbh, $query, $login);
 
 945   while ($row = $sth->fetchrow_hashref()) {
 
 946     $rights->{$row->{right}} |= $row->{granted};
 
 950   map({ $rights->{$_} = 0 unless (defined $rights->{$_}); } SL::Auth::all_rights());
 
 952   $main::lxdebug->leave_sub();