Skip to content

Commit 085014e

Browse files
committed
Fix locate confd
1 parent 783b48b commit 085014e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

rasp/librasp/src/php.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::process::Command;
33
use crate::process::ProcessInfo;
44
use procfs::process::Process;
55
use anyhow::{anyhow, Result as AnyhowResult};
6+
use fs_extra::dir::DirEntryAttr::Path;
67
use libc::{kill, pid_t, SIGUSR2};
78
use regex::Regex;
89
use crate::settings::RASP_PHP_PROBE;
@@ -188,7 +189,7 @@ fn search_maps(process: &Process) -> AnyhowResult<Option<String>> {
188189
}
189190

190191
fn search_argv(process: &Process) -> AnyhowResult<Option<String>> {
191-
let raw_fpm_regex = Regex::new(r"/.+php.+\.conf")?;
192+
let regex = Regex::new(r"/.+php.+\.conf")?;
192193
let cmdlines = process.cmdline()?;
193194
for cmdline in cmdlines.iter() {
194195
if let Some(caps) = regex.captures(cmdline) {
@@ -212,15 +213,16 @@ pub fn locate_extension_dir(process: &Process) -> AnyhowResult<String> {
212213
}
213214

214215
pub fn locate_confd_dir(process: &Process) -> AnyhowResult<String> {
216+
let root_dir = PathBuf::from(format!("/proc/{}/root/", process.pid));
215217
if let Some(conf) = search_argv(process)? {
216218
if let Some(confp) = PathBuf::from(conf).parent() {
217219
let confd = confp.join("conf.d");
218-
if confd.exists() {
220+
if root_dir.join(confd.as_path()).exists() {
219221
return Ok(String::from(confd.to_str().unwrap()));
220222
}
221223
if let Some(confpp) = PathBuf::from(confp).parent() {
222224
let confd = confpp.join("conf.d");
223-
if confd.exists() {
225+
if root_dir.join(confd.as_path()).exists() {
224226
return Ok(String::from(confd.to_str().unwrap()));
225227
}
226228
}

0 commit comments

Comments
 (0)