pub struct EsClient {
pub rx: Receiver<EsMessage>,
/* private fields */
}
Expand description
Create a new client to connect to Endpoint Security.
Fields§
§rx: Receiver<EsMessage>
Implementations§
Source§impl EsClient
impl EsClient
Sourcepub fn new() -> Result<EsClient>
pub fn new() -> Result<EsClient>
Create a new client that connects to the ES subsystem.
§Example
let client = endpointsecurity_rs::EsClient::new();
assert!(client.is_ok());
Examples found in repository?
3fn main() {
4 let mut client = EsClient::new().unwrap();
5 client
6 .add_event(EsEventType::NotifyLWSessionLock)
7 .add_event(EsEventType::NotifyLWSessionUnlock)
8 .subscribe();
9
10 loop {
11 let evt = client.recv_msg().unwrap();
12 println!("{:?}", evt);
13 }
14}
More examples
3fn main() {
4 let mut client = EsClient::new().unwrap();
5 client.add_event(EsEventType::NotifyExec).subscribe();
6
7 loop {
8 let msg = client.recv_msg().unwrap();
9 if let Some(ref data) = msg.event_data {
10 match data {
11 EsEventData::NotifyExec(proc) => {
12 println!("{:?}", proc);
13 }
14 _ => {}
15 }
16 }
17 }
18}
3fn main() {
4 let mut client = EsClient::new().unwrap();
5 client.add_event(EsEventType::AuthRename).subscribe();
6
7 loop {
8 let ev = client.rx.recv().unwrap();
9 if let Some(ref data) = ev.event_data {
10 match data {
11 EsEventData::AuthRename(info) => {
12 if info.source.path.contains("/Users/idipot/subcom.tech/test") {
13 println!("{:?}", ev);
14 ev.deny(&client);
15 } else {
16 }
17 }
18 _ => {}
19 }
20 }
21 }
22}
3fn main() {
4 let mut client = EsClient::new().unwrap();
5 client
6 .add_event(EsEventType::NotifyOpenSSHLogin)
7 .subscribe();
8
9 loop {
10 let msg = client.rx.recv().unwrap();
11 if let Some(ref data) = msg.event_data {
12 match data {
13 EsEventData::NotifyOpenSSHLogin(ssh_deets) => {
14 let addr = match &ssh_deets.source_address {
15 EsAddressType::None => panic!("Sadge"),
16 EsAddressType::Ipv4(addr) => addr.to_string(),
17 EsAddressType::Ipv6(addr) => addr.to_string(),
18 EsAddressType::NamedSocket(addr) => addr.clone(),
19 };
20 println!(
21 "Someone from {} is trying to connect as {}",
22 addr, ssh_deets.username
23 );
24 }
25 _ => {}
26 }
27 }
28 }
29}
Sourcepub fn add_event(&mut self, event: EsEventType) -> &mut Self
pub fn add_event(&mut self, event: EsEventType) -> &mut Self
Add a new event to subscribe
Examples found in repository?
3fn main() {
4 let mut client = EsClient::new().unwrap();
5 client
6 .add_event(EsEventType::NotifyLWSessionLock)
7 .add_event(EsEventType::NotifyLWSessionUnlock)
8 .subscribe();
9
10 loop {
11 let evt = client.recv_msg().unwrap();
12 println!("{:?}", evt);
13 }
14}
More examples
3fn main() {
4 let mut client = EsClient::new().unwrap();
5 client.add_event(EsEventType::NotifyExec).subscribe();
6
7 loop {
8 let msg = client.recv_msg().unwrap();
9 if let Some(ref data) = msg.event_data {
10 match data {
11 EsEventData::NotifyExec(proc) => {
12 println!("{:?}", proc);
13 }
14 _ => {}
15 }
16 }
17 }
18}
3fn main() {
4 let mut client = EsClient::new().unwrap();
5 client.add_event(EsEventType::AuthRename).subscribe();
6
7 loop {
8 let ev = client.rx.recv().unwrap();
9 if let Some(ref data) = ev.event_data {
10 match data {
11 EsEventData::AuthRename(info) => {
12 if info.source.path.contains("/Users/idipot/subcom.tech/test") {
13 println!("{:?}", ev);
14 ev.deny(&client);
15 } else {
16 }
17 }
18 _ => {}
19 }
20 }
21 }
22}
3fn main() {
4 let mut client = EsClient::new().unwrap();
5 client
6 .add_event(EsEventType::NotifyOpenSSHLogin)
7 .subscribe();
8
9 loop {
10 let msg = client.rx.recv().unwrap();
11 if let Some(ref data) = msg.event_data {
12 match data {
13 EsEventData::NotifyOpenSSHLogin(ssh_deets) => {
14 let addr = match &ssh_deets.source_address {
15 EsAddressType::None => panic!("Sadge"),
16 EsAddressType::Ipv4(addr) => addr.to_string(),
17 EsAddressType::Ipv6(addr) => addr.to_string(),
18 EsAddressType::NamedSocket(addr) => addr.clone(),
19 };
20 println!(
21 "Someone from {} is trying to connect as {}",
22 addr, ssh_deets.username
23 );
24 }
25 _ => {}
26 }
27 }
28 }
29}
Sourcepub fn subscribe(&self)
pub fn subscribe(&self)
Subscribe to all the events added using Self::add_event
Examples found in repository?
3fn main() {
4 let mut client = EsClient::new().unwrap();
5 client
6 .add_event(EsEventType::NotifyLWSessionLock)
7 .add_event(EsEventType::NotifyLWSessionUnlock)
8 .subscribe();
9
10 loop {
11 let evt = client.recv_msg().unwrap();
12 println!("{:?}", evt);
13 }
14}
More examples
3fn main() {
4 let mut client = EsClient::new().unwrap();
5 client.add_event(EsEventType::NotifyExec).subscribe();
6
7 loop {
8 let msg = client.recv_msg().unwrap();
9 if let Some(ref data) = msg.event_data {
10 match data {
11 EsEventData::NotifyExec(proc) => {
12 println!("{:?}", proc);
13 }
14 _ => {}
15 }
16 }
17 }
18}
3fn main() {
4 let mut client = EsClient::new().unwrap();
5 client.add_event(EsEventType::AuthRename).subscribe();
6
7 loop {
8 let ev = client.rx.recv().unwrap();
9 if let Some(ref data) = ev.event_data {
10 match data {
11 EsEventData::AuthRename(info) => {
12 if info.source.path.contains("/Users/idipot/subcom.tech/test") {
13 println!("{:?}", ev);
14 ev.deny(&client);
15 } else {
16 }
17 }
18 _ => {}
19 }
20 }
21 }
22}
3fn main() {
4 let mut client = EsClient::new().unwrap();
5 client
6 .add_event(EsEventType::NotifyOpenSSHLogin)
7 .subscribe();
8
9 loop {
10 let msg = client.rx.recv().unwrap();
11 if let Some(ref data) = msg.event_data {
12 match data {
13 EsEventData::NotifyOpenSSHLogin(ssh_deets) => {
14 let addr = match &ssh_deets.source_address {
15 EsAddressType::None => panic!("Sadge"),
16 EsAddressType::Ipv4(addr) => addr.to_string(),
17 EsAddressType::Ipv6(addr) => addr.to_string(),
18 EsAddressType::NamedSocket(addr) => addr.clone(),
19 };
20 println!(
21 "Someone from {} is trying to connect as {}",
22 addr, ssh_deets.username
23 );
24 }
25 _ => {}
26 }
27 }
28 }
29}
Sourcepub fn unsubscribe_all(&self) -> bool
pub fn unsubscribe_all(&self) -> bool
returns true if call to unsubscribe is successful, otherwise false
Sourcepub fn unsubscribe(&mut self, event: EsEventType) -> bool
pub fn unsubscribe(&mut self, event: EsEventType) -> bool
returns true if call to unsubscribe is successful, otherwise false/
Sourcepub fn subscriptions(&self) -> Option<Vec<EsEventType>>
pub fn subscriptions(&self) -> Option<Vec<EsEventType>>
Get the events that the user subscribed to. Returns None
on error
Sourcepub fn recv_msg(&self) -> Result<EsMessage, RecvError>
pub fn recv_msg(&self) -> Result<EsMessage, RecvError>
This function blocks
Examples found in repository?
3fn main() {
4 let mut client = EsClient::new().unwrap();
5 client
6 .add_event(EsEventType::NotifyLWSessionLock)
7 .add_event(EsEventType::NotifyLWSessionUnlock)
8 .subscribe();
9
10 loop {
11 let evt = client.recv_msg().unwrap();
12 println!("{:?}", evt);
13 }
14}
More examples
3fn main() {
4 let mut client = EsClient::new().unwrap();
5 client.add_event(EsEventType::NotifyExec).subscribe();
6
7 loop {
8 let msg = client.recv_msg().unwrap();
9 if let Some(ref data) = msg.event_data {
10 match data {
11 EsEventData::NotifyExec(proc) => {
12 println!("{:?}", proc);
13 }
14 _ => {}
15 }
16 }
17 }
18}
Sourcepub fn try_recv_msg(&self) -> Result<EsMessage, TryRecvError>
pub fn try_recv_msg(&self) -> Result<EsMessage, TryRecvError>
This function doesn’t block
Sourcepub fn mute_path(&self, path: &Path, ty: EsMutePath) -> bool
pub fn mute_path(&self, path: &Path, ty: EsMutePath) -> bool
Suppresses events from executables that match a given path.
Returns true
if muting was succesful.
Sourcepub fn unmute_path(&self, path: &Path, ty: EsMutePath) -> bool
pub fn unmute_path(&self, path: &Path, ty: EsMutePath) -> bool
Restores event delivery from a previously-muted path.
Returns true
if muting was succesful.
Sourcepub fn unmute_path_events(
&self,
path: &Path,
ty: EsMutePath,
events: &[EsEventType],
) -> bool
pub fn unmute_path_events( &self, path: &Path, ty: EsMutePath, events: &[EsEventType], ) -> bool
Restores event delivery of a subset of events from a previously-muted path.
Sourcepub fn unmute_all_paths(&self) -> bool
pub fn unmute_all_paths(&self) -> bool
Restores event delivery from previously-muted paths.
Sourcepub fn destroy_client(self)
pub fn destroy_client(self)
Deletes the client