From 91a17e6b5747eddfa9ed111fbb9bb8d0f47e55cb Mon Sep 17 00:00:00 2001 From: Gregor Reitzenstein Date: Fri, 23 Oct 2020 11:52:49 +0200 Subject: [PATCH] Updates rsasl --- Cargo.toml | 2 +- src/auth.rs | 58 ++++++++++++++++++++++++++++++++--------------------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bb5aed0..efcf734 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ uuid = { version = "0.8", features = ["serde", "v4"] } clap = "2.33" # 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 paho-mqtt = { git = "https://github.com/dequbed/paho.mqtt.rust.git", branch = "master", features = ["build_bindgen"] } diff --git a/src/auth.rs b/src/auth.rs index 3ef57e0..dba4a33 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -5,47 +5,59 @@ use slog::Logger; -use rsasl::{SASL, Property, Session, ReturnCode}; -use rsasl::sys::{Gsasl, Gsasl_session}; +use rsasl::{ + SASL, + Property, + Session, + ReturnCode, + Callback, + SaslCtx, +}; use crate::error::Result; use crate::config::Settings; pub use crate::schema::auth_capnp; -extern "C" fn callback(ctx: *mut Gsasl, sctx: *mut Gsasl_session, prop: Property) -> i32 { - let sasl = SASL::from_ptr(ctx); - let mut session = Session::from_ptr(sctx); +struct AppData; +struct SessionData; - let rc = match prop { - Property::GSASL_VALIDATE_SIMPLE => { - let authid = session.get_property_fast(Property::GSASL_AUTHID).to_string_lossy(); - let pass = session.get_property_fast(Property::GSASL_PASSWORD).to_string_lossy(); +struct CB; +impl Callback for CB { + fn callback(sasl: SaslCtx, session: Session, prop: Property) -> libc::c_int { + 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" { - ReturnCode::GSASL_OK - } else { - ReturnCode::GSASL_AUTHENTICATION_ERROR + if authid == "test" && pass == "secret" { + ReturnCode::GSASL_OK + } else { + ReturnCode::GSASL_AUTHENTICATION_ERROR + } } - } - p => { - println!("Callback called with property {:?}", p); - ReturnCode::GSASL_NO_CALLBACK - } - }; - - rc as i32 + p => { + println!("Callback called with property {:?}", p); + ReturnCode::GSASL_NO_CALLBACK + } + }; + ret as libc::c_int + } } pub struct Auth { - pub ctx: SASL, + pub ctx: SASL, } impl Auth { pub fn new() -> Self { let mut ctx = SASL::new().unwrap(); - ctx.install_callback(Some(callback)); + let mut appdata = Box::new(AppData); + + ctx.store(appdata); + + ctx.install_callback::(); Self { ctx } }