diff --git a/Cargo.toml b/Cargo.toml index acd5bc42b33f1447b57a0a4b3e7842411a15a641..6c8f7bb35f2ed2a914d296c8cd351999c3b3daf9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,16 +1,20 @@ [package] -name = "parselog" -version = "0.1.0" +name = "parselog-ldap" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] gethostname = "0.4.3" +lazy_static = "1.4.0" regex = "1.9.5" -rusqlite = { version = "0.29.0", features = ["bundled"] } syslog = "6.1.0" [[bin]] -name = "parselog" +name = "parselog-ldap" path = "parselog.rs" + +[profile.release] +lto="fat" +codegen-units = 1 diff --git a/README.md b/README.md index 3c381b51997c334c71991d438d4d3f8c514497e3..82aa79d3b2581fdf1096e1bfc48732db4775f31a 100644 --- a/README.md +++ b/README.md @@ -4,89 +4,30 @@ ## Getting started -To make it easy for you to get started with GitLab, here's a list of recommended next steps. +Le programme parselog-ldap permet de construire des logs LDAP lisibles et exploitables. Il doit se lancer sur le serveur LDAP. Il ne peut pas recevoir les logs de plusieurs serveurs LDAP car il pourrait y avoir plusieurs fois le même numéro de connexion et donc des logs inconsistants. -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: +Le programme prend en entrée un port sur lequel il va écouter en TCP et un couple IP/Port sur lequel il va envoyer en TCP les logs construits. Pour cela, il faudra passer en argument du programme ces paramètres: ``` -cd existing_repo -git remote add origin https://gitlab.lis-lab.fr/sebastien.boutelier/parselog-ldap.git -git branch -M main -git push -uf origin main +parselog-ldap --listen=8080 --loghost=172.26.66.74:4514 ``` -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.lis-lab.fr/sebastien.boutelier/parselog-ldap/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. +Il faudra ensuite indiquer au rsyslog du serveur LDAP d'envoyer les logs LDAP sur le démon, c'est à dire s'il écoute sur le port 8080 d'envoyer en TCP sur 127.0.0.1:8080. Celui-ci va en retour envoyer les logs sur le loghost indiqué en utilisant le protocole TCP. -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. +Le démon parselog-ldap ne doit pas tourner en tant que root, il faut donc lui créer un utilisateur sous lequel il sera exécuté. -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. +## Compilation -## Contributing -State if you are open to contributions and what your requirements are for accepting them. +Installer [rust](https://www.rust-lang.org/tools/install) puis: ```cargo build -r``` -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. +Le binaire sera présent dans target/release -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. +## Fonctionnement -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. +A la réception d'un log une première expression régulière va analyser la commande LDAP (BIND, ADD, DEL, SRCH...) et va envoyer le log dans la fonction adequat. Les logs sont construit en récupérant les info dans les logs et en utilisant le numéro de connexion et numéro d'opération. Tout est stocké dans des tables de hashage gérés dans le fichier hashmap.rs. Quand on tombe sur la commande RESULT, on va aller récupérer les infos préalablement stocké, construile la ligne de log à envoyer, l'envoyer avec la fonction sendlog() et nettoyer les tables de hashage. ## License -For open source projects, say how it is licensed. +Aucune ## Project status If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. diff --git a/hashmap.rs b/hashmap.rs new file mode 100644 index 0000000000000000000000000000000000000000..881ecafb566f88f081ae63be3e9c31c5aa6947bd --- /dev/null +++ b/hashmap.rs @@ -0,0 +1,72 @@ +use std::sync::Mutex; +use std::collections::HashMap; +use lazy_static::lazy_static; + +lazy_static! { + static ref HASHIP: Mutex<HashMap<String, String>> = { + let m = HashMap::new(); + Mutex::new(m) + }; + static ref HASHBIND: Mutex<HashMap<String, String>> = { + let m = HashMap::new(); + Mutex::new(m) + }; + static ref HASHCMD: Mutex<HashMap<String, String>> = { + let m = HashMap::new(); + Mutex::new(m) + }; + static ref HASHVAL1: Mutex<HashMap<String, String>> = { + let m = HashMap::new(); + Mutex::new(m) + }; + static ref HASHVAL2: Mutex<HashMap<String, String>> = { + let m = HashMap::new(); + Mutex::new(m) + }; + static ref HASHATTR: Mutex<HashMap<String, String>> = { + let m = HashMap::new(); + Mutex::new(m) + }; +} + +pub fn set_val(hash: &str, key: String,val: String){ + match hash { + "ip" => { let mut map = HASHIP.lock().unwrap(); map.insert(key,val); }, + "bind" => { let mut map = HASHBIND.lock().unwrap(); map.insert(key,val); }, + "cmd" => { let mut map = HASHCMD.lock().unwrap(); map.insert(key,val); }, + "val1" => { let mut map = HASHVAL1.lock().unwrap(); map.insert(key,val); }, + "val2" => { let mut map = HASHVAL2.lock().unwrap(); map.insert(key,val); }, + "attr" => { let mut map = HASHATTR.lock().unwrap(); map.insert(key,val); }, + _ =>{}, + } +} + +pub fn get_val(hash: &str, key: String)->String{ + match hash { + "ip" => { let map = HASHIP.lock().unwrap(); map.get(&key).unwrap_or(&"0".to_string()).to_string() }, + "bind" => { let map = HASHBIND.lock().unwrap(); map.get(&key).unwrap_or(&"Anonymous".to_string()).to_string() }, + "cmd" => { let map = HASHCMD.lock().unwrap(); map.get(&key).unwrap_or(&"-".to_string()).to_string() }, + "val1" => { let map = HASHVAL1.lock().unwrap(); map.get(&key).unwrap_or(&"-".to_string()).to_string() }, + "val2" => { let map = HASHVAL2.lock().unwrap(); map.get(&key).unwrap_or(&"-".to_string()).to_string() }, + "attr" => { let map = HASHATTR.lock().unwrap(); map.get(&key).unwrap_or(&"-".to_string()).to_string() }, + _ =>{ "-".to_string()}, + } +} + +pub fn removecon(key: String){ + let mut map = HASHIP.lock().unwrap(); + map.remove(&key); + let mut map = HASHBIND.lock().unwrap(); + map.remove(&key); +} + +pub fn removeop(key: String){ + let mut map = HASHCMD.lock().unwrap(); + map.remove(&key); + let mut map = HASHVAL1.lock().unwrap(); + map.remove(&key); + let mut map = HASHVAL2.lock().unwrap(); + map.remove(&key); + let mut map = HASHATTR.lock().unwrap(); + map.remove(&key); +} diff --git a/parselog-ldap.service b/parselog-ldap.service new file mode 100644 index 0000000000000000000000000000000000000000..26c338af10e82855bd521c6b89abbe4526999424 --- /dev/null +++ b/parselog-ldap.service @@ -0,0 +1,17 @@ +[Unit] +Description=LDAP Log parser daemon +After=network.target + +[Service] +Type=simple +User=parselog-ldap +Group=parselog-ldap +Environment="OPTIONS=--listen=8080 --loghost=172.26.66.74:4514" +ExecStart=/usr/bin/parselog-ldap ${OPTIONS} +ExecReload=/bin/kill -HUP $MAINPID +KillMode=process +Restart=on-failure +RestartSec=42s + +[Install] +WantedBy=multi-user.target diff --git a/parselog.rs b/parselog.rs index c1d5c7a695797f2607dac10d4e93e24a1c3e31ff..95bd4b361a51de6d6a6630b8c93345f7b08f83d0 100644 --- a/parselog.rs +++ b/parselog.rs @@ -1,21 +1,20 @@ use std::net::TcpListener; use std::process; -use std::io::{self, BufRead, Write}; -use std::fs; +use std::io::{self, BufRead}; use std::env; -use std::fs::File; -use rusqlite::{Connection, Result,params}; use regex::Regex; use syslog::{Facility, Formatter3164}; use std::sync::OnceLock; use gethostname::gethostname; -static LOGHOST: OnceLock<String> = OnceLock::new(); -static REGEXP_CLOSE: OnceLock<Regex> = OnceLock::new(); -static REGEXP_CMD: OnceLock<Regex> = OnceLock::new(); -static REGEXP_CONNECT: OnceLock<Regex> = OnceLock::new(); -static REGEXP_LAUNCH: OnceLock<Regex> = OnceLock::new(); -static REGEXP_RESULT: OnceLock<Regex> = OnceLock::new(); +mod hashmap; + +static LOGHOST: OnceLock<String> = OnceLock::new(); +static REGEXP_CLOSE: OnceLock<Regex> = OnceLock::new(); +static REGEXP_CMD: OnceLock<Regex> = OnceLock::new(); +static REGEXP_CONNECT: OnceLock<Regex> = OnceLock::new(); +static REGEXP_LAUNCH: OnceLock<Regex> = OnceLock::new(); +static REGEXP_RESULT: OnceLock<Regex> = OnceLock::new(); fn help() { println!("Usage: parselog-ldap --listen=NUMBER --loghost=IP:PORT"); @@ -23,7 +22,7 @@ fn help() { println!(" IP:PORT: La socket sur laquelle on envoie les logs."); } -fn getport()->Result<String> { +fn getport()->Result<String,String> { let regexp_arg = Regex::new(r"--listen=(?<port>[0-9]{1,5})").unwrap(); for argument in env::args() { let Some(caps) = regexp_arg.captures(&argument) else { @@ -36,8 +35,7 @@ fn getport()->Result<String> { process::exit(1); } -fn getloghost()->Result<String> { - //let regexp_arg = Regex::new(r"--loghost=(?<ipport>(25[0–5]|2[0–4][0–9]|[01]?[0–9][0–9]?).(25[0–5]|2[0–4][0–9]|[01]?[0–9][0–9]?).(25[0–5]|2[0–4][0–9]|[01]?[0–9][0–9]?).(25[0–5]|2[0–4][0–9]|[01]?[0–9][0–9]?):[0-9]{1,5})").unwrap(); +fn getloghost()->Result<String,String> { let regexp_arg = Regex::new(r"--loghost=(?<ipport>[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}:[0-9]{1,5})").unwrap(); for argument in env::args() { let Some(caps) = regexp_arg.captures(&argument) else { @@ -51,109 +49,64 @@ fn getloghost()->Result<String> { } -fn getip(con: &str) -> Result<String> { - let c = Connection::open("/dev/shm/parselog.db")?; - let mut stmt = c.prepare("SELECT ip FROM conip WHERE con = :con")?; - let rows = stmt.query_map(&[(":con", &con)], |row| { - Ok(row.get(0)?) - })?; - for row in rows { - let ip: String = row?; - return Ok(ip); - } - Ok("0".to_string()) -} - -fn getbind(con: &str) -> Result<String> { - let c = Connection::open("/dev/shm/parselog.db")?; - let mut stmt = c.prepare("SELECT bind FROM conip WHERE con = :con")?; - let rows = stmt.query_map(&[(":con", &con)], |row| { - Ok(row.get(0)?) - })?; - for row in rows { - let bind: String = row?; - if bind == "\"\"" { - return Ok("Anonymous".to_string()); - } - return Ok(bind); - } - Ok("Anonymous".to_string()) -} - fn com_accept(line: String){ let Some(caps) = REGEXP_CONNECT.get().expect("unitialized Regexp").captures(&line) else { return; }; - let c = Connection::open("/dev/shm/parselog.db").unwrap(); - let query = "INSERT INTO conip VALUES(?1,?2,'Anonymous')"; - c.execute(query,(&caps["con"],&caps["ip"]),).unwrap(); + let val = caps["ip"].to_string(); + let key = caps["con"].to_string(); + hashmap::set_val("ip",key.clone(),val); } fn com_result(line: String){ let Some(caps) = REGEXP_RESULT.get().expect("unitialized Regexp").captures(&line) else { - println!("Parse foireux sur {}",line); return; }; let nentries = caps.name("nentries").map_or("0", |m| m.as_str()); - let c = Connection::open("/dev/shm/parselog.db").unwrap(); - let mut stmt = c.prepare("UPDATE log SET result = ?1, nentries = ?2 WHERE con = ?3 AND op = ?4").unwrap(); - stmt.execute(params![&caps["res"],nentries,&caps["con"],&caps["op"]]).unwrap(); - construct_log(&caps["con"],&caps["op"]); -} - -fn construct_log(con: &str,op: &str){ - let c = Connection::open("/dev/shm/parselog.db").unwrap(); - let mut stmt = c.prepare("SELECT * FROM log WHERE con = :con AND op = :op LIMIT 1").unwrap(); - let mut rows = stmt.query(&[(":con", &con),(":op", &op)]).unwrap(); - while let Some(row) = rows.next().unwrap() { - let command: String = row.get(2).unwrap(); - let val1: String = row.get(3).unwrap(); - let val2: String = row.get(4).unwrap(); - let attr: String = row.get(5).unwrap(); - let result: String = row.get(6).unwrap(); - let nentries: String = row.get(7).unwrap(); - let ip = getip(&con).unwrap(); - let bind = getbind(con).unwrap(); - - if ip == "0" { - return; - } - - let linelog : String; - let err : String; - let user : String; - match result.as_str(){ - "err=0" => err = "OK".to_string(), - _ => err = "refused".to_string(), - } - match bind.as_str(){ - "\"\"" => user = "Anonymous".to_string(), - _ => user = bind, - } - match command.as_str() { + let ip = hashmap::get_val("ip",caps["con"].to_string()); + if ip == "0" { return; } + let con = &caps["con"]; + let bind = hashmap::get_val("bind",caps["con"].to_string()); + let key = format!("{}-{}",&caps["con"],&caps["op"]); + let cmd = hashmap::get_val("cmd",key.clone()); + let val1 = hashmap::get_val("val1",key.clone()); + let val2 = hashmap::get_val("val2",key.clone()); + let attr = hashmap::get_val("attr",key.clone()); + + let linelog : String; + let err : String; + let user : String; + match &caps["err"]{ + "err=0" => err = "OK".to_string(), + _ => err = "refused".to_string(), + } + match bind.as_str(){ + "\"\"" => user = "Anonymous".to_string(), + _ => user = bind, + } + match cmd.as_str() { "BIND" => { - if result == "err=0" { - let mut stmt = c.prepare("UPDATE conip SET bind = ?1 WHERE con = ?2").unwrap(); - stmt.execute(params![val1,&con]).unwrap(); + if &caps["err"] == "err=0" { + hashmap::set_val("bind",caps["con"].to_string(),val1.clone()); } if val1 == "\"\"" { return; } - linelog = format!("ID={} SRC={} BIND={} {}",con,ip,val1,err); + linelog = format!("ID={} SRC={} BIND={} {} -> {}",con,ip,val1,cmd,err); }, "SRCH" => { - linelog = format!("ID={} SRC={} BIND={} {} attr {} in {} with filter {} {} -> {} answer",con,ip,user,command,attr,val1,val2,err,nentries); + linelog = format!("ID={} SRC={} BIND={} {} attr {} in {} with filter {} -> {} ({} answer)",con,ip,user,cmd,attr,val1,val2,err,nentries); }, "MOD" => { - linelog = format!("ID={} SRC={} BIND={} {} {} attr={} -> {}",con,ip,user,command,val1,attr,err); + linelog = format!("ID={} SRC={} BIND={} {} {} attr={} -> {}",con,ip,user,cmd,val1,attr,err); }, "CMP" => { - linelog = format!("ID={} SRC={} BIND={} {} {} attr={} -> {}",con,ip,user,command,val1,val2,err); + linelog = format!("ID={} SRC={} BIND={} {} {} attr={} -> {}",con,ip,user,cmd,val1,val2,err); }, _ => { // ADD DEL - linelog = format!("ID={} SRC={} BIND={} {} {} -> {}",con,ip,user,command,val1,err); + linelog = format!("ID={} SRC={} BIND={} {} {} -> {}",con,ip,user,cmd,val1,err); } } - sendlog(linelog); - } + hashmap::removeop(key.clone()); + sendlog(linelog); } fn create_log(line: String){ @@ -161,23 +114,22 @@ fn create_log(line: String){ return; }; let val2 = caps.name("val2").map_or("-", |m| m.as_str()); - let c = Connection::open("/dev/shm/parselog.db").unwrap(); + let key = format!("{}-{}",&caps["con"],&caps["op"]); + hashmap::set_val("cmd",key.clone(),caps["cmd"].to_string()); match &caps["v"]{ "base"=>{ - let query = "INSERT INTO log ('con','op','command','val1','val2','attr','result','nentries') VALUES(?1,?2,?3,?4,?5,'-','-','-')"; - c.execute(query,(&caps["con"],&caps["op"],&caps["cmd"],&caps["val1"],val2),).unwrap(); + hashmap::set_val("val1",key.clone(),caps["val1"].to_string()); + hashmap::set_val("val2",key.clone(),val2.to_string()); }, "dn"=>{ - let query = "INSERT INTO log ('con','op','command','val1','val2','attr','result','nentries') VALUES(?1,?2,?3,?4,?5,'-','-','-')"; - c.execute(query,(&caps["con"],&caps["op"],&caps["cmd"],&caps["val1"],val2),).unwrap(); + hashmap::set_val("val1",key.clone(),caps["val1"].to_string()); + hashmap::set_val("val2",key.clone(),val2.to_string()); }, "attr"=>{ - let mut stmt = c.prepare("UPDATE log SET attr = ?1 WHERE con = ?2 AND op = ?3").unwrap(); - stmt.execute(params![&caps["val1"],&caps["con"],&caps["op"]]).unwrap(); + hashmap::set_val("attr",key,caps["val1"].to_string()); }, "id"=>{ - let query = "INSERT INTO log ('con','op','command','val1','val2','attr','result','nentries') VALUES(?1,?2,?3,?4,'-','-','-','-')"; - c.execute(query,(&caps["con"],&caps["op"],&caps["cmd"],&caps["val1"]),).unwrap(); + hashmap::set_val("val1",key,caps["val1"].to_string()); }, _=>com_default(line.to_string()), } @@ -188,11 +140,7 @@ fn com_closed(line: String){ let Some(caps) = REGEXP_CLOSE.get().expect("unitialized Regexp").captures(&line) else { return; }; - let c = Connection::open("/dev/shm/parselog.db").unwrap(); - let mut stmt = c.prepare("DELETE FROM conip WHERE con = ?1").unwrap(); - stmt.execute(params![&caps["con"]]).unwrap(); - let mut stmt = c.prepare("DELETE FROM log WHERE con = ?1").unwrap(); - stmt.execute(params![&caps["con"]]).unwrap(); + hashmap::removecon(caps["con"].to_string()); } fn com_default(line: String){ @@ -202,7 +150,6 @@ fn com_default(line: String){ } fn sendlog(line: String){ - println!("OUT: {}",line); let formatter = Formatter3164 { facility: Facility::LOG_USER, hostname: Some(gethostname().into_string().unwrap()), @@ -242,26 +189,12 @@ fn launch<R: BufRead>(reader: R) { } } -fn initdb(){ - let _res = fs::remove_file("/dev/shm/parselog.db"); - let mut file = File::create("/dev/shm/parselog.db").expect("Error encountered while creating file!"); - file.write_all(b"Writing").expect("Error while writing to file"); - fs::remove_file("/dev/shm/parselog.db").unwrap(); - let c = Connection::open("/dev/shm/parselog.db").unwrap(); - let query = "CREATE TABLE conip (con INT, ip TEXT, bind TEXT)"; - c.execute(query,(),).unwrap(); - let query = "CREATE TABLE log (con INT, op INT, command TEXT, val1 TEXT, val2 TEXT, attr TEXT, result TEXT, nentries TEXT)"; - c.execute(query,(),).unwrap(); -} - - fn main() { let loghost = getloghost().unwrap(); let _ = LOGHOST.set(loghost); let port = getport().unwrap(); - initdb(); let _ = REGEXP_LAUNCH.set(Regex::new(r"^\S+ \S+ \S+ \S+ \S+ (?<con>\S+) (?<op>\S+) (?<command>\S+)").unwrap()); - let _ = REGEXP_RESULT.set(Regex::new(r"^\S+ \S+ \S+ \S+ \S+ conn=(?<con>[0-9]+) op=(?<op>[0-9]+)( SEARCH)? RESULT \S+ (?<res>\S+)( nentries=(?<nentries>[0-9]+))?").unwrap()); + let _ = REGEXP_RESULT.set(Regex::new(r"^\S+ \S+ \S+ \S+ \S+ conn=(?<con>[0-9]+) op=(?<op>[0-9]+)( SEARCH)? RESULT \S+ (?<err>\S+)( nentries=(?<nentries>[0-9]+))?").unwrap()); let _ = REGEXP_CMD.set(Regex::new(r"^\S+ \S+ \S+ \S+ \S+ conn=(?<con>[0-9]+) op=(?<op>[0-9]+) (?<cmd>(ADD|DEL|BIND|CMP|MOD|PASSMOD|SRCH)) (?<v>[a-z]+)=(?<val1>\S+)( \S+ \S+)?( (attr|filter)=(?<val2>\S+))?").unwrap()); let _ = REGEXP_CONNECT.set(Regex::new(r"^\S+ \S+ \S+ \S+ \S+ conn=(?<con>[0-9]+) \S+ ACCEPT from IP=(?<ip>[0-9.:]+):[0-9]+").unwrap()); let _ = REGEXP_CLOSE.set(Regex::new(r"^\S+ \S+ \S+ \S+ \S+ conn=(?<con>[0-9]+) \S+ closed").unwrap());