Skip to content

Commit

Permalink
Merge pull request #234 from OCSInventory-NG/winlib
Browse files Browse the repository at this point in the history
Add WMI_FLAG_MODE configuration + DEFAULT_USER_DOMAIN
  • Loading branch information
gillesdubois authored Feb 7, 2022
2 parents 4259797 + 1c655f8 commit 63ddaf7
Show file tree
Hide file tree
Showing 14 changed files with 302 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;
}
76 changes: 76 additions & 0 deletions NSIS_agent_setup/Agent2.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
; Ini file generated by the HM NIS Edit IO designer.
[Settings]
NumFields=9

[Field 1]
Type=Groupbox
Text=WMI options...
Left=0
Right=300
Top=3
Bottom=102

[Field 2]
Type=Label
Text=Behavior of WMI calls :
Left=9
Right=85
Top=17
Bottom=27

[Field 3]
Type=Label
Text=Default user domain :
Left=9
Right=78
Top=81
Bottom=96

[Field 4]
Type=Text
Left=80
Right=290
Top=80
Bottom=92

[Field 5]
Type=Label
Text=COMPLETE: Allow WMI to retrieve current domain user
Left=9
Right=285
Top=32
Bottom=40

[Field 6]
Type=Label
Text=If the WMI does not allow the recovery of the current user
Left=9
Right=292
Top=54
Bottom=64

[Field 7]
Type=Label
Text=READ: Not allow
Left=9
Right=62
Top=41
Bottom=49

[Field 8]
Type=Label
Text=which default user should OCS return ?
Left=9
Right=132
Top=65
Bottom=73

[Field 9]
Type=Droplist
State=COMPLETE
ListItems=COMPLETE|READ
Left=88
Right=290
Top=14
Bottom=107

36 changes: 36 additions & 0 deletions NSIS_agent_setup/OCS-NG_Windows_Agent_Setup_x64.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ ICON "install-ocs.ico"
Page custom AskServerOptions ValidateServerOptions ""
Page custom AskProxyOptions ValidateProxyOptions ""
Page custom AskAgentOptions ValidateAgentOptions ""
Page custom AskAgent2Options ValidateAgent2Options ""
; Where to save inventory result when /LOCAL is used
Page custom AskLocalInventory ValidateLocalInventory ""
; Directory page
Expand Down Expand Up @@ -529,6 +530,22 @@ ParseCmd_NoTag_End:
; Remove parsed arg from command line
${WordReplace} '$9' '/TAG=$R0' "" "+" $R1
StrCpy $9 $R1
; /WMI_FLAG_MODE="value"
${GetOptions} '$9' '/WMI_FLAG_MODE=' $R0
IfErrors 0 +2
StrCpy $R0 "COMPLETE"
WriteINIStr "$PLUGINSDIR\agent2.ini" "Field 9" "State" "$R0"
; Remove parsed arg from command line
${WordReplace} '$9' '/WMI_FLAG_MODE=$R0' "" "+" $R1
StrCpy $9 $R1
; /DEFAULT_USER_DOMAIN="value"
${GetOptions} '$9' '/DEFAULT_USER_DOMAIN=' $R0
IfErrors 0 +2
StrCpy $R0 ""
WriteINIStr "$PLUGINSDIR\agent2.ini" "Field 4" "State" "$R0"
; Remove parsed arg from command line
${WordReplace} '$9' '/DEFAULT_USER_DOMAIN=$R0' "" "+" $R1
StrCpy $9 $R1
; No service
${GetOptions} '$9' '/NO_SERVICE' $R0
IfErrors 0 ParseCmd_NoService
Expand Down Expand Up @@ -1081,6 +1098,14 @@ WriteServiceIni_Skip_NoTag:
ReadINIStr $R0 "$PLUGINSDIR\agent.ini" "Field 6" "State"
StrCpy $R1 '$R2 /TAG="$R0"'
StrCpy $R2 $R1
; WMI_FLAG_MODE
ReadINIStr $R0 "$PLUGINSDIR\agent2.ini" "Field 9" "State"
StrCpy $R1 '$R2 /WMI_FLAG_MODE="$R0"'
StrCpy $R2 $R1
; DEFAULT_USER_DOMAIN
ReadINIStr $R0 "$PLUGINSDIR\agent2.ini" "Field 4" "State"
StrCpy $R1 '$R2 /DEFAULT_USER_DOMAIN="$R0"'
StrCpy $R2 $R1
; No Service
ReadINIStr $R0 "$PLUGINSDIR\agent.ini" "Field 7" "State"
StrCmp $R0 "1" 0 WriteServiceIni_Skip_NoService
Expand Down Expand Up @@ -1162,6 +1187,7 @@ not_running:
File /oname=$PLUGINSDIR\server.ini "server.ini"
File /oname=$PLUGINSDIR\proxy.ini "proxy.ini"
File /oname=$PLUGINSDIR\agent.ini "agent.ini"
File /oname=$PLUGINSDIR\agent2.ini "agent2.ini"
File /oname=$PLUGINSDIR\local.ini "local.ini"
File /oname=$PLUGINSDIR\splash.bmp "Banner-ocs.bmp"
File /oname=$PLUGINSDIR\SetACL.exe "SetACL.exe"
Expand Down Expand Up @@ -1360,6 +1386,16 @@ FunctionEnd
Function ValidateAgentOptions
FunctionEnd

