Skip to content

Instantly share code, notes, and snippets.

@blizzz
Created January 28, 2015 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blizzz/101e17cdc1d399031b50 to your computer and use it in GitHub Desktop.
Save blizzz/101e17cdc1d399031b50 to your computer and use it in GitHub Desktop.
Returns intermediate results on resolving a user's primary group
#!/usr/bin/php
<?php
use OCA\user_ldap\lib\FilesystemHelper;
use OCA\user_ldap\lib\LDAP;
use OCA\user_ldap\lib\LogWrapper;
use OCA\User_LDAP\lib\user\Manager;
use OCA\User_LDAP\lib\Access;
use OCA\User_LDAP\lib\Connection;
require_once 'lib/base.php';
class PrimGrTest extends \OCA\User_LDAP\GROUP_LDAP {
protected $userDN;
public function __construct($userDN, $configPrefix) {
$this->userDN = $userDN;
parent::__construct($this->getAccess($configPrefix));
}
public function run() {
$pGID = $this->getUserPrimaryGroupIDs($this->userDN);
print("User Primary Group ID is: " . $pGID . PHP_EOL);
$domainDN = $this->access->getDomainDNFromDN($this->userDN);
print("The DN of the domain is: " . $domainDN . PHP_EOL);
$sID = $this->access->getSID($this->userDN);
print("The SID of the domain is: " . $sID . PHP_EOL);
print("The object SID should be: " . $sID . '-' . $pGID . PHP_EOL);
$filter = 'objectsid=' . $sID . '-' . $pGID;
$result = $this->access->searchGroups($filter, array('dn'), 1);
if(is_array($result) && isset($result[0])) {
print("VERY GOOD: The group DN is: " . $result[0] . PHP_EOL);
} else {
print("NOT GOOD: cannot determine group dn" . PHP_EOL);
}
}
/**
* @param string $configPrefix
* @return Access
*/
private function getAccess($configPrefix) {
$ocConfig = \OC::$server->getConfig();
$fs = new FilesystemHelper();
$log = new LogWrapper();
$avatarM = \OC::$server->getAvatarManager();
$ldap = new LDAP();
$userManager =
new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image());
$connector = new Connection($ldap, $configPrefix);
return new Access($connector, $ldap, $userManager);
}
}
if($argc < 2) {
print('Usage: php -f ' . $argv[0] . ' UserDN [ConfigPrefix]' . PHP_EOL);
die;
}
$userDN = $argv[1];
$cfgPrf = isset($argv[2]) ? $argv[2] : "";
$test = new PrimGrTest($userDN, $cfgPrf);
$test->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment