Skip to content

Commit

Permalink
fix permission
Browse files Browse the repository at this point in the history
  • Loading branch information
namachan10777 committed Oct 6, 2024
1 parent 9e40ac3 commit ac73e08
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::{io, path::PathBuf};
use std::{io, os::unix::fs::PermissionsExt, path::PathBuf};

use anyhow::Context;
use clap::Parser;
use futures::future::try_join_all;
use serde::Deserialize;
use tokio::{
fs,
fs::{self, set_permissions},
io::{AsyncSeekExt, AsyncWriteExt},
time::{sleep, Instant},
};
Expand All @@ -32,6 +32,15 @@ async fn run(opts: &Opts) -> anyhow::Result<()> {
.with_context(|| "read config file")?;
let config: Config = toml::from_str(&config).with_context(|| "parse config file")?;

if let Some(parent) = config.authorized_keys_file.parent() {
fs::create_dir_all(parent)
.await
.with_context(|| "create ssh dir")?;
set_permissions(parent, PermissionsExt::from_mode(0o700))
.await
.with_context(|| "set mode")?;
}

let mut authorized_keys = fs::File::options()
.append(false)
.create(true)
Expand All @@ -40,6 +49,12 @@ async fn run(opts: &Opts) -> anyhow::Result<()> {
.open(&config.authorized_keys_file)
.await
.with_context(|| "open authorized keys")?;
set_permissions(
&config.authorized_keys_file,
PermissionsExt::from_mode(0o600),
)
.await
.with_context(|| "set mode")?;
loop {
let instant = Instant::now();

Expand Down

0 comments on commit ac73e08

Please sign in to comment.