Thread: LDAP access
View Single Post
  #1  
Old November 26th 08, 09:53 AM posted to microsoft.public.outlook.program_addins
Sergeichik
external usenet poster
 
Posts: 21
Default LDAP access

I'm trying to read AD(Active directory) content from Outlook addin (C++,
MAPI) by the following way:
(AD's in Outlook are represented by LDAP, and neither I nor plugin don't
know their logins or passwords, hidden somewhere in depth of Outlook internal
data)

accessing containers:
//////////////////////////////////////////////
HRESULT hr;
CComPtrIMAPISession pSess;
hr = MAPILogonEx(0, NULL, NULL, MAPI_EXTENDED|MAPI_UNICODE, &pSess);
if(FAILED(hr))
{
errorMes = _T("MAPI Logon failed.");
return false;
}
// open address book
CComPtrIAddrBook pAddr;
hr = pSess-OpenAddressBook(0, 0, 0, &pAddr);
if(FAILED(hr))
{
pSess-Logoff(0, 0, 0);
return false;
};

LPSRowSet containers;
hr = pAddr-GetSearchPath(MAPI_UNICODE , &containers);
if (hr!=S_OK)
{
pAddr.Release();
pSess-Logoff(0, 0, 0);
return false;
}

// number of folders in address book
long cont_count = containers-cRows;
if (cont_count = 0)
{
pAddr.Release();
pSess-Logoff(0, 0, 0);
return false;
}


for (int folder_number = 0; folder_number cont_count; folder_number++)
{
WCHAR tx [30];
_itow(folder_number, tx, 10);
CAtlString f_mess = _T("Processing folder number '");
f_mess += CAtlString(tx); f_mess += _T("' from address book.");


SRow* folder_row = &containers-aRow[folder_number];
if (!folder_row)
{
continue;
}

LPSPropValue lpDN_cont =
PpropFindProp(folder_row-lpProps,folder_row-cValues,PR_ENTRYID);
if (!lpDN_cont)
{
continue;
}

_PV* ContainerEntryId = NULL;
ContainerEntryId = &lpDN_cont-Value;
if (!ContainerEntryId)
{
continue;
}
ReadContainerContents(pAddr, ContainerEntryId);
}

///////////////////////////////////////////////////////////////////////////////
// reading container ..
void ReadContainerContents(CComPtrIAddrBook& pAddr, _PV* ContainerEntryId)
{

HRESULT hr = S_OK;
ULONG ulCount = NULL;
LPSRowSet pRows = NULL;
ULONG cbeid = 0L;
LPENTRYID lpeid = NULL;
LPMAPITABLE lpMAPItbl = NULL;
LPABCONT lpGAL = NULL;


if ((pAddr == NULL)||(ContainerEntryId == NULL)) return;

// SizedSPropTagArray(2, Columns) =
// {2, {PR_ENTRYID, PR_DISPLAY_TYPE}};

LPUNKNOWN lpIUnknown = NULL;
ULONG ulObjType = NULL;

if (FAILED(pAddr-OpenEntry(ContainerEntryId-bin.cb,
(LPENTRYID)ContainerEntryId-bin.lpb, NULL, MAPI_BEST_ACCESS,
&ulObjType, (LPUNKNOWN*)&lpIUnknown)))
{
return;
}

//See if it is an address book container
// If no, return ...
if (ulObjType != MAPI_ABCONT))
{
return;
}


ULONG ulFlags = NULL;
IABContainer* lpABContainer = static_castIABContainer*(lpIUnknown);
//cast the IUnknown pointer returned from previous function to what we need
hr = lpABContainer-GetContentsTable(ulFlags, &lpMAPItbl);
// ASSERT(lpMAPItbl);
if (hr!=S_OK)
{
if (lpABContainer) lpABContainer-Release();
return;
}

ULONG ulRows; //Number of rows in the MAPI table

hr = lpMAPItbl-GetRowCount(0, &ulRows);
if (hr!=S_OK)
{
if (lpMAPItbl) lpMAPItbl-Release();
if (lpABContainer) lpABContainer-Release();
return;
}

if (ulRows = 0)
{
// MessageBox("No contacts was finded");
if (lpMAPItbl) lpMAPItbl-Release();
if (lpABContainer) lpABContainer-Release();
return;
}

// ... process here founded contacts ..

}
/////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////

But haven't any success in case of AD!!
I can read the names of AD LDAP directories(by such a way) as well as usual
local 'Address book' folders,
but if I try to read the count of contacts in them, I receive 0(zero).
Though, local folders quering return valid number of contcts (not zero) and
then I can read all of them fully.
Sure, there are some contacts in my LDAP directory exist certain and can be
viewed from the Outlook contacts book !!
And I can access them through another technology (ADO).
But need through MAPI(for example), without knowing login and password which
is already stored somewhere in Outlook and I don't authorized to know them.
Best regards, SergK.

Ads