Skip to content

fretn/sqldap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQLDAP

Ever wanted to query AD or LDAP with SQL like queries ?

I'm going to answer this question myself: yes ! Why ? Because I never could remember all the ldapsearch arguments and filters, etc.

But after building this tool I am now a master of ldapsearch :)

Supported queries:

  • simple select queries: SELECT * FROM "$tablename" WHERE var=val;
  • show databases; show tables;

Work in Progress:

  • update queries: Don't use this in a production environment !!!

Example queries:

@group should be defined in sqldap.ini (see sqldap.ini.example)

Select from default (first) configured server:

[user@awesome ~]$ sqldap 'SELECT memberuid FROM @group WHERE cn=groupname'

Select from a different configured Active Directory server named examplead

[user@awesome ~]$ sqldap 'SELECT gid FROM @group ' examplead

Don't use > and <

> and < are not supported, work your way around this problem by using: >= and <=

This is a valid query:

[user@awesome ~]$ sqldap 'SELECT uid,cn,passwordretrycount,ou FROM @people WHERE passwordretrycount>=3'

This is an invalid query:

[user@awesome ~]$ sqldap 'SELECT uid,cn,passwordretrycount,ou FROM @people WHERE passwordretrycount>2'`

You can also run queries that are defined in the sqldap.ini config file:

[user@awesome ~]$ sqldap @passwordretrycount

When you pass a filename as an argument, then sqldap parses the file and executes the queries that are defined this file

[user@awesome ~]$ sqldap queries.sql

Using config file /home/user/sqldap/sqldap.ini
Using server: exampleldap (ldap://ldap.example.com:389)

+-------+-------------+--------------------+----------+
| uid   | cn          | passwordretrycount | ou       |
+-------+-------------+--------------------+----------+
| user1 | Username1   | 3                  | group1   |
+-------+-------------+--------------------+----------+
| user2 | Username2   | 3                  | group2   |
+-------+-------------+--------------------+----------+
| user3 | Username3   | 3                  | group3   |
+-------+-------------+--------------------+----------+

[user@awesome ~]$

Compiling from source

First you'll have to install Rust on your system:

[user@awesome ~]$ curl https://sh.rustup.rs -sSf | sh

Now run the following command in the root of the project:

[user@awesome ~]$ cargo build --release

The sqldap binary can be found in the target/release/ folder.