📄 snmpeldl.cpp
字号:
{
WriteTrace(0x00,"Read_Registry_Parameters: ThresholdCount parameter found in registry of %lu.\n",
dwThresholdCount);
if (dwThresholdCount < 2)
{
WriteTrace(0x00,"Read_Registry_Parameters: ThresholdCount is an invalid value -- a minimum of 2 is used.\n");
dwThresholdCount = 2;
WriteLog(SNMPELEA_REGISTRY_LOW_THRESHOLDCOUNT_PARAMETER, dwThresholdCount);
}
}
WriteTrace(0x00,"Read_Registry_Parameters: Checking ThresholdTime parameter read from registry\n");
if ( !fThresholdTimeFlg )
{
WriteTrace(0x00,"Read_Registry_Parameters: ThresholdTime parameter not found in registry, defaulting to %lu.\n",
THRESHOLD_TIME);
dwThresholdTime = THRESHOLD_TIME;
}
else
{
WriteTrace(0x00,"Read_Registry_Parameters: ThresholdTime parameter found in registry of %lu.\n",
dwThresholdTime);
if (dwThresholdTime < 1)
{
WriteTrace(0x00,"Read_Registry_Parameters: ThresholdTime is an invalid value -- a minimum of 1 is used.\n");
dwThresholdTime = 1;
WriteLog(SNMPELEA_REGISTRY_LOW_THRESHOLDTIME_PARAMETER, dwThresholdTime);
}
}
if ( (fThresholdEnabled && !fThreshold && fThresholdOff) ||
(!fThresholdEnabled && fThresholdOff) )
{
WriteTrace(0x0a,"Read_Registry_Parameters: Threshold values have been reset. Trap processing resumed.\n");
WriteLog(SNMPELEA_THRESHOLD_RESUMED);
if (fLogInit)
{
for (DWORD inum = 0; inum < uNumEventLogs; inum++)
{
Position_to_Log_End(phEventLogs[inum]);
}
}
}
if ( fThresholdEnabled && fThreshold && !fThresholdOff )
{
WriteTrace(0x0a,"Read_Registry_Parameters: Threshold values have been set. Trap processing will not be done.\n");
WriteLog(SNMPELEA_THRESHOLD_SET);
}
WriteTrace(0x00,"Read_Registry_Parameters: BaseEnterpriseOID is %s\n", szBaseOID);
WriteTrace(0x00,"Read_Registry_Parameters: SupportedView is %s\n", szSupView);
WriteTrace(0x00,"Read_Registry_Parameters: Global TrimFlag value is %lu (trim yes/no)\n", fTrimFlag);
WriteTrace(0x00,"Read_Registry_Parameters: Global TrimMessage value is %lu (trim msg/ins str first)\n", fGlobalTrim);
if (fLogInit)
{
WriteTrace(0x00,"Read_Registry_Parameters: Reread of registry parameters is complete\n");
WriteTrace(0x0a,"Read_Registry_Parameters: Exiting Read_Registry_Parameters with TRUE\n");
return(TRUE);
}
fLogInit = TRUE; // indicate not to read log information again
WriteTrace(0x0a,"Read_Registry_Parameters: Opening %s\n", EVENTLOG_BASE);
if ((status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, EVENTLOG_BASE, 0,
(KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS), &hkResult))
!= ERROR_SUCCESS) // open for log names
{
WriteTrace(0x14,"Read_Registry_Parameters: Error in RegOpenKeyEx for EventLog = %lu\n",
status);
WriteLog(SNMPELEA_NO_REGISTRY_LOG_NAME, status); // log error message
return(FALSE); // if error, service stop
}
iValue = 0; // read first parameter
parmSize = MAX_PATH; // maximum parameter size
while ((status = RegEnumKey(hkResult, iValue, (char *) &parm, parmSize)) != ERROR_NO_MORE_ITEMS)
{ // read until no more entries
if (status != ERROR_SUCCESS) // if error during read
{
WriteTrace(0x14,"Read_Registry_Parameters: Error reading registry value is %lu for index %lu (EventLogFiles)\n",
status, iValue); // show error information
WriteLog(SNMPELEA_ERROR_REGISTRY_LOG_NAME_ENUMERATE, status, iValue); // log the error message
RegCloseKey(hkResult); // close registry
return(FALSE); // indicate service stop
}
// MikeCure 4/3/98 hotfix for SMS Bug1 #20521
//===========================================
EnablePrivilege();
hLogFile = OpenEventLog( (LPTSTR) NULL, parm);
if (hLogFile == NULL)
{ // did log file open?
lastError = GetLastError(); // save error code
WriteTrace(0x14,"Read_Registry_Parameters: Error in EventLogOpen = %lu\n",
lastError);
WriteTrace(0x14,"Read_Registry_Parameters: Log file name: %s\n",parm);
WriteLog(SNMPELEA_ERROR_OPEN_EVENT_LOG, parm, lastError); // log the error message
continue; // failed -- forget this one
}
if ( !Position_to_Log_End(hLogFile) )
{
WriteTrace(0x14,"Read_Registry_Parameters: Unable to position to end of log. DLL terminated.\n");
WriteLog(SNMPELEA_ERROR_LOG_END);
WriteLog(SNMPELEA_ABNORMAL_INITIALIZATION);
return(FALSE); // exit with error
}
phEventLogs = (PHANDLE) SNMP_realloc( (LPVOID) phEventLogs,
(uNumEventLogs+1) * sizeof(HANDLE));
// reallocate array space
if (phEventLogs == (PHANDLE) NULL)
{
WriteTrace(0x14,"Read_Registry_Parameters: Unable to reallocate log event array\n");
WriteLog(SNMPELEA_REALLOC_LOG_EVENT_ARRAY);
return(FALSE); // exit with error
}
WriteTrace(0x00,"Read_Registry_Parameters: Event log array reallocated at %08X\n",
phEventLogs);
*(phEventLogs+uNumEventLogs) = hLogFile; // save handle
lpszEventLogs = (LPTSTR) SNMP_realloc( (LPVOID) lpszEventLogs,
iLogNameSize + MAX_PATH + 1 );
if (lpszEventLogs == (LPTSTR) NULL)
{
WriteTrace(0x14,"Read_Registry_Parameters: Unable to reallocate log name array\n");
WriteLog(SNMPELEA_REALLOC_LOG_NAME_ARRAY);
return(FALSE); // exit with error
}
WriteTrace(0x00,"Read_Registry_Parameters: Event log name array reallocated at %p\n",
lpszEventLogs);
iLogNameSize += MAX_PATH + 1;
strcpy(lpszEventLogs+uNumEventLogs*(MAX_PATH+1), parm);
phPrimHandles = (PHMODULE) SNMP_realloc( (LPVOID) phPrimHandles,
(uNumEventLogs+1) * sizeof(HANDLE));
// reallocate array space
if (phPrimHandles == (PHMODULE) NULL)
{
WriteTrace(0x14,"Read_Registry_Parameters: Unable to reallocate PrimaryModule handle array\n");
WriteLog(SNMPELEA_REALLOC_PRIM_HANDLE_ARRAY);
return(FALSE); // exit with error
}
WriteTrace(0x00,"Read_Registry_Parameters: PrimaryModule handle array reallocated at %08X\n",
phPrimHandles);
parmSize = MAX_PATH; // reset to maximum
strcpy(lpszLog, EVENTLOG_BASE); // copy base registry name
strcat(lpszLog, parm); // add on the log file name read
WriteTrace(0x0a,"Read_Registry_Parameters: Opening registry for PrimaryModule for %s\n", lpszLog);
if ( (status = RegOpenKeyEx( // open the registry to read the name
HKEY_LOCAL_MACHINE, // of the message module DLL
lpszLog, // registry key to open
0,
KEY_READ,
&hkResult2) ) != ERROR_SUCCESS)
{
WriteTrace(0x14,"Read_Registry_Parameters: Unable to open EventLog service registry key %s; RegOpenKeyEx returned %lu\n",
lpszLog, status); // write trace event record
WriteLog(SNMPELEA_CANT_OPEN_REGISTRY_PARM_DLL, lpszLog, status);
WriteTrace(0x0a,"Read_Registry_Parameters: Exiting Read_Registry_Parameters with FALSE\n");
return(FALSE); // return
}
if ( (status = RegQueryValueEx( // look up module name
hkResult2, // handle to registry key
EXTENSION_PRIM_MODULE, // key to look up
0, // ignored
&dwType, // address to return type value
(LPBYTE) parm, // where to return message module name
&parmSize) ) != ERROR_SUCCESS) // size of message module name field
{
WriteTrace(0x14,"Read_Registry_Parameters: No PrimaryModule registry key for %s; RegQueryValueEx returned %lu\n",
lpszEventLogs+uNumEventLogs*(MAX_PATH+1), status); // write trace event record
*(phPrimHandles+uNumEventLogs) = (HMODULE) NULL;
}
else
{
DWORD retCode;
tPrimaryModuleParms PMParams;
PMParams.dwParams = PMP_PARAMMSGFILE;
retCode = LoadPrimaryModuleParams(hkResult2, parm, PMParams);
if (retCode != ERROR_SUCCESS)
{
WriteTrace(0x14, "Read_Registry_Parameters: LoadPrimaryModuleParams failed with errCode = %lu\n", retCode);
*(phPrimHandles+uNumEventLogs) = NULL;
}
else
*(phPrimHandles+uNumEventLogs) = PMParams.hModule;
}
RegCloseKey(hkResult2); // close registry key
WriteTrace(0x00,"Read_Registry_Parameters: Log file name is %s\n",
lpszEventLogs+uNumEventLogs*(MAX_PATH+1));
WriteTrace(0x00,"Read_Registry_Parameters: Log handle #%lu is %08X\n",
uNumEventLogs,hLogFile);
WriteTrace(0x00,"Read_Registry_Parameters: PrimaryModule handle #%lu is %08X\n",
uNumEventLogs,*(phPrimHandles+uNumEventLogs));
uNumEventLogs++;
parmSize = MAX_PATH; // reset to maximum
iValue++; // read next parameter
} // end while
RegCloseKey(hkResult); // close registry info
WriteTrace(0x00,"Read_Registry_Parameters: Number of handles acquired is %lu\n",
uNumEventLogs);
for (uVal = 0; uVal < uNumEventLogs; uVal++)
{
WriteTrace(0x00,"Read_Registry_Parameters: Handle # %lu\t%08X\t%s\n", uVal,
*(phEventLogs+uVal), lpszEventLogs+uVal*(MAX_PATH+1));
}
if (uNumEventLogs) // if we have logs opened
{
return(TRUE); // then we can say all okay
}
else
{
WriteTrace(0x14,"Read_Registry_Parameters: Registry contains no log file entries to process\n");
//WriteLog(SNMPELEA_NO_REGISTRY_EVENT_LOGS); // log error message
return(FALSE); // if not, then not okay
}
} // request stop
}
//nadir
VOID
CloseSourceHandles(VOID)
{
PSourceHandleList lpSource;
UINT lastError;
lpSource = lpSourceHandleList;
while (lpSource != (PSourceHandleList)NULL)
{
if ( !FreeLibrary(lpSource->handle) ) // free msg dll
{
lastError = GetLastError(); // get error code
WriteTrace(0x14,"CloseSourceHandles: Error freeing message dll is %lu.\n", lastError);
WriteLog(SNMPELEA_ERROR_FREEING_MSG_DLL, lastError);
}
lpSourceHandleList = lpSource->Next;
SNMP_free(lpSource);
lpSource = lpSourceHandleList;
}
}
//nadir
extern "C" {
BOOL
APIENTRY
DllMain(
IN HANDLE hDll,
IN DWORD dwReason,
IN LPVOID lpReserved
)
/*++
Routine Description:
SNMPEventLogDllMain is the dll initialization and termination routine.
Once this termination request is received, the appropriate events will be
signaled, notifying the subordinate threads that they should terminate
to accomodate service termination.
Arguments:
hDll - Handle to the DLL. Unreferenced.
dwReason - Reason this routine was entered (process/thread attach/detach).
lpReserved - Reserved. Unreferenced.
Return Value:
TRUE - If initialization or termination was successful.
FALSE - If initialization or termination was unsuccessful.
--*/
{
DWORD lastError; // to save GetLastError() return code
UNREFERENCED_PARAMETER(hDll);
UNREFERENCED_PARAMETER(lpReserved);
WriteTrace(0x0a,"SNMPEventLogDllMain: Entering SNMPEventLogDllMain routine.....\n");
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
WriteTrace(0x0a,"SNMPEventLogDllMain: Reason code indicates process attach\n");
if ( (hWriteEvent = RegisterEventSource(
(LPTSTR) NULL,
EVNTAGNT_NAME) )
== NULL)
{
WriteTrace(0x20,"SNMPEventLogDllMain: Unable to log application events; code is %lu\n",
GetLastError() );
WriteTrace(0x20,"SNMPEventLogDllMain: SNMP Event Log Extension Agent DLL initialization abnormal termination\n");
WriteTrace(0x0a,"SNMPEventLogDllMain: Exiting SNMPEventLogDllMain routine with FALSE\n");
return(FALSE); // error initializing
}
WriteTrace(0x14,"SNMPEventLogDllMain: SNMP Event Log Extension Agent DLL is starting\n");
WriteLog(SNMPELEA_STARTED);
WriteTrace(0x0a,"SNMPEventLogDllMain: Creating event for extension DLL shutdown\n");
if ( (hStopAll= CreateEvent(
(LPSECURITY_ATTRIBUTES) NULL,
FALSE,
FALSE,
(LPTSTR) NULL)) == NULL)
{
lastError = GetLastError(); // save error status
WriteTrace(0x14,"SNMPEventLogDllMain: Error creating stop extension DLL event; code %lu\n",
lastError);
WriteLog(SNMPELEA_ERROR_CREATING_STOP_AGENT_EVENT, lastError);
WriteTrace(0x14,"SNMPEventLogDllMain: SNMPELEA DLL abnormal initialization\n");
WriteLog(SNMPELEA_ABNORMAL_INITIALIZATION); // log error message
WriteTrace(0x0a,"SNMPEventLogDllMain: Exiting SNMPEventLogDllMain routine with FALSE\n");
return(FALSE);
}
WriteTrace(0x00,"SNMPEventLogDllMain: Extension DLL shutdown event handle is %08X\n",
hStopAll);
break;
case DLL_PROCESS_DETACH:
WriteTrace(0x0a,"SNMPEventLogDllMain: Reason code indicates process detach\n");
break;
case DLL_THREAD_ATTACH:
WriteTrace(0x0a,"SNMPEventLogDllMain: Reason code indicates thread attach\n");
break;
case DLL_THREAD_DETACH:
WriteTrace(0x0a,"SNMPEventLogDllMain: Reason code indicates thread detach\n");
break;
default:
WriteTrace(0x0a,"SNMPEventLogDllMain: Unknown reason code indicated in SNMPEventLogDllMain\n");
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -