1 /*****************************************************************************
2  * Copyright (C) 2000 Shie Erlich <krusader@users.sourceforge.net>           *
3  * Copyright (C) 2000 Rafi Yanai <krusader@users.sourceforge.net>            *
4  * Copyright (C) 2004-2019 Krusader Krew [https://krusader.org]              *
5  *                                                                           *
6  * This file is part of Krusader [https://krusader.org].                     *
7  *                                                                           *
8  * Krusader is free software: you can redistribute it and/or modify          *
9  * it under the terms of the GNU General Public License as published by      *
10  * the Free Software Foundation, either version 2 of the License, or         *
11  * (at your option) any later version.                                       *
12  *                                                                           *
13  * Krusader is distributed in the hope that it will be useful,               *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
16  * GNU General Public License for more details.                              *
17  *                                                                           *
18  * You should have received a copy of the GNU General Public License         *
19  * along with Krusader.  If not, see [http://www.gnu.org/licenses/].         *
20  *****************************************************************************/
21 
22 
23 #ifndef KRPERMHANDLER_H
24 #define KRPERMHANDLER_H
25 
26 // QtCore
27 #include <QHash>
28 #include <QSet>
29 #include <QString>
30 
31 #include <KIO/Global>
32 
33 #include <time.h>
34 #include <stdlib.h>
35 #include <unistd.h>
36 
37 #define NO_PERM      0
38 #define UNKNOWN_PERM 1
39 #define ALLOWED_PERM 2
40 
41 class KRpermHandler
42 {
43 public:
44     static void init();
45 
46     static QString gid2group(gid_t groupId);
47     static QString uid2user(uid_t userId);
48 
49     static char writeable(const QString &perm, gid_t gid, uid_t uid);
50     static char readable(const QString &perm, gid_t gid, uid_t uid);
51     static char executable(const QString &perm, gid_t gid, uid_t uid);
52 
53     static char ftpWriteable(const QString &fileOwner, const QString & userName, const QString &perm);
54     static char ftpReadable(const QString &fileOwner, const QString &userName, const QString &perm);
55     static char ftpExecutable(const QString &fileOwner, const QString &userName, const QString &perm);
56 
57     static QString mode2QString(mode_t m);
58     static QString parseSize(KIO::filesize_t val);
59 
60 private:
KRpermHandler()61     KRpermHandler() {}
62     static char getLocalPermission(const QString &perm, gid_t gid, uid_t uid, int permOffset,
63                                    bool ignoreRoot = false);
64     static char getFtpPermission(const QString &fileOwner, const QString &userName,
65                                  const QString &perm, int permOffset);
66 
67     static QSet<int> currentGroups;
68     static QHash<int, QString> uidCache;
69     static QHash<int, QString> gidCache;
70 };
71 
72 #endif
73