Updates rsasl

This commit is contained in:
Gregor Reitzenstein 2020-10-23 11:52:49 +02:00
parent 36745683e0
commit 91a17e6b57
2 changed files with 36 additions and 24 deletions

View File

@ -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"] }

View File

@ -5,47 +5,59 @@
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;
Property::GSASL_VALIDATE_SIMPLE => { impl Callback<AppData, SessionData> for CB {
let authid = session.get_property_fast(Property::GSASL_AUTHID).to_string_lossy(); fn callback(sasl: SaslCtx<AppData, SessionData>, session: Session<SessionData>, prop: Property) -> libc::c_int {
let pass = session.get_property_fast(Property::GSASL_PASSWORD).to_string_lossy(); let ret = match prop {
Property::GSASL_VALIDATE_SIMPLE => {
let authid = session.get_property(Property::GSASL_AUTHID).unwrap().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
} else { } else {
ReturnCode::GSASL_AUTHENTICATION_ERROR ReturnCode::GSASL_AUTHENTICATION_ERROR
}
} }
} p => {
p => { println!("Callback called with property {:?}", p);
println!("Callback called with property {:?}", p); 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 }
} }