Added search filter option
This commit is contained in:
parent
1ae83b3a4c
commit
3605e00090
@ -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()?;
|
||||
|
||||
|
14
src/main.rs
14
src/main.rs
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user