Skip to content

Commit

Permalink
Add dynamic wmi_flag_mode retrieved by .ini file
Browse files Browse the repository at this point in the history
  • Loading branch information
charleneauger committed Feb 7, 2022
1 parent 3f8930a commit 1c655f8
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 71 deletions.
8 changes: 8 additions & 0 deletions Agent/OCSInventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -775,5 +775,13 @@ BOOL COCSInventoryApp::parseCommandLine()
// /NOTIFY
if (isRequired( m_lpCmdLine, _T( "notify")))
m_pConfig->setNotify( TRUE);
// /WMI_FLAG_MODE[=READ/COMPLETE]^M
if (isRequired(m_lpCmdLine, _T("wmi_flag_mode")))
// Get wmi flag mode
m_pConfig->setWmiFlagMode(getParamValue(m_lpCmdLine, _T("wmi_flag_mode")));
// /DEFAULT_USER_DOMAIN[=user]
if (isRequired(m_lpCmdLine, _T("default_user_domain")))
// Get default user domain
m_pConfig->setDefaultUserDomain(getParamValue(m_lpCmdLine, _T("default_user_domain")));
return TRUE;
}
52 changes: 52 additions & 0 deletions OCSInventory Front/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ void CConfig::Clear()
m_csIpDiscLat.Empty();
m_bFastIp = FALSE;
m_csVersion.Empty();
m_csWmiFlagMode = "COMPLETE";
m_csDefaultUserDomain.Empty();
}

LPCTSTR CConfig::getVersion()
Expand Down Expand Up @@ -97,6 +99,36 @@ LPCTSTR CConfig::getLocalInventoryFolder()
return m_csLocal;
}

BOOL CConfig::isDefaultUserDomainRequired()
{
return !m_csDefaultUserDomain.IsEmpty();
}

LPCTSTR CConfig::getDefaultUserDomain()
{
return m_csDefaultUserDomain;
}

tag_WBEM_GENERIC_FLAG_TYPE CConfig::getWmiFlagMode()
{
CString m_csComplete("READ");
if (m_csWmiFlagMode == m_csComplete)
m_uFlag = WBEM_FLAG_DIRECT_READ;
else
m_uFlag = WBEM_FLAG_RETURN_WBEM_COMPLETE;
return m_uFlag;
}

LPCTSTR CConfig::getWmiFlagModeText()
{
CString m_csComplete("READ");
if (m_csWmiFlagMode == m_csComplete)
m_csFlag = "WBEM_FLAG_DIRECT_READ";
else
m_csFlag = "WBEM_FLAG_RETURN_WBEM_COMPLETE";
return m_csFlag;
}

BOOL CConfig::isNoTagRequired()
{
return m_bNoTag;
Expand Down Expand Up @@ -191,6 +223,12 @@ BOOL CConfig::load( LPCTSTR lpstrFile)
GetPrivateProfileString( OCS_AGENT_SECTION, _T( "ComProvider"), OCS_DEFAULT_PROVIDER, csBuffer.GetBuffer( 1024), 1024, m_csConfigFile);
csBuffer.ReleaseBuffer();
setCommunicationProvider( csBuffer);
// Default user domain name
GetPrivateProfileString(OCS_AGENT_SECTION, _T("DEFAULT_USER_DOMAIN"), _T(""), m_csDefaultUserDomain.GetBuffer(1024), 1024, m_csConfigFile);
m_csDefaultUserDomain.ReleaseBuffer();
// WMI flag mode
GetPrivateProfileString(OCS_AGENT_SECTION, _T("WMI_FLAG_MODE"), _T(""), m_csWmiFlagMode.GetBuffer(1024), 1024, m_csConfigFile);
m_csWmiFlagMode.ReleaseBuffer();
return TRUE;
}

