[owncloud-devel] duplicate lastlog with new authentication app

Arthur Schiwon blizzz at owncloud.com
Wed Jun 24 21:25:10 GMT 2015


Hey,

On Wednesday 24 June 2015 16:41:02 Cornelius Kölbel wrote:
> Hello,
> 
> I am writing an authentication App, that is supposed to replace the
> authentication of the users and verify the user account against an
> external two factor authentication server.
> 
> I am done with all the configuration stuff and now I am about replacing
> the user backend.
> 
> Roughly my app.php looks like this (I took a look at user_external,
> user_ldap and user_otp):
> 
> <?php
> \OCP\App::registerAdmin('user_privacyidea', 'adminSettings');
> 
> OC::$CLASSPATH['OC_User_PRIVACYIDEA'] =
> 'apps/user_privacyidea/lib/otp_privacyidea.php';
> 
> $enabled = OCP\Config::getAppValue('privacyIDEA','enable_privacyidea');
> OCP\Util::writeLog('user_privacyidea', $enabled, OCP\Util::ERROR);
> if($enabled === "yes") {
>     OCP\Util::writeLog('user_privacyidea', 'privacyIDEA is enabled',
>     OCP\Util::ERROR);
> 
>     $usedBackends = OC_User::getUsedBackends();
>     OC_User::clearBackends();
>     $userBackend = new OC_User_PRIVACYIDEA();
>     // register user backend
>     OC_User::useBackend($userBackend);
> 
> } else {
>     OCP\Util::writeLog('user_privacyidea', 'privacyIDEA is disabled',
> OCP\Util::ERROR);
> }
> 
> 
> So far it works fine. The normal local users can not login anymore! ;-)
> 
> Nevertheless I get the following error in the log file and wondering,
> how I ended up there:
> 
> {"reqId":"ddfc040c35abc68350c806acf72e1c57","remoteAddr":"212.185.212.207","
> app":"handleLogin","message":"Exception: {\"Message\":\"An exception
> occurred while executing 'INSERT INTO `oc_preferences`
> (`configvalue`,`userid`,`appid`,`configkey`) SELECT ?,?,?,? FROM
> `oc_preferences` WHERE `configkey` = ? AND `userid` IS NULL AND `appid` = ?
> HAVING COUNT(*) = 0' with params [1435154884, null, \\\"login\\\",
> \\\"lastLogin\\\", \\\"lastLogin\\\", \\\"login\\\"]:\\n\\nSQLSTATE[23000]:
> Integrity constraint violation: 1062 Duplicate entry 'login-lastLogin' for
> key 'PRIMARY'\",\"Code\":0,\"Trace\":\"#0
> \\\/var\\\/www\\\/owncloud\\\/3rdparty\\\/doctrine\\\/dbal\\\/lib\\\/Doctri
> ne\\\/DBAL\\\/DBALException.php(116):
> Doctrine\\\\DBAL\\\\Driver\\\\AbstractMySQLDriver->convertException('An
> exception oc...', Object(Doctrine\\\\DBAL\\\\Driver\\\\PDOException))\\n#1
> \\\/var\\\/www\\\/owncloud\\\/3rdparty\\\/doctrine\\\/dbal\\\/lib\\\/Doctri
> ne\\\/DBAL\\\/Connection.php(996):
> Doctrine\\\\DBAL\\\\DBALException::driverExceptionDuringQuery(Object(Doctri
> ne\\\\DBAL\\\\Driver\\\\PDOMySql\\\\Driver),
> Object(Doctrine\\\\DBAL\\\\Driver\\\\PDOException), 'INSERT INTO `oc...',
> Array)\\n#2
> \\\/var\\\/www\\\/owncloud\\\/lib\\\/private\\\/db\\\/connection.php(132):
> Doctrine\\\\DBAL\\\\Connection->executeUpdate('INSERT INTO `oc...', Array,
> Array)\\n#3
> \\\/var\\\/www\\\/owncloud\\\/lib\\\/private\\\/db\\\/adapter.php(75):
> OC\\\\DB\\\\Connection->executeUpdate('INSERT INTO `*P...', Array)\\n#4
> \\\/var\\\/www\\\/owncloud\\\/lib\\\/private\\\/db\\\/connection.php(171):
> OC\\\\DB\\\\Adapter->insertIfNotExist('*PREFIX*prefere...', Array,
> Array)\\n#5
> \\\/var\\\/www\\\/owncloud\\\/lib\\\/private\\\/allconfig.php(198):
> OC\\\\DB\\\\Connection->insertIfNotExist('*PREFIX*prefere...', Array,
> Array)\\n#6
> \\\/var\\\/www\\\/owncloud\\\/lib\\\/private\\\/user\\\/user.php(145):
> OC\\\\AllConfig->setUserValue(NULL, 'login', 'lastLogin', 1435154884)\\n#7
> \\\/var\\\/www\\\/owncloud\\\/lib\\\/private\\\/user\\\/manager.php(57):
> OC\\\\User\\\\User->updateLastLoginTimestamp()\\n#8 [internal function]:
> OC\\\\User\\\\Manager->OC\\\\User\\\\{closure}(Object(OC\\\\User\\\\User),
> 'test123!')\\n#9
> \\\/var\\\/www\\\/owncloud\\\/lib\\\/private\\\/hooks\\\/basicemitter.php(8
> 5): call_user_func_array(Object(Closure), Array)\\n#10
> \\\/var\\\/www\\\/owncloud\\\/lib\\\/private\\\/hooks\\\/publicemitter.php(
> 18): OC\\\\Hooks\\\\BasicEmitter->emit('\\\\OC\\\\User', 'postLogin',
> Array)\\n#11
> \\\/var\\\/www\\\/owncloud\\\/lib\\\/private\\\/user\\\/session.php(202):
> OC\\\\Hooks\\\\PublicEmitter->emit('\\\\OC\\\\User', 'postLogin',
> Array)\\n#12 \\\/var\\\/www\\\/owncloud\\\/lib\\\/private\\\/user.php(216):
> OC\\\\User\\\\Session->login('admin', 'test123!')\\n#13
> \\\/var\\\/www\\\/owncloud\\\/lib\\\/base.php(991): OC_User::login('admin',
> 'test123!')\\n#14 \\\/var\\\/www\\\/owncloud\\\/lib\\\/base.php(887):
> OC::tryFormLogin()\\n#15
> \\\/var\\\/www\\\/owncloud\\\/lib\\\/base.php(849): OC::handleLogin()\\n#16
> \\\/var\\\/www\\\/owncloud\\\/index.php(36): OC::handleRequest()\\n#17
> {main}\",\"File\":\"\\\/var\\\/www\\\/owncloud\\\/3rdparty\\\/doctrine\\\/d
> bal\\\/lib\\\/Doctrine\\\/DBAL\\\/Driver\\\/AbstractMySQLDriver.php\",\"Line
> \":66}","level":4,"time":"2015-06-24T14:08:04+00:00"}
> 
> 
> So what is the duplicate with the last log?

The output is terrible to read in an email. Nevertheless, 

6 \\\/var\\\/www\\\/owncloud\\\/lib\\\/private\\\/user\\\/user.php(145): 
OC\\\\AllConfig->setUserValue(NULL, 'login', 'lastLogin', 1435154884)

looks like the provided username is NULL. I did not double check, but that 
might be the root cause.  Wild guess: your checkPassword should return the 
username if login was successful.

The outcome "Integrity constraint violation: 1062 Duplicate entry 'login-
lastLogin' for key 'PRIMARY'". The primary key (you can check db_structure.xml 
in the root dir) consists of userid, appid and configkey, but the userid is 
missing in 'login-lastLogin'. Expected with correct behaviour was 'admin-
login-lastLogin'.

Cheers
Arthur

> 
> Thanks a lot and kind regards
> Cornelius

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

XMPP: blizzz at jabber.arthur-schiwon.de

www.owncloud.com - Your Data, Your Cloud, Your Way!

ownCloud GmbH, GF: Markus Rex, Holger Dyroff, Frank Karlitschek
Schloßäckerstrasse 26a, 90443 Nürnberg, HRB 28050 (AG Nürnberg)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://mailman.owncloud.org/pipermail/devel/attachments/20150624/d7ae329e/attachment-0001.sig>


More information about the Devel mailing list