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 :)
- simple select queries:
SELECT * FROM "$tablename" WHERE var=val;
show databases;
show tables;
- update queries: Don't use this in a production environment !!!
@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
>
and <
are not supported, work your way around this problem by using: >=
and <=
[user@awesome ~]$ sqldap 'SELECT uid,cn,passwordretrycount,ou FROM @people WHERE passwordretrycount>=3'
[user@awesome ~]$ sqldap 'SELECT uid,cn,passwordretrycount,ou FROM @people WHERE passwordretrycount>2'`
[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 ~]$
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.