Getting user info from LDAP with GUID

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have this piece of code, in C/C++.
<br/>
<br/>
IADs *pADsGUID,*pADs;<br/>
BSTR bstr;<br/>
char buffer[101];<br/>
<br/>
<br/>
HRESULT hr = CoInitialize(NULL);<br/>
if (hr != S_OK) { return 0; }<br/>
<br/>
<span class="x_Apple-tab-span" style="white-space:pre //get GUID from local PC <br/>
<span class="x_Apple-tab-span" style="white-space:pre hr=ADsGetObject(L"WinNT://mydomain/me", IID_IADs, (void**) &pADs); <br/>
if (hr != S_OK) <br/>
<span class="x_Apple-tab-span" style="white-space:pre { <br/>
<span class="x_Apple-tab-span" style="white-space:pre printf("failed to getn");<br/>
<span class="x_Apple-tab-span" style="white-space:pre return 0; <br/>
<span class="x_Apple-tab-span" style="white-space:pre }<br/>
<br/>
if( S_OK == pADs->get_ADsPath(&bstr)) {<br/>
<span class="x_Apple-tab-span" style="white-space:pre printf("Object first AD Path: %Sn",bstr);<span class="x_Apple-tab-span" style="white-space:pre
<br/>
<span class="x_Apple-tab-span" style="white-space:pre }<br/>
if( S_OK == pADs->get_GUID(&bstr)) {<br/>
<span class="x_Apple-tab-span" style="white-space:pre printf("Object GUID: %Sn",bstr);<span class="x_Apple-tab-span" style="white-space:pre
<br/>
<span class="x_Apple-tab-span" style="white-space:pre }<br/>
<br/>
<span class="x_Apple-tab-span" style="white-space:pre //MUST FIND A BETTER WAY <br/>
<span class="x_Apple-tab-span" style="white-space:pre char pszFilter[100] = "LDAP://mydomain/";<br/>
sprintf(buffer,"%S",bstr);<br/>
<span class="x_Apple-tab-span" style="white-space:pre printf("buffer %sn",buffer);<br/>
<span class="x_Apple-tab-span" style="white-space:pre unsigned int i = 0;<br/>
for(i = 0; i < strlen(buffer); ++i){<br/>
<span class="x_Apple-tab-span" style="white-space:pre if (buffer == {){ buffer = <; }<br/>
<span class="x_Apple-tab-span" style="white-space:pre if (buffer == }){ buffer = >; }<br/>
}<br/>
<span class="x_Apple-tab-span" style="white-space:pre printf("buffer %sn",buffer);<br/>
<span class="x_Apple-tab-span" style="white-space:pre strcat(pszFilter, buffer);<span class="x_Apple-tab-span" style="white-space:pre
<br/>
<br/>
<span class="x_Apple-tab-span" style="white-space:pre //get infor from LDAP<br/>
//hr = ADsGetObject((LPWSTR) pszFilter, IID_IADs, (void**)&pADsGUID);<br/>
<span class="x_Apple-tab-span" style="white-space:pre hr = ADsGetObject(L"LDAP://myDomain/<GUID=D83F1060-1E71-11CF-B1F3-02608C9E7553>", IID_IADs, (void**)&pADsGUID);<br/>
<span class="x_Apple-tab-span" style="white-space:pre <br/>
<span class="x_Apple-tab-span" style="white-space:pre if (hr !=S_OK) {printf("can not connect to LDPAn");return 0;}<span class="x_Apple-tab-span" style="white-space:pre
<br/>
<br/>
<br/>
<span class="x_Apple-tab-span" style="white-space:pre if( S_OK == pADsGUID->get_Name(&bstr)) {<br/>
<span class="x_Apple-tab-span" style="white-space:pre printf("Object Name: %Sn",bstr);<span class="x_Apple-tab-span" style="white-space:pre
<br/>
<span class="x_Apple-tab-span" style="white-space:pre }<br/>
if( S_OK == pADsGUID->get_ADsPath(&bstr)) {<br/>
<span class="x_Apple-tab-span" style="white-space:pre printf("AD path: %Sn",bstr);<span class="x_Apple-tab-span" style="white-space:pre
<br/>
<span class="x_Apple-tab-span" style="white-space:pre }<br/>
<br/>
<br/>
<span class="x_Apple-tab-span" style="white-space:pre if (pADs)<br/>
<span class="x_Apple-tab-span" style="white-space:pre {<br/>
<span class="x_Apple-tab-span" style="white-space:pre pADs->Release();<br/>
<span class="x_Apple-tab-span" style="white-space:pre }<br/>
<br/>
<br/>
CoUninitialize();<br/>
<br/>
<br/>
<br/>
<br/>
I first get my GUID with
<pre class="prettyprint hr=ADsGetObject(L"WinNT://mydomain/me", IID_IADs, (void**) &pADs); [/code]
and afterwards send the GUID to the LDPA server to get the users info.
This , however, does not work and I can not connect to the LDPA server with the GUID. So my questions are
1- Am I doing something wrong?
2- How should I use the GUID to get users info, need the user group.
3- and can anyone show me a better way to add the GUID to the LDPA string, this is how Im doing it now
<pre class="prettyprint //MUST FIND A BETTER WAY
char pszFilter[100] = "LDAP://mydomain/";
sprintf(buffer,"%S",bstr);
printf("buffer %sn",buffer);
unsigned int i = 0;
for(i = 0; i < strlen(buffer); ++i){
if (buffer == {){ buffer = <; }
if (buffer == }){ buffer = >; }
}[/code]

Thanks,
Ehsan
<br/>
<br/>

View the full article
 

Similar threads

A
Replies
0
Views
158
ANIL AYDINALP
A
D
Replies
0
Views
97
Donald Uko
D
D
Replies
0
Views
101
Donald Uko
D
Back
Top