Skip to content

Commit

Permalink
Look up nextcloud instance based off SRV
Browse files Browse the repository at this point in the history
This change allows a federated user/share to be added using a hostname
different to the real hostname of the nextcloud server.

This is useful in cases where a cloud is on a different domain to an
email address as it will allow users to share directly with the email
address and have it resolve to the nextcloud user.

For example, if somebody has the email address 'me@example.com', and
a nextcloud instance at 'cloud.example.com', this change will resolve
the federated user to 'me@cloud.example.com'.

This requires the username to be the same as the email address prefix.
It also requires an appropriate _nextcloud._tcp SRV record.

Related issue: nextcloud#365

Signed-off-by: Joshua Hesketh <josh@nitrotech.org>
  • Loading branch information
jhesketh committed May 2, 2018
1 parent 49f26d1 commit 023970c
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/private/Federation/CloudId.php
Expand Up @@ -44,7 +44,7 @@ class CloudId implements ICloudId {
public function __construct(string $id, string $user, string $remote) {
$this->id = $id;
$this->user = $user;
$this->remote = $remote;
$this->remote = $this->getHostname($remote);
}

/**
Expand Down Expand Up @@ -77,4 +77,30 @@ public function getUser(): string {
public function getRemote(): string {
return $this->remote;
}

/**
* The real hostname of the server
*
* @param string $remote
* @return string
*/
public function getHostname(string $remote): string {
// Check for srv record
$srv_prefix = '_nextcloud._tcp.';
$rec = \dns_get_record($srv_prefix . $remote, \DNS_SRV);
if (!empty($rec)) {
// TODO(jhesketh): Handle weight & ports etc
if (empty($rec[0]['target'])) {
return $remote;
}
else {
return $rec[0]['target'];
}
}

// TODO: Optionally, or alternatively, support checking a TXT record.
// TODO: Optionally, or alternatively, check for .well-known record
// Default to given remote:
return $remote;
}
}

0 comments on commit 023970c

Please sign in to comment.