summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2004-07-15 04:13:35 (UTC)
committer Michael Krelin <hacker@klever.net>2004-07-15 04:13:35 (UTC)
commit5e437102c59f4544e3803598eabcb643d403272d (patch) (side-by-side diff)
tree7703657f2dac2fd9fb2b2a1f453ca2f30227efa1
parent4f8a6f291a231410a03c438bc9d63a7beb861e7b (diff)
downloaddudki-5e437102c59f4544e3803598eabcb643d403272d.zip
dudki-5e437102c59f4544e3803598eabcb643d403272d.tar.gz
dudki-5e437102c59f4544e3803598eabcb643d403272d.tar.bz2
initgroups() call added when changing uid
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--src/process.cc17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/process.cc b/src/process.cc
index fda35e8..bfab311 100644
--- a/src/process.cc
+++ b/src/process.cc
@@ -60,3 +60,4 @@ void process::check(const string& id,configuration& config) {
void process::launch(const string& id,configuration& config) {
- uid_t uid = 0;
+ uid_t uid = (uid_t)-1;
+ gid_t gid = (gid_t)-1;
if(!user.empty()) {
@@ -65,2 +66,3 @@ void process::launch(const string& id,configuration& config) {
uid = ptmp->pw_uid;
+ gid = ptmp->pw_gid;
}else{
@@ -72,3 +74,2 @@ void process::launch(const string& id,configuration& config) {
}
- gid_t gid = 0;
if(!group.empty()) {
@@ -91,2 +92,9 @@ void process::launch(const string& id,configuration& config) {
setsid();
+ if(user.empty()) {
+ if((getgid()!=gid) && setgid(gid))
+ throw runtime_error(string(__PRETTY_FUNCTION__)+": failed to setgid()");
+ }else{
+ if(initgroups(user.c_str(),gid))
+ throw runtime_error(string(__PRETTY_FUNCTION__)+": failed to initgroups()");
+ }
if(!chroot.empty()) {
@@ -95,7 +103,2 @@ void process::launch(const string& id,configuration& config) {
}
- if(!group.empty()) {
- // TODO: initgroups()?
- if((getgid()!=gid) && setgid(gid))
- throw runtime_error(string(__PRETTY_FUNCTION__)+": failed to setgid()");
- }
if(!user.empty()) {