[OTR-dev] pidgin-otr: mode 600 instead of 644

Caspar Clemens Mierau damokles@ubuntu.com
Tue, 17 Jun 2008 23:17:14 +0200


--zjcmjzIkjQU2rmur
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

> > Actually I even think that you are already fine using g_fopen under
> > Win32, but somebody needs to confirm this.
>=20
> But there's no equivalent for umask, right?

Right. On Windows there is POSIX umask equivalent. There only exists a
readonly flag which poorly acts like a 444 mode. Glib therefore mostly
seems to ignore umask calls and only tries to set "readonly" when it
seems equivalent to the current umask.

If we want to be totally safe, we should check the platform and don't
call the umask when on Win32. Otherwise trusting glib documentation
actually prevents us from writing more code than actually necessary.

Let's have a look at g_chmod in glib:



-------snip------
/**
 * g_chmod:
 * @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
 * @mode: as in chmod()
 *
 * A wrapper for the POSIX chmod() function. The chmod() function is
 * used to set the permissions of a file system object. Note that on
 * Windows the file protection mechanism is not at all POSIX-like, and
 * the underlying chmod() function in the C library just sets or
 * clears the READONLY attribute. It does not touch any ACL. Software
 * that needs to manage file permissions on Windows exactly should
 * use the Win32 API.
 *
 * See the C library manual for more details about chmod().
 *
 * Returns: zero if the operation succeeded, -1 on error.
 *=20
 * Since: 2.8
 */
int
g_chmod (const gchar *filename,
         int          mode)
{
#ifdef G_OS_WIN32
  wchar_t *wfilename =3D g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
  int retval;
  int save_errno;
   =20
  if (wfilename =3D=3D NULL)
    {
      errno =3D EINVAL;
      return -1;
    }

  retval =3D _wchmod (wfilename, mode);
  save_errno =3D errno;

  g_free (wfilename);

  errno =3D save_errno;
  return retval;
#else
  return chmod (filename, mode);
#endif
}
-------snap------

Note: This has been introduced in glib 2.8 and would therefore increase
the current minimum glib version from 2.6 to 2.8.


Best,


Caspar Clemens Mierau






--=20
Caspar Clemens Mierau
 Dipl.-Kult. (Medien)
 official "Ubuntu member"
 ubuntu Deutschland e.V.
 Ubuntu Berlin
 c-base e.V.


--zjcmjzIkjQU2rmur
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIWCnadbVIHJiaHn8RAux2AKCEn31oCXYZ8Uk/ObCAhrtnR+XpmwCgkK/v
8ivOtXXBq3jyWrBxL2f6/aQ=
=L7Cw
-----END PGP SIGNATURE-----

--zjcmjzIkjQU2rmur--