Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow chmod for non-root users #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stormshield-sylvaing
Copy link

Problem

We have a non-root program using a hybrid system for daemonisation, it must use the PID files created by Daemonize. The files need to be chowned to the user group, this is how it's made :

Daemonize::new()
        .pid_file("/path/to/file.pid")
        .chown_pid_file(true)
        .user(Uid::current().as_raw())
        .group("my_group_name")
        .umask(0o017); // Gives RW permissions to user and group

The program fails because it tries to setgid and setuid while it is run as non-root.

Solution

I added a boolean to skip setgid and setuid so we can run the program as non-root. By default, the boolean is set to true for retro-compatibility :

Daemonize::new()
        .pid_file("/path/to/file.pid")
        .chown_pid_file(true)
        .set_group_and_user_id(false) // Skip `setgid` and `setuid`, can be run as non-root
        .user(Uid::current().as_raw())
        .group("my_group_name")
        .umask(0o017);

Impact for existing code base

None. By default, daemonize works exactly the same.

@stormshield-sylvaing stormshield-sylvaing marked this pull request as ready for review November 23, 2023 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant