[Bug 213538] KSaveFile loose gid permissions and guid on save (if the user is not owner or root)

stephane stephane.bouthors at gmail.com
Sat Nov 7 13:00:46 GMT 2009


https://bugs.kde.org/show_bug.cgi?id=213538





--- Comment #1 from stephane <stephane bouthors gmail com>  2009-11-07 14:00:43 ---
I have found the error:
in open function, fchown is used to uid and gid and permissions are set only on
success.
It can succeed only for root or if uid are the same (user and file). 
It explains the BUG.


Here is my fix proposal:


original code: (look in open)

115     // if we're overwriting an existing file, ensure temp file's
116     // permissions are the same as existing file so the existing
117     // file's permissions are preserved. this will succeed only if we
118     // are the same owner and group - or allmighty root.
119     QFileInfo fi ( d->realFileName );
120     if (fi.exists()) {
121         //Qt apparently has no way to change owner/group of file :(
122         if (!fchown(tempFile.handle(), fi.ownerId(), fi.groupId()))
123             tempFile.setPermissions(fi.permissions());
124     }
125     else {
126         mode_t umsk = KGlobal::umask();
127         fchmod(tempFile.handle(), 0666&(~umsk));
128     }


mine:

   QFileInfo fi ( d->realFileName );
    if (fi.exists())
    {
        // set permissions
        tempFile.setPermissions(fi.permissions());

        // Qt apparently has no way to change owner/group of file :(
        // try to set user and group (changing user may requiere root
privilege)
        if (fchown(tempFile.handle(), fi.ownerId(), fi.groupId()))
        {
            // failed to set user and group => try to restore group anyway
            fchown(tempFile.handle(), -1, fi.groupId());
        }
    }
    else {
        mode_t umsk = KGlobal::umask();
        fchmod(tempFile.handle(), 0666&(~umsk));
    }



=> may a better way should be to set separetly gid and uid.
Hope it helps!

-- 
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the Unassigned-bugs mailing list