config: add pid client criteria
This commit is contained in:
parent
587ffc7ee5
commit
a952e658da
13 changed files with 55 additions and 1 deletions
|
|
@ -83,6 +83,7 @@ pub enum ClientCriterionIpc {
|
||||||
},
|
},
|
||||||
Sandboxed,
|
Sandboxed,
|
||||||
Uid(i32),
|
Uid(i32),
|
||||||
|
Pid(i32),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq)]
|
#[derive(Serialize, Deserialize, Clone, Debug, Hash, Eq, PartialEq)]
|
||||||
|
|
|
||||||
|
|
@ -1543,6 +1543,7 @@ impl ConfigClient {
|
||||||
ClientCriterion::SandboxInstanceIdRegex(t) => string!(t, SandboxInstanceId, true),
|
ClientCriterion::SandboxInstanceIdRegex(t) => string!(t, SandboxInstanceId, true),
|
||||||
ClientCriterion::Sandboxed => ClientCriterionIpc::Sandboxed,
|
ClientCriterion::Sandboxed => ClientCriterionIpc::Sandboxed,
|
||||||
ClientCriterion::Uid(p) => ClientCriterionIpc::Uid(p),
|
ClientCriterion::Uid(p) => ClientCriterionIpc::Uid(p),
|
||||||
|
ClientCriterion::Pid(p) => ClientCriterionIpc::Pid(p),
|
||||||
};
|
};
|
||||||
let res = self.send_with_response(&ClientMessage::CreateClientMatcher { criterion });
|
let res = self.send_with_response(&ClientMessage::CreateClientMatcher { criterion });
|
||||||
get_response!(
|
get_response!(
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,8 @@ pub enum ClientCriterion<'a> {
|
||||||
Sandboxed,
|
Sandboxed,
|
||||||
/// Matches the user ID of the client.
|
/// Matches the user ID of the client.
|
||||||
Uid(i32),
|
Uid(i32),
|
||||||
|
/// Matches the process ID of the client.
|
||||||
|
Pid(i32),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClientCriterion<'_> {
|
impl ClientCriterion<'_> {
|
||||||
|
|
|
||||||
|
|
@ -1886,6 +1886,7 @@ impl ConfigProxyHandler {
|
||||||
}
|
}
|
||||||
ClientCriterionIpc::Sandboxed => mgr.sandboxed(),
|
ClientCriterionIpc::Sandboxed => mgr.sandboxed(),
|
||||||
ClientCriterionIpc::Uid(p) => mgr.uid(*p),
|
ClientCriterionIpc::Uid(p) => mgr.uid(*p),
|
||||||
|
ClientCriterionIpc::Pid(p) => mgr.pid(*p),
|
||||||
};
|
};
|
||||||
let cached = Rc::new(CachedCriterion {
|
let cached = Rc::new(CachedCriterion {
|
||||||
crit: criterion.clone(),
|
crit: criterion.clone(),
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use {
|
||||||
CritDestroyListener, CritLiteralOrRegex, CritMatcherId, CritMatcherIds, CritMgrExt,
|
CritDestroyListener, CritLiteralOrRegex, CritMatcherId, CritMatcherIds, CritMgrExt,
|
||||||
CritUpstreamNode, FixedRootMatcher, RootMatcherMap,
|
CritUpstreamNode, FixedRootMatcher, RootMatcherMap,
|
||||||
clm::clm_matchers::{
|
clm::clm_matchers::{
|
||||||
|
clmm_pid::ClmMatchPid,
|
||||||
clmm_sandboxed::ClmMatchSandboxed,
|
clmm_sandboxed::ClmMatchSandboxed,
|
||||||
clmm_string::{
|
clmm_string::{
|
||||||
ClmMatchSandboxAppId, ClmMatchSandboxEngine, ClmMatchSandboxInstanceId,
|
ClmMatchSandboxAppId, ClmMatchSandboxEngine, ClmMatchSandboxInstanceId,
|
||||||
|
|
@ -54,6 +55,7 @@ pub struct RootMatchers {
|
||||||
sandbox_engine: ClmRootMatcherMap<ClmMatchSandboxEngine>,
|
sandbox_engine: ClmRootMatcherMap<ClmMatchSandboxEngine>,
|
||||||
sandbox_instance_id: ClmRootMatcherMap<ClmMatchSandboxInstanceId>,
|
sandbox_instance_id: ClmRootMatcherMap<ClmMatchSandboxInstanceId>,
|
||||||
uid: ClmRootMatcherMap<ClmMatchUid>,
|
uid: ClmRootMatcherMap<ClmMatchUid>,
|
||||||
|
pid: ClmRootMatcherMap<ClmMatchPid>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_cl_changes(state: Rc<State>) {
|
pub async fn handle_cl_changes(state: Rc<State>) {
|
||||||
|
|
@ -154,6 +156,7 @@ impl ClMatcherManager {
|
||||||
unconditional!(sandbox_app_id);
|
unconditional!(sandbox_app_id);
|
||||||
unconditional!(sandbox_engine);
|
unconditional!(sandbox_engine);
|
||||||
unconditional!(uid);
|
unconditional!(uid);
|
||||||
|
unconditional!(pid);
|
||||||
fixed!(sandboxed);
|
fixed!(sandboxed);
|
||||||
self.constant[true].handle(data);
|
self.constant[true].handle(data);
|
||||||
}
|
}
|
||||||
|
|
@ -178,6 +181,10 @@ impl ClMatcherManager {
|
||||||
pub fn uid(&self, pid: i32) -> Rc<ClmUpstreamNode> {
|
pub fn uid(&self, pid: i32) -> Rc<ClmUpstreamNode> {
|
||||||
self.root(ClmMatchUid(pid as _))
|
self.root(ClmMatchUid(pid as _))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn pid(&self, pid: i32) -> Rc<ClmUpstreamNode> {
|
||||||
|
self.root(ClmMatchPid(pid as _))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CritTarget for Rc<Client> {
|
impl CritTarget for Rc<Client> {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ macro_rules! fixed_root_criterion {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod clmm_pid;
|
||||||
pub mod clmm_sandboxed;
|
pub mod clmm_sandboxed;
|
||||||
pub mod clmm_string;
|
pub mod clmm_string;
|
||||||
pub mod clmm_uid;
|
pub mod clmm_uid;
|
||||||
|
|
|
||||||
20
src/criteria/clm/clm_matchers/clmm_pid.rs
Normal file
20
src/criteria/clm/clm_matchers/clmm_pid.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
use {
|
||||||
|
crate::{
|
||||||
|
client::Client,
|
||||||
|
criteria::{RootMatcherMap, clm::RootMatchers, crit_graph::CritRootCriterion},
|
||||||
|
},
|
||||||
|
std::rc::Rc,
|
||||||
|
uapi::c,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct ClmMatchPid(pub c::pid_t);
|
||||||
|
|
||||||
|
impl CritRootCriterion<Rc<Client>> for ClmMatchPid {
|
||||||
|
fn matches(&self, data: &Rc<Client>) -> bool {
|
||||||
|
data.pid_info.pid == self.0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn nodes(roots: &RootMatchers) -> Option<&RootMatcherMap<Rc<Client>, Self>> {
|
||||||
|
Some(&roots.pid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -233,6 +233,7 @@ pub struct ClientMatch {
|
||||||
pub sandbox_instance_id_regex: Option<String>,
|
pub sandbox_instance_id_regex: Option<String>,
|
||||||
pub sandboxed: Option<bool>,
|
pub sandboxed: Option<bool>,
|
||||||
pub uid: Option<i32>,
|
pub uid: Option<i32>,
|
||||||
|
pub pid: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ impl Parser for ClientMatchParser<'_> {
|
||||||
sandbox_app_id,
|
sandbox_app_id,
|
||||||
sandbox_app_id_regex,
|
sandbox_app_id_regex,
|
||||||
),
|
),
|
||||||
(sandbox_instance_id, sandbox_instance_id_regex, uid),
|
(sandbox_instance_id, sandbox_instance_id_regex, uid, pid),
|
||||||
) = ext.extract((
|
) = ext.extract((
|
||||||
(
|
(
|
||||||
opt(str("name")),
|
opt(str("name")),
|
||||||
|
|
@ -67,6 +67,7 @@ impl Parser for ClientMatchParser<'_> {
|
||||||
opt(str("sandbox-instance-id")),
|
opt(str("sandbox-instance-id")),
|
||||||
opt(str("sandbox-instance-id-regex")),
|
opt(str("sandbox-instance-id-regex")),
|
||||||
opt(s32("uid")),
|
opt(s32("uid")),
|
||||||
|
opt(s32("pid")),
|
||||||
),
|
),
|
||||||
))?;
|
))?;
|
||||||
let mut not = None;
|
let mut not = None;
|
||||||
|
|
@ -108,6 +109,7 @@ impl Parser for ClientMatchParser<'_> {
|
||||||
sandbox_instance_id_regex: sandbox_instance_id_regex.despan_into(),
|
sandbox_instance_id_regex: sandbox_instance_id_regex.despan_into(),
|
||||||
sandboxed: sandboxed.despan(),
|
sandboxed: sandboxed.despan(),
|
||||||
uid: uid.despan(),
|
uid: uid.despan(),
|
||||||
|
pid: pid.despan(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,7 @@ impl Rule for ClientRule {
|
||||||
value_ref!(SandboxInstanceId, sandbox_instance_id);
|
value_ref!(SandboxInstanceId, sandbox_instance_id);
|
||||||
value_ref!(SandboxInstanceIdRegex, sandbox_instance_id_regex);
|
value_ref!(SandboxInstanceIdRegex, sandbox_instance_id_regex);
|
||||||
value!(Uid, uid);
|
value!(Uid, uid);
|
||||||
|
value!(Pid, pid);
|
||||||
bool!(Sandboxed, sandboxed);
|
bool!(Sandboxed, sandboxed);
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -563,6 +563,10 @@
|
||||||
"uid": {
|
"uid": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"description": "Matches the user ID of the client."
|
"description": "Matches the user ID of the client."
|
||||||
|
},
|
||||||
|
"pid": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Matches the process ID of the client."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": []
|
"required": []
|
||||||
|
|
|
||||||
|
|
@ -879,6 +879,14 @@ The table has the following fields:
|
||||||
|
|
||||||
The numbers should be integers.
|
The numbers should be integers.
|
||||||
|
|
||||||
|
- `pid` (optional):
|
||||||
|
|
||||||
|
Matches the process ID of the client.
|
||||||
|
|
||||||
|
The value of this field should be a number.
|
||||||
|
|
||||||
|
The numbers should be integers.
|
||||||
|
|
||||||
|
|
||||||
<a name="types-ClientMatchExactly"></a>
|
<a name="types-ClientMatchExactly"></a>
|
||||||
### `ClientMatchExactly`
|
### `ClientMatchExactly`
|
||||||
|
|
|
||||||
|
|
@ -3242,6 +3242,11 @@ ClientMatch:
|
||||||
integer_only: true
|
integer_only: true
|
||||||
required: false
|
required: false
|
||||||
description: Matches the user ID of the client.
|
description: Matches the user ID of the client.
|
||||||
|
pid:
|
||||||
|
kind: number
|
||||||
|
integer_only: true
|
||||||
|
required: false
|
||||||
|
description: Matches the process ID of the client.
|
||||||
|
|
||||||
|
|
||||||
ClientMatchExactly:
|
ClientMatchExactly:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue