let quit_now = Arc::clone(&stop_now);
let interrupt_now = Arc::clone(&stop_now);
+ let frame = talloc::talloc_stackframe!();
+
async {
// Set the command line debug level
if let Some(debuglevel) = clap_args.get_one::<u16>("debuglevel") {
Ok(lp) => lp,
Err(e) => {
eprintln!("Failed loading smb.conf: {:?}", e);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
"The realm MUST be set in the \
smb.conf to start himmelblaud"
);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
Ok(Some(logfile)) => debug_set_logfile(&logfile),
_ => {
eprintln!("Failed to determine logfile name");
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
}
// Determine the unix socket path
let sock_dir_str = match lp.winbindd_socket_directory() {
Ok(Some(sock_dir)) => sock_dir,
- _ => return ExitCode::FAILURE,
+ _ => {
+ talloc::TALLOC_FREE!(frame);
+ return ExitCode::FAILURE;
+ }
};
let sock_dir = Path::new(&sock_dir_str);
let mut sock_path = PathBuf::from(sock_dir);
sock_path.push("hb_pipe");
let sock_path = match sock_path.to_str() {
Some(sock_path) => sock_path,
- None => return ExitCode::FAILURE,
+ None => {
+ talloc::TALLOC_FREE!(frame);
+ return ExitCode::FAILURE;
+ }
};
// Initialize the Himmelblau cache
Ok(Some(private_cache_path)) => private_cache_path,
_ => {
DBG_ERR!("Failed to determine private cache path");
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
"The private directory '{}' does not exist",
private_dir.display()
);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
let mut pcache = match PrivateCache::new(&private_cache_path) {
"Failed to open the himmelblau private cache: {:?}",
e
);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
Ok(Some(cache_dir)) => cache_dir,
_ => {
DBG_ERR!("Failed to determine cache directory");
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
if !Path::new(&cache_dir).exists() {
DBG_ERR!("The cache directory '{}' does not exist", cache_dir);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
Ok(cache) => cache,
Err(e) => {
DBG_ERR!("Failed to open the himmelblau user cache: {:?}", e);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
Ok(cache) => cache,
Err(e) => {
DBG_ERR!("Failed to open the himmelblau uid cache: {:?}", e);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
Ok(cache) => cache,
Err(e) => {
DBG_ERR!("Failed to open the himmelblau group cache: {:?}", e);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
Ok(Some(hsm_pin_path)) => hsm_pin_path,
_ => {
DBG_ERR!("Failed loading hsm pin path.");
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
"The hsm pin directory '{}' does not exist",
hsm_pin_dir.display()
);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
let auth_value =
Ok(auth_value) => auth_value,
Err(e) => {
DBG_ERR!("{:?}", e);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
Ok(lmk) => lmk,
Err(e) => {
DBG_ERR!("{:?}", e);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
private_cache_path
);
DBG_INFO!("The host will forget domain enrollments.");
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
Ok(graph) => graph,
Err(e) => {
DBG_ERR!("Failed initializing the graph: {:?}", e);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
Ok(client) => client,
Err(e) => {
DBG_ERR!("Failed initializing the broker: {:?}", e);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
Ok(idmap) => idmap,
Err(e) => {
DBG_ERR!("Failed initializing the idmapper: {:?}", e);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
Ok(res) => res,
Err(e) => {
DBG_ERR!("Failed fetching idmap range: {:?}", e);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
if let Err(e) = idmap.add_gen_domain(&realm, &tenant_id, (low, high)) {
DBG_ERR!("Failed adding the domain idmap range: {:?}", e);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
Ok(listener) => listener,
Err(e) => {
DBG_ERR!("Failed setting up the socket listener: {:?}", e);
+ talloc::TALLOC_FREE!(frame);
return ExitCode::FAILURE;
}
};
}
}
+ talloc::TALLOC_FREE!(frame);
ExitCode::SUCCESS
}
.await
--- /dev/null
+use std::env;
+use std::path::PathBuf;
+
+fn main() {
+ let bindings = bindgen::Builder::default()
+ .blocklist_function("qgcvt")
+ .blocklist_function("qgcvt_r")
+ .blocklist_function("qfcvt")
+ .blocklist_function("qfcvt_r")
+ .blocklist_function("qecvt")
+ .blocklist_function("qecvt_r")
+ .blocklist_function("strtold")
+ .clang_arg("-Dbool=int")
+ .generate_comments(false)
+ .clang_arg("-I../../lib/talloc")
+ .header("../../lib/util/talloc_stack.h")
+ .parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
+ .generate()
+ .expect("Unable to generate bindings");
+ println!("cargo:rerun-if-changed=../../lib/util/talloc_stack.h");
+
+ let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
+ bindings
+ .write_to_file(out_path.join("bindings.rs"))
+ .expect("Couldn't write bindings!");
+
+ let mut src_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
+ src_dir.push("../../bin/default/lib/talloc");
+ if config::USING_SYSTEM_TALLOC == 1 {
+ println!("cargo:rustc-link-lib=talloc");
+ } else {
+ println!("cargo:rustc-link-lib=talloc-private-samba");
+ }
+ println!(
+ "cargo:rustc-link-search=native={}",
+ src_dir.to_str().unwrap()
+ );
+}
--- /dev/null
+/*
+ Unix SMB/CIFS implementation.
+
+ Talloc stackframe functions
+
+ Copyright (C) David Mulder 2024
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+pub mod ffi {
+ #![allow(non_upper_case_globals)]
+ #![allow(non_camel_case_types)]
+ #![allow(non_snake_case)]
+ #![allow(dead_code)]
+ #![allow(clippy::upper_case_acronyms)]
+ include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
+}
+
+#[macro_export]
+macro_rules! talloc_stackframe {
+ () => {{
+ let function = chelps::function!();
+ let function_cstr = chelps::wrap_string(&function);
+ unsafe {
+ let ret = $crate::ffi::_talloc_stackframe(function_cstr);
+ chelps::string_free(function_cstr);
+ ret
+ }
+ }};
+}
+
+#[macro_export]
+macro_rules! TALLOC_FREE {
+ ($ctx:ident) => {{
+ if !$ctx.is_null() {
+ let function = chelps::function!();
+ let function_cstr = chelps::wrap_string(&function);
+ unsafe {
+ $crate::ffi::_talloc_free($ctx, function_cstr);
+ chelps::string_free(function_cstr);
+ }
+ }
+ }};
+}