Commit 02759814 authored by Jorn Baayen's avatar Jorn Baayen
Browse files

fix #91319

parent 7628e66f
2002-10-30 Jorn Baayen <jorn@nl.linux.org>
* README:
Updated pointer to rb list.
* lib/rb-file-helpers.c: (have_uid), (have_gid),
(rb_uri_is_readable), (rb_uri_is_writable),
(rb_uri_handle_recursively):
* lib/rb-file-helpers.h:
Fix #91319, add functions for checking file read/writeability.
2002-10-29 Jorn Baayen <jorn@nl.linux.org>
* lib/widgets/rb-node-view.c: (rb_node_view_finalize):
......
......@@ -11,7 +11,7 @@ The official web site is:
http://www.rhythmbox.org/
Information about mailing lists can be found at:
http://lists.sourceforge.net/lists/listinfo/rhythmbox-devel
http://lists.gnome.org/mailman/listinfo/rhythmbox-devel
Our IRC channel is #rhythmbox on GIMPnet (irc.gimp.org).
......
......@@ -512,6 +512,79 @@ rb_uri_resolve_relative (const char *location)
return uri;
}
static gboolean
have_uid (guint uid)
{
return (uid == getuid ());
}
static gboolean
have_gid (guint gid)
{
gid_t gids[100];
int n_groups, i;
n_groups = getgroups (100, gids);
for (i = 0; i < n_groups; i++)
{
if (gids[i] == getegid ())
continue;
if (gids[i] == gid)
return TRUE;
}
return FALSE;
}
gboolean
rb_uri_is_readable (const char *text_uri)
{
GnomeVFSFileInfo *info;
gboolean ret = FALSE;
info = gnome_vfs_file_info_new ();
if (info == NULL)
return FALSE;
if (gnome_vfs_get_file_info (text_uri, info, GNOME_VFS_FILE_INFO_FOLLOW_LINKS) != GNOME_VFS_OK)
return FALSE;
if ((info->permissions & GNOME_VFS_PERM_OTHER_READ) ||
((info->permissions & GNOME_VFS_PERM_USER_READ) &&
(have_uid (info->uid) == TRUE)) ||
((info->permissions & GNOME_VFS_PERM_GROUP_READ) &&
(have_gid (info->gid) == TRUE)))
ret = TRUE;
gnome_vfs_file_info_unref (info);
return ret;
}
gboolean
rb_uri_is_writable (const char *text_uri)
{
GnomeVFSFileInfo *info;
gboolean ret = FALSE;
info = gnome_vfs_file_info_new ();
if (info == NULL)
return FALSE;
if (gnome_vfs_get_file_info (text_uri, info, GNOME_VFS_FILE_INFO_FOLLOW_LINKS) != GNOME_VFS_OK)
return FALSE;
if ((info->permissions & GNOME_VFS_PERM_OTHER_WRITE) ||
((info->permissions & GNOME_VFS_PERM_USER_WRITE) &&
(have_uid (info->uid) == TRUE)) ||
((info->permissions & GNOME_VFS_PERM_GROUP_WRITE) &&
(have_gid (info->gid) == TRUE)))
ret = TRUE;
gnome_vfs_file_info_unref (info);
return ret;
}
void
rb_uri_handle_recursively (const char *text_uri,
GFunc func,
......@@ -522,10 +595,11 @@ rb_uri_handle_recursively (const char *text_uri,
uri = gnome_vfs_uri_new (text_uri);
gnome_vfs_directory_list_load (&list, text_uri,
(GNOME_VFS_FILE_INFO_GET_MIME_TYPE |
GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE |
GNOME_VFS_FILE_INFO_FOLLOW_LINKS));
if (gnome_vfs_directory_list_load (&list, text_uri,
(GNOME_VFS_FILE_INFO_GET_MIME_TYPE |
GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE |
GNOME_VFS_FILE_INFO_FOLLOW_LINKS)) != GNOME_VFS_OK)
return;
for (l = list; l != NULL; l = g_list_next (l))
{
......@@ -534,7 +608,7 @@ rb_uri_handle_recursively (const char *text_uri,
char *file_uri_text;
info = (GnomeVFSFileInfo *) l->data;
file_uri = gnome_vfs_uri_append_path (uri, info->name);
if (file_uri == NULL)
continue;
......
......@@ -33,6 +33,8 @@ char *rb_uri_resolve_symlink (const char *uri);
gboolean rb_uri_is_directory (const char *uri);
gboolean rb_uri_exists (const char *uri);
char *rb_uri_resolve_relative (const char *uri);
gboolean rb_uri_is_readable (const char *uri);
gboolean rb_uri_is_writable (const char *uri);
void rb_uri_handle_recursively (const char *uri,
GFunc func,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment