Changeset 13796


Ignore:
Timestamp:
01/23/12 19:00:19 (4 weeks ago)
Author:
CrawfordCurrie
Message:

Item11458: simplify and streamline handling of password file; it now must exist for Foswiki to run, and will be created by =configure= if not. This lets us do enhanced checking in =configure= while reducing the runtime burden.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/UnitTestContrib/test/unit/FoswikiFnTestCase.pm

    r13752 r13796  
    6666    $Foswiki::cfg{RCS}{AutoAttachPubFiles}  = 0; 
    6767    $Foswiki::cfg{Register}{AllowLoginName} = 1; 
    68     $Foswiki::cfg{Htpasswd}{FileName}    = "$Foswiki::cfg{WorkingDir}/htpasswd"; 
    69     $Foswiki::cfg{PasswordManager}       = 'Foswiki::Users::HtPasswdUser'; 
     68    $Foswiki::cfg{Htpasswd}{FileName} = "$Foswiki::cfg{WorkingDir}/htpasswd"; 
     69    unless (-e $Foswiki::cfg{Htpasswd}{FileName} ) { 
     70        my $fh; 
     71        open($fh, ">", $Foswiki::cfg{Htpasswd}{FileName}) || die $!; 
     72        close($fh) || die $!; 
     73    } 
     74    $Foswiki::cfg{PasswordManager}    = 'Foswiki::Users::HtPasswdUser'; 
    7075    $Foswiki::cfg{Htpasswd}{GlobalCache} = 0; 
    71     $Foswiki::cfg{UserMappingManager}    = 'Foswiki::Users::TopicUserMapping'; 
    72     $Foswiki::cfg{LoginManager} = 'Foswiki::LoginManager::TemplateLogin'; 
     76    $Foswiki::cfg{UserMappingManager} = 'Foswiki::Users::TopicUserMapping'; 
     77    $Foswiki::cfg{LoginManager}       = 'Foswiki::LoginManager::TemplateLogin'; 
    7378    $Foswiki::cfg{Register}{EnableNewUserRegistration} = 1; 
    7479    $Foswiki::cfg{RenderLoggedInButUnknownUsers} = 0; 
  • trunk/UnitTestContrib/test/unit/RegisterTests.pm

    r13791 r13796  
    12461246 
    12471247    $query->path_info( '/' . $this->{users_web} . '/WebHome' ); 
    1248     unlink $Foswiki::cfg{Htpasswd}{FileName}; 
     1248    my $fh; 
     1249    open($fh, ">", $Foswiki::cfg{Htpasswd}{FileName}) || die $!; 
     1250    close($fh) || die $!; 
    12491251 
    12501252    $this->createNewFoswikiSession( $Foswiki::cfg{DefaultUserLogin}, $query ); 
  • trunk/core/lib/Foswiki/Configure/Checkers/Htpasswd/FileName.pm

    r13286 r13796  
    2424    Foswiki::Configure::Load::expandValue($f); 
    2525 
    26     return $e 
    27       . $this->WARN( 
    28 "file $f is not found.  This may be normal for a new installation.  it will be created when the first user registers to the site" 
    29       ) unless ( -f $f ); 
    30  
    31     return $e 
    32       . $this->ERROR( 
    33 "$f is not writable.  User registration will be disabled until this is corrected." 
    34       ) unless ( -w $f ); 
     26    unless ( -e $f ) { 
     27        # password file does not exist; check it can be created 
     28        my $fh; 
     29        if (!open($fh, ">", $f) || !close($fh)) { 
     30            return $e . $this->ERROR("Password file $f does not exist and could not be created: $!"); 
     31        } else { 
     32            $e .= $this->NOTE("A new password file $f has been created."); 
     33            unless (chmod(0600, $f)) { 
     34                $e .= $this->WARN("Permissions could not be changed on the new password file $f") 
     35            } 
     36        } 
     37    } elsif ( !( -f $f && -w $f )) { 
     38        # password file exists but is not writable 
     39        return $e 
     40            . $this->ERROR( 
     41            "$f is not a writable plain file. " 
     42            . "User registration will be disabled until this is corrected.") 
     43    } 
    3544 
    3645    return $e; 
  • trunk/core/lib/Foswiki/Contrib/core/MANIFEST

    r13524 r13796  
    483483lib/Foswiki/Configure/Checkers/Htpasswd/Encoding.pm 0444 
    484484lib/Foswiki/Configure/Checkers/Htpasswd/FileName.pm 0444 
     485lib/Foswiki/Configure/Checkers/Htpasswd/LockFileName.pm 0444 
    485486lib/Foswiki/Configure/Checkers/HttpCompress.pm 0444 
    486487lib/Foswiki/Configure/Checkers/Introduction.pm 0444 
  • trunk/core/lib/Foswiki/UI/Register.pm

    r13643 r13796  
    101101    } 
    102102    elsif ( $action eq 'resetPassword' ) { 
     103        if ( !$session->inContext("passwords_modifyable") ) { 
     104            throw Foswiki::OopsException( 
     105                'attention', 
     106                web   => $session->{webName}, 
     107                topic => $session->{topicName}, 
     108                def   => 'passwords_disabled' 
     109            ); 
     110        } 
    103111        require Foswiki::UI::Passwords; 
    104112        Foswiki::UI::Passwords::resetpasswd($session); 
     
    287295        my $cUID = $users->addUser( 
    288296            $row->{LoginName}, $row->{WikiName}, 
    289             $row->{Password},  $row->{Email} 
     297            $session->inContext("passwords_modifyable") ? $row->{Password} : undef, 
     298            $row->{Email} 
    290299        ); 
    291300        $log .= 
     
    837846    my $users = $session->{users}; 
    838847    try { 
    839         unless ( defined( $data->{Password} ) ) { 
     848        unless ( !$session->inContext("passwords_modifyable") || 
     849                 defined( $data->{Password} ) ) { 
    840850 
    841851            # SMELL: should give consideration to disabling 
     
    855865        my $cUID = $users->addUser( 
    856866            $data->{LoginName}, $data->{WikiName}, 
    857             $data->{Password},  $data->{Email} 
     867            $session->inContext("passwords_modifyable") ? $data->{Password} : undef, 
     868            $data->{Email} 
    858869        ); 
    859870        my $log = _createUserTopic( $session, $data ); 
  • trunk/core/lib/Foswiki/Users/ApacheHtpasswdUser.pm

    r12236 r13796  
    121121    my $path = $Foswiki::cfg{Htpasswd}{FileName}; 
    122122 
    123     #TODO: what if the data dir is also read only? 
    124     if ( ( !-e $path ) || ( -e $path && -r $path && !-d $path && -w $path ) ) { 
    125         $this->{session}->enterContext('passwords_modifyable'); 
    126         return 0; 
    127     } 
     123    # We expect the path to exist and be writable. 
     124    return 0 if ( -e $path && -f $path && -w $path ); 
     125 
     126    # Otherwise, log a problem. 
     127    $this->{session}->logger->log( 
     128        'warning', 
     129        'The password file does not exist or cannot be written.' . 
     130        'Run =configure= and check the setting of {Htpasswd}{FileName}.' . 
     131        ' New user registration has been disabled until this is corrected.'); 
     132    # And disable registration (and password changes) 
     133    $Foswiki::cfg{Register}{EnableNewUserRegistration} = 0; 
    128134    return 1; 
    129135} 
  • trunk/core/lib/Foswiki/Users/HtPasswdUser.pm

    r13756 r13796  
    162162    my $path = $Foswiki::cfg{Htpasswd}{FileName}; 
    163163 
    164     #TODO: what if the data dir is also read only? 
    165     if ( ( !-e $path ) || ( -e $path && -r $path && !-d $path && -w $path ) ) { 
    166         $this->{session}->enterContext('passwords_modifyable'); 
    167         return 0; 
    168     } 
     164    # We expect the path to exist and be writable. 
     165    return 0 if ( -e $path && -f $path && -w $path ); 
     166 
     167    # Otherwise, log a problem. 
     168    $this->{session}->logger->log( 
     169        'warning', 
     170        'The password file does not exist or cannot be written.' . 
     171        'Run =configure= and check the setting of {Htpasswd}{FileName}.' . 
     172        ' New user registration has been disabled until this is corrected.'); 
     173    # And disable registration (which will also disable password changes) 
     174    $Foswiki::cfg{Register}{EnableNewUserRegistration} = 0; 
     175 
    169176    return 1; 
    170177} 
  • trunk/core/lib/Foswiki/Users/Password.pm

    r7452 r13796  
    5757 
    5858returns true if the password database is not currently modifyable 
    59 also needs to call 
    60 $this->{session}->enter_context('passwords_modifyable'); 
     59also needs to set $this->{session}->enter_context('passwords_modifyable'); 
    6160if you want to be able to use the existing TopicUserMappingContrib ChangePassword topics 
    6261 
  • trunk/core/templates/messages.tmpl

    r13655 r13796  
    170170 
    171171%MAKETEXT{"You have *not* been registered."}% 
     172%TMPL:END% 
     173%TMPL:DEF{"passwords_disabled"}% 
     174---+++ %MAKETEXT{"Passwords disabled"}% 
     175 
     176%MAKETEXT{"The Administrator has disabled password changes."}% 
     177 
     178%MAKETEXT{"Please contact [_1]." args="%WIKIWEBMASTER%"}% 
     179 
     180%MAKETEXT{"Your password has not been changed."}% 
    172181%TMPL:END% 
    173182%TMPL:DEF{"thanks"}% 
Note: See TracChangeset for help on using the changeset viewer.