Skip to content

Commit 599be48

Browse files
committed
Modify socket path to conform to FHS
Unix domain sockets should be in /run/. Signed-off-by: Hugues de Valon <[email protected]>
1 parent 2a57277 commit 599be48

File tree

2 files changed

+3
-47
lines changed

2 files changed

+3
-47
lines changed

e2e_tests/src/raw_request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const MAX_BODY_SIZE: usize = 1 << 31;
1313
#[derive(Copy, Clone, Debug)]
1414
pub struct RawRequestClient;
1515

16-
static SOCKET_PATH: &str = "/tmp/parsec/parsec.sock";
16+
static SOCKET_PATH: &str = "/run/parsec/parsec.sock";
1717
const TIMEOUT: Duration = Duration::from_secs(5);
1818

1919
#[allow(clippy::new_without_default)]

src/front/domain_socket.rs

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::os::unix::net::UnixListener;
1919
use std::path::Path;
2020
use std::time::Duration;
2121

22-
static SOCKET_PATH: &str = "/tmp/parsec/parsec.sock";
22+
static SOCKET_PATH: &str = "/run/parsec/parsec.sock";
2323
#[cfg(not(feature = "no-parsec-user-and-clients-group"))]
2424
const PARSEC_USERNAME: &str = "parsec";
2525
#[cfg(not(feature = "no-parsec-user-and-clients-group"))]
@@ -42,11 +42,8 @@ impl DomainSocketListener {
4242
#[cfg(not(feature = "no-parsec-user-and-clients-group"))]
4343
DomainSocketListener::check_user_details()?;
4444

45-
// is Parsec instance was socket activated (see the `parsec.socket`
46-
// file), the listener will be opened by systemd and passed to the
47-
// process.
4845
// If Parsec was service activated or not started under systemd, this
49-
// will return `0`.
46+
// will return `0`. `1` will be returned in case Parsec is socket activated.
5047
let listener = match sd_notify::listen_fds()? {
5148
0 => {
5249
let socket = Path::new(SOCKET_PATH);
@@ -56,8 +53,6 @@ impl DomainSocketListener {
5653
} else if socket.exists() {
5754
fs::remove_file(&socket)?;
5855
}
59-
#[cfg(not(feature = "no-parsec-user-and-clients-group"))]
60-
DomainSocketListener::set_socket_dir_permissions(parent_dir)?;
6156

6257
let listener = UnixListener::bind(SOCKET_PATH)?;
6358
listener.set_nonblocking(true)?;
@@ -93,45 +88,6 @@ impl DomainSocketListener {
9388
Ok(Self { listener, timeout })
9489
}
9590

96-
#[cfg(not(feature = "no-parsec-user-and-clients-group"))]
97-
fn set_socket_dir_permissions(parent_dir: &Path) -> Result<()> {
98-
if let Some(parent_dir_str) = parent_dir.to_str() {
99-
fs::set_permissions(parent_dir, Permissions::from_mode(0o750))?;
100-
// Although `parsec` has to be part of the `parsec_clients` group, it may not be the primary group. Therefore force group ownership to `parsec_clients`
101-
if unsafe {
102-
let parent_dir_cstr = CString::new(parent_dir_str)
103-
.expect("Failed to convert socket path parent to cstring");
104-
{
105-
libc::chown(
106-
parent_dir_cstr.as_ptr(),
107-
users::get_current_uid(), // To get to this point, user has to be `parsec`
108-
users::get_group_by_name(PARSEC_GROUPNAME).unwrap().gid(), // `parsec_clients` exists by this point so should be safe
109-
)
110-
}
111-
} != 0
112-
{
113-
error!(
114-
"Changing ownership of {} to user {} and group {} failed.",
115-
parent_dir_str, PARSEC_USERNAME, PARSEC_GROUPNAME
116-
);
117-
return Err(Error::new(
118-
ErrorKind::Other,
119-
"Changing ownership of socket directory failed",
120-
));
121-
}
122-
} else {
123-
error!(
124-
"Error converting {} parent directory to string.",
125-
SOCKET_PATH
126-
);
127-
return Err(Error::new(
128-
ErrorKind::InvalidInput,
129-
"Error retrieving parent directory for socket",
130-
));
131-
}
132-
Ok(())
133-
}
134-
13591
#[cfg(not(feature = "no-parsec-user-and-clients-group"))]
13692
fn check_user_details() -> Result<()> {
13793
// Check Parsec is running as parsec user

0 commit comments

Comments
 (0)