remade patches for libnautilus-private/nautilus-file.c part two




hi gals and dudes : )

here's the second patch. it includes the last one i sent, but i sent that one separately so that it could be identified more easily. so this is the patch that sums it all up. i made it in collaboration with gicmo, whom i've checked the concepts with, but the patch i made myself : )

since it's my first big patch tell me if it works : )

ciao! : )

edoardo
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus/ChangeLog,v
retrieving revision 1.6437
diff -u -p -r1.6437 ChangeLog
--- ChangeLog	16 Mar 2005 08:32:19 -0000	1.6437
+++ ChangeLog	21 Mar 2005 01:25:54 -0000
@@ -1,3 +1,13 @@
+2005-03-21  thetroublemaker <thetroublemaker inventati org>
+
+	* libnautilus-private/nautilus-file.c:
+	made easy modifications to fix bug #40644
+	* libnautilus-private/nautilus-directory-async.c:
+	* libnautilus-private/nautilus-file.c:
+	made heavy modifications so that now access mode is not governed
+	by uid and gid bits, but by _ACCESS parts. thank you to gicmo for
+	all the support.
+
 2005-03-16  Alexander Larsson  <alexl redhat com>
 
 	* configure.in:
Index: libnautilus-private/nautilus-directory-async.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory-async.c,v
retrieving revision 1.212
diff -u -p -r1.212 nautilus-directory-async.c
--- libnautilus-private/nautilus-directory-async.c	22 Nov 2004 15:24:35 -0000	1.212
+++ libnautilus-private/nautilus-directory-async.c	21 Mar 2005 01:25:59 -0000
@@ -1518,7 +1518,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);
@@ -2888,7 +2889,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.362
diff -u -p -r1.362 nautilus-file.c
--- libnautilus-private/nautilus-file.c	22 Feb 2005 10:41:46 -0000	1.362
+++ libnautilus-private/nautilus-file.c	21 Mar 2005 01:26:03 -0000
@@ -659,85 +659,6 @@ nautilus_file_get_user_info (void)
 }
 
 /**
- * nautilus_file_denies_access_permission:
- * 
- * Check whether the current file does not have a given permission
- * for the current user. The sense is negative because the function
- * 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).
- * 
- * Return value: TRUE if the current user definitely does not have
- * the specified permission. FALSE if the current user does have
- * permission, or if the permissions themselves are not queryable.
- */
-static gboolean
-nautilus_file_denies_access_permission (NautilusFile *file, 
-				        GnomeVFSFilePermissions owner_permission,
-				        GnomeVFSFilePermissions group_permission,
-				        GnomeVFSFilePermissions other_permission)
-{
-	struct NautilusUserInfo *user_info;
-	int i;
-
-	g_assert (NAUTILUS_IS_FILE (file));
-
-	/* Once the file is gone, you are denied permission to do anything. */
-	if (nautilus_file_is_gone (file)) {
-		return TRUE;
-	}
-
-	/* File system does not provide permission bits.
-	 * Can't determine specific permissions, do not deny permission at all.
-	 */
-	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;
-}
-
-/**
  * nautilus_file_can_read:
  * 
  * Check whether the user is allowed to read the contents of this file.
@@ -754,11 +675,14 @@ 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);
+	/* if cannot determine access bits of the permissions bitfield,
+	 * return TRUE.
+	 */
+	if !(file->details->info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_ACCESS) {
+		return TRUE;
+	}
+
+	return (file->details->info->permissions & GNOME_VFS_PERM_ACCESS_READABLE);
 }
 
 /**
@@ -778,11 +702,14 @@ 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);
+	/* if cannot determine access bits of the permissions bitfield,
+	 * return TRUE.
+	 */
+	if !(file->details->info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_ACCESS) {
+		return TRUE;
+	}
+
+	return (file->details->info->permissions & GNOME_VFS_PERM_ACCESS_WRITABLE);
 }
 
 /**
@@ -802,11 +729,14 @@ 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);
+	/* if cannot determine access bits of the permissions bitfield,
+	 * return TRUE.
+	 */
+	if !(file->details->info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_ACCESS) {
+		return TRUE;
+	}
+
+	return (file->details->info->permissions & GNOME_VFS_PERM_ACCESS_EXECUTTABLE);
 }
 
 static gboolean
@@ -3730,11 +3660,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_UID);
 }
 
 /**
@@ -3953,11 +3879,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_GID);
 }
 
 /**
@@ -3977,14 +3899,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_GID)) {
 		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);
 
@@ -4284,11 +4202,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_UID)) {
 		return NULL;
 	}
 


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