From 2da730dd3e1b7b33d66383ceeb1f38ecf1bdaf83 Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Thu, 25 Jun 2026 13:31:02 -0400 Subject: [PATCH] feat: improve dns record discovery Signed-off-by: SebastianKrupinski --- .github/workflows/phpunit-test.yml | 3 ++- lib/Service/CoreService.php | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.github/workflows/phpunit-test.yml b/.github/workflows/phpunit-test.yml index 54b6ff2..7836e5c 100644 --- a/.github/workflows/phpunit-test.yml +++ b/.github/workflows/phpunit-test.yml @@ -349,7 +349,8 @@ jobs: listen-address=127.0.0.1 bind-interfaces resolv-file=/etc/dnsmasq-upstream-resolv.conf - address=/${{ env.DAV_DOMAIN }}/127.0.0.1 + local=/${{ env.DAV_DOMAIN }}/ + host-record=${{ env.DAV_DOMAIN }},127.0.0.1 srv-host=_caldav._tcp.${{ env.DAV_DOMAIN }},${{ env.DAV_HOST }},10080,0,0 EOF diff --git a/lib/Service/CoreService.php b/lib/Service/CoreService.php index 94c9fdd..3943d59 100644 --- a/lib/Service/CoreService.php +++ b/lib/Service/CoreService.php @@ -64,15 +64,41 @@ public function locateAccount(array $configuration): ?array { } // find dns service records if (empty($configuration['location_host'])) { - $dns = dns_get_record('_caldavs._tcp.' . $identityDomain, DNS_SRV); + // attempt to locate service host and port using dns srv records + // example: _caldavs._tcp.example.com. IN SRV 0 5 443 dav.example.com. + $dnsService = '_caldavs._tcp.' . $identityDomain; + $dns = dns_get_record($dnsService, DNS_SRV); if (empty($dns)) { - $dns = dns_get_record('_caldav._tcp.' . $identityDomain, DNS_SRV); + $dnsService = '_caldav._tcp.' . $identityDomain; + $dns = dns_get_record($dnsService, DNS_SRV); + } + if (empty($dns)) { + $dnsService = '_carddavs._tcp.' . $identityDomain; + $dns = dns_get_record($dnsService, DNS_SRV); + } + if (empty($dns)) { + $dnsService = '_carddav._tcp.' . $identityDomain; + $dns = dns_get_record($dnsService, DNS_SRV); } if (!empty($dns) && ($dns[0]['type'] ?? null) === 'SRV') { $dnsTarget = $dns[0]['target']; $dnsPort = $dns[0]['port']; $configuration['location_host'] = $dnsTarget; $configuration['location_port'] = $dnsPort; + // attempt to locate service path using dns txt records + // example: _caldavs._tcp.example.com. IN TXT "path=/dav/" + if (empty($configuration['location_path'])) { + $dnsTxt = dns_get_record($dnsService, DNS_TXT); + foreach (is_array($dnsTxt) ? $dnsTxt : [] as $record) { + if (($record['type'] ?? null) !== 'TXT') { + continue; + } + if (preg_match('/(?:^|\s)path=(\S+)/', $record['txt'] ?? '', $matches) === 1) { + $configuration['location_path'] = $matches[1]; + break; + } + } + } } } // find template for dns service target