Skip to content

Commit

Permalink
fix: don't try to release a connection if its null
Browse files Browse the repository at this point in the history
  • Loading branch information
rvazarkar committed Jul 19, 2024
1 parent d472c20 commit b1b6fb2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/CommonLib/ConnectionPoolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public ConnectionPoolManager(LdapConfig config, ILogger log = null, PortScanner
}

public void ReleaseConnection(LdapConnectionWrapper connectionWrapper, bool connectionFaulted = false) {
//I dont think this is possible, but at least account for it
if (connectionWrapper == null) {
return;
}
//I don't think this is possible, but at least account for it
if (!_pools.TryGetValue(connectionWrapper.PoolIdentifier, out var pool)) {
_log.LogWarning("Could not find pool for {Identifier}", connectionWrapper.PoolIdentifier);
connectionWrapper.Connection.Dispose();
Expand Down
1 change: 1 addition & 0 deletions src/CommonLib/DirectoryObjects/DirectoryEntryWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public bool TryGetProperty(string propertyName, out string value) {
var s = _entry.Properties[propertyName][0];
value = s switch {
string st => st,
int i => i.ToString(),
_ => null
};

Expand Down
17 changes: 8 additions & 9 deletions src/CommonLib/LdapUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,11 +1052,10 @@ public bool GetDomain(out Domain domain) {

if (_hostResolutionMap.TryGetValue(strippedHost, out var sid)) return (true, sid);

//Immediately start with NetWekstaGetInfo as its our most reliable indicator if successful
var workstationInfo = await GetWorkstationInfo(strippedHost);
if (workstationInfo.HasValue) {
var tempName = workstationInfo.Value.ComputerName;
var tempDomain = workstationInfo.Value.LanGroup;
//Immediately start with NetWkstaGetInfo as it's our most reliable indicator if successful
if (await GetWorkstationInfo(strippedHost) is (true, var workstationInfo)) {
var tempName = workstationInfo.ComputerName;
var tempDomain = workstationInfo.LanGroup;

if (string.IsNullOrWhiteSpace(tempDomain)) {
tempDomain = domain;
Expand Down Expand Up @@ -1138,14 +1137,14 @@ public bool GetDomain(out Domain domain) {
/// </summary>
/// <param name="hostname"></param>
/// <returns></returns>
private async Task<NetAPIStructs.WorkstationInfo100?> GetWorkstationInfo(string hostname) {
private async Task<(bool Success, NetAPIStructs.WorkstationInfo100 Info)> GetWorkstationInfo(string hostname) {
if (!await _portScanner.CheckPort(hostname))
return null;
return (false, default);

var result = _nativeMethods.CallNetWkstaGetInfo(hostname);
if (result.IsSuccess) return result.Value;
if (result.IsSuccess) return (true, result.Value);

return null;
return (false, default);
}

public async Task<(bool Success, string[] Sids)> GetGlobalCatalogMatches(string name, string domain) {
Expand Down

0 comments on commit b1b6fb2

Please sign in to comment.