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

📄 pppserver.c

📁 WinCE5.0部分核心源码
💻 C
📖 第 1 页 / 共 5 页
字号:
		}
	}

	return pMatchingLine;
}

PPPServerLineConfiguration_t *
PPPServerCreateLineConfig(
	PLIST_ENTRY	pLineList,
	RASDEVINFO	*pRasDevInfo)
//
//	Create a new line configuration structure, initialize it with default settings,
//	and add it to the list.
//
{
	PPPServerLineConfiguration_t *pLineConfig;

	pLineConfig = pppAllocateMemory(sizeof(*pLineConfig));
	if (!pLineConfig)
	{
		DEBUGMSG( ZONE_ERROR, (TEXT("PPP: ERROR, unable to allocate space for new line config\n")));
	}
	else
	{
		_tcscpy(pLineConfig->rasDevInfo.szDeviceName, pRasDevInfo->szDeviceName);
		_tcscpy(pLineConfig->rasDevInfo.szDeviceType, pRasDevInfo->szDeviceType);

		pLineConfig->pDevConfig = NULL;
		pLineConfig->dwDevConfigSize = 0;
		pLineConfig->bEnable = FALSE;
		pLineConfig->bmFlags = 0;
		pLineConfig->DisconnectIdleSeconds = 0;

		pLineConfig->IPAddrInfo[SERVER_INDEX].hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
		pLineConfig->IPAddrInfo[CLIENT_INDEX].hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);

		if (pLineConfig->IPAddrInfo[SERVER_INDEX].hEvent == NULL
		||  pLineConfig->IPAddrInfo[CLIENT_INDEX].hEvent == NULL)
		{
			CloseHandle(pLineConfig->IPAddrInfo[SERVER_INDEX].hEvent);
			pppFreeMemory(pLineConfig, sizeof(*pLineConfig));
			pLineConfig = NULL;
		}
		else
		{
			InsertTailList(pLineList, &pLineConfig->listEntry);
		}
	}

	return pLineConfig;
}



PPPServerLineConfiguration_t *
PPPServerFindOrCreateLineConfig(
	PLIST_ENTRY	pLineList,
	RASDEVINFO	*pRasDevInfo)
//
//	Find an existing line config by the given name.
//	If one does not already exist, create one and initialize with defaults.
//
{
	PPPServerLineConfiguration_t *pLineConfig;

	pLineConfig = PPPServerFindLineConfig(pLineList, pRasDevInfo);
	if (pLineConfig == NULL)
		pLineConfig = PPPServerCreateLineConfig(pLineList, pRasDevInfo);

	return pLineConfig;
}

void
PPPServerDestroyLineConfig(
	IN	OUT	PLIST_ENTRY	pLineList,
	IN	OUT	PPPServerLineConfiguration_t *pLineConfig)
//
//	Remove a line config from the list and free it.
//
{
	DEBUGMSG( ZONE_FUNCTION, (TEXT("PPP: +PPPServerDestroyLineConfig %s\n"), pLineConfig->rasDevInfo.szDeviceName));

	RemoveEntryList(&pLineConfig->listEntry);
	pLineConfig->listEntry.Flink = NULL;
	pLineConfig->listEntry.Blink = NULL;

	CloseHandle(pLineConfig->IPAddrInfo[SERVER_INDEX].hEvent);
	CloseHandle(pLineConfig->IPAddrInfo[CLIENT_INDEX].hEvent);

	pppFreeMemory(pLineConfig, sizeof(*pLineConfig));
}

void
PPPServerRemoveLineConfigurationRegistrySettings(
	PPPServerLineConfiguration_t	*pLineConfig)
