I've been searching for a day now for information on why ADsEnumerateNext can fail enumerating the global catalog.
I've a client whose debug log files show me that this function is failing with S_FALSE. The code is below.
I just get a debug trace back with enumerated 0 objects.
The process is a system service, running in an account which has domain administrator privileges.
I'm wondering what the possible failure modes for this are, e.g.
1. There is nothing in the GC (is this even possible)?
2. Service does not have permission to enumerate the GC (but can connect to it?)
3. There's some referral required?
4. User is in wrong domain without proper trust relation to the forest
Any ideas to check?
IADsContainer *pCont = NULL;
HRESULT rc = ADsOpenObject( L"GC:", NULL, NULL, ADS_SECURE_AUTHENTICATION, IID_IADsContainer, (void**)&pCont);
if( S_OK == rc )
IEnumVARIANT *pEnum = NULL;
FileTrace("[*] GetIADs -> Opened IID_IADsContainer");
rc = ADsBuildEnumerator(pCont, &pEnum);
if(S_OK == hResult)
FileTrace("[*] GetIADs -> Built enumeration VARIANT");
IDispatch *pDisp = NULL;
ULONG lFetch = 0;
VariantInit( &var );
// Now enumerate. There is only one child of the GC: object.
rc = ADsEnumerateNext(pEnum, 1, &var, &lFetch);
if (( rc == S_OK ) && ( lFetch == 1 ) )
FileTrace("[*] GetIADs -> Enumerated 1 object");
pDisp = V_DISPATCH(&var);
rc = pDisp->QueryInterface( IID_IADs, (void**)&pIADS);
FileTrace("[*] GetIADs -> Enumerated %d objects (hResult: %x)",lFetch,rc);
// clean up the variant.
if (pEnum) ADsFreeEnumerator(pEnum);
FileTrace("[*] GetIADs -> ADsBuildEnumerator failed (rc: %x)", hResult);
if( pCont ) pCont->Release( );
FileTrace("[*] GetIADs -> ADsOpenObject failed (hResult: %x)", rc);