receiving corrupted GUID from LDAP server

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello,
I have the following code that gets the current users GUID and then uses that to bind to the LDAP server,
<pre class="prettyprint int checkCurrentUserWithLDAP()
{
TCHAR buff[100];
char ldapTail[] = ";
char ldap[512];

unsigned long buffSize = 1024;
IADs *pADs;
BSTR bstr = NULL;

GetUserNameEx(NameUniqueId, buff, &buffSize);
printf("Active users GUID is: %sn",buff);

removeChar({,buff);
removeChar(},buff);

sprintf(ldap,"LDAP://myDomain/<guid=%s>",buff);
HRESULT hr = CoInitialize(NULL);
if (hr != S_OK)
{
showError(hr);
return 0;
}

wchar_t *wtext = (wchar_t*)malloc((strlen(ldap)+1)*sizeof(wchar_t));
mbstowcs(wtext, ldap, strlen(ldap)+1);
printf("nGetting current active users infomation from LDAP servern");

hr = ADsGetObject(wtext, IID_IADs, (void**)&pADs);
if (hr !=S_OK)
{
showError(hr);
return 0;
}

if( S_OK == pADs->get_GUID(&bstr)) {
printf("AD guid: %Sn",bstr);
}
SysFreeString(bstr);

// Clean-up
if ( pADs )
{
pADs->Release();
}
free(wtext);
CoUninitialize();

return 1;
}[/code]

The out put is this:
<pre class="prettyprint Active users GUID is: {a6788430-a47a-41e7-bc69-a3ad76824cc3}

Getting current active users infomation from LDAP server
AD guid: 308478a67aa4e741bc69a3ad76824cc3
[/code]
<br/>
as it can be seen the first 16 characters are corrupted. Does any one know why?

thanks,
Ehsan


View the full article
 
Back
Top