Page MenuHomePhabricator

LDAP Authorization throws a error when wiki is in readonly mode
Closed, DeclinedPublic

Description

When I set $wgReadOnly='reaonly reason', I recieve a error when logging in.

Error stack from log:

[exception] [928a82ffc7fbeb742806306f] /index.php?title=--- Wikimedia\Rdbms\DBReadOnlyError from line 1121 of /etc/mediawiki/includes/libs/rdbms/database/Database.php: Database is read-only: This wiki is in readonly mode.
#0 /etc/mediawiki/includes/libs/rdbms/database/Database.php(2010): Wikimedia\Rdbms\Database->query(string, string)
#1 /etc/mediawiki/extensions/LdapAuthentication/LdapAuthenticationPlugin.php(2170): Wikimedia\Rdbms\Database->update(string, array, array, string)
#2 /etc/mediawiki/extensions/LdapAuthentication/LdapAuthenticationPlugin.php(1260): LdapAuthenticationPlugin::saveDomain(User, string)
#3 /etc/mediawiki/includes/auth/AuthPluginPrimaryAuthenticationProvider.php(145): LdapAuthenticationPlugin->updateUser(User)
#4 /etc/mediawiki/includes/Hooks.php(177): MediaWiki\Auth\AuthPluginPrimaryAuthenticationProvider->onUserLoggedIn(User)
#5 /etc/mediawiki/includes/Hooks.php(205): Hooks::callHook(string, array, array, NULL)
#6 /etc/mediawiki/includes/auth/AuthManager.php(2392): Hooks::run(string, array)
#7 /etc/mediawiki/includes/auth/AuthManager.php(691): MediaWiki\Auth\AuthManager->setSessionDataForUser(User, boolean)
#8 /etc/mediawiki/includes/auth/AuthManager.php(383): MediaWiki\Auth\AuthManager->continueAuthentication(array)
#9 /etc/mediawiki/includes/specialpage/AuthManagerSpecialPage.php(353): MediaWiki\Auth\AuthManager->beginAuthentication(array, string)
#10 /etc/mediawiki/includes/specialpage/AuthManagerSpecialPage.php(482): AuthManagerSpecialPage->performAuthenticationStep(string, array)
#11 /etc/mediawiki/includes/htmlform/HTMLForm.php(660): AuthManagerSpecialPage->handleFormSubmit(array, VFormHTMLForm)
#12 /etc/mediawiki/includes/specialpage/AuthManagerSpecialPage.php(416): HTMLForm->trySubmit()
#13 /etc/mediawiki/includes/specialpage/LoginSignupSpecialPage.php(316): AuthManagerSpecialPage->trySubmit()
#14 /etc/mediawiki/includes/specialpage/SpecialPage.php(522): LoginSignupSpecialPage->execute(NULL)
#15 /etc/mediawiki/includes/specialpage/SpecialPageFactory.php(568): SpecialPage->run(NULL)
#16 /etc/mediawiki/includes/MediaWiki.php(288): SpecialPageFactory::executePath(Title, RequestContext)
#17 /etc/mediawiki/includes/MediaWiki.php(861): MediaWiki->performRequest()
#18 /etc/mediawiki/includes/MediaWiki.php(524): MediaWiki->main()
#19 /etc/mediawiki/index.php(42): MediaWiki->run()
#20 {main}

Looks like the login itself works well for existing users but the problem is extension tries to update domain for user even when the domain is the same as it was before.

Probably we can just add another if to check whether we need to update $olddomain to $domain:

static function saveDomain( $user, $domain ) {
	$user_id = $user->getId();
	if ( $user_id != 0 ) {
		$dbw = wfGetDB( DB_MASTER );
		$olddomain = self::loadDomain( $user );
		if ( $olddomain ) {
			//Check whether we need to update domain in database or not
			if( $olddomain != $domain ){
				return $dbw->update(
					'ldap_domains',
					[ 'domain' => $domain ],
					[ 'user_id' => $user_id ],
					__METHOD__
				);
			}
		} else {
			return $dbw->insert(
				'ldap_domains',
				[
					'domain' => $domain,
					'user_id' => $user_id
				],
				__METHOD__
			);
		}
	}
	return false;
}

The change fixed problem on my lab.

Event Timeline

@Urfiner: Thanks for taking a look at the code!

You are very welcome to use developer access to submit the proposed code changes as a Git branch directly into Gerrit which makes it easier to review them quickly and provide feedback. If you don't want to set up Git/Gerrit, you can also use the Gerrit Patch Uploader. Thanks again!

Change 449699 had a related patch set uploaded (by Reedy; owner: Ulfberht):
[mediawiki/extensions/LdapAuthentication@master] Fix error on login in readonly mode

https://gerrit.wikimedia.org/r/449699

Change 449699 merged by jenkins-bot:
[mediawiki/extensions/LdapAuthentication@master] Fix error on login in readonly mode

https://gerrit.wikimedia.org/r/449699