Expand Down Expand Up @@ -219,6 +257,10 @@ BOOL CConfig::save( LPCTSTR lpstrFile)
bResult = bResult && WritePrivateProfileString( OCS_AGENT_SECTION, _T( "NoTAG"), csBuffer, m_csConfigFile);
// Force IP Discover for the specified network
bResult = bResult && WritePrivateProfileString( OCS_AGENT_SECTION, _T( "IpDisc"), m_csIpDisc, m_csConfigFile);
// Wmi flag mode
bResult = bResult && WritePrivateProfileString(OCS_AGENT_SECTION, _T("WMI_FLAG_MODE"), m_csWmiFlagMode, m_csConfigFile);
// Default user domain
bResult = bResult && WritePrivateProfileString(OCS_AGENT_SECTION, _T("DEFAULT_USER_DOMAIN"), m_csDefaultUserDomain, m_csConfigFile);
// Communication provider to use
CFile comFile( m_csComProvider, CFile::modeRead);
bResult = bResult && WritePrivateProfileString( OCS_AGENT_SECTION, _T( "ComProvider"), comFile.GetFileName(), m_csConfigFile);
Expand Down Expand Up @@ -302,6 +344,16 @@ void CConfig::setNoTagRequired(BOOL bNoTag)
m_bNoTag = bNoTag;
}

void CConfig::setWmiFlagMode(LPCTSTR lpstrWmiFlag)
{
m_csWmiFlagMode = lpstrWmiFlag;
}

void CConfig::setDefaultUserDomain(LPCTSTR lpstrDefaultUserDomain)
{
m_csDefaultUserDomain = lpstrDefaultUserDomain;
}

void CConfig::setXmlFolder(LPCTSTR lpstrFolder)
{
if ((lpstrFolder == NULL) || (_tcslen( lpstrFolder) == 0))
Expand Down
15 changes: 15 additions & 0 deletions OCSInventory Front/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class CConfig;

#include "OCSInventory Front Classes.h"
#include "Singleton.h"
#include <OcsWmi.h>

class OCSINVENTORYFRONT_API CConfig : public CSingleton<CConfig>
{
Expand Down Expand Up @@ -115,6 +116,12 @@ class OCSINVENTORYFRONT_API CConfig : public CSingleton<CConfig>
BOOL isForceInventoryRequired();
// Get Communication Provider DLL
LPCTSTR getCommunicationProvider();
// Get Default User Domain
BOOL isDefaultUserDomainRequired();
LPCTSTR getDefaultUserDomain();
// Get WMI flag mode
tag_WBEM_GENERIC_FLAG_TYPE getWmiFlagMode();
LPCTSTR getWmiFlagModeText();

// Enable pr not debugging mode
void setDebugRequired( UINT uDebug = TRUE);
Expand Down Expand Up @@ -147,6 +154,10 @@ class OCSINVENTORYFRONT_API CConfig : public CSingleton<CConfig>
void setHkcuRequired( BOOL bHKCU = TRUE);
// Set Communication Provider DLL to use without extension .DLL
void setCommunicationProvider( LPCTSTR lpstrDll);
// Set WMI flag /WMI_FLAG_MODE=[READ/COMPLETE]
void setWmiFlagMode(LPCTSTR lpstrWmiFlag = LPCTSTR("COMPLETE"));
// Set Default user domain /DEFAULT_USER_DOMAIN=name
void setDefaultUserDomain(LPCTSTR lpstrDefaultUserDomain = NULL);

// Write Administrative info to admininfo.conf hidden file in agent install folder
BOOL writeAccountInfos( LPCTSTR lpstrName, LPCTSTR lpstrValue);
Expand All @@ -170,6 +181,10 @@ class OCSINVENTORYFRONT_API CConfig : public CSingleton<CConfig>
CString m_csIpDiscLat; // Is /IPDISC_LAT:"number_of_ms" enabled to force IP Discover latency
BOOL m_bFastIp; // Is /FASTIP enabled, to disable network load contriol settings in IP Discover
CString m_csComProvider; // What's the communication provider to use to contact server ?
CString m_csWmiFlagMode; // READ or COMPLETE
tag_WBEM_GENERIC_FLAG_TYPE m_uFlag;
CString m_csDefaultUserDomain; // Default user domain name
CString m_csFlag;
// Agent version
CString m_csVersion;
};
Expand Down
18 changes: 13 additions & 5 deletions OCSInventory Front/InventoryRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ BOOL CInventoryRequest::runInventory()
CSoftware cSoftOS;

// Get logged on user
if (!m_pSysInfo->getUserName( cs1))
m_pLogger->log(LOG_PRIORITY_DEBUG, _T("INVENTORY => WMI FLAG MODE is set to <%s>"), getAgentConfig()->getWmiFlagModeText());
if (!m_pSysInfo->getUserName(cs1, getAgentConfig()->getWmiFlagMode()))
m_pLogger->log( LOG_PRIORITY_WARNING, _T( "INVENTORY => Failed to retrieve logged on user"));
else
m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "INVENTORY => Logged on user ID is <%s>"), cs1);
Expand Down Expand Up @@ -655,11 +656,18 @@ BOOL CInventoryRequest::runInventory()
cs1);
m_Device.SetDomainOrWorkgroup( cs1);
// Get NT user Domain
if (!m_pSysInfo->getUserDomain( cs1))
m_pLogger->log( LOG_PRIORITY_WARNING, _T( "INVENTORY => Failed to retrieve user domain"));
if (!getAgentConfig()->isDefaultUserDomainRequired())
{
if (!m_pSysInfo->getUserDomain(cs1, getAgentConfig()->getWmiFlagMode()))
m_pLogger->log(LOG_PRIORITY_WARNING, _T("INVENTORY => Failed to retrieve user domain"));
else
m_pLogger->log(LOG_PRIORITY_DEBUG, _T("INVENTORY => User domain is <%s>"), cs1);
}
else
m_pLogger->log( LOG_PRIORITY_DEBUG, _T( "INVENTORY => User domain is <%s>"),
cs1);
{
cs1 = getAgentConfig()->getDefaultUserDomain();
m_pLogger->log(LOG_PRIORITY_DEBUG, _T("INVENTORY => Default User domain is set to <%s>"), cs1);
}
m_Device.SetUserDomain( cs1);
// Get BIOS information
if (!m_pSysInfo->getBiosInfo( &m_BIOS))
Expand Down
24 changes: 12 additions & 12 deletions OcsWmi/OcsWmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ BOOL COcsWmi::GetClassObjectVariantValue( LPCTSTR lpstrProperty, VARIANT &pVal)
}


INT_PTR COcsWmi::GetRefElementClassObjectLength( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty)
INT_PTR COcsWmi::GetRefElementClassObjectLength( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag)
{
if (IsWindows8OrGreater())
{
Expand All @@ -503,7 +503,7 @@ INT_PTR COcsWmi::GetRefElementClassObjectLength( LPCTSTR lpstrRefElement, LPCTST
if (csObject.IsEmpty())
return 0;
m_hResult = m_pIWbemServices->GetObject(_bstr_t(csObject),
WBEM_FLAG_RETURN_WBEM_COMPLETE,
m_uFlag,
NULL,
&pClassObject,
NULL);
Expand Down Expand Up @@ -536,7 +536,7 @@ INT_PTR COcsWmi::GetRefElementClassObjectLength( LPCTSTR lpstrRefElement, LPCTST
}
}

BOOL COcsWmi::GetRefElementClassObjectVariantValue( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, VARIANT &pVal)
BOOL COcsWmi::GetRefElementClassObjectVariantValue( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, VARIANT &pVal, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag)
{
ASSERT( m_pClassObject);
ASSERT( lpstrRefElement);
Expand All @@ -556,7 +556,7 @@ BOOL COcsWmi::GetRefElementClassObjectVariantValue( LPCTSTR lpstrRefElement, LPC
if (csObject.IsEmpty())
return FALSE;
m_hResult = m_pIWbemServices->GetObject( _bstr_t( csObject),
WBEM_FLAG_RETURN_WBEM_COMPLETE,
m_uFlag,
NULL,
&pClassObject,
NULL);
Expand Down Expand Up @@ -584,7 +584,7 @@ BOOL COcsWmi::GetRefElementClassObjectVariantValue( LPCTSTR lpstrRefElement, LPC
}


LPCTSTR COcsWmi::GetRefElementClassObjectStringValue(LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty)
LPCTSTR COcsWmi::GetRefElementClassObjectStringValue(LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag)
{
ASSERT( m_pClassObject);
ASSERT( lpstrRefElement);
Expand All @@ -606,7 +606,7 @@ LPCTSTR COcsWmi::GetRefElementClassObjectStringValue(LPCTSTR lpstrRefElement, LP
if (csObject.IsEmpty())
return NULL;
m_hResult = m_pIWbemServices->GetObject( _bstr_t( csObject),
WBEM_FLAG_RETURN_WBEM_COMPLETE,
m_uFlag,
NULL,
&pClassObject,
NULL);
Expand Down Expand Up @@ -638,7 +638,7 @@ LPCTSTR COcsWmi::GetRefElementClassObjectStringValue(LPCTSTR lpstrRefElement, LP
}


DWORD COcsWmi::GetRefElementClassObjectDwordValue(LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty)
DWORD COcsWmi::GetRefElementClassObjectDwordValue(LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag)
{
ASSERT( m_pClassObject);
ASSERT( lpstrRefElement);
Expand All @@ -661,7 +661,7 @@ DWORD COcsWmi::GetRefElementClassObjectDwordValue(LPCTSTR lpstrRefElement, LPCTS
if (csObject.IsEmpty())
return 0;
m_hResult = m_pIWbemServices->GetObject( _bstr_t( csObject),
WBEM_FLAG_RETURN_WBEM_COMPLETE,
m_uFlag,
NULL,
&pClassObject,
NULL);
Expand All @@ -688,7 +688,7 @@ DWORD COcsWmi::GetRefElementClassObjectDwordValue(LPCTSTR lpstrRefElement, LPCTS
}


__int64 COcsWmi::GetRefElementClassObjectI64Value(LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty)
__int64 COcsWmi::GetRefElementClassObjectI64Value(LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag)
{
ASSERT( m_pClassObject);
ASSERT( lpstrRefElement);
Expand All @@ -711,7 +711,7 @@ __int64 COcsWmi::GetRefElementClassObjectI64Value(LPCTSTR lpstrRefElement, LPCTS
if (csObject.IsEmpty())
return 0;
m_hResult = m_pIWbemServices->GetObject( _bstr_t( csObject),
WBEM_FLAG_RETURN_WBEM_COMPLETE,
m_uFlag,
NULL,
&pClassObject,
NULL);
Expand All @@ -738,7 +738,7 @@ __int64 COcsWmi::GetRefElementClassObjectI64Value(LPCTSTR lpstrRefElement, LPCTS
}


unsigned __int64 COcsWmi::GetRefElementClassObjectU64Value(LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty)
unsigned __int64 COcsWmi::GetRefElementClassObjectU64Value(LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag)
{
ASSERT( m_pClassObject);
ASSERT( lpstrRefElement);
Expand All @@ -761,7 +761,7 @@ unsigned __int64 COcsWmi::GetRefElementClassObjectU64Value(LPCTSTR lpstrRefEleme
if (csObject.IsEmpty())
return 0;
m_hResult = m_pIWbemServices->GetObject( _bstr_t( csObject),
WBEM_FLAG_RETURN_WBEM_COMPLETE,
m_uFlag,
NULL,
&pClassObject,
NULL);
Expand Down
12 changes: 6 additions & 6 deletions OcsWmi/OcsWmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ class OCSWMI_API COcsWmi

// Get Length of data in object
INT_PTR GetClassObjectLength( LPCTSTR lpstrProperty);
INT_PTR GetRefElementClassObjectLength( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty);
INT_PTR GetRefElementClassObjectLength( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag);

// Get current enumerated object properties (or properties of an objet referenced by the current enumerated object)
LPCTSTR GetClassObjectStringValue( LPCTSTR lpstrProperty);
LPCTSTR GetRefElementClassObjectStringValue( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty);
LPCTSTR GetRefElementClassObjectStringValue( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag);

DWORD GetClassObjectDwordValue( LPCTSTR lpstrProperty);
DWORD GetRefElementClassObjectDwordValue( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty);
DWORD GetRefElementClassObjectDwordValue( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag);

__int64 GetClassObjectI64Value( LPCTSTR lpstrProperty);
__int64 GetRefElementClassObjectI64Value( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty);
__int64 GetRefElementClassObjectI64Value( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag);

unsigned __int64 GetClassObjectU64Value( LPCTSTR lpstrProperty);
unsigned __int64 GetRefElementClassObjectU64Value( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty);
unsigned __int64 GetRefElementClassObjectU64Value( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag);

BOOL GetClassObjectVariantValue( LPCTSTR lpstrProperty, VARIANT &pVal);
BOOL GetRefElementClassObjectVariantValue( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, VARIANT &pVal);
BOOL GetRefElementClassObjectVariantValue( LPCTSTR lpstrRefElement, LPCTSTR lpstrProperty, VARIANT &pVal, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag);

HRESULT GetLastErrorWMI();

Expand Down
8 changes: 4 additions & 4 deletions SysInfo/SysInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ BOOL CSysInfo::isNotebook()
}


BOOL CSysInfo::getUserName(CString &csUserName)
BOOL CSysInfo::getUserName(CString &csUserName, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag)
{
TCHAR szUserName[255];
DWORD dwUserName = 255;
Expand All @@ -657,7 +657,7 @@ BOOL CSysInfo::getUserName(CString &csUserName)
See https://bugs.launchpad.net/ocsinventory-windows-agent/+bug/1300172
*/
if (m_wmiInfo.IsConnected() && m_wmiInfo.GetLoggedOnUser( csUserName))
if (m_wmiInfo.IsConnected() && m_wmiInfo.GetLoggedOnUser( csUserName, m_uFlag))
return TRUE;
// Call the GetUserName function.
AddLog( _T( "GetUserName: Trying to find logged on User ID from current running process...\n"));
Expand Down Expand Up @@ -862,10 +862,10 @@ BOOL CSysInfo::getDomainOrWorkgroup(CString &csDomain)
return m_registryInfo.GetDomainOrWorkgroup( csDomain);
}

BOOL CSysInfo::getUserDomain(CString &csUserDomain)
BOOL CSysInfo::getUserDomain(CString &csUserDomain, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag)
{
// First, try WMI
if (m_wmiInfo.GetUserDomain( csUserDomain))
if (m_wmiInfo.GetUserDomain( csUserDomain, m_uFlag))
return TRUE;
// Last, use registry
return m_registryInfo.GetDomainOrWorkgroup( csUserDomain);
Expand Down
4 changes: 2 additions & 2 deletions SysInfo/SysInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class SYSINFO_API CSysInfo
BOOL getOS( CString &csName, CString &csVersion, CString &csComment, CString &csDescription, CString &csInstallDate);
DWORD getAddressWidthOS();
BOOL getDomainOrWorkgroup( CString &csDomain);
BOOL getUserDomain( CString &csUserDomain);
BOOL getUserDomain( CString &csUserDomain, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag);

// Memory information
BOOL getMemory( ULONG *m_ulPhysicalMemory, ULONG *m_ulSwapSize);
Expand All @@ -133,7 +133,7 @@ class SYSINFO_API CSysInfo
BOOL isNotebook();

// User information
BOOL getUserName( CString &csUserName);
BOOL getUserName( CString &csUserName, tag_WBEM_GENERIC_FLAG_TYPE m_uFlag);
BOOL getUserNameFromExplorerProcess( CString &csUserName);

// Last user logged in the system
Expand Down
Loading

0 comments on commit 1c655f8

Please sign in to comment.