Skip to content

Commit

Permalink
1.0.61
Browse files Browse the repository at this point in the history
  • Loading branch information
Bureau Audit committed Jan 2, 2019
1 parent f76797d commit d20431a
Show file tree
Hide file tree
Showing 8 changed files with 356 additions and 143 deletions.
135 changes: 130 additions & 5 deletions Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ pProcessDomain(
_In_ BOOL bWriteTableInfo
);

BOOL
pGetFileVersion(
_Out_ wchar_t* szVersion,
_In_ size_t _BufferCount
);

BOOL
Process (
_In_ PGLOBAL_CONFIG pGlobalConfig
Expand All @@ -35,10 +41,14 @@ Process (

ROOTDSE_CONFIG RootDse = { 0 };

DWORD dwStartTime, dwEndTime;

dwStartTime = GetTickCount();

//
// Get server by DC Locator, if needed
//
if (wcscmp(pGlobalConfig->szServer, L"[dsgetdc]") == 0)
if (wcscmp(pGlobalConfig->szServer, DC_LOCATOR_OPTION) == 0)
{
bResult = pLocateDc(NULL, &szServer);
if (bResult == FALSE)
Expand Down Expand Up @@ -79,13 +89,13 @@ Process (
}

swprintf(
szDirectory, MAX_PATH,
pGlobalConfig->szFullOutDirectory, MAX_PATH,
L"%s\\%s\\%s",
pGlobalConfig->szOutDirectory,
szRootDns,
pGlobalConfig->szSystemTime
);
CreateDirectory(szDirectory, NULL);
CreateDirectory(pGlobalConfig->szFullOutDirectory, NULL);

swprintf(
szDirectory, MAX_PATH,
Expand Down Expand Up @@ -190,7 +200,39 @@ Process (
{
ROOTDSE_CONFIG pRootDse = { 0 };

pProcessDomain(pGlobalConfig, &pRootDse, szDirectory, szServer, szRootDns, TRUE, TRUE);
pProcessDomain(pGlobalConfig, &pRootDse, szDirectory, szServer, szRootDns, TRUE, FALSE);

//
// Process Forest domains
//
if (pGlobalConfig->szForestDomains != NULL)
{
LPWSTR szContext = NULL;
LPWSTR szOtherDomain = wcstok_s(pGlobalConfig->szForestDomains, L",", &szContext);

while (szOtherDomain != NULL)
{
ROOTDSE_CONFIG pOtherRootDse = { 0 };
bResult = pLocateDc(szOtherDomain, &szServer);
if (bResult != FALSE)
{
Log(
__FILE__, __FUNCTION__, __LINE__, LOG_LEVEL_INFORMATION,
"Processing extra domain in forest: %S",
szOtherDomain
);
pProcessDomain(pGlobalConfig, &pOtherRootDse, szDirectory, szServer, szRootDns, TRUE, TRUE);
}
szOtherDomain = wcstok_s(NULL, L",", &szContext);
}
}

//
// Write table infos into table file (FALSE, TRUE)
// Done only after all requests (TRUE, FALSE) to be sure to have max text size for all domains
//
pProcessDomain(pGlobalConfig, &pRootDse, szDirectory, szServer, szRootDns, FALSE, TRUE);

_SafeHeapRelease(szServer);
}
else
Expand Down Expand Up @@ -257,10 +299,55 @@ Process (
bReturn = TRUE;

End:
_SafeHeapRelease(szRootDns);
dwEndTime = GetTickCount() - dwStartTime;

if (pGlobalConfig->hTableFile != NULL)
{
//
// Write metatada table
//
BUFFER_DATA Buffer;
WCHAR szFilename[MAX_PATH];
WCHAR szMetadata[1024];

swprintf(
szFilename, MAX_PATH,
L"%s\\%s\\%s\\metadata.tsv",
pGlobalConfig->szOutDirectory,
szRootDns,
pGlobalConfig->szSystemTime
);
bResult = BufferInitialize(&Buffer, szFilename);
if (bResult != FALSE)
{
// Exe version
BufferWrite(&Buffer, (LPWSTR)L"oradad_version");
BufferWriteTab(&Buffer);
pGetFileVersion(szMetadata, 1024);
BufferWrite(&Buffer, szMetadata);
BufferWriteLine(&Buffer);
// Process Time
BufferWrite(&Buffer, (LPWSTR)L"oradad_processtime");
BufferWriteTab(&Buffer);
swprintf_s(szMetadata, 1024, L"%d", dwEndTime);
BufferWrite(&Buffer, szMetadata);
BufferWriteLine(&Buffer);
// Level
BufferWrite(&Buffer, (LPWSTR)L"oradad_level");
BufferWriteTab(&Buffer);
swprintf_s(szMetadata, 1024, L"%d", pGlobalConfig->dwLevel);
BufferWrite(&Buffer, szMetadata);
BufferWriteLine(&Buffer);

BufferClose(&Buffer);

WriteTextFile(pGlobalConfig->hTableFile, "metadata.tsv\tmetadata\tmetadata\t2\tkey\tnvarchar(255)\tvalue\tnvarchar(1024)\n");
}

CloseHandle(pGlobalConfig->hTableFile);
}

_SafeHeapRelease(szRootDns);
return bReturn;
}

Expand Down Expand Up @@ -405,4 +492,42 @@ pProcessDomain (
_SafeHeapRelease(szDomainDns);

return TRUE;
}

BOOL
pGetFileVersion (
_Out_ wchar_t* const szVersion,
_In_ size_t const _BufferCount
)
{
WCHAR szFilename[MAX_PATH];

GetModuleFileNameW(NULL, szFilename, MAX_PATH);
DWORD dwHandle;
DWORD sz = GetFileVersionInfoSizeW(szFilename, &dwHandle);
if (0 == sz)
{
return FALSE;
}
PBYTE pbBuf = (PBYTE)_HeapAlloc(sz);
if (GetFileVersionInfoW(szFilename, dwHandle, sz, pbBuf) == FALSE)
{
_SafeHeapRelease(pbBuf);
return FALSE;
}
VS_FIXEDFILEINFO * pvi;
sz = sizeof(VS_FIXEDFILEINFO);
if (!VerQueryValueW(pbBuf, L"\\", (LPVOID*)&pvi, (unsigned int*)&sz))
{
_SafeHeapRelease(pbBuf);
return FALSE;
}
swprintf(szVersion, _BufferCount, L"%d.%d.%d.%d",
pvi->dwProductVersionMS >> 16,
pvi->dwFileVersionMS & 0xFFFF,
pvi->dwFileVersionLS >> 16,
pvi->dwFileVersionLS & 0xFFFF
);
_SafeHeapRelease(pbBuf);
return 0;
}
59 changes: 47 additions & 12 deletions LDAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,14 @@ LdapProcessRequest (

berval *pBerVal = NULL;

DWORD dwObjectCount = 0;
DWORD dwStartTime, dwEndTime;

dwStartTime = GetTickCount();

Log(
__FILE__, __FUNCTION__, __LINE__, LOG_LEVEL_VERBOSE,
"Start dump '%S/%S/%S/%S'.", szRootDns, szPath1, szPath2, pRequest->szName
__FILE__, __FUNCTION__, __LINE__, LOG_LEVEL_INFORMATION,
"Dumping '%S/%S/%S/%S'.", szRootDns, szPath1, szPath2, pRequest->szName
);

//
Expand Down Expand Up @@ -772,10 +773,15 @@ LdapProcessRequest (
}
else
{
Log(
__FILE__, __FUNCTION__, __LINE__, LOG_LEVEL_WARNING,
"ldap_get_values(%S, %s) has no value but is not with range.", szDn, pAttribute
);
// We exclude 'msDS-RevealedList' attribute which can be
// returned even null
if (wcscmp(pAttribute, L"msDS-RevealedList") != 0)
{
Log(
__FILE__, __FUNCTION__, __LINE__, LOG_LEVEL_WARNING,
"ldap_get_values(%S, %S) has no value but is not with range.", szDn, pAttribute
);
}
}
}
}
Expand Down Expand Up @@ -1009,7 +1015,7 @@ LdapProcessRequest (
}

BufferWriteLine(pBuffer);

dwObjectCount++;
ldap_memfree(szDn);
}

Expand Down Expand Up @@ -1090,12 +1096,15 @@ LdapProcessRequest (
BufferClose(&Buffer);

dwEndTime = GetTickCount();
dwEndTime = (dwEndTime - dwStartTime) / 1000;

Log(
__FILE__, __FUNCTION__, __LINE__, LOG_LEVEL_INFORMATION,
"Dump '%S/%S/%S/%S' finished (elapsed time: %u seconds).",
szRootDns, szPath1, szPath2, pRequest->szName,
(dwEndTime - dwStartTime) / 1000
" Finished: elapsed time: %u second%s, %u object%s.",
dwEndTime,
dwEndTime > 1 ? "s" : "",
dwObjectCount,
dwObjectCount > 1 ? "s" : ""
);
}

Expand Down Expand Up @@ -1369,7 +1378,7 @@ pHasAttributeWithRange (
{
Log(
__FILE__, __FUNCTION__, __LINE__, LOG_LEVEL_VERBOSE,
"'%S' has attribute '%S' with range.",
"'%S' has at least one attribute with range ('%S').",
szDn, szAttrName
);
bReturn = TRUE;
Expand Down Expand Up @@ -1496,4 +1505,30 @@ pGetRangedAttribute (
ldap_msgfree(pLdapMessage);

return ppValue;
}
}

/*
BerElement* pBer = NULL;
pAttribute = ldap_first_attribute(
pLdapHandle, // Session handle
pEntry, // Current entry
&pBer); // [out] Current BerElement
while (pAttribute != NULL)
{
ldap_memfree(pAttribute);
pAttribute = ldap_next_attribute(
pLdapHandle, // Session Handle
pEntry, // Current entry
pBer); // Current BerElement
}
}
if (pBer != NULL)
{
ber_free(pBer, 0);
pBer = NULL;
}
*/
Loading

0 comments on commit d20431a

Please sign in to comment.