diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2019-09-19 15:07:06 +0300 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2019-09-19 15:07:06 +0300 |
commit | c839dc1e73fe10c20e44c2c80347d67480c6efb1 (patch) | |
tree | 763c1dee99d6a09a4f353b4094849ba356e76d43 /lib/UserBackend.php | |
parent | 1d0a8a7f1fa9a5a9827eb1a0b105ad843e42e695 (diff) |
decode objectGUID to their ASCII representation if
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib/UserBackend.php')
-rw-r--r-- | lib/UserBackend.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/UserBackend.php b/lib/UserBackend.php index d421002a..ba0cb955 100644 --- a/lib/UserBackend.php +++ b/lib/UserBackend.php @@ -691,4 +691,46 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { } } } + + /** + * returns the plain text UUID if the provided $uid string is a + * base64-encoded binary string representing e.g. the objectGUID. Otherwise + * + */ + public function testEncodedObjectGUID(string $uid): string { + $candidate = base64_decode($uid, true); + if($candidate === false) { + return $uid; + } + $candidate = $this->convertObjectGUID2Str($candidate); + // the regex only matches the structure of the UUID, not its semantic + // (i.e. version or variant) simply to be future compatible + if(preg_match('/^[a-f0-9]{8}(-[a-f0-9]{4}){4}[a-f0-9]{8}$/i', $candidate) === 1) { + $uid = $candidate; + } + return $uid; + } + + /** + * @see \OCA\User_LDAP\Access::convertObjectGUID2Str + */ + public function convertObjectGUID2Str($oguid) { + $hex_guid = bin2hex($oguid); + $hex_guid_to_guid_str = ''; + for($k = 1; $k <= 4; ++$k) { + $hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2); + } + $hex_guid_to_guid_str .= '-'; + for($k = 1; $k <= 2; ++$k) { + $hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2); + } + $hex_guid_to_guid_str .= '-'; + for($k = 1; $k <= 2; ++$k) { + $hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2); + } + $hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4); + $hex_guid_to_guid_str .= '-' . substr($hex_guid, 20); + + return strtoupper($hex_guid_to_guid_str); + } } |