X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dbus%2Fdbus-file-unix.c;h=197593362b7c6d3556889fac4801d92ef066ed36;hb=383f596c4aee2561c90abca3ce9d1f52407a3eec;hp=363a278a8d236691ac56f4dcf6ac06e418ee7b5d;hpb=e1c31c73074513d96fa22b5c0355107c42720597;p=platform%2Fupstream%2Fdbus.git diff --git a/dbus/dbus-file-unix.c b/dbus/dbus-file-unix.c index 363a278..1975933 100644 --- a/dbus/dbus-file-unix.c +++ b/dbus/dbus-file-unix.c @@ -156,12 +156,14 @@ _dbus_file_get_contents (DBusString *str, * * @param str the string to write out * @param filename the file to save string to + * @param world_readable If set, ensure the file is world readable * @param error error to be filled in on failure * @returns #FALSE on failure */ dbus_bool_t _dbus_string_save_to_file (const DBusString *str, const DBusString *filename, + dbus_bool_t world_readable, DBusError *error) { int fd; @@ -211,7 +213,7 @@ _dbus_string_save_to_file (const DBusString *str, tmp_filename_c = _dbus_string_get_const_data (&tmp_filename); fd = open (tmp_filename_c, O_WRONLY | O_BINARY | O_EXCL | O_CREAT, - 0600); + world_readable ? 0644 : 0600); if (fd < 0) { dbus_set_error (error, _dbus_error_from_errno (errno), @@ -219,6 +221,20 @@ _dbus_string_save_to_file (const DBusString *str, _dbus_strerror (errno)); goto out; } + if (world_readable) + { + /* Ensure the file is world readable even in the presence of + * possibly restrictive umasks; + * see http://lists.freedesktop.org/archives/dbus/2010-September/013367.html + */ + if (fchmod (fd, 0644) < 0) + { + dbus_set_error (error, _dbus_error_from_errno (errno), + "Could not chmod %s: %s", tmp_filename_c, + _dbus_strerror (errno)); + goto out; + } + } _dbus_verbose ("tmp file fd %d opened\n", fd);