asdasd
This commit is contained in:
42
src/App/RegistrationIdentityAllocator.php
Normal file
42
src/App/RegistrationIdentityAllocator.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App;
|
||||
|
||||
final class RegistrationIdentityAllocator
|
||||
{
|
||||
private JsonStore $store;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $config
|
||||
*/
|
||||
public function __construct(
|
||||
string $storagePath,
|
||||
private readonly array $config,
|
||||
) {
|
||||
$this->store = new JsonStore($storagePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{uid_number: string, gid_number: string, samba_sid: string}
|
||||
*/
|
||||
public function allocate(): array
|
||||
{
|
||||
$payload = $this->store->read();
|
||||
$nextUid = (int) ($payload['next_uid_number'] ?? ($this->config['ldap']['uid_number_start'] ?? 1000010));
|
||||
$nextRid = (int) ($payload['next_samba_rid'] ?? ($this->config['ldap']['samba_rid_start'] ?? 1025));
|
||||
$gidNumber = (int) ($this->config['ldap']['gid_number_default'] ?? 1000012);
|
||||
$domainSid = trim((string) ($this->config['ldap']['samba_domain_sid'] ?? ''));
|
||||
|
||||
$payload['next_uid_number'] = $nextUid + 1;
|
||||
$payload['next_samba_rid'] = $nextRid + 1;
|
||||
$this->store->write($payload);
|
||||
|
||||
return [
|
||||
'uid_number' => (string) $nextUid,
|
||||
'gid_number' => (string) $gidNumber,
|
||||
'samba_sid' => $domainSid !== '' ? $domainSid . '-' . $nextRid : '',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user