2016-09-16 4 views
1

私はADのユーザ一意識別子(SID)を取得する方法がわかりません。コードフラグメント:私は0�@�d^�WL7�U ようsecoundなも​​ので、ユーザー名を見ることができる最初の出力でPHP LDAP取得ユーザSID

echo $this->info[0]["cn"][0]; 

または

echo $this->info[0]["objectsid"][0]; 

は、私はSIDがあるべきと考えている:私は情報を引き出すことができ

...  
$filter="(&(samaccountname=".$this->username.")(memberOf:1.2.840.113556.1.4.1941:=CN=GROUP_NAME,OU=Security,DC=something,DC=something))"; 
    $attribute = array("cn","objectsid","description", "group", "member", "samaccountname"); 
    $sr=ldap_search($this->conn_ldap, $this->ldap_dn, $filter, $attribute); 

    if ($sr) 
    { 

    $this->info = ldap_get_entries($this->conn_ldap, $sr); 
    if ($this->info["count"] == 1){ 

    ldap_close($this->conn_ldap); 
    return true; 
    } 
    ... 

S-......のように?

+0

最初の2つのリンクのPHP LDAPは、SIDを取得する "試してみる価値はいくつかのコード投げる:http://php.net/manual/en/function.ldap-get-values-lenを。 php(derek dot ethierのコメントを参照)&http://l3rady.com/index.html%3Fp=435.html –

+0

'' $ attributes'''配列に "+"を追加して、結果は次にあります。それはいくつかの追加情報を明らかにするかもしれない。 – heiglandreas

答えて

2

他のウェブサイト(下記参照)に解決策が見つかりました。 は、基本的に、この関数は変換器であり、SIDが見えるように:

public static function SIDtoString($ADsid) 
{ 
    $sid = "S-"; 
    //$ADguid = $info[0]['objectguid'][0]; 
    $sidinhex = str_split(bin2hex($ADsid), 2); 
    // Byte 0 = Revision Level 
    $sid = $sid.hexdec($sidinhex[0])."-"; 
    // Byte 1-7 = 48 Bit Authority 
    $sid = $sid.hexdec($sidinhex[6].$sidinhex[5].$sidinhex[4].$sidinhex[3].$sidinhex[2].$sidinhex[1]); 
    // Byte 8 count of sub authorities - Get number of sub-authorities 
    $subauths = hexdec($sidinhex[7]); 
    //Loop through Sub Authorities 
    for($i = 0; $i < $subauths; $i++) { 
     $start = 8 + (4 * $i); 
     // X amount of 32Bit (4 Byte) Sub Authorities 
     $sid = $sid."-".hexdec($sidinhex[$start+3].$sidinhex[$start+2].$sidinhex[$start+1].$sidinhex[$start]); 
    } 
    return $sid; 
} 

https://www.null-byte.org/development/php-active-directory-ldap-authentication/

1

別の例として、これは完全にPHPのアンパック機能を用いて行うことができます。するobjectSIDバイナリ構造は、最良this MSDN docに記載されて:

リビジョン(1バイト):SIDの リビジョンレベルを指定する8ビットの符号なし整数。この値は0x01に設定しなければなりません。

SubAuthorityCount(1バイト): サブ機関の配列内の要素の数を指定する8ビットの符号なし整数。 SIDが作成された権限を示すSID_IDENTIFIER_AUTHORITY構造 :許容要素の最大数は15

IdentifierAuthority(6バイト)あります。 は、SIDを作成したエンティティを表します。 Identifier Authority 値{0,0,0,0,0,5}は、NT SID権限によって作成されたSIDを示します。

サブ機関(可変)一意 IdentifierAuthorityに主相対を識別する符号なし32ビット 整数の可変長配列。その長さはSubAuthorityCountによって決まります。以下のためにグーグルから

/** 
* Decode the binary SID into its readable form. 
* 
* @param string $value 
* @return string 
*/ 
function decodeSID($value) 
{ 
    # revision - 8bit unsigned int (C1) 
    # count - 8bit unsigned int (C1) 
    # 2 null bytes 
    # ID - 32bit unsigned long, big-endian order 
    $sid = @unpack('C1rev/C1count/x2/N1id', $value); 
    $subAuthorities = []; 

    if (!isset($sid['id']) || !isset($sid['rev'])) { 
     throw new \UnexpectedValueException(
      'The revision level or identifier authority was not found when decoding the SID.' 
     ); 
    } 

    $revisionLevel = $sid['rev']; 
    $identifierAuthority = $sid['id']; 
    $subs = isset($sid['count']) ? $sid['count'] : 0; 

    // The sub-authorities depend on the count, so only get as many as the count, regardless of data beyond it 
    for ($i = 0; $i < $subs; $i++) { 
     # Each sub-auth is a 32bit unsigned long, little-endian order 
     $subAuthorities[] = unpack('V1sub', hex2bin(substr(bin2hex($value), 16 + ($i * 8), 8)))['sub']; 
    } 

    # Tack on the 'S-' and glue it all together... 
    return 'S-'.$revisionLevel.'-'.$identifierAuthority.implode(
     preg_filter('/^/', '-', $subAuthorities) 
    ); 
} 
関連する問題