mirror of
https://git.proxmox.com/git/proxmox-perl-rs
synced 2025-05-29 14:11:03 +00:00
pve: switch openid to use magic
Instead of blessed raw pointers as these can easily lead to double free corruptions when they're copied in perl. Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
e3bc763de4
commit
1c2ff27e75
@ -1,6 +1,5 @@
|
|||||||
#[perlmod::package(name = "PVE::RS::OpenId", lib = "pve_rs")]
|
#[perlmod::package(name = "PVE::RS::OpenId", lib = "pve_rs")]
|
||||||
mod export {
|
mod export {
|
||||||
use std::convert::TryFrom;
|
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
@ -9,34 +8,13 @@ mod export {
|
|||||||
|
|
||||||
use proxmox_openid::{OpenIdAuthenticator, OpenIdConfig, PrivateAuthState};
|
use proxmox_openid::{OpenIdAuthenticator, OpenIdConfig, PrivateAuthState};
|
||||||
|
|
||||||
const CLASSNAME: &str = "PVE::RS::OpenId";
|
perlmod::declare_magic!(Box<OpenId> : &OpenId as "PVE::RS::OpenId");
|
||||||
|
|
||||||
/// An OpenIdAuthenticator client instance.
|
/// An OpenIdAuthenticator client instance.
|
||||||
pub struct OpenId {
|
pub struct OpenId {
|
||||||
inner: Mutex<OpenIdAuthenticator>,
|
inner: Mutex<OpenIdAuthenticator>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TryFrom<&'a Value> for &'a OpenId {
|
|
||||||
type Error = Error;
|
|
||||||
|
|
||||||
fn try_from(value: &'a Value) -> Result<&'a OpenId, Error> {
|
|
||||||
Ok(unsafe { value.from_blessed_box(CLASSNAME)? })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bless(class: Value, mut ptr: Box<OpenId>) -> Result<Value, Error> {
|
|
||||||
let value = Value::new_pointer::<OpenId>(&mut *ptr);
|
|
||||||
let value = Value::new_ref(&value);
|
|
||||||
let this = value.bless_sv(&class)?;
|
|
||||||
let _perl = Box::leak(ptr);
|
|
||||||
Ok(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[export(name = "DESTROY")]
|
|
||||||
fn destroy(#[raw] this: Value) {
|
|
||||||
perlmod::destructor!(this, OpenId: CLASSNAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a new OpenId client instance
|
/// Create a new OpenId client instance
|
||||||
#[export(raw_return)]
|
#[export(raw_return)]
|
||||||
pub fn discover(
|
pub fn discover(
|
||||||
@ -45,12 +23,12 @@ mod export {
|
|||||||
redirect_url: &str,
|
redirect_url: &str,
|
||||||
) -> Result<Value, Error> {
|
) -> Result<Value, Error> {
|
||||||
let open_id = OpenIdAuthenticator::discover(&config, redirect_url)?;
|
let open_id = OpenIdAuthenticator::discover(&config, redirect_url)?;
|
||||||
bless(
|
Ok(perlmod::instantiate_magic!(
|
||||||
class,
|
&class,
|
||||||
Box::new(OpenId {
|
MAGIC => Box::new(OpenId {
|
||||||
inner: Mutex::new(open_id),
|
inner: Mutex::new(open_id),
|
||||||
}),
|
})
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[export]
|
#[export]
|
||||||
|
Loading…
Reference in New Issue
Block a user