📄 snmpeldl.cpp
字号:
/*++
Copyright (c) 1994 Microsoft Corporation
Module Name:
SNMPELDL.CPP
Abstract:
This module is the main extension agent DLL for the SNMP Event Log
Extension Agent DLL.
Standard tracing and logging routines are defined in this module.
DLL initialization and termination routines are defined here.
SNMP trap initialization and processing is defined here.
Spawning of the log processing thread is done in this routine.
Author:
Randy G. Braze (Braze Computing Services) Created 16 October 1994
Revision History:
9 Feb 99 FlorinT: Removed warning event logs on startup (when registry parameters are not found)
16 Dec 98 FlorinT: Added LoadPrimaryModuleParams and 'EALoad.*' files
1 Dec 98 FlorinT: Remove psupportedView - it is freed by the SNMP master agent
7 Feb 96 Moved tracing and logging to separate module.
Restructured building of varbinds to be outside of trap generation.
Calculated trap buffer length correctly.
Created varbind queue and removed event log buffer queue.
28 Feb 96 Added code to support a performance threshold reached indicator.
Removed pointer references to varbindlist and enterpriseoid.
10 Mar 96 Removed OemToChar coding and registry checking.
Modifications to read log file names from EventLog registry entries and not
from specific entries in the SNMP Extension Agent's registry entries.
Included SnmpMgrStrToOid as an internal function, as opposed to using the function
provided by MGMTAPI.DLL. SNMPTRAP.EXE will be called if MGMTAPI is called, which
will disable other agents from being able to receive any traps. All references
to MGMTAPI.DLL and MGMTAPI.H will be removed.
Added a ThresholdEnabled flag to the registry to indicate if the threshold values
were to be monitored or ignored.
13 Mar 96 Modified StrToOid routine to append the BaseEnterpriseOID to the specified string
if the string passed does not start with a period. Otherwise, the string is
converted as normal.
Changed TraceFileName parameter in the registry from REG_SZ to REG_EXPAND_SZ.
Modified registry reading routine to accept REG_EXPAND_SZ parameters.
Added additional tracing.
07 May 96 Removed SnmpUtilOidFree and use two SNMP_free. One for the OID's ids array and
one for the OID itself. Also added psupportedView to free memory at exit.
26 Jun 96 Modified the StrToOid function such that strings without leading "." have the base
OID appended instead of strings with a leading ".".
--*/
extern "C"
{
#include <stdlib.h>
#include <windows.h> // windows definitions
#include <string.h> // string declarations
#include <snmp.h> // snmp definitions
#include <snmpexts.h> // extension agent definitions
#include "snmpelea.h" // global dll definitions
#include "snmpeldl.h" // module specific definitions
#include "snmpelmg.h" // message definitions
}
extern VOID FreeVarBind(UINT,RFC1157VarBindList *);
#include "snmpelep.h" // c++ variables and definitions
#include "EALoad.h" // parameters loading functions
// MikeCure 4/3/98 hotfix for SMS Bug1 #20521
//===========================================
BOOL EnablePrivilege(VOID);
BOOL
StrToOid(
IN PCHAR lpszStr,
IN OUT AsnObjectIdentifier *asnOid
)
/*++
Routine Description:
This routine will convert the string passed to an OID.
Arguments:
lpszStr - Address of a null terminated string in the form n.n...n.
asnOid - Address of converted OID of the input string.
Return Value:
TRUE - If the string was successfully converted.
FALSE - If the string could not be converted.
--*/
{
CHAR tokens[] = TEXT("."); // delimiters to scan for
CHAR *token; // token returned
UINT nTokens; // number of tokens located
UINT i; // temporary counter
CHAR szString[MAX_PATH*2+1]; // temporary string holder
CHAR szOrgString[MAX_PATH*2+1]; // temporary string holder
CHAR *szStopString; // temporary string pointer
WriteTrace(0x0a,"StrToOid: Entering routine to convert string to OID\n");
WriteTrace(0x00,"StrToOid: String to convert is %s\n", lpszStr);
nTokens = 0; // reset counter
if ( strlen(lpszStr) == 0 )
{
WriteTrace(0x14,"StrToOid: No strings found. Exiting with FALSE\n");
return(FALSE);
}
if (lpszStr[0] != '.')
{
WriteTrace(0x0a,"StrToOid: BaseOID will not be appended to this OID\n");
strcpy(szString, lpszStr); // copy original string
}
else
{
WriteTrace(0x0a,"StrToOid: BaseOID %s will be appended to this OID\n", szBaseOID);
strcpy(szString, szBaseOID); // copy in base OID
strcat(szString, TEXT(".")); // stick in the .
strcat(szString, lpszStr); // add in requested string
}
strcpy(szOrgString, szString); // save this string
token = strtok(szString, tokens); // get first token
while (token != NULL)
{
szStopString = token; // set pointer to string
strtoul(token, &szStopString, 10); // check for valid values
if ( (token == szStopString) || (*szStopString != NULL) )
{
WriteTrace(0x14,"StrToOid: String contains a non-numeric value. Exiting with FALSE\n");
WriteLog(SNMPELEA_NON_NUMERIC_OID);
return(FALSE);
}
nTokens++; // increment number of tokens found
token = strtok(NULL, tokens); // get next token
}
if (nTokens == 0)
{
WriteTrace(0x14,"StrToOid: No strings found. Exiting with FALSE\n");
return(FALSE);
}
WriteTrace(0x00,"StrToOid: %lu tokens found\n", nTokens);
WriteTrace(0x0a,"StrToOid: Allocating storage for OID\n");
asnOid->ids = (UINT *) SNMP_malloc(nTokens * sizeof(UINT)); // allocate integer array
if (asnOid->ids == NULL)
{
WriteTrace(0x14,"StrToOid: Unable to allocate integer array for OID structure. Exiting with FALSE\n");
WriteLog(SNMPELEA_CANT_ALLOCATE_OID_ARRAY);
return(FALSE);
}
WriteTrace(0x00,"StrToOid: OID integer array storage allocated at %08X\n", asnOid->ids);
asnOid->idLength = nTokens; // set size of array
strcpy(szString, szOrgString); // copy original string
token = strtok(szString, tokens); // get first token
i = 0; // set index to 0
while (token != NULL)
{
asnOid->ids[i++] = strtoul(token, &szStopString, 10); // convert string to number
token = strtok(NULL, tokens); // get next token
}
if (nTraceLevel == 0)
{
for (i = 0; i < nTokens; i++)
{
WriteTrace(0x00,"StrToOid: OID[%lu] is %lu\n",
i, asnOid->ids[i]);
}
}
WriteTrace(0x0a,"StrToOid: Exiting routine with TRUE\n");
return(TRUE);
}
VOID
CloseStopAll(
IN VOID
)
/*++
Routine Description:
This routine will close the event handle used to terminate the extension agent dll.
Arguments:
None
Return Value:
None
--*/
{
LONG lastError; // for GetLastError()
if (hStopAll == NULL)
{
return;
}
WriteTrace(0x0a,"CloseStopAll: Closing handle to service shutdown event %08X\n",
hStopAll);
if ( !CloseHandle(hStopAll) )
{
lastError = GetLastError(); // save status
WriteTrace(0x14,"CloseStopAll: Error closing handle for service shutdown event %08X; code %lu\n",
hStopAll, lastError);
WriteLog(SNMPELEA_ERROR_CLOSING_STOP_AGENT_HANDLE,
HandleToUlong(hStopAll), lastError);
}
}
VOID
CloseEventNotify(
IN VOID
)
/*++
Routine Description:
This routine will close the event handle used to notify SNMPELDL that a
trap is waiting to be sent.
Arguments:
None
Return Value:
None
--*/
{
LONG lastError; // for GetLastError()
if (hEventNotify == NULL)
{
return;
}
WriteTrace(0x0a,"CloseEventNotify: Closing handle to event notify event %08X\n",
hEventNotify);
if ( !CloseHandle(hEventNotify) ) // close log processing routine shutdown event handle
{
lastError = GetLastError(); // save error status
WriteTrace(0x14,"CloseEventNotify: Error closing handle for StopLog event %08X; code %lu\n",
hEventNotify, lastError);
WriteLog(SNMPELEA_ERROR_CLOSING_STOP_LOG_EVENT_HANDLE,
HandleToUlong(hEventNotify), lastError);
}
}
VOID
CloseRegNotify(
IN VOID
)
/*++
Routine Description:
This routine will close the event handle used to notify SNMPELDL that a
registry key value has changed.
Arguments:
None
Return Value:
None
--*/
{
LONG lastError; // for GetLastError()
if (hRegChanged == NULL)
{
return;
}
WriteTrace(0x0a,"CloseRegNotify: Closing handle to registry key changed notify event %08X\n",
hRegChanged);
if ( !CloseHandle(hRegChanged) ) // close event handle
{
lastError = GetLastError(); // save error status
WriteTrace(0x14,"CloseRegNotify: Error closing handle for registry key changed event %08X; code %lu\n",
hRegChanged, lastError);
WriteLog(SNMPELEA_ERROR_CLOSING_REG_CHANGED_EVENT_HANDLE,
HandleToUlong(hRegChanged), lastError);
}
}
VOID
CloseRegParmKey(
IN VOID
)
/*++
Routine Description:
This routine will close the registry key handle used to read the Parameters information
from the registry.
Arguments:
None
Return Value:
None
--*/
{
LONG lastError;
if (!fRegOk)
{
return;
}
WriteTrace(0x0a,"CloseRegParmKey: Closing Parameter key in registry\n");
if ( (lastError = RegCloseKey(hkRegResult)) != ERROR_SUCCESS ) // close handle
{
WriteTrace(0x14,"CloseRegParmKey: Error closing handle for Parameters registry key %08X; code %lu\n",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -