//---------------------------------------------------------------------------- // // Microsoft Windows // Copyright (C) Microsoft Corporation, 1992 - 1993. // // File: drt.cxx // // Contents: Main for OleDs DRT // // // History: 28-Oct-94 KrishnaG, created OleDs DRT // 28-Oct-94 ChuckC, rewritten. // //---------------------------------------------------------------------------- // // System Includes // #define INC_OLE2 #include // // CRunTime Includes // #include #include #include #include // // Public OleDs includes // // // Private defines // #define BAIL_ON_NULL(p) \ if (!(p)) { \ goto error; \ } #define BAIL_ON_FAILURE(hr) \ if (FAILED(hr)) { \ goto error; \ } #include "activeds.h" #include "main.hxx" #include "adsi.h" // // Globals representing the parameters // LPWSTR pszSearchBase, pszSearchFilter, pszAttrNames[10], pszAttrList; DWORD dwNumberAttributes = -1; // // Preferences // BOOL fASynchronous=FALSE, fDerefAliases=FALSE, fAttrsOnly=FALSE; DWORD fSizeLimit, fTimeLimit, dwTimeOut, dwPageSize, dwSearchScope; ADS_SEARCHPREF_INFO pSearchPref[10]; DWORD dwCurrPref = 0; LPWSTR pszUserName=NULL, pszPassword=NULL; DWORD dwAuthFlags=0; DWORD cErr=0; char *prefNameLookup[] = { "ADS_SEARCHPREF_ASYNCHRONOUS", "ADS_SEARCHPREF_DEREF_ALIASES", "ADS_SEARCHPREF_SIZE_LIMIT", "ADS_SEARCHPREF_TIME_LIMIT", "ADS_SEARCHPREF_ATTRIBTYPES_ONLY", "ADS_SEARCHPREF_SEARCH_SCOPE", "ADS_SEARCHPREF_TIMEOUT", "ADS_SEARCHPREF_PAGESIZE", "ADS_SEARCHPREF_PAGED_TIME_LIMIT", "ADS_SEARCHPREF_CHASE_REFERRALS" }; HRESULT ConvertTrusteeToSid( LPWSTR bstrTrustee, PSID * ppSid, PDWORD pdwSidSize ); //+--------------------------------------------------------------------------- // // Function: main // // Synopsis: // //---------------------------------------------------------------------------- INT __cdecl main(int argc, char * argv[]) { HRESULT hr=S_OK; HANDLE handle = NULL; ADS_SEARCH_HANDLE hSearchHandle=NULL; ADS_SEARCH_COLUMN Column; DWORD nRows = 0, i; LPWSTR pszColumnName = NULL; LPWSTR pszDest = NULL; LPBYTE pSid = NULL; DWORD dwSize = 0; #if 0 // Enable if you want to test binary values in filters and send // pszBinaryFilter instead of pszSearchFilter in ExecuteSearch WCHAR pszBinaryFilter[256] = L"objectSid="; LPWSTR pszDest = NULL; BYTE column[100] = { 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0x59, 0x51, 0xb8, 0x17, 0x66, 0x72, 0x5d, 0x25, 0x64, 0x63, 0x3b, 0x0b, 0x29, 0x99, 0x21, 0x00 }; hr = ADsEncodeBinaryData ( column, 28, &pszDest ); wcscat( pszBinaryFilter, pszDest ); FreeADsMem( pszDest ); #endif // // Sets the global variables with the parameters // hr = ProcessArgs(argc, argv); BAIL_ON_FAILURE(hr); hr = ADSIOpenDSObject( pszSearchBase, pszUserName, pszPassword, dwAuthFlags, &handle ); BAIL_ON_FAILURE(hr); if (dwCurrPref) { hr = ADSISetSearchPreference( handle, pSearchPref, dwCurrPref ); BAIL_ON_FAILURE(hr); if (hr != S_OK) { for (i=0; i= pszText; pChar--) { if(!iswspace(*pChar)) break; else *pChar = L'\0'; } return pszText; } HRESULT ConvertTrusteeToSid( LPWSTR bstrTrustee, PSID * ppSid, PDWORD pdwSidSize ) { HRESULT hr = S_OK; BYTE Sid[MAX_PATH]; DWORD dwSidSize = sizeof(Sid); DWORD dwRet = 0; WCHAR szDomainName[MAX_PATH]; DWORD dwDomainSize = sizeof(szDomainName)/sizeof(WCHAR); SID_NAME_USE eUse; PSID pSid = NULL; dwSidSize = sizeof(Sid); dwRet = LookupAccountNameW( NULL, bstrTrustee, Sid, &dwSidSize, szDomainName, &dwDomainSize, (PSID_NAME_USE)&eUse ); if (!dwRet) { hr = HRESULT_FROM_WIN32(GetLastError()); BAIL_ON_FAILURE(hr); } memcpy(pSid, Sid, dwSidSize); *pdwSidSize = dwSidSize; *ppSid = pSid; error: return(hr); }