KNM.LDAPHelper 1.1.3

KNM.LdapUserInfoHelper

.NET

A cross-platform .NET library for detecting the local LDAP/Active Directory user context and retrieving the user’s Security Identifier (SID/S-1-x-x). Made for easy use with Dependency Injection and zero external configuration.

Features

  • Automatic Windows AD Discovery: Detects domain and controller from the environment—no configuration required
  • DNS-based Discovery on Linux/macOS: Attempts SRV lookup _ldap._tcp.<domain> using the machine DNS suffix to auto-discover LDAP host and base DN
  • SID Retrieval: Automatically obtains the Windows user’s Security Identifier (SID) when running on Windows
  • Global Directory User Lookup: Query Active Directory / LDAP for any directory object by SID or username, or perform global text search on multiple attributes
  • Cross-platform: Works on Windows and provides best-effort DNS-based LDAP discovery on Linux/macOS, with safe fallbacks and diagnostics
  • Dependency Injection Ready: Single extension method AddKnmLdapHelper() to register the provider in any .NET application

Quick Start

1. Installation

dotnet add package KNM.LdapUserInfoHelper

2. Registration (Program.cs)

using KNM.LDAPHelper;

var builder = WebApplication.CreateBuilder(args);

// KNM LDAP Helper registration (singleton, auto-discovery)
builder.Services.AddKnmLdapCollection();

var app = builder.Build();

3. Usage Example

public class MyService
{
    private readonly LdapUserInfo _ldapUserInfo;

    public MyService(ILdapUserInfoProvider ldapUserInfoProvider)
    {
        _ldapUserInfo = ldapUserInfoProvider.GetUserInfo();
    }

    public void PrintLdapUser()
    {
        if (_ldapUserInfo.LdapUser)
            Console.WriteLine($"LDAP/AD user detected. SID: {_ldapUserInfo.SsId}");
        else
            Console.WriteLine($"No LDAP/AD context detected. Result: {_ldapUserInfo.Result}");
    }
}

4. Directory User Lookup Examples

// Lookup by SID (Windows: objectSid, non-Windows: falls back to sAMAccountName)
var user = await ldapProvider.FindUserBySsIdAsync("S-1-5-21-...");

// Global search across multiple attributes
var users = await ldapProvider.FindUsersAsync("john"); // searches name, username, mail, etc.

Data Models

Property Type Description
LdapUser bool True if valid LDAP/AD environment detected
SsId string User Security Identifier (Windows) or empty
Result string? Diagnostic message
DirectoryUser.AccountEnabled bool True if UAC bit 2 (ACCOUNTDISABLE) is not set
DirectoryUser.ResourceType string "User", "Computer", etc. from objectCategory

Platform Support

Platform Auto-Discovery SID Support Search
Windows Domain.GetComputerDomain() ✅ Full ✅ Full
Linux/macOS DNS SRV _ldap._tcp.domain ❌ Fallback username ✅ Full

How it Works

Windows: Uses Domain.GetComputerDomain() → picks DC → binds LDAP → gets root DN → reads WindowsIdentity.User

Linux/macOS: hostname -d → DNS SRV lookup → LDAP bind → root DN discovery

All connections use LdapConnection with AuthType.Negotiate and proper binary SID encoding.

Licensing

Proprietary / Private Repository (KoNiMa Internal)

No packages depend on KNM.LDAPHelper.

Version Downloads Last updated
1.1.4 3 12/01/2026
1.1.3 1 12/01/2026
1.1.2 4 10/01/2026
1.1.1 5 25/11/2025
1.1.0 1 25/11/2025
1.0.9 1 25/11/2025
1.0.8 1 25/11/2025
1.0.7 1 25/11/2025
1.0.6 1 25/11/2025
1.0.5 1 25/11/2025