//
//	Remove a line's settings from the registry
//
//		HKLM\Comm\ppp\Server\Line\<LineName>\
//
{
	LONG	lResult;
	TCHAR	tszKeyName[MAX_PATH + 1];	

    ASSERT(PPP_REGKEY_LINE_LEN + 1 + RAS_MaxDeviceName + 1 < MAX_PATH);
	_stprintf(tszKeyName, TEXT("%s\\%s"), PPP_REGKEY_LINE, pLineConfig->rasDevInfo.szDeviceName);

	lResult = DeleteRegistryKeyAndContents(HKEY_LOCAL_MACHINE, tszKeyName);
}

void
PPPServerWriteLineConfigurationRegistrySettings(
	PPPServerLineConfiguration_t	*pLineConfig)
//
//	Write a line's settings out to the registry
//
//		HKLM\Comm\ppp\Server\Line\<LineName>\
//
{
	TCHAR	tszKeyName[MAX_PATH + 1];	

    ASSERT(PPP_REGKEY_LINE_LEN + 1 + RAS_MaxDeviceName + 1 < MAX_PATH);
	_stprintf(tszKeyName, TEXT("%s\\%s"), PPP_REGKEY_LINE, pLineConfig->rasDevInfo.szDeviceName);

	(void) WriteRegistryValues(
				HKEY_LOCAL_MACHINE, tszKeyName,
				RAS_PARMNAME_DEVICE_TYPE,			 REG_SZ,    0,				  pLineConfig->rasDevInfo.szDeviceType,sizeof(pLineConfig->rasDevInfo.szDeviceType) / sizeof(char),
				RAS_PARMNAME_DEVICE_INFO,			 REG_BINARY,0,				 &pLineConfig->pDevConfig,		       pLineConfig->dwDevConfigSize,
				RAS_PARMNAME_ENABLE,			     REG_DWORD, 0,				 &pLineConfig->bEnable,				   sizeof(pLineConfig->bEnable),
				RAS_PARMNAME_FLAGS,					 REG_DWORD, 0,				 &pLineConfig->bmFlags,				   sizeof(pLineConfig->bmFlags),
				RAS_PARMNAME_DISCONNECT_IDLE_SECONDS,REG_DWORD, 0,				 &pLineConfig->DisconnectIdleSeconds,  sizeof(pLineConfig->DisconnectIdleSeconds),
				NULL);
}

DWORD
PPPServerLineComputeRasOptions(
	PPPServerLineConfiguration_t *pLine)
//
//	Compute the RASENTRY.dwfOptions settings for the line,
//	based upon the global and per-line configuration settings.
//
{
	PPPServerConfiguration_t *pConfig = &PPPServerConfig;
	DWORD					  dwfOptions,
							  bmFlags;

	dwfOptions = PPPServerConfig.bmAuthenticationMethods;

	bmFlags = pLine->bmFlags | pConfig->bmFlags;

	if (bmFlags & PPPSRV_FLAG_REQUIRE_DATA_ENCRYPTION)
	{
		dwfOptions |= RASEO_RequireDataEncryption;
		//
		//	Encryption requires MS CHAP v1 or v2 authentication, force them on.
		//
		if ((dwfOptions & (RASEO_ProhibitMsCHAP | RASEO_ProhibitMsCHAP2)) ==
			 (RASEO_ProhibitMsCHAP | RASEO_ProhibitMsCHAP2))
		{
			DEBUGMSG(ZONE_ERROR, (L"PPP: Server configuration error, REQUIRE_DATA_ENCRYPTION requires MSCHAP authentication\n"));
			dwfOptions &= ~(RASEO_ProhibitMsCHAP | RASEO_ProhibitMsCHAP2);
		}
	}

	if (!(bmFlags & PPPSRV_FLAG_NO_VJ_HEADER_COMPRESSION))
	{
		dwfOptions |= RASEO_IpHeaderCompression;
	}

	if (!(bmFlags & PPPSRV_FLAG_NO_DATA_COMPRESSION))
	{
		dwfOptions |= RASEO_SwCompression;
	}

	return dwfOptions;
}

VOID
PPPServerLineUpdateActiveSettings(
	IN	PPPServerLineConfiguration_t	*pLine)
{
	//
	//	If the line is currently open and listening for connections,
	//	then update the settings based upon the current bmFlags.
	//
	if (pLine->pSession)
	{
		pLine->pSession->rasEntry.dwfOptions = PPPServerLineComputeRasOptions(pLine);
		pppComputeAuthTypesAllowed(pLine->pSession);
	}
}

void
PPPServerReadLineConfigurationRegistrySettings(
	LIST_ENTRY	*pLineList)
//
//	Read the PPP Server's per line configuration settings from the registry keys:
//
//		HKLM\Comm\ppp\Server\Line\<LineName>\
//
{
    HKEY        hKey;
    LONG        hRes;
    DWORD       cbRequired = 0;
    DWORD       RetVal = ERROR_SUCCESS;
    DWORD       ccDeviceName;
	UINT		numLines = 0;
	PPPServerLineConfiguration_t	*pLineConfig;
	RASDEVINFO	devInfo;
	
    hRes = RegOpenKeyEx( HKEY_LOCAL_MACHINE, PPP_REGKEY_LINE, 0, KEY_READ, &hKey );

	if (ERROR_SUCCESS == hRes )
	{
        // Now loop over the sub-keys getting the names of each.

        while (TRUE)
		{
            ccDeviceName = sizeof(devInfo.szDeviceName) / sizeof(devInfo.szDeviceName[0]);
            hRes = RegEnumKeyEx (hKey, numLines, devInfo.szDeviceName, &ccDeviceName, NULL, NULL, NULL, NULL);
			if (hRes != ERROR_SUCCESS)
				break;

            DEBUGMSG( ZONE_RAS | ZONE_FUNCTION, (TEXT("PPP: Found Registry Key for device %s\r\n"), devInfo.szDeviceName));

			// Temp dummy type during creation, real type read from registry below
			devInfo.szDeviceType[0] = TEXT('\0');

			pLineConfig = PPPServerCreateLineConfig(pLineList, &devInfo);
			if (!pLineConfig)
			{
				DEBUGMSG( ZONE_ERROR, (TEXT("PPP: ERROR, Server unable to create device %s\n"), devInfo.szDeviceName));
			}
			else
			{
				//
				//	Read in the new line's configuration settings
				//
				(void) ReadRegistryValues(
						hKey, devInfo.szDeviceName,
						RAS_PARMNAME_DEVICE_TYPE,			 REG_SZ,    0,				  pLineConfig->rasDevInfo.szDeviceType,sizeof(pLineConfig->rasDevInfo.szDeviceType) / sizeof(char),
						RAS_PARMNAME_DEVICE_INFO,			 REG_BINARY,REG_ALLOC_MEMORY,&pLineConfig->pDevConfig,		   &pLineConfig->dwDevConfigSize,
						RAS_PARMNAME_ENABLE,			     REG_DWORD, 0,				 &pLineConfig->bEnable,				   sizeof(pLineConfig->bEnable),
						RAS_PARMNAME_FLAGS,					 REG_DWORD, 0,				 &pLineConfig->bmFlags,				   sizeof(pLineConfig->bmFlags),
						RAS_PARMNAME_DISCONNECT_IDLE_SECONDS,REG_DWORD, 0,				 &pLineConfig->DisconnectIdleSeconds,  sizeof(pLineConfig->DisconnectIdleSeconds),
						NULL);
			}
			numLines++;
        }
        RegCloseKey (hKey);
    }

	DEBUGMSG( ZONE_RAS | ZONE_FUNCTION, (TEXT("PPP: Configured %d server lines from registry\n"), numLines));
}

void
PPPServerWriteRegistrySettings(
	PPPServerConfiguration_t *pConfig)
{
	//
	// Write out server registry settings
	// A future optimization would be to only write out those settings which differ from the defaults.
	//

	(void) WriteRegistryValues(
			HKEY_LOCAL_MACHINE,                 PPP_REGKEY_PARMS,
			RAS_PARMNAME_STATIC_IP_ADDR_START,	REG_DWORD, 0, &pConfig->dwStaticIpAddrStart,	sizeof(pConfig->dwStaticIpAddrStart),
			RAS_PARMNAME_STATIC_IP_ADDR_COUNT,	REG_DWORD, 0, &pConfig->dwStaticIpAddrCount,	sizeof(pConfig->dwStaticIpAddrCount),
			RAS_PARMNAME_AUTHENTICATION_METHODS,REG_DWORD, 0, &pConfig->bmAuthenticationMethods,sizeof(pConfig->bmAuthenticationMethods),
			RAS_PARMNAME_ENABLE,				REG_DWORD, 0, &pConfig->bEnable,				sizeof(pConfig->bEnable),
			RAS_PARMNAME_FLAGS,					REG_DWORD, 0, &pConfig->bmFlags,				sizeof(pConfig->bmFlags),
			RAS_PARMNAME_USE_AUTOIP_ADDRESSES,	REG_DWORD, 0, &pConfig->bUseAutoIpAddresses,	sizeof(pConfig->bUseAutoIpAddresses),
			RAS_PARMNAME_AUTOIP_SUBNET,	        REG_DWORD, 0, &pConfig->dwAutoIpSubnet,	        sizeof(pConfig->dwAutoIpSubnet),
			RAS_PARMNAME_AUTOIP_SUBNET_MASK,	REG_DWORD, 0, &pConfig->dwAutoIpSubnetMask,	    sizeof(pConfig->dwAutoIpSubnetMask),
			RAS_PARMNAME_USE_DHCP_ADDRESSES,	REG_DWORD, 0, &pConfig->bUseDhcpAddresses,		sizeof(pConfig->bUseDhcpAddresses),
			RAS_PARMNAME_DHCP_IF_NAME,	        REG_SZ,    0, &pConfig->wszDhcpInterface[0],	(wcslen(pConfig->wszDhcpInterface)+1) * sizeof(WCHAR),
			RAS_PARMNAME_IPV6_NET_PREFIX,       REG_BINARY,0, &pConfig->IPV6NetPrefix[0],       sizeof(pConfig->IPV6NetPrefix),
			RAS_PARMNAME_IPV6_NET_PREFIX_LEN,   REG_DWORD, 0, &pConfig->IPV6NetPrefixBitLength, sizeof(DWORD),
			RAS_PARMNAME_IPV6_NET_COUNT,        REG_DWORD, 0, &pConfig->IPV6NetCount,           sizeof(DWORD),
			NULL);
}

