📄 rasreg.c
字号:
AfdRasDeleteEntry(LPTSTR lpszPhonebook, LPTSTR lpszEntry)
{
TCHAR KeyName[128];
DWORD RetVal = 0;
DEBUGMSG( ZONE_RAS | ZONE_FUNCTION,
(TEXT("+AfdRasDeleteEntry (0x%08X, 0x%08X(%s))\r\n"),
lpszPhonebook, lpszEntry,
(lpszEntry != 0) ? lpszEntry : TEXT("Null")) );
if (NULL != lpszPhonebook)
{
// We only support the system/registry phonebook.
RetVal = ERROR_CANNOT_OPEN_PHONEBOOK;
}
else if (!(RetVal = RaspCheckEntryName(lpszEntry)))
{
// Build the key name.
StringCchPrintfW(KeyName, COUNTOF(KeyName), L"%s\\%s", RASBOOK_KEY, lpszEntry);
// Now try to delete the key and all of it's values.
RetVal = RegDeleteKey (HKEY_CURRENT_USER, KeyName);
}
DEBUGMSG( ZONE_RAS | ZONE_FUNCTION,
(TEXT("-AfdRasDeleteEntry Returning %d\r\n"),
RetVal));
return RetVal;
}
/*****************************************************************************
*
*
* @func DWORD | RasRenameEntry |
* The RasRenameEntry function changes the name of an entry in
* the phonebook.
*
* @rdesc
* If the function succeeds, the return value is zero.
* If the function fails, the return value is
* ERROR_INVALID_NAME, ERROR_ALREADY_EXISTS, or
* ERROR_CANNOT_FIND_PHONEBOOK_ENTRY.
*
* @parm LPTSTR | szPhonebook | PhoneBook name. Must be NULL.
* @parm LPTSTR | szOldEntry | Old entry name.
* @parm LPTSTR | szNewEntry | New entry name.
*
*
*/
DWORD WINAPI
AfdRasRenameEntry(
IN LPTSTR lpszPhonebook,
IN LPTSTR lpszOldEntry,
IN LPTSTR lpszNewEntry)
{
HKEY hKeyRasBook;
DWORD RetVal;
pppSession_t * pSession;
RASDIALPARAMS dialParams;
BOOL bMoveCredentials;
PPP_CONTEXT *pppCntxt_p = NULL;
DEBUGMSG( ZONE_RAS | ZONE_FUNCTION,
(TEXT("+AfdRasRenameEntry (0x%08X, 0x%08X(%s), 0x%08X(%s))\r\n"),
lpszPhonebook, lpszOldEntry,
(lpszOldEntry != 0) ? lpszOldEntry : TEXT("Null"),
lpszNewEntry,
(lpszNewEntry != 0) ? lpszNewEntry : TEXT("Null")) );
RetVal = RaspCheckEntryName(lpszOldEntry);
if (RetVal == ERROR_SUCCESS)
{
RetVal = RaspCheckEntryName(lpszNewEntry);
if (RetVal == ERROR_SUCCESS)
{
RetVal = RegOpenKeyEx(HKEY_CURRENT_USER, RASBOOK_KEY, 0, 0, &hKeyRasBook);
if (RetVal == ERROR_SUCCESS)
{
//
// We only need to move the credman credentials for the entry
// if the szEntryName is changing, and credman ignores case?
//
bMoveCredentials = (0 != wcsicmp(lpszOldEntry, lpszNewEntry));
if (bMoveCredentials)
{
wcscpy(dialParams.szEntryName, lpszOldEntry);
RetVal = RasCredentialsRead(&dialParams, FALSE, NULL);
if (ERROR_NOT_FOUND == RetVal)
{
// No credentials are associated with this connectoid currently
RetVal = ERROR_SUCCESS;
bMoveCredentials = FALSE;
}
}
if (ERROR_SUCCESS == RetVal)
{
// Copy the credman credentials to the new name
if (bMoveCredentials)
{
wcscpy(dialParams.szEntryName, lpszNewEntry);
RetVal = RasCredentialsWrite(&dialParams, FALSE);
}
if (ERROR_SUCCESS == RetVal)
{
RetVal = RegRenameKey(hKeyRasBook, lpszOldEntry, lpszNewEntry);
if (ERROR_SUCCESS == RetVal)
{
wcscpy(dialParams.szEntryName, lpszOldEntry);
}
if (bMoveCredentials)
{
// Delete the old (or new if RegRenameKeyFailed) credman created credentials
if (ERROR_SUCCESS != RasCredentialsDelete(&dialParams))
{
RetVal = ERROR_INTERNAL_ERROR;
}
}
}
}
SecureZeroMemory(&dialParams, sizeof(dialParams));
RegCloseKey(hKeyRasBook);
}
}
}
if( ERROR_SUCCESS == RetVal )
{
EnterCriticalSection (&v_ListCS);
// Loop through the currently active contexts to update the dynamic linked list with the new name.
for( pppCntxt_p = pppContextList;
pppCntxt_p;
pppCntxt_p = pppCntxt_p->Next )
{
DEBUGMSG( ZONE_RAS, ( TEXT( " Data\r\n" ) ) );
//
// Do not count null sessions (is this possible?) or server sessions
//
pSession = pppCntxt_p->Session;
if( pSession && PPPADDREF(pSession, REF_RAS_RENAME) )
{
if( !pSession->bIsServer )
{
//Check for the old entry whose name is to be replaced.
if( lpszOldEntry && !_tcsnicmp(
pSession->rasDialParams.szEntryName,
lpszOldEntry,
RAS_MaxEntryName)
)
{
_tcsncpy(
pSession->rasDialParams.szEntryName,
lpszNewEntry,
RAS_MaxEntryName);
pSession->rasDialParams.szEntryName[RAS_MaxEntryName] = _T('\0');
PPPDELREF( pSession, REF_RAS_RENAME);
break;
}
}
PPPDELREF( pSession, REF_RAS_RENAME);
}
}
LeaveCriticalSection (&v_ListCS);
}
DEBUGMSG( ZONE_RAS | ZONE_FUNCTION | (ZONE_ERROR && RetVal),
(TEXT("-AfdRasRenameEntry Returning %d\n"), RetVal));
return RetVal;
}
static BOOL
IsEncryptedRasEntry(
IN HKEY hKey)
{
// VPN dev configs are currently encrypted. See AfdRasGetEntryProperties.
// Get the Entry data.
RASPENTRY RaspEntry;
DWORD dwSize, dwType;
LONG hRes;
dwSize = sizeof(RASPENTRY);
hRes = RegQueryValueEx (hKey, RASBOOK_ENTRY_VALUE, 0, &dwType,
(LPBYTE)&RaspEntry,
&dwSize);
if (ERROR_SUCCESS == hRes
&& dwSize == sizeof(RaspEntry)
&& (!_tcscmp (RaspEntry.szDeviceType, RASDT_Vpn)))
{
return TRUE;
}
return FALSE;
}
/*****************************************************************************
*
* @func DWORD | RasGetEntryDevConfig |
* This function retrieves the device information saved by the last
* successful call to the <f RasSetEntryDevConfig>
*
* @rdesc If the function succeeds, the return value is zero.
* If the function fails, the return value will be set to the
* error code.
* @ecode ERROR_CANNOT_OPEN_PHONEBOOK | Invalid szPhonebook
* @ecode ERROR_CANNOT_FIND_PHONEBOOK_ENTRY | Invalid szEntry
* @ecode ERROR_INVALID_NAME | Invalid szEntry
* @ecode ERROR_INVALID_PARAMETER | Invalid pdwDeviceID or
* pdwSize parameter.
* @ecode ERROR_BUFFER_TOO_SMALL | Specified buffer was too small.
* @parm LPCTSTR | lpszPhoneBook |
* Points to a null terminated string that specifies the full path and
* filename of the phonebook file. This parameter can be NULL, in which
* case the default phonebook file is used. This parameter should always
* be NULL for Windows 95 and WinCE since the phonebook entries are
* stored in the registry.
* @parm LPCTSTR | szEntry |
* Points to a null terminated string containing an existing entry name.
* @parm LPDWORD | pdwDeviceID |
* Returns the saved dwDeviceID.
* @parm LPDWORD | pdwSize |
* Size of the pDeviceConfig structure returned. This should be
* filled with the size required.
* @parm LPVARSTRING | pDeviceConfig |
* Specifies a pointer to the memory location of the type <f VARSTRING>
* where the device configuration structure is returned. If NULL then
* only the correct size is returned.
*
* @ex An example of how to use this function follows |
*
* DWORD dwDeviceID;
* LPVARSTRING pDeviceConfig;
* DWORD dwSize;
*
* dwSize = 0;
* if (RasGetEntryDeviceConfig (NULL, EntryName, &dwDeviceID,
* &dwSize, NULL)) {
* DEBUGMSG (1, (TEXT("Error getting device info size\r\n")));
* return;
* }
* pDeviceConfig = LocalAlloc (LPTR, dwSize);
* if (RasGetEntryDeviceConfig (NULL, EntryName, &dwDeviceID,
* &dwSize, pdwDeviceConfig)) {
* DEBUGMSG (1, (TEXT("Error getting device info\r\n")));
* return;
* } else {
* DEBUGMSG (1, (TEXT("dwDeviceID=%d\r\n"), dwDeviceID));
* if (pDeviceConfig) {
* DEBUGMSG (1, (TEXT("Have a device config @ 0x%X\r\n"),
* pDeviceConfig));
* LocalFree(pDeviceConfig);
* }
* }
*
*/
DWORD APIENTRY
AfdRasGetEntryDevConfig (LPCTSTR szPhonebook, LPCTSTR szEntry,
LPDWORD pdwDeviceID, LPDWORD pdwSize,
LPVARSTRING pDeviceConfig)
{
HKEY hKey;
LONG hRes;
DWORD RetVal;
DWORD dwType;
DWORD dwSize;
DEBUGMSG(ZONE_RAS | ZONE_FUNCTION,
(TEXT( "+RasGetEntryDevConfig( 0x%08X(%s), 0x%08X(%s), ")
TEXT("0x%08X, 0x%X(%d), 0x%08X)\r\n"),
szPhonebook, (szPhonebook != NULL) ? szPhonebook : TEXT("NULL"),
szEntry, (szEntry != NULL) ? szEntry : TEXT("NULL"),
pdwDeviceID, pdwSize, (pdwSize != NULL) ? *pdwSize : 0,
pDeviceConfig) );
DEBUGMSG (1, (TEXT("RasGetEntryDevConfig is obsolete, use RasGetEntryProperties instead\r\n")));
if (NULL == pdwSize)
{
DEBUGMSG (ZONE_RAS|ZONE_ERROR, (TEXT("-RasGetEntryDevConfig Invalid Parameter\n")));
return ERROR_INVALID_PARAMETER;
}
if (pdwDeviceID)
{
// We no longer use this
*pdwDeviceID = 0;
}
RetVal = OpenRasEntryKey(szPhonebook, szEntry, &hKey);
if (ERROR_SUCCESS == RetVal)
{
if (IsEncryptedRasEntry(hKey))
{
// Rather than duplicate the encryption/decryption code in this deprecated API
// just error out if the device type is VPN
RetVal = ERROR_UNKNOWN_DEVICE_TYPE;
}
else
{
hRes = RegQueryValueEx (hKey, RASBOOK_DEVCFG_VALUE, 0, &dwType,
NULL, &dwSize);
if (ERROR_SUCCESS == hRes) {
DEBUGMSG (ZONE_RAS|ZONE_ERROR,
(TEXT(" RasGetEntryDevConfig RasQuery Success Size=%d\r\n"),
dwSize));
if (NULL == pDeviceConfig) {
// They just want the length...
*pdwSize = dwSize + sizeof(VARSTRING);
} else {
if (*pdwSize >= (dwSize + sizeof(VARSTRING))) {
// Set up their VARstring data.
pDeviceConfig->dwTotalSize = *pdwSize;
pDeviceConfig->dwNeededSize = dwSize + sizeof(VARSTRING);
pDeviceConfig->dwUsedSize = dwSize + sizeof(VARSTRING);
pDeviceConfig->dwStringFormat = 0;
pDeviceConfig->dwStringSize = dwSize;
pDeviceConfig->dwStringOffset = sizeof(VARSTRING);
hRes = RegQueryValueEx (hKey, RASBOOK_DEVCFG_VALUE, 0,
&dwType,
(LPBYTE)pDeviceConfig + pDeviceConfig->dwStringOffset,
&dwSize);
} else {
RetVal = ERROR_BUFFER_TOO_SMALL;
}
}
} else {
DEBUGMSG (ZONE_RAS|ZONE_ERROR,
(TEXT(" RasGetEntryDevConfig Error from RegQuery %d\r\n"),
hRes));
RetVal = ERROR_CANNOT_FIND_PHONEBOOK_ENTRY;
}
}
RegCloseKey (hKey);
}
DEBUGMSG (ZONE_RAS, (TEXT("-RasGetEntryDevConfig %d\r\n"), RetVal));
return RetVal;
}
/*****************************************************************************
*
* @func DWORD | RasSetEntryDevConfig |
* This function saves the device information used with a Ras Entry.
*
* @rdesc If the function succeeds, the return value is zero.
* If the function fails, the return value will be set to the
* error code.
* @ecode ERROR_CANNOT_OPEN_PHONEBOOK | Invalid szPhonebook
* @ecode ERROR_CANNOT_FIND_PHONEBOOK_ENTRY | Invalid szEntry
* @ecode ERROR_INVALID_PARAMETER | Invalid pDeviceConfig parameter
*
* @parm LPCTSTR | lpszPhoneBook |
* Points to a null terminated string that specifies the full path and
* filename of the phonebook file. This parameter can be NULL, in which
* case the default phonebook file is used. This parameter should always
* be NULL for Windows 95 and WinCE since the phonebook entries are
* stored in the registry.
* @parm LPCTSTR | szEntry |
* Points to a null terminated string containing an existing entry name.
* @parm DWORD | dwDeviceID |
* The TAPI device ID to save.
* @parm LPVARSTRING | lpDeviceConfig |
* Specifies a pointer to the memory location of the type <f VARSTRING>
* of the device configuration structure.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -