Perl: SID のバイナリ→テキスト変換

Active Directory から取得したバイナリ形式の SID をテキスト形式に変換する方法。 下記の $entryNet::LDAP::Entry オブジェクト。

my $sid_bin = $entry->get_value('objectSid');
my ($sid_rev, $sid_sub_auths_num, $sid_reserved, $sid_id_auth, @sid_sub_auths) =
  unpack('C2nNV*', $sid_bin);
my $sid = sprintf(
  'S-%u-%u' . '-%u' x $sid_sub_auths_num,
  $sid_rev, $sid_id_auth, @sid_sub_auths
);

2009-07-10: コードを修正。 SID テキストの 3 番目の文字は subauthority の数 ($sid_sub_auths_num) ではなく identifiter-authority ($sid_id_auth) だった。

add to hatena hatena.comment (0) add to del.icio.us (0) add to livedoor.clip (0) add to Yahoo!Bookmark (0) Total: 0

コメントを書く

Your email is never shared. * 印の項目は必須項目です。

*
*