diff --git a/ChangeLog b/ChangeLog index e34b46a50e10fa8050260f637fa0e391ba80858e..2785d8efbe7eb0458c06158bf82c31ee51c3c229 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2006-01-31 Benedikt Meurer <benny@xfce.org> + + * thunar/thunar-standard-view.c: Disable the "create-document" action + on non-writable folders. + * thunar-vfs/thunar-vfs-scandir.c: Return an error when trying to scan + a directory for which the user has no execute permissions. Bug #1408. + * thunar/thunar-file.c(thunar_file_get_emblem_names): Add "cant-read" + emblem to folders, where we don't have permissions to enter. Second + part of fix for bug #1408. + 2006-01-31 Benedikt Meurer <benny@xfce.org> * thunar-vfs/thunar-vfs-info.c: Treat .desktop files of Type=Link as diff --git a/thunar-vfs/thunar-vfs-scandir.c b/thunar-vfs/thunar-vfs-scandir.c index 15a9330f3b3baff4acd2868d3abaa9eb42b00847..1684a7f42df30aa9f8ffd3b3035caea81ad38341 100644 --- a/thunar-vfs/thunar-vfs-scandir.c +++ b/thunar-vfs/thunar-vfs-scandir.c @@ -1,6 +1,6 @@ /* $Id$ */ /*- - * Copyright (c) 2005 Benedikt Meurer <benny@xfce.org> + * Copyright (c) 2005-2006 Benedikt Meurer <benny@xfce.org> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -138,6 +138,17 @@ thunar_vfs_scandir_collect_fast (ThunarVfsScandirHandle *handle, goto done; } + /* verify that we can enter the directory (else + * we won't get any useful infos about the dir + * contents either, so no need to continue). See + * http://bugzilla.xfce.org/show_bug.cgi?id=1408. + */ + if ((statb.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != (S_IXUSR | S_IXGRP | S_IXOTH) && (access (handle->fname, X_OK) < 0)) + { + errno = EACCES; + goto done; + } + /* calculate the directory buffer size */ dlen = statb.st_blksize * 4; if (G_UNLIKELY ((dlen % DIRBLKSIZ) != 0)) @@ -253,6 +264,7 @@ thunar_vfs_scandir_collect_slow (ThunarVfsScandirHandle *handle, ThunarVfsPath *child; struct dirent dbuf; struct dirent *dp; + struct stat fstatb; gint sverrno; gint n; DIR *dirp; @@ -264,6 +276,10 @@ thunar_vfs_scandir_collect_slow (ThunarVfsScandirHandle *handle, if (G_UNLIKELY (dirp == NULL)) return FALSE; + /* stat the just opened directory */ + if (fstat (dirfd (dirp), &fstatb) < 0) + goto error; + /* verify that the directory is really the directory we want * to open. If not, we've probably detected a race condition, * so we'll better stop rather than doing anything stupid @@ -272,13 +288,8 @@ thunar_vfs_scandir_collect_slow (ThunarVfsScandirHandle *handle, */ if (G_UNLIKELY ((handle->flags & THUNAR_VFS_SCANDIR_FOLLOW_LINKS) == 0)) { - struct stat fstatb; struct stat lstatb; - /* stat the just opened directory */ - if (fstat (dirfd (dirp), &fstatb) < 0) - goto error; - /* stat the path (without following links) */ if (lstat (handle->fname, &lstatb) < 0) goto error; @@ -291,6 +302,17 @@ thunar_vfs_scandir_collect_slow (ThunarVfsScandirHandle *handle, } } + /* verify that we can enter the directory (else + * we won't get any useful infos about the dir + * contents either, so no need to continue). See + * http://bugzilla.xfce.org/show_bug.cgi?id=1408. + */ + if ((fstatb.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != (S_IXUSR | S_IXGRP | S_IXOTH) && (access (handle->fname, X_OK) < 0)) + { + errno = EACCES; + goto error; + } + /* read the directory content */ for (;;) { diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 3a56e27c5f2b8423e389f292792ca0aca4b51b36..bcffb89df21a362d7f8a6e33fc304782a663b582 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -1488,8 +1488,17 @@ thunar_file_get_emblem_names (ThunarFile *file) if ((info->flags & THUNAR_VFS_FILE_FLAGS_SYMLINK) != 0) emblems = g_list_prepend (emblems, THUNAR_FILE_EMBLEM_NAME_SYMBOLIC_LINK); - if (!thunar_file_is_readable (file)) - emblems = g_list_prepend (emblems, THUNAR_FILE_EMBLEM_NAME_CANT_READ); + /* we add "cant-read" if either (a) the file is not readable or (b) a directory, that lacks the + * x-bit, see http://bugzilla.xfce.org/show_bug.cgi?id=1408 for the details about this change. + */ + if (!thunar_file_is_readable (file) + || (thunar_file_is_directory (file) + && thunar_file_denies_access_permission (file, THUNAR_VFS_FILE_MODE_USR_EXEC, + THUNAR_VFS_FILE_MODE_GRP_EXEC, + THUNAR_VFS_FILE_MODE_OTH_EXEC))) + { + emblems = g_list_prepend (emblems, THUNAR_FILE_EMBLEM_NAME_CANT_READ); + } return emblems; } diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index 0e498f677d0c76c0fd05361edd1814b29cd8ad92..fc45dd4d6366f944e41c10b78223edb4c936ecf6 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -229,6 +229,7 @@ struct _ThunarStandardViewPrivate { ThunarLauncher *launcher; GtkAction *action_create_folder; + GtkAction *action_create_document; GtkAction *action_properties; GtkAction *action_copy; GtkAction *action_cut; @@ -460,8 +461,6 @@ thunar_standard_view_view_init (ThunarViewIface *iface) static void thunar_standard_view_init (ThunarStandardView *standard_view) { - GtkAction *action; - standard_view->priv = THUNAR_STANDARD_VIEW_GET_PRIVATE (standard_view); standard_view->priv->drag_timer_id = -1; @@ -501,11 +500,13 @@ thunar_standard_view_init (ThunarStandardView *standard_view) standard_view->priv->action_rename = gtk_action_group_get_action (standard_view->action_group, "rename"); /* add the "Create Document" sub menu action */ - action = thunar_templates_action_new ("create-document", _("Create _Document")); - g_signal_connect (G_OBJECT (action), "create-empty-file", G_CALLBACK (thunar_standard_view_action_create_empty_file), standard_view); - g_signal_connect (G_OBJECT (action), "create-template", G_CALLBACK (thunar_standard_view_action_create_template), standard_view); - gtk_action_group_add_action (standard_view->action_group, action); - g_object_unref (G_OBJECT (action)); + standard_view->priv->action_create_document = thunar_templates_action_new ("create-document", _("Create _Document")); + g_signal_connect (G_OBJECT (standard_view->priv->action_create_document), "create-empty-file", + G_CALLBACK (thunar_standard_view_action_create_empty_file), standard_view); + g_signal_connect (G_OBJECT (standard_view->priv->action_create_document), "create-template", + G_CALLBACK (thunar_standard_view_action_create_template), standard_view); + gtk_action_group_add_action (standard_view->action_group, standard_view->priv->action_create_document); + g_object_unref (G_OBJECT (standard_view->priv->action_create_document)); /* setup the list model */ standard_view->model = thunar_list_model_new (); @@ -2806,8 +2807,9 @@ thunar_standard_view_selection_changed (ThunarStandardView *standard_view) && thunar_file_is_directory (selected_files->data) && thunar_file_is_writable (selected_files->data); - /* update the "Create Folder" action */ + /* update the "Create Folder"/"Create Document" actions */ gtk_action_set_sensitive (standard_view->priv->action_create_folder, writable); + gtk_action_set_sensitive (standard_view->priv->action_create_document, writable); /* update the "Properties" action */ gtk_action_set_sensitive (standard_view->priv->action_properties, (n_selected_files == 1 || (n_selected_files == 0 && current_directory != NULL)));