Skip to content

Commit

Permalink
daemons: dropping privileges AFTER pid file creation
Browse files Browse the repository at this point in the history
  • Loading branch information
alaaeddineelamri committed Sep 22, 2021
1 parent 57abb93 commit c43af60
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions core/src/dird/dird.cc
Expand Up @@ -316,11 +316,6 @@ int main(int argc, char* argv[])
}
if (argc) { usage(); }

// See if we want to drop privs.
if (geteuid() == 0) {
drop(uid, gid, false); /* reduce privileges if requested */
}

if (export_config_schema) {
PoolMem buffer;

Expand Down Expand Up @@ -359,6 +354,11 @@ int main(int argc, char* argv[])
}
}

// See if we want to drop privs.
if (geteuid() == 0) {
drop(uid, gid, false); /* reduce privileges if requested */
}

if (InitCrypto() != 0) {
Jmsg((JobControlRecord*)nullptr, M_ERROR_TERM, 0,
_("Cryptography library initialization failed.\n"));
Expand Down
6 changes: 3 additions & 3 deletions core/src/filed/filed.cc
Expand Up @@ -201,9 +201,6 @@ int main(int argc, char* argv[])
Emsg0(M_ERROR_TERM, 0, _("-k option has no meaning without -u option.\n"));
}

// See if we want to drop privs.
if (geteuid() == 0) { drop(uid, gid, keep_readall_caps); }

if (!no_signals) {
InitSignals(TerminateFiled);
} else {
Expand Down Expand Up @@ -246,6 +243,9 @@ int main(int argc, char* argv[])
InitStackDump(); /* set new pid */
}

// See if we want to drop privs.
if (geteuid() == 0) { drop(uid, gid, keep_readall_caps); }

if (InitCrypto() != 0) {
Emsg0(M_ERROR, 0, _("Cryptography library initialization failed.\n"));
TerminateFiled(1);
Expand Down
6 changes: 3 additions & 3 deletions core/src/stored/stored.cc
Expand Up @@ -232,9 +232,6 @@ int main(int argc, char* argv[])
}
if (argc) { usage(); }

// See if we want to drop privs.
if (geteuid() == 0) { drop(uid, gid, false); }

if (export_config_schema) {
PoolMem buffer;

Expand Down Expand Up @@ -276,6 +273,9 @@ int main(int argc, char* argv[])
InitStackDump(); /* pick up new pid */
}

// See if we want to drop privs.
if (geteuid() == 0) { drop(uid, gid, false); }

if (InitCrypto() != 0) {
Jmsg((JobControlRecord*)nullptr, M_ERROR_TERM, 0,
_("Cryptography library initialization failed.\n"));
Expand Down

0 comments on commit c43af60

Please sign in to comment.