summaryrefslogtreecommitdiff
path: root/server/src/authorized_keys.rs
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-06-04 00:11:41 +0200
committerJoel Klinghed <the_jk@spawned.biz>2025-06-04 00:11:41 +0200
commita84d3cb7e9659b57ad3bbca6cc894a46fbf741fd (patch)
tree9a032c6e6c716436084f346790a7901a09b67e23 /server/src/authorized_keys.rs
parentcd971e758ba7669b94ea3d1d3c2bf2376550820f (diff)
Make integration actually work
Add logs Add remote keys for each user
Diffstat (limited to 'server/src/authorized_keys.rs')
-rw-r--r--server/src/authorized_keys.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/server/src/authorized_keys.rs b/server/src/authorized_keys.rs
index 21651ef..81885b3 100644
--- a/server/src/authorized_keys.rs
+++ b/server/src/authorized_keys.rs
@@ -1,9 +1,11 @@
use futures::stream::TryStreamExt;
+use log::{error, info};
use rocket::fairing::{self, AdHoc};
use rocket::serde::Deserialize;
use rocket::{Build, Rocket};
use rocket_db_pools::{sqlx, Database};
use std::borrow::Cow;
+use std::os::unix::fs::MetadataExt;
use std::path::{Path, PathBuf};
use std::sync::Mutex;
use tokio::fs;
@@ -86,8 +88,18 @@ impl AuthorizedKeys {
let tmp = path.with_extension("new");
fs::write(&tmp, content.as_bytes()).await?;
+ if let Ok(metadata) = fs::metadata(path).await {
+ // Try to replicate ownership and permissions of original file
+ fs::set_permissions(&tmp, metadata.permissions())
+ .await
+ .unwrap_or(());
+ std::os::unix::fs::chown(&tmp, Some(metadata.uid()), Some(metadata.gid()))
+ .unwrap_or(());
+ }
fs::rename(tmp, path).await?;
+ info!("Updated {path:?}, {} keys", keys.len());
+
Ok(())
}
}
@@ -127,7 +139,10 @@ async fn setup_users(rocket: Rocket<Build>) -> fairing::Result {
Some(roots) => match Db::fetch(&rocket) {
Some(db) => match setup_users_keys(roots, config, db).await {
Ok(_) => Ok(rocket),
- Err(_) => Err(rocket),
+ Err(e) => {
+ error!("{e:?}");
+ Err(rocket)
+ }
},
None => Err(rocket),
},