2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-12 16:46:35 +00:00

Better setgid by Christopher

git-svn-id: https://svn.fhem.de/fhem/trunk@1204 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2012-01-22 12:21:05 +00:00
parent 1952f29a97
commit cf5fd30fa1
2 changed files with 21 additions and 9 deletions

View File

@ -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

View File

@ -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]);
}
}
###################################################