mirror of
https://gitlab.com/erkanisik/yali-rs.git
synced 2026-07-30 18:59:02 +00:00
feat: enhance password setting process with secure echo method and clean up bootmnt directory
This commit is contained in:
+76
-9
@@ -1370,6 +1370,8 @@ impl Job for CleanupLiveJob {
|
||||
// YALI desktop dosyaları
|
||||
let _ = tokio::fs::remove_file(format!("{}/usr/share/applications/yali.desktop", mt)).await;
|
||||
let _ = tokio::fs::remove_file(format!("{}/usr/share/applications/yali-bin.desktop", mt)).await;
|
||||
let _ = tokio::fs::remove_dir_all(format!("{}/bootmnt", mt)).await;
|
||||
|
||||
|
||||
ui.log("✓ Live temizlik tamamlandı");
|
||||
Ok(())
|
||||
@@ -1707,20 +1709,37 @@ impl Job for CreateUserJob {
|
||||
&self.username,
|
||||
]).await?;
|
||||
|
||||
// chpasswd ile şifre ayarla (stdin üzerinden güvenli)
|
||||
ui.log(format!("Şifre ayarlanıyor: {}", self.username));
|
||||
let chpasswd_input = format!("{}:{}", self.username, self.password);
|
||||
set_password_via_chpasswd(&self.mount, &chpasswd_input).await?;
|
||||
// // chpasswd ile şifre ayarla (stdin üzerinden güvenli)
|
||||
// ui.log(format!("Şifre ayarlanıyor: {}", self.username));
|
||||
// let chpasswd_input = format!("{}:{}", self.username, self.password);
|
||||
// set_password_via_chpasswd(&self.mount, &chpasswd_input).await?;
|
||||
|
||||
// Root şifresi: belirlenmişse ayarla, yoksa kilitle
|
||||
// // Root şifresi: belirlenmişse ayarla, yoksa kilitle
|
||||
// if self.root_password.is_empty() {
|
||||
// ui.log("Root hesabı kilitleniyor…");
|
||||
// run_chroot(&self.mount, &["passwd", "-l", "root"]).await?;
|
||||
// } else {
|
||||
// ui.log("Root şifresi ayarlanıyor…");
|
||||
// let root_input = format!("root:{}", self.root_password);
|
||||
// set_password_via_chpasswd(&self.mount, &root_input).await?;
|
||||
// }
|
||||
|
||||
// 2. chpasswd ile şifre ayarla (YENİ BASİTLEŞTİRİLMİŞ VE KESİN YÖNTEM)
|
||||
ui.log(format!("Şifre ayarlanıyor: {}", self.username));
|
||||
// sh -c kullanarak echo ile chpasswd'e şifreyi güvenli bir şekilde üflüyoruz
|
||||
let user_cmd = format!("echo '{}:{}' | chpasswd -c SHA512", self.username, self.password);
|
||||
run_chroot(&self.mount, &["sh", "-c", &user_cmd]).await?;
|
||||
|
||||
// 3. Root şifresi: belirlenmişse ayarla, yoksa kilitle
|
||||
if self.root_password.is_empty() {
|
||||
ui.log("Root hesabı kilitleniyor…");
|
||||
run_chroot(&self.mount, &["passwd", "-l", "root"]).await?;
|
||||
} else {
|
||||
ui.log("Root şifresi ayarlanıyor…");
|
||||
let root_input = format!("root:{}", self.root_password);
|
||||
set_password_via_chpasswd(&self.mount, &root_input).await?;
|
||||
}
|
||||
let root_cmd = format!("echo 'root:{}' | chpasswd -c SHA512", self.root_password);
|
||||
run_chroot(&self.mount, &["sh", "-c", &root_cmd]).await?;
|
||||
}
|
||||
|
||||
|
||||
// sudoers: wheel grubu sudo yetkisi alsın
|
||||
let sudoers_dir = format!("{}/etc/sudoers.d", self.mount);
|
||||
@@ -1739,6 +1758,43 @@ impl Job for CreateUserJob {
|
||||
}
|
||||
}
|
||||
|
||||
// /// `chpasswd` komutuna stdin üzerinden kullanıcı:şifre gönderir.
|
||||
// async fn set_password_via_chpasswd(mount: &str, input: &str) -> Result<(), String> {
|
||||
// if DEMO_MODE.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
// tokio::time::sleep(std::time::Duration::from_millis(2500)).await;
|
||||
// return Ok(());
|
||||
// }
|
||||
|
||||
// use tokio::io::AsyncWriteExt;
|
||||
// use tokio::process::Command;
|
||||
|
||||
// let mut child = Command::new("chroot")
|
||||
// .args([mount, "chpasswd"])
|
||||
// .stdin(std::process::Stdio::piped())
|
||||
// .stdout(std::process::Stdio::null())
|
||||
// .stderr(std::process::Stdio::piped())
|
||||
// .spawn()
|
||||
// .map_err(|e| format!("chpasswd başlatılamadı: {}", e))?;
|
||||
|
||||
// if let Some(mut stdin) = child.stdin.take() {
|
||||
// let mut data = input.as_bytes().to_vec();
|
||||
// if !data.ends_with(b"\n") {
|
||||
// data.push(b'\n');
|
||||
// }
|
||||
// stdin.write_all(&data).await
|
||||
// .map_err(|e| format!("chpasswd stdin yazma hatası: {}", e))?;
|
||||
// }
|
||||
|
||||
// let output = child.wait_with_output().await
|
||||
// .map_err(|e| format!("chpasswd bekleme hatası: {}", e))?;
|
||||
|
||||
// if output.status.success() {
|
||||
// Ok(())
|
||||
// } else {
|
||||
// Err(String::from_utf8_lossy(&output.stderr).trim().to_string())
|
||||
// }
|
||||
// }
|
||||
|
||||
/// `chpasswd` komutuna stdin üzerinden kullanıcı:şifre gönderir.
|
||||
async fn set_password_via_chpasswd(mount: &str, input: &str) -> Result<(), String> {
|
||||
if DEMO_MODE.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
@@ -1751,6 +1807,7 @@ async fn set_password_via_chpasswd(mount: &str, input: &str) -> Result<(), Strin
|
||||
|
||||
let mut child = Command::new("chroot")
|
||||
.args([mount, "chpasswd"])
|
||||
// Gerekirse varsayılan algoritmayı garantiye almak için araya "-c", "SHA512" argümanları eklenebilir.
|
||||
.stdin(std::process::Stdio::piped())
|
||||
.stdout(std::process::Stdio::null())
|
||||
.stderr(std::process::Stdio::piped())
|
||||
@@ -1762,10 +1819,20 @@ async fn set_password_via_chpasswd(mount: &str, input: &str) -> Result<(), Strin
|
||||
if !data.ends_with(b"\n") {
|
||||
data.push(b'\n');
|
||||
}
|
||||
|
||||
// 1. Veriyi tampon belleğe yaz
|
||||
stdin.write_all(&data).await
|
||||
.map_err(|e| format!("chpasswd stdin yazma hatası: {}", e))?;
|
||||
|
||||
// 2. KRİTİK EKSİK: Tampondaki veriyi chpasswd sürecine zorla gönder (Sıvazla)
|
||||
stdin.flush().await
|
||||
.map_err(|e| format!("chpasswd stdin flush hatası: {}", e))?;
|
||||
|
||||
// 3. Kanalı elinle kapatarak chpasswd'e "bitti" (EOF) sinyali yolla
|
||||
drop(stdin);
|
||||
}
|
||||
|
||||
// wait_with_output zaten arkada kalan süreçleri temizler ve çıktıları toplar
|
||||
let output = child.wait_with_output().await
|
||||
.map_err(|e| format!("chpasswd bekleme hatası: {}", e))?;
|
||||
|
||||
@@ -1774,7 +1841,7 @@ async fn set_password_via_chpasswd(mount: &str, input: &str) -> Result<(), Strin
|
||||
} else {
|
||||
Err(String::from_utf8_lossy(&output.stderr).trim().to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// fstab'ı doğrudan dosyaya yazar (genfstab yerine; ISO ortamında daha güvenilir).
|
||||
pub struct GenerateFstabJob {
|
||||
|
||||
Reference in New Issue
Block a user