wayland: implement wp-security-manager-v1
This commit is contained in:
parent
886339ff96
commit
1fceffe235
16 changed files with 417 additions and 11 deletions
|
|
@ -48,7 +48,7 @@ impl WlRegistryRequestHandler for WlRegistry {
|
|||
fn bind(&self, bind: Bind, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
let name = GlobalName::from_raw(bind.name);
|
||||
let globals = &self.client.state.globals;
|
||||
let global = globals.get(name, self.client.caps, self.client.is_xwayland)?;
|
||||
let global = globals.get(name, self.client.effective_caps, self.client.is_xwayland)?;
|
||||
if global.interface().name() != bind.interface {
|
||||
return Err(WlRegistryError::InvalidInterface(InterfaceError {
|
||||
name: global.name(),
|
||||
|
|
|
|||
107
src/ifs/wp_security_context_manager_v1.rs
Normal file
107
src/ifs/wp_security_context_manager_v1.rs
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
use {
|
||||
crate::{
|
||||
client::{Client, ClientError},
|
||||
globals::{Global, GlobalName},
|
||||
ifs::wp_security_context_v1::WpSecurityContextV1,
|
||||
leaks::Tracker,
|
||||
object::{Object, Version},
|
||||
wire::{wp_security_context_manager_v1::*, WpSecurityContextManagerV1Id},
|
||||
},
|
||||
std::rc::Rc,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
pub struct WpSecurityContextManagerV1Global {
|
||||
pub name: GlobalName,
|
||||
}
|
||||
|
||||
impl WpSecurityContextManagerV1Global {
|
||||
pub fn new(name: GlobalName) -> Self {
|
||||
Self { name }
|
||||
}
|
||||
|
||||
fn bind_(
|
||||
self: Rc<Self>,
|
||||
id: WpSecurityContextManagerV1Id,
|
||||
client: &Rc<Client>,
|
||||
version: Version,
|
||||
) -> Result<(), WpSecurityContextManagerV1Error> {
|
||||
let obj = Rc::new(WpSecurityContextManagerV1 {
|
||||
id,
|
||||
client: client.clone(),
|
||||
tracker: Default::default(),
|
||||
version,
|
||||
});
|
||||
track!(client, obj);
|
||||
client.add_client_obj(&obj)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
global_base!(
|
||||
WpSecurityContextManagerV1Global,
|
||||
WpSecurityContextManagerV1,
|
||||
WpSecurityContextManagerV1Error
|
||||
);
|
||||
|
||||
impl Global for WpSecurityContextManagerV1Global {
|
||||
fn singleton(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn version(&self) -> u32 {
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
simple_add_global!(WpSecurityContextManagerV1Global);
|
||||
|
||||
pub struct WpSecurityContextManagerV1 {
|
||||
pub id: WpSecurityContextManagerV1Id,
|
||||
pub client: Rc<Client>,
|
||||
pub tracker: Tracker<Self>,
|
||||
pub version: Version,
|
||||
}
|
||||
|
||||
impl WpSecurityContextManagerV1RequestHandler for WpSecurityContextManagerV1 {
|
||||
type Error = WpSecurityContextManagerV1Error;
|
||||
|
||||
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
self.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_listener(&self, req: CreateListener, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
let obj = Rc::new(WpSecurityContextV1 {
|
||||
id: req.id,
|
||||
client: self.client.clone(),
|
||||
tracker: Default::default(),
|
||||
version: self.version,
|
||||
listen_fd: req.listen_fd,
|
||||
close_fd: req.close_fd,
|
||||
sandbox_engine: Default::default(),
|
||||
app_id: Default::default(),
|
||||
instance_id: Default::default(),
|
||||
committed: Default::default(),
|
||||
});
|
||||
track!(self.client, obj);
|
||||
self.client.add_client_obj(&obj)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
object_base! {
|
||||
self = WpSecurityContextManagerV1;
|
||||
version = self.version;
|
||||
}
|
||||
|
||||
impl Object for WpSecurityContextManagerV1 {}
|
||||
|
||||
simple_add_obj!(WpSecurityContextManagerV1);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WpSecurityContextManagerV1Error {
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
}
|
||||
efrom!(WpSecurityContextManagerV1Error, ClientError);
|
||||
119
src/ifs/wp_security_context_v1.rs
Normal file
119
src/ifs/wp_security_context_v1.rs
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
use {
|
||||
crate::{
|
||||
client::{Client, ClientCaps, ClientError},
|
||||
leaks::Tracker,
|
||||
object::{Object, Version},
|
||||
wire::{wp_security_context_v1::*, WpSecurityContextV1Id},
|
||||
},
|
||||
std::{
|
||||
cell::{Cell, RefCell},
|
||||
rc::Rc,
|
||||
},
|
||||
thiserror::Error,
|
||||
uapi::OwnedFd,
|
||||
};
|
||||
|
||||
pub struct WpSecurityContextV1 {
|
||||
pub id: WpSecurityContextV1Id,
|
||||
pub client: Rc<Client>,
|
||||
pub tracker: Tracker<Self>,
|
||||
pub version: Version,
|
||||
pub listen_fd: Rc<OwnedFd>,
|
||||
pub close_fd: Rc<OwnedFd>,
|
||||
pub sandbox_engine: RefCell<Option<String>>,
|
||||
pub app_id: RefCell<Option<String>>,
|
||||
pub instance_id: RefCell<Option<String>>,
|
||||
pub committed: Cell<bool>,
|
||||
}
|
||||
|
||||
impl WpSecurityContextV1 {
|
||||
fn check_committed(&self) -> Result<(), WpSecurityContextV1Error> {
|
||||
if self.committed.get() {
|
||||
return Err(WpSecurityContextV1Error::Committed);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl WpSecurityContextV1RequestHandler for WpSecurityContextV1 {
|
||||
type Error = WpSecurityContextV1Error;
|
||||
|
||||
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
self.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_sandbox_engine(
|
||||
&self,
|
||||
req: SetSandboxEngine<'_>,
|
||||
_slf: &Rc<Self>,
|
||||
) -> Result<(), Self::Error> {
|
||||
self.check_committed()?;
|
||||
let val = &mut *self.sandbox_engine.borrow_mut();
|
||||
if val.is_some() {
|
||||
return Err(WpSecurityContextV1Error::EnginSet);
|
||||
}
|
||||
*val = Some(req.name.to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_app_id(&self, req: SetAppId<'_>, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
self.check_committed()?;
|
||||
let val = &mut *self.app_id.borrow_mut();
|
||||
if val.is_some() {
|
||||
return Err(WpSecurityContextV1Error::AppSet);
|
||||
}
|
||||
*val = Some(req.app_id.to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_instance_id(&self, req: SetInstanceId<'_>, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
self.check_committed()?;
|
||||
let val = &mut *self.instance_id.borrow_mut();
|
||||
if val.is_some() {
|
||||
return Err(WpSecurityContextV1Error::InstanceSet);
|
||||
}
|
||||
*val = Some(req.instance_id.to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn commit(&self, _req: Commit, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
self.check_committed()?;
|
||||
self.committed.set(true);
|
||||
let caps = ClientCaps::none() & self.client.bounding_caps;
|
||||
self.client.state.security_context_acceptors.spawn(
|
||||
&self.client.state,
|
||||
self.sandbox_engine.take(),
|
||||
self.app_id.take(),
|
||||
self.instance_id.take(),
|
||||
&self.listen_fd,
|
||||
&self.close_fd,
|
||||
caps,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
object_base! {
|
||||
self = WpSecurityContextV1;
|
||||
version = self.version;
|
||||
}
|
||||
|
||||
impl Object for WpSecurityContextV1 {}
|
||||
|
||||
simple_add_obj!(WpSecurityContextV1);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WpSecurityContextV1Error {
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error("The sandbox engine has already been set")]
|
||||
EnginSet,
|
||||
#[error("The app id has already been set")]
|
||||
AppSet,
|
||||
#[error("The instance id has already been set")]
|
||||
InstanceSet,
|
||||
#[error("The context has already been committed")]
|
||||
Committed,
|
||||
}
|
||||
efrom!(WpSecurityContextV1Error, ClientError);
|
||||
Loading…
Add table
Add a link
Reference in a new issue