Remove windows-specific smartcard manager startup code completely
Restore the behaviour of the original node-pcsclite[1], which is to simply fail and leave retry handling to the user. [1] https://github.com/santigimeno/node-pcsclite/blob/master/src/pcsclite.cpp#L32 Signed-off-by: Stefan Knoblich <stkn@bitplumber.de>
This commit is contained in:
@@ -31,51 +31,12 @@ PCSCLite::PCSCLite(): m_card_context(0),
|
|||||||
assert(uv_mutex_init(&m_mutex) == 0);
|
assert(uv_mutex_init(&m_mutex) == 0);
|
||||||
assert(uv_cond_init(&m_cond) == 0);
|
assert(uv_cond_init(&m_cond) == 0);
|
||||||
|
|
||||||
// TODO: consider removing this Windows workaround that should not be needed anymore
|
// TODO: make dwScope (now hard-coded to SCARD_SCOPE_SYSTEM) customisable
|
||||||
#ifdef _WIN32
|
LONG result = SCardEstablishContext(SCARD_SCOPE_SYSTEM,
|
||||||
HKEY hKey;
|
|
||||||
DWORD startStatus, datacb = sizeof(DWORD);
|
|
||||||
LONG _res;
|
|
||||||
_res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Services\\SCardSvr", 0, KEY_READ, &hKey);
|
|
||||||
if (_res != ERROR_SUCCESS) {
|
|
||||||
printf("Reg Open Key exited with %d\n", _res);
|
|
||||||
goto postServiceCheck;
|
|
||||||
}
|
|
||||||
_res = RegQueryValueEx(hKey, "Start", NULL, NULL, (LPBYTE)&startStatus, &datacb);
|
|
||||||
if (_res != ERROR_SUCCESS) {
|
|
||||||
printf("Reg Query Value exited with %d\n", _res);
|
|
||||||
goto postServiceCheck;
|
|
||||||
}
|
|
||||||
if (startStatus != 2) {
|
|
||||||
SHELLEXECUTEINFO seInfo = {0};
|
|
||||||
seInfo.cbSize = sizeof(SHELLEXECUTEINFO);
|
|
||||||
seInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
|
|
||||||
seInfo.hwnd = NULL;
|
|
||||||
seInfo.lpVerb = "runas";
|
|
||||||
seInfo.lpFile = "sc.exe";
|
|
||||||
seInfo.lpParameters = "config SCardSvr start=auto";
|
|
||||||
seInfo.lpDirectory = NULL;
|
|
||||||
seInfo.nShow = SW_SHOWNORMAL;
|
|
||||||
seInfo.hInstApp = NULL;
|
|
||||||
if (!ShellExecuteEx(&seInfo)) {
|
|
||||||
printf("Shell Execute failed with %d\n", GetLastError());
|
|
||||||
goto postServiceCheck;
|
|
||||||
}
|
|
||||||
WaitForSingleObject(seInfo.hProcess, INFINITE);
|
|
||||||
CloseHandle(seInfo.hProcess);
|
|
||||||
}
|
|
||||||
postServiceCheck:
|
|
||||||
#endif // _WIN32
|
|
||||||
|
|
||||||
LONG result, attempt = 0;
|
|
||||||
// TODO: consider removing this do-while Windows workaround that should not be needed anymore
|
|
||||||
do {
|
|
||||||
// TODO: make dwScope (now hard-coded to SCARD_SCOPE_SYSTEM) customisable
|
|
||||||
result = SCardEstablishContext(SCARD_SCOPE_SYSTEM,
|
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
&m_card_context);
|
&m_card_context);
|
||||||
} while((result == SCARD_E_NO_SERVICE || result == SCARD_E_SERVICE_STOPPED) && ++attempt <= 10);
|
|
||||||
if (result != SCARD_S_SUCCESS) {
|
if (result != SCARD_S_SUCCESS) {
|
||||||
Nan::ThrowError(error_msg("SCardEstablishContext", result).c_str());
|
Nan::ThrowError(error_msg("SCardEstablishContext", result).c_str());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user