Need programming help with ldapcheck utility program using clap and ldap3 crates


#1

Hi

Coming from python scripting background, I am interested to convert a few of my python scripts to rust.

1st goal is to connect to public ldap server using default ldap account and password.

Ex: ./ldapcheck02 --check -a myname -p mypassword

Currently ldapcheck02.rs, I am not able to pass on myname and myspassword strings to ldap connection function.

I won’t mind your help to shorten my beginner struggle :wink:


#2

You can use .unwrap() or expect("Error: no password provided").

let username =  matches.value_of("username").expect("Error: no username provided");
let password =  matches.value_of("password").expect("Error: no password provided");

// --- change function signature of do_tls_conn to
fn do_tls_conn(username : &str, password : &str) -> Result<(), Box<Error>> 

#3

@mmmmib

Rust programming is not easy ;-< , for a casual programmer like me. Need to put in more efforts doing my homework.

Thanks for the hint on unwrap, the 03 version is now working as I expected. Will need more cleanup on lines not needed.

[me@gapri6 ldapcheck]$ cargo run --bin ldapcheck03  -- -c -l "ldap://ldap.forumsys.com:3899"  -a read-only-admin  -p password
    Finished dev [unoptimized + debuginfo] target(s) in 0.13s
     Running `target/debug/ldapcheck03 -c -l 'ldap://ldap.forumsys.com:3899' -a read-only-admin -p password`
Os { code: 111, kind: ConnectionRefused, message: "Connection refused" }
[me@gapri6 ldapcheck]$ cargo run --bin ldapcheck03  -- -c -l "ldap://ldap.forumsys.com:389"  -a read-only-admin  -p password
    Finished dev [unoptimized + debuginfo] target(s) in 0.21s
     Running `target/debug/ldapcheck03 -c -l 'ldap://ldap.forumsys.com:389' -a read-only-admin -p password`
OK to connect to ldap://ldap.forumsys.com:389:cn=read-only-admin,dc=example,dc=com using password:password
[me@gapri6 ldapcheck]$