line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gantry::Control::C::Authz::PageBasedBase; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1772
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
573
|
use Gantry::Control; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
109
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
33
|
|
|
99
|
use constant MP2 => ( |
7
|
|
|
|
|
|
|
exists $ENV{MOD_PERL_API_VERSION} and |
8
|
|
|
|
|
|
|
$ENV{MOD_PERL_API_VERSION} >= 2 |
9
|
1
|
|
|
1
|
|
7
|
); |
|
1
|
|
|
|
|
3
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# must explicitly import for mod_perl2 |
12
|
|
|
|
|
|
|
BEGIN { |
13
|
1
|
|
|
1
|
|
1074
|
if (MP2) { |
14
|
|
|
|
|
|
|
require Gantry::Engine::MP20; |
15
|
|
|
|
|
|
|
Gantry::Engine::MP20->import(); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
############################################################ |
20
|
|
|
|
|
|
|
# Functions # |
21
|
|
|
|
|
|
|
############################################################ |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
###################################################################### |
24
|
|
|
|
|
|
|
# Main Execution Begins Here # |
25
|
|
|
|
|
|
|
###################################################################### |
26
|
|
|
|
|
|
|
sub handler : method { |
27
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $r ) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
my $user_model = $self->user_model; |
30
|
0
|
|
|
|
|
0
|
my $group_members_model = $self->group_members_model(); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Check Exclude paths |
33
|
0
|
0
|
|
|
|
0
|
if ( $r->dir_config( 'exclude_path' ) ) { |
34
|
0
|
|
|
|
|
0
|
foreach my $p ( split( /\s*;\s*/, $r->dir_config( 'exclude_path' ) ) ) { |
35
|
0
|
0
|
|
|
|
0
|
if ( $r->path_info =~ /^$p$/ ) { |
36
|
0
|
|
|
|
|
0
|
return( $self->status_const( 'OK' ) ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} # end if exclude_path |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
0
|
my $requires = $r->requires; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# If we don't have any requirements get out ! |
44
|
0
|
0
|
|
|
|
0
|
return( $self->status_const( 'DECLINED' ) ) if ( ! $requires ); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Who's the user ? |
47
|
0
|
|
|
|
|
0
|
my $user = $r->user; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# get the uri and fill @p. |
50
|
0
|
|
|
|
|
0
|
my @p = split( '/', $r->uri ); |
51
|
0
|
0
|
|
|
|
0
|
@p = 'index.html' if ( scalar( @p ) < 1 ); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Get the users groups and put them in a hash. |
54
|
0
|
|
|
|
|
0
|
my ( %groups, %group_ids, $uperm, $gperm, $wperm, $uid, $oid, $gid ); |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
0
|
if( $user ) { |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
0
|
my @user_row = $user_model->search( user_name => $user ); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# set user id |
61
|
0
|
|
|
|
|
0
|
$uid = $user_row[0]->id; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# get groups for user |
64
|
0
|
|
|
|
|
0
|
my @group_rows = $group_members_model->search( |
65
|
|
|
|
|
|
|
user_id => $user_row[0]->id |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
0
|
foreach ( @group_rows ) { |
69
|
0
|
|
|
|
|
0
|
$groups{$_->group_id->name} = 1; |
70
|
0
|
|
|
|
|
0
|
$group_ids{$_->group_id} = 1; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} # end: if user |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# make the check uri database calls here. |
75
|
0
|
|
|
|
|
0
|
( $uperm, $gperm, $wperm, $oid, $gid ) = $self->lookup_uri( @p ); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# This should actually be Forbidden I believe. |
78
|
0
|
0
|
|
|
|
0
|
if ( $self->status_const( 'OK' ) |
79
|
|
|
|
|
|
|
ne $self->do_requires( $requires, $user, \%groups ) ) { |
80
|
0
|
|
|
|
|
0
|
return( $self->status_const( 'FORBIDDEN' ) ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# compare against world |
84
|
0
|
0
|
|
|
|
0
|
return( $self->status_const( 'OK' ) ) if ( ( dec2bin( $wperm ) )[0] ); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# compare against group |
87
|
0
|
0
|
|
|
|
0
|
if ( defined $group_ids{$gid} ) { |
88
|
0
|
0
|
|
|
|
0
|
return( $self->status_const( 'OK' ) ) if ( ( dec2bin( $gperm ) )[0] ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# compare against user |
92
|
0
|
0
|
|
|
|
0
|
if ( $oid == $uid ) { |
93
|
0
|
0
|
|
|
|
0
|
return( $self->status_const( 'OK' ) ) if ( ( dec2bin( $uperm ) )[0] ); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# This should actually be Forbidden I believe. |
97
|
|
|
|
|
|
|
# fail if all else dosen't work :( -- bye |
98
|
0
|
|
|
|
|
0
|
$r->note_basic_auth_failure; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
0
|
return( $self->status_const( 'FORBIDDEN' ) ); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} # END $self->handler |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
#------------------------------------------------- |
105
|
|
|
|
|
|
|
# do_requires( $requires, $user, $groups ) |
106
|
|
|
|
|
|
|
#------------------------------------------------- |
107
|
|
|
|
|
|
|
sub do_requires { |
108
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $requires, $user, $groups ) = @_; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
0
|
for my $req_ent ( @$requires ) { |
111
|
0
|
|
|
|
|
0
|
my ( $req, @rest ) = split( /\s+/, $req_ent->{requirement} ); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# This is kinda odd. Do I really need this ? |
114
|
0
|
0
|
|
|
|
0
|
if ( lc( $req ) eq 'valid-user' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
115
|
0
|
|
|
|
|
0
|
return( $self->status_const( 'OK' ) ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
elsif( lc( $req ) eq 'user' ) { |
118
|
0
|
|
|
|
|
0
|
for my $valid_user ( @rest ) { |
119
|
0
|
0
|
|
|
|
0
|
return( $self->status_const( 'OK' ) ) |
120
|
|
|
|
|
|
|
if ( $user eq $valid_user ); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
elsif( lc( $req ) eq 'group' ) { |
124
|
0
|
|
|
|
|
0
|
for my $valid_group ( @rest ) { |
125
|
0
|
0
|
|
|
|
0
|
return( $self->status_const( 'OK' ) ) |
126
|
|
|
|
|
|
|
if ( exists $$groups{$valid_group} ); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
} # END do_requires |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
#------------------------------------------------- |
134
|
|
|
|
|
|
|
# $self->lookup_uri( @p ) |
135
|
|
|
|
|
|
|
#------------------------------------------------- |
136
|
|
|
|
|
|
|
sub lookup_uri { |
137
|
0
|
|
|
0
|
1
|
0
|
my ( $self, @p ) = @_; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# Sane staring point, nothing works ;) |
140
|
0
|
|
|
|
|
0
|
my ( $uperm, $gperm, $wperm, $oid, $gid ) = ( 0, 0, 0, 0, 0 ); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# Leave now if no @p |
143
|
0
|
0
|
|
|
|
0
|
return( $uperm, $gperm, $wperm, $oid, $gid ) if ( scalar( @p ) < 1 ); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# Figure out what the uri is. |
146
|
0
|
|
|
|
|
0
|
my $uri = join( '/', @p ); |
147
|
0
|
0
|
|
|
|
0
|
$uri = "/$uri" if ( $uri !~ /^\// ); |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# Do the lookup. |
150
|
0
|
|
|
|
|
0
|
my @page_row = Gantry::Control::Model::auth_pages->search( uri => $uri ); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# If we find it set the vals. |
153
|
0
|
0
|
|
|
|
0
|
if ( @page_row ) { |
154
|
0
|
|
|
|
|
0
|
( $uperm, $gperm, $wperm, $oid, $gid ) = ( |
155
|
|
|
|
|
|
|
$page_row[0]->user_perm, |
156
|
|
|
|
|
|
|
$page_row[0]->group_perm, |
157
|
|
|
|
|
|
|
$page_row[0]->world_perm, |
158
|
|
|
|
|
|
|
$page_row[0]->owner_id, |
159
|
|
|
|
|
|
|
$page_row[0]->group_id |
160
|
|
|
|
|
|
|
); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else { |
164
|
|
|
|
|
|
|
# Take one down and pass it around |
165
|
0
|
|
|
|
|
0
|
pop( @p ); |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
0
|
( $uperm, $gperm, $wperm, $oid, $gid ) = $self->lookup_uri( @p ); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# Return what we have. |
171
|
0
|
|
|
|
|
0
|
return( $uperm, $gperm, $wperm, $oid, $gid ); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
} # end lookup_uri |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
#------------------------------------------------- |
176
|
|
|
|
|
|
|
# $self->import( $self, @options ) |
177
|
|
|
|
|
|
|
#------------------------------------------------- |
178
|
|
|
|
|
|
|
sub import { |
179
|
1
|
|
|
1
|
|
14
|
my ( $self, @options ) = @_; |
180
|
|
|
|
|
|
|
|
181
|
1
|
|
|
|
|
2
|
my( $engine, $tplugin ); |
182
|
|
|
|
|
|
|
|
183
|
1
|
|
|
|
|
13
|
foreach (@options) { |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
# Import the proper engine |
186
|
0
|
0
|
|
|
|
|
if (/^-Engine=(.*)$/) { |
187
|
0
|
|
|
|
|
|
$engine = "Gantry::Engine::$1"; |
188
|
0
|
|
|
|
|
|
eval "use $engine"; |
189
|
0
|
0
|
|
|
|
|
if ( $@ ) { |
190
|
0
|
|
|
|
|
|
die "unable to load engine $1 ($@)"; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
} # end: import |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
# EOF |
199
|
|
|
|
|
|
|
1; |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
__END__ |