DWORD
PPPServerSetParameters(
	IN	PRASCNTL_SERVERSTATUS pBufIn,
	IN	DWORD				  dwLenIn)
{
	PPPServerConfiguration_t	 *pConfig = &PPPServerConfig;
	PPPServerLineConfiguration_t *pLine;
	DWORD						  dwRetVal = SUCCESS;

	if ((pBufIn == NULL)
	||  (dwLenIn < sizeof(RASCNTL_SERVERSTATUS)))
	{
		dwRetVal = ERROR_INVALID_PARAMETER;
	}
	else
	{
		EnterCriticalSection( &PPPServerCritSec );

		pConfig->bmFlags = pBufIn->bmFlags;
		pConfig->dwStaticIpAddrStart = pBufIn->dwStaticIpAddrStart;
		pConfig->dwStaticIpAddrCount = pBufIn->dwStaticIpAddrCount;
		pConfig->bmAuthenticationMethods = pBufIn->bmAuthenticationMethods;
	    pConfig->bmAuthenticationMethods &= RASEO_ProhibitPAP |
		                                    RASEO_ProhibitCHAP |
										    RASEO_ProhibitMsCHAP |
										    RASEO_ProhibitMsCHAP2 |
										    RASEO_ProhibitEAP;


		pConfig->bUseAutoIpAddresses = pBufIn->bUseAutoIpAddresses;
		pConfig->dwAutoIpSubnet      = pBufIn->dwAutoIpSubnet;
		pConfig->dwAutoIpSubnetMask  = pBufIn->dwAutoIpSubnetMask;

		pConfig->bUseDhcpAddresses = pBufIn->bUseDhcpAddresses;
		wcsncpy(&pConfig->wszDhcpInterface[0], &pBufIn->wszDhcpInterface[0], MAX_IF_NAME_LEN);
		pConfig->wszDhcpInterface[MAX_IF_NAME_LEN] = L'\0';

		PPPServerWriteRegistrySettings(pConfig);

		//
		//	Update any open lines for the new global flags settings.
		//
		for (pLine  = (PPPServerLineConfiguration_t *)(pConfig->LineList.Flink);
			 pLine != (PPPServerLineConfiguration_t *)(&pConfig->LineList);
			 pLine  = (PPPServerLineConfiguration_t *)pLine->listEntry.Flink)
		{
			PPPServerLineUpdateActiveSettings(pLine);
		}

		LeaveCriticalSection( &PPPServerCritSec );
	}

	return dwRetVal;
}

DWORD
PPPServerGetParameters(
	OUT	PRASCNTL_SERVERSTATUS pBufOut,
	IN	DWORD				  dwLenOut,
	OUT	PDWORD				  pdwActualOut)
{
	PPPServerConfiguration_t	 *pConfig = &PPPServerConfig;
	DWORD						 dwRetVal,
								 dwSizeNeeded,
								 dwNumLines;

	EnterCriticalSection( &PPPServerCritSec );

	//
	// Count the number of lines
	//
	dwNumLines = CountListEntries(&pConfig->LineList);

	dwSizeNeeded = sizeof(RASCNTL_SERVERSTATUS);

	if ((dwLenOut < dwSizeNeeded) || (NULL == pBufOut))
	{
		dwRetVal = ERROR_BUFFER_TOO_SMALL;
	}
	else
	{
		pBufOut->bEnable = pConfig->bEnable;
		pBufOut->bmFlags = pConfig->bmFlags;
		pBufOut->dwStaticIpAddrStart = pConfig->dwStaticIpAddrStart;
		pBufOut->dwStaticIpAddrCount = pConfig->dwStaticIpAddrCount;
		pBufOut->bmAuthenticationMethods = pConfig->bmAuthenticationMethods;
		pBufOut->dwNumLines = dwNumLines;

		pBufOut->bUseAutoIpAddresses = pConfig->bUseAutoIpAddresses;
		pBufOut->dwAutoIpSubnet      = pConfig->dwAutoIpSubnet;
		pBufOut->dwAutoIpSubnetMask  = pConfig->dwAutoIpSubnetMask;

		pBufOut->bUseDhcpAddresses = pConfig->bUseDhcpAddresses;
		wcsncpy(&pBufOut->wszDhcpInterface[0], &pConfig->wszDhcpInterface[0], MAX_IF_NAME_LEN);
		pBufOut->wszDhcpInterface[MAX_IF_NAME_LEN] = L'\0';

		dwRetVal = ERROR_SUCCESS;
	}

	if (pdwActualOut)
		*pdwActualOut = dwSizeNeeded;

	LeaveCriticalSection( &PPPServerCritSec );

	return dwRetVal;
}

