3 # Change the ownership and permissions on a file
5 require './file-lib.pl';
6 $disallowed_buttons{'info'} && &error($text{'ebutton'});
8 &webmin_log($in{'linkto'} ? "relink" : "chmod", undef, $in{'path'}, \%in);
9 &switch_acl_uid_and_chroot();
10 print "Content-type: text/plain\n\n";
11 !$access{'ro'} && &can_access($in{'path'}) ||
12 &failure(&text('chmod_eaccess', $in{'path'}));
14 if (defined($in{'user'})) {
15 $uid = $in{'user'} =~ /^\d+$/ ? $in{'user'} :
16 defined(%user_to_uid) ? $user_to_uid{$in{'user'}} :
17 getpwnam($in{'user'});
18 &failure(&text('chmod_euser', $in{'user'})) if (!defined($uid));
19 $gid = $in{'group'} =~ /^\d+$/ ? $in{'group'} :
20 defined(%group_to_gid) ? $group_to_gid{$in{'group'}} :
21 getgrnam($in{'group'});
22 &failure(&text('chmod_egroup', $in{'group'})) if (!defined($gid));
26 # Just changing the link target
27 $follow && &failure($text{'chmod_efollow'});
28 &lock_file($in{'path'});
30 symlink($in{'linkto'}, $in{'path'}) ||
31 &failure(&text('chmod_elink', $1));
32 &unlock_file($in{'path'});
34 elsif ($in{'rec'} == 0) {
36 &update($in{'path'}, 0);
38 elsif ($in{'rec'} == 1) {
39 # This directory and all its files
40 &update($in{'path'}, 0);
41 opendir(DIR, $in{'path'});
42 foreach $f (readdir(DIR)) {
43 next if ($f eq "." || $f eq "..");
45 &update("$in{'path'}/$f", 1) if (!-d $full);
49 elsif ($in{'rec'} == 2) {
50 # Directory and all subdirectories
51 &update($in{'path'}, 0);
52 &recurse($in{'path'});
58 local(@files, $f, $full);
60 @files = readdir(DIR);
64 next if ($f eq "." || $f eq "..");
66 &update($full, !-d $full);
67 &recurse($full) if (-d $full);
77 # update(file, perms_only)
80 local $perms = $in{'perms'};
82 chown($uid, $gid, $_[0]) || &failure(&text('chmod_echown', $!));
84 if (defined($perms)) {
87 $perms = ($perms & 07777) | ($st[2] & 037777770000);
89 chmod($perms, $_[0]) || &failure(&text('chmod_echmod', $!));