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
|
// 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()?;
|
||||||
|
|
||||||
|
14
src/main.rs
14
src/main.rs
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user