DWORD
PPPServerGetIPV6NetPrefix(
	OUT	PRASCNTL_SERVER_IPV6_NET_PREFIX pBufOut,
	IN	DWORD				            dwLenOut,
	OUT	PDWORD				            pdwActualOut)
{
	PPPServerConfiguration_t	 *pConfig = &PPPServerConfig;
	DWORD                         dwRetVal = ERROR_SUCCESS;

	if ((dwLenOut < sizeof(RASCNTL_SERVER_IPV6_NET_PREFIX)) || (NULL == pBufOut))
	{
		dwRetVal = ERROR_BUFFER_TOO_SMALL;
	}
	else
	{
		memcpy(pBufOut->IPV6NetPrefix, pConfig->IPV6NetPrefix, sizeof(pBufOut->IPV6NetPrefix));
		pBufOut->IPV6NetPrefixBitLength = pConfig->IPV6NetPrefixBitLength;
		pBufOut->IPV6NetPrefixCount = pConfig->IPV6NetCount;
	}

	return dwRetVal;
}

DWORD
PPPServerSetIPV6NetPrefix(
	IN	PRASCNTL_SERVER_IPV6_NET_PREFIX pBufIn,
	IN	DWORD				            dwLenIn)
{
	PPPServerConfiguration_t	 *pConfig = &PPPServerConfig;
	DWORD                         dwRetVal = ERROR_SUCCESS;

	if ((dwLenIn < sizeof(RASCNTL_SERVER_IPV6_NET_PREFIX)) || (NULL == pBufIn))
	{
		dwRetVal = ERROR_BUFFER_TOO_SMALL;
	}
	else
	{
		memcpy(pConfig->IPV6NetPrefix, pBufIn->IPV6NetPrefix, sizeof(pConfig->IPV6NetPrefix));
		pConfig->IPV6NetPrefixBitLength = pBufIn->IPV6NetPrefixBitLength;
		pConfig->IPV6NetCount = pBufIn->IPV6NetPrefixCount;

		PPPServerWriteRegistrySettings(pConfig);
	}

	return dwRetVal;
}

DWORD
PPPServerGetStatus(
	OUT	PRASCNTL_SERVERSTATUS pBufOut,
	IN	DWORD				  dwLenOut,
	OUT	PDWORD				  pdwActualOut)
{
	PPPServerConfiguration_t	 *pConfig = &PPPServerConfig;
	PPPServerLineConfiguration_t *pLineConfig;
	DWORD						 dwRetVal,
								 dwSizeNeeded,
								 dwNumLines;
	RASCNTL_SERVERLINE			 *pLineOut;

	EnterCriticalSection( &PPPServerCritSec );

	//
	// Get server globals
	//
	dwRetVal = PPPServerGetParameters(pBufOut, dwLenOut, pdwActualOut);

	//
	// Count the number of lines
	//
	dwNumLines = CountListEntries(&pConfig->LineList);

	dwSizeNeeded = sizeof(RASCNTL_SERVERSTATUS) + dwNumLines * sizeof(RASCNTL_SERVERLINE);

	if ((dwLenOut < dwSizeNeeded) || (NULL == pBufOut))
	{
		dwRetVal = ERROR_BUFFER_TOO_SMALL;
	}
	else
	{
		//
		// Get individual line states
		//
		// Line configuration information is placed into the buffer immediately
		// following the global server config.
		//
		pLineOut = (RASCNTL_SERVERLINE *)(&pBufOut[1]);
		pLineConfig = (PPPServerLineConfiguration_t *)(pConfig->LineList.Flink);
		
		while (dwNumLines--)
		{
			pLineOut->rasDevInfo            = pLineConfig->rasDevInfo;
			pLineOut->bEnable               = pLineConfig->bEnable;
			pLineOut->bmFlags               = pLineConfig->bmFlags;
			pLineOut->DisconnectIdleSeconds = pLineConfig->DisconnectIdleSeconds;

			pLineOut++;
			pLineConfig = (PPPServerLineConfiguration_t *)pLineConfig->listEntry.Flink;
		}
		dwRetVal = ERROR_SUCCESS;
	}

	if (pdwActualOut)
		*pdwActualOut = dwSizeNeeded;

	LeaveCriticalSection( &PPPServerCritSec );

	return dwRetVal;

⌨️ 快捷键说明

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