5 sub supplemental_groups {
9 while (my @fields=getgrent()) {
10 if (grep { $_ eq $user } split(' ', $fields[3])) {
11 push @list, $fields[2];
22 if (! getpwnam("$user")) {
23 print STDERR "warning: user $user does not exist\n";
27 print STDERR "warning: $setup does not exist, skipping\n";
30 print "Processing $setup as user $user ...\n";
31 # su is not used because it passes arguments through the shell,
32 # which is not safe for untrusted setup file names.
33 defined(my $pid = fork) or die "Can’t fork: $!";
35 my ($uuid, $ugid) = (getpwnam($user))[2, 3];
36 my $grouplist=join(" ", $ugid, $ugid, supplemental_groups($user));
40 die "failed to set egid $grouplist: $!";
45 if ($< != $uuid || $> != $uuid || $( != $ugid) {
46 die "failed to drop permissions to $user";
50 HOME => (getpwnam($user))[7],
52 exec("ikiwiki", "-setup", $setup, @ARGV);
53 die "failed to run ikiwiki: $!";
57 print STDERR "Processing $setup as user $user failed with code $?\n";
66 open ($list, "<$file") || die "$file: $!";
71 next if /^#/ || ! length;
73 if (/^([^\s]+)\s+([^\s]+)$/) {
76 if (defined $forceuser && $forceuser ne $user) {
77 print STDERR "warning: in $file line $., attempt to set user to $user, but user forced to $forceuser. Skipping\n";
79 processline($user, $setup);
81 elsif (/^([^\s]+)$/) {
83 my $home=(getpwnam($user))[7];
84 if (defined $home && -d $home) {
85 my $dotfile="$home/.ikiwiki/wikilist";
87 processlist($dotfile, $user);
95 my $wikilist="/etc/ikiwiki/wikilist";
98 processlist($wikilist);