Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
fix(agent): fixed agent account name on enrollment process.
Browse files Browse the repository at this point in the history
  • Loading branch information
DIOHz0r authored and ajsb85 committed Nov 15, 2017
1 parent 263d036 commit dc48776
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion inc/agent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,8 @@ protected function enrollByInvitationToken($input) {
$agentAccount = new User();
$agentAccount->add([
'usercategories_id' => $config['agentusercategories_id'],
'name' => $serial,
'name' => 'flyvemdm-' . PluginFlyvemdmCommon::generateUUID(),
'realname' => $serial,
'_profiles_id' => $config['agent_profiles_id'],
'profiles_id' => $config['agent_profiles_id'], // Default profile when user logs in
'_entities_id' => $entityId,
Expand Down
25 changes: 25 additions & 0 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,29 @@ static function getEnumValues($table, $field) {
return $enum;
}

/**
* @return string pseudo-random UUID version 4
*/
public static function generateUUID() {
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',

// 32 bits for "time_low"
mt_rand(0, 0xffff), mt_rand(0, 0xffff),

// 16 bits for "time_mid"
mt_rand(0, 0xffff),

// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand(0, 0x0fff) | 0x4000,

// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand(0, 0x3fff) | 0x8000,

// 48 bits for "node"
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
}
2 changes: 1 addition & 1 deletion tests/suite-integration/PluginFlyvemdmAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function testEnrollAgent() {

// Test a new user for the agent exists
$agentUser = new \User();
$agentUser->getFromDBbyName($serial);
$agentUser->getFromDBByCrit(['realname' => $serial]);
$this->boolean($agentUser->isNewItem())->isFalse();

// Test the agent user does not have a password
Expand Down

0 comments on commit dc48776

Please sign in to comment.