| 1 | package Apache2::AuthzNIS; | ||
| 2 | |||
| 3 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 0 | ▶ | use Net::NIS; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 6 | use mod_perl2; | ||
| 7 | |||
| 8 | BEGIN { | ||
| 9 | require Apache2::Const; | ||
| 10 | require Apache2::Access; | ||
| 11 | require Apache2::Connection; | ||
| 12 | require Apache2::Log; | ||
| 13 | require Apache2::RequestRec; | ||
| 14 | require Apache2::RequestUtil; | ||
| 15 | Apache2::Const->import( | ||
| 16 | '-compile' => 'HTTP_UNAUTHORIZED', | ||
| 17 | 'OK', 'HTTP_INTERNAL_SERVER_ERROR' | ||
| 18 | ); | ||
| 19 | } | ||
| 20 | |||
| 21 | =head1 NAME | ||
| 22 | |||
| 23 | Apache2::AuthzNIS - mod_perl2 NIS Group Authorization module | ||
| 24 | |||
| 25 | =cut | ||
| 26 | |||
| 27 | our $VERSION = '0.13'; | ||
| 28 | |||
| 29 | |||
| 30 | =head1 SYNOPSIS | ||
| 31 | |||
| 32 | <Directory /foo/bar> | ||
| 33 | # This is the standard authentication stuff | ||
| 34 | AuthName "Foo Bar Authentication" | ||
| 35 | AuthType Basic | ||
| 36 | |||
| 37 | # The following is actually only needed when you will authenticate | ||
| 38 | # via NIS passwd as well as authorize via NIS group. | ||
| 39 | # Apache2::AuthenNIS is a separate module. | ||
| 40 | PerlAuthenHandler Apache2::AuthenNIS | ||
| 41 | |||
| 42 | # Standard require stuff, NIS users or groups, and | ||
| 43 | # "valid-user" all work OK | ||
| 44 | require user username1 username2 ... | ||
| 45 | require group groupname1 groupname2 ... | ||
| 46 | require valid-user | ||
| 47 | |||
| 48 | PerlAuthzHandler Apache2::AuthzNIS | ||
| 49 | |||
| 50 | </Directory> | ||
| 51 | |||
| 52 | These directives can also be used in the <Location> directive or in | ||
| 53 | an .htaccess file. | ||
| 54 | |||
| 55 | =head1 DESCRIPTION | ||
| 56 | |||
| 57 | This perl module is designed to work with mod_perl, the Net::NIS module by | ||
| 58 | Rik Haris (B<rik.harris@fulcrum.com.au>), and the Apache2::AuthenNIS module. | ||
| 59 | Version 0.11 of Apache::AuthzNIS was renamed and modified to use mod_perl2. | ||
| 60 | That module was a direct adaptation of Michael Parker's | ||
| 61 | (B<parker@austx.tandem.com>) Apache::AuthenSmb module (which also included | ||
| 62 | an authorization routine). | ||
| 63 | |||
| 64 | The module calls B<Net::NIS::yp_match> using each of the B<require group> | ||
| 65 | elements as keys to the the B<group.byname> map, until a match with the | ||
| 66 | (already authenticated) B<user> is found. | ||
| 67 | |||
| 68 | For completeness, the module also handles B<require user> and B<require | ||
| 69 | valid-user> directives. | ||
| 70 | |||
| 71 | =head2 Apache2::AuthenNIS vs. Apache2::AuthzNIS | ||
| 72 | |||
| 73 | The following comments are from Apache::AuthzNIS. | ||
| 74 | |||
| 75 | I've taken "authentication" to be meaningful only in terms of a user and | ||
| 76 | password combination, not group membership. This means that you can use | ||
| 77 | Apache::AuthenNIS with the B<require user> and B<require valid-user> | ||
| 78 | directives. In the NIS context I consider B<require group> to be an | ||
| 79 | "authorization" concern. I.e., Group authorization consists of | ||
| 80 | establishing whether the already authenticated user is a member of one of | ||
| 81 | the indicated groups in the B<require group> directive. This process may | ||
| 82 | be handled by B<Apache::AuthzNIS>. | ||
| 83 | |||
| 84 | |||
| 85 | =head2 Functions | ||
| 86 | |||
| 87 | =over 4 | ||
| 88 | |||
| 89 | =item handler | ||
| 90 | |||
| 91 | This is the mod_perl2 handler function. | ||
| 92 | |||
| 93 | =cut | ||
| 94 | |||
| 95 | sub handler { | ||
| 96 | my $r = shift; | ||
| 97 | my $requires = $r->requires; | ||
| 98 | return Apache2::Const::OK unless $requires; | ||
| 99 | |||
| 100 | my $name = $r->user; | ||
| 101 | |||
| 102 | for my $req ( @$requires ) { | ||
| 103 | my( $require, @list ) = split /\s+/, $req->{'requirement'}; | ||
| 104 | |||
| 105 | #ok if user is one of these users | ||
| 106 | if ( $require eq 'user' ) { | ||
| 107 | return Apache2::Const::OK if grep $name eq $_, @list; | ||
| 108 | } | ||
| 109 | #ok if user is simply authenticated | ||
| 110 | elsif ( $require eq 'valid-user' ) { | ||
| 111 | return Apache2::Const::OK; | ||
| 112 | } | ||
| 113 | elsif ( $require eq 'group' ) { | ||
| 114 | my $domain = Net::NIS::yp_get_default_domain(); | ||
| 115 | unless ( $domain ) { | ||
| 116 | $r->note_basic_auth_failure; | ||
| 117 | $r->log_error( __PACKAGE__, " - cannot obtain NIS domain", $r->uri ); | ||
| 118 | return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR; | ||
| 119 | } | ||
| 120 | foreach my $thisgroup ( @list ) { | ||
| 121 | my( $status, $entry ) | ||
| 122 | = Net::NIS::yp_match( $domain, "group.byname", $thisgroup ); | ||
| 123 | if ( $status ) { | ||
| 124 | my $error_msg = Net::NIS::yperr_string( $status ); | ||
| 125 | $r->note_basic_auth_failure; | ||
| 126 | $r->log_error( __PACKAGE__, | ||
| 127 | " - group: $thisgroup: yp_match status $status, ", | ||
| 128 | $error_msg, $r->uri | ||
| 129 | ); | ||
| 130 | return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR; | ||
| 131 | } | ||
| 132 | my @names = split /\,/, $entry; | ||
| 133 | $names[0] =~ s/^.*:.*:.*://; | ||
| 134 | foreach my $oneuser ( @names ) { | ||
| 135 | if ( $oneuser eq $name ) { | ||
| 136 | return Apache2::Const::OK; | ||
| 137 | } | ||
| 138 | } | ||
| 139 | } | ||
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | $r->note_basic_auth_failure; | ||
| 144 | $r->log_error( __PACKAGE__, " - user $name: not authorized", $r->uri ); | ||
| 145 | return Apache2::Const::HTTP_UNAUTHORIZED; | ||
| 146 | } | ||
| 147 | |||
| 148 | =back | ||
| 149 | |||
| 150 | |||
| 151 | =head1 INSTALLATION | ||
| 152 | |||
| 153 | To install this module, run the following commands: | ||
| 154 | |||
| 155 | perl Build.PL | ||
| 156 | ./Build | ||
| 157 | ./Build test | ||
| 158 | ./Build install | ||
| 159 | |||
| 160 | |||
| 161 | =head1 AUTHOR | ||
| 162 | |||
| 163 | Demetrios E. Paneras C<< <dep at media.mit.edu> >> | ||
| 164 | |||
| 165 | Ported to mod_perl by Shannon Eric Peevey C<< <speeves at unt.edu> >> | ||
| 166 | |||
| 167 | Ported to mod_perl2 by Nguon Hao Ching C<< <hao at iteaha.us> >> | ||
| 168 | |||
| 169 | =head1 BUGS | ||
| 170 | |||
| 171 | Please report any bugs or feature requests to C<bug-apache2-authznis at rt.cpan.org>, or through | ||
| 172 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Apache2-AuthzNIS>. I will be notified, and then you'll | ||
| 173 | automatically be notified of progress on your bug as I make changes. | ||
| 174 | |||
| 175 | |||
| 176 | =head1 SUPPORT & DOCUMENTATION | ||
| 177 | |||
| 178 | You can find documentation for this module with the perldoc command. | ||
| 179 | |||
| 180 | perldoc Apache2::AuthzNIS | ||
| 181 | |||
| 182 | |||
| 183 | You can also look for information at: | ||
| 184 | |||
| 185 | =over 4 | ||
| 186 | |||
| 187 | =item * RT: CPAN's request tracker | ||
| 188 | |||
| 189 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-AuthzNIS> | ||
| 190 | |||
| 191 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 192 | |||
| 193 | L<http://annocpan.org/dist/Apache2-AuthzNIS> | ||
| 194 | |||
| 195 | =item * CPAN Ratings | ||
| 196 | |||
| 197 | L<http://cpanratings.perl.org/d/Apache2-AuthzNIS> | ||
| 198 | |||
| 199 | =item * Search CPAN | ||
| 200 | |||
| 201 | L<http://search.cpan.org/dist/Apache2-AuthzNIS> | ||
| 202 | |||
| 203 | =back | ||
| 204 | |||
| 205 | |||
| 206 | =head1 COPYRIGHT & LICENSE | ||
| 207 | |||
| 208 | Copyright (c) 1998 Demetrios E. Paneras, MIT Media Laboratory. | ||
| 209 | |||
| 210 | This program is free software; you can redistribute it and/or modify it | ||
| 211 | under the same terms as Perl itself. | ||
| 212 | |||
| 213 | |||
| 214 | =cut | ||
| 215 | |||
| 216 | 1; # End of Apache2::AuthzNIS | ||