Changeset View
Changeset View
Standalone View
Standalone View
src/buffer/katesecuretextbuffer_p.h
Show All 17 Lines | |||||
18 | * Boston, MA 02110-1301, USA. | 18 | * Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #ifndef KATE_SECURE_TEXTBUFFER_P_H | 21 | #ifndef KATE_SECURE_TEXTBUFFER_P_H | ||
22 | #define KATE_SECURE_TEXTBUFFER_P_H | 22 | #define KATE_SECURE_TEXTBUFFER_P_H | ||
23 | 23 | | |||
24 | #include <QObject> | 24 | #include <QObject> | ||
25 | #include <QString> | 25 | #include <QString> | ||
26 | #include <QCryptographicHash> | ||||
26 | 27 | | |||
27 | #include <kauth.h> | 28 | #include <kauth.h> | ||
28 | 29 | | |||
29 | using namespace KAuth; | 30 | using namespace KAuth; | ||
30 | 31 | | |||
31 | /** | 32 | /** | ||
32 | * Class used as KAuth helper binary. | 33 | * Class used as KAuth helper binary. | ||
33 | * It is supposed to be called through KAuth action. | 34 | * It is supposed to be called through KAuth action. | ||
34 | * | 35 | * | ||
35 | * It also contains couple of common methods intended to be used | 36 | * It also contains couple of common methods intended to be used | ||
36 | * directly by TextBuffer as well as from helper binary. | 37 | * directly by TextBuffer as well as from helper binary. | ||
37 | * | 38 | * | ||
38 | * This class should only be used by TextBuffer. | 39 | * This class should only be used by TextBuffer. | ||
39 | */ | 40 | */ | ||
40 | class SecureTextBuffer : public QObject | 41 | class SecureTextBuffer : public QObject | ||
41 | { | 42 | { | ||
42 | Q_OBJECT | 43 | Q_OBJECT | ||
43 | 44 | | |||
44 | public: | 45 | public: | ||
45 | 46 | | |||
46 | /** | | |||
47 | * We support Prepare action for temporary file creation | | |||
48 | * and Move action for moving final file to its destination | | |||
49 | */ | | |||
50 | enum ActionMode { | | |||
51 | Prepare = 1, | | |||
52 | Move = 2 | | |||
53 | }; | | |||
54 | | ||||
55 | SecureTextBuffer() {} | 47 | SecureTextBuffer() {} | ||
56 | 48 | | |||
57 | ~SecureTextBuffer() {} | 49 | ~SecureTextBuffer() {} | ||
58 | 50 | | |||
59 | /** | 51 | /** | ||
60 | * Common helper methods | 52 | * Common helper method | ||
61 | */ | 53 | */ | ||
62 | static void setOwner(const QString &filename, const uint ownerId, const uint groupId); | 54 | static void setOwner(const int filedes, const uint ownerId, const uint groupId); | ||
63 | static void syncToDisk(const int fd); | 55 | | ||
56 | static const QCryptographicHash::Algorithm checksumAlgorithm = QCryptographicHash::Algorithm::Sha512; | ||||
64 | 57 | | |||
65 | private: | 58 | private: | ||
66 | static const qint64 bufferLength = 4096; | 59 | static const qint64 bufferLength = 4096; | ||
67 | 60 | | |||
68 | /** | 61 | /** | ||
69 | * Creates temporary file based on given target file path. | 62 | * Saves file contents using sets permissions. | ||
70 | * Temporary file is set to not be deleted on object destroy | | |||
71 | * so KTextEditor can save contents in it. | | |||
72 | */ | 63 | */ | ||
73 | static QString prepareTempFileInternal(const QString &targetFile, const uint ownerId); | 64 | static bool saveFileInternal(const QString &sourceFile, const QString &targetFile, | ||
65 | const QByteArray &checksum, const uint ownerId, const uint groupId); | ||||
74 | 66 | | |||
75 | /** | 67 | static bool moveFile(const QString &sourceFile, const QString &targetFile); | ||
76 | * Move file to its given destination and set owner. | 68 | | ||
77 | */ | 69 | static void syncToDisk(const int fd); | ||
78 | static bool moveFileInternal(const QString &sourceFile, const QString &targetFile, const uint ownerId, const uint groupId); | | |||
79 | 70 | | |||
80 | public Q_SLOTS: | 71 | public Q_SLOTS: | ||
81 | /** | 72 | /** | ||
82 | * KAuth action to perform both prepare or move work based on given parameters. | 73 | * KAuth action to perform both prepare or move work based on given parameters. | ||
83 | * We keep this code in one method to prevent multiple KAuth user queries during one save action. | 74 | * We keep this code in one method to prevent multiple KAuth user queries during one save action. | ||
84 | */ | 75 | */ | ||
85 | static ActionReply savefile(const QVariantMap &args); | 76 | static ActionReply savefile(const QVariantMap &args); | ||
86 | 77 | | |||
87 | }; | 78 | }; | ||
88 | 79 | | |||
89 | #endif | 80 | #endif |