| 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
| |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if ($PASSWD ne $Config->passwd | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$PASSWD ne $NNML::Auth::Config->passwd or (stat $NNML::Auth::Config->passwd)[9] > $TIME
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 42 | 0 | local ($_); | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | while (<$fh>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ($NORESTRICTION) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return 1 if $command =~ /HELP|QUIT|AUTHINFO|MODE|SLAVE/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return 0 unless $con->{_user}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | return 0 unless $con->{_passwd}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | unless (check($con->{_user}, $con->{_passwd})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | # just paranoid | ||||||||||||||||||||||||||||
| 79 | 0 | return 0; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ($command =~ /SHUT|CREATE|DELETE|MOVE/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | return $PERM{$con->{_user}}->{'admin'}; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ($command =~ /POST|IHAVE/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | return 1 if $PASSWD{$user} eq '*'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||