Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 7ed4b336

Von Moritz Bunkus vor mehr als 9 Jahren hinzugefügt

  • ID 7ed4b336b89b861479a1fc2670b9456334b0d1be
  • Vorgänger c05d6e3a
  • Nachfolger f9c91009

Auth.pm cosmetics: Entfernen von $::lxdebug->enter_sub/leave_sub

Unterschiede anzeigen:

SL/Auth.pm
32 32

  
33 33

  
34 34
sub new {
35
  $main::lxdebug->enter_sub();
36

  
37 35
  my ($type, %params) = @_;
38 36
  my $self            = bless {}, $type;
39 37

  
40 38
  $self->_read_auth_config(%params);
41 39
  $self->reset;
42 40

  
43
  $main::lxdebug->leave_sub();
44

  
45 41
  return $self;
46 42
}
47 43

  
......
97 93
}
98 94

  
99 95
sub _read_auth_config {
100
  $main::lxdebug->enter_sub();
101

  
102 96
  my ($self, %params) = @_;
103 97

  
104 98
  map { $self->{$_} = $::lx_office_conf{authentication}->{$_} } keys %{ $::lx_office_conf{authentication} };
......
143 137

  
144 138
  $self->{session_timeout} *= 1;
145 139
  $self->{session_timeout}  = 8 * 60 if (!$self->{session_timeout});
146

  
147
  $main::lxdebug->leave_sub();
148 140
}
149 141

  
150 142
sub has_access_to_client {
......
165 157
}
166 158

  
167 159
sub authenticate_root {
168
  $main::lxdebug->enter_sub();
169

  
170 160
  my ($self, $password) = @_;
171 161

  
172 162
  my $session_root_auth = $self->get_session_value(SESSION_KEY_ROOT_AUTH());
173 163
  if (defined $session_root_auth && $session_root_auth == OK) {
174
    $::lxdebug->leave_sub;
175 164
    return OK;
176 165
  }
177 166

  
178 167
  if (!defined $password) {
179
    $::lxdebug->leave_sub;
180 168
    return ERR_PASSWORD;
181 169
  }
182 170

  
......
186 174
  my $result = $password eq $admin_password ? OK : ERR_PASSWORD;
187 175
  $self->set_session_value(SESSION_KEY_ROOT_AUTH() => $result);
188 176

  
189
  $::lxdebug->leave_sub;
190 177
  return $result;
191 178
}
192 179

  
193 180
sub authenticate {
194
  $main::lxdebug->enter_sub();
195

  
196 181
  my ($self, $login, $password) = @_;
197 182

  
198 183
  if (!$self->client || !$self->has_access_to_client($login)) {
199
    $::lxdebug->leave_sub;
200 184
    return ERR_PASSWORD;
201 185
  }
202 186

  
203 187
  my $session_auth = $self->get_session_value(SESSION_KEY_USER_AUTH());
204 188
  if (defined $session_auth && $session_auth == OK) {
205
    $::lxdebug->leave_sub;
206 189
    return OK;
207 190
  }
208 191

  
209 192
  if (!defined $password) {
210
    $::lxdebug->leave_sub;
211 193
    return ERR_PASSWORD;
212 194
  }
213 195

  
214 196
  my $result = $login ? $self->{authenticator}->authenticate($login, $password) : ERR_USER;
215 197
  $self->set_session_value(SESSION_KEY_USER_AUTH() => $result, login => $login, client_id => $self->client->{id});
216

  
217
  $::lxdebug->leave_sub;
218 198
  return $result;
219 199
}
220 200

  
......
237 217
}
238 218

  
239 219
sub dbconnect {
240
  $main::lxdebug->enter_sub(2);
241

  
242 220
  my $self     = shift;
243 221
  my $may_fail = shift;
244 222

  
245 223
  if ($self->{dbh}) {
246
    $main::lxdebug->leave_sub(2);
247 224
    return $self->{dbh};
248 225
  }
249 226

  
......
262 239
    $main::form->error($main::locale->text('The connection to the authentication database failed:') . "\n" . $DBI::errstr);
263 240
  }
264 241

  
265
  $main::lxdebug->leave_sub(2);
266

  
267 242
  return $self->{dbh};
268 243
}
269 244

  
270 245
sub dbdisconnect {
271
  $main::lxdebug->enter_sub();
272

  
273 246
  my $self = shift;
274 247

  
275 248
  if ($self->{dbh}) {
276 249
    $self->{dbh}->disconnect();
277 250
    delete $self->{dbh};
278 251
  }
279

  
280
  $main::lxdebug->leave_sub();
281 252
}
282 253

  
283 254
sub check_tables {
284
  $main::lxdebug->enter_sub();
285

  
286 255
  my ($self, $dbh)    = @_;
287 256

  
288 257
  $dbh   ||= $self->dbconnect();
......
290 259

  
291 260
  my ($count) = $dbh->selectrow_array($query);
292 261

  
293
  $main::lxdebug->leave_sub();
294

  
295 262
  return $count > 0;
296 263
}
297 264

  
298 265
sub check_database {
299
  $main::lxdebug->enter_sub();
300

  
301 266
  my $self = shift;
302 267

  
303 268
  my $dbh  = $self->dbconnect(1);
304 269

  
305
  $main::lxdebug->leave_sub();
306

  
307 270
  return $dbh ? 1 : 0;
308 271
}
309 272

  
310 273
sub create_database {
311
  $main::lxdebug->enter_sub();
312

  
313 274
  my $self   = shift;
314 275
  my %params = @_;
315 276

  
......
359 320
  }
360 321

  
361 322
  $dbh->disconnect();
362

  
363
  $main::lxdebug->leave_sub();
364 323
}
365 324

  
366 325
sub create_tables {
367
  $main::lxdebug->enter_sub();
368

  
369 326
  my $self = shift;
370 327
  my $dbh  = $self->dbconnect();
371 328

  
372 329
  $dbh->rollback();
373 330
  SL::DBUpgrade2->new(form => $::form)->process_query($dbh, 'sql/auth_db.sql');
374

  
375
  $main::lxdebug->leave_sub();
376 331
}
377 332

  
378 333
sub save_user {
379
  $main::lxdebug->enter_sub();
380

  
381 334
  my $self   = shift;
382 335
  my $login  = shift;
383 336
  my %params = @_;
......
414 367
  }
415 368

  
416 369
  $dbh->commit();
417

  
418
  $main::lxdebug->leave_sub();
419 370
}
420 371

  
421 372
sub can_change_password {
......
425 376
}
426 377

  
427 378
sub change_password {
428
  $main::lxdebug->enter_sub();
429

  
430 379
  my ($self, $login, $new_password) = @_;
431 380

  
432 381
  my $result = $self->{authenticator}->change_password($login, $new_password);
433 382

  
434
  $main::lxdebug->leave_sub();
435

  
436 383
  return $result;
437 384
}
438 385

  
439 386
sub read_all_users {
440
  $main::lxdebug->enter_sub();
441

  
442 387
  my $self  = shift;
443 388

  
444 389
  my $dbh   = $self->dbconnect();
......
471 416

  
472 417
  $sth->finish();
473 418

  
474
  $main::lxdebug->leave_sub();
475

  
476 419
  return %users;
477 420
}
478 421

  
479 422
sub read_user {
480
  $main::lxdebug->enter_sub();
481

  
482 423
  my ($self, %params) = @_;
483 424

  
484 425
  my $dbh   = $self->dbconnect();
......
518 459

  
519 460
  $sth->finish();
520 461

  
521
  $main::lxdebug->leave_sub();
522

  
523 462
  return %user_data;
524 463
}
525 464

  
526 465
sub get_user_id {
527
  $main::lxdebug->enter_sub();
528

  
529 466
  my $self  = shift;
530 467
  my $login = shift;
531 468

  
532 469
  my $dbh   = $self->dbconnect();
533 470
  my ($id)  = selectrow_query($main::form, $dbh, qq|SELECT id FROM auth."user" WHERE login = ?|, $login);
534 471

  
535
  $main::lxdebug->leave_sub();
536

  
537 472
  return $id;
538 473
}
539 474

  
540 475
sub delete_user {
541
  $::lxdebug->enter_sub;
542

  
543 476
  my $self  = shift;
544 477
  my $login = shift;
545 478

  
546 479
  my $dbh   = $self->dbconnect;
547 480
  my $id    = $self->get_user_id($login);
548 481

  
549
  $dbh->rollback and return $::lxdebug->leave_sub if (!$id);
482
  if (!$id) {
483
    $dbh->rollback;
484
    return;
485
  }
550 486

  
551 487
  $dbh->begin_work;
552 488

  
......
558 494
  # do_query($::form, $u_dbh, qq|UPDATE employee SET deleted = 't' WHERE login = ?|, $login) if $u_dbh && $user_db_exists;
559 495

  
560 496
  $dbh->commit;
561

  
562
  $::lxdebug->leave_sub;
563 497
}
564 498

  
565 499
# --------------------------------------
......
567 501
my $session_id;
568 502

  
569 503
sub restore_session {
570
  $main::lxdebug->enter_sub();
571

  
572 504
  my $self = shift;
573 505

  
574 506
  $session_id        =  $::request->{cgi}->cookie($self->get_session_cookie_name());
......
577 509
  $self->{SESSION}   = { };
578 510

  
579 511
  if (!$session_id) {
580
    $main::lxdebug->leave_sub();
581 512
    return $self->session_restore_result(SESSION_NONE());
582 513
  }
583 514

  
......
587 518

  
588 519
  # Don't fail if the auth DB doesn't yet.
589 520
  if (!( $dbh = $self->dbconnect(1) )) {
590
    $::lxdebug->leave_sub;
591 521
    return $self->session_restore_result(SESSION_NONE());
592 522
  }
593 523

  
......
597 527

  
598 528
  if (!($sth = $dbh->prepare($query)) || !$sth->execute($session_id)) {
599 529
    $sth->finish if $sth;
600
    $::lxdebug->leave_sub;
601 530
    return $self->session_restore_result(SESSION_NONE());
602 531
  }
603 532

  
......
616 545
  $cookie_is_bad     ||= $cookie->{ip_address} ne $ENV{REMOTE_ADDR}                       if !$api_token_cookie;
617 546
  if ($cookie_is_bad) {
618 547
    $self->destroy_session();
619
    $main::lxdebug->leave_sub();
620 548
    return $self->session_restore_result($cookie ? SESSION_EXPIRED() : SESSION_NONE());
621 549
  }
622 550

  
......
626 554
    $self->_load_without_auto_restore_column($dbh, $session_id);
627 555
  }
628 556

  
629
  $main::lxdebug->leave_sub();
630

  
631 557
  return $self->session_restore_result(SESSION_OK());
632 558
}
633 559

  
......
710 636
}
711 637

  
712 638
sub destroy_session {
713
  $main::lxdebug->enter_sub();
714

  
715 639
  my $self = shift;
716 640

  
717 641
  if ($session_id) {
......
729 653
    $session_id      = undef;
730 654
    $self->{SESSION} = { };
731 655
  }
732

  
733
  $main::lxdebug->leave_sub();
734 656
}
735 657

  
736 658
sub active_session_ids {
......
745 667
}
746 668

  
747 669
sub expire_sessions {
748
  $main::lxdebug->enter_sub();
749

  
750 670
  my $self  = shift;
751 671

  
752
  $main::lxdebug->leave_sub and return if !$self->session_tables_present;
672
  return if !$self->session_tables_present;
753 673

  
754 674
  my $dbh   = $self->dbconnect();
755 675

  
......
774 694

  
775 695
    $dbh->commit();
776 696
  }
