2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2002-06-29 03:03:52 +04:00
|
|
|
|
|
|
|
// This source is mostly a bunch of Windows API calls. It is only compiled for
|
|
|
|
// Windows builds.
|
2002-07-24 06:43:22 +04:00
|
|
|
//
|
|
|
|
// Registry entries for Autodial mappings are located here:
|
|
|
|
// HKEY_CURRENT_USER\Software\Microsoft\RAS Autodial\Addresses
|
|
|
|
|
2002-06-29 03:03:52 +04:00
|
|
|
#include <windows.h>
|
|
|
|
#include <winsvc.h>
|
2008-08-28 01:44:54 +04:00
|
|
|
#include "nsString.h"
|
2002-06-29 03:03:52 +04:00
|
|
|
#include "nsAutodialWin.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2012-01-11 20:43:44 +04:00
|
|
|
#include "nsWindowsHelpers.h"
|
2002-06-29 03:03:52 +04:00
|
|
|
|
2005-07-06 07:06:32 +04:00
|
|
|
#define AUTODIAL_DEFAULT AUTODIAL_NEVER
|
|
|
|
|
2002-06-29 03:03:52 +04:00
|
|
|
//
|
|
|
|
// Log module for autodial logging...
|
|
|
|
//
|
|
|
|
// To enable logging (see prlog.h for full details):
|
|
|
|
//
|
|
|
|
// set NSPR_LOG_MODULES=Autodial:5
|
|
|
|
// set NSPR_LOG_FILE=nspr.log
|
|
|
|
//
|
2015-06-04 01:25:57 +03:00
|
|
|
// this enables LogLevel::Debug level information and places all output in
|
2002-06-29 03:03:52 +04:00
|
|
|
// the file nspr.log
|
|
|
|
//
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
static PRLogModuleInfo* gLog = nullptr;
|
2002-06-29 03:03:52 +04:00
|
|
|
|
2013-11-21 02:55:44 +04:00
|
|
|
#undef LOGD
|
|
|
|
#undef LOGE
|
2015-06-04 01:25:57 +03:00
|
|
|
#define LOGD(args) MOZ_LOG(gLog, mozilla::LogLevel::Debug, args)
|
|
|
|
#define LOGE(args) MOZ_LOG(gLog, mozilla::LogLevel::Error, args)
|
2002-06-29 03:03:52 +04:00
|
|
|
|
|
|
|
// Don't try to dial again within a few seconds of when user pressed cancel.
|
|
|
|
#define NO_RETRY_PERIOD_SEC 5
|
2009-04-14 08:41:33 +04:00
|
|
|
PRIntervalTime nsAutodial::mDontRetryUntil = 0;
|
2002-06-29 03:03:52 +04:00
|
|
|
|
|
|
|
// ctor.
|
2009-04-14 08:41:33 +04:00
|
|
|
nsAutodial::nsAutodial()
|
2005-07-06 07:06:32 +04:00
|
|
|
: mAutodialBehavior(AUTODIAL_DEFAULT),
|
2013-05-07 05:52:35 +04:00
|
|
|
mAutodialServiceDialingLocation(-1),
|
|
|
|
mNumRASConnectionEntries(0)
|
2002-06-29 03:03:52 +04:00
|
|
|
{
|
2007-02-08 20:48:22 +03:00
|
|
|
// Initializations that can be made again since RAS OS settings can
|
|
|
|
// change.
|
|
|
|
Init();
|
2002-06-29 03:03:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// dtor
|
2009-04-14 08:41:33 +04:00
|
|
|
nsAutodial::~nsAutodial()
|
2002-06-29 03:03:52 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get settings from the OS. These are settings that might change during
|
|
|
|
// the OS session. Call Init() again to pick up those changes if required.
|
|
|
|
// Returns NS_ERROR_FAILURE if error or NS_OK if success.
|
2009-04-14 08:41:33 +04:00
|
|
|
nsresult nsAutodial::Init()
|
2002-06-29 03:03:52 +04:00
|
|
|
{
|
2002-07-02 08:51:40 +04:00
|
|
|
if (!gLog)
|
|
|
|
gLog = PR_NewLogModule("Autodial");
|
|
|
|
|
2002-06-29 03:03:52 +04:00
|
|
|
mDefaultEntryName[0] = '\0';
|
|
|
|
mNumRASConnectionEntries = 0;
|
|
|
|
mAutodialBehavior = QueryAutodialBehavior();
|
|
|
|
|
|
|
|
// No need to continue in this case.
|
|
|
|
if (mAutodialBehavior == AUTODIAL_NEVER)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-07-02 08:51:40 +04:00
|
|
|
|
2002-06-29 03:03:52 +04:00
|
|
|
// Get the number of dialup entries in the phonebook.
|
|
|
|
mNumRASConnectionEntries = NumRASEntries();
|
|
|
|
|
|
|
|
// Get the name of the default entry.
|
2008-08-28 01:44:54 +04:00
|
|
|
nsresult result = GetDefaultEntryName(mDefaultEntryName,
|
|
|
|
sizeof(mDefaultEntryName));
|
2002-06-29 03:03:52 +04:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Should we attempt to dial on a network error? Yes if the Internet Options
|
2002-07-24 06:43:22 +04:00
|
|
|
// configured as such. Yes if the RAS autodial service is running (we'll try to
|
|
|
|
// force it to dial in that case by adding the network address to its db.)
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsAutodial::ShouldDialOnNetworkError()
|
2002-06-29 03:03:52 +04:00
|
|
|
{
|
|
|
|
// Don't try to dial again within a few seconds of when user pressed cancel.
|
|
|
|
if (mDontRetryUntil)
|
|
|
|
{
|
|
|
|
PRIntervalTime intervalNow = PR_IntervalNow();
|
|
|
|
if (intervalNow < mDontRetryUntil)
|
|
|
|
{
|
|
|
|
LOGD(("Autodial: Not dialing: too soon."));
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-06-29 03:03:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ((mAutodialBehavior == AUTODIAL_ALWAYS)
|
|
|
|
|| (mAutodialBehavior == AUTODIAL_ON_NETWORKERROR)
|
|
|
|
|| (mAutodialBehavior == AUTODIAL_USE_SERVICE));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The autodial info is set in Control Panel | Internet Options | Connections.
|
|
|
|
// The values are stored in the registry. This function gets those values from
|
|
|
|
// the registry and determines if we should never dial, always dial, or dial
|
|
|
|
// when there is no network found.
|
2009-04-14 08:41:33 +04:00
|
|
|
int nsAutodial::QueryAutodialBehavior()
|
2002-06-29 03:03:52 +04:00
|
|
|
{
|
|
|
|
if (IsAutodialServiceRunning())
|
2002-07-24 06:43:22 +04:00
|
|
|
{
|
|
|
|
// Is Autodial service enabled for the current login session?
|
|
|
|
DWORD disabled = 0;
|
|
|
|
DWORD size = sizeof(DWORD);
|
2012-01-03 14:08:12 +04:00
|
|
|
if (RasGetAutodialParamW(RASADP_LoginSessionDisable, &disabled, &size) == ERROR_SUCCESS)
|
2002-07-24 06:43:22 +04:00
|
|
|
{
|
|
|
|
if (!disabled)
|
|
|
|
{
|
|
|
|
// If current dialing location has autodial on, we'll let the service dial.
|
|
|
|
mAutodialServiceDialingLocation = GetCurrentLocation();
|
|
|
|
if (IsAutodialServiceEnabled(mAutodialServiceDialingLocation))
|
|
|
|
{
|
|
|
|
return AUTODIAL_USE_SERVICE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we get to here, then the service is not going to dial on error, so we
|
|
|
|
// can dial ourselves if the control panel settings are set up that way.
|
2002-06-29 03:03:52 +04:00
|
|
|
HKEY hKey = 0;
|
2008-08-28 01:44:54 +04:00
|
|
|
LONG result = ::RegOpenKeyExW(
|
2002-06-29 03:03:52 +04:00
|
|
|
HKEY_CURRENT_USER,
|
2008-08-28 01:44:54 +04:00
|
|
|
L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
|
2002-06-29 03:03:52 +04:00
|
|
|
0,
|
|
|
|
KEY_READ,
|
|
|
|
&hKey);
|
|
|
|
|
|
|
|
if (result != ERROR_SUCCESS)
|
|
|
|
{
|
2002-07-02 08:51:40 +04:00
|
|
|
LOGE(("Autodial: Error opening reg key Internet Settings"));
|
2002-06-29 03:03:52 +04:00
|
|
|
return AUTODIAL_NEVER;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD entryType = 0;
|
|
|
|
DWORD autodial = 0;
|
|
|
|
DWORD onDemand = 0;
|
|
|
|
DWORD paramSize = sizeof(DWORD);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
result = ::RegQueryValueExW(hKey, L"EnableAutodial", nullptr, &entryType, (LPBYTE)&autodial, ¶mSize);
|
2002-06-29 03:03:52 +04:00
|
|
|
if (result != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
::RegCloseKey(hKey);
|
2002-07-02 08:51:40 +04:00
|
|
|
LOGE(("Autodial: Error reading reg value EnableAutodial."));
|
2002-06-29 03:03:52 +04:00
|
|
|
return AUTODIAL_NEVER;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
result = ::RegQueryValueExW(hKey, L"NoNetAutodial", nullptr, &entryType, (LPBYTE)&onDemand, ¶mSize);
|
2002-06-29 03:03:52 +04:00
|
|
|
if (result != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
::RegCloseKey(hKey);
|
2002-07-02 08:51:40 +04:00
|
|
|
LOGE(("Autodial: Error reading reg value NoNetAutodial."));
|
2002-06-29 03:03:52 +04:00
|
|
|
return AUTODIAL_NEVER;
|
|
|
|
}
|
|
|
|
|
|
|
|
::RegCloseKey(hKey);
|
|
|
|
|
|
|
|
if (!autodial)
|
|
|
|
{
|
|
|
|
return AUTODIAL_NEVER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (onDemand)
|
|
|
|
{
|
|
|
|
return AUTODIAL_ON_NETWORKERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return AUTODIAL_ALWAYS;
|
|
|
|
}
|
|
|
|
}
|
2005-07-06 07:06:32 +04:00
|
|
|
}
|
|
|
|
|
2002-06-29 03:03:52 +04:00
|
|
|
// If the RAS autodial service is running, use it. Otherwise, dial
|
|
|
|
// the default RAS connection. There are two possible RAS dialogs:
|
|
|
|
// one that dials a single entry, and one that lets the user choose which
|
|
|
|
// to dial. If there is only one connection entry in the phone book, or
|
|
|
|
// there are multiple entries but one is defined as the default, we'll use
|
|
|
|
// the single entry dial dialog. If there are multiple connection entries,
|
|
|
|
// and none is specified as default, we'll bring up the diallog which lets
|
|
|
|
// the user select the connection entry to use.
|
2002-07-24 06:43:22 +04:00
|
|
|
//
|
|
|
|
// Return values:
|
|
|
|
// NS_OK: dialing was successful and caller should retry
|
|
|
|
// all other values indicate that the caller should not retry
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult nsAutodial::DialDefault(const char16_t* hostName)
|
2002-06-29 03:03:52 +04:00
|
|
|
{
|
|
|
|
mDontRetryUntil = 0;
|
|
|
|
|
|
|
|
if (mAutodialBehavior == AUTODIAL_NEVER)
|
|
|
|
{
|
2002-07-24 06:43:22 +04:00
|
|
|
return NS_ERROR_FAILURE; // don't retry the network error
|
2002-06-29 03:03:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If already a RAS connection, bail.
|
|
|
|
if (IsRASConnected())
|
|
|
|
{
|
|
|
|
LOGD(("Autodial: Not dialing: active connection."));
|
2002-07-24 06:43:22 +04:00
|
|
|
return NS_ERROR_FAILURE; // don't retry
|
2002-06-29 03:03:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If no dialup connections configured, bail.
|
|
|
|
if (mNumRASConnectionEntries <= 0)
|
|
|
|
{
|
|
|
|
LOGD(("Autodial: Not dialing: no entries."));
|
2002-07-24 06:43:22 +04:00
|
|
|
return NS_ERROR_FAILURE; // don't retry
|
2002-06-29 03:03:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-24 06:43:22 +04:00
|
|
|
// If autodial service is running, let it dial. In order for it to dial more
|
2002-06-29 03:03:52 +04:00
|
|
|
// reliably, we have to add the target address to the autodial database.
|
|
|
|
// This is the only way the autodial service dial if there is a network
|
2002-07-24 06:43:22 +04:00
|
|
|
// adapter installed. But even then it might not dial. We have to assume that
|
|
|
|
// it will though, or we could end up with two attempts to dial on the same
|
|
|
|
// network error if the user cancels the first one: one from the service and
|
|
|
|
// one from us.
|
2002-06-29 03:03:52 +04:00
|
|
|
// See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/rras/ras4over_3dwl.asp
|
|
|
|
if (mAutodialBehavior == AUTODIAL_USE_SERVICE)
|
|
|
|
{
|
2002-07-24 06:43:22 +04:00
|
|
|
AddAddressToAutodialDirectory(hostName);
|
|
|
|
return NS_ERROR_FAILURE; // don't retry
|
2002-06-29 03:03:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Do the dialing ourselves.
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If a default dial entry is configured, use it.
|
|
|
|
if (mDefaultEntryName[0] != '\0')
|
|
|
|
{
|
|
|
|
LOGD(("Autodial: Dialing default: %s.",mDefaultEntryName));
|
|
|
|
|
|
|
|
RASDIALDLG rasDialDlg;
|
2008-08-28 01:44:54 +04:00
|
|
|
memset(&rasDialDlg, 0, sizeof(rasDialDlg));
|
|
|
|
rasDialDlg.dwSize = sizeof(rasDialDlg);
|
2002-06-29 03:03:52 +04:00
|
|
|
|
2012-01-03 14:08:12 +04:00
|
|
|
BOOL dialed =
|
2012-07-30 18:20:58 +04:00
|
|
|
RasDialDlgW(nullptr, mDefaultEntryName, nullptr, &rasDialDlg);
|
2002-07-24 06:43:22 +04:00
|
|
|
|
2002-06-29 03:03:52 +04:00
|
|
|
if (!dialed)
|
|
|
|
{
|
|
|
|
if (rasDialDlg.dwError != 0)
|
|
|
|
{
|
|
|
|
LOGE(("Autodial ::RasDialDlg failed: Error: %d.",
|
|
|
|
rasDialDlg.dwError));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mDontRetryUntil = PR_IntervalNow() + PR_SecondsToInterval(NO_RETRY_PERIOD_SEC);
|
|
|
|
LOGD(("Autodial: User cancelled dial."));
|
|
|
|
}
|
2002-07-24 06:43:22 +04:00
|
|
|
return NS_ERROR_FAILURE; // don't retry
|
2002-06-29 03:03:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LOGD(("Autodial: RAS dialup connection successful."));
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no default connection specified, open the dialup dialog that lets
|
|
|
|
// the user specifiy which connection to dial.
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOGD(("Autodial: Prompting for phonebook entry."));
|
|
|
|
|
|
|
|
RASPBDLG rasPBDlg;
|
2008-08-28 01:44:54 +04:00
|
|
|
memset(&rasPBDlg, 0, sizeof(rasPBDlg));
|
|
|
|
rasPBDlg.dwSize = sizeof(rasPBDlg);
|
2002-06-29 03:03:52 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
BOOL dialed = RasPhonebookDlgW(nullptr, nullptr, &rasPBDlg);
|
2002-06-29 03:03:52 +04:00
|
|
|
|
|
|
|
if (!dialed)
|
|
|
|
{
|
|
|
|
if (rasPBDlg.dwError != 0)
|
|
|
|
{
|
|
|
|
LOGE(("Autodial: ::RasPhonebookDlg failed: Error = %d.",
|
|
|
|
rasPBDlg.dwError));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mDontRetryUntil = PR_IntervalNow() + PR_SecondsToInterval(NO_RETRY_PERIOD_SEC);
|
|
|
|
LOGD(("Autodial: User cancelled dial."));
|
|
|
|
}
|
|
|
|
|
2002-07-24 06:43:22 +04:00
|
|
|
return NS_ERROR_FAILURE; // don't retry
|
2002-06-29 03:03:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LOGD(("Autodial: RAS dialup connection successful."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-24 06:43:22 +04:00
|
|
|
// Retry because we just established a dialup connection.
|
2002-06-29 03:03:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-07-06 07:06:32 +04:00
|
|
|
|
2002-06-29 03:03:52 +04:00
|
|
|
// Check to see if RAS is already connected.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsAutodial::IsRASConnected()
|
2002-06-29 03:03:52 +04:00
|
|
|
{
|
|
|
|
DWORD connections;
|
|
|
|
RASCONN rasConn;
|
2008-08-28 01:44:54 +04:00
|
|
|
rasConn.dwSize = sizeof(rasConn);
|
|
|
|
DWORD structSize = sizeof(rasConn);
|
2002-06-29 03:03:52 +04:00
|
|
|
|
2012-01-03 14:08:12 +04:00
|
|
|
DWORD result = RasEnumConnectionsW(&rasConn, &structSize, &connections);
|
2002-06-29 03:03:52 +04:00
|
|
|
|
|
|
|
// ERROR_BUFFER_TOO_SMALL is OK because we only need one struct.
|
|
|
|
if (result == ERROR_SUCCESS || result == ERROR_BUFFER_TOO_SMALL)
|
|
|
|
{
|
|
|
|
return (connections > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
LOGE(("Autodial: ::RasEnumConnections failed: Error = %d", result));
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-06-29 03:03:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the first RAS dial entry name from the phonebook.
|
2013-12-03 18:54:59 +04:00
|
|
|
nsresult nsAutodial::GetFirstEntryName(wchar_t* entryName, int bufferSize)
|
2002-06-29 03:03:52 +04:00
|
|
|
{
|
2008-08-28 01:44:54 +04:00
|
|
|
RASENTRYNAMEW rasEntryName;
|
|
|
|
rasEntryName.dwSize = sizeof(rasEntryName);
|
|
|
|
DWORD cb = sizeof(rasEntryName);
|
2002-06-29 03:03:52 +04:00
|
|
|
DWORD cEntries = 0;
|
|
|
|
|
|
|
|
DWORD result =
|
2012-07-30 18:20:58 +04:00
|
|
|
RasEnumEntriesW(nullptr, nullptr, &rasEntryName, &cb, &cEntries);
|
2002-06-29 03:03:52 +04:00
|
|
|
|
|
|
|
// ERROR_BUFFER_TOO_SMALL is OK because we only need one struct.
|
|
|
|
if (result == ERROR_SUCCESS || result == ERROR_BUFFER_TOO_SMALL)
|
|
|
|
{
|
2008-08-28 01:44:54 +04:00
|
|
|
wcsncpy(entryName, rasEntryName.szEntryName,
|
|
|
|
bufferSize / sizeof(*entryName));
|
2002-06-29 03:03:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the number of RAS dial entries in the phonebook.
|
2009-04-14 08:41:33 +04:00
|
|
|
int nsAutodial::NumRASEntries()
|
2002-06-29 03:03:52 +04:00
|
|
|
{
|
2008-08-28 01:44:54 +04:00
|
|
|
RASENTRYNAMEW rasEntryName;
|
|
|
|
rasEntryName.dwSize = sizeof(rasEntryName);
|
|
|
|
DWORD cb = sizeof(rasEntryName);
|
2002-06-29 03:03:52 +04:00
|
|
|
DWORD cEntries = 0;
|
|
|
|
|
|
|
|
|
|
|
|
DWORD result =
|
2012-07-30 18:20:58 +04:00
|
|
|
RasEnumEntriesW(nullptr, nullptr, &rasEntryName, &cb, &cEntries);
|
2002-06-29 03:03:52 +04:00
|
|
|
|
|
|
|
// ERROR_BUFFER_TOO_SMALL is OK because we only need one struct.
|
|
|
|
if (result == ERROR_SUCCESS || result == ERROR_BUFFER_TOO_SMALL)
|
|
|
|
{
|
|
|
|
return (int)cEntries;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the name of the default dial entry.
|
2013-12-03 18:54:59 +04:00
|
|
|
nsresult nsAutodial::GetDefaultEntryName(wchar_t* entryName, int bufferSize)
|
2002-06-29 03:03:52 +04:00
|
|
|
{
|
|
|
|
// No RAS dialup entries.
|
|
|
|
if (mNumRASConnectionEntries <= 0)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2002-07-24 06:43:22 +04:00
|
|
|
// Single RAS dialup entry. Use it as the default to autodial.
|
2002-06-29 03:03:52 +04:00
|
|
|
if (mNumRASConnectionEntries == 1)
|
|
|
|
{
|
|
|
|
return GetFirstEntryName(entryName, bufferSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Multiple RAS dialup entries. If a default configured in the registry,
|
|
|
|
// use it.
|
|
|
|
//
|
|
|
|
// For Windows XP: HKCU/Software/Microsoft/RAS Autodial/Default/DefaultInternet.
|
|
|
|
// or HKLM/Software/Microsoft/RAS Autodial/Default/DefaultInternet.
|
|
|
|
|
2013-12-03 18:54:59 +04:00
|
|
|
const wchar_t* key = L"Software\\Microsoft\\RAS Autodial\\Default";
|
|
|
|
const wchar_t* val = L"DefaultInternet";
|
2002-06-29 03:03:52 +04:00
|
|
|
|
|
|
|
HKEY hKey = 0;
|
|
|
|
LONG result = 0;
|
|
|
|
|
2012-02-23 18:53:55 +04:00
|
|
|
|
|
|
|
// Try HKCU first.
|
|
|
|
result = ::RegOpenKeyExW(
|
|
|
|
HKEY_CURRENT_USER,
|
|
|
|
key,
|
|
|
|
0,
|
|
|
|
KEY_READ,
|
|
|
|
&hKey);
|
2002-06-29 03:03:52 +04:00
|
|
|
|
2012-02-23 18:53:55 +04:00
|
|
|
if (result != ERROR_SUCCESS)
|
2012-02-09 01:04:21 +04:00
|
|
|
{
|
2012-02-23 18:53:55 +04:00
|
|
|
// If not present, try HKLM.
|
2012-02-09 01:04:21 +04:00
|
|
|
result = ::RegOpenKeyExW(
|
2012-02-23 18:53:55 +04:00
|
|
|
HKEY_LOCAL_MACHINE,
|
2012-02-09 01:04:21 +04:00
|
|
|
key,
|
|
|
|
0,
|
|
|
|
KEY_READ,
|
|
|
|
&hKey);
|
|
|
|
|
|
|
|
if (result != ERROR_SUCCESS)
|
|
|
|
{
|
2012-02-23 18:53:55 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-02-09 01:04:21 +04:00
|
|
|
}
|
|
|
|
}
|
2002-06-29 03:03:52 +04:00
|
|
|
|
|
|
|
|
|
|
|
DWORD entryType = 0;
|
|
|
|
DWORD buffSize = bufferSize;
|
|
|
|
|
2008-08-28 01:44:54 +04:00
|
|
|
result = ::RegQueryValueExW(hKey,
|
2002-06-29 03:03:52 +04:00
|
|
|
val,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr,
|
2002-06-29 03:03:52 +04:00
|
|
|
&entryType,
|
|
|
|
(LPBYTE)entryName,
|
|
|
|
&buffSize);
|
|
|
|
|
|
|
|
::RegCloseKey(hKey);
|
|
|
|
|
|
|
|
|
|
|
|
if (result != ERROR_SUCCESS)
|
|
|
|
{
|
2002-07-02 08:51:40 +04:00
|
|
|
// Results in a prompt for which to use at dial time.
|
2002-06-29 03:03:52 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Determine if the autodial service is running on this PC.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsAutodial::IsAutodialServiceRunning()
|
2002-06-29 03:03:52 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
nsAutoServiceHandle hSCManager(OpenSCManager(nullptr,
|
2012-01-11 20:43:44 +04:00
|
|
|
SERVICES_ACTIVE_DATABASE,
|
|
|
|
SERVICE_QUERY_STATUS));
|
2002-06-29 03:03:52 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (hSCManager == nullptr)
|
2002-06-29 03:03:52 +04:00
|
|
|
{
|
|
|
|
LOGE(("Autodial: failed to open service control manager. Error %d.",
|
|
|
|
::GetLastError()));
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-06-29 03:03:52 +04:00
|
|
|
}
|
|
|
|
|
2012-01-11 20:43:44 +04:00
|
|
|
nsAutoServiceHandle hService(OpenServiceW(hSCManager,
|
|
|
|
L"RasAuto",
|
|
|
|
SERVICE_QUERY_STATUS));
|
2002-06-29 03:03:52 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (hSCManager == nullptr)
|
2002-06-29 03:03:52 +04:00
|
|
|
{
|
|
|
|
LOGE(("Autodial: failed to open RasAuto service."));
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-06-29 03:03:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SERVICE_STATUS status;
|
|
|
|
if (!QueryServiceStatus(hService, &status))
|
|
|
|
{
|
|
|
|
LOGE(("Autodial: ::QueryServiceStatus() failed. Error: %d",
|
|
|
|
::GetLastError()));
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-06-29 03:03:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (status.dwCurrentState == SERVICE_RUNNING);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the specified address to the autodial directory.
|
2013-12-03 18:54:59 +04:00
|
|
|
bool nsAutodial::AddAddressToAutodialDirectory(char16ptr_t hostName)
|
2002-06-29 03:03:52 +04:00
|
|
|
{
|
|
|
|
// First see if there is already a db entry for this address.
|
2008-08-28 01:44:54 +04:00
|
|
|
RASAUTODIALENTRYW autodialEntry;
|
|
|
|
autodialEntry.dwSize = sizeof(autodialEntry);
|
|
|
|
DWORD size = sizeof(autodialEntry);
|
2002-06-29 03:03:52 +04:00
|
|
|
DWORD entries = 0;
|
|
|
|
|
2012-01-03 14:08:12 +04:00
|
|
|
DWORD result = RasGetAutodialAddressW(hostName,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr,
|
2012-01-03 14:08:12 +04:00
|
|
|
&autodialEntry,
|
|
|
|
&size,
|
|
|
|
&entries);
|
2002-06-29 03:03:52 +04:00
|
|
|
|
2002-07-24 06:43:22 +04:00
|
|
|
// If there is already at least 1 entry in db for this address, return.
|
|
|
|
if (result != ERROR_FILE_NOT_FOUND)
|
2002-06-29 03:03:52 +04:00
|
|
|
{
|
|
|
|
LOGD(("Autodial: Address %s already in autodial db.", hostName));
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-06-29 03:03:52 +04:00
|
|
|
}
|
|
|
|
|
2008-08-28 01:44:54 +04:00
|
|
|
autodialEntry.dwSize = sizeof(autodialEntry);
|
2002-06-29 03:03:52 +04:00
|
|
|
autodialEntry.dwFlags = 0;
|
2002-07-24 06:43:22 +04:00
|
|
|
autodialEntry.dwDialingLocation = mAutodialServiceDialingLocation;
|
2008-08-28 01:44:54 +04:00
|
|
|
GetDefaultEntryName(autodialEntry.szEntry, sizeof(autodialEntry.szEntry));
|
2002-06-29 03:03:52 +04:00
|
|
|
|
2012-01-03 14:08:12 +04:00
|
|
|
result = RasSetAutodialAddressW(hostName,
|
|
|
|
0,
|
|
|
|
&autodialEntry,
|
|
|
|
sizeof(autodialEntry),
|
|
|
|
1);
|
2002-06-29 03:03:52 +04:00
|
|
|
|
|
|
|
if (result != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
LOGE(("Autodial ::RasSetAutodialAddress failed result %d.", result));
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-06-29 03:03:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
LOGD(("Autodial: Added address %s to RAS autodial db for entry %s.",
|
2008-08-28 01:44:54 +04:00
|
|
|
hostName, NS_ConvertUTF16toUTF8(autodialEntry.szEntry).get()));
|
2002-06-29 03:03:52 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-06-29 03:03:52 +04:00
|
|
|
}
|
2002-07-24 06:43:22 +04:00
|
|
|
|
|
|
|
// Get the current TAPI dialing location.
|
2009-04-14 08:41:33 +04:00
|
|
|
int nsAutodial::GetCurrentLocation()
|
2002-07-24 06:43:22 +04:00
|
|
|
{
|
|
|
|
HKEY hKey = 0;
|
2008-08-28 01:44:54 +04:00
|
|
|
LONG result = ::RegOpenKeyExW(
|
2002-07-24 06:43:22 +04:00
|
|
|
HKEY_LOCAL_MACHINE,
|
2008-08-28 01:44:54 +04:00
|
|
|
L"Software\\Microsoft\\Windows\\CurrentVersion\\Telephony\\Locations",
|
2002-07-24 06:43:22 +04:00
|
|
|
0,
|
|
|
|
KEY_READ,
|
|
|
|
&hKey);
|
|
|
|
|
|
|
|
if (result != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
LOGE(("Autodial: Error opening reg key ...CurrentVersion\\Telephony\\Locations"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD entryType = 0;
|
|
|
|
DWORD location = 0;
|
|
|
|
DWORD paramSize = sizeof(DWORD);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
result = ::RegQueryValueExW(hKey, L"CurrentID", nullptr, &entryType, (LPBYTE)&location, ¶mSize);
|
2002-07-24 06:43:22 +04:00
|
|
|
if (result != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
::RegCloseKey(hKey);
|
|
|
|
LOGE(("Autodial: Error reading reg value CurrentID."));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
::RegCloseKey(hKey);
|
|
|
|
return location;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if autodial for the specified location is enabled.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsAutodial::IsAutodialServiceEnabled(int location)
|
2002-07-24 06:43:22 +04:00
|
|
|
{
|
|
|
|
if (location < 0)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-07-24 06:43:22 +04:00
|
|
|
|
2011-08-30 22:55:14 +04:00
|
|
|
BOOL enabled;
|
2012-01-03 14:08:12 +04:00
|
|
|
if (RasGetAutodialEnableW(location, &enabled) != ERROR_SUCCESS)
|
2002-07-24 06:43:22 +04:00
|
|
|
{
|
|
|
|
LOGE(("Autodial: Error calling RasGetAutodialEnable()"));
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-07-24 06:43:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return enabled;
|
|
|
|
}
|