Re: [PATCH] Determine access rights to files by GNOME_VFS_FILE_INFO_FIELDS_ACCESS



On Fr, 2005-12-09 at 12:44 +0100, Alexander Larsson wrote:
> On Thu, 2005-12-01 at 15:22 +0100, Christian Neumair wrote:
> > Christian Kellner asked me to improve and submit a patch to this list
> > that makes Nautilus use GNOME_VFS_FILE_INFO_FIELDS_ACCESS for
> > determining file permissions.
> > I've also attached a patch that makes gnome_vfs_file_info_matches check
> > for valid_fields being identical, since this can make client
> > applications assume that two file infos match where they don't, and
> > Nautilus uses it.
> > 
> > OK to commit?

> No need to pass this in mime_list_load.
> (...)
> I think "and" semantics is better, so this should be:
> (file->details->info->permissions & permissions) != permissions

Attaching new patch.

-- 
Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-desktop-icon-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-desktop-icon-file.c,v
retrieving revision 1.6
diff -u -p -r1.6 nautilus-desktop-icon-file.c
--- libnautilus-private/nautilus-desktop-icon-file.c	22 Feb 2005 10:41:46 -0000	1.6
+++ libnautilus-private/nautilus-desktop-icon-file.c	9 Dec 2005 14:44:11 -0000
@@ -204,13 +204,16 @@ update_info_from_link (NautilusDesktopIc
 		GNOME_VFS_PERM_GROUP_WRITE |
 		GNOME_VFS_PERM_USER_READ |
 		GNOME_VFS_PERM_OTHER_READ |
-		GNOME_VFS_PERM_GROUP_READ;
+		GNOME_VFS_PERM_GROUP_READ |
+		GNOME_VFS_PERM_ACCESS_READABLE |
+		GNOME_VFS_PERM_ACCESS_WRITABLE;
 	
 	file_info->valid_fields = GNOME_VFS_FILE_INFO_FIELDS_TYPE |
 		GNOME_VFS_FILE_INFO_FIELDS_FLAGS |
 		GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE |
 		GNOME_VFS_FILE_INFO_FIELDS_SIZE |
 		GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS |
+		GNOME_VFS_FILE_INFO_FIELDS_ACCESS |
 		GNOME_VFS_FILE_INFO_FIELDS_LINK_COUNT;
 
 	volume = nautilus_desktop_link_get_volume (link);
Index: libnautilus-private/nautilus-directory-async.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory-async.c,v
retrieving revision 1.216
diff -u -p -r1.216 nautilus-directory-async.c
--- libnautilus-private/nautilus-directory-async.c	6 Sep 2005 15:12:46 -0000	1.216
+++ libnautilus-private/nautilus-directory-async.c	9 Dec 2005 14:44:13 -0000
@@ -1476,7 +1476,8 @@ nautilus_directory_get_info_for_new_file
 		(&handle,
 		 vfs_uri_list,
 		 (GNOME_VFS_FILE_INFO_GET_MIME_TYPE
-		  | GNOME_VFS_FILE_INFO_FOLLOW_LINKS),
+		  | GNOME_VFS_FILE_INFO_FOLLOW_LINKS
+		  | GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS),
 		 GNOME_VFS_PRIORITY_DEFAULT,
 		 new_files_callback,
 		 directory);
@@ -1996,7 +1997,8 @@ start_monitoring_file_list (NautilusDire
 		(&directory->details->directory_load_in_progress, /* handle */
 		 directory->details->uri,                         /* uri */
 		 (GNOME_VFS_FILE_INFO_GET_MIME_TYPE	          /* options */
-		  | GNOME_VFS_FILE_INFO_FOLLOW_LINKS),
+		  | GNOME_VFS_FILE_INFO_FOLLOW_LINKS
+		  | GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS),
 		 DIRECTORY_LOAD_ITEMS_PER_CALLBACK,               /* items_per_notification */
 		 GNOME_VFS_PRIORITY_DEFAULT,
 		 directory_load_callback,                         /* callback */
@@ -2808,7 +2810,8 @@ file_info_start (NautilusDirectory *dire
 	fake_list.next = NULL;
 
 	options = GNOME_VFS_FILE_INFO_GET_MIME_TYPE
-		| GNOME_VFS_FILE_INFO_FOLLOW_LINKS;
+		| GNOME_VFS_FILE_INFO_FOLLOW_LINKS
+		| GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS;
 	if (need_slow_mime) {
 		options |= GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE;
 	}
Index: libnautilus-private/nautilus-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.c,v
retrieving revision 1.375
diff -u -p -r1.375 nautilus-file.c
--- libnautilus-private/nautilus-file.c	24 Nov 2005 10:49:19 -0000	1.375
+++ libnautilus-private/nautilus-file.c	9 Dec 2005 14:44:16 -0000
@@ -612,48 +612,6 @@ nautilus_file_get_parent (NautilusFile *
 	return nautilus_directory_get_corresponding_file (file->details->directory);
 }
 
-struct NautilusUserInfo {
-	uid_t user_id;
-	
-	gboolean has_primary_group;
-	gid_t primary_group;
-	
-	int num_supplementary_groups;
-	gid_t supplementary_groups[NGROUPS_MAX];
-};
-
-/* Returns a pointer to the cached info, does not need freeing */
-static struct NautilusUserInfo *
-nautilus_file_get_user_info (void)
-{
-	static struct timeval cached_time;
-	static struct NautilusUserInfo info;
-	static gboolean has_cached_info = FALSE;
-	struct passwd *password_info;
-	struct timeval now;
-
-	gettimeofday (&now, NULL);
-	
-	if (!has_cached_info ||
-	    ((now.tv_sec - cached_time.tv_sec) > GETPWUID_CACHE_TIME)) {
-		cached_time = now;
-		has_cached_info = TRUE;
-
-		info.user_id = geteuid ();
-		
-		info.has_primary_group = FALSE;
-		/* No need to free result of getpwuid. */
-		password_info = getpwuid (info.user_id);
-		if (password_info) {
-			info.has_primary_group = TRUE;
-			info.primary_group = password_info->pw_gid;
-		}
-		info.num_supplementary_groups = getgroups (NGROUPS_MAX, info.supplementary_groups);
-	}
-
-	return &info;
-}
-
 /**
  * nautilus_file_denies_access_permission:
  * 
@@ -662,9 +620,9 @@ nautilus_file_get_user_info (void)
  * returns FALSE if permissions cannot be determined.
  * 
  * @file: The file to check.
- * @owner_permission: The USER version of the permission (e.g. GNOME_VFS_PERM_USER_READ).
- * @group_permission: The GROUP version of the permission (e.g. GNOME_VFS_PERM_GROUP_READ).
- * @other_permission: The OTHER version of the permission (e.g. GNOME_VFS_PERM_OTHER_READ).
+ * @permissions: The permissions to check. Must be either
+ * GNOME_VFS_PERM_ACCESS_READABLE, GNOME_VFS_PERM_ACCESS_WRITABLE,
+ * GNOME_VFS_PERM_ACCESS_EXECUTABLE
  * 
  * Return value: TRUE if the current user definitely does not have
  * the specified permission. FALSE if the current user does have
@@ -672,15 +630,13 @@ nautilus_file_get_user_info (void)
  */
 static gboolean
 nautilus_file_denies_access_permission (NautilusFile *file, 
-				        GnomeVFSFilePermissions owner_permission,
-				        GnomeVFSFilePermissions group_permission,
-				        GnomeVFSFilePermissions other_permission)
+				        GnomeVFSFilePermissions permissions)
 {
-	struct NautilusUserInfo *user_info;
-	int i;
-
 	g_assert (NAUTILUS_IS_FILE (file));
-
+	g_assert (permissions & (GNOME_VFS_PERM_ACCESS_READABLE |
+				 GNOME_VFS_PERM_ACCESS_WRITABLE |
+				 GNOME_VFS_PERM_ACCESS_EXECUTABLE));
+	
 	/* Once the file is gone, you are denied permission to do anything. */
 	if (nautilus_file_is_gone (file)) {
 		return TRUE;
@@ -692,45 +648,8 @@ nautilus_file_denies_access_permission (
 	if (!nautilus_file_can_get_permissions (file)) {
 		return FALSE;
 	}
-
-	/* This is called often. Cache the user information for five minutes */
-
-	user_info = nautilus_file_get_user_info ();
-
-	/* Check the user. */
 	
-	/* Root is not forbidden to do anything. */
-	if (user_info->user_id == 0) {
-		return FALSE;
-	}
-
-	/* File owner's access is governed by the owner bits. */
-	/* FIXME bugzilla.gnome.org 40644: 
-	 * Can we trust the uid in the file info? Might
-	 * there be garbage there? What will it do for non-local files?
-	 */
-	if (user_info->user_id == (uid_t) file->details->info->uid) {
-		return (file->details->info->permissions & owner_permission) == 0;
-	}
-
-
-	/* Group member's access is governed by the group bits. */
-	/* FIXME bugzilla.gnome.org 40644: 
-	 * Can we trust the gid in the file info? Might
-	 * there be garbage there? What will it do for non-local files?
-	 */
-	if (user_info->has_primary_group
-	    && user_info->primary_group == (gid_t) file->details->info->gid) {
-		return (file->details->info->permissions & group_permission) == 0;
-	}
-	/* Check supplementary groups */
-	for (i = 0; i < user_info->num_supplementary_groups; i++) {
-		if ((gid_t) file->details->info->gid == user_info->supplementary_groups[i]) {
-			return (file->details->info->permissions & group_permission) == 0;
-		}
-	}
-	/* Other users' access is governed by the other bits. */
-	return (file->details->info->permissions & other_permission) == 0;
+	return (file->details->info->permissions & permissions) != permissions;
 }
 
 /**
@@ -751,10 +670,7 @@ nautilus_file_can_read (NautilusFile *fi
 	g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
 
 	return !nautilus_file_denies_access_permission
-		(file,
-		 GNOME_VFS_PERM_USER_READ,
-		 GNOME_VFS_PERM_GROUP_READ,
-		 GNOME_VFS_PERM_OTHER_READ);
+		(file, GNOME_VFS_PERM_ACCESS_READABLE);
 }
 
 /**
@@ -775,10 +691,7 @@ nautilus_file_can_write (NautilusFile *f
 	g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
 
 	return !nautilus_file_denies_access_permission
-		(file, 
-		 GNOME_VFS_PERM_USER_WRITE,
-		 GNOME_VFS_PERM_GROUP_WRITE,
-		 GNOME_VFS_PERM_OTHER_WRITE);
+		(file, GNOME_VFS_PERM_ACCESS_WRITABLE);
 }
 
 /**
@@ -799,10 +712,7 @@ nautilus_file_can_execute (NautilusFile 
 	g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
 
 	return !nautilus_file_denies_access_permission
-		(file, 
-		 GNOME_VFS_PERM_USER_EXEC,
-		 GNOME_VFS_PERM_GROUP_EXEC,
-		 GNOME_VFS_PERM_OTHER_EXEC);
+		(file, GNOME_VFS_PERM_ACCESS_EXECUTABLE);
 }
 
 /**
@@ -3425,7 +3335,7 @@ nautilus_file_get_size (NautilusFile *fi
 gboolean
 nautilus_file_can_get_permissions (NautilusFile *file)
 {
-	return !nautilus_file_info_missing (file, GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS);
+	return !nautilus_file_info_missing (file, GNOME_VFS_FILE_INFO_FIELDS_ACCESS);
 }
 
 /**
@@ -3540,7 +3450,8 @@ nautilus_file_set_permissions (NautilusF
 	op->use_slow_mime = file->details->got_slow_mime_type;
 
 	options = GNOME_VFS_FILE_INFO_GET_MIME_TYPE
-		| GNOME_VFS_FILE_INFO_FOLLOW_LINKS;
+		| GNOME_VFS_FILE_INFO_FOLLOW_LINKS
+		| GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS;
 	if (op->use_slow_mime) {
 		options |= GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE;
 	}
@@ -3725,11 +3636,7 @@ gboolean
 nautilus_file_can_get_owner (NautilusFile *file)
 {
 	/* Before we have info on a file, the owner is unknown. */
-	/* FIXME bugzilla.gnome.org 40644: 
-	 * Can we trust the uid in the file info? Might
-	 * there be garbage there? What will it do for non-local files?
-	 */
-	return !nautilus_file_info_missing (file, 0 /* FIXME bugzilla.gnome.org 40644: GNOME_VFS_FILE_INFO_FIELDS_UID */);
+	return !nautilus_file_info_missing (file, GNOME_VFS_FILE_INFO_FIELDS_IDS);
 }
 
 /**
@@ -3948,11 +3855,7 @@ gboolean
 nautilus_file_can_get_group (NautilusFile *file)
 {
 	/* Before we have info on a file, the group is unknown. */
-	/* FIXME bugzilla.gnome.org 40644: 
-	 * Can we trust the gid in the file info? Might
-	 * there be garbage there? What will it do for non-local files?
-	 */
-	return !nautilus_file_info_missing (file, 0 /* FIXME bugzilla.gnome.org 40644: GNOME_VFS_FILE_INFO_FIELDS_GID */);
+	return !nautilus_file_info_missing (file, GNOME_VFS_FILE_INFO_FIELDS_IDS);
 }
 
 /**
@@ -3972,14 +3875,10 @@ nautilus_file_get_group_name (NautilusFi
 	struct group *group_info;
 
 	/* Before we have info on a file, the owner is unknown. */
-	if (nautilus_file_info_missing (file, 0 /* FIXME bugzilla.gnome.org 40644: GNOME_VFS_FILE_INFO_FIELDS_GID */)) {
+	if (nautilus_file_info_missing (file, GNOME_VFS_FILE_INFO_FIELDS_IDS)) {
 		return NULL;
 	}
 
-	/* FIXME bugzilla.gnome.org 40644: 
-	 * Can we trust the gid in the file info? Might
-	 * there be garbage there? What will it do for non-local files?
-	 */
 	/* No need to free result of getgrgid */
 	group_info = getgrgid ((gid_t) file->details->info->gid);
 
@@ -4279,11 +4178,7 @@ nautilus_file_get_owner_as_string (Nauti
 	char *user_name;
 
 	/* Before we have info on a file, the owner is unknown. */
-	/* FIXME bugzilla.gnome.org 40644: 
-	 * Can we trust the uid in the file info? Might
-	 * there be garbage there? What will it do for non-local files?
-	 */
-	if (nautilus_file_info_missing (file, 0 /* FIXME bugzilla.gnome.org 40644: GNOME_VFS_FILE_INFO_FIELDS_UID */)) {
+	if (nautilus_file_info_missing (file, GNOME_VFS_FILE_INFO_FIELDS_IDS)) {
 		return NULL;
 	}
 
@@ -5226,10 +5121,8 @@ nautilus_file_is_executable (NautilusFil
 		return FALSE;
 	}
 
-	return (file->details->info->permissions
-		& (GNOME_VFS_PERM_USER_EXEC
-		   | GNOME_VFS_PERM_GROUP_EXEC
-		   | GNOME_VFS_PERM_OTHER_EXEC)) != 0;
+	return ((file->details->info->permissions
+		 & GNOME_VFS_PERM_ACCESS_EXECUTABLE) != 0);
 }
 
 /**

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]