sabre-io / Baikal

Baïkal is a Calendar+Contacts server
https://sabre.io/baikal/
GNU General Public License v3.0
2.49k stars 286 forks source link

Address book not showing up in DAVx5 #1234

Closed broke closed 6 months ago

broke commented 8 months ago

Baikal version: 0.9.4

Expected behaviour: While trying to connect to the Baikal server with DAVx5 version: 4.3.12.1-ose from an Android device default calender and address book should show up in DAVx5.

Current behaviour: The default calender show up but not the address book. An error can be found in the nginx log right after the attempt to update address books provided by server in DAVx5:

Feb 03 20:32:39 nginx[6550]: 2024/02/03 20:32:39 [error] 6550#6550: *1932 FastCGI sent in stderr: "PHP message: ErrorException: unserialize(): Error at offset 51 of 100 bytes in /srv/www/baikal/vendor/sabre/dav/lib/DAV/PropertyStorage/Backend/PDO.php:100
Feb 03 20:32:39 nginx[6550]: Stack trace:
Feb 03 20:32:39 nginx[6550]: #0 [internal function]: Baikal\Framework::exception_error_handler()
Feb 03 20:32:39 nginx[6550]: #1 /srv/www/baikal/vendor/sabre/dav/lib/DAV/PropertyStorage/Backend/PDO.php(100): unserialize()
Feb 03 20:32:39 nginx[6550]: #2 /srv/www/baikal/vendor/sabre/dav/lib/DAV/PropertyStorage/Plugin.php(84): Sabre\DAV\PropertyStorage\Backend\PDO->propFind()
Feb 03 20:32:39 nginx[6550]: #3 /srv/www/baikal/vendor/sabre/event/lib/WildcardEmitterTrait.php(89): Sabre\DAV\PropertyStorage\Plugin->propFind()
Feb 03 20:32:39 nginx[6550]: #4 /srv/www/baikal/vendor/sabre/dav/lib/DAV/Server.php(1052): Sabre\DAV\Server->emit()
Feb 03 20:32:39 nginx[6550]: #5 /srv/www/baikal/vendor/sabre/dav/lib/DAV/Server.php(984): Sabre\DAV\Server->getPropertiesByNode()
Feb 03 20:32:39 nginx[6550]: #6 /srv/www/baikal/vendor/sabre/dav/lib/DAV/Server.php(1662): Sabre\DAV\Server->getPropertiesIteratorForPath()
Feb 03 20:32:39 nginx[6550]: #7 /srv/www/baikal/vendor/sabre/dav/lib/DAV/Server.php(1647): Sabre\DAV\Server->writeMultiStatus()
Feb 03 20:32:39 nginx[6550]: #8 /srv/www/baikal/vendor/sabre/dav/li" while reading response header from upstream, client: ###.###.###.###, server: dav.########.###, request: "PROPFIND /dav.php/addressbooks/<USER>/ HTTP/2.0", upstream: "fastcgi://unix:/run/phpfpm/baikalpool.sock:", host: "dav.########.###"

Similar error can be found in DAVx5 log:

2024-02-03 16:26:50 475 [network.HttpClient] <-- 500 https://dav.########.###/dav.php/addressbooks/<USER>/ (39ms)
2024-02-03 16:26:50 475 [network.HttpClient] server: nginx
2024-02-03 16:26:50 475 [network.HttpClient] date: Sat, 03 Feb 2024 15:26:49 GMT
2024-02-03 16:26:50 475 [network.HttpClient] content-type: application/xml; charset=utf-8
2024-02-03 16:26:50 475 [network.HttpClient] x-powered-by: PHP/8.2.15
2024-02-03 16:26:50 475 [network.HttpClient] expires: Thu, 19 Nov 1981 08:52:00 GMT
2024-02-03 16:26:50 475 [network.HttpClient] cache-control: no-store, no-cache, must-revalidate
2024-02-03 16:26:50 475 [network.HttpClient] pragma: no-cache
2024-02-03 16:26:50 475 [network.HttpClient] x-sabre-version: 4.5.0
2024-02-03 16:26:50 475 [network.HttpClient] vary: Brief,Prefer
2024-02-03 16:26:50 475 [network.HttpClient] dav: 1, 3, extended-mkcol, access-control, calendarserver-principal-property-search, calendar-access, calendar-proxy, calendar-auto-schedule, calendar-availability, resource-sharing, calendarserver-sharing, addressbook
2024-02-03 16:26:50 475 [network.HttpClient] 
2024-02-03 16:26:50 475 [network.HttpClient] <?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:sabredav-version>4.5.0</s:sabredav-version>
  <s:exception>ErrorException</s:exception>
  <s:message>unserialize(): Error at offset 51 of 100 bytes</s:message>
</d:error>

Note: User and Domain got replaced in logs

Steps to reproduce:

  1. Install DAVx5 on Android and add a new account to an Baikal instance with an existing calender and address book. Calender as well as address book have token ID: default
Reihar commented 6 months ago

Hi @broke ! I'm just a Baikal user but I just bought a new phone and went through the same issue. The problem which needs to be addressed in Sabre (maybe you'll be redirect to open a ticket there by the dev) is that the code is using dynamic properties which are deprecated in PHP 8.2 My Arch server using 8.3 by default, I installed PHP 8.1 and associated php-fpm version and got Baikal running.

To save you some time, here are the extensions I had to manually install (as they are separate packages in my distribution). Some of them further had to be enabled in the php.ini for PHP 8.1.

phil-davis commented 6 months ago

The dynamic properties thing is dav issue https://github.com/sabre-io/Baikal/issues/1154

According to my comment https://github.com/sabre-io/Baikal/issues/1154#issuecomment-1823817051 it seems that Baikal 0.9.4 was before all the deprecated dynamic properties things were fixed and released as dav 4.5.1

So another release of Baikal is still needed to get the latest sabre/dav bundled into the release tarball.

@ByteHamster is that correct?

broke commented 6 months ago

I'm currently running NixOS 23.11 and downgraded to PHP 8.1.27 but the issue still persists. I was also trying to change files manually like mentioned here https://github.com/sabre-io/Baikal/issues/1154#issuecomment-1427028654 but no success. Is there a way to get more verbose output of what baikal is doing to get to the root of this problem?

ByteHamster commented 6 months ago

So another release of Baikal is still needed to get the latest sabre/dav bundled into the release tarball.

Yes, correct. I have been testing the upgrade for the last few weeks now, seems good to go. Will create a release.

broke commented 6 months ago

I updated baikal to version 0.9.5 and PHP version in use is 8.2.17 now, but i still receive the same exception:

15:54:33 [error] 46113#46113: *13436 FastCGI sent in stderr: "PHP message: ErrorException: unserialize(): Error at offset 51 of 100 bytes in /srv/www/baikal/vendor/sabre/dav/lib/DAV/PropertyStorage/Backend/PDO.php:100

Could it be that some contact in my SQLite is malformed from previous versions of baikal causing this issue?

broke commented 6 months ago

I poked around a little bit and what i could figure out with my lack of knowledge of PHP is: In my case i end up in this line https://github.com/sabre-io/dav/blob/da8c1f226f1c053849540a189262274ef6809d1c/lib/DAV/PropertyStorage/Backend/PDO.php#L100 when the issue occurs. From my understanding PHP tries to create an object from the data which comes from my SQLite DB. From the backtrace i see data is coming from the table propertystorage. Since this table has only one row and the value column is used to create the PHP object i can look up the serialized object in the DB. So i did. I found this value in the DB

O:27:"Sabre\DAV\Xml\Property\Href":2:{s:8:"\0*\0hrefs";a:1:{i:0;s:0:"";}s:13:"\0*\0autoPrefix";b:1;}

where deserialization fails at byte 51, so at the beginning of refs inside the curly braces. Can i modify this line to match to fix this issue?

broke commented 6 months ago

Finally. I created a new addressbook in the WebUI. This action didn't create a new line in the propertystorage table. So i deleted the existing row which causes the deserialization issue and now syncing with my phone work. I remember now that in the past i was migrating from MYSQL to SQLite with this guide https://github.com/sabre-io/Baikal/issues/647#issuecomment-1100709198 . Now i think the entry in the property storage is a leftover from this migration which triggers the issues when you try to setup a new phone with DAVx5 and scan for existing addressbooks.