Function AskAgent2Options
${If} ${SectionIsSelected} 3 ; Index of Network inventory section
!insertmacro MUI_HEADER_TEXT "OCS Inventory NG Agent for Windows properties" "If needed, specify OCS Inventory NG Agent options..."
InstallOptions::dialog "$PLUGINSDIR\agent2.ini"
${EndIf}
FunctionEnd

Function ValidateAgent2Options
FunctionEnd

Function AskLocalInventory
${If} ${SectionIsSelected} 4 ; Index of Local inventory section
!insertmacro MUI_HEADER_TEXT "OCS Inventory Agent for Windows" "Choose folder to save inventory result..."
Expand Down
36 changes: 36 additions & 0 deletions NSIS_agent_setup/OCS-NG_Windows_Agent_Setup_x86.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ ICON "install-ocs.ico"
Page custom AskServerOptions ValidateServerOptions ""
Page custom AskProxyOptions ValidateProxyOptions ""
Page custom AskAgentOptions ValidateAgentOptions ""
Page custom AskAgent2Options ValidateAgent2Options ""
; Where to save inventory result when /LOCAL is used
Page custom AskLocalInventory ValidateLocalInventory ""
; Directory page
Expand Down Expand Up @@ -529,6 +530,22 @@ ParseCmd_NoTag_End:
; Remove parsed arg from command line
${WordReplace} '$9' '/TAG=$R0' "" "+" $R1
StrCpy $9 $R1
; /WMI_FLAG_MODE="value"
${GetOptions} '$9' '/WMI_FLAG_MODE=' $R0
IfErrors 0 +2
StrCpy $R0 "COMPLETE"
WriteINIStr "$PLUGINSDIR\agent2.ini" "Field 9" "State" "$R0"
; Remove parsed arg from command line
${WordReplace} '$9' '/WMI_FLAG_MODE=$R0' "" "+" $R1
StrCpy $9 $R1
; /DEFAULT_USER_DOMAIN="value"
${GetOptions} '$9' '/DEFAULT_USER_DOMAIN=' $R0
IfErrors 0 +2
StrCpy $R0 ""
WriteINIStr "$PLUGINSDIR\agent2.ini" "Field 4" "State" "$R0"
; Remove parsed arg from command line
${WordReplace} '$9' '/DEFAULT_USER_DOMAIN=$R0' "" "+" $R1
StrCpy $9 $R1
; No service
${GetOptions} '$9' '/NO_SERVICE' $R0
IfErrors 0 ParseCmd_NoService
Expand Down Expand Up @@ -1037,6 +1054,14 @@ WriteServiceIni_Skip_NoTag:
ReadINIStr $R0 "$PLUGINSDIR\agent.ini" "Field 6" "State"
StrCpy $R1 '$R2 /TAG="$R0"'
StrCpy $R2 $R1
; WMI_FLAG_MODE
ReadINIStr $R0 "$PLUGINSDIR\agent2.ini" "Field 9" "State"
StrCpy $R1 '$R2 /WMI_FLAG_MODE="$R0"'
StrCpy $R2 $R1
; DEFAULT_USER_DOMAIN
ReadINIStr $R0 "$PLUGINSDIR\agent2.ini" "Field 4" "State"
StrCpy $R1 '$R2 /DEFAULT_USER_DOMAIN="$R0"'
StrCpy $R2 $R1
; No Service
ReadINIStr $R0 "$PLUGINSDIR\agent.ini" "Field 7" "State"
StrCmp $R0 "1" 0 WriteServiceIni_Skip_NoService
Expand Down Expand Up @@ -1111,6 +1136,7 @@ not_running:
File /oname=$PLUGINSDIR\server.ini "server.ini"
File /oname=$PLUGINSDIR\proxy.ini "proxy.ini"
File /oname=$PLUGINSDIR\agent.ini "agent.ini"
File /oname=$PLUGINSDIR\agent2.ini "agent2.ini"
File /oname=$PLUGINSDIR\local.ini "local.ini"
File /oname=$PLUGINSDIR\splash.bmp "Banner-ocs.bmp"
File /oname=$PLUGINSDIR\SetACL.exe "SetACL.exe"
Expand Down Expand Up @@ -1309,6 +1335,16 @@ FunctionEnd
Function ValidateAgentOptions
FunctionEnd

Function AskAgent2Options
${If} ${SectionIsSelected} 3 ; Index of Network inventory section
!insertmacro MUI_HEADER_TEXT "OCS Inventory NG Agent for Windows properties" "If needed, specify OCS Inventory NG Agent options..."
InstallOptions::dialog "$PLUGINSDIR\agent2.ini"
${EndIf}
FunctionEnd

Function ValidateAgent2Options
FunctionEnd

Function AskLocalInventory
${If} ${SectionIsSelected} 4 ; Index of Local inventory section
!insertmacro MUI_HEADER_TEXT "OCS Inventory NG Agent for Windows" "Choose folder to save inventory result..."
Expand Down
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
Loading

0 comments on commit 63ddaf7

Please sign in to comment.