// SPDX-FileCopyrightText: 2022 Matteo Settenvini // SPDX-License-Identifier: GPL-3.0-or-later #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] #![allow(dead_code)] use { anyhow::{ensure, Result}, std::env, std::ffi::CString, std::path::PathBuf, std::sync::Once, }; include!(concat!(env!("OUT_DIR"), "/bindings.rs")); static SETUP: Once = Once::new(); pub fn setup() -> Result<()> { let out_dir = PathBuf::from(env!("OUT_DIR")); let nss_config_status = unsafe { SETUP.call_once(|| { let library_path = test_cdylib::build_current_project(); let mut library_filename = library_path.file_name().unwrap().to_owned(); library_filename.push(".2"); // required for NSS modules let dest = out_dir.join(library_filename); std::fs::copy(library_path, dest).unwrap(); }); let db = CString::new("hosts").unwrap(); let resolvers = CString::new("malcontent [UNAVAIL=return] dns").unwrap(); __nss_configure_lookup(db.as_ptr(), resolvers.as_ptr()) }; ensure!( nss_config_status == 0, "Unable to configure NSS to load module: __nss_configure_lookup() returned {}", nss_config_status ); Ok(()) }