line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
1
|
|
7
|
use NNML::Config qw($Config); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
128
|
|
24
|
1
|
|
|
1
|
|
6
|
use IO::File; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
152
|
|
25
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
939
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $NORESTRICTION = -1; |
28
|
|
|
|
|
|
|
my $PASSWD = ''; |
29
|
|
|
|
|
|
|
my $TIME; |
30
|
|
|
|
|
|
|
my (%PASSWD, %PERM); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _update { |
33
|
0
|
|
|
0
|
|
|
my $norestriction = $NORESTRICTION; |
34
|
0
|
0
|
|
|
|
|
if (-e $Config->passwd) { |
35
|
0
|
0
|
0
|
|
|
|
if ($PASSWD ne $Config->passwd |
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
|
0
|
|
|
|
|
if (defined $fh) { |
42
|
0
|
|
|
|
|
|
local ($_); |
43
|
0
|
|
|
|
|
|
while (<$fh>) { |
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
|
0
|
|
|
|
|
if ($NORESTRICTION != $norestriction) { |
60
|
0
|
0
|
|
|
|
|
if ($NORESTRICTION) { |
61
|
0
|
|
|
|
|
|
print "Authorization disabled\n"; |
62
|
|
|
|
|
|
|
} else { |
63
|
0
|
|
|
|
|
|
print "Authorization enabled\n"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub perm { |
69
|
0
|
|
|
0
|
0
|
|
my ($con, $command) = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
_update; |
72
|
0
|
0
|
|
|
|
|
return 1 if $NORESTRICTION; |
73
|
0
|
0
|
|
|
|
|
return 1 if $command =~ /HELP|QUIT|AUTHINFO|MODE|SLAVE/i; |
74
|
0
|
0
|
|
|
|
|
return 0 unless $con->{_user}; |
75
|
0
|
0
|
|
|
|
|
return 0 unless $con->{_passwd}; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
unless (check($con->{_user}, $con->{_passwd})) { |
78
|
|
|
|
|
|
|
# just paranoid |
79
|
0
|
|
|
|
|
|
return 0; |
80
|
|
|
|
|
|
|
} |
81
|
0
|
0
|
|
|
|
|
if ($command =~ /SHUT|CREATE|DELETE|MOVE/i) { |
82
|
0
|
|
|
|
|
|
return $PERM{$con->{_user}}->{'admin'}; |
83
|
|
|
|
|
|
|
} |
84
|
0
|
0
|
|
|
|
|
if ($command =~ /POST|IHAVE/i) { |
85
|
0
|
|
|
|
|
|
return $PERM{$con->{_user}}->{'write'}; |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
|
return $PERM{$con->{_user}}->{'read'}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub check { |
91
|
0
|
|
|
0
|
0
|
|
my ($user, $passwd) = @_; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
_update; |
94
|
0
|
0
|
|
|
|
|
return 0 unless exists $PASSWD{$user}; |
95
|
0
|
0
|
|
|
|
|
return 1 if $PASSWD{$user} eq '*'; |
96
|
0
|
|
|
|
|
|
my $salt = substr($PASSWD{$user},0,2); |
97
|
0
|
|
|
|
|
|
return (crypt($passwd, $salt) eq $PASSWD{$user}); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub add_user { |
101
|
0
|
|
|
0
|
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
|
0
|
|
|
|
|
if (defined $fh) { |
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; |