Added search filter option

This commit is contained in:
Gregory Ballantine 2018-07-12 22:49:57 -04:00
parent 1ae83b3a4c
commit 3605e00090
2 changed files with 14 additions and 4 deletions

View File

@ -19,11 +19,11 @@ pub fn connect(ldap_connection_info: HashMap<&str, &str>) -> LdapConn {
}
// perform an LDAP search
pub fn do_search(ldap_conn: LdapConn, search_base: &str) -> Result<(), Box<Error>> {
pub fn do_search(ldap_conn: LdapConn, search_base: &str, search_filter: &str) -> Result<(), Box<Error>> {
let (rs, _res) = ldap_conn.search(
search_base,
Scope::Subtree,
"(&(objectClass=*))",
search_filter,
vec!["*"]
)?.success()?;

View File

@ -54,13 +54,22 @@ fn main() {
// LDAP search subcommand
.subcommand(SubCommand::with_name("search")
.about("Search an LDAP directory")
// search base argument
.arg(Arg::with_name("base")
.short("b")
.long("base")
.takes_value(true)
.required(true)
.default_value(yaml["muldap"]["search_base"].as_str().unwrap())
.help("Base DN to search with")))
.help("Base DN to search with"))
// search filter argument
.arg(Arg::with_name("filter")
.short("f")
.long("filter")
.takes_value(true)
.required(false)
.default_value("(&(objectClass=*))")
.help("LDAP search filter")))
.get_matches();
@ -78,8 +87,9 @@ fn main() {
if let Some(matches) = matches.subcommand_matches("search") {
// get search options
let search_base = matches.value_of("base").unwrap();
let search_filter = matches.value_of("filter").unwrap();
// run the LDAP search
let _ = ldap::do_search(ldap_conn, search_base);
let _ = ldap::do_search(ldap_conn, search_base, search_filter);
}
}