strat has asked for the wisdom of the Perl Monks concerning the following question:

Hello

For my work, I need to get a list of users from an Active Directory (Win2003) including a lot of subdomains and write them to an LDIF file. Well, I decided to try it with Perl and ADSI and basically it works fine.

But there is one problem: I need to convert binary attribute values (e.g. objectGUID) to hex, but I don't know how to find out if a value is binary or not.

Here are some fragments of my code, stripped down to the essentials

# $adsPath is a path to a single userobject returned by a # previous search by the global catalog, just GC:// replaced # with LDAP://, e.g. # LDAP://ADS_Server/CN=Panther\, Paul,OU=test,DC=xyz,DC=de my $object = Win32::OLE->GetObject($adsPath); unless ($object) { # ... } foreach my $attr (@$attributeList) { if (ref($object->{$attr}) eq 'ARRAY') { # ... } # if elsif (ref($object->{$attr})) { # ... } # elsif elsif (defined $object->{$attr}) { if ( ???????? ) { # binary -> print as hex-string print "$attr: ", unpack("H*", $value), "\n"; } # if else { # text -> print as text print "$attr: $value\n"; } # else } # elsif } # foreach # .....

Do you know how I can find it out with ADSI?

Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

Replies are listed 'Best First'.
Re: ADSI -> how to recognize binary attribute values
by Anonymous Monk on Dec 02, 2004 at 14:48 UTC
    What makes it a binary value or how does ADSI tell you to deal with it?

      Thank you for your reply.

      The objectGUID of an Active Directory user (as well as some other attributes like userCert(ificate), password, ...) is defined in the Schema as Octett which may contain non printable chars (e.g. A+§R9Ð?@½!í+Å?ÐR).

      If I look it up in the schema with ADSI, I don't know yet on how to read the format of an attribute. With the following code I can access the schema, but only know the properties of mandatory and optional attributes.

      # $adsPath is the path to a user object my $object = Win32::OLE->GetObject($adsPath) or die "..."; my $schemaObj = Win32::OLE->GetObject($object->{Schema}) or die "..."; my @mandatoryAttributes = $schemaObj->{MandatoryProperties}; my @optionalAttributes = $schemaObj->{OptionalProperties};

      If I could get the format for an attribute, I could as well find out if it is binary or not

      Best regards,
      perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"