⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snmpeldl.cpp

📁 windows的snmp api源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	DWORD	parmSize;						// length of the parm value
	HANDLE	hLogFile;						// handle from log open
	UINT	uVal;							// loop counter
	BOOL	fTrimMsg = FALSE;				// registry info found flags
	BOOL	fBaseOID = FALSE;				// registry info found flags
	BOOL	fSupView = FALSE;				// registry info found flags
	BOOL	fTrapSize = FALSE;				// registry info found flags
	BOOL	fTrimFlg = FALSE;				// registry info found flags
	BOOL	fThresholdFlg = FALSE;			// registry info found flags
	BOOL	fThresholdCountFlg = FALSE; 	// registry info found flags
	BOOL	fThresholdTimeFlg = FALSE;		// registry info found flags
	BOOL	fTraceLevelFlg = FALSE; 		// registry info found flags
	BOOL	fThresholdEnabledFlg = FALSE;	// registry info found flags
	BOOL	fThresholdOff = FALSE;			// temporary flag
	DWORD	nReadBytes = 0; 				// number of bytes read from profile information
	TCHAR	lpszLog[MAX_PATH+1];			// temporary registry name
	BOOL	fLastBootFlg = FALSE;			// registry info found flag

	WriteTrace(0x0a,"Read_Registry_Parameters: Entering routine\n");

	if (fSendThresholdTrap)
	{
		WriteTrace(0x0a,"Read_Registry_Parameters: Routined entered due to threshold performance parameters reached and modified.\n");

		if ( hRegChanged != NULL )
		{
			if ( (lastError = RegNotifyChangeKeyValue(
					hkRegResult,																					// handle of key to watch
					TRUE,																									// watch subkey stuff
					REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_LAST_SET,	// types of changes to notify on
					hRegChanged,																					// event to signal when change
					TRUE)) == ERROR_SUCCESS )																// asynchronous processing
			{
				WriteTrace(0x0a,"Read_Registry_Parameters: Notification of registry key changes was successful.\n");
				fRegOk = TRUE;							// show registry notification is in effect
			}
			else
			{
				WriteTrace(0x14,"Read_Registry_Parameters: Notification of registry key changes failed with code of %lu\n",
						lastError);
				WriteLog(SNMPELEA_REG_NOTIFY_CHANGE_FAILED, lastError);
				WriteTrace(0x14,"Read_Registry_Parameters: Initialization continues, but registry changes will require a restart of SNMP\n");
				CloseRegNotify();
			}
		}

		WriteTrace(0x0a,"Read_Registry_Parameters: Exiting Read_Registry_Parameters routine with TRUE.\n");
		return(TRUE);
	}

	WriteTrace(0x0a,"Read_Registry_Parameters: Opening %s\n", EXTENSION_PARM);

	if (fThreshold && fThresholdEnabled)	// if threshold checking enabled and threshold reached
	{
			fThresholdOff = TRUE;							// indicate that we're not sending traps right now
	}
	else
	{
			fThresholdOff = FALSE;							// otherwise, indicate we are sending traps right now
	}

	if (hkRegResult == NULL)
	{
			if ((status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, EXTENSION_PARM, 0,
					KEY_READ | KEY_SET_VALUE, &hkRegResult))
					!= ERROR_SUCCESS)					// open registry information
			{
					WriteTrace(0x14,"Read_Registry_Parameters: Error in RegOpenKeyEx for Parameters = %lu \n",
							status);
					WriteLog(SNMPELEA_NO_REGISTRY_PARAMETERS, status);	 // log error message
					return(FALSE);									// failed -- can't continue
			}
	}

	if (!fRegNotify)
	{
		WriteTrace(0x0a,"Read_Registry_Parameters: Creating event for registry change notification\n");
		fRegNotify = TRUE;								// set flag to show initialization complete

		if ( (hRegChanged = CreateEvent(
				(LPSECURITY_ATTRIBUTES) NULL,
				FALSE,
				FALSE,
				(LPTSTR) NULL)) == NULL)
		{
			lastError = GetLastError(); // save error status
			WriteTrace(0x14,"Read_Registry_Parameters: Error creating registry change notification event; code %lu\n",
					lastError);
			WriteLog(SNMPELEA_ERROR_CREATING_REG_CHANGE_EVENT, lastError);

			WriteTrace(0x14,"Read_Registry_Parameters: No registry notification will be performed. Continuing with initialization.\n");
		}
		else
		{
			WriteTrace(0x00,"Read_Registry_Parameters: Registry key changed event handle is %08X\n",
					hRegChanged);
		}
	}

	if ( hRegChanged != NULL )
	{
		if ( (lastError = RegNotifyChangeKeyValue(
				hkRegResult,																					// handle of key to watch
				TRUE,																									// watch subkey stuff
				REG_NOTIFY_CHANGE_NAME | REG_NOTIFY_CHANGE_LAST_SET,	// types of changes to notify on
				hRegChanged,																					// event to signal when change
				TRUE)) == ERROR_SUCCESS )																// asynchronous processing
		{
			WriteTrace(0x0a,"Read_Registry_Parameters: Notification of registry key changes was successful.\n");
			fRegOk = TRUE;							// show registry notification is in effect
		}
		else
		{
			WriteTrace(0x14,"Read_Registry_Parameters: Notification of registry key changes failed with code of %lu\n",
					lastError);
			WriteLog(SNMPELEA_REG_NOTIFY_CHANGE_FAILED, lastError);
			WriteTrace(0x14,"Read_Registry_Parameters: Initialization continues, but registry changes will require a restart of SNMP\n");
			CloseRegNotify();
		}
	}

	iValue = 0; 							 // read first parameter
	nameSize = MAX_PATH;					 // can't be greater than this
	parmSize = MAX_PATH;					 // can't be greater than this

	while ((status = RegEnumValue(hkRegResult, iValue, parmName, &nameSize, 0,
				&dwType, (LPBYTE)&parm, &parmSize)) != ERROR_NO_MORE_ITEMS)
	{									  // read until no more values
		if (status != ERROR_SUCCESS)		  // if error during read
		{
			WriteTrace(0x14,"Read_Registry_Parameters: Error reading registry value is %lu for index %lu (Parameters)\n",
								status, iValue);			// show error information
			WriteLog(SNMPELEA_ERROR_REGISTRY_PARAMETER_ENUMERATE,
								(DWORD) status, iValue);   // log error message

			fRegOk = FALSE; 										// don't want to do notify now
			CloseRegNotify();										// close event handle
			CloseRegParmKey();										// close registry key
			return(FALSE);												// indicate stop
		}

		WriteTrace(0x00,"Read_Registry_Parameters: Parameter read is %s, length is %lu\n",
						parmName, strlen(parmName));

		switch (dwType)
		{
			case REG_SZ : // if we have a string
			{
				WriteTrace(0x00,"Read_Registry_Parameters: Parameter type is REG_SZ\n");

				if ( _stricmp(parmName,EXTENSION_BASE_OID) == 0 )
				{
					WriteTrace(0x00,"Read_Registry_Parameters: BaseEnterpriseOID parameter matched\n");
					strcpy(szBaseOID,parm); 		// save base OID
					fBaseOID = TRUE;						// indicate parameter read
				}
				else if ( _stricmp(parmName,EXTENSION_TRACE_FILE) == 0 )
				{
					WriteTrace(0x00,"Read_Registry_Parameters: TraceFileName parameter matched\n");
					strcpy(szTraceFileName,parm);	// save filename
					fTraceFileName = TRUE;					// indicate parameter read
				}
				else if ( _stricmp(parmName,EXTENSION_SUPPORTED_VIEW) == 0 )
				{
					WriteTrace(0x00,"Read_Registry_Parameters: SupportedView parameter matched\n");
					strcpy(szSupView,parm); 		// save supported view OID
					fSupView = TRUE;						// indicate parameter read
				}
				else						  // otherwise, bad value read
				{
					WriteTrace(0x00,"Read_Registry_Parameters: Unknown Registry value name: %s\n",parmName );
					WriteTrace(0x00,"Read_Registry_Parameters: Unknown Registry value contents %s\n",parm );
				}
			}
			break;

			case REG_DWORD :// if double word parameter
			{
				WriteTrace(0x00,"Read_Registry_Parameters: Parameter type is REG_DWORD\n");

				if ( _stricmp(parmName,EXTENSION_TRACE_LEVEL) == 0 )
				{
					WriteTrace(0x00,"Read_Registry_Parameters: TraceLevel parameter matched\n");
					nTraceLevel = *((DWORD *)parm); // copy registry trace level
					fTraceLevelFlg = TRUE;					//indicate parameter read
					break;
				}
				else if ( _stricmp(parmName,EXTENSION_TRIM) == 0 )
				{
					WriteTrace(0x00,"Read_Registry_Parameters: Global TrimMessage parameter matched\n");
					fGlobalTrim = (*((DWORD *)parm) == 1);			// set global message trim flag
					fTrimMsg = TRUE;		 // show parameter found
					break;									// exit case
				}
				else if ( _stricmp(parmName,EXTENSION_MAX_TRAP_SIZE) == 0 )
				{
					WriteTrace(0x00,"Read_Registry_Parameters: Maximum Trap Size parameter matched\n");
					nMaxTrapSize = *((DWORD *)parm);				// get trap size
					fTrapSize = TRUE;								// show parameter found
					break;
				}
				else if ( _stricmp(parmName,EXTENSION_TRIM_FLAG) == 0)
				{
					WriteTrace(0x00,"Read_Registry_Parameters: Global trap trimming flag TrimFlag parameter matched\n");
					fTrimFlag = (*((DWORD *)parm) == 1);	// set global trim flag
					fTrimFlg = TRUE;				// show parameter found
					break;									// exit case
				}
				else if ( _stricmp(parmName,EXTENSION_THRESHOLD_ENABLED) == 0)
				{
					WriteTrace(0x00,"Read_Registry_Parameters: Global threshold checking flag ThresholdEnabled parameter matched\n");
					fThresholdEnabled = (*((DWORD *)parm) == 1);	// set global threshold enabled flag
					fThresholdEnabledFlg = TRUE;
					break;									// exit case
				}
				else if ( _stricmp(parmName,EXTENSION_THRESHOLD_FLAG) == 0)
				{
					WriteTrace(0x00,"Read_Registry_Parameters: Global preformance threshold flag Threshold parameter matched\n");
					fThreshold = (*((DWORD *)parm) == 1);	// set global performance threshold flag
					fThresholdFlg = TRUE;
					break;									// exit case
				}
				else if ( _stricmp(parmName,EXTENSION_THRESHOLD_COUNT) == 0)
				{
					WriteTrace(0x00,"Read_Registry_Parameters: Global preformance threshold count ThresholdCount parameter matched\n");
					dwThresholdCount = *((DWORD *)parm);	// set global performance threshold count
					fThresholdCountFlg = TRUE;
					break;									// exit case
				}
				else if ( _stricmp(parmName,EXTENSION_THRESHOLD_TIME) == 0)
				{
					WriteTrace(0x00,"Read_Registry_Parameters: Global preformance threshold time ThresholdTime parameter matched\n");
					dwThresholdTime = *((DWORD *)parm); 	// set global performance threshold time
					fThresholdTimeFlg = TRUE;
					break;									// exit case
				}
				else if (fDoLogonEvents && (_stricmp(parmName,EXTENSION_LASTBOOT_TIME) == 0))
				{
					WriteTrace(0x00,"Read_Registry_Parameters: Initialization last boot time parameter matched\n");
					dwLastBootTime = *((DWORD *)parm); 	// set global last boot time
					fLastBootFlg = TRUE;
					break;									// exit case
				}
				else													// otherwise, bad parameter read
				{
					WriteTrace(0x00,"Read_Registry_Parameters: Unknown Registry value name: %s\n",parmName );
					WriteTrace(0x00,"Read_Registry_Parameters: Unknown Registry value contents: %lu\n",parm );
				}
			}
			break;

			default :   // if not above, bad value read
			{
				WriteTrace(0x00,"Read_Registry_Parameters: Unknown Registry value name: %s\n",parmName );
				WriteTrace(0x00,"Read_Registry_Parameters: Unknown Registry value contents not displayed\n" );
			}
		} // end switch

		nameSize = MAX_PATH;				  // reset maximum length
		parmSize = MAX_PATH;				  // reset maximum length
		iValue++;							  // request next parameter value

	} // end while

	if (!fRegOk)
	{
		CloseRegParmKey();										// close registry key
	}

	WriteTrace(0x00,"Read_Registry_Parameters: Checking BaseEnterpriseOID read from registry\n");
	
	if ( !fBaseOID )
	{
		WriteTrace(0x14,"Read_Registry_Parameters: BaseEnterpriseOID parameter not found in registry\n");
		WriteLog(SNMPELEA_NO_REGISTRY_BASEOID_PARAMETER);
		return(FALSE);											// exit - can't continue
	}

	WriteTrace(0x00,"Read_Registry_Parameters: Checking SupportedView read from registry\n");
	
	if ( !fSupView )
	{
		WriteTrace(0x14,"Read_Registry_Parameters: SupportedView parameter not found in registry\n");
		WriteLog(SNMPELEA_NO_REGISTRY_SUPVIEW_PARAMETER);
		return(FALSE);											// exit - can't continue
	}

	WriteTrace(0x00,"Read_Registry_Parameters: Checking TraceFileName read from registry\n");
	
	if ( !fTraceFileName )
	{
		WriteTrace(0x00,"Read_Registry_Parameters: TraceFileName parameter not found in registry, defaulting to %s.\n",
						szTraceFileName);
	}
	else
	{
		WriteTrace(0x00,"Read_Registry_Parameters: TraceFileName parameter found in registry of %s.\n", szTraceFileName);
	}

	WriteTrace(0x00,"Read_Registry_Parameters: Checking TraceLevel read from registry\n");
	
	if ( !fTraceLevelFlg )
	{
		WriteTrace(0x00,"Read_Registry_Parameters: TraceLevel parameter not found in registry, defaulting to %lu.\n",
						nTraceLevel);
	}
	else
	{
		WriteTrace(0x00,"Read_Registry_Parameters: TraceLevel parameter found in registry of %lu.\n", nTraceLevel);
	}

	WriteTrace(0x00,"Read_Registry_Parameters: Checking MaxTrapSize read from registry\n");
	
	if ( !fTrapSize )
	{
		WriteTrace(0x00,"Read_Registry_Parameters: MaxTrapSize parameter not found in registry, defaulting to %lu.\n",
						MAX_TRAP_SIZE);
		nMaxTrapSize = MAX_TRAP_SIZE;
	}
	else
	{
		WriteTrace(0x00,"Read_Registry_Parameters: MaxTrapSize parameter found in registry of %lu.\n", nMaxTrapSize);
	}

	WriteTrace(0x00,"Read_Registry_Parameters: Checking TrimFlag read from registry\n");

	if ( !fTrimFlg )
	{
		WriteTrace(0x00,"Read_Registry_Parameters: TrimFlag parameter not found in registry, defaulting to %lu.\n",
						fTrimFlag);
	}
	else
	{
		WriteTrace(0x00,"Read_Registry_Parameters: TrimFlag parameter found in registry of %lu.\n", fTrimFlag);
	}

	WriteTrace(0x00,"Read_Registry_Parameters: Checking TrimFlag read from registry\n");

	if ( !fTrimMsg )
	{
		WriteTrace(0x00,"Read_Registry_Parameters: TrimMessage parameter not found in registry, defaulting to %lu.\n",
						fGlobalTrim);
	}
	else
	{
		WriteTrace(0x00,"Read_Registry_Parameters: TrimMessage parameter found in registry of %lu.\n", fGlobalTrim);
	}


	WriteTrace(0x00,"Read_Registry_Parameters: Checking ThresholdEnabled parameter read from registry\n");

	if ( !fThresholdEnabledFlg )
	{
		WriteTrace(0x00,"Read_Registry_Parameters: ThresholdEnabled parameter not found in registry, defaulting to 1.\n");
				fThresholdEnabled = TRUE;
	}
	else
	{
		WriteTrace(0x00,"Read_Registry_Parameters: ThresholdEnabled parameter found in registry of %lu.\n", fThresholdEnabled);
	}

	WriteTrace(0x00,"Read_Registry_Parameters: Checking Threshold parameter read from registry\n");
	
	if ( !fThresholdFlg )
	{
		WriteTrace(0x00,"Read_Registry_Parameters: Threshold parameter not found in registry, defaulting to 0.\n");
		fThreshold = FALSE;
	}
	else
	{
		WriteTrace(0x00,"Read_Registry_Parameters: Threshold parameter found in registry of %lu.\n", fThreshold);
	}

	WriteTrace(0x00,"Read_Registry_Parameters: Checking ThresholdCount parameter read from registry\n");
	
	if ( !fThresholdCountFlg )
	{
		WriteTrace(0x00,"Read_Registry_Parameters: ThresholdCount parameter not found in registry, defaulting to %lu.\n",
						THRESHOLD_COUNT);
		dwThresholdCount = THRESHOLD_COUNT;
	}
	else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -