Auth.pm

filter: Statementstmt 20.9% 14 / 67 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 42.8% 3 / 7 Podpod 0.0% 0 / 3 totaltotal 14.9% 17 / 114 CC 18 SCAR 39.1
CC
18
Cov
14%
_update
72.0
perm
72.0
check
12.0
CRAP 50.1
« Connection.pm ↑ Summary Group.pm »
1 #!/app/unido-i06/magic/perl
2 # -*- Mode: Perl -*-
3 # Auth.pm --
4 # ITIID : $ITI$ $Header $__Header$
5 # Author : Ulrich Pfeifer
6 # Created On : Mon Sep 30 08:49:41 1996
7 # Last Modified By: Ulrich Pfeifer
8 # Last Modified On: Fri Oct 25 11:44:44 1996
9 # Language : CPerl
10 # Update Count : 31
11 # Status : Unknown, Use with caution!
12 #
13 # (C) Copyright 1996, Universität Dortmund, all rights reserved.
14 #
15 # $Locker: $
16 # $Log: Auth.pm,v $
17 # Revision 1.1 1997/02/10 19:47:12 pfeifer
18 # Switched to CVS
19 #
20 #
21  
22 package NNML::Auth;
23 1 ▶use NNML::Config qw($Config);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 my $NORESTRICTION = -1;
28 1 my $PASSWD = '';
29 1 my $TIME;
30 1 my (%PASSWD, %PERM);
31  
32 0 ▶sub _update {
Subroutine _update: not called CC=8 SCAR=42.8
33 0 my $norestriction = $NORESTRICTION;
34 0 ▶ if (-e $Config->passwd) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $NNML::Auth::Config->passwd) { } 0 0 0
35 0 ▶ if ($PASSWD ne $Config->passwd
Branch: 1 branch
BranchTrueFalseTotal
if ($PASSWD ne $NNML::Auth::Config->passwd or (stat $NNML::Auth::Config->passwd)[9] > $TIME) 0 0 0
Condition0%0/3
$PASSWD ne $NNML::Auth::Config->passwd or (stat $NNML::Auth::Config->passwd)[9] > $TIME
l!l&&r!l&&!r
000
MC/DC0%0/2
$PASSWD ne $NNML::Auth::Config->passwd or (stat $NNML::Auth::Config->passwd)[9] > $TIME
$PASSWD ne $NNML::Auth::Config->passwd (stat $NNML::Auth::Config->passwd)[9] > $TIME
Truth table0%0/3
A or B
A= $PASSWD ne $NNML::Auth::Config->passwdB= (stat $NNML::Auth::Config->passwd)[9] > $TIME
ABresult
1X1
011
000
36 or (stat($Config->passwd))[9] > $TIME) {
37 0 $PASSWD = $Config->passwd;
38 0 $TIME = (stat($Config->passwd))[9];
39
40 0 my $fh = new IO::File '< ' . $Config->passwd;
41 0 ▶ if (defined $fh) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fh) { } 0 0 0
42 0 local ($_);
43 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
44 0 chomp;
45 0 my($user, $passwd, @perm) = split;
46 0 $PASSWD{$user} = $passwd;
47 0 my %perm;
48 0 @perm{@perm} = @perm;
49 0 $PERM{$user} = \%perm;
50 }
51 0 $NORESTRICTION = 0;
52 } else { # could not read passwd
53 0 $NORESTRICTION = 1;
54 }
55 }
56 } else { # tehere is no passwd
57 0 $NORESTRICTION = 1;
58 }
59 0 ▶ if ($NORESTRICTION != $norestriction) {
Branch: 1 branch
BranchTrueFalseTotal
if ($NORESTRICTION != $norestriction) 0 0 0
60 0 ▶ if ($NORESTRICTION) {
Branch: 1 branch
BranchTrueFalseTotal
if ($NORESTRICTION) { } 0 0 0
61 0 print "Authorization disabled\n";
62 } else {
63 0 print "Authorization enabled\n";
64 }
65 }
66 }
67  
68 0 ▶sub perm {
Subroutine perm: not called CC=8 SCAR=42.8
Pod undocumented
69 0 my ($con, $command) = @_;
70  
71 0 _update;
72 0 ▶ return 1 if $NORESTRICTION;
Branch: 1 branch
BranchTrueFalseTotal
if $NORESTRICTION 0 0 0
73 0 ▶ return 1 if $command =~ /HELP|QUIT|AUTHINFO|MODE|SLAVE/i;
Branch: 1 branch
BranchTrueFalseTotal
if $command =~ /HELP|QUIT|AUTHINFO|MODE|SLAVE/i 0 0 0
74 0 ▶ return 0 unless $con->{_user};
Branch: 1 branch
BranchTrueFalseTotal
unless $con->{"_user"} 0 0 0
75 0 ▶ return 0 unless $con->{_passwd};
Branch: 1 branch
BranchTrueFalseTotal
unless $con->{"_passwd"} 0 0 0
76  
77 0 ▶ unless (check($con->{_user}, $con->{_passwd})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (check($con->{"_user"}, $con->{"_passwd"})) 0 0 0
78 # just paranoid
79 0 return 0;
80 }
81 0 ▶ if ($command =~ /SHUT|CREATE|DELETE|MOVE/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command =~ /SHUT|CREATE|DELETE|MOVE/i) 0 0 0
82 0 return $PERM{$con->{_user}}->{'admin'};
83 }
84 0 ▶ if ($command =~ /POST|IHAVE/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($command =~ /POST|IHAVE/i) 0 0 0
85 0 return $PERM{$con->{_user}}->{'write'};
86 }
87 0 return $PERM{$con->{_user}}->{'read'};
88 }
89  
90 0 ▶sub check {
Subroutine check: not called CC=3 SCAR=24.8
Pod undocumented
91 0 my ($user, $passwd) = @_;
92  
93 0 _update;
94 0 ▶ return 0 unless exists $PASSWD{$user};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $PASSWD{$user} 0 0 0
95 0 ▶ return 1 if $PASSWD{$user} eq '*';
Branch: 1 branch
BranchTrueFalseTotal
if $PASSWD{$user} eq "*" 0 0 0
96 0 my $salt = substr($PASSWD{$user},0,2);
97 0 return (crypt($passwd, $salt) eq $PASSWD{$user});
98 }
99  
100 0 ▶sub add_user {
Subroutine add_user: not called CC=2 SCAR=17.9
Pod undocumented
101 0 my ($user, $passwd, @perm) = @_;
102 0 my @cs = ('a'..'z', 'A'..'Z', '0'..'9','.','/');
103 0 srand(time);
104  
105 0 my $salt = $cs[rand(64)] . $cs[rand(64)];
106 0 my $cpasswd = crypt($passwd, $salt);
107 0 my $fh = new IO::File '>>' . $Config->passwd;
108 0 ▶ if (defined $fh) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fh) { } 0 0 0
109 0 $fh->print("$user $cpasswd @perm\n");
110 0 $fh->close;
111 } else {
112 0 print "Could not write '%s': $!\n", $Config->passwd;
113 0 return 0;
114 }
115 0 return 1;
116 }
117  
118  
119 1 1;
« Connection.pm ↑ Summary Group.pm »