UNPKG

node-expose-sspi-strict

Version:

Expose the Microsoft Windows SSPI interface in order to do NTLM and Kerberos authentication.

52 lines (51 loc) 1.6 kB
"use strict"; exports.__esModule = true; exports.isActiveDirectoryReachable = exports.isOnDomain = exports.getDefaultDomain = void 0; var api_1 = require("../../lib/api"); var adConnection_1 = require("./adConnection"); /** * Get the domain (Microsoft domain) or hostname (workgroup) of this machine. * * @returns {string} domain name */ function getDefaultDomain() { var str = api_1.sspi.GetUserNameEx('NameSamCompatible'); var domain = str.split('\\')[0]; return domain; } exports.getDefaultDomain = getDefaultDomain; /** * Want to know if your computer has joined a Microsoft Windows domain ? * * @export * @returns {boolean} true if this computer joined a domain, false otherwise. */ function isOnDomain() { return api_1.sysinfo.GetComputerNameEx('ComputerNameDnsDomain').length > 0; } exports.isOnDomain = isOnDomain; function isActiveDirectoryReachable() { var gc; var element; var ds; try { adConnection_1.openADConnection(); gc = api_1.adsi.ADsOpenObjectSync({ binding: 'GC:', riid: 'IID_IADsContainer' }); element = gc.Next(); ds = element.QueryInterface('IID_IDirectorySearch'); } catch (e) { return false; } finally { ds.Release(); element === null || element === void 0 ? void 0 : element.Release(); gc === null || gc === void 0 ? void 0 : gc.Release(); adConnection_1.closeADConnection(); } return true; } exports.isActiveDirectoryReachable = isActiveDirectoryReachable;