mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-26 08:34:55 +01:00
Updates rsasl
This commit is contained in:
parent
36745683e0
commit
91a17e6b57
@ -36,7 +36,7 @@ uuid = { version = "0.8", features = ["serde", "v4"] }
|
|||||||
clap = "2.33"
|
clap = "2.33"
|
||||||
|
|
||||||
# TODO update this if bindgen breaks (again)
|
# TODO update this if bindgen breaks (again)
|
||||||
rsasl = "0.1.2"
|
rsasl = "0.2.2"
|
||||||
|
|
||||||
# rumqtt needs tokio which I'm trying to get away from
|
# rumqtt needs tokio which I'm trying to get away from
|
||||||
paho-mqtt = { git = "https://github.com/dequbed/paho.mqtt.rust.git", branch = "master", features = ["build_bindgen"] }
|
paho-mqtt = { git = "https://github.com/dequbed/paho.mqtt.rust.git", branch = "master", features = ["build_bindgen"] }
|
||||||
|
36
src/auth.rs
36
src/auth.rs
@ -5,22 +5,30 @@
|
|||||||
|
|
||||||
use slog::Logger;
|
use slog::Logger;
|
||||||
|
|
||||||
use rsasl::{SASL, Property, Session, ReturnCode};
|
use rsasl::{
|
||||||
use rsasl::sys::{Gsasl, Gsasl_session};
|
SASL,
|
||||||
|
Property,
|
||||||
|
Session,
|
||||||
|
ReturnCode,
|
||||||
|
Callback,
|
||||||
|
SaslCtx,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::error::Result;
|
use crate::error::Result;
|
||||||
use crate::config::Settings;
|
use crate::config::Settings;
|
||||||
|
|
||||||
pub use crate::schema::auth_capnp;
|
pub use crate::schema::auth_capnp;
|
||||||
|
|
||||||
extern "C" fn callback(ctx: *mut Gsasl, sctx: *mut Gsasl_session, prop: Property) -> i32 {
|
struct AppData;
|
||||||
let sasl = SASL::from_ptr(ctx);
|
struct SessionData;
|
||||||
let mut session = Session::from_ptr(sctx);
|
|
||||||
|
|
||||||
let rc = match prop {
|
struct CB;
|
||||||
|
impl Callback<AppData, SessionData> for CB {
|
||||||
|
fn callback(sasl: SaslCtx<AppData, SessionData>, session: Session<SessionData>, prop: Property) -> libc::c_int {
|
||||||
|
let ret = match prop {
|
||||||
Property::GSASL_VALIDATE_SIMPLE => {
|
Property::GSASL_VALIDATE_SIMPLE => {
|
||||||
let authid = session.get_property_fast(Property::GSASL_AUTHID).to_string_lossy();
|
let authid = session.get_property(Property::GSASL_AUTHID).unwrap().to_string_lossy();
|
||||||
let pass = session.get_property_fast(Property::GSASL_PASSWORD).to_string_lossy();
|
let pass = session.get_property(Property::GSASL_PASSWORD).unwrap().to_string_lossy();
|
||||||
|
|
||||||
if authid == "test" && pass == "secret" {
|
if authid == "test" && pass == "secret" {
|
||||||
ReturnCode::GSASL_OK
|
ReturnCode::GSASL_OK
|
||||||
@ -33,19 +41,23 @@ extern "C" fn callback(ctx: *mut Gsasl, sctx: *mut Gsasl_session, prop: Property
|
|||||||
ReturnCode::GSASL_NO_CALLBACK
|
ReturnCode::GSASL_NO_CALLBACK
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
ret as libc::c_int
|
||||||
rc as i32
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Auth {
|
pub struct Auth {
|
||||||
pub ctx: SASL,
|
pub ctx: SASL<AppData, SessionData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Auth {
|
impl Auth {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let mut ctx = SASL::new().unwrap();
|
let mut ctx = SASL::new().unwrap();
|
||||||
|
|
||||||
ctx.install_callback(Some(callback));
|
let mut appdata = Box::new(AppData);
|
||||||
|
|
||||||
|
ctx.store(appdata);
|
||||||
|
|
||||||
|
ctx.install_callback::<CB>();
|
||||||
|
|
||||||
Self { ctx }
|
Self { ctx }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user