473,320 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ldap_search objectGUID in AD

Hi all,
this is _really_ bugging me, and the Google God has failed me:

Doing an ldap_search of a Wink2k Active Directory trying to get the
objectGUID. This is a unique id within AD and is meant to be a 128bit
octal string. (16 bytes).

Works 99% of the time, but the occasional objectGUID comes up short.
e.g.

$ld_filter = '(sAMAccountName=*)';
$ld_data = array('objectGUID', 'sAMAccountName');
$ld_sr = ldap_search($Connect, $ldap_base_dn, $ld_filter);
$ld_info = ldap_get_entries($Connect, $ld_sr);
for($i=0; $i < $ld_info['count']; $i++) {
$o = $ld_info[$i]['objectguid'][0];
$len = strlen($o);
print("len: $len <br>");
}

MOST of the entries are the correct 16 bytes, a FEW are not. It's like
the occasional objectGUID is barfing php somehow and not getting placed
into the holder variable, or something. Only getting the first x bytes.

The correct entries I can convert to an escaped hex string and then
search AD correctly. The incorrect ones, can't be used.

Doing an ldap_search from the command line generates a base64 encoded
string, which I can decode, convert to hex and search properly, so it's
not the AD data.

PHP Version 4.3.2
Apache/1.3.28
Linux tnz014 2.4.18-14 #1 Wed Sep 4 11:57:57 EDT 2002 i586
ldap.c,v 1.130.2.4 2003/04/30 21:54:02 iliaa Exp $

Any ideas????

Cheers,
Alan Way
Jul 17 '05 #1
1 10208
Sacs wrote:

$ld_filter = '(sAMAccountName=*)';
$ld_data = array('objectGUID', 'sAMAccountName');
$ld_sr = ldap_search($Connect, $ldap_base_dn, $ld_filter);
$ld_info = ldap_get_entries($Connect, $ld_sr);
for($i=0; $i < $ld_info['count']; $i++) {
$o = $ld_info[$i]['objectguid'][0];
$len = strlen($o);
print("len: $len <br>");
}

MOST of the entries are the correct 16 bytes, a FEW are not. It's like
the occasional objectGUID is barfing php somehow and not getting placed
into the holder variable, or something. Only getting the first x bytes.


Solved the bugger. ldap_get_entries() handles the data as strings,
which is not good for binary data containing nulls (like the AD
objectGUID may do).

So, I need to use ldap_get_values_len() to extract the binary data :-)
e.g. to get the objectGUID of an organisation unit:

function getGUIDbyOU ($ou) {
global $ldap_base_dn, $ldap_server, $ldap_bind_d, $ldap_bind_user;

$Connect = ldap_connect($ldap_server) ;
$Bind = ldap_bind($Connect, $ldap_bin_dn, $ldap_bind_user);

$ld_filter = '(ou=' . $ou . ')';
$ld_data = array('objectGUID');
$ld_sr = ldap_search($Connect, $ldap_base_dn, $ld_filter, $ld_data);
if(ldap_count_entries($Connect, $ld_sr) > 0) {
$entry = ldap_first_entry($Connect, $ld_sr);
$guid = ldap_get_values_len($Connect, $entry, 'objectguid');
return $guid[0];
} else {
return NULL;
}
}

Thanks to anyone who bothered reading the parent :-)

Alan
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ammar | last post by:
I don't want to extend the AD schema but need the hierarchical info on some groups (objectGuids that maintain the group). So I need to store the objectGuid of groups and accounts into the...
0
by: Ryo | last post by:
Hello ! I want to do something like this: string strFilter = "SyntaxThatICantFound"; DirectoryEntry dreAD = new DirectoryEntry("LDAP://192.168.0.1", "Admin", "Admin"); DirectorySearcher drsAD...
0
by: Max | last post by:
Hi, I've got a web GUI in which users can add server IP, ldap base, username, password to enable connectivity to Active Directory. Everything works great in the connection, etc. However, if the...
0
by: Ward Germonpré | last post by:
Hi, ldap_search takes an array of attributes it is supposed to retrieve from AD. However the order in which the attributes are returned is not the same as the attributes in the array. Is...
0
by: rumich | last post by:
Hi, I have the following problem when trying to retrieve Windows 2003 AD entry (objectclass=person). <?php $ad = ldap_connect($ADhost,$ADldap_port) or die( "Could not connect!" ); $set =...
1
by: theS70RM | last post by:
Hey, Im creating an intranet and when a user logs on I use the Active Directory to validate their logon, then store the objectGUID in a session variable, which I first convert to hex using...
0
by: theS70RM | last post by:
Hey Peeps =) I have a function that returns an active directory users group membership as an array. This code is part of a bigger object, but something like: function...
5
by: macca | last post by:
Hi, I'm doing an two ldap_search queries and I need to combine the two results into one single array containing all the results from each but removing duplicates. I have tried built in php...
1
by: theS70RM | last post by:
Hi, I have a php script to retrieve data about a user from the active directory using ldap. Here's a cut down version: $domainName = "domain.com"; $serverName = "server";...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.