summaryrefslogtreecommitdiff
blob: b6b83845f795e4d3c3b650362ac4af3a30690583 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
From 2574c9158febdcb3dd7a0ebc3e76311f016d00d0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20Mal=C3=BD?= <malymi@natur.cuni.cz>
Date: Wed, 12 Jul 2017 11:55:04 +0200
Subject: Always create the "." UDSEntry

Summary:
The smb_kio plugin does not create the "." UDSEntry,
relying on the underlying KIO infrastructure to create a default one.

This patch ensures that the UDSEntry is always created with proper access permissions.

CCBUG: 376344

Reviewers: elvisangelaccio

Differential Revision: https://phabricator.kde.org/D6616
---
 smb/kio_smb_browse.cpp | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/smb/kio_smb_browse.cpp b/smb/kio_smb_browse.cpp
index 1ca90a2..06ca60b 100644
--- a/smb/kio_smb_browse.cpp
+++ b/smb/kio_smb_browse.cpp
@@ -309,6 +309,7 @@ void SMBSlave::listDir( const QUrl& kurl )
    int                 dirfd;
    struct smbc_dirent  *dirp = NULL;
    UDSEntry    udsentry;
+   bool dir_is_root = true;
 
    dirfd = smbc_opendir( m_current_url.toSmbcUrl() );
    if (dirfd > 0){
@@ -350,8 +351,14 @@ void SMBSlave::listDir( const QUrl& kurl )
               udsentry.insert(KIO::UDSEntry::UDS_HIDDEN, 1);
            }
 
-           if (udsName == "." || udsName == "..")
+           if (udsName == ".")
            {
+               // Skip the "." entry
+               // Mind the way m_current_url is handled in the loop
+           }
+           else if (udsName == "..")
+           {
+               dir_is_root = false;
                // fprintf(stderr,"----------- hide: -%s-\n",dirp->name);
                // do nothing and hide the hidden shares
            }
@@ -430,6 +437,20 @@ void SMBSlave::listDir( const QUrl& kurl )
            udsentry.clear();
        } while (dirp); // checked already in the head
 
+       if (dir_is_root) {
+           udsentry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR);
+           udsentry.insert(KIO::UDSEntry::UDS_NAME, ".");
+           udsentry.insert(KIO::UDSEntry::UDS_ACCESS, (S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH));
+           udsentry.insert(KIO::UDSEntry::UDS_MIME_TYPE, QLatin1String("application/x-smb-server"));
+       }
+       else
+       {
+           udsentry.insert(KIO::UDSEntry::UDS_NAME, ".");
+           browse_stat_path(m_current_url, udsentry, true);
+       }
+       listEntry(udsentry);
+       udsentry.clear();
+
        // clean up
        smbc_closedir(dirfd);
    }
-- 
cgit v0.11.2
From e792aa44b5aa0b122e006234a8f87a16ff12fe6f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20Mal=C3=BD?= <malymi@natur.cuni.cz>
Date: Wed, 12 Jul 2017 11:57:12 +0200
Subject: Return appropriate error code from browse_stat_path() instead of
 trying to deal with the error internally.

Summary:
Current behavior of browse_stat_path() can result in both finished() and error() being signaled to KIO.
This patch adjusts the logic to prevent this case.

Reviewers: elvisangelaccio

BUG: 376344
FIXED-IN: 17.08.0

Differential Revision: https://phabricator.kde.org/D6617
---
 smb/kio_smb.h          |  5 ++--
 smb/kio_smb_browse.cpp | 67 ++++++++++++++++++++++++++++----------------------
 2 files changed, 40 insertions(+), 32 deletions(-)

diff --git a/smb/kio_smb.h b/smb/kio_smb.h
index a5cae11..a2a9343 100644
--- a/smb/kio_smb.h
+++ b/smb/kio_smb.h
@@ -156,10 +156,9 @@ protected:
      * Description :  Return a stat of given SMBUrl. Calls cache_stat and
      *                pack it in UDSEntry. UDSEntry will not be cleared
      * Parameter :    SMBUrl the url to stat
-     *                ignore_errors do not call error(), but warning()
-     * Return :       false if any error occurred (errno), else true
+     * Return :       cache_stat() return code
      */
-    bool browse_stat_path(const SMBUrl& url, UDSEntry& udsentry, bool ignore_errors);
+    int browse_stat_path(const SMBUrl& url, UDSEntry& udsentry);
 
     /**
      * Description :  call smbc_stat and return stats of the url
diff --git a/smb/kio_smb_browse.cpp b/smb/kio_smb_browse.cpp
index 06ca60b..84bfdc2 100644
--- a/smb/kio_smb_browse.cpp
+++ b/smb/kio_smb_browse.cpp
@@ -55,8 +55,7 @@ int SMBSlave::cache_stat(const SMBUrl &url, struct stat* st )
 }
 
 //---------------------------------------------------------------------------
-bool SMBSlave::browse_stat_path(const SMBUrl& _url, UDSEntry& udsentry, bool ignore_errors)
-  // Returns: true on success, false on failure
+int SMBSlave::browse_stat_path(const SMBUrl& _url, UDSEntry& udsentry)
 {
    SMBUrl url = _url;
 
@@ -68,7 +67,7 @@ bool SMBSlave::browse_stat_path(const SMBUrl& _url, UDSEntry& udsentry, bool ign
          qCDebug(KIO_SMB) << "mode: "<< st.st_mode;
          warning(i18n("%1:\n"
                       "Unknown file type, neither directory or file.", url.toDisplayString()));
-         return false;
+         return EINVAL;
       }
 
       udsentry.insert(KIO::UDSEntry::UDS_FILE_TYPE, st.st_mode & S_IFMT);
@@ -96,24 +95,8 @@ bool SMBSlave::browse_stat_path(const SMBUrl& _url, UDSEntry& udsentry, bool ign
       udsentry.insert(KIO::UDSEntry::UDS_ACCESS_TIME, st.st_atime);
       // No, st_ctime is not UDS_CREATION_TIME...
    }
-   else
-   {
-       if (!ignore_errors) {
-           if (cacheStatErr == EPERM || cacheStatErr == EACCES)
-               if (checkPassword(url)) {
-                   redirection( url );
-                   return false;
-               }
-
-           reportError(url, cacheStatErr);
-       } else if (cacheStatErr == ENOENT || cacheStatErr == ENOTDIR) {
-           warning(i18n("File does not exist: %1", url.url()));
-       }
-       qCDebug(KIO_SMB) << "ERROR!!";
-       return false;
-   }
 
-   return true;
+   return cacheStatErr;
 }
 
 //===========================================================================
@@ -141,7 +124,7 @@ void SMBSlave::stat( const QUrl& kurl )
     switch(m_current_url.getType())
     {
     case SMBURLTYPE_UNKNOWN:
-        error(ERR_MALFORMED_URL,m_current_url.toDisplayString());
+        error(ERR_MALFORMED_URL, url.toDisplayString());
         return;
 
     case SMBURLTYPE_ENTIRE_NETWORK:
@@ -150,12 +133,38 @@ void SMBSlave::stat( const QUrl& kurl )
         break;
 
     case SMBURLTYPE_SHARE_OR_PATH:
-        if (browse_stat_path(m_current_url, udsentry, false))
+        {
+            int ret = browse_stat_path(m_current_url, udsentry);
+
+            if (ret == EPERM || ret == EACCES)
+            {
+                SMBUrl smbUrl(url);
+
+                if (checkPassword(smbUrl))
+                {
+                    redirection(smbUrl);
+                    finished();
+                }
+                else
+                {
+                    reportError(url, ret);
+                }
+
+                return;
+            }
+            else if (ret == ENOENT || ret == ENOTDIR)
+            {
+                warning(i18n("File does not exist: %1", url.url()));
+                finished();
+                return;
+            }
+            else if (ret != 0)
+            {
+                qCDebug(KIO_SMB) << "stat() error" << ret << url;
+                reportError(url, ret);
+                return;
+            }
             break;
-        else {
-            qCDebug(KIO_SMB) << "ERROR!!";
-            finished();
-            return;
         }
     default:
         qCDebug(KIO_SMB) << "UNKNOWN " << url;
@@ -366,7 +375,7 @@ void SMBSlave::listDir( const QUrl& kurl )
            {
                // Set stat information
                m_current_url.addPath(dirpName);
-               browse_stat_path(m_current_url, udsentry, true);
+               browse_stat_path(m_current_url, udsentry);
                m_current_url.cd("..");
 
                // Call base class to list entry
@@ -375,7 +384,7 @@ void SMBSlave::listDir( const QUrl& kurl )
            else if(dirp->smbc_type == SMBC_DIR)
            {
                m_current_url.addPath(dirpName);
-               browse_stat_path(m_current_url, udsentry, true);
+               browse_stat_path(m_current_url, udsentry);
                m_current_url.cd("..");
 
                // Call base class to list entry
@@ -446,7 +455,7 @@ void SMBSlave::listDir( const QUrl& kurl )
        else
        {
            udsentry.insert(KIO::UDSEntry::UDS_NAME, ".");
-           browse_stat_path(m_current_url, udsentry, true);
+           browse_stat_path(m_current_url, udsentry);
        }
        listEntry(udsentry);
        udsentry.clear();
-- 
cgit v0.11.2