After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 581368 - SMB doesn't set G_FILE_ATTRIBUTE_ACCESS_ file attributes
SMB doesn't set G_FILE_ATTRIBUTE_ACCESS_ file attributes
Status: RESOLVED OBSOLETE
Product: gvfs
Classification: Core
Component: smb backend
1.2.x
Other All
: Normal minor
: ---
Assigned To: gvfs-maint
gvfs-maint
Depends on:
Blocks:
 
 
Reported: 2009-05-04 20:39 UTC by kdekorte
Modified: 2018-09-21 16:44 UTC
See Also:
GNOME target: ---
GNOME version: 2.25/2.26



Description kdekorte 2009-05-04 20:39:59 UTC
Please describe the problem:
I was trying to see if an smb uri was readable using the g_file_info_get_attribute_boolean method, works fine for sftp and local files, but fails for smb mounts

Steps to reproduce:
1. See example code below
2. 
3. 


Actual results:
Returns false for file opened off of an smb share

Expected results:
should return true, works ok in nautilus

Does this happen every time?
yes, and on other system levels

Other information:
Example code with workaround

        file = g_file_new_for_uri(uri);
        if (file != NULL) {
            info = g_file_query_info(file, "*", G_FILE_QUERY_INFO_NONE, NULL, NULL);
            if (info != NULL) {
                // SMB filesystems seem to give incorrect access answers over GIO, 
                // so if the file has a filesize > 0 we think it is not streaming
                if (g_ascii_strncasecmp(uri, "smb://", strlen("smb://")) == 0) {
                    ret = (g_file_info_get_size(info) > 0) ? FALSE : TRUE;
                } else {
                    ret =
                        !g_file_info_get_attribute_boolean(info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ);
                }
                g_object_unref(info);
            } else {
                ret = !g_file_test(uri, G_FILE_TEST_EXISTS);
            }
        }
        g_object_unref(file);
Comment 1 Andreas Henriksson 2009-05-13 17:07:05 UTC
I bet this is because the smb backend doesn't support permissions. You'll probably see the same problem on the ftp backend.
Try using g_file_info_has_attribute to make sure the attribute actually exists before reading the value.
Comment 2 Christian Kellner 2009-10-30 10:50:35 UTC
From a quick look at the smb backend it's clear that the G_FILE_ATTRIBUTE_ACCESS_CAN_READ attribute is just not set, so a call to _get_attribute_boolean will naturally return FALSE *every time*. As Andreas already pointed out you need to check for if the attribute is present before using it. 

If the attribute is not set then this indicates (in most cases) that we just don't know better. So in case it is not set the best you can do is the best we would do: assume its readable until proven otherwise.
Comment 3 Tomas Bzatek 2009-11-10 15:59:28 UTC
Although samba on linux supports POSIX permissions, I don't see a way how to retrieve them using libsmbclient call. The smbc_stat_fn() returns struct stat in some way but the st_mode field contains different information. To get real G_FILE_ATTRIBUTE_ACCESS_CAN_READ attribute, we would have to try opening each file and this is certainly nothing we want in the query_info() call.

The other possibility would be to look at smbc_getxattr_fn() and smbc_listxattr_fn() to see if we can get any useful information.
Comment 4 Ondrej Holy 2016-06-14 08:10:14 UTC
See setup_stat() code, where st_mode is filled:
https://github.com/samba-team/samba/blob/82801f9ec895deb9536a2b0a4e0ce4b3d5853220/source3/libsmb/libsmb_stat.c#L54

S_IRUSR is always set regardless of actual permissions. It seems to me that only S_IWUSR is reliable (for files only) as per the code and per my testing. 

See for details about DOS attributes:
https://en.wikipedia.org/wiki/File_attribute#Types
Comment 5 Ondrej Holy 2016-06-14 10:12:57 UTC
I've changed the summary, because there is a problem with other G_FILE_ATTRIBUTE_ACCESS_ attribtues as well...
Comment 6 GNOME Infrastructure Team 2018-09-21 16:44:28 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gvfs/issues/93.