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 // 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( let (rs, _res) = ldap_conn.search(
search_base, search_base,
Scope::Subtree, Scope::Subtree,
"(&(objectClass=*))", search_filter,
vec!["*"] vec!["*"]
)?.success()?; )?.success()?;

View File

@ -54,13 +54,22 @@ fn main() {
// LDAP search subcommand // LDAP search subcommand
.subcommand(SubCommand::with_name("search") .subcommand(SubCommand::with_name("search")
.about("Search an LDAP directory") .about("Search an LDAP directory")
// search base argument
.arg(Arg::with_name("base") .arg(Arg::with_name("base")
.short("b") .short("b")
.long("base") .long("base")
.takes_value(true) .takes_value(true)
.required(true) .required(true)
.default_value(yaml["muldap"]["search_base"].as_str().unwrap()) .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(); .get_matches();
@ -78,8 +87,9 @@ fn main() {
if let Some(matches) = matches.subcommand_matches("search") { if let Some(matches) = matches.subcommand_matches("search") {
// get search options // get search options
let search_base = matches.value_of("base").unwrap(); let search_base = matches.value_of("base").unwrap();
let search_filter = matches.value_of("filter").unwrap();
// run the LDAP search // run the LDAP search
let _ = ldap::do_search(ldap_conn, search_base); let _ = ldap::do_search(ldap_conn, search_base, search_filter);
} }
} }