Skip to content

Active Directory authentication library wrapper written in C++

License

Notifications You must be signed in to change notification settings

theriverman/libAdAuth

Repository files navigation

libAdAuth

Active Directory authentication library wrapper written in C++

Motivation

Authenticating users against Active Directory in Python is slow with pure Python packages. I wanted to speed up the process for saving time on both ends (server & client). It seemed trivial to implement the AD authentication in C/C++ and call it from Python.

According to my simple, unaccredited tests, the speedup was clearly observable.

Getting user details, such as, e-mail address, full name, manager, group memberships, etc... have been deliberately excluded from this wrapper because I wanted to speed up the login procedure only. The rest of the calls to AD are done asynchronously without blocking the end-user.

Last, but not least I wanted to learn about the C/C++ <-> Python interoperability while trying to write a cross-platform code.

Building

The libAdAuth library is cross-platform (Linux + Windows) library with a single platform dependency.
To build the library, a C/C++ compiler will be required on each build system.

The built binaries and/or libraries are put in the out directory.

Dependencies

Linux

The recommended compiler is g++ 5.4.0 or newer.
To be able to link against libldap, it must be installed first.

To install libldap on Debian/Ubuntu, execute the following command:
sudo apt-get install libldap2-dev

macOS

The recommended compiler is g++ (clang).
To be able to link against libldap, it must be installed first.

To install libldap on macOS with brew, execute the following command:
brew install openldap

Windows

The recommended compiler is MSVC 2017 or newer.
To be able to link against winldap, it must be installed first.

To install winldap, the Windows 10 SDK must be installed.

Implementation

The libAdAuth library is compiled to a Shared Library on all platforms.

  • Linux: libAdAuth.so
  • macOS: libAdAuth.dylib
  • Windows: libAdAuth.dll

The libAdAuth library exposes a single C function interface in Release build and an optional debug function called foo in Debug build mode.

// Release Build
int auth(char *username, char *password, char *host, char *domain, int *port);

// Debug Build only [ with -DDEBUG ]
int foo(); // "Hello from foo()"

Python

For a Python reference implementation for each platform, see the following files:

Copyright

Copyright © 2019 - 2020 github.com/theriverman