#include-once ; ============================================================================================================================================== ; McAfee Endpoint Encryption AutoIt Module ; ============================================================================================================================================== ; Script Version: 0.2 (Beta) ; AutoIt Version: 3.0 ; Language: English ; Description: Functions that assist with querying the McAfee Endpoint Encryption Database ; http://www.TechnicallyChris.com/ ; 22-Feb-2009: Created Registration and Unregistration Modules for SbAdmCom.Dll ; Created Connection and Disconnection Functions for Database ; Created Execution Function to Execute a Command and Return a Simple Result or XML Dump. ; 27-May-2009: Removed Requirement for Connection to Database to Invoke _EEPCExecute for commands like GetCryptState ; XMLDomWrapper is required to use this module. Thanks to eltorro (http://www.autoitscript.com/forum/index.php?showtopic=19848). ; This does not come with AutoIt and will need to be downloaded. #Include <_XMLDomWrapper.au3> ; Create Global COM Object Global $objAdmCL = objCreate("SbAdmCom.SbAdmScripting") Func _EEPCRegisterCOM($fPath = "c:\program files\mcafee\Endpoint Encryption for PC\sbadmcom.dll", $regPath = "") ; This function registers the SbAdmCom.dll. This needs to happen at least once on a machine before ; the COM functions used by this script can be executed. ; fPath = Path to SbAdmCom.dll ; regPath = Path to REGSVR32.exe (should be fine as default) ; RETURNS: NULL, check @error for status. ; @error = 0 - Successfully able to connect to object. ; = 1 - Unable to find SBADMCOM.DLL FILE ; = 2 - Unable to find REGSVR32.EXE FILE ; = 3 - Error returned running REGSVR32.EXE (try to register manually) ; = 4 - Still cannot connect after registration if $regPath = "" then $regPath = @WindowsDir & "\System32\regsvr32.exe" if not fileexists($fPath) then return seterror(1) if not fileexists($regPath) then return seterror(2) $reg = ShellExecuteWait($regPath,"/s " & chr(34) & $fPath & chr(34)) if $reg <> 0 then return seterror(3) Global $objAdmCL = objCreate("SbAdmCom.SbAdmScripting") if isobj($objAdmCl) then seterror(0) Else seterror(4) Endif EndFunc Func _EEPCUnregisterCOM($fPath = "c:\program files\mcafee\Endpoint Encryption for PC\sbadmcom.dll", $regPath = "") ; This function unregisters the SbAdmCom.dll. There should be no need to do this during and is provided ; for testing only. Unregistering this file will stop any scripts created with this module from working ; as well as any others that use the COM Object. ; fPath = Path to SbAdmCom.dll ; regPath = Path to REGSVR32.exe (should be fine as default) ; RETURNS: NULL, check @error for status. ; @error = 0 - No longer able to connect to the object ; = 1 - Unable to find SBADMCOM.DLL FILE ; = 2 - Unable to find REGSVR32.EXE FILE ; = 3 - Error returned running REGSVR32.EXE (try to unregister manually) ; = 4 - Still can connect after unregistering if $regPath = "" then $regPath = @WindowsDir & "\System32\regsvr32.exe" if not fileexists($fPath) then return seterror(1) if not fileexists($regPath) then return seterror(2) $reg = ShellExecuteWait($regPath,"/u /s " & chr(34) & $fPath & chr(34)) if $reg <> 0 then return seterror(3) Global $objAdmCL = objCreate("SbAdmCom.SbAdmScripting") if isobj($objAdmCl) then seterror(4) Else seterror(0) Endif EndFunc Func _EEPCConnect($adminUser, $adminPassword, $auth = false, $database = "") ; This function creates the connection to the database. The result of this function should be used ; when sending commands to the database, or closing the connection before ending your script. ; adminUser = Username to Database ; adminPassword = Password to Database ; auth = Use adminAuth instead of adminPwd ; database = Name of Database, use blank for Default ; RETURNS: Connection Reference ID or -1 if error ; @error = 1 - Unable to Use Object (SbAdmCom.SbAdmScripting) ; = 2 - Unable to make a connection. Text Error Returned to Console. ; Check if Object is Value, Error if not if not isObj($objAdmCl) then return seterror(1,0,-1) EndIf ; Build Connection XML Statement $xml = "" $xml = $xml & "" $xml = $xml & " " $xml = $xml & " " $xml = $xml & " Persistent.New" $xml = $xml & " UserNamePassword" $xml = $xml & " " & $adminUser & "" if $auth = false Then ; If Not Using AdminAuth, Set Password in Plain Text $xml = $xml & " " & $adminPassword & "" Else ; If Using AdminAuth, Set Auth in Scrambled Text $xml = $xml & " " & $adminPassword & "" EndIf $xml = $xml & " " $xml = $xml & " " $xml = $xml & "" ; Make the Connection $connection = $objAdmCL.execute($xml) ; Load the Results in the XML Parser $ret = _XMLLoadXML($connection) ; Get the Error Code of the Connection $rCode = _XMLGetValue("/SafeBoot/SbAdminScripting/SbAdminConnectionResult/ResultCode") if $rCode[1] <> "0x00000000" Then ; Connection Failed, Return Error. $desc = _XMLGetValue("/SafeBoot/SbAdminScripting/SbAdminConnectionResult/ResultDescription") ConsoleWriteError("ERROR CONNECTING: " & $rCode[1] & " : " & $desc[1] & @CRLF) return SetError(2,0,-1) EndIf ; Get the Connection Reference $rCode = _XMLGetValue("/SafeBoot/SbAdminScripting/SbAdminConnectionResult/ConnectionRef") return $rCode[1] EndFunc Func _EEPCDisconnect($connection) ; This function closes the connection to the database. You can use this to free-up the connection ; to the database when you are done with your script. You will not be able to execute any further ; commands to the database using your script until a new connection is opened. ; Testing shows that when the AutoIt scripts end, the connection is closed when the COM Object is ; destroyed even if this function is never called. ; connection = Name of Connection Created with _EEPCConnect ; RETURNS: "" ; @error = 1 - Unable to Use Object (SbAdmCom.SbAdmScripting) ; = 2 - Unable to disconnect. Text Error Returned to Console. ; Check if Object is Value, Error if not if not isObj($objAdmCl) then return seterror(1,0,-1) EndIf ; Build Disconnection XML Statement $xml = "" $xml = $xml & "" $xml = $xml & " " $xml = $xml & " " $xml = $xml & " Persistent.Close" $xml = $xml & " " & $connection & "" $xml = $xml & " " $xml = $xml & " " $xml = $xml & "" ; Make the Disconnection $connection = $objAdmCL.execute($xml) ; Load the Results in the XML Parser $ret = _XMLLoadXML($connection) ; Get the Error Code of the Connection $rCode = _XMLGetValue("/SafeBoot/SbAdminScripting/SbAdminConnectionResult/ResultCode") if $rCode[1] <> "0x00000000" Then ; Disconection Failed, Return Error. $desc = _XMLGetValue("/SafeBoot/SbAdminScripting/SbAdminConnectionResult/ResultDescription") ConsoleWriteError("ERROR DISCONNECTING: " & $rCode[1] & " : " & $desc[1] & @CRLF) return SetError(2,0,-1) EndIf return "" EndFunc Func _EEPCExecute($connection, $command, $params="", $result="ResultCode") ; connection = Connection Reference Created Using _EEPCConnect ; If blank, executes command without connecting to database. ; command = Command to Execute ; params = 2D Array of Parameters to Pass where the 0 = ParamName and 1 = ParamValue. ; Example: ; $params[0][0] = "User" ; $params[0][1] = "testuser" ; $params[0][0] = "Group" ; $params[0][1] = "Users - Default" ; result = Name of return parameter to return using _EEPCExecute (Default: ResultCode). ; This will only work when there is only a single easily read result to report ; back. Use an empty result string to get an XML dump of the return to parse ; in the calling program. ; RETURNS: Result Requested in $result variable or -1 if error ; @error = 1 - Unable to Use Object (SbAdmCom.SbAdmScripting) ; = 2 - Unable to make a connection. Text Error Returned to Console. ; = 3 - Command Returned Error. Text Returned as Parameter ; Check if Object is Value, Error if not if not isObj($objAdmCl) then return seterror(1,0,-1) EndIf ; Build Connection XML Statement $xml = "" $xml = $xml & "" $xml = $xml & " " if $connection <> "" then $xml = $xml & " " $xml = $xml & " Persistent.Use" $xml = $xml & " " & $connection & "" $xml = $xml & " " EndIf $xml = $xml & " " $xml = $xml & " " & $command & "" if $params <> "" and isarray($params) Then for $iP = 0 to ubound($params)-1 $xml = $xml & "<" & $params[$ip][0] & ">" & $params[$ip][1] & "" next Endif $xml = $xml & " " $xml = $xml & " " $xml = $xml & "" ; ConsoleWrite($xml) ; Execute the Command $e = $objAdmCL.execute($xml) ; Load the Results in the XML Parser $ret = _XMLLoadXML($e) ; Get the Error Code of the Connection $rCode = _XMLGetValue("/SafeBoot/SbAdminScripting/SbAdminConnectionResult/ResultCode") if $rCode[1] <> "0x00000000" Then ; Connection Failed, Return Error. $desc = _XMLGetValue("/SafeBoot/SbAdminScripting/SbAdminConnectionResult/ResultDescription") ConsoleWriteError("ERROR CONNECTING: " & $rCode[1] & " : " & $desc[1] & @CRLF) return SetError(2,0,-1) EndIf ; Get the Error Code of the Command $rCode = _XMLGetValue("/SafeBoot/SbAdminScripting/SbAdminCommandResult/ResultCode") if $rCode[1] <> "0x00000000" Then ; Command Failed, Return Error. Will still return command result array. $commandFail = True Else $commandFail = false EndIf if $result <> "" then ; Get the Value of the Desired Command from $result $rCode = _XMLGetValue("/SafeBoot/SbAdminScripting/SbAdminCommandResult/" & $result) if $commandFail = true Then return setError(3,0,$rCode[1]) Else return $rCode[1] endif Else ; Dump XML Data if $commandFail = true Then return setError(3,0,$e) Else return $e endif EndIf EndFunc