node-expose-sspi-strict
Version:
Expose the Microsoft Windows SSPI interface in order to do NTLM and Kerberos authentication.
45 lines (44 loc) • 1.35 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
exports.__esModule = true;
exports.closeADConnection = exports.openADConnection = void 0;
var __1 = require("..");
var debug_1 = __importDefault(require("debug"));
var debug = debug_1["default"]('node-expose-sspi:adConnection');
var adConnection = {
counter: 0
};
/**
* Open an Active Directory connection only if no connection is already open.
*
* @export
*/
function openADConnection() {
if (adConnection.counter < 0) {
adConnection.counter = 0;
}
if (adConnection.counter === 0) {
__1.adsi.CoInitializeEx(['COINIT_MULTITHREADED']);
}
adConnection.counter++;
debug('openADConnection: counter: ', adConnection.counter);
}
exports.openADConnection = openADConnection;
/**
* Close an Active Directory connection only if nobodyelse still use a connection.
*
* @export
*/
function closeADConnection() {
adConnection.counter--;
if (adConnection.counter === 0) {
__1.adsi.CoUninitialize();
}
if (adConnection.counter < 0) {
adConnection.counter = 0;
}
debug('closeADConnection: counter: ', adConnection.counter);
}
exports.closeADConnection = closeADConnection;