777

  
778
  $main::lxdebug->leave_sub();
779 697
}
780 698

  
781 699
sub _create_session_id {
782
  $main::lxdebug->enter_sub();
783

  
784 700
  my @data;
785 701
  map { push @data, int(rand() * 255); } (1..32);
786 702

  
787 703
  my $id = md5_hex(pack 'C*', @data);
788 704

  
789
  $main::lxdebug->leave_sub();
790

  
791 705
  return $id;
792 706
}
793 707

  
......
796 710
}
797 711

  
798 712
sub save_session {
799
  $::lxdebug->enter_sub;
800 713
  my $self         = shift;
801 714
  my $provided_dbh = shift;
802 715

  
803 716
  my $dbh          = $provided_dbh || $self->dbconnect(1);
804 717

  
805
  $::lxdebug->leave_sub && return unless $dbh && $session_id;
718
  return unless $dbh && $session_id;
806 719

  
807 720
  $dbh->begin_work unless $provided_dbh;
808 721

  
......
810 723
  # the admin is just trying to create the auth database.
811 724
  if (!$dbh->do(qq|LOCK auth.session_content|)) {
812 725
    $dbh->rollback unless $provided_dbh;
813
    $::lxdebug->leave_sub;
814 726
    return;
815 727
  }
816 728

  
......
862 774
  }
863 775

  
864 776
  $dbh->commit() unless $provided_dbh;
865
  $::lxdebug->leave_sub;
866 777
}
867 778

  
868 779
sub set_session_value {
869
  $main::lxdebug->enter_sub();
870

  
871 780
  my $self   = shift;
872 781
  my @params = @_;
873 782

  
......
888 797
    }
889 798
  }
890 799

  
891
  $main::lxdebug->leave_sub();
892

  
893 800
  return $self;
894 801
}
895 802

  
896 803
sub delete_session_value {
897
  $main::lxdebug->enter_sub();
898

  
899 804
  my $self = shift;
900 805

  
901 806
  $self->{SESSION} ||= { };
902 807
  delete @{ $self->{SESSION} }{ @_ };
903 808

  
904
  $main::lxdebug->leave_sub();
905

  
906 809
  return $self;
907 810
}
908 811

  
909 812
sub get_session_value {
910
  $main::lxdebug->enter_sub();
911

  
912 813
  my $self = shift;
913 814
  my $data = $self->{SESSION} && $self->{SESSION}->{ $_[0] } ? $self->{SESSION}->{ $_[0] }->get : undef;
914 815

  
915
  $main::lxdebug->leave_sub();
916

  
917 816
  return $data;
918 817
}
919 818

  
......
999 898
}
1000 899

  
1001 900
sub session_tables_present {
1002
  $main::lxdebug->enter_sub();
1003

  
1004 901
  my $self = shift;
1005 902

  
1006 903
  # Only re-check for the presence of auth tables if either the check
1007 904
  # hasn't been done before of if they weren't present.
1008 905
  if ($self->{session_tables_present}) {
1009
    $main::lxdebug->leave_sub();
1010 906
    return $self->{session_tables_present};
1011 907
  }
1012 908

  
1013 909
  my $dbh  = $self->dbconnect(1);
1014 910

  
1015 911
  if (!$dbh) {
1016
    $main::lxdebug->leave_sub();
1017 912
    return 0;
1018 913
  }
1019 914

  
......
1027 922

  
1028 923
  $self->{session_tables_present} = 2 == $count;
1029 924

  
1030
  $main::lxdebug->leave_sub();
1031

  
1032 925
  return $self->{session_tables_present};
1033 926
}
1034 927

  
......
1105 998
}
1106 999

  
1107 1000
sub read_groups {
1108
  $main::lxdebug->enter_sub();
1109

  
1110 1001
  my $self = shift;
1111 1002

  
1112 1003
  my $form   = $main::form;
......
1154 1045
  }
1155 1046
  $sth->finish();
1156 1047

  
1157
  $main::lxdebug->leave_sub();
1158

  
1159 1048
  return $groups;
1160 1049
}
1161 1050

  
1162 1051
sub save_group {
1163
  $main::lxdebug->enter_sub();
1164

  
1165 1052
  my $self  = shift;
1166 1053
  my $group = shift;
1167 1054

  
......
1202 1089
  $sth->finish();
1203 1090

  
1204 1091
  $dbh->commit();
1205

  
1206
  $main::lxdebug->leave_sub();
1207 1092
}
1208 1093

  
1209 1094
sub delete_group {
1210
  $main::lxdebug->enter_sub();
1211

  
1212 1095
  my $self = shift;
1213 1096
  my $id   = shift;
1214 1097

  
......
1222 1105
  do_query($form, $dbh, qq|DELETE FROM auth."group" WHERE id = ?|, $id);
1223 1106

  
1224 1107
  $dbh->commit();
1225

  
1226
  $main::lxdebug->leave_sub();
1227 1108
}
1228 1109

  
1229 1110
sub evaluate_rights_ary {
1230
  $main::lxdebug->enter_sub(2);
1231

  
1232 1111
  my $ary    = shift;
1233 1112

  
1234 1113
  my $value  = 0;
......
1254 1133
    }
1255 1134
  }
1256 1135

  
1257
  $main::lxdebug->leave_sub(2);
1258

  
1259 1136
  return $value;
1260 1137
}
1261 1138

  
1262 1139
sub _parse_rights_string {
1263
  $main::lxdebug->enter_sub(2);
1264

  
1265 1140
  my $self   = shift;
1266 1141

  
1267 1142
  my $login  = shift;
......
1288 1163
      pop @stack;
1289 1164

  
1290 1165
      if (!@stack) {
1291
        $main::lxdebug->leave_sub(2);
1292 1166
        return 0;
1293 1167
      }
1294 1168

  
......
1304 1178

  
1305 1179
  my $result = ($access || (1 < scalar @stack)) ? 0 : evaluate_rights_ary($stack[0]);
1306 1180

  
1307
  $main::lxdebug->leave_sub(2);
1308

  
1309 1181
  return $result;
1310 1182
}
1311 1183

  
1312 1184
sub check_right {
1313
  $main::lxdebug->enter_sub(2);
1314

  
1315 1185
  my $self    = shift;
1316 1186
  my $login   = shift;
1317 1187
  my $right   = shift;
......
1330 1200
  my $granted = $self->{FULL_RIGHTS}->{$login}->{$right};
1331 1201
  $granted    = $default if (!defined $granted);
1332 1202

  
1333
  $main::lxdebug->leave_sub(2);
1334

  
1335 1203
  return $granted;
1336 1204
}
1337 1205

  
1338 1206
sub assert {
1339
  $::lxdebug->enter_sub(2);
1340 1207
  my ($self, $right, $dont_abort) = @_;
1341 1208

  
1342 1209
  if ($self->check_right($::myconfig{login}, $right)) {
1343
    $::lxdebug->leave_sub(2);
1344 1210
    return 1;
1345 1211
  }
1346 1212

  
......
1349 1215
    $::form->show_generic_error($::locale->text("You do not have the permissions to access this function."));
1350 1216
  }
1351 1217

  
1352
  $::lxdebug->leave_sub(2);
1353

  
1354 1218
  return 0;
1355 1219
}
1356 1220

  
1357 1221
sub load_rights_for_user {
1358
  $::lxdebug->enter_sub;
1359

  
1360 1222
  my ($self, $login) = @_;
1361 1223
  my $dbh   = $self->dbconnect;
1362 1224
  my ($query, $sth, $row, $rights);
......
1383 1245
  }
1384 1246
  $sth->finish();
1385 1247

  
1386
  $::lxdebug->leave_sub;
1387

  
1388 1248
  return $rights;
1389 1249
}
1390 1250

  

Auch abrufbar als: Unified diff