本文整理汇总了C++中IADs类的典型用法代码示例。如果您正苦于以下问题:C++ IADs类的具体用法?C++ IADs怎么用?C++ IADs使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IADs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetI
// @pymethod object|PyIADs|Get|Description of Get.
// @rdesc The result is a Python object converted from a COM variant. It
// may be an array, or any types supported by COM variant.
PyObject *PyIADs::Get(PyObject *self, PyObject *args)
{
IADs *pIAD = GetI(self);
if ( pIAD == NULL )
return NULL;
VARIANT val;
VariantInit(&val);
// @pyparm <o PyUnicode>|prop||The name of the property to fetch
PyObject *obbstrName;
BSTR bstrName;
if ( !PyArg_ParseTuple(args, "O:Get", &obbstrName) )
return NULL;
BOOL bPythonIsHappy = TRUE;
if (bPythonIsHappy && !PyWinObject_AsBstr(obbstrName, &bstrName)) bPythonIsHappy = FALSE;
if (!bPythonIsHappy) return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIAD->Get( bstrName, &val );
SysFreeString(bstrName);
PY_INTERFACE_POSTCALL;
if ( FAILED(hr) )
return PyCom_BuildPyException(hr, pIAD, IID_IADs );
PyObject *ret = PyCom_PyObjectFromVariant(&val);
{
PY_INTERFACE_PRECALL;
VariantClear(&val);
PY_INTERFACE_POSTCALL;
}
return ret;
}
示例2: PrintAllObjects
HRESULT PrintAllObjects(IADsContainer* pContainer)
{
HRESULT hr;
if(NULL == pContainer)
{
return E_INVALIDARG;
}
IEnumVARIANT *pEnum = NULL;
// Create an enumerator object in the container.
hr = ADsBuildEnumerator(pContainer, &pEnum);
if(SUCCEEDED(hr))
{
VARIANT var;
ULONG ulFetched = 0L;
// Get the next contained object.
while(S_OK == (hr = ADsEnumerateNext(pEnum, 1, &var, &ulFetched)) && (ulFetched > 0))
{
IADs *pADs;
// Print the object
hr = V_DISPATCH(&var)->QueryInterface(IID_IADs, (void**)&pADs);
if(SUCCEEDED(hr))
{
CComBSTR sbstr;
IADsContainer *pChildContainer;
hr = pADs->get_Name(&sbstr);
if(SUCCEEDED(hr))
{
wprintf(sbstr);
wprintf(L"\n");
}
hr = pADs->QueryInterface(IID_IADsContainer, (void**)&pChildContainer);
if(SUCCEEDED(hr))
{
// If the retrieved object is a container, recursively print its contents as well.
PrintAllObjects(pChildContainer);
}
pADs->Release();
}
// Release the VARIANT.
VariantClear(&var);
}
ADsFreeEnumerator(pEnum);
}
return hr;
}
示例3: UpdateData
void CDlgIADs::OnSchemaPath()
{
HRESULT hr;
UpdateData(TRUE); // Retrieve from UI
USES_CONVERSION;
IUnknown *pUnk;
IADs *pADs;
BSTR bstr;
CWaitCursor wait;
hr = App->ADsOpenObject( T2OLE( m_sSchema ), IID_IADs, (void**) &pADs );
RETURN_ON_FAILURE(hr);
hr = pADs->get_Parent( &bstr );
pADs->Release();
RETURN_ON_FAILURE(hr);
hr = App->ADsOpenObject( bstr, IID_IUnknown, (void**) &pUnk );
SysFreeString( bstr );
/////////////////////////////////////
// Bring up the IADsContainer Dialog
///////////////////////////////////////
if ( SUCCEEDED(hr) )
{
pUnk->AddRef();
CDlgIADsContainer dlg( pUnk, this );
dlg.DoModal();
pUnk->Release();
}
}
示例4: main
int main(int argc, char* argv[])
{
HRESULT hr;
CoInitialize(NULL);
IADsContainer *pCont=NULL;
hr = ADsGetObject(L"LDAP://DC=mydomain2,DC=mydomain1,DC=microsoft,DC=com",
IID_IADsContainer,
(void**) &pCont );
RETURN_ON_FAILURE(hr);
/////////////////////////////////////////////////////////////
// Get the child from the container
// Note in the LDAP provider you can go down more than one level
///////////////////////////////////////////////////////////////
IDispatch *pDisp = NULL;
IADs *pADs = NULL;
hr = pCont->GetObject(L"user", L"CN=Mike Smith, OU=myou1", &pDisp );
pCont->Release();
RETURN_ON_FAILURE(hr);
hr = pDisp->QueryInterface( IID_IADs, (void**) &pADs );
pDisp->Release();
RETURN_ON_FAILURE(hr);
// ... do something with pADs here .
pADs->Release();
CoUninitialize();
return 0;
}
示例5: PyIADs_getattro
PyObject* PyIADs_getattro(PyObject *ob, PyObject *obname)
{
char *name = PYWIN_ATTR_CONVERT(obname);
if (!name) return NULL;
IADs *p = PyIADs::GetI(ob);
// These are all BSTR values
BSTR ret = NULL;
HRESULT hr;
BOOL bad = FALSE;
Py_BEGIN_ALLOW_THREADS
// docs refer to 'property' as AdsPath, but function is ADsPath
// allow both
// @prop <o PyUnicode>|ADsPath|
// @prop <o PyUnicode>|AdsPath|Synonym for ADsPath
if (strcmp(name, "AdsPath")==0 || strcmp(name, "ADsPath")==0)
hr = p->get_ADsPath(&ret);
// @prop <o PyUnicode>|Class|
else if (strcmp(name, "Class")==0)
hr = p->get_Class(&ret);
// @prop <o PyUnicode>|GUID|Like the IADs method, this returns a string rather than a GUID object.
else if (strcmp(name, "GUID")==0)
hr = p->get_GUID(&ret);
// @prop <o PyUnicode>|Name|
else if (strcmp(name, "Name")==0)
hr = p->get_Name(&ret);
// @prop <o PyUnicode>|Parent|
else if (strcmp(name, "Parent")==0)
hr = p->get_Parent(&ret);
// @prop <o PyUnicode>|Schema|
else if (strcmp(name, "Schema")==0)
hr = p->get_Schema(&ret);
else
bad = TRUE;
Py_END_ALLOW_THREADS
if (bad)
return PyIBase::getattro(ob, obname);
if (FAILED(hr))
return PyCom_BuildPyException(hr, p, IID_IADs );
PyObject *rc = MakeBstrToObj(ret);
SysFreeString(ret);
return rc;
}
示例6: CUGP
LDAPAUTH_API
BOOL CUGP(char * userin,char *password,char *machine, char * groupin,int locdom)
{
OSVERSIONINFO ovi = { sizeof ovi };
GetVersionEx( &ovi );
if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT &&
ovi.dwMajorVersion >= 5 )
{
//Handle the command line arguments.
LPOLESTR pszBuffer = new OLECHAR[MAX_PATH*2];
LPOLESTR pszBuffer2 = new OLECHAR[MAX_PATH*2];
LPOLESTR pszBuffer3 = new OLECHAR[MAX_PATH*2];
LPOLESTR pszBuffer4 = new OLECHAR[MAX_PATH*2];
mbstowcs( (wchar_t *) pszBuffer, userin, MAX_PATH );
mbstowcs( (wchar_t *) pszBuffer2, password, MAX_PATH );
mbstowcs( (wchar_t *) pszBuffer3, machine, MAX_PATH );
mbstowcs( (wchar_t *) pszBuffer4, groupin, MAX_PATH );
HRESULT hr = S_OK;
//Get rootDSE and the domain container's DN.
IADs *pObject = NULL;
IADs *pObjectUser = NULL;
IADs *pObjectGroup = NULL;
IDirectorySearch *pDS = NULL;
LPOLESTR szPath = new OLECHAR[MAX_PATH];
LPOLESTR myPath = new OLECHAR[MAX_PATH];
VARIANT var;
wcscpy(szPath,L"LDAP://");
wcscat(szPath,L"rootDSE");
wprintf(szPath);
wprintf(L"\n");
hr = ADsOpenObject(szPath,
pszBuffer,
pszBuffer2,
ADS_SECURE_AUTHENTICATION, //Use Secure Authentication
IID_IADs,
(void**)&pObject);
if (FAILED(hr))
{
wprintf(L"Bind to domain failed %i\n",hr);
if (pObject) pObject->Release();
delete [] pszBuffer;
delete [] pszBuffer2;
delete [] pszBuffer3;
delete [] pszBuffer4;
delete [] szPath;
delete [] myPath;
return false;
}
hr = pObject->Get(L"defaultNamingContext",&var);
if (SUCCEEDED(hr))
{
wcscpy(szPath,L"LDAP://");
wcscat(szPath,var.bstrVal);
VariantClear(&var);
if (pObject)
{
pObject->Release();
pObject = NULL;
}
wprintf( szPath);
wprintf(L"\n");
//Bind to the root of the current domain.
hr = ADsOpenObject(szPath,pszBuffer,pszBuffer2,
ADS_SECURE_AUTHENTICATION,IID_IDirectorySearch,(void**)&pDS);
if (SUCCEEDED(hr))
{
if (SUCCEEDED(hr))
{
hr = FindUserByName(pDS, pszBuffer, &pObjectUser);
if (FAILED(hr))
{
wprintf(L"User not found %i\n",hr);
delete [] pszBuffer;
delete [] pszBuffer2;
delete [] pszBuffer3;
delete [] szPath;
delete [] myPath;
if (pDS) pDS->Release();
if (pObjectUser) pObjectUser->Release();
return false;
}
if (pObjectUser) pObjectUser->Release();
///////////////////// VNCACCESS
hr = FindGroup(pDS, pszBuffer, &pObjectGroup,pszBuffer4);
if (pObjectGroup)
{
pObjectGroup->Release();
pObjectGroup = NULL;
}
if (FAILED(hr)) wprintf(L"group not found\n");
if (SUCCEEDED(hr))
{
wprintf(L"Group found OK\n");
IADsGroup * pIADsG;
hr = ADsOpenObject( gbsGroup,pszBuffer, pszBuffer2,
ADS_SECURE_AUTHENTICATION,IID_IADsGroup, (void**) &pIADsG);
//.........这里部分代码省略.........
示例7: RecursiveIsMember
BOOL RecursiveIsMember(IADsGroup * pADsGroup,LPWSTR pwszMemberGUID,LPWSTR pwszMemberPath,
BOOL bVerbose, LPOLESTR pwszUser, LPOLESTR pwszPassword)
{
HRESULT hr = S_OK; // COM Result Code
IADsMembers * pADsMembers = NULL; // Ptr to Members of the IADsGroup
BOOL fContinue = TRUE; // Looping Variable
IEnumVARIANT * pEnumVariant = NULL; // Ptr to the Enum variant
IUnknown * pUnknown = NULL; // IUnknown for getting the ENUM initially
VARIANT VariantArray[FETCH_NUM]; // Variant array for temp holding returned data
ULONG ulElementsFetched = NULL; // Number of elements retrieved
BSTR bsGroupPath = NULL;
BOOL bRet = FALSE;
if(!pADsGroup || !pwszMemberGUID || !pwszMemberPath)
{
return FALSE;
}
// Get the path of the object passed in
hr = pADsGroup->get_ADsPath(&bsGroupPath);
if (!SUCCEEDED(hr))
return hr;
if (bVerbose)
{
WCHAR pwszOutput[2048];
wsprintf(pwszOutput,L"Checking the Group:\n\n%s\n\n for the member:\n\n%s\n\n",bsGroupPath,pwszMemberPath);
PrintBanner(pwszOutput);
}
// Get an interface pointer to the IADsCollection of members
hr = pADsGroup->Members(&pADsMembers);
if (SUCCEEDED(hr))
{
// Query the IADsCollection of members for a new ENUM Interface
// Be aware that the enum comes back as an IUnknown *
hr = pADsMembers->get__NewEnum(&pUnknown);
if (SUCCEEDED(hr))
{
// QI the IUnknown * for an IEnumVARIANT interface
hr = pUnknown->QueryInterface(IID_IEnumVARIANT, (void **)&pEnumVariant);
if (SUCCEEDED(hr))
{
// While have not hit errors or end of data....
while (fContinue)
{
ulElementsFetched = 0;
// Get a "batch" number of group members-number of rows specified by FETCH_NUM
hr = ADsEnumerateNext(pEnumVariant, FETCH_NUM, VariantArray, &ulElementsFetched);
if (ulElementsFetched )
{
// Loop through the current batch-printing the path for each member.
for (ULONG i = 0; i < ulElementsFetched; i++ )
{
IDispatch * pDispatch = NULL; // ptr for holding dispath of element
BSTR bstrCurrentPath = NULL; // Holds path of object
BSTR bstrGuidCurrent = NULL; // Holds path of object
IDirectoryObject * pIDOCurrent = NULL;// Holds the current object
// Get the dispatch ptr for the variant
pDispatch = VariantArray[i].pdispVal;
// assert(HAS_BIT_STYLE(VariantArray[i].vt,VT_DISPATCH));
// Get the IADs interface for the "member" of this group
hr = pDispatch->QueryInterface(IID_IDirectoryObject,
(VOID **) &pIDOCurrent ) ;
if (SUCCEEDED(hr))
{
// Get the GUID for the current object
hr = GetObjectGuid(pIDOCurrent,bstrGuidCurrent);
if (FAILED(hr))
return hr;
IADs * pIADsCurrent = NULL;
// Retrieve the IADs Interface for the current object
hr = pIDOCurrent->QueryInterface(IID_IADs,(void**)&pIADsCurrent);
if (FAILED(hr))
return hr;
// Get the ADsPath property for this member
hr = pIADsCurrent->get_ADsPath(&bstrCurrentPath);
if (SUCCEEDED(hr))
{
if (bVerbose)
wprintf(L"Comparing:\n\n%s\nWITH:\n%s\n\n",bstrGuidCurrent,pwszMemberGUID);
// Verify that the member of this group is Equal to passed.
if (_wcsicmp(bstrGuidCurrent,pwszMemberGUID)==0)
{
if (bVerbose)
wprintf(L"!!!!!Object:\n\n%s\n\nIs a member of\n\n%s\n\n",pwszMemberPath,bstrGuidCurrent);
//.........这里部分代码省略.........
示例8: main
int main(int argc, char* argv[])
{
IADs *pNS = NULL,
*pRoot=NULL,
*pAuth=NULL;
IADsOpenDSObject *pDSObj=NULL;
VARIANT varDSRoot;
TCHAR adspath[MAX_PATH],username[255],password[255];
HRESULT hr;
hr = CoInitialize(NULL);
// Get the name of the root container for this domain.
// Read the Root DSE from the default DS, which will be the DS for
// the local domain. This will get us the name of the schema container,
// which is stored in the "defaultNamingContext" operational attribute.
hr = ADsGetObject(TEXT("LDAP://RootDSE"),
IID_IADs,
(void**)&pRoot);
if ( FAILED(hr) )
{
::CoUninitialize();
_tprintf(TEXT("\nError in ADsGetObject"));
return 1;
}
hr = pRoot->Get(TEXT("defaultNamingContext"),&varDSRoot);
if ( FAILED(hr) )
{
::CoUninitialize();
pRoot->Release();
_tprintf(TEXT("\nError in reading defaultNamingContext"));
return 1;
}
_tprintf(TEXT("\nDomain Name is :%s\n"),varDSRoot.bstrVal);
pRoot->Release();
_tcscpy_s(adspath,MAX_PATH, TEXT("LDAP://"));
// get the remaining buffer size; make sure it copies, avoid buffer overrun
int rem = (sizeof(adspath)/sizeof(TCHAR)) - _tcslen(adspath) -1; //-1 is for NULL
int len = wcslen(varDSRoot.bstrVal);
if ( rem >= len )
{
_tcsncat_s(adspath,MAX_PATH,varDSRoot.bstrVal, len);
}
else
{
pRoot->Release();
VariantClear(&varDSRoot);
return 1;
}
hr = ADsGetObject(TEXT("LDAP:"),
IID_IADs,
(void**)&pNS);
if ( FAILED(hr) )
{
::CoUninitialize();
_tprintf(TEXT("\nError in ADsGetObject"));
return 1;
}
hr = pNS->QueryInterface(IID_IADsOpenDSObject,(void**)&pDSObj);
if ( FAILED(hr) )
{
::CoUninitialize();
pNS->Release();
_tprintf(TEXT("\nError in QueryInterface"));
return 1;
}
//
// Collect the username and password and bind to the Domain using these.
//
if SUCCEEDED(hr)
{
pNS->Release();
_tprintf(TEXT("\nusername:"));
_fgetts(username,sizeof(username)/sizeof(TCHAR),stdin);
username[_tcslen(username)-1] = '\0';
_tprintf(TEXT("\"%s\""), username);
_tprintf(TEXT("\npassword:"));
_fgetts(password, sizeof(password)/sizeof(TCHAR), stdin);
password[_tcslen(password)-1] = '\0';
hr = pDSObj->OpenDSObject(adspath,username,password,ADS_SECURE_AUTHENTICATION,(IDispatch**)&pAuth);
//.........这里部分代码省略.........
示例9: GetDeletedObjectsContainer
//----------------------------------------------------------------------------
//
// GetDeletedObjectsContainer()
//
// Binds to the Deleted Object container.
//
//----------------------------------------------------------------------------
HRESULT GetDeletedObjectsContainer(IADsContainer **ppContainer)
{
if(NULL == ppContainer)
{
return E_INVALIDARG;
}
HRESULT hr;
IADs *pRoot;
*ppContainer = NULL;
// Bind to the rootDSE object.
hr = ADsOpenObject(L"LDAP://rootDSE",
NULL,
NULL,
ADS_SECURE_AUTHENTICATION,
IID_IADs,
(LPVOID*)&pRoot);
if(SUCCEEDED(hr))
{
VARIANT var;
VariantInit(&var);
// Get the current domain DN.
hr = pRoot->Get(L"defaultNamingContext", &var);
if(SUCCEEDED(hr))
{
// Build the binding string.
LPWSTR pwszFormat = L"LDAP://<WKGUID=%s,%s>";
LPWSTR pwszPath;
pwszPath = new WCHAR[wcslen(pwszFormat) + wcslen(GUID_DELETED_OBJECTS_CONTAINER_W) + wcslen(var.bstrVal)];
if(NULL != pwszPath)
{
swprintf(pwszPath, pwszFormat, GUID_DELETED_OBJECTS_CONTAINER_W, var.bstrVal);
// Bind to the object.
hr = ADsOpenObject(pwszPath,
NULL,
NULL,
ADS_FAST_BIND | ADS_SECURE_AUTHENTICATION,
IID_IADsContainer,
(LPVOID*)ppContainer);
delete pwszPath;
}
else
{
hr = E_OUTOFMEMORY;
}
VariantClear(&var);
}
pRoot->Release();
}
return hr;
}
示例10: wmain
/* Note: Using the UNICODE version of main().
this removes the need for the sample to include
UNICODE-ANSI conversion routines
*/
void wmain( int argc, wchar_t *argv[ ])
{
WCHAR pwszTemp[4096];
// We have now scanned PAST whitespace- so copy the string:
wcscpy_s(pwszTemp,4096,L" A String");
Trim(pwszTemp);
HRESULT hr;
IDirectoryObject * pDirObjectContainer = NULL;
IDirectoryObject * pDirObjRet = NULL;
if (!ParseCommandLine(argc,argv))
return;
// Initialize COM
CoInitialize(0);
// Bind to the container passed
// If USER and PASS passed in, use ADsOpenObject()
if (bsUSER)
hr = ADsOpenObject(bsLDAP, bsUSER, bsPASS,
ADS_SECURE_AUTHENTICATION,IID_IDirectoryObject, (void**) &pDirObjectContainer);
else
hr = ADsGetObject( bsLDAP, IID_IDirectoryObject,(void **)&pDirObjectContainer);
if (SUCCEEDED(hr))
{
// if a file is NOT passed in- Do the simple version
if (!bsFILE)
{
// Call the helper funtion to create the User
hr = CreateUser(pDirObjectContainer, bsUNAME,bsSAMNAME,
&pDirObjRet);
}
else // file was passed in
{
// Call the helper funtion to create the User
hr = CreateUserFromFile(pDirObjectContainer, bsUNAME,bsSAMNAME,
&pDirObjRet,bsFILE);
}
if (SUCCEEDED(hr))
{
_putws(L"\n\n New User created with the following properties:\n");
IADs * pIADsNewGoup = NULL;
// User succeeded- now get an IADs interface to it
// and print some properties
hr = pDirObjRet->QueryInterface(IID_IADs,(void**)&pIADsNewGoup);
if (SUCCEEDED(hr))
{
PrintIADSObject(pIADsNewGoup);
pIADsNewGoup->Release();
pIADsNewGoup = NULL;
}
else
CheckADHRESULT(hr,L"QueryInterface() - New User for IADs");
pDirObjRet->Release();
pDirObjRet = NULL;
}
else
CheckADHRESULT(hr,L"CreateUser()");
pDirObjectContainer->Release();
pDirObjectContainer = NULL;
}
else
if (bsUSER)
CheckADHRESULT(hr,L"ADsOpenObject()");
else
CheckADHRESULT(hr,L"ADsGetObject()");
if ( bsLDAP )
::SysFreeString(bsLDAP);
if ( bsUNAME )
::SysFreeString(bsUNAME);
if ( bsSAMNAME )
::SysFreeString(bsSAMNAME);
if ( bsFILE )
::SysFreeString(bsFILE);
if ( bsUSER )
::SysFreeString(bsUSER);
if ( bsPASS )
::SysFreeString(bsPASS);
CoUninitialize();
}
示例11: MessageBeep
void CADQIDlg::OnDblClkInterfaces()
{
CString s;
int xx=0;
int idx;
IUnknown *pNewUnk = NULL;
idx = m_cListIf.GetCurSel();
if ( idx == LB_ERR )
{
MessageBeep(0);
return;
}
CWaitCursor wait;
m_cListIf.GetText( idx, s );
//////////////////////////////////////////////////////////////
//
// Find the appropriate dialog box to display
//
/////////////////////////////////////////////////////////////////
while( !IsEqualIID( *adsiIfs[xx].pIID, IID_NULL ) && s != adsiIfs[xx].szIf )
{
xx++;
}
ASSERT( !IsEqualIID( *adsiIfs[xx].pIID, IID_NULL ) );
if ( adsiIfs[xx].pFn )
{
m_pUnk->AddRef();
(*adsiIfs[xx].pFn)( m_pUnk, &pNewUnk );
}
else
{
wait.Restore();
AfxMessageBox(_T("No UI implemented yet"));
}
////////////////////////////////////////////////////
// if IADsOpenObject is selected, special care
///////////////////////////////////////////////////
if ( pNewUnk )
{
HRESULT hr;
BSTR bstr;
IADs *pADs;
hr = pNewUnk->QueryInterface( IID_IADs, (void**) &pADs );
if ( SUCCEEDED(hr) )
{
pADs->get_ADsPath( &bstr );
}
pADs->Release();
m_sADsPath = bstr;
SysFreeString( bstr );
m_pUnk->Release(); // old ads iunknown path;
m_pUnk = pNewUnk;
UpdateData(FALSE);
EnumerateInterface();
}
}
示例12: EnumAllObject
HRESULT EnumAllObject(LPWSTR pszADsPath, int indent)
{
ULONG cElementFetched = 0L;
IEnumVARIANT * pEnumVariant = NULL;
VARIANT VariantArray[MAX_ENUM];
HRESULT hr = S_OK;
IADsContainer * pADsContainer = NULL;
DWORD dwObjects = 0, dwEnumCount = 0, i = 0;
BOOL fContinue = TRUE;
hr = ADsGetObject(
pszADsPath,
IID_IADsContainer,
(void **)&pADsContainer
);
if (FAILED(hr)) {
printf("\"%S\" is not a valid container object.\n", pszADsPath);
goto exitpoint;
}
hr = ADsBuildEnumerator(
pADsContainer,
&pEnumVariant
);
if (FAILED(hr))
{
printf("ADsBuildEnumerator failed with %lx\n", hr);
goto exitpoint;
}
fContinue = TRUE;
while (fContinue) {
IADs *pObject;
hr = ADsEnumerateNext(
pEnumVariant,
MAX_ENUM,
VariantArray,
&cElementFetched
);
if (FAILED(hr))
{
printf("ADsEnumerateNext failed with %lx\n", hr);
goto exitpoint;
}
if (hr == S_FALSE) {
fContinue = FALSE;
}
dwEnumCount++;
for (i = 0; i < cElementFetched; i++) {
IDispatch *pDispatch = NULL;
BSTR bstrADsPath = NULL;
pDispatch = VariantArray[i].pdispVal;
hr = V_DISPATCH(VariantArray + i)->QueryInterface(IID_IADs, (void **)&pObject);
if (SUCCEEDED(hr))
{
pObject->get_ADsPath(&bstrADsPath);
printf("%S\n", bstrADsPath);
EnumAllObject(bstrADsPath, indent + 2);
}
pObject->Release();
VariantClear(VariantArray + i);
SysFreeString(bstrADsPath);
}
dwObjects += cElementFetched;
}
printf("Total Number of Objects enumerated is %d\n", dwObjects);
exitpoint:
if (pEnumVariant) {
ADsFreeEnumerator(pEnumVariant);
}
if (pADsContainer) {
pADsContainer->Release();
}
return(hr);
}
示例13: wmain
void wmain( int argc, wchar_t *argv[])
{
//Handle the command line arguments.
int maxAlloc = MAX_PATH*2;
LPOLESTR pszBuffer = new OLECHAR[maxAlloc];
wcscpy_s(pszBuffer, maxAlloc, L"");
BOOL bReturnVerbose = FALSE;
for (int i = 1;i<argc;i++)
{
if (_wcsicmp(argv[i],L"/V") == 0)
{
bReturnVerbose = TRUE;
}
else if ((_wcsicmp(argv[i],L"/?") == 0)||
(_wcsicmp(argv[i],L"-?") == 0))
{
wprintf(L"This program queries for users in the current user's domain.\n");
wprintf(L"Syntax: queryusers [/V][querystring]\n");
wprintf(L"where /V specifies that all properties for the found users should be returned.\n");
wprintf(L" querystring is the query criteria in ldap query format.\n");
wprintf(L"Defaults: If no /V is specified, the query returns only the RDN and DN of the items found.\n");
wprintf(L" If no querystring is specified, the query returns all users.\n");
wprintf(L"Example: queryusers (sn=Smith)\n");
wprintf(L"Returns all users with surname Smith.\n");
return;
}
else
{
if ( IS_BUFFER_ENOUGH(maxAlloc, pszBuffer, argv[i]) > 0 )
{
wcscpy_s(pszBuffer,maxAlloc,argv[i]);
}
else
{
wprintf(L"Buffer is too small for the argument");
delete [] pszBuffer;
return;
}
}
}
if (_wcsicmp(pszBuffer,L"") == 0)
wprintf(L"\nFinding all user objects...\n\n");
else
wprintf(L"\nFinding user objects based on query: %s...\n\n", pszBuffer);
//Initialize COM
CoInitialize(NULL);
HRESULT hr = S_OK;
//Get rootDSE and the current user's domain container DN.
IADs *pObject = NULL;
IDirectorySearch *pContainerToSearch = NULL;
LPOLESTR szPath = new OLECHAR[MAX_PATH];
VARIANT var;
hr = ADsOpenObject(L"LDAP://rootDSE",
NULL,
NULL,
ADS_SECURE_AUTHENTICATION, //Use Secure Authentication
IID_IADs,
(void**)&pObject);
if (FAILED(hr))
{
wprintf(L"Could not execute query. Could not bind to LDAP://rootDSE.\n");
if (pObject)
pObject->Release();
delete [] pszBuffer;
delete [] szPath;
CoUninitialize();
return;
}
if (SUCCEEDED(hr))
{
hr = pObject->Get(L"defaultNamingContext",&var);
if (SUCCEEDED(hr))
{
//Build path to the domain container.
wcscpy_s(szPath,MAX_PATH,L"LDAP://");
if ( IS_BUFFER_ENOUGH(MAX_PATH, szPath, var.bstrVal) > 0 )
{
wcscat_s(szPath,MAX_PATH,var.bstrVal);
}
else
{
wprintf(L"Buffer is too small for the domain DN");
delete [] pszBuffer;
delete [] szPath;
CoUninitialize();
return;
}
hr = ADsOpenObject(szPath,
NULL,
NULL,
ADS_SECURE_AUTHENTICATION, //Use Secure Authentication
IID_IDirectorySearch,
(void**)&pContainerToSearch);
if (SUCCEEDED(hr))
//.........这里部分代码省略.........
示例14: wmain
void wmain( int argc, wchar_t *argv[ ])
{
BOOL bIsAttributeQuery = TRUE;
BOOL bReturnVerbose = FALSE;
LPOLESTR szType = L"attribute";
if (1==argc||(_wcsicmp(argv[1],L"/?") == 0))
{
wprintf(L"This program queries the schema for the specified classes or attributes.\n");
wprintf(L"Syntax: getschemainfo [/C|/A][/V][querystring]\n");
wprintf(L"where /C specifies to query for classes.\n");
wprintf(L" /A specifies to query for attributes.\n");
wprintf(L" /V specifies that all properties for the found classes or attributes should be returned.\n");
wprintf(L" querystring is the query criteria in ldap query format.\n");
wprintf(L"Defaults: If neither /A or /C is specified, the query is against both.\n");
wprintf(L" If no /V is specified, the query returns only the ldapDisplayName and cn of the items found.\n");
wprintf(L" If no querystring is specified, the query returns all classes and/or attributes.\n");
wprintf(L"Example: getschemainfo /A (IsSingleValued=TRUE)\n");
wprintf(L"Returns all single-valued attributes in the schema.\n");
wprintf(L"Common querystrings:\n");
wprintf(L"For attributes:\n");
wprintf(L"(cn=Street-Address) to find the attribute with CN of Street-Address.\n");
wprintf(L"(ldapdisplayname=street) to find the attribute with ldapdisplayname of street.\n");
wprintf(L"(IsSingleValued=TRUE) for single-valued attributes.\n");
wprintf(L"(IsSingleValued=FALSE) for mulit-valued attributes.\n");
wprintf(L"(systemFlags:1.2.840.113556.1.4.804:=00000001) for non-replicated attributes\n");
wprintf(L"(systemFlags:1.2.840.113556.1.4.804:=00000004) for constructed attributes\n");
wprintf(L"(searchFlags=1) for indexed attributes.\n");
wprintf(L"(isMemberOfPartialAttributeSet=TRUE) for attributes included in the global catalog\n");
return;
}
//Handle the command line arguments
int maxAlloc=MAX_PATH*2;
LPOLESTR pszBuffer = new OLECHAR[maxAlloc];
if ( !pszBuffer )
{
wprintf(L"Alloc Failed ");
return;
}
wcscpy_s(pszBuffer, maxAlloc, L"");
for (int i = 1;i<argc;i++)
{
if (_wcsicmp(argv[i],L"/C") == 0)
{
bIsAttributeQuery = FALSE;
szType = L"class";
}
else if (_wcsicmp(argv[i],L"/A") == 0)
{
bIsAttributeQuery = TRUE;
szType = L"attribute";
}
else if (_wcsicmp(argv[i],L"/V") == 0)
{
bReturnVerbose = TRUE;
}
else
{
if ( IS_BUFFER_ENOUGH(maxAlloc,pszBuffer, argv[i]) > 0 )
{
wcscpy_s(pszBuffer,maxAlloc,argv[i]);
}
else
{
wprintf(L"The argument is too large ");
if ( pszBuffer )
delete [] pszBuffer;
return;
}
}
}
if (_wcsicmp(pszBuffer,L"") == 0)
wprintf(L"\nFinding all %sSchema objects in the schema...\n\n",szType);
else
wprintf(L"\nFinding %sSchema objects based on query: %s...\n\n",szType, pszBuffer);
HRESULT hr = S_OK;
//Get rootDSE and the domain container's DN.
IADs *pObject = NULL;
IDirectorySearch *pSchemaNC = NULL;
const unsigned int pathLen = MAX_PATH;
LPOLESTR szPath = new OLECHAR[pathLen];
if ( !szPath )
{
wprintf(L"Alloc Failed ");
delete [] pszBuffer;
return;
}
//Intialize COM
CoInitialize(NULL);
VARIANT var;
hr = ADsOpenObject(L"LDAP://rootDSE",
NULL,
NULL,
//.........这里部分代码省略.........
示例15: wmain
void wmain( int argc, wchar_t *argv[ ])
{
//Handle the command line arguments.
LPOLESTR pszBuffer = NULL;
pszBuffer = new OLECHAR[MAX_PATH*2];
if(pszBuffer == NULL)
goto ret;
if (argv[1] == NULL)
{
wprintf(L"This program finds a user in the current Window 2000 domain\n");
wprintf(L"and displays its objectSid property in string form.\n");
wprintf(L"This program demonstrates reading a property of type octet string.\n\n");
wprintf(L"Enter Common Name of the user to find:");
if ( !_getws_s(pszBuffer, MAX_PATH*2))
{
delete [] pszBuffer;
wprintf(L"String exceeded buffer size.\n\n");
return;
}
}
else
if ( !wcscpy_s(pszBuffer, MAX_PATH*2, argv[1]))
{
delete [] pszBuffer;
wprintf(L"String exceeded buffer size.\n\n");
return;
}
//if empty string, exit.
if (0==wcscmp(L"", pszBuffer))
goto ret;
wprintf(L"\nFinding user: %s...\n",pszBuffer);
//Intialize COM
CoInitialize(NULL);
HRESULT hr = S_OK;
//Get rootDSE and the domain container's DN.
IADs *pObject = NULL;
IDirectorySearch *pDS = NULL;
LPOLESTR szPath = NULL;
szPath = new OLECHAR[MAX_PATH];
if(szPath == NULL)
goto ret;
VARIANT var;
hr = ADsOpenObject(L"LDAP://rootDSE",
NULL,
NULL,
ADS_SECURE_AUTHENTICATION, //Use Secure Authentication
IID_IADs,
(void**)&pObject);
if (FAILED(hr))
{
wprintf(L"Not Found. Could not bind to the domain.\n");
if (pObject)
pObject->Release();
goto ret;
}
VariantInit(&var);
hr = pObject->Get(L"defaultNamingContext",&var);
if (SUCCEEDED(hr))
{
wcscpy_s(szPath,MAX_PATH,L"LDAP://");
wcscat_s(szPath,MAX_PATH,var.bstrVal);
VariantClear(&var);
if (pObject)
{
pObject->Release();
pObject = NULL;
}
//Bind to the root of the current domain.
hr = ADsOpenObject(szPath,
NULL,
NULL,
ADS_SECURE_AUTHENTICATION, //Use Secure Authentication
IID_IDirectorySearch,
(void**)&pDS);
if (SUCCEEDED(hr))
{
hr = FindUserByName(pDS, //Container to search
pszBuffer, //Name of user to find.
&pObject); //Return a pointer to the user
if (SUCCEEDED(hr))
{
//Get the objectSid property
hr = pObject->Get(L"objectSid", &var);
if (SUCCEEDED(hr))
{
LPBYTE pByte = NULL;
wprintf (L"----------------------------------------------\n");
wprintf (L"----------Call GetLPBYTEtoOctetString---------\n");
wprintf (L"----------------------------------------------\n");
hr = GetLPBYTEtoOctetString(&var, //IN. Pointer to variant containing the octetstring.
&pByte //OUT. Return LPBYTE to the data represented in octetstring.
);
PSID pObjectSID = (PSID)pByte;
//.........这里部分代码省略.........