From: Kevin Ottens Date: Thu, 2 Jul 2020 15:22:43 +0000 (+0200) Subject: Add isE2eEncrypted column in the metadata table X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~222^2^2~116^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=7bb48a76c40a75a23c7e5c70d884d41b0fd595c2;p=nextcloud-desktop.git Add isE2eEncrypted column in the metadata table This will allow to exploit the information of a directory being encrypted or not during the discovery phase. Signed-off-by: Kevin Ottens --- diff --git a/src/common/syncjournaldb.cpp b/src/common/syncjournaldb.cpp index df3360879..d44f1f98b 100644 --- a/src/common/syncjournaldb.cpp +++ b/src/common/syncjournaldb.cpp @@ -47,7 +47,7 @@ Q_LOGGING_CATEGORY(lcDb, "nextcloud.sync.database", QtInfoMsg) #define GET_FILE_RECORD_QUERY \ "SELECT path, inode, modtime, type, md5, fileid, remotePerm, filesize," \ - " ignoredChildrenRemote, contentchecksumtype.name || ':' || contentChecksum, e2eMangledName " \ + " ignoredChildrenRemote, contentchecksumtype.name || ':' || contentChecksum, e2eMangledName, isE2eEncrypted " \ " FROM metadata" \ " LEFT JOIN checksumtype as contentchecksumtype ON metadata.contentChecksumTypeId == contentchecksumtype.id" @@ -64,6 +64,7 @@ static void fillFileRecordFromGetQuery(SyncJournalFileRecord &rec, SqlQuery &que rec._serverHasIgnoredFiles = (query.intValue(8) > 0); rec._checksumHeader = query.baValue(9); rec._e2eMangledName = query.baValue(10); + rec._isE2eEncrypted = query.intValue(11) > 0; } static QByteArray defaultJournalMode(const QString &dbPath) @@ -724,6 +725,16 @@ bool SyncJournalDb::updateMetadataTableStructure() commitInternal("update database structure: add e2eMangledName col"); } + if (!columns.contains("isE2eEncrypted")) { + SqlQuery query(_db); + query.prepare("ALTER TABLE metadata ADD COLUMN isE2eEncrypted INTEGER;"); + if (!query.exec()) { + sqlFail("updateMetadataTableStructure: add e2eMangledName column", query); + re = false; + } + commitInternal("update database structure: add e2eMangledName col"); + } + if (!tableColumns("uploadinfo").contains("contentChecksum")) { SqlQuery query(_db); query.prepare("ALTER TABLE uploadinfo ADD COLUMN contentChecksum TEXT;"); @@ -843,7 +854,8 @@ bool SyncJournalDb::setFileRecord(const SyncJournalFileRecord &_record) qCInfo(lcDb) << "Updating file record for path:" << record._path << "inode:" << record._inode << "modtime:" << record._modtime << "type:" << record._type << "etag:" << record._etag << "fileId:" << record._fileId << "remotePerm:" << record._remotePerm.toString() - << "fileSize:" << record._fileSize << "checksum:" << record._checksumHeader << "e2eMangledName:" << record._e2eMangledName; + << "fileSize:" << record._fileSize << "checksum:" << record._checksumHeader + << "e2eMangledName:" << record._e2eMangledName << "isE2eEncrypted:" << record._isE2eEncrypted; qlonglong phash = getPHash(record._path); if (checkConnect()) { @@ -862,8 +874,8 @@ bool SyncJournalDb::setFileRecord(const SyncJournalFileRecord &_record) if (!_setFileRecordQuery.initOrReset(QByteArrayLiteral( "INSERT OR REPLACE INTO metadata " - "(phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm, filesize, ignoredChildrenRemote, contentChecksum, contentChecksumTypeId, e2eMangledName) " - "VALUES (?1 , ?2, ?3 , ?4 , ?5 , ?6 , ?7, ?8 , ?9 , ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17);"), _db)) { + "(phash, pathlen, path, inode, uid, gid, mode, modtime, type, md5, fileid, remotePerm, filesize, ignoredChildrenRemote, contentChecksum, contentChecksumTypeId, e2eMangledName, isE2eEncrypted) " + "VALUES (?1 , ?2, ?3 , ?4 , ?5 , ?6 , ?7, ?8 , ?9 , ?10, ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18);"), _db)) { return false; } @@ -884,6 +896,7 @@ bool SyncJournalDb::setFileRecord(const SyncJournalFileRecord &_record) _setFileRecordQuery.bindValue(15, checksum); _setFileRecordQuery.bindValue(16, contentChecksumTypeId); _setFileRecordQuery.bindValue(17, record._e2eMangledName); + _setFileRecordQuery.bindValue(18, record._isE2eEncrypted); if (!_setFileRecordQuery.exec()) { return false; @@ -1272,6 +1285,7 @@ bool SyncJournalDb::setFileRecordMetadata(const SyncJournalFileRecord &record) existing._fileSize = record._fileSize; existing._serverHasIgnoredFiles = record._serverHasIgnoredFiles; existing._e2eMangledName = record._e2eMangledName; + existing._isE2eEncrypted = record._isE2eEncrypted; return setFileRecord(existing); } diff --git a/src/common/syncjournalfilerecord.h b/src/common/syncjournalfilerecord.h index 3124f7820..2bff92022 100644 --- a/src/common/syncjournalfilerecord.h +++ b/src/common/syncjournalfilerecord.h @@ -65,6 +65,7 @@ public: bool _serverHasIgnoredFiles = false; QByteArray _checksumHeader; QByteArray _e2eMangledName; + bool _isE2eEncrypted = false; }; bool OCSYNC_EXPORT diff --git a/src/csync/csync.cpp b/src/csync/csync.cpp index 48cdcc7d9..b07a3f4fe 100644 --- a/src/csync/csync.cpp +++ b/src/csync/csync.cpp @@ -340,5 +340,6 @@ std::unique_ptr csync_file_stat_s::fromSyncJournalFileRecord( st->has_ignored_files = rec._serverHasIgnoredFiles; st->checksumHeader = rec._checksumHeader; st->e2eMangledName = rec._e2eMangledName; + st->isE2eEncrypted = rec._isE2eEncrypted; return st; } diff --git a/src/csync/csync.h b/src/csync/csync.h index f23e9d21c..97895b2c2 100644 --- a/src/csync/csync.h +++ b/src/csync/csync.h @@ -173,6 +173,7 @@ struct OCSYNC_EXPORT csync_file_stat_s { // In both cases, the format is "SHA1:baff". QByteArray checksumHeader; QByteArray e2eMangledName; + bool isE2eEncrypted; CSYNC_STATUS error_status = CSYNC_STATUS_OK; @@ -183,6 +184,7 @@ struct OCSYNC_EXPORT csync_file_stat_s { , child_modified(false) , has_ignored_files(false) , is_hidden(false) + , isE2eEncrypted(false) { } static std::unique_ptr fromSyncJournalFileRecord(const OCC::SyncJournalFileRecord &rec); diff --git a/src/csync/csync_update.cpp b/src/csync/csync_update.cpp index 94351a3f8..f6f029ca6 100644 --- a/src/csync/csync_update.cpp +++ b/src/csync/csync_update.cpp @@ -203,7 +203,8 @@ static int _csync_detect_update(CSYNC *ctx, std::unique_ptr f if(base.isValid()) { /* there is an entry in the database */ // When the file is loaded from the file system it misses - // the e2e mangled name + // the e2e mangled name and e2e encryption status + fs->isE2eEncrypted = base._isE2eEncrypted; if (fs->e2eMangledName.isEmpty() && !base._e2eMangledName.isEmpty()) { fs->e2eMangledName = base._e2eMangledName; fs->path = base._path;