Begin add uds_windows (Not working) + add config load
This commit is contained in:
parent
46d401493b
commit
980722c6cb
4 changed files with 31 additions and 8 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -139,6 +139,7 @@ dependencies = [
|
|||
"tonic",
|
||||
"tonic-build",
|
||||
"tower",
|
||||
"uds_windows",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
|
@ -959,6 +960,16 @@ version = "0.2.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
|
||||
|
||||
[[package]]
|
||||
name = "uds_windows"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce65604324d3cce9b966701489fbd0cf318cb1f7bd9dd07ac9a4ee6fb791930d"
|
||||
dependencies = [
|
||||
"tempfile",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.6"
|
||||
|
|
|
@ -34,5 +34,8 @@ tower = "0.4" # Required for tonic with unix socket
|
|||
prost = "0.11" # Required for tonic
|
||||
tonic = "0.8"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
uds_windows = "1.0"
|
||||
|
||||
[build-dependencies]
|
||||
tonic-build = { version = "0.8", features = ["prost"] } # Required for tonic
|
|
@ -8,6 +8,14 @@ pub struct Configuration {
|
|||
}
|
||||
|
||||
impl Configuration {
|
||||
pub fn read_or_create() -> Self {
|
||||
let path = std::path::Path::new("configuration.yml");
|
||||
let file = std::fs::File::open(path).unwrap();
|
||||
let buffer = std::io::BufReader::new(file);
|
||||
use std::io::Read;
|
||||
serde_yaml::from_reader(buffer).unwrap()
|
||||
}
|
||||
|
||||
pub fn command_allowed(&self, command: &str) -> bool {
|
||||
self.whitelist == command
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ mod sessions;
|
|||
mod configuration;
|
||||
|
||||
pub(self) static SESSIONS : Mutex<Vec<libcommand::Session>> = Mutex::new(Vec::new());
|
||||
pub(self) static CONFIGURATION : Mutex<Option<configuration::Configuration>> = Mutex::new(None);
|
||||
|
||||
pub use sessions::{
|
||||
get_sessions_lock,
|
||||
|
@ -14,20 +15,25 @@ pub use sessions::{
|
|||
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
#[cfg(unix)]
|
||||
use tokio::net::UnixListener;
|
||||
|
||||
#[cfg(unix)]
|
||||
use tokio_stream::wrappers::UnixListenerStream;
|
||||
use tonic::transport::Server;
|
||||
|
||||
#[cfg(unix)]
|
||||
use tokio::net::UnixListener;
|
||||
|
||||
#[cfg(windows)]
|
||||
use uds_windows::UnixListener;
|
||||
|
||||
use libcommand::interpreter::unix_server::UnixServer;
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
std::fs::create_dir_all(Path::new(libcommand::SOCK_FILE).parent().unwrap())?;
|
||||
|
||||
*CONFIGURATION.get_mut().unwrap() = Some(configuration::Configuration::read_or_create());
|
||||
|
||||
let server = server::DaemonServer::default();
|
||||
|
||||
let uds = UnixListener::bind(libcommand::SOCK_FILE)?;
|
||||
|
@ -51,9 +57,4 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
fn main() {
|
||||
panic!("The `uds` example only works on unix systems!");
|
||||
}
|
Reference in a new issue