home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / AuthenPasswd.pm < prev    next >
Encoding:
Perl POD Document  |  2001-07-13  |  3.3 KB  |  111 lines

  1. package Apache::AuthenPasswd;
  2.  
  3. use strict;
  4. use Apache::Constants ':common';
  5.  
  6. $Apache::AuthenPasswd::VERSION = '0.10';
  7.  
  8. sub handler {
  9.     my $r = shift;
  10.     my($res, $sent_pwd) = $r->get_basic_auth_pw;
  11.     return $res if $res; #decline if not Basic
  12.  
  13.     my $name = $r->connection->user;
  14.  
  15.     if ($name eq "") {
  16.     $r->note_basic_auth_failure;
  17.         $r->log_reason("Apache::AuthenPasswd - no username given", $r->uri);
  18.         return AUTH_REQUIRED;
  19.     }
  20.  
  21.     my ($user, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwnam $name;
  22.  
  23.     unless ($user) {
  24.     $r->note_basic_auth_failure;
  25.     $r->log_reason("Apache::AuthenPasswd - user $name: unknown", $r->uri);
  26.     return AUTH_REQUIRED;
  27.     }
  28.  
  29.     if(crypt($sent_pwd, $passwd) eq $passwd) {
  30.     return OK;
  31.     } else {
  32.     $r->note_basic_auth_failure;
  33.     $r->log_reason("Apache::AuthenPasswd - user $name: bad password", $r->uri);
  34.     return AUTH_REQUIRED;
  35.     }
  36.  
  37.     return OK;
  38. }
  39.  
  40. 1;
  41.  
  42. __END__
  43.  
  44. =head1 NAME
  45.  
  46. Apache::AuthenPasswd - mod_perl passwd Authentication module
  47.  
  48. =head1 SYNOPSIS
  49.  
  50.     <Directory /foo/bar>
  51.     # This is the standard authentication stuff
  52.     AuthName "Foo Bar Authentication"
  53.     AuthType Basic
  54.  
  55.     PerlAuthenHandler Apache::AuthenPasswd
  56.  
  57.     # Standard require stuff, /etc/passwd users or /etc/group groups, and
  58.     # "valid-user" all work OK
  59.     require user username1 username2 ...
  60.     require group groupname1 groupname2 ... # [Need Apache::AuthzPasswd]
  61.     require valid-user
  62.  
  63.     # The following is actually only needed when authorizing
  64.     # against /etc/group. This is a separate module.
  65.     PerlAuthzHandler Apache::AuthzPasswd
  66.  
  67.     </Directory>
  68.  
  69.     These directives can also be used in the <Location> directive or in
  70.     an .htaccess file.
  71.  
  72. = head1 DESCRIPTION
  73.  
  74. This perl module is designed to work with mod_perl. It is a direct
  75. adaptation (i.e. I modified the code) of Michael Parker's
  76. (B<parker@austx.tandem.com>) Apache::AuthenSmb module.
  77.  
  78. The module uses getpwnam to retrieve the B<passwd> entry from the
  79. B</etc/passwd> file, using the supplied username as the search key.  It
  80. then uses B<crypt()> to verify that the supplied password matches the
  81. retrieved hashed password.
  82.  
  83. = head2 Apache::AuthenPasswd vs. Apache::AuthzPasswd
  84.  
  85. I've taken "authentication" to be meaningful only in terms of a user and
  86. password combination, not group membership.  This means that you can use
  87. Apache::AuthenPasswd with the B<require user> and B<require valid-user>
  88. directives.  In the /etc/passwd and /etc/group context I consider B<require
  89. group> to be an "authorization" concern.  I.e., group authorization
  90. consists of establishing whether the already authenticated user is a member
  91. of one of the indicated groups in the B<require group> directive.  This
  92. process may be handled by B<Apache::AuthzPasswd>.  Admittedly, AuthzPasswd
  93. is a misnomer, but I wanted to keep AuthenPasswd and AuthzPasswd related,
  94. if only by name.
  95.  
  96. I welcome any feedback on this module, esp. code improvements, given
  97. that it was written hastily, to say the least.
  98.  
  99. =head1 AUTHOR
  100.  
  101. Demetrios E. Paneras <dep@media.mit.edu>
  102.  
  103. =head1 COPYRIGHT
  104.  
  105. Copyright (c) 1998 Demetrios E. Paneras, MIT Media Laboratory.
  106.  
  107. This library is free software; you can redistribute it and/or
  108. modify it under the same terms as Perl itself.
  109.  
  110. =cut
  111.