KSaveFile not keeping mode, uid and gid!

Waldo Bastian bastian at kde.org
Fri Jul 23 21:43:47 BST 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Friday 23 July 2004 17:43, Reinhold Kainhofer wrote:
> Hi,
> In KOrganizer (where we use KSaveFile when saving local files) we have the
> problem that the mode, the uid and gid of a file are not retained if uid
> and gid of the file are not the uid and gid of the user.
>
> For example, I (user reinhold, group reinhold) have a file
> -rw-------  1 reinhold reinhold  397 2004-07-23 17:31 tt.ics
> If I use KSaveFile to save something to tt.ics, the 600 mode is kept.
>
> Now, if I have a file
> -rw-------  1 reinhold users     397 2004-07-23 17:31 tt.ics
> then using KSaveFile reverts the file's permissions to 644, user reinhold,
> group reinhold.
>
> This is of course caused by the check
>           (stat_buf.st_uid == getuid())
>           && (stat_buf.st_gid == getgid()))
> in lines 73/74 of ksavefile.cpp. This assumes that the user is only able to
> write to files that have his own uid and gid set, but neglect the fact that
> he might be allowed to write to other files, which for example might be
> group- or even world-writable, but do not belong to the user.

The semantics of KSaveFile are such that it replaces the original file, so by 
definition the new file will be owned by the user. KConfig opens / truncates 
the original file in case the file wasn't owned by the user but KSaveFile 
can't do that because KSaveFile supports "abort" which is supposed to leave 
the original file intact and that is rather hard to do after we truncated it.

It could try a little harder to restore the group though.

Cheers,
Waldo
- -- 
bastian at kde.org  |   KDE Community World Summit 2004  |  bastian at suse.com
bastian at kde.org  | 21-29 August, Ludwigsburg, Germany |  bastian at suse.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFBAXiDN4pvrENfboIRAkASAJ43xBvknXBwkORly5efYLLgk86a4wCeLxJ6
RsKgwLW0W7pBHqFcXJdl644=
=6Oox
-----END PGP SIGNATURE-----




More information about the kde-core-devel mailing list