Set perms last, as changing UID breaks setuid
authorJamie Cameron <jcameron@webmin.com>
Tue, 24 Mar 2009 06:59:16 +0000 (06:59 +0000)
committerJamie Cameron <jcameron@webmin.com>
Tue, 24 Mar 2009 06:59:16 +0000 (06:59 +0000)
file/CHANGELOG
file/chmod.cgi

index 5670a29..75c63d7 100644 (file)
@@ -47,3 +47,5 @@ POSIX ACLs can now be edited on FreeBSD, if the setfacl and getfacl commands are
 Added a button to the compressed file extraction dialog to show the contents of a ZIP or tar file, instead of extracting it.
 ---- Changes since 1.460 ----
 Fixed bugs that broke the file manager under the new Webmin API module.
+---- Changes since 1.470 ----
+Fixed a bug that prevented setuid and setgid permissions from being changed.
index 914b5c1..3eab8ac 100755 (executable)
@@ -78,15 +78,15 @@ exit;
 sub update
 {
 local $perms = $in{'perms'};
+if (defined($uid)) {
+       chown($uid, $gid, $_[0]) || &failure(&text('chmod_echown', $!));
+       }
 if (defined($perms)) {
        if ($_[1]) {
                @st = stat($_[0]);
-               $perms = ($perms & 0777) | ($st[2] & 037777777000);
+               $perms = ($perms & 07777) | ($st[2] & 037777770000);
                }
        chmod($perms, $_[0]) || &failure(&text('chmod_echmod', $!));
        }
-if (defined($uid)) {
-       chown($uid, $gid, $_[0]) || &failure(&text('chmod_echown', $!));
-       }
 }