diff --git a/fhem/CHANGED b/fhem/CHANGED index 28835cb40..2f4480d7b 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -3,8 +3,8 @@ - feature: the usb command tries to flash unflashed CULs on linux - feature: FHEMWEB: jsonp support, .holiday and .cfg added to Edit Files - feature: SVG: filled area support, some ls/lw fixes - - feature: WOL (wake on lan) module added - + - feature: WOL (wake on lan) module added (by Matthias) + - feature: additional groups from /etc/groups are applied (Christopher) - 2011-12-31 (5.2) - bugfix: applying smallscreen attributes to firefox/opera diff --git a/fhem/fhem.pl b/fhem/fhem.pl index fee4dc813..410b2b80d 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -253,17 +253,29 @@ if(int(@ARGV) != 1 && int(@ARGV) != 2) { # If started as root, and there is a fhem user in the /etc/passwd, su to it if($^O !~ m/Win/ && $< == 0) { - my @gr = getgrnam("dialout"); - if(@gr) { - use POSIX qw(setgid); - setgid($gr[2]); - } - my @pw = getpwnam("fhem"); if(@pw) { - use POSIX qw(setuid); + use POSIX qw(setuid setgid); + + # set primary group + setgid($pw[3]); + + # read all secondary groups into an array: + my @groups; + while ( my ($name, $pw, $gid, $members) = getgrent() ) { + push(@groups, $gid) if ( grep($_ eq $pw[0],split(/\s+/,$members)) ); + } + + # set the secondary groups via $) + if (@groups) { + $) = "$pw[3] ".join(" ",@groups); + } else { + $) = "$pw[3] $pw[3]"; + } + setuid($pw[2]); } + } ###################################################