Merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-11-new into lp:ubuntu-filemanager-app
- samba-browsing-11-new
- Merge into trunk
Proposed by
Carlos Jose Mazieri
Status: | Merged |
---|---|
Approved by: | Arto Jalkanen |
Approved revision: | 421 |
Merged at revision: | 421 |
Proposed branch: | lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-11-new |
Merge into: | lp:ubuntu-filemanager-app |
Diff against target: |
709 lines (+641/-4) 8 files modified
src/plugin/folderlistmodel/CMakeLists.txt (+4/-0) src/plugin/folderlistmodel/plugin.cpp (+1/-0) src/plugin/folderlistmodel/plugin.h (+1/-0) src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient.pri (+8/-4) src/plugin/folderlistmodel/smb/qsambaclient/src/smbplaces.cpp (+134/-0) src/plugin/folderlistmodel/smb/qsambaclient/src/smbplaces.h (+77/-0) src/plugin/folderlistmodel/smb/qsambaclient/src/smbusershare.cpp (+234/-0) src/plugin/folderlistmodel/smb/qsambaclient/src/smbusershare.h (+182/-0) |
To merge this branch: | bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-11-new |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Ubuntu File Manager Developers | Pending | ||
Review via email: mp+262520@code.launchpad.net |
Commit message
It replaces https:/
Description of the change
It replaces https:/
The MP for samba-browsing-11 //code.
To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
review:
Approve
(continuous-integration)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/plugin/folderlistmodel/CMakeLists.txt' |
2 | --- src/plugin/folderlistmodel/CMakeLists.txt 2015-05-20 16:18:07 +0000 |
3 | +++ src/plugin/folderlistmodel/CMakeLists.txt 2015-06-20 15:24:03 +0000 |
4 | @@ -73,6 +73,10 @@ |
5 | smb/smblocation.cpp |
6 | smb/smblocationauthentication.cpp |
7 | smb/smblocationauthentication.h |
8 | + smb/qsambaclient/src/smbplaces.cpp |
9 | + smb/qsambaclient/src/smbplaces.h |
10 | + smb/qsambaclient/src/smbusershare.cpp |
11 | + smb/qsambaclient/src/smbusershare.h |
12 | net/netauthenticationdata.cpp |
13 | net/netauthenticationdata.h |
14 | net/netutil.cpp |
15 | |
16 | === modified file 'src/plugin/folderlistmodel/plugin.cpp' |
17 | --- src/plugin/folderlistmodel/plugin.cpp 2014-06-25 21:56:09 +0000 |
18 | +++ src/plugin/folderlistmodel/plugin.cpp 2015-06-20 15:24:03 +0000 |
19 | @@ -54,5 +54,6 @@ |
20 | DirModel::registerMetaTypes(); |
21 | qmlRegisterType<DirSelection>(uri, 1, 0, "FolderListSelection"); |
22 | qmlRegisterType<DirModel>(uri, 1, 0, "FolderListModel"); |
23 | + qmlRegisterType<SmbUserShare>(uri, 1, 0,"FolderListSmbUserShare"); |
24 | } |
25 | |
26 | |
27 | === modified file 'src/plugin/folderlistmodel/plugin.h' |
28 | --- src/plugin/folderlistmodel/plugin.h 2014-06-25 21:56:09 +0000 |
29 | +++ src/plugin/folderlistmodel/plugin.h 2015-06-20 15:24:03 +0000 |
30 | @@ -34,6 +34,7 @@ |
31 | |
32 | #include "dirmodel.h" |
33 | #include "dirselection.h" |
34 | +#include "smbusershare.h" |
35 | |
36 | #include <QtGlobal> |
37 | |
38 | |
39 | === modified file 'src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient.pri' |
40 | --- src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient.pri 2015-06-03 11:54:36 +0000 |
41 | +++ src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient.pri 2015-06-20 15:24:03 +0000 |
42 | @@ -1,12 +1,16 @@ |
43 | |
44 | -SOURCES += $$PWD/src/smbutil.cpp \ |
45 | - $$PWD/src/smbiteminfo.cpp \ |
46 | +SOURCES += $$PWD/src/smbutil.cpp \ |
47 | + $$PWD/src/smbusershare.cpp \ |
48 | + $$PWD/src/smbiteminfo.cpp \ |
49 | + $$PWD/src/smbplaces.cpp \ |
50 | $$PWD/src/smbobject.cpp \ |
51 | $$PWD/src/smblocationdiriterator.cpp |
52 | |
53 | |
54 | -HEADERS += $$PWD/src/smbutil.h \ |
55 | - $$PWD/src/smbiteminfo.h \ |
56 | +HEADERS += $$PWD/src/smbutil.h \ |
57 | + $$PWD/src/smbusershare.h \ |
58 | + $$PWD/src/smbiteminfo.h \ |
59 | + $$PWD/src/smbplaces.h \ |
60 | $$PWD/src/smbobject.h \ |
61 | $$PWD/src/smblocationdiriterator.h |
62 | |
63 | |
64 | === added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbplaces.cpp' |
65 | --- src/plugin/folderlistmodel/smb/qsambaclient/src/smbplaces.cpp 1970-01-01 00:00:00 +0000 |
66 | +++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbplaces.cpp 2015-06-20 15:24:03 +0000 |
67 | @@ -0,0 +1,134 @@ |
68 | +/************************************************************************** |
69 | + * |
70 | + * Copyright 2014 Canonical Ltd. |
71 | + * Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com> |
72 | + * |
73 | + * This program is free software; you can redistribute it and/or modify |
74 | + * it under the terms of the GNU Lesser General Public License as published by |
75 | + * the Free Software Foundation; version 3. |
76 | + * |
77 | + * This program is distributed in the hope that it will be useful, |
78 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
79 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
80 | + * GNU Lesser General Public License for more details. |
81 | + * |
82 | + * You should have received a copy of the GNU Lesser General Public License |
83 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
84 | + * |
85 | + * File: smbplaces.cpp |
86 | + * Date: 27/12/2014 |
87 | + */ |
88 | + |
89 | +#include "smbplaces.h" |
90 | +#include "smbutil.h" |
91 | +#include <QThread> |
92 | + |
93 | + |
94 | +#define SECOND_IN_MILLISECONDS 60000 |
95 | + |
96 | +/*! |
97 | + * \brief The SmbPlacesThread class gets the list of shares on a secondary thread |
98 | + */ |
99 | +class SmbPlacesThread : public QThread |
100 | +{ |
101 | +public: |
102 | + SmbPlacesThread(QObject *parent = 0): QThread(parent) |
103 | + {} |
104 | + inline QStringList getShareList() { return shares; } |
105 | +protected: |
106 | + virtual void run() |
107 | + { |
108 | + SmbUtil smb; |
109 | + shares = smb.lisShares(); |
110 | + } |
111 | + |
112 | +private: |
113 | + QStringList shares; |
114 | +}; |
115 | + |
116 | + |
117 | + |
118 | +//=============================================================================================== |
119 | +/*! |
120 | + * \brief SmbPlaces::SmbPlaces |
121 | + * \param parent |
122 | + */ |
123 | +SmbPlaces::SmbPlaces(QObject *parent) : |
124 | + QObject(parent) |
125 | + ,m_thread(0) |
126 | +{ |
127 | + |
128 | +} |
129 | + |
130 | + |
131 | +//=============================================================================================== |
132 | +/*! |
133 | + * \brief SmbPlaces::~SmbPlaces |
134 | + */ |
135 | +SmbPlaces::~SmbPlaces() |
136 | +{ |
137 | + if (m_thread) |
138 | + { |
139 | + m_thread->quit(); // finish the thead, the information is no longer necessary |
140 | + m_thread->wait( 3600 * SECOND_IN_MILLISECONDS ); // wait up to an hour |
141 | + delete m_thread; |
142 | + } |
143 | +} |
144 | + |
145 | +//=============================================================================================== |
146 | +/*! |
147 | + * \brief SmbPlaces::listPlacesSync() |
148 | + * \return the new list of the shares |
149 | + */ |
150 | +QStringList SmbPlaces::listPlacesSync() |
151 | +{ |
152 | + SmbUtil smb; |
153 | + m_sharesList = smb.lisShares(); |
154 | + return m_sharesList; |
155 | +} |
156 | + |
157 | +//=============================================================================================== |
158 | +/*! |
159 | + * \brief SmbPlaces::listPlacesAsync() |
160 | + * |
161 | + * Creates a SmbPlacesThread object (the secondary thread) to get the shares list |
162 | + */ |
163 | +void SmbPlaces::listPlacesAsync() |
164 | +{ |
165 | + if (m_thread == 0) |
166 | + { |
167 | + m_thread = new SmbPlacesThread(this); |
168 | + connect(m_thread, SIGNAL(finished()), |
169 | + this, SLOT(onSmbPlacesThreadFinished())); |
170 | + } |
171 | + if (!m_thread->isRunning()) |
172 | + { |
173 | + m_thread->start(); |
174 | + } |
175 | +} |
176 | + |
177 | + |
178 | +//=============================================================================================== |
179 | +/*! |
180 | + * \brief SmbPlaces::gePlaces() |
181 | + * \return the current list of shares |
182 | + */ |
183 | +QStringList SmbPlaces::gePlaces() const |
184 | +{ |
185 | + return m_sharesList; |
186 | +} |
187 | + |
188 | + |
189 | +//=============================================================================================== |
190 | +/*! |
191 | + * \brief SmbPlaces::onSmbPlacesThreadFinished |
192 | + * |
193 | + * called when SmbPlacesThread thread finishes, SmbPlacesThread is deleted |
194 | + */ |
195 | +void SmbPlaces::onSmbPlacesThreadFinished() |
196 | +{ |
197 | + m_sharesList = m_thread->getShareList(); |
198 | + m_thread->deleteLater(); |
199 | + m_thread = 0; |
200 | + emit sharesList(m_sharesList); |
201 | +} |
202 | |
203 | === added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbplaces.h' |
204 | --- src/plugin/folderlistmodel/smb/qsambaclient/src/smbplaces.h 1970-01-01 00:00:00 +0000 |
205 | +++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbplaces.h 2015-06-20 15:24:03 +0000 |
206 | @@ -0,0 +1,77 @@ |
207 | +/************************************************************************** |
208 | + * |
209 | + * Copyright 2014 Canonical Ltd. |
210 | + * Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com> |
211 | + * |
212 | + * This program is free software; you can redistribute it and/or modify |
213 | + * it under the terms of the GNU Lesser General Public License as published by |
214 | + * the Free Software Foundation; version 3. |
215 | + * |
216 | + * This program is distributed in the hope that it will be useful, |
217 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
218 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
219 | + * GNU Lesser General Public License for more details. |
220 | + * |
221 | + * You should have received a copy of the GNU Lesser General Public License |
222 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
223 | + * |
224 | + * File: smbplaces.h |
225 | + * Date: 27/12/2014 |
226 | + */ |
227 | + |
228 | +#ifndef SMBPLACES_H |
229 | +#define SMBPLACES_H |
230 | + |
231 | +#include <QObject> |
232 | +#include <QStringList> |
233 | + |
234 | +class SmbPlacesThread; |
235 | + |
236 | + |
237 | +/*! |
238 | + * \brief The SmbPlaces class gets the list of current Samba/CIFS shares |
239 | + */ |
240 | + |
241 | +class SmbPlaces : public QObject |
242 | +{ |
243 | + Q_OBJECT |
244 | +public: |
245 | + explicit SmbPlaces(QObject *parent = 0); |
246 | + ~SmbPlaces(); |
247 | + |
248 | +public: |
249 | + /*! |
250 | + * list all Samba/Cifs shares in sync mode, that means it may block any active UI |
251 | + * |
252 | + * \return the list of the shares in the current network |
253 | + */ |
254 | + Q_INVOKABLE QStringList listPlacesSync(); |
255 | + |
256 | + Q_INVOKABLE QStringList gePlaces() const; |
257 | + |
258 | +public slots: |
259 | + /*! |
260 | + * list all Samba/Cifs shares in async mode, the job is made on a secondary thread |
261 | + * that means it does not block any active UI |
262 | + * |
263 | + * After the job is done the signal \ref sharesList is emitted within the current shares list |
264 | + */ |
265 | + void listPlacesAsync(); |
266 | + |
267 | +signals: |
268 | + void sharesList(QStringList); |
269 | + |
270 | +private slots: |
271 | + void onSmbPlacesThreadFinished(); |
272 | + |
273 | +private: |
274 | + QStringList m_sharesList; |
275 | + SmbPlacesThread * m_thread; |
276 | + |
277 | +#if defined(REGRESSION_TEST_QSAMBACLIENT) |
278 | + friend class TestQSambaSuite; |
279 | +#endif |
280 | + |
281 | +}; |
282 | + |
283 | +#endif // SMBPLACES_H |
284 | |
285 | === added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbusershare.cpp' |
286 | --- src/plugin/folderlistmodel/smb/qsambaclient/src/smbusershare.cpp 1970-01-01 00:00:00 +0000 |
287 | +++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbusershare.cpp 2015-06-20 15:24:03 +0000 |
288 | @@ -0,0 +1,234 @@ |
289 | +/************************************************************************** |
290 | + * |
291 | + * Copyright 2014 Canonical Ltd. |
292 | + * Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com> |
293 | + * |
294 | + * This program is free software; you can redistribute it and/or modify |
295 | + * it under the terms of the GNU Lesser General Public License as published by |
296 | + * the Free Software Foundation; version 3. |
297 | + * |
298 | + * This program is distributed in the hope that it will be useful, |
299 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
300 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
301 | + * GNU Lesser General Public License for more details. |
302 | + * |
303 | + * You should have received a copy of the GNU Lesser General Public License |
304 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
305 | + * |
306 | + * File: smbusershare.cpp |
307 | + * Date: 02/12/2014 |
308 | + */ |
309 | + |
310 | +#include "smbusershare.h" |
311 | + |
312 | +#include <stdlib.h> |
313 | + |
314 | +#include <QFileInfo> |
315 | +#include <QFile> |
316 | +#include <QDir> |
317 | +#include <QRegExp> |
318 | +#include <QCoreApplication> |
319 | +#include <QDebug> |
320 | +#include <unistd.h> |
321 | + |
322 | +#define VAR_USER_SHARE_DIR QLatin1String("/var/lib/samba/usershares") |
323 | + |
324 | +QString SmbUserShare::m_error; |
325 | + |
326 | + |
327 | +bool SmbUserShare::UserShareFile::exists() const |
328 | +{ |
329 | + return !name.isEmpty() && QFileInfo(path).exists(); |
330 | +} |
331 | + |
332 | + |
333 | +SmbUserShare::SmbUserShare(QObject *parent) : QObject(parent) |
334 | +{ |
335 | +} |
336 | + |
337 | + |
338 | +SmbUserShare::~SmbUserShare() |
339 | +{ |
340 | + |
341 | +} |
342 | + |
343 | + |
344 | +bool SmbUserShare::canCreateShares() |
345 | +{ |
346 | + bool ret = false; |
347 | + m_error.clear(); |
348 | + QString path_var = ::qgetenv("PATH"); |
349 | + if (!path_var.isEmpty()) |
350 | + { |
351 | + QStringList paths = path_var.split(QLatin1Char(':')); |
352 | + for(int counter = 0; !ret && counter < paths.count(); ++counter) |
353 | + { |
354 | + QFileInfo net(paths.at(counter)); |
355 | + ret = net.exists() && net.isExecutable(); |
356 | + } |
357 | + } |
358 | + if (!ret) |
359 | + { |
360 | + m_error = tr("net tool not found, check samba installation"); |
361 | + } |
362 | + else |
363 | + { |
364 | + QFileInfo varUserShareDir(VAR_USER_SHARE_DIR); |
365 | + ret &= varUserShareDir.isDir() && varUserShareDir.isWritable(); |
366 | + if (!ret) |
367 | + { |
368 | + m_error = tr("cannot write in ") + VAR_USER_SHARE_DIR; |
369 | + } |
370 | + } |
371 | + return ret; |
372 | +} |
373 | + |
374 | + |
375 | +QString SmbUserShare::proposedName (const QString &fulldirpath) |
376 | +{ |
377 | + QFileInfo path(fulldirpath); |
378 | + return path.fileName().replace(QLatin1Char(' '), QLatin1Char('_')); |
379 | +} |
380 | + |
381 | + |
382 | +bool SmbUserShare::createShareForFolder(const QString &fulldirpath, |
383 | + Access access, |
384 | + bool allowGuests, |
385 | + const QString &name) |
386 | +{ |
387 | + bool ret = false; |
388 | + QFileInfo dir(fulldirpath); |
389 | + if (dir.exists() && dir.isDir() ) |
390 | + { |
391 | + QString cmd("net usershare add "); |
392 | + cmd += !name.isEmpty() ? name : proposedName(fulldirpath); |
393 | + cmd += QLatin1Char(' ') + fulldirpath |
394 | + + QString(" \"create by %1 using SmbUserShare class\" "). |
395 | + arg(QCoreApplication::applicationName()); |
396 | + |
397 | + if (access == ReadWrite) |
398 | + { |
399 | + //cmd += QLatin1String(" everyone:f "); |
400 | + cmd += QLatin1String(" S-1-1-0:f "); |
401 | + QFile::setPermissions( fulldirpath, QFile::permissions(fulldirpath) | QFile::ReadGroup | |
402 | + QFile::ReadOther | QFile::ExeOther | QFile::ExeGroup | QFile::WriteGroup | QFile::WriteOther |
403 | + ); |
404 | + } |
405 | + else |
406 | + { |
407 | + //cmd += QLatin1String(" everyone:r "); |
408 | + cmd += QString(" S-1-1-0:r,S-1-22-1-%1:f ").arg(::getuid()); |
409 | + QFile::setPermissions( fulldirpath, QFile::permissions(fulldirpath) | QFile::ReadGroup | |
410 | + QFile::ReadOther | QFile::ExeOther | QFile::ExeGroup |
411 | + ); |
412 | + } |
413 | + cmd += QLatin1String("guest_ok="); |
414 | + cmd += allowGuests ? QLatin1Char('y') : QLatin1Char('n'); |
415 | + int retSystem = ::system(cmd.toLocal8Bit().constData()); |
416 | + ret = retSystem == 0; |
417 | + } |
418 | + return ret; |
419 | +} |
420 | + |
421 | + |
422 | + |
423 | +bool SmbUserShare::removeShare(const QString& name_OR_fulldirpath) |
424 | +{ |
425 | + bool ret = false; |
426 | + UserShareFile info = search(name_OR_fulldirpath); |
427 | + if (!info.name.isEmpty()) |
428 | + { |
429 | + QString cmd("net usershare delete "); |
430 | + cmd += info.name; |
431 | + ret = ::system(cmd.toLocal8Bit().constData()) == 0; |
432 | + } |
433 | + return ret; |
434 | +} |
435 | + |
436 | + |
437 | +SmbUserShare::Access SmbUserShare::getEveryoneAccess(const QString& name_OR_fulldirpath) |
438 | +{ |
439 | + UserShareFile ret = search(name_OR_fulldirpath); |
440 | + return ret.getAccess(); |
441 | +} |
442 | + |
443 | + |
444 | +bool SmbUserShare::isGuestAllowed(const QString& name_OR_fulldirpath) |
445 | +{ |
446 | + UserShareFile ret = search(name_OR_fulldirpath); |
447 | + return ret.isGuestAllowed(); |
448 | +} |
449 | + |
450 | + |
451 | +SmbUserShare::UserShareFile SmbUserShare::readConfigFile(const QString &pathname) |
452 | +{ |
453 | + UserShareFile ret; |
454 | + QFile shareFile(pathname); |
455 | + if (shareFile.open(QFile::ReadOnly)) |
456 | + { |
457 | + QString line(shareFile.readLine().trimmed()); |
458 | + while (line.length() > 0) |
459 | + { |
460 | + if (!line.startsWith(QLatin1Char('#'))) |
461 | + { |
462 | + QStringList pair = line.split(QLatin1Char('=')); |
463 | + if (pair.count() == 2) |
464 | + { |
465 | + QString name = pair.at(0).trimmed(); |
466 | + QString value = pair.at(1).trimmed(); |
467 | + if (name == QLatin1String("path")) |
468 | + { |
469 | + ret.path = value; |
470 | + } |
471 | + else |
472 | + if (name== QLatin1String("usershare_acl")) |
473 | + { |
474 | + QStringList v = value.split(QChar(':')); |
475 | + if (v.count() > 1) |
476 | + { |
477 | + ret.everyoneFlag = v.at(1).trimmed().at(0).toLower(); |
478 | + } |
479 | + } |
480 | + else |
481 | + if (name == QLatin1String("guest_ok")) |
482 | + { |
483 | + ret.guest_ok = value.at(0).toLower(); |
484 | + } |
485 | + else |
486 | + if (name == QLatin1String("sharename")) |
487 | + { |
488 | + ret.name = value; |
489 | + } |
490 | + } |
491 | + } |
492 | + line = shareFile.readLine().trimmed(); |
493 | + }//while |
494 | + } |
495 | + return ret; |
496 | +} |
497 | + |
498 | + |
499 | +SmbUserShare::UserShareFile SmbUserShare::search(const QString& name_OR_fulldirpath) |
500 | +{ |
501 | + UserShareFile ret; |
502 | + if (!name_OR_fulldirpath.isEmpty()) |
503 | + { |
504 | + bool found = false ; |
505 | + bool isPath = QFileInfo(name_OR_fulldirpath).isAbsolute(); |
506 | + UserShareFile current ; |
507 | + QDir d(VAR_USER_SHARE_DIR, QString(), QDir::NoSort, QDir::Files | QDir::NoSymLinks); |
508 | + for(uint counter=0; !found && counter < d.count(); ++ counter) |
509 | + { |
510 | + current = readConfigFile(d.absoluteFilePath(d[counter])); |
511 | + found = isPath ? (current.path == name_OR_fulldirpath) |
512 | + : (current.name == name_OR_fulldirpath); |
513 | + } |
514 | + if (found) |
515 | + { |
516 | + ret = current; |
517 | + } |
518 | + } |
519 | + return ret; |
520 | +} |
521 | + |
522 | + |
523 | |
524 | === added file 'src/plugin/folderlistmodel/smb/qsambaclient/src/smbusershare.h' |
525 | --- src/plugin/folderlistmodel/smb/qsambaclient/src/smbusershare.h 1970-01-01 00:00:00 +0000 |
526 | +++ src/plugin/folderlistmodel/smb/qsambaclient/src/smbusershare.h 2015-06-20 15:24:03 +0000 |
527 | @@ -0,0 +1,182 @@ |
528 | +/************************************************************************** |
529 | + * |
530 | + * Copyright 2014 Canonical Ltd. |
531 | + * Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com> |
532 | + * |
533 | + * This program is free software; you can redistribute it and/or modify |
534 | + * it under the terms of the GNU Lesser General Public License as published by |
535 | + * the Free Software Foundation; version 3. |
536 | + * |
537 | + * This program is distributed in the hope that it will be useful, |
538 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
539 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
540 | + * GNU Lesser General Public License for more details. |
541 | + * |
542 | + * You should have received a copy of the GNU Lesser General Public License |
543 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
544 | + * |
545 | + * File: smbusershare.h |
546 | + * Date: 02/12/2014 |
547 | + */ |
548 | + |
549 | +#ifndef SMBUSERSHARE_H |
550 | +#define SMBUSERSHARE_H |
551 | + |
552 | + |
553 | +#include <QString> |
554 | +#include <QObject> |
555 | + |
556 | +/*! |
557 | + * \brief The SmbUserShare class provides simple mechanisms to create/remove Samba shares on the localhost |
558 | + * |
559 | + * <p> User shares configuration files are under \b /var/lib/samba/usershares/ |
560 | + * |
561 | + * Tests: |
562 | + * \li Works: For a user who already has shares, just creating a new share file under /var/lib/samba/usershares/ |
563 | + * \li Works: For a new created user, just creating a new share file under /var/lib/samba/usershares/ |
564 | + * \li Works: using commnad line: net usershare add created_net_usershare `pwd`/created_net_usershare "created ny SmbUserShare" everyone:F guest_ok=y |
565 | + * \li Works: using command line: net usershare add created_net_usershare `pwd`/created_net_usershare "created ny SmbUserShare" everyone:R guest_ok=n |
566 | + * \li Works: using command line: net usershare delete created_net_usershare |
567 | + * \li Works: if the usershare exits prints the name: net usershare list created_net_usershare |
568 | + * |
569 | + * User share File example: |
570 | + * \code |
571 | + * path=/home/carlos/samba |
572 | + * comment= |
573 | + * usershare_acl=S-1-1-0:d,S-1-22-1-1000:r |
574 | + * guest_ok=y |
575 | + * sharename=samba |
576 | + * \endcode |
577 | + * |
578 | + * Once the user is suitable set a new share is created by just by creating a new file under /var/lib/samba/usershares/ |
579 | + * |
580 | + * Where \a \b usershare_acl is: (\sa \link http://devarthur.blogspot.de/2008/05/integrating-ubuntu-hardy-heron-804-with.html) |
581 | + * \code |
582 | + * usershare_acl=Group_SID:access_modifier |
583 | + * |
584 | + * SID "S-1-1-0" is Everyone |
585 | + * |
586 | + * The access modifiers after the group SID are as follows: |
587 | + * R - read-only |
588 | + * F - full access |
589 | + * D - deny access |
590 | + * \endcode |
591 | + */ |
592 | + |
593 | +class SmbUserShare : public QObject |
594 | +{ |
595 | +public: |
596 | + |
597 | + /*! |
598 | + * \brief The Access enum |
599 | + * |
600 | + * For simplification purposes Deny users are not available |
601 | + */ |
602 | + Q_ENUMS(Access) |
603 | + /*! |
604 | + * \brief The Access enum specifies how a user share is created by this class |
605 | + * |
606 | + * \TODO create some deny mechanism |
607 | + */ |
608 | + enum Access |
609 | + { |
610 | + None, //!< Error, perhaps the share does not exist |
611 | + Readonly, |
612 | + ReadWrite |
613 | + //TODO allow deny users |
614 | + }; |
615 | + |
616 | + |
617 | + /*! |
618 | + * \brief The UserShareFile struct keeps information from usershare config files |
619 | + */ |
620 | + struct UserShareFile |
621 | + { |
622 | + QString path; |
623 | + QChar everyoneFlag; |
624 | + QChar guest_ok; |
625 | + QString name; |
626 | + bool isGuestAllowed() const { return guest_ok == QChar('y'); } |
627 | + Access getAccess() const |
628 | + { |
629 | + Access ret = None; |
630 | + if (everyoneFlag == QChar('f')) |
631 | + { |
632 | + ret = ReadWrite; |
633 | + } |
634 | + else |
635 | + if (everyoneFlag == QChar('r')) |
636 | + { |
637 | + ret = Readonly; |
638 | + } |
639 | + return ret; |
640 | + } |
641 | + bool exists() const; |
642 | + }; |
643 | + |
644 | + |
645 | + |
646 | + explicit SmbUserShare(QObject *parent = 0); |
647 | + ~SmbUserShare(); |
648 | + |
649 | + /*! |
650 | + * \brief SmbUserShare::canCreateShares() |
651 | + * |
652 | + * Finds for "net" in the PATH as it will be used to create/remove shares |
653 | + * |
654 | + * \return true if the executable "net" exists in the PATH |
655 | + */ |
656 | + Q_INVOKABLE static bool canCreateShares(); |
657 | + |
658 | + /*! |
659 | + * \brief SmbUserShare::createShareForFolder() attempts to create a user share using "net" command |
660 | + * \param fulldirpath the full path of the directory |
661 | + * \param access [optional] defaults to ReadOnly |
662 | + * \param allowGuests [optional] defaults to true |
663 | + * \param name [optional] defaults to \ref proposedName() |
664 | + * \return true when the "net" returns zero |
665 | + */ |
666 | + Q_INVOKABLE static bool createShareForFolder(const QString& fulldirpath, Access access = Readonly, bool allowGuests = true, const QString& name = QLatin1String(0)); |
667 | + |
668 | + /*! |
669 | + * \brief SmbUserShare::removeShare() attempts to remove a share related to |
670 | + * \param name_OR_fulldirpath it can be a share name or a dirpathname which has a share in it |
671 | + * \return |
672 | + */ |
673 | + Q_INVOKABLE static bool removeShare(const QString& name_OR_fulldirpath); |
674 | + |
675 | + /*! |
676 | + * \brief QSmbShareCreation::proposedName() returns a suitable share name for a such directory |
677 | + * \param fulldirpath full path of the directory where a share is being to created/removed |
678 | + * \return name with no spaces |
679 | + */ |
680 | + Q_INVOKABLE static QString proposedName(const QString& fulldirpath); |
681 | + |
682 | + /*! |
683 | + * \brief QSmbShareCreation::getAccess() returns the main Access of a share, \ref None when it does not exist |
684 | + */ |
685 | + Q_INVOKABLE static Access getEveryoneAccess(const QString& name_OR_fulldirpath); |
686 | + |
687 | + /*! |
688 | + * \brief QSmbShareCreation::isGuestAllowed() |
689 | + * \return true if guest can browse the share |
690 | + */ |
691 | + Q_INVOKABLE static bool isGuestAllowed(const QString& name_OR_fulldirpath); |
692 | + |
693 | + static UserShareFile search(const QString& name_OR_fulldirpath); |
694 | + static UserShareFile readConfigFile(const QString& pathname); |
695 | + |
696 | +signals: |
697 | + static QString error(); |
698 | + |
699 | + |
700 | +private: |
701 | + static QString m_error; |
702 | + |
703 | +#if defined(REGRESSION_TEST_QSAMBACLIENT) |
704 | + friend class TestQSambaSuite; |
705 | +#endif |
706 | +}; |
707 | + |
708 | + |
709 | +#endif // SMBUSERSHARE_H |
PASSED: Continuous integration, rev:421 91.189. 93.70:8080/ job/ubuntu- filemanager- app-ci/ 496/ 91.189. 93.70:8080/ job/generic- mediumtests- utopic/ 2965 91.189. 93.70:8080/ job/generic- mediumtests- utopic/ 2965/artifact/ work/output/ *zip*/output. zip 91.189. 93.70:8080/ job/ubuntu- filemanager- app-utopic- amd64-ci/ 212 91.189. 93.70:8080/ job/ubuntu- filemanager- app-vivid- amd64-ci/ 118
http://
Executed test runs:
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: 91.189. 93.70:8080/ job/ubuntu- filemanager- app-ci/ 496/rebuild
http://