From ac748b4a9a90589ececf8dbbdbe525ce9fb3c557 Mon Sep 17 00:00:00 2001 From: Valient Gough Date: Tue, 29 Nov 2016 21:54:20 -0800 Subject: [PATCH] logging: switch to spdlog --- CMakeLists.txt | 8 ++-- encfs/BlockFileIO.cpp | 24 ++++++------ encfs/BlockNameIO.cpp | 10 ++--- encfs/CipherFileIO.cpp | 76 +++++++++++++++++++------------------- encfs/ConfigReader.cpp | 10 ++--- encfs/ConfigVar.cpp | 9 ++--- encfs/Context.cpp | 3 +- encfs/DirNode.cpp | 81 ++++++++++++++++++++--------------------- encfs/Error.cpp | 28 ++++++++------ encfs/Error.h | 26 ++++++------- encfs/FileNode.cpp | 10 ++--- encfs/FileUtils.cpp | 83 +++++++++++++++++++----------------------- encfs/Interface.cpp | 5 +-- encfs/MACFileIO.cpp | 11 +++--- encfs/NameIO.cpp | 1 - encfs/RawFileIO.cpp | 37 +++++++++---------- encfs/SSL_Cipher.cpp | 48 ++++++++++++------------ encfs/SSL_Compat.h | 6 +-- encfs/StreamNameIO.cpp | 5 +-- encfs/XmlReader.cpp | 13 +++---- encfs/base64.cpp | 4 +- encfs/encfs.cpp | 60 ++++++++++++++---------------- encfs/encfs.h | 8 ++-- encfs/encfsctl.cpp | 7 +--- encfs/main.cpp | 60 +++++++++++++----------------- encfs/makeKey.cpp | 2 - encfs/openssl.cpp | 2 +- encfs/test.cpp | 48 +++++++++++++----------- model/logging.c | 14 +++---- 29 files changed, 333 insertions(+), 366 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 62eab18..dd6450f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(EncFS C CXX) set (ENCFS_MAJOR 1) set (ENCFS_MINOR 9) -set (ENCFS_PATCH 1) +set (ENCFS_PATCH 2) set (ENCFS_VERSION "${ENCFS_MAJOR}.${ENCFS_MINOR}.${ENCFS_PATCH}") set (ENCFS_SOVERSION "${ENCFS_MAJOR}.${ENCFS_MINOR}") set (ENCFS_NAME "Encrypted Filesystem") @@ -64,6 +64,8 @@ add_definitions (-D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=26) find_package (OpenSSL REQUIRED) include_directories (${OPENSSL_INCLUDE_DIR}) +include_directories (${CMAKE_CURRENT_LIST_DIR}/internal) + if (USE_INTERNAL_TINYXML) message("-- Using local TinyXML2 copy") add_subdirectory(internal/tinyxml2-3.0.0) @@ -102,12 +104,10 @@ set (CMAKE_THREAD_PREFER_PTHREAD) find_package (Threads REQUIRED) # Logging. -add_definitions (-DELPP_THREAD_SAFE -DELPP_DISABLE_DEFAULT_CRASH_HANDLING) -add_definitions (-DELPP_NO_DEFAULT_LOG_FILE) check_include_file_cxx (syslog.h HAVE_SYSLOG_H) if (HAVE_SYSLOG_H) message ("-- Enabled syslog logging support") - add_definitions(-DELPP_SYSLOG) + add_definitions(-DSPDLOG_ENABLE_SYSLOG) endif (HAVE_SYSLOG_H) # Packaging config. diff --git a/encfs/BlockFileIO.cpp b/encfs/BlockFileIO.cpp index 032217d..88d1721 100644 --- a/encfs/BlockFileIO.cpp +++ b/encfs/BlockFileIO.cpp @@ -42,7 +42,7 @@ static void clearCache(IORequest &req, int blockSize) { BlockFileIO::BlockFileIO(int blockSize, const FSConfigPtr &cfg) : _blockSize(blockSize), _allowHoles(cfg->config->allowHoles) { - CHECK(_blockSize > 1); + rAssert(_blockSize > 1); _cache.data = new unsigned char[_blockSize]; _noCache = cfg->opts->noCache; } @@ -59,8 +59,8 @@ BlockFileIO::~BlockFileIO() { * returned data as neccessary. */ ssize_t BlockFileIO::cacheReadOneBlock(const IORequest &req) const { - CHECK(req.dataLen <= _blockSize); - CHECK(req.offset % _blockSize == 0); + rAssert(req.dataLen <= _blockSize); + rAssert(req.offset % _blockSize == 0); /* we can satisfy the request even if _cache.dataLen is too short, because * we always request a full block during reads. This just means we are @@ -113,7 +113,7 @@ bool BlockFileIO::cacheWriteOneBlock(const IORequest &req) { * lower layer. */ ssize_t BlockFileIO::read(const IORequest &req) const { - CHECK(_blockSize != 0); + rAssert(_blockSize != 0); int partialOffset = req.offset % _blockSize; off_t blockNum = req.offset / _blockSize; @@ -150,7 +150,7 @@ ssize_t BlockFileIO::read(const IORequest &req) const { if (readSize <= partialOffset) break; // didn't get enough bytes int cpySize = min((size_t)(readSize - partialOffset), size); - CHECK(cpySize <= readSize); + rAssert(cpySize <= readSize); // if we read to a temporary buffer, then move the data if (blockReq.data != out) @@ -172,7 +172,7 @@ ssize_t BlockFileIO::read(const IORequest &req) const { } bool BlockFileIO::write(const IORequest &req) { - CHECK(_blockSize != 0); + rAssert(_blockSize != 0); off_t fileSize = getSize(); if (fileSize < 0) return false; @@ -194,7 +194,7 @@ bool BlockFileIO::write(const IORequest &req) { padFile(fileSize, req.offset, forceWrite); } - // check against edge cases where we can just let the base class handle the + // rAssert against edge cases where we can just let the base class handle the // request as-is.. if (partialOffset == 0 && req.dataLen <= _blockSize) { // if writing a full block.. pretty safe.. @@ -297,7 +297,7 @@ void BlockFileIO::padFile(off_t oldSize, off_t newSize, bool forceWrite) { cacheWriteOneBlock(req); } } else - VLOG(1) << "optimization: not padding last block"; + LOG->debug("optimization: not padding last block"); } else { mb = MemoryPool::allocate(_blockSize); req.data = mb.data; @@ -311,7 +311,7 @@ void BlockFileIO::padFile(off_t oldSize, off_t newSize, bool forceWrite) { // 1. req.dataLen == 0, iff oldSize was already a multiple of blocksize if (req.dataLen != 0) { - VLOG(1) << "padding block " << oldLastBlock; + LOG->debug("padding block {}", oldLastBlock); memset(mb.data, 0, _blockSize); cacheReadOneBlock(req); req.dataLen = _blockSize; // expand to full block size @@ -322,7 +322,7 @@ void BlockFileIO::padFile(off_t oldSize, off_t newSize, bool forceWrite) { // 2, pad zero blocks unless holes are allowed if (!_allowHoles) { for (; oldLastBlock != newLastBlock; ++oldLastBlock) { - VLOG(1) << "padding block " << oldLastBlock; + LOG->debug("padding block {}", oldLastBlock); req.offset = oldLastBlock * _blockSize; req.dataLen = _blockSize; memset(mb.data, 0, req.dataLen); @@ -382,8 +382,8 @@ int BlockFileIO::truncateBase(off_t size, FileIO *base) { if ((rdSz < 0) || (!wrRes)) { // rwarning - unlikely to ever occur.. - RLOG(WARNING) << "truncate failure: read " << rdSz - << " bytes, partial block of " << partialBlock; + LOG->warn("truncate failure: read {} bytes, partial block of ", rdSz, + partialBlock); } MemoryPool::release(mb); diff --git a/encfs/BlockNameIO.cpp b/encfs/BlockNameIO.cpp index 0fdff9a..7314e7b 100644 --- a/encfs/BlockNameIO.cpp +++ b/encfs/BlockNameIO.cpp @@ -29,7 +29,6 @@ #include "Interface.h" #include "NameIO.h" #include "base64.h" -#include "internal/easylogging++.h" #include "intl/gettext.h" namespace encfs { @@ -187,7 +186,7 @@ int BlockNameIO::decodeName(const char *encodedName, int length, uint64_t *iv, // don't bother trying to decode files which are too small if (decodedStreamLen < _bs) { - VLOG(1) << "Rejecting filename " << encodedName; + LOG->debug("Rejecting filename {}", encodedName); throw Error("Filename too small to decode"); } @@ -218,8 +217,7 @@ int BlockNameIO::decodeName(const char *encodedName, int length, uint64_t *iv, // might happen if there is an error decoding.. if (padding > _bs || finalSize < 0) { - VLOG(1) << "padding, _bx, finalSize = " << padding << ", " << _bs << ", " - << finalSize; + LOG->debug("padding, _bx, finalSize = {}, {}, {}", padding, _bs, finalSize); throw Error("invalid padding size"); } @@ -235,8 +233,8 @@ int BlockNameIO::decodeName(const char *encodedName, int length, uint64_t *iv, BUFFER_RESET(tmpBuf); if (mac2 != mac) { - VLOG(1) << "checksum mismatch: expected " << mac << ", got " << mac2 - << " on decode of " << finalSize << " bytes"; + LOG->debug("checksum mismatch: expected {}, got {} on decode of {} bytes", + mac, mac2, finalSize); throw Error("checksum mismatch in filename decode"); } diff --git a/encfs/CipherFileIO.cpp b/encfs/CipherFileIO.cpp index 1a16dac..8c71f75 100644 --- a/encfs/CipherFileIO.cpp +++ b/encfs/CipherFileIO.cpp @@ -19,8 +19,8 @@ */ #include "CipherFileIO.h" +#include "Error.h" -#include "internal/easylogging++.h" #include #include #include @@ -32,7 +32,6 @@ #include "BlockFileIO.h" #include "Cipher.h" #include "CipherKey.h" -#include "Error.h" #include "FileIO.h" namespace encfs { @@ -59,8 +58,8 @@ CipherFileIO::CipherFileIO(const std::shared_ptr &_base, cipher = cfg->cipher; key = cfg->key; - CHECK_EQ(fsConfig->config->blockSize % fsConfig->cipher->cipherBlockSize(), 0) - << "FS block size must be multiple of cipher block size"; + CHECK_EQ(fsConfig->config->blockSize % fsConfig->cipher->cipherBlockSize(), + 0); } CipherFileIO::~CipherFileIO() {} @@ -82,15 +81,15 @@ void CipherFileIO::setFileName(const char *fileName) { const char *CipherFileIO::getFileName() const { return base->getFileName(); } bool CipherFileIO::setIV(uint64_t iv) { - VLOG(1) << "in setIV, current IV = " << externalIV << ", new IV = " << iv - << ", fileIV = " << fileIV; + LOG->debug("in setIV, current IV = {}, new IV = {}, fileIV = {}", externalIV, + iv, fileIV); if (externalIV == 0) { // we're just being told about which IV to use. since we haven't // initialized the fileIV, there is no need to just yet.. externalIV = iv; if (fileIV != 0) { - RLOG(WARNING) << "fileIV initialized before externalIV: " << fileIV - << ", " << externalIV; + LOG->warn("fileIV initialized before externalIV: {}, {}", fileIV, + externalIV); } } else if (haveHeader) { // we have an old IV, and now a new IV, so we need to update the fileIV @@ -105,7 +104,7 @@ bool CipherFileIO::setIV(uint64_t iv) { externalIV = iv; return base->setIV(iv); } else { - VLOG(1) << "writeHeader failed to re-open for write"; + LOG->debug("writeHeader failed to re-open for write"); return false; } } @@ -175,7 +174,7 @@ void CipherFileIO::initHeader() { // create one. off_t rawSize = base->getSize(); if (rawSize >= HEADER_SIZE) { - VLOG(1) << "reading existing header, rawSize = " << rawSize; + LOG->debug("reading existing header, rawSize = {}", rawSize); // has a header.. read it unsigned char buf[8] = {0}; @@ -192,7 +191,7 @@ void CipherFileIO::initHeader() { rAssert(fileIV != 0); // 0 is never used.. } else { - VLOG(1) << "creating new file IV header"; + LOG->debug("creating new file IV header"); unsigned char buf[8] = {0}; do { @@ -202,8 +201,9 @@ void CipherFileIO::initHeader() { fileIV = 0; for (int i = 0; i < 8; ++i) fileIV = (fileIV << 8) | (uint64_t)buf[i]; - if (fileIV == 0) - RLOG(WARNING) << "Unexpected result: randomize returned 8 null bytes!"; + if (fileIV == 0) { + LOG->warn("Unexpected result: randomize returned 8 null bytes!"); + } } while (fileIV == 0); // don't accept 0 as an option.. if (base->isWritable()) { @@ -216,10 +216,10 @@ void CipherFileIO::initHeader() { base->write(req); } else { - VLOG(1) << "base not writable, IV not written.."; + LOG->debug("base not writable, IV not written.."); } } - VLOG(1) << "initHeader finished, fileIV = " << fileIV; + LOG->debug("initHeader finished, fileIV = {}", fileIV); } bool CipherFileIO::writeHeader() { @@ -227,15 +227,15 @@ bool CipherFileIO::writeHeader() { // open for write.. int newFlags = lastFlags | O_RDWR; if (base->open(newFlags) < 0) { - VLOG(1) << "writeHeader failed to re-open for write"; + LOG->debug("writeHeader failed to re-open for write"); return false; } } if (fileIV == 0) { - RLOG(ERROR) << "Internal error: fileIV == 0 in writeHeader!!!"; + LOG->error("Internal error: fileIV == 0 in writeHeader!!!"); } - VLOG(1) << "writing fileIV " << fileIV; + LOG->debug("writing fileIV {}", fileIV); unsigned char buf[8] = {0}; for (int i = 0; i < 8; ++i) { @@ -275,7 +275,7 @@ void CipherFileIO::generateReverseHeader(unsigned char *headerBuf) { ino_t ino = stbuf.st_ino; rAssert(ino != 0); - VLOG(1) << "generating reverse file IV header from ino=" << ino; + LOG->debug("generating reverse file IV header from ino={}", ino); // Serialize the inode number into inoBuf unsigned char inoBuf[sizeof(ino_t)]; @@ -298,7 +298,7 @@ void CipherFileIO::generateReverseHeader(unsigned char *headerBuf) { fileIV = (fileIV << 8) | (uint64_t)headerBuf[i]; } - VLOG(1) << "fileIV=" << fileIV; + LOG->debug("fileIV={}", fileIV); // Encrypt externally-visible header cipher->streamEncode(headerBuf, HEADER_SIZE, externalIV, key); @@ -328,19 +328,19 @@ ssize_t CipherFileIO::readOneBlock(const IORequest &req) const { const_cast(this)->initHeader(); if (readSize != bs) { - VLOG(1) << "streamRead(data, " << readSize << ", IV)"; + LOG->debug("streamRead(data, {}, IV)", readSize); ok = streamRead(tmpReq.data, (int)readSize, blockNum ^ fileIV); } else { ok = blockRead(tmpReq.data, (int)readSize, blockNum ^ fileIV); } if (!ok) { - VLOG(1) << "decodeBlock failed for block " << blockNum << ", size " - << readSize; + LOG->debug("decodeBlock failed for block {}, size {}", blockNum, + readSize); readSize = -1; } } else { - VLOG(1) << "readSize zero for offset " << req.offset; + LOG->debug("readSize zero for offset {}", req.offset); } return readSize; @@ -349,8 +349,8 @@ ssize_t CipherFileIO::readOneBlock(const IORequest &req) const { bool CipherFileIO::writeOneBlock(const IORequest &req) { if (haveHeader && fsConfig->reverseEncryption) { - VLOG(1) - << "writing to a reverse mount with per-file IVs is not implemented"; + LOG->debug( + "writing to a reverse mount with per-file IVs is not implemented"); return false; } @@ -374,8 +374,8 @@ bool CipherFileIO::writeOneBlock(const IORequest &req) { } else ok = base->write(req); } else { - VLOG(1) << "encodeBlock failed for block " << blockNum << ", size " - << req.dataLen; + LOG->debug("encodeBlock failed for block {}, size {}", blockNum, + req.dataLen); ok = false; } return ok; @@ -383,7 +383,7 @@ bool CipherFileIO::writeOneBlock(const IORequest &req) { bool CipherFileIO::blockWrite(unsigned char *buf, int size, uint64_t _iv64) const { - VLOG(1) << "Called blockWrite"; + LOG->debug("Called blockWrite"); if (!fsConfig->reverseEncryption) return cipher->blockEncode(buf, size, _iv64, key); else @@ -392,7 +392,7 @@ bool CipherFileIO::blockWrite(unsigned char *buf, int size, bool CipherFileIO::streamWrite(unsigned char *buf, int size, uint64_t _iv64) const { - VLOG(1) << "Called streamWrite"; + LOG->debug("Called streamWrite"); if (!fsConfig->reverseEncryption) return cipher->streamEncode(buf, size, _iv64, key); else @@ -434,7 +434,7 @@ int CipherFileIO::truncate(off_t size) { // open for write.. int newFlags = lastFlags | O_RDWR; if (base->open(newFlags) < 0) - VLOG(1) << "writeHeader failed to re-open for write"; + LOG->debug("writeHeader failed to re-open for write"); } initHeader(); } @@ -456,13 +456,13 @@ ssize_t CipherFileIO::read(const IORequest &origReq) const { /* if reverse mode is not active with uniqueIV, * the read request is handled by the base class */ if (!(fsConfig->reverseEncryption && haveHeader)) { - VLOG(1) << "relaying request to base class: offset=" << origReq.offset - << ", dataLen=" << origReq.dataLen; + LOG->debug("relaying request to base class: offset={}, dataLen={}", + origReq.offset, origReq.dataLen); return BlockFileIO::read(origReq); } - VLOG(1) << "handling reverse unique IV read: offset=" << origReq.offset - << ", dataLen=" << origReq.dataLen; + LOG->debug("handling reverse unique IV read: offset={}, dataLen={}", + origReq.offset, origReq.dataLen); // generate the file IV header // this is needed in any case - without IV the file cannot be decoded @@ -484,7 +484,7 @@ ssize_t CipherFileIO::read(const IORequest &origReq) const { headerBytes = -req.offset; if (req.dataLen < headerBytes) headerBytes = req.dataLen; // only up to the number of bytes requested - VLOG(1) << "Adding " << headerBytes << " header bytes"; + LOG->debug("Adding {} header bytes", headerBytes); // copy the header bytes into the data int headerOffset = HEADER_SIZE - headerBytes; @@ -504,12 +504,12 @@ ssize_t CipherFileIO::read(const IORequest &origReq) const { // read the payload ssize_t readBytes = BlockFileIO::read(req); - VLOG(1) << "read " << readBytes << " bytes from backing file"; + LOG->debug("read {} bytes from backing file", readBytes); if (readBytes < 0) return readBytes; // Return error code else { ssize_t sum = headerBytes + readBytes; - VLOG(1) << "returning sum=" << sum; + LOG->debug("returning sum={}", sum); return sum; } } diff --git a/encfs/ConfigReader.cpp b/encfs/ConfigReader.cpp index e622ecf..88723c2 100644 --- a/encfs/ConfigReader.cpp +++ b/encfs/ConfigReader.cpp @@ -55,8 +55,8 @@ bool ConfigReader::load(const char *fileName) { close(fd); if (res != size) { - RLOG(WARNING) << "Partial read of config file, expecting " << size - << " bytes, got " << res; + LOG->warn("Partial read of config file, expecting {} bytes, got {}", size, + res); delete[] buf; return false; } @@ -79,7 +79,7 @@ bool ConfigReader::loadFromVar(ConfigVar &in) { in >> key >> value; if (key.length() == 0) { - RLOG(ERROR) << "Invalid key encoding in buffer"; + LOG->error("Invalid key encoding in buffer"); return false; } ConfigVar newVar(value); @@ -98,11 +98,11 @@ bool ConfigReader::save(const char *fileName) const { int retVal = ::write(fd, out.buffer(), out.size()); close(fd); if (retVal != out.size()) { - RLOG(ERROR) << "Error writing to config file " << fileName; + LOG->error("Error writing to config file {}", fileName); return false; } } else { - RLOG(ERROR) << "Unable to open or create file " << fileName; + LOG->error("Unable to open or create file {}", fileName); return false; } diff --git a/encfs/ConfigVar.cpp b/encfs/ConfigVar.cpp index a4fadc8..594ad84 100644 --- a/encfs/ConfigVar.cpp +++ b/encfs/ConfigVar.cpp @@ -18,12 +18,10 @@ * along with this program. If not, see . */ -#include "ConfigVar.h" - -#include "internal/easylogging++.h" +#include "Error.h" #include -#include "Error.h" +#include "ConfigVar.h" namespace encfs { @@ -194,8 +192,7 @@ const ConfigVar &operator>>(const ConfigVar &src, std::string &result) { } if (readLen != length) { - VLOG(1) << "string encoded as size " << length << " bytes, read " - << readLen; + LOG->debug("string encoded as size {} bytes, read {}", length, readLen); } rAssert(readLen == length); diff --git a/encfs/Context.cpp b/encfs/Context.cpp index 4cdcd36..152a5b3 100644 --- a/encfs/Context.cpp +++ b/encfs/Context.cpp @@ -18,12 +18,10 @@ * along with this program. If not, see . */ -#include "internal/easylogging++.h" #include #include "Context.h" #include "DirNode.h" -#include "Error.h" #include "Mutex.h" namespace encfs { @@ -44,6 +42,7 @@ EncFS_Context::~EncFS_Context() { // release all entries from map openFiles.clear(); } + std::shared_ptr EncFS_Context::getRoot(int *errCode) { std::shared_ptr ret; do { diff --git a/encfs/DirNode.cpp b/encfs/DirNode.cpp index 3612d6d..dc1a18f 100644 --- a/encfs/DirNode.cpp +++ b/encfs/DirNode.cpp @@ -27,6 +27,7 @@ #include #include "DirNode.h" +#include "Error.h" #include "FSConfig.h" #include "FileNode.h" #include "FileUtils.h" @@ -35,11 +36,9 @@ #include #endif -#include "internal/easylogging++.h" #include #include "Context.h" -#include "Error.h" #include "Mutex.h" using namespace std; @@ -101,7 +100,7 @@ std::string DirTraverse::nextPlaintextName(int *fileType, ino_t *inode) { return naming->decodePath(de->d_name, &localIv); } catch (encfs::Error &ex) { // .. .problem decoding, ignore it and continue on to next name.. - VLOG(1) << "error decoding filename: " << de->d_name; + LOG->debug("error decoding filename: {}", de->d_name); } } @@ -175,7 +174,7 @@ bool RenameOp::apply() { try { while (last != renameList->end()) { // backing store rename. - VLOG(1) << "renaming " << last->oldCName << " -> " << last->newCName; + LOG->debug("renaming {} -> {}", last->oldCName, last->newCName); struct stat st; bool preserve_mtime = ::stat(last->oldCName.c_str(), &st) == 0; @@ -185,8 +184,7 @@ bool RenameOp::apply() { // rename on disk.. if (::rename(last->oldCName.c_str(), last->newCName.c_str()) == -1) { - RLOG(WARNING) << "Error renaming " << last->oldCName << ": " - << strerror(errno); + LOG->warn("Error renaming {}: {}", last->oldCName, strerror(errno)); dn->renameNode(last->newPName.c_str(), last->oldPName.c_str(), false); return false; } @@ -203,16 +201,16 @@ bool RenameOp::apply() { return true; } catch (encfs::Error &err) { - RLOG(WARNING) << err.what(); + LOG->warn(err.what()); return false; } } void RenameOp::undo() { - VLOG(1) << "in undoRename"; + LOG->debug("in undoRename"); if (last == renameList->begin()) { - VLOG(1) << "nothing to undo"; + LOG->debug("nothing to undo"); return; // nothing to undo } @@ -224,19 +222,19 @@ void RenameOp::undo() { while (it != renameList->begin()) { --it; - VLOG(1) << "undo: renaming " << it->newCName << " -> " << it->oldCName; + LOG->debug("undo: renaming {} -> {}", it->newCName, it->oldCName); ::rename(it->newCName.c_str(), it->oldCName.c_str()); try { dn->renameNode(it->newPName.c_str(), it->oldPName.c_str(), false); } catch (encfs::Error &err) { - RLOG(WARNING) << err.what(); + LOG->warn(err.what()); // continue on anyway... } ++undoCount; }; - RLOG(WARNING) << "Undo rename count: " << undoCount; + LOG->warn("Undo rename count: {}", undoCount); } DirNode::DirNode(EncFS_Context *_ctx, const string &sourceDir, @@ -329,7 +327,7 @@ string DirNode::plainPath(const char *cipherPath_) { // Default. return naming->decodePath(cipherPath_); } catch (encfs::Error &err) { - RLOG(ERROR) << "decode err: " << err.what(); + LOG->error("decode err: {}", err.what()); return string(); } } @@ -345,7 +343,7 @@ string DirNode::relativeCipherPath(const char *plaintextPath) { return naming->encodePath(plaintextPath); } catch (encfs::Error &err) { - RLOG(ERROR) << "encode err: " << err.what(); + LOG->error("encode err: {}", err.what()); return string(); } } @@ -355,7 +353,7 @@ DirTraverse DirNode::openDir(const char *plaintextPath) { DIR *dir = ::opendir(cyName.c_str()); if (dir == NULL) { - VLOG(1) << "opendir error " << strerror(errno); + LOG->debug("opendir error: {}", strerror(errno)); return DirTraverse(shared_ptr(), 0, std::shared_ptr()); } else { std::shared_ptr dp(dir, DirDeleter()); @@ -366,7 +364,7 @@ DirTraverse DirNode::openDir(const char *plaintextPath) { try { if (naming->getChainedNameIV()) naming->encodePath(plaintextPath, &iv); } catch (encfs::Error &err) { - RLOG(ERROR) << "encode err: " << err.what(); + LOG->error("encode err: {}", err.what()); } return DirTraverse(dp, iv, naming); } @@ -387,7 +385,7 @@ bool DirNode::genRenameList(list &renameList, const char *fromP, if (fromIV == toIV) return true; // generate the real destination path, where we expect to find the files.. - VLOG(1) << "opendir " << sourcePath; + LOG->debug("opendir {}", sourcePath); std::shared_ptr dir = std::shared_ptr(opendir(sourcePath.c_str()), DirDeleter()); if (!dir) return false; @@ -449,15 +447,15 @@ bool DirNode::genRenameList(list &renameList, const char *fromP, } } - VLOG(1) << "adding file " << oldFull << " to rename list"; + LOG->debug("adding file {} to rename list", oldFull); renameList.push_back(ren); } catch (encfs::Error &err) { // We can't convert this name, because we don't have a valid IV for // it (or perhaps a valid key).. It will be inaccessible.. - RLOG(WARNING) << "Aborting rename: error on file: " - << fromCPart.append(1, '/').append(de->d_name); - RLOG(WARNING) << err.what(); + LOG->warn("Aborting rename: error on file: {}", + fromCPart.append(1, '/').append(de->d_name)); + LOG->warn(err.what()); // abort.. Err on the side of safety and disallow rename, rather // then loosing files.. @@ -481,7 +479,7 @@ bool DirNode::genRenameList(list &renameList, const char *fromP, // Undo everything if we encounter an error! std::shared_ptr > renameList(new list); if (!genRenameList(*renameList.get(), fromP, toP)) { - RLOG(WARNING) << "Error during generation of recursive rename list"; + LOG->warn("Error during generation of recursive rename list"); return std::shared_ptr(); } else return std::shared_ptr(new RenameOp(this, renameList)); @@ -492,7 +490,7 @@ int DirNode::mkdir(const char *plaintextPath, mode_t mode, uid_t uid, string cyName = rootDir + naming->encodePath(plaintextPath); rAssert(!cyName.empty()); - VLOG(1) << "mkdir on " << cyName; + LOG->debug("mkdir on {}", cyName); // if uid or gid are set, then that should be the directory owner int olduid = -1; @@ -507,8 +505,7 @@ int DirNode::mkdir(const char *plaintextPath, mode_t mode, uid_t uid, if (res == -1) { int eno = errno; - RLOG(WARNING) << "mkdir error on " << cyName << " mode " << mode << ": " - << strerror(eno); + LOG->warn("mkdir error on {} mode {}: {}", cyName, mode, strerror(eno)); res = -eno; } else res = 0; @@ -524,22 +521,22 @@ int DirNode::rename(const char *fromPlaintext, const char *toPlaintext) { rAssert(!fromCName.empty()); rAssert(!toCName.empty()); - VLOG(1) << "rename " << fromCName << " -> " << toCName; + LOG->debug("rename {} -> {}", fromCName, toCName); std::shared_ptr toNode = findOrCreate(toPlaintext); std::shared_ptr renameOp; if (hasDirectoryNameDependency() && isDirectory(fromCName.c_str())) { - VLOG(1) << "recursive rename begin"; + LOG->debug("recursive rename begin"); renameOp = newRenameOp(fromPlaintext, toPlaintext); if (!renameOp || !renameOp->apply()) { if (renameOp) renameOp->undo(); - RLOG(WARNING) << "rename aborted"; + LOG->warn("rename aborted"); return -EACCES; } - VLOG(1) << "recursive rename end"; + LOG->debug("recursive rename end"); } int res = 0; @@ -564,12 +561,12 @@ int DirNode::rename(const char *fromPlaintext, const char *toPlaintext) { } } catch (encfs::Error &err) { // exception from renameNode, just show the error and continue.. - RLOG(WARNING) << err.what(); + LOG->warn(err.what()); res = -EIO; } if (res != 0) { - VLOG(1) << "rename failed: " << strerror(errno); + LOG->debug("rename failed: {}", strerror(errno)); res = -errno; } @@ -585,11 +582,11 @@ int DirNode::link(const char *from, const char *to) { rAssert(!fromCName.empty()); rAssert(!toCName.empty()); - VLOG(1) << "link " << fromCName << " -> " << toCName; + LOG->debug("link {} -> {}", fromCName, toCName); int res = -EPERM; if (fsConfig->config->externalIVChaining) { - VLOG(1) << "hard links not supported with external IV chaining!"; + LOG->debug("hard links not supported with external IV chaining!"); } else { res = ::link(fromCName.c_str(), toCName.c_str()); if (res == -1) @@ -616,14 +613,13 @@ std::shared_ptr DirNode::renameNode(const char *from, const char *to, uint64_t newIV = 0; string cname = rootDir + naming->encodePath(to, &newIV); - VLOG(1) << "renaming internal node " << node->cipherName() << " -> " - << cname; + LOG->debug("renaming internal node {} -> {}", node->cipherName(), cname); if (node->setName(to, cname.c_str(), newIV, forwardMode)) { if (ctx) ctx->renameNode(from, to); } else { // rename error! - put it back - RLOG(ERROR) << "renameNode failed"; + LOG->error("renameNode failed"); throw Error("Internal node name change failed!"); } } @@ -641,7 +637,7 @@ std::shared_ptr DirNode::findOrCreate(const char *plainName) { if (fsConfig->config->externalIVChaining) node->setName(0, 0, iv); - VLOG(1) << "created FileNode for " << node->cipherName(); + LOG->debug("created FileNode for {}", node->cipherName()); } return node; @@ -674,7 +670,7 @@ shared_ptr DirNode::lookupNode(const char *plainName, int DirNode::unlink(const char *plaintextName) { string cyName = naming->encodePath(plaintextName); - VLOG(1) << "unlink " << cyName; + LOG->debug("unlink {}", cyName); Lock _lock(mutex); @@ -683,16 +679,17 @@ int DirNode::unlink(const char *plaintextName) { // If FUSE is running with "hard_remove" option where it doesn't // hide open files for us, then we can't allow an unlink of an open // file.. - RLOG(WARNING) << "Refusing to unlink open file: " << cyName - << ", hard_remove option " - "is probably in effect"; + LOG->warn( + "Refusing to unlink open file: {}, " + ", hard_remove option is probably in effect", + cyName); res = -EBUSY; } else { string fullName = rootDir + cyName; res = ::unlink(fullName.c_str()); if (res == -1) { res = -errno; - VLOG(1) << "unlink error: " << strerror(errno); + LOG->debug("unlink error: {}", strerror(errno)); } } diff --git a/encfs/Error.cpp b/encfs/Error.cpp index bbb90ce..31d91a4 100644 --- a/encfs/Error.cpp +++ b/encfs/Error.cpp @@ -1,23 +1,29 @@ #include "Error.h" +#include namespace encfs { -el::base::DispatchAction rlogAction = el::base::DispatchAction::NormalLog; - Error::Error(const char *msg) : runtime_error(msg) {} void initLogging(bool enable_debug) { - el::Loggers::addFlag(el::LoggingFlag::ColoredTerminalOutput); + // Multithreaded console logger(with color support) + auto console = spdlog::stdout_color_mt("global"); - el::Configurations defaultConf; - defaultConf.setToDefault(); - defaultConf.set(el::Level::Verbose, el::ConfigurationType::Format, - std::string("%datetime %level [%fbase:%line] %msg")); - defaultConf.set(el::Level::Global, el::ConfigurationType::ToFile, "false"); - if (!enable_debug) { - defaultConf.set(el::Level::Debug, el::ConfigurationType::Enabled, "false"); + if (enable_debug) { + console->set_level(spdlog::level::debug); + } else { + console->set_level(spdlog::level::info); } - el::Loggers::reconfigureLogger("default", defaultConf); +} + +void enable_syslog() { + spdlog::drop("global"); + std::string ident = "encfs"; +#ifdef SPDLOG_ENABLE_SYSLOG + auto logger = spdlog::syslog_logger("global", ident, LOG_PID); +#else + LOG->info("syslog not supported") +#endif } } // namespace encfs diff --git a/encfs/Error.h b/encfs/Error.h index bcedd43..a6c22e3 100644 --- a/encfs/Error.h +++ b/encfs/Error.h @@ -3,11 +3,13 @@ // Provides compatibility with RLog's rAssert, which throws an Error exception. -#include "internal/easylogging++.h" +#include "spdlog/spdlog.h" #include namespace encfs { +#define LOG spdlog::get("global") + class Error : public std::runtime_error { public: Error(const char *msg); @@ -15,22 +17,20 @@ class Error : public std::runtime_error { #define STR(X) #X -#define rAssert(cond) \ - do { \ - if ((cond) == false) { \ - RLOG(ERROR) << "Assert failed: " << STR(cond); \ - throw encfs::Error(STR(cond)); \ - } \ +#define rAssert(cond) \ + do { \ + if ((cond) == false) { \ + LOG->error("Assert failed: {}", STR(cond)); \ + throw encfs::Error(STR(cond)); \ + } \ } while (0) +#define CHECK_EQ(l, r) rAssert(l == r) + void initLogging(bool enable_debug = false); -// This can be changed to change log action between normal and syslog logging. -// Not thread-safe, so any change must occur outside of threading context. -extern el::base::DispatchAction rlogAction; - -#define RLOG(LEVEL, ...) \ - C##LEVEL(el::base::Writer, rlogAction, ELPP_CURR_FILE_LOGGER_ID) +// Calling enable_syslog replaces the logger sink with a syslog sink. +void enable_syslog(); } // namespace encfs diff --git a/encfs/FileNode.cpp b/encfs/FileNode.cpp index dea5a1a..c5ac4d3 100644 --- a/encfs/FileNode.cpp +++ b/encfs/FileNode.cpp @@ -100,7 +100,7 @@ static bool setIV(const std::shared_ptr &io, uint64_t iv) { bool FileNode::setName(const char *plaintextName_, const char *cipherName_, uint64_t iv, bool setIVFirst) { // Lock _lock( mutex ); - if (cipherName_) VLOG(1) << "calling setIV on " << cipherName_; + if (cipherName_) LOG->debug("calling setIV on {}", cipherName_); if (setIVFirst) { if (fsConfig->config->externalIVChaining && !setIV(io, iv)) return false; @@ -140,14 +140,14 @@ int FileNode::mknod(mode_t mode, dev_t rdev, uid_t uid, gid_t gid) { if (uid != 0) { olduid = setfsuid(uid); if (olduid == -1) { - RLOG(DEBUG) << "setfsuid error: " << strerror(errno); + LOG->debug("setfsuid error: {}", strerror(errno)); return -EPERM; } } if (gid != 0) { oldgid = setfsgid(gid); if (oldgid == -1) { - RLOG(DEBUG) << "setfsgid error: " << strerror(errno); + LOG->debug("setfsgid error: {}", strerror(errno)); return -EPERM; } } @@ -170,7 +170,7 @@ int FileNode::mknod(mode_t mode, dev_t rdev, uid_t uid, gid_t gid) { if (res == -1) { int eno = errno; - VLOG(1) << "mknod error: " << strerror(eno); + LOG->debug("mknod error: {]}", strerror(eno)); res = -eno; } @@ -210,7 +210,7 @@ ssize_t FileNode::read(off_t offset, unsigned char *data, ssize_t size) const { } bool FileNode::write(off_t offset, unsigned char *data, ssize_t size) { - VLOG(1) << "FileNode::write offset " << offset << ", data size " << size; + LOG->debug("FileNode::write offset {}, data size {}", offset, size); IORequest req; req.offset = offset; diff --git a/encfs/FileUtils.cpp b/encfs/FileUtils.cpp index edd2b71..4d0526e 100644 --- a/encfs/FileUtils.cpp +++ b/encfs/FileUtils.cpp @@ -18,13 +18,6 @@ * along with this program. If not, see . */ -// defines needed for RedHat 7.3... -#ifdef linux -#define _XOPEN_SOURCE 500 // make sure pwrite() is pulled in -#endif -#define _BSD_SOURCE // pick up setenv on RH7.3 - -#include "internal/easylogging++.h" #include #include #include @@ -214,11 +207,10 @@ ConfigType readConfig_load(ConfigInfo *nm, const char *path, return nm->type; } } catch (encfs::Error &err) { - RLOG(ERROR) << "readConfig error: " << err.what(); + LOG->error("readConfig error: {}", err.what()); } - RLOG(ERROR) << "Found config file " << path - << ", but failed to load - exiting"; + LOG->error("Found config file {}, but failed to load - exiting", path); exit(1); } else { // No load function - must be an unsupported type.. @@ -239,9 +231,9 @@ ConfigType readConfig(const string &rootDir, EncFSConfig *config) { char *envFile = getenv(nm->environmentOverride); if (envFile != NULL) { if (!fileExists(envFile)) { - RLOG(ERROR) - << "fatal: config file specified by environment does not exist: " - << envFile; + LOG->error( + "fatal: config file specified by environment does not exist: {}", + envFile); exit(1); } return readConfig_load(nm, envFile, config); @@ -268,7 +260,7 @@ bool readV6Config(const char *configFile, EncFSConfig *cfg, ConfigInfo *info) { XmlReader rdr; if (!rdr.load(configFile)) { - RLOG(ERROR) << "Failed to load config file " << configFile; + LOG->error("Failed to load config file {}", configFile); return false; } @@ -278,34 +270,34 @@ bool readV6Config(const char *configFile, EncFSConfig *cfg, ConfigInfo *info) { config = (*serialization)["config"]; } if (!config) { - RLOG(ERROR) << "Unable to find XML configuration in file " << configFile; + LOG->error("Unable to find XML configuration in file {}", configFile); return false; } int version; if (!config->read("version", &version) && !config->read("@version", &version)) { - RLOG(ERROR) << "Unable to find version in config file"; + LOG->error("Unable to find version in config file"); return false; } // version numbering was complicated by boost::archive if (version == 20 || version >= 20100713) { - VLOG(1) << "found new serialization format"; + LOG->debug("found new serialization format"); cfg->subVersion = version; } else if (version == 26800) { - VLOG(1) << "found 20080816 version"; + LOG->debug("found 20080816 version"); cfg->subVersion = 20080816; } else if (version == 26797) { - VLOG(1) << "found 20080813"; + LOG->debug("found 20080813"); cfg->subVersion = 20080813; } else if (version < V5SubVersion) { - RLOG(ERROR) << "Invalid version " << version << " - please fix config file"; + LOG->error("Invalid version {} - please fix config file", version); } else { - VLOG(1) << "Boost <= 1.41 compatibility mode"; + LOG->debug("Boost <= 1.41 compatibility mode"); cfg->subVersion = version; } - VLOG(1) << "subVersion = " << cfg->subVersion; + LOG->debug("subVersion = {}", cfg->subVersion); config->read("creator", &cfg->creator); config->read("cipherAlg", &cfg->cipherIface); @@ -363,14 +355,16 @@ bool readV5Config(const char *configFile, EncFSConfig *config, if (config->subVersion > info->currentSubVersion) { /* config file specifies a version outside our supported range.. */ - RLOG(WARNING) << "Config subversion " << config->subVersion - << " found, which is newer than supported version " - << info->currentSubVersion; + LOG->warn( + "Config subversion {} found, which is newer than supported version " + "{}", + config->subVersion, info->currentSubVersion); return false; } if (config->subVersion < 20040813) { - RLOG(ERROR) << "This version of EncFS doesn't support " - "filesystems created before 2004-08-13"; + LOG->error( + "This version of EncFS doesn't support " + "filesystems created before 2004-08-13"); return false; } @@ -391,8 +385,8 @@ bool readV5Config(const char *configFile, EncFSConfig *config, ok = true; } catch (encfs::Error &err) { - RLOG(WARNING) << err.what(); - VLOG(1) << "Error parsing data in config file " << configFile; + LOG->warn(err.what()); + LOG->debug("Error parsing data in config file {}", configFile); ok = false; } } @@ -431,8 +425,8 @@ bool readV4Config(const char *configFile, EncFSConfig *config, ok = true; } catch (encfs::Error &err) { - RLOG(WARNING) << err.what(); - VLOG(1) << "Error parsing config file " << configFile; + LOG->warn(err.what()); + LOG->debug("Error parsing config file {}", configFile); ok = false; } } @@ -457,7 +451,7 @@ bool saveConfig(ConfigType type, const string &rootDir, try { ok = (*nm->saveFunc)(path.c_str(), config); } catch (encfs::Error &err) { - RLOG(WARNING) << err.what(); + LOG->warn(err.what()); ok = false; } break; @@ -956,9 +950,9 @@ RootPtr createV6Config(EncFS_Context *ctx, const std::string passwordProgram = opts->passwordProgram; bool useStdin = opts->useStdin; bool reverseEncryption = opts->reverseEncryption; - ConfigMode configMode = (useStdin && - opts->configMode == Config_Prompt) ? Config_Standard - : opts->configMode; + ConfigMode configMode = (useStdin && opts->configMode == Config_Prompt) + ? Config_Standard + : opts->configMode; bool annotate = opts->annotate; RootPtr rootInfo; @@ -1104,8 +1098,8 @@ RootPtr createV6Config(EncFS_Context *ctx, alg.name.c_str(), keySize, blockSize); return rootInfo; } else { - VLOG(1) << "Using cipher " << alg.name << ", key size " << keySize - << ", block size " << blockSize; + LOG->debug("Using cipher {}, key size {}, block size ", alg.name, keySize, + blockSize); } std::shared_ptr config(new EncFSConfig); @@ -1162,7 +1156,7 @@ RootPtr createV6Config(EncFS_Context *ctx, // get user key and use it to encode volume key CipherKey userKey; - VLOG(1) << "useStdin: " << useStdin; + LOG->debug("useStdin: {}", useStdin); if (useStdin) { if (annotate) cerr << "$PROMPT$ new_passwd" << endl; userKey = config->getUserKey(useStdin); @@ -1171,8 +1165,7 @@ RootPtr createV6Config(EncFS_Context *ctx, else userKey = config->getNewUserKey(); - if (userKey == nullptr) - return rootInfo; + if (userKey == nullptr) return rootInfo; cipher->writeKey(volumeKey, encodedKey, userKey); userKey.reset(); @@ -1439,7 +1432,7 @@ CipherKey EncFSConfig::getUserKey(const std::string &passProg, perror(_("Internal error: socketpair() failed")); return result; } - VLOG(1) << "getUserKey: fds = " << fds[0] << ", " << fds[1]; + LOG->debug("getUserKey: fds = {}, {}", fds[0], fds[1]); pid = fork(); if (pid == -1) { @@ -1577,7 +1570,7 @@ RootPtr initFS(EncFS_Context *ctx, const std::shared_ptr &opts) { CipherKey userKey; if (opts->passwordProgram.empty()) { - VLOG(1) << "useStdin: " << opts->useStdin; + LOG->debug("useStdin: {}", opts->useStdin); if (opts->annotate) cerr << "$PROMPT$ passwd" << endl; userKey = config->getUserKey(opts->useStdin); } else @@ -1585,7 +1578,7 @@ RootPtr initFS(EncFS_Context *ctx, const std::shared_ptr &opts) { if (!userKey) return rootInfo; - VLOG(1) << "cipher key size = " << cipher->encodedKeySize(); + LOG->debug("cipher key size = {}", cipher->encodedKeySize()); // decode volume key.. CipherKey volumeKey = cipher->readKey(config->getKeyData(), userKey, opts->checkKey); @@ -1639,14 +1632,14 @@ RootPtr initFS(EncFS_Context *ctx, const std::shared_ptr &opts) { } int remountFS(EncFS_Context *ctx) { - VLOG(1) << "Attempting to reinitialize filesystem"; + LOG->debug("Attempting to reinitialize filesystem"); RootPtr rootInfo = initFS(ctx, ctx->opts); if (rootInfo) { ctx->setRoot(rootInfo->root); return 0; } else { - RLOG(WARNING) << "Remount failed"; + LOG->warn("Remount failed"); return -EACCES; } } diff --git a/encfs/Interface.cpp b/encfs/Interface.cpp index 8cd8def..73e9b52 100644 --- a/encfs/Interface.cpp +++ b/encfs/Interface.cpp @@ -107,9 +107,8 @@ static int diffSum(const Interface &A, const Interface &B) { const int EqualVersion = (1 * 3 + 1) * 3 + 1; bool Interface::implements(const Interface &B) const { - VLOG(1) << "checking if " << name() << "(" << current() << ":" << revision() - << ":" << age() << ") implements " << B.name() << "(" << B.current() - << ":" << B.revision() << ")"; + LOG->debug("checking if {} ({}:{}:{}) implements {} ({}:{})", name(), + current(), revision(), age(), B.name(), B.current(), B.revision()); if (name() != B.name()) return false; diff --git a/encfs/MACFileIO.cpp b/encfs/MACFileIO.cpp index cf2760c..7635433 100644 --- a/encfs/MACFileIO.cpp +++ b/encfs/MACFileIO.cpp @@ -20,7 +20,6 @@ #include "MACFileIO.h" -#include "internal/easylogging++.h" #include #include #include @@ -67,9 +66,9 @@ MACFileIO::MACFileIO(const std::shared_ptr &_base, warnOnly(cfg->opts->forceDecode) { rAssert(macBytes >= 0 && macBytes <= 8); rAssert(randBytes >= 0); - VLOG(1) << "fs block size = " << cfg->config->blockSize - << ", macBytes = " << cfg->config->blockMACBytes - << ", randBytes = " << cfg->config->blockMACRandBytes; + LOG->debug("fs block size = {}, macBytes = {}, randBytes = {}", + cfg->config->blockSize, cfg->config->blockMACBytes, + cfg->config->blockMACRandBytes); } MACFileIO::~MACFileIO() {} @@ -187,7 +186,7 @@ ssize_t MACFileIO::readOneBlock(const IORequest &req) const { if (fail > 0) { // uh oh.. long blockNum = req.offset / bs; - RLOG(WARNING) << "MAC comparison failure in block " << blockNum; + LOG->warn("MAC comparison failure in block {}", blockNum); if (!warnOnly) { MemoryPool::release(mb); throw Error(_("MAC comparison failure, refusing to read")); @@ -199,7 +198,7 @@ ssize_t MACFileIO::readOneBlock(const IORequest &req) const { readSize -= headerSize; memcpy(req.data, tmp.data + headerSize, readSize); } else { - VLOG(1) << "readSize " << readSize << " at offset " << req.offset; + LOG->debug("readSize {} at offset {}", readSize, req.offset); if (readSize > 0) readSize = 0; } diff --git a/encfs/NameIO.cpp b/encfs/NameIO.cpp index 6495586..db825e3 100644 --- a/encfs/NameIO.cpp +++ b/encfs/NameIO.cpp @@ -20,7 +20,6 @@ #include "NameIO.h" -#include "internal/easylogging++.h" #include // for static build. Need to reference the modules which are registered at // run-time, to ensure that the linker doesn't optimize them away. diff --git a/encfs/RawFileIO.cpp b/encfs/RawFileIO.cpp index accb3fd..382401e 100644 --- a/encfs/RawFileIO.cpp +++ b/encfs/RawFileIO.cpp @@ -21,7 +21,6 @@ #ifdef linux #define _XOPEN_SOURCE 500 // pick up pread , pwrite #endif -#include "internal/easylogging++.h" #include #include #include @@ -96,7 +95,7 @@ static int open_readonly_workaround(const char *path, int flags) { fd = ::open(path, flags); chmod(path, stbuf.st_mode); } else { - RLOG(INFO) << "can't stat file " << path; + LOG->info("can't stat file {}", path); } return fd; @@ -113,13 +112,13 @@ static int open_readonly_workaround(const char *path, int flags) { */ int RawFileIO::open(int flags) { bool requestWrite = ((flags & O_RDWR) || (flags & O_WRONLY)); - VLOG(1) << "open call, requestWrite = " << requestWrite; + LOG->debug("open call, requestWrite = {]}", requestWrite); int result = 0; // if we have a descriptor and it is writable, or we don't need writable.. if ((fd >= 0) && (canWrite || !requestWrite)) { - VLOG(1) << "using existing file descriptor"; + LOG->debug("using existing file descriptor"); result = fd; // success } else { int finalFlags = requestWrite ? O_RDWR : O_RDONLY; @@ -132,17 +131,17 @@ int RawFileIO::open(int flags) { int newFd = ::open(name.c_str(), finalFlags); - VLOG(1) << "open file with flags " << finalFlags << ", result = " << newFd; + LOG->debug("open file with flags {}, result = {}", finalFlags, newFd); if ((newFd == -1) && (errno == EACCES)) { - VLOG(1) << "using readonly workaround for open"; + LOG->debug("using readonly workaround for open"); newFd = open_readonly_workaround(name.c_str(), finalFlags); } if (newFd >= 0) { if (oldfd >= 0) { - RLOG(ERROR) << "leaking FD?: oldfd = " << oldfd << ", fd = " << fd - << ", newfd = " << newFd; + LOG->error("leaking FD?: oldfd = {}, fs = {}, newfd = {}", oldfd, fd, + newFd); } // the old fd might still be in use, so just keep it around for @@ -152,7 +151,7 @@ int RawFileIO::open(int flags) { result = fd = newFd; } else { result = -errno; - RLOG(DEBUG) << "::open error: " << strerror(errno); + LOG->debug("::open error: {}", strerror(errno)); } } @@ -164,7 +163,7 @@ int RawFileIO::getAttr(struct stat *stbuf) const { int eno = errno; if (res < 0) { - RLOG(DEBUG) << "getAttr error on " << name << ": " << strerror(eno); + LOG->debug("getAttr error on {}: {}", name, strerror(eno)); } return (res < 0) ? -eno : 0; @@ -185,7 +184,7 @@ off_t RawFileIO::getSize() const { const_cast(this)->knownSize = true; return fileSize; } else { - RLOG(ERROR) << "getSize on " << name << " failed: " << strerror(errno); + LOG->error("getSize on {} failed: {}", name, strerror(errno)); return -1; } } else { @@ -199,8 +198,8 @@ ssize_t RawFileIO::read(const IORequest &req) const { ssize_t readSize = pread(fd, req.data, req.dataLen, req.offset); if (readSize < 0) { - RLOG(WARNING) << "read failed at offset " << req.offset << " for " - << req.dataLen << " bytes: " << strerror(errno); + LOG->warn("read failed at offset {} for {} bytes: {}", req.offset, + req.dataLen, strerror(errno)); } return readSize; @@ -220,8 +219,8 @@ bool RawFileIO::write(const IORequest &req) { if (writeSize < 0) { knownSize = false; - RLOG(WARNING) << "write failed at offset " << offset << " for " << bytes - << " bytes: " << strerror(errno); + LOG->warn("write failed at offset {} for {} bytes: {}", offset, bytes, + strerror(errno)); return false; } @@ -232,8 +231,8 @@ bool RawFileIO::write(const IORequest &req) { } if (bytes != 0) { - RLOG(ERROR) << "Write error: wrote " << req.dataLen - bytes << " bytes of " - << req.dataLen << ", max retries reached"; + LOG->error("Write error: wrote {} bytes of {}, max retries reached", + req.dataLen - bytes, req.dataLen); knownSize = false; return false; } else { @@ -259,8 +258,8 @@ int RawFileIO::truncate(off_t size) { if (res < 0) { int eno = errno; - RLOG(WARNING) << "truncate failed for " << name << " (" << fd << ") size " - << size << ", error " << strerror(eno); + LOG->warn("truncate failed for {} ({}) size {}, error {}", name, fd, size, + strerror(eno)); res = -eno; knownSize = false; } else { diff --git a/encfs/SSL_Cipher.cpp b/encfs/SSL_Cipher.cpp index f2f8294..a0bbb24 100644 --- a/encfs/SSL_Cipher.cpp +++ b/encfs/SSL_Cipher.cpp @@ -18,7 +18,6 @@ * along with this program. If not, see . */ -#include "internal/easylogging++.h" #include #include #include @@ -36,8 +35,8 @@ #include "Interface.h" #include "Mutex.h" #include "Range.h" -#include "SSL_Compat.h" #include "SSL_Cipher.h" +#include "SSL_Compat.h" #include "intl/gettext.h" using namespace std; @@ -330,15 +329,15 @@ SSL_Cipher::SSL_Cipher(const Interface &iface_, const Interface &realIface_, rAssert(_ivLength == 8 || _ivLength == 16); - VLOG(1) << "allocated cipher " << iface.name() << ", keySize " << _keySize - << ", ivlength " << _ivLength; + LOG->debug("allocated cipher {}, keySize {}, ivLength {}", iface.name(), + _keySize, _ivLength); if ((EVP_CIPHER_key_length(_blockCipher) != (int)_keySize) && iface.current() == 1) { - RLOG(WARNING) << "Running in backward compatibilty mode for 1.0 - " - "key is really " - << EVP_CIPHER_key_length(_blockCipher) * 8 << " bits, not " - << _keySize * 8; + LOG->warn( + "Running in backward compatibilty mode for 1.0 - " + "key is really {} bits, not {}", + EVP_CIPHER_key_length(_blockCipher) * 8, _keySize * 8); } } @@ -364,7 +363,7 @@ CipherKey SSL_Cipher::newKey(const char *password, int passwdLength, TimedPBKDF2(password, passwdLength, salt, saltLen, _keySize + _ivLength, KeyData(key), 1000 * desiredDuration); if (res <= 0) { - RLOG(WARNING) << "openssl error, PBKDF2 failed"; + LOG->warn("openssl error, PBKDF2 failed"); return CipherKey(); } else iterationCount = res; @@ -373,7 +372,7 @@ CipherKey SSL_Cipher::newKey(const char *password, int passwdLength, if (PKCS5_PBKDF2_HMAC_SHA1( password, passwdLength, const_cast(salt), saltLen, iterationCount, _keySize + _ivLength, KeyData(key)) != 1) { - RLOG(WARNING) << "openssl error, PBKDF2 failed"; + LOG->warn("openssl error, PBKDF2 failed"); return CipherKey(); } } @@ -396,8 +395,8 @@ CipherKey SSL_Cipher::newKey(const char *password, int passwdLength) { // the reason for moving from EVP_BytesToKey to BytesToKey function.. if (bytes != (int)_keySize) { - RLOG(WARNING) << "newKey: BytesToKey returned " << bytes << ", expecting " - << _keySize << " key bytes"; + LOG->warn("newKey: BytesToKey returned {}, expecting {} key bytes", bytes, + _keySize); } } else { // for backward compatibility with filesystems created with 1:0 @@ -434,7 +433,7 @@ CipherKey SSL_Cipher::newRandomKey() { // Doesn't need to be reproducable.. if (PKCS5_PBKDF2_HMAC_SHA1((char *)tmpBuf, bufLen, saltBuf, saltLen, 1000, _keySize + _ivLength, KeyData(key)) != 1) { - RLOG(WARNING) << "openssl error, PBKDF2 failed"; + LOG->warn("openssl error, PBKDF2 failed"); return CipherKey(); } @@ -501,7 +500,7 @@ bool SSL_Cipher::randomize(unsigned char *buf, int len, char errStr[120]; // specs require string at least 120 bytes long.. unsigned long errVal = 0; if ((errVal = ERR_get_error()) != 0) { - RLOG(WARNING) << "openssl error: " << ERR_error_string(errVal, errStr); + LOG->warn("openssl error: {}", ERR_error_string(errVal, errStr)); } return false; @@ -538,9 +537,8 @@ CipherKey SSL_Cipher::readKey(const unsigned char *data, // check for success unsigned int checksum2 = MAC_32(tmpBuf, _keySize + _ivLength, masterKey); if (checksum2 != checksum && checkKey) { - VLOG(1) << "checksum mismatch: expected " << checksum << ", got " - << checksum2; - VLOG(1) << "on decode of " << _keySize + _ivLength << " bytes"; + LOG->debug("checksum mismatch: expected {}, got {}", checksum, checksum2); + LOG->debug("on decode of {} bytes", _keySize + _ivLength); memset(tmpBuf, 0, sizeof(tmpBuf)); return CipherKey(); } @@ -746,8 +744,8 @@ bool SSL_Cipher::streamEncode(unsigned char *buf, int size, uint64_t iv64, dstLen += tmpLen; if (dstLen != size) { - RLOG(ERROR) << "encoding " << size << " bytes, got back " << dstLen << " (" - << tmpLen << " in final_ex)"; + LOG->error("encoding {} bytes, got back {} ({} in final_ex)", size, dstLen, + tmpLen); } return true; @@ -782,8 +780,8 @@ bool SSL_Cipher::streamDecode(unsigned char *buf, int size, uint64_t iv64, dstLen += tmpLen; if (dstLen != size) { - RLOG(ERROR) << "decoding " << size << " bytes, got back " << dstLen << " (" - << tmpLen << " in final_ex)"; + LOG->error("decoding {} bytes, got back {} ({} in final_ex)", size, dstLen, + tmpLen); } return true; @@ -814,8 +812,8 @@ bool SSL_Cipher::blockEncode(unsigned char *buf, int size, uint64_t iv64, dstLen += tmpLen; if (dstLen != size) { - RLOG(ERROR) << "encoding " << size << " bytes, got back " << dstLen << " (" - << tmpLen << " in final_ex)"; + LOG->error("encoding {} bytes, got back {} ({} in final_ex)", size, dstLen, + tmpLen); } return true; @@ -846,8 +844,8 @@ bool SSL_Cipher::blockDecode(unsigned char *buf, int size, uint64_t iv64, dstLen += tmpLen; if (dstLen != size) { - RLOG(ERROR) << "decoding " << size << " bytes, got back " << dstLen << " (" - << tmpLen << " in final_ex)"; + LOG->error("decoding {} bytes, got back {} ({} in final_ex)", size, dstLen, + tmpLen); } return true; diff --git a/encfs/SSL_Compat.h b/encfs/SSL_Compat.h index f7b1629..276bf26 100644 --- a/encfs/SSL_Compat.h +++ b/encfs/SSL_Compat.h @@ -30,8 +30,7 @@ #define HMAC_CTX_reset HMAC_CTX_cleanup // Missing methods (based on 1.1.0 versions) -HMAC_CTX *HMAC_CTX_new(void) -{ +HMAC_CTX *HMAC_CTX_new(void) { HMAC_CTX *ctx = (HMAC_CTX *)OPENSSL_malloc(sizeof(HMAC_CTX)); if (ctx != NULL) { memset(ctx, 0, sizeof(HMAC_CTX)); @@ -40,8 +39,7 @@ HMAC_CTX *HMAC_CTX_new(void) return ctx; } -void HMAC_CTX_free(HMAC_CTX *ctx) -{ +void HMAC_CTX_free(HMAC_CTX *ctx) { if (ctx != NULL) { HMAC_CTX_cleanup(ctx); OPENSSL_free(ctx); diff --git a/encfs/StreamNameIO.cpp b/encfs/StreamNameIO.cpp index e07c4e5..db60715 100644 --- a/encfs/StreamNameIO.cpp +++ b/encfs/StreamNameIO.cpp @@ -20,7 +20,6 @@ #include "StreamNameIO.h" -#include "internal/easylogging++.h" #include #include "Cipher.h" @@ -174,8 +173,8 @@ int StreamNameIO::decodeName(const char *encodedName, int length, uint64_t *iv, BUFFER_RESET(tmpBuf); if (mac2 != mac) { - VLOG(1) << "checksum mismatch: expected " << mac << ", got " << mac2; - VLOG(1) << "on decode of " << decodedStreamLen << " bytes"; + LOG->debug("checksum mismatch: expected {}, got {}", mac, mac2); + LOG->debug("on decode of {} bytes", decodedStreamLen); throw Error("checksum mismatch in filename decode"); } diff --git a/encfs/XmlReader.cpp b/encfs/XmlReader.cpp index c0aaf9b..f5f3e2f 100644 --- a/encfs/XmlReader.cpp +++ b/encfs/XmlReader.cpp @@ -38,7 +38,7 @@ XmlValuePtr XmlValue::operator[](const char *path) const { return find(path); } XmlValuePtr XmlValue::find(const char *path) const { // Shouldn't get here. - RLOG(ERROR) << "in XmlValue::find for path " << path; + LOG->error("in XmlValue::find for path {}", path); return XmlValuePtr(); } @@ -93,13 +93,12 @@ bool XmlValue::readB64(const char *path, unsigned char *data, int decodedSize = B64ToB256Bytes(s.size()); if (decodedSize != length) { - RLOG(ERROR) << "decoding bytes len " << s.size() - << ", expecting output len " << length << ", got " - << decodedSize; + LOG->error("decoding bytes len {}, expecting output len {}, got {}", + s.size(), length, decodedSize); return false; } if (!B64StandardDecode(data, (unsigned char *)s.data(), s.size())) { - RLOG(ERROR) << "B64 decode failure on \"" << s << "\""; + LOG->error("B64 decode failure on \"{}\"", s); return false; } @@ -174,13 +173,13 @@ bool XmlReader::load(const char *fileName) { XmlValuePtr XmlReader::operator[](const char *name) const { tinyxml2::XMLNode *node = pd->doc->FirstChildElement(name); if (node == NULL) { - RLOG(ERROR) << "Xml node " << name << " not found"; + LOG->error("Xml node {} not found", name); return XmlValuePtr(new XmlValue()); } tinyxml2::XMLElement *element = node->ToElement(); if (element == NULL) { - RLOG(ERROR) << "Xml node " << name << " not element"; + LOG->error("Xml node {} not element", name); return XmlValuePtr(new XmlValue()); } diff --git a/encfs/base64.cpp b/encfs/base64.cpp index 1c69164..189b897 100644 --- a/encfs/base64.cpp +++ b/encfs/base64.cpp @@ -203,7 +203,7 @@ bool B64StandardDecode(unsigned char *out, const unsigned char *in, int inLen) { while (in < end) { unsigned char v = *in++; if (v > 'z') { - RLOG(ERROR) << "Invalid character: " << (unsigned int)v; + LOG->error("Invalid character: {}", (unsigned int)v); return false; } unsigned char c = d[v]; @@ -212,7 +212,7 @@ bool B64StandardDecode(unsigned char *out, const unsigned char *in, int inLen) { case WHITESPACE: continue; /* skip whitespace */ case INVALID: - RLOG(ERROR) << "Invalid character: " << (unsigned int)v; + LOG->error("Invalid character: {}", (unsigned int)v); return false; /* invalid input, return error */ case EQUALS: /* pad character, end of data */ in = end; diff --git a/encfs/encfs.cpp b/encfs/encfs.cpp index 0529bec..a5f652f 100644 --- a/encfs/encfs.cpp +++ b/encfs/encfs.cpp @@ -41,7 +41,6 @@ #include #endif -#include "internal/easylogging++.h" #include #include #include @@ -93,20 +92,19 @@ static int withCipherPath(const char *opName, const char *path, try { string cyName = FSRoot->cipherPath(path); - VLOG(1) << "op: " << opName << " : " << cyName; + LOG->debug("op: {} : {}", opName, cyName); res = op(ctx, cyName); if (res == -1) { int eno = errno; - VLOG(1) << "op: " << opName << " error: " << strerror(eno); + LOG->debug("op: {} error: {}", opName, strerror(eno)); res = -eno; } else if (!passReturnCode) { res = ESUCCESS; } } catch (encfs::Error &err) { - RLOG(ERROR) << "withCipherPath: error caught in " << opName << ": " - << err.what(); + LOG->error("withCipherPath: error caught in {}: {}", opName, err.what()); } return res; } @@ -125,12 +123,12 @@ static int withFileNode(const char *opName, const char *path, auto do_op = [&FSRoot, opName, &op](FileNode *fnode) { rAssert(fnode != nullptr); - VLOG(1) << "op: " << opName << " : " << fnode->cipherName(); + LOG->debug("op: {} : {}", opName, fnode->cipherName()); // check that we're not recursing into the mount point itself if (FSRoot->touchesMountpoint(fnode->cipherName())) { - VLOG(1) << "op: " << opName << " error: Tried to touch mountpoint: '" - << fnode->cipherName() << "'"; + LOG->debug("op: {} error: Tried to touch mountpoint: '{}''", opName, + fnode->cipherName()); return -EIO; } return op(fnode); @@ -142,11 +140,10 @@ static int withFileNode(const char *opName, const char *path, res = do_op(FSRoot->lookupNode(path, opName).get()); if (res < 0) { - RLOG(DEBUG) << "op: " << opName << " error: " << strerror(-res); + LOG->debug("op: {} error: {}", opName, strerror(-res)); } } catch (encfs::Error &err) { - RLOG(ERROR) << "withFileNode: error caught in " << opName << ": " - << err.what(); + LOG->error("withFileNode: error caught in {}: {}", opName, err.what()); } return res; } @@ -208,7 +205,7 @@ int encfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, DirTraverse dt = FSRoot->openDir(path); - VLOG(1) << "readdir on " << FSRoot->cipherPath(path); + LOG->debug("readdir on {}", FSRoot->cipherPath(path)); if (dt.valid()) { int fileType = 0; @@ -230,12 +227,12 @@ int encfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, name = dt.nextPlaintextName(&fileType, &inode); } } else { - VLOG(1) << "readdir request invalid, path: '" << path << "'"; + LOG->debug("readdir request invalid, path: '{}'", path); } return res; } catch (encfs::Error &err) { - RLOG(ERROR) << "Error caught in readdir"; + LOG->error("Error caught in readdir"); return -EIO; } } @@ -252,8 +249,7 @@ int encfs_mknod(const char *path, mode_t mode, dev_t rdev) { try { std::shared_ptr fnode = FSRoot->lookupNode(path, "mknod"); - VLOG(1) << "mknod on " << fnode->cipherName() << ", mode " << mode - << ", dev " << rdev; + LOG->debug("mknod on {}, mode {}, dev {}", fnode->cipherName(), mode, rdev); uid_t uid = 0; gid_t gid = 0; @@ -267,7 +263,7 @@ int encfs_mknod(const char *path, mode_t mode, dev_t rdev) { if (ctx->publicFilesystem && -res == EACCES) { // try again using the parent dir's group string parent = fnode->plaintextParent(); - VLOG(1) << "trying public filesystem workaround for " << parent; + LOG->debug("trying public filesystem workaround for {}", parent); std::shared_ptr dnode = FSRoot->lookupNode(parent.c_str(), "mknod"); @@ -276,7 +272,7 @@ int encfs_mknod(const char *path, mode_t mode, dev_t rdev) { res = fnode->mknod(mode, rdev, uid, st.st_gid); } } catch (encfs::Error &err) { - RLOG(ERROR) << "error caught in mknod: " << err.what(); + LOG->error("error caught in mknod: {}", err.what()); } return res; } @@ -311,7 +307,7 @@ int encfs_mkdir(const char *path, mode_t mode) { res = FSRoot->mkdir(path, mode, uid, st.st_gid); } } catch (encfs::Error &err) { - RLOG(ERROR) << "error caught in mkdir: " << err.what(); + LOG->error("error caught in mkdir: {}", err.what()); } return res; } @@ -330,7 +326,7 @@ int encfs_unlink(const char *path) { // conditions res = FSRoot->unlink(path); } catch (encfs::Error &err) { - RLOG(ERROR) << "error caught in unlink: " << err.what(); + LOG->error("error caught in unlink: {}", err.what()); } return res; } @@ -359,7 +355,7 @@ int _do_readlink(EncFS_Context *ctx, const string &cyName, char *buf, try { decodedName = FSRoot->plainPath(buf); } catch (...) { - VLOG(1) << "caught error decoding path"; + LOG->debug("caught error decoding path"); } if (!decodedName.empty()) { @@ -368,7 +364,7 @@ int _do_readlink(EncFS_Context *ctx, const string &cyName, char *buf, return ESUCCESS; } else { - RLOG(WARNING) << "Error decoding link"; + LOG->warn("Error decoding link"); return -1; } } @@ -395,7 +391,7 @@ int encfs_symlink(const char *to, const char *from) { // allow fully qualified names in symbolic links. string toCName = FSRoot->relativeCipherPath(to); - VLOG(1) << "symlink " << fromCName << " -> " << toCName; + LOG->debug("symlink {} -> {}", fromCName, toCName); // use setfsuid / setfsgid so that the new link will be owned by the // uid/gid provided by the fuse_context. @@ -415,7 +411,7 @@ int encfs_symlink(const char *to, const char *from) { else res = ESUCCESS; } catch (encfs::Error &err) { - RLOG(ERROR) << "error caught in symlink: " << err.what(); + LOG->error("error caught in symlink: {}", err.what()); } return res; } @@ -432,7 +428,7 @@ int encfs_link(const char *from, const char *to) { try { res = FSRoot->link(from, to); } catch (encfs::Error &err) { - RLOG(ERROR) << "error caught in link: " << err.what(); + LOG->error("error caught in link: {}", err.what()); } return res; } @@ -449,7 +445,7 @@ int encfs_rename(const char *from, const char *to) { try { res = FSRoot->rename(from, to); } catch (encfs::Error &err) { - RLOG(ERROR) << "error caught in rename: " << err.what(); + LOG->error("error caught in rename: {}", err.what()); } return res; } @@ -531,8 +527,8 @@ int encfs_open(const char *path, struct fuse_file_info *file) { FSRoot->openNode(path, "open", file->flags, &res); if (fnode) { - VLOG(1) << "encfs_open for " << fnode->cipherName() << ", flags " - << file->flags; + LOG->debug("encfs_open for {}, flags {}", fnode->cipherName(), + file->flags); if (res >= 0) { file->fh = @@ -541,7 +537,7 @@ int encfs_open(const char *path, struct fuse_file_info *file) { } } } catch (encfs::Error &err) { - RLOG(ERROR) << "error caught in open: " << err.what(); + LOG->error("error caught in open: {}", err.what()); } return res; @@ -594,7 +590,7 @@ int encfs_release(const char *path, struct fuse_file_info *finfo) { ctx->eraseNode(path, reinterpret_cast(finfo->fh)); return ESUCCESS; } catch (encfs::Error &err) { - RLOG(ERROR) << "error caught in release: " << err.what(); + LOG->error("error caught in release: {}", err.what()); return -EIO; } } @@ -642,7 +638,7 @@ int encfs_statfs(const char *path, struct statvfs *st) { rAssert(st != NULL); string cyName = ctx->rootCipherDir; - VLOG(1) << "doing statfs of " << cyName; + LOG->debug("doing statfs of {}", cyName); res = statvfs(cyName.c_str(), st); if (!res) { // adjust maximum name length.. @@ -650,7 +646,7 @@ int encfs_statfs(const char *path, struct statvfs *st) { } if (res == -1) res = -errno; } catch (encfs::Error &err) { - RLOG(ERROR) << "error caught in statfs: " << err.what(); + LOG->error("error caught in statfs: {}", err.what()); } return res; } diff --git a/encfs/encfs.h b/encfs/encfs.h index 2988af2..02acafa 100644 --- a/encfs/encfs.h +++ b/encfs/encfs.h @@ -21,7 +21,7 @@ #ifndef _encfs_incl_ #define _encfs_incl_ -#include "internal/easylogging++.h" +#include "Error.h" #include #include #include @@ -30,7 +30,7 @@ namespace encfs { -#if defined(HAVE_SYS_XATTR_H) | defined(HAVE_ATTR_XATTR_H) +#if defined(HAVE_SYS_XATTR_H) || defined(HAVE_ATTR_XATTR_H) #define HAVE_XATTR #endif @@ -41,7 +41,7 @@ static __inline int setfsuid(uid_t uid) { uid_t olduid = geteuid(); if (seteuid(uid) != 0) { - VLOG(1) << "seteuid error: " << errno; + LOG->debug("seteuid error: {}", errno); } return olduid; @@ -51,7 +51,7 @@ static __inline int setfsgid(gid_t gid) { gid_t oldgid = getegid(); if (setegid(gid) != 0) { - VLOG(1) << "setfsgid error: " << errno; + LOG->debug("setfsgid error: {}", errno); } return oldgid; diff --git a/encfs/encfsctl.cpp b/encfs/encfsctl.cpp index 6a5d17e..decf7e8 100644 --- a/encfs/encfsctl.cpp +++ b/encfs/encfsctl.cpp @@ -53,8 +53,6 @@ using namespace std; using gnu::autosprintf; using namespace encfs; -INITIALIZE_EASYLOGGINGPP - static int showInfo(int argc, char **argv); static int showVersion(int argc, char **argv); static int chpasswd(int argc, char **argv); @@ -234,7 +232,7 @@ static RootPtr initRootInfo(int &argc, char **&argv) { opts->passwordProgram.assign(optarg); break; default: - RLOG(WARNING) << "getopt error: " << res; + LOG->warn("getopt error: {}", res); break; } } @@ -714,7 +712,6 @@ static int ckpasswdAutomaticly(int argc, char **argv) { } int main(int argc, char **argv) { - START_EASYLOGGINGPP(argc, argv); encfs::initLogging(); #if defined(ENABLE_NLS) && defined(LOCALEDIR) @@ -733,7 +730,7 @@ int main(int argc, char **argv) { // Skip over uninteresting args. while (argc > 2 && *argv[1] == '-') { - VLOG(1) << "skipping arg " << argv[1]; + LOG->debug("skipping arg {}", argv[1]); argc--; argv[1] = argv[0]; argv++; diff --git a/encfs/main.cpp b/encfs/main.cpp index e56b83a..6278931 100644 --- a/encfs/main.cpp +++ b/encfs/main.cpp @@ -58,8 +58,6 @@ using namespace std; using namespace encfs; using gnu::autosprintf; -INITIALIZE_EASYLOGGINGPP - namespace encfs { class DirNode; @@ -342,9 +340,9 @@ static bool processArgs(int argc, char *argv[], out->opts->passwordProgram.assign(optarg); break; case 'P': - if (geteuid() != 0) - RLOG(WARNING) << "option '--public' ignored for non-root user"; - else { + if (geteuid() != 0) { + cerr << _("option '--public' ignored for non-root user"); + } else { out->opts->ownerCreate = true; // add 'allow_other' option // add 'default_permissions' option (default) @@ -368,7 +366,7 @@ static bool processArgs(int argc, char *argv[], // missing parameter for option.. break; default: - RLOG(WARNING) << "getopt error: " << res; + LOG->warn("getopt error: {}", res); break; } } @@ -493,25 +491,24 @@ void *encfs_init(fuse_conn_info *conn) { if (ctx->args->isDaemon) { // Switch to using syslog. - encfs::rlogAction = el::base::DispatchAction::SysLog; + encfs::enable_syslog(); } // if an idle timeout is specified, then setup a thread to monitor the // filesystem. if (ctx->args->idleTimeout > 0) { - VLOG(1) << "starting idle monitoring thread"; + LOG->debug("starting idle monitoring thread"); ctx->running = true; int res = pthread_create(&ctx->monitorThread, 0, idleMonitor, (void *)ctx); if (res != 0) { - RLOG(ERROR) << "error starting idle monitor thread, " - "res = " - << res << ", errno = " << errno; + LOG->error("error starting idle monitor thread, res = {}, errno = {}", + res, errno); } } if (ctx->args->isDaemon && oldStderr >= 0) { - VLOG(1) << "Closing stderr"; + LOG->debug("Closing stderr"); close(oldStderr); oldStderr = -1; } @@ -539,14 +536,10 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - if (encfsArgs->isVerbose) { - el::Loggers::setVerboseLevel(1); - } - encfs::initLogging(encfsArgs->isVerbose); - VLOG(1) << "Root directory: " << encfsArgs->opts->rootDir; - VLOG(1) << "Fuse arguments: " << encfsArgs->toString(); + LOG->debug("Root directory: {}", encfsArgs->opts->rootDir); + LOG->debug("Fuse arguments: {}", encfsArgs->toString()); fuse_operations encfs_oper; // in case this code is compiled against a newer FUSE library and new @@ -669,22 +662,22 @@ int main(int argc, char *argv[]) { fclose(out); } } catch (std::exception &ex) { - RLOG(ERROR) << "Internal error: Caught exception from main loop: " - << ex.what(); + LOG->error("Internal error: Caught exception from main loop: {}", + ex.what()); } catch (...) { - RLOG(ERROR) << "Internal error: Caught unexpected exception"; + LOG->error("Internal error: Caught unexpected exception"); } if (ctx->args->idleTimeout > 0) { ctx->running = false; // wake up the thread if it is waiting.. - VLOG(1) << "waking up monitoring thread"; + LOG->debug("waking up monitoring thread"); pthread_mutex_lock(&ctx->wakeupMutex); pthread_cond_signal(&ctx->wakeupCond); pthread_mutex_unlock(&ctx->wakeupMutex); - VLOG(1) << "joining with idle monitoring thread"; + LOG->debug("joining with idle monitoring thread"); pthread_join(ctx->monitorThread, 0); - VLOG(1) << "join done"; + LOG->debug("join done"); } } @@ -734,14 +727,13 @@ static void *idleMonitor(void *_arg) { break; } } else { - RLOG(WARNING) << "Filesystem " << arg->opts->mountPoint - << " inactivity detected, but still " << openCount - << " opened files"; + LOG->warn("Filesystem {} inactivity detected, but still {} open files", + arg->opts->mountPoint, openCount); } } - VLOG(1) << "idle cycle count: " << idleCycles << ", timeout after " - << timeoutCycles; + LOG->debug("idle cycle count: {}, timeout after {}", idleCycles, + timeoutCycles); struct timeval currentTime; gettimeofday(¤tTime, 0); @@ -753,7 +745,7 @@ static void *idleMonitor(void *_arg) { pthread_mutex_unlock(&ctx->wakeupMutex); - VLOG(1) << "Idle monitoring thread exiting"; + LOG->debug("Idle monitoring thread exiting"); return 0; } @@ -761,15 +753,15 @@ static void *idleMonitor(void *_arg) { static bool unmountFS(EncFS_Context *ctx) { std::shared_ptr arg = ctx->args; if (arg->opts->mountOnDemand) { - VLOG(1) << "Detaching filesystem due to inactivity: " - << arg->opts->mountPoint; + LOG->debug("Detaching filesystem due to inactivity: {}", + arg->opts->mountPoint); ctx->setRoot(std::shared_ptr()); return false; } else { // Time to unmount! - RLOG(WARNING) << "Unmounting filesystem due to inactivity: " - << arg->opts->mountPoint; + LOG->warn("Unmounting filesystem due to inactivity: {},", + arg->opts->mountPoint); fuse_unmount(arg->opts->mountPoint.c_str()); return true; } diff --git a/encfs/makeKey.cpp b/encfs/makeKey.cpp index d0a14d2..1e69eda 100644 --- a/encfs/makeKey.cpp +++ b/encfs/makeKey.cpp @@ -31,8 +31,6 @@ using namespace std; using namespace encfs; -INITIALIZE_EASYLOGGINGPP - void genKey(const std::shared_ptr &cipher) { CipherKey key = cipher->newRandomKey(); diff --git a/encfs/openssl.cpp b/encfs/openssl.cpp index 801a105..52c06f0 100644 --- a/encfs/openssl.cpp +++ b/encfs/openssl.cpp @@ -44,7 +44,7 @@ void pthreads_locking_callback(int mode, int n, const char *caller_file, (void)caller_line; if (!crypto_locks) { - VLOG(1) << "Allocating " << CRYPTO_num_locks() << " locks for OpenSSL"; + LOG->debug("Allocating {} locks for OpenSSL", CRYPTO_num_locks()); crypto_locks = new pthread_mutex_t[CRYPTO_num_locks()]; for (int i = 0; i < CRYPTO_num_locks(); ++i) pthread_mutex_init(crypto_locks + i, 0); diff --git a/encfs/test.cpp b/encfs/test.cpp index ee66469..ba1e5eb 100644 --- a/encfs/test.cpp +++ b/encfs/test.cpp @@ -38,7 +38,6 @@ #include "NameIO.h" #include "Range.h" #include "StreamNameIO.h" -#include "internal/easylogging++.h" #define NO_DES #include @@ -49,8 +48,6 @@ using namespace std; using namespace encfs; -INITIALIZE_EASYLOGGINGPP - const int FSBlockSize = 256; static int checkErrorPropogation(const std::shared_ptr &cipher, @@ -138,8 +135,9 @@ bool runTests(const std::shared_ptr &cipher, bool verbose) { } CipherKey key = cipher->newRandomKey(); - if (verbose) cerr << "Testing key save / restore :"; { + if (verbose) cerr << "Testing key save / restore :"; + CipherKey encodingKey = cipher->newRandomKey(); int encodedKeySize = cipher->encodedKeySize(); unsigned char keyBuf[encodedKeySize]; @@ -159,8 +157,9 @@ bool runTests(const std::shared_ptr &cipher, bool verbose) { } } - if (verbose) cerr << "Testing Config interface load / store :"; { + if (verbose) cerr << "Testing Config interface load / store :"; + CipherKey encodingKey = cipher->newRandomKey(); int encodedKeySize = cipher->encodedKeySize(); unsigned char keyBuf[encodedKeySize]; @@ -175,11 +174,12 @@ bool runTests(const std::shared_ptr &cipher, bool verbose) { cfg.assignKeyData(keyBuf, encodedKeySize); // save config - //Creation of a temporary file should be more platform independent. On c++17 we could use std::filesystem. + // Creation of a temporary file should be more platform independent. On + // c++17 we could use std::filesystem. string name = "/tmp/encfstestXXXXXX"; int tmpFd = mkstemp(&name[0]); rAssert(-1 != tmpFd); - //mkstemp opens the temporary file, but we only need its name -> close it + // mkstemp opens the temporary file, but we only need its name -> close it rAssert(0 == close(tmpFd)); { auto ok = writeV6Config(name.c_str(), &cfg); @@ -192,9 +192,9 @@ bool runTests(const std::shared_ptr &cipher, bool verbose) { auto ok = readV6Config(name.c_str(), &cfg2, nullptr); rAssert(ok == true); } - //delete the temporary file where we stored the config + // delete the temporary file where we stored the config rAssert(0 == unlink(name.c_str())); - + // check.. rAssert(cfg.cipherIface.implements(cfg2.cipherIface)); rAssert(cfg.keySize == cfg2.keySize); @@ -222,9 +222,10 @@ bool runTests(const std::shared_ptr &cipher, bool verbose) { fsCfg->config.reset(new EncFSConfig); fsCfg->config->blockSize = FSBlockSize; - if (verbose) - cerr << "Testing name encode/decode (stream coding w/ IV chaining)\n"; { + if (verbose) + cerr << "Testing name encode/decode (stream coding w/ IV chaining)\n"; + fsCfg->opts.reset(new EncFS_Opts); fsCfg->opts->idleTracking = false; fsCfg->config->uniqueIV = false; @@ -238,9 +239,10 @@ bool runTests(const std::shared_ptr &cipher, bool verbose) { if (!testNameCoding(dirNode, verbose)) return false; } - if (verbose) - cerr << "Testing name encode/decode (block coding w/ IV chaining)\n"; { + if (verbose) + cerr << "Testing name encode/decode (block coding w/ IV chaining)\n"; + fsCfg->opts->idleTracking = false; fsCfg->config->uniqueIV = false; fsCfg->nameCoding.reset(new BlockNameIO(BlockNameIO::CurrentInterface(), @@ -253,10 +255,11 @@ bool runTests(const std::shared_ptr &cipher, bool verbose) { if (!testNameCoding(dirNode, verbose)) return false; } - if (verbose) - cerr - << "Testing name encode/decode (block coding w/ IV chaining, base32)\n"; { + if (verbose) + cerr << "Testing name encode/decode (block coding w/ IV chaining, " + "base32)\n"; + fsCfg->opts->idleTracking = false; fsCfg->config->uniqueIV = false; fsCfg->nameCoding.reset(new BlockNameIO(BlockNameIO::CurrentInterface(), @@ -294,8 +297,9 @@ bool runTests(const std::shared_ptr &cipher, bool verbose) { } } - if (verbose) cerr << "Testing block encode/decode on full block - "; { + if (verbose) cerr << "Testing block encode/decode on full block - "; + int numErrors = checkErrorPropogation(cipher, FSBlockSize, -1, key); if (numErrors) { if (verbose) cerr << " FAILED!\n"; @@ -304,8 +308,9 @@ bool runTests(const std::shared_ptr &cipher, bool verbose) { if (verbose) cerr << " OK\n"; } } - if (verbose) cerr << "Testing block encode/decode on partial block - "; { + if (verbose) cerr << "Testing block encode/decode on partial block - "; + int numErrors = checkErrorPropogation(cipher, FSBlockSize - 1, -1, key); if (numErrors) { if (verbose) cerr << " FAILED!\n"; @@ -315,8 +320,9 @@ bool runTests(const std::shared_ptr &cipher, bool verbose) { } } - if (verbose) cerr << "Checking error propogation in partial block:\n"; { + if (verbose) cerr << "Checking error propogation in partial block:\n"; + int minChanges = FSBlockSize - 1; int maxChanges = 0; int minAt = 0; @@ -341,8 +347,9 @@ bool runTests(const std::shared_ptr &cipher, bool verbose) { << maxAt << "\n"; } } - if (verbose) cerr << "Checking error propogation on full block:\n"; { + if (verbose) cerr << "Checking error propogation on full block:\n"; + int minChanges = FSBlockSize; int maxChanges = 0; int minAt = 0; @@ -397,7 +404,6 @@ static bool testCipherSize(const string &name, int keySize, int blockSize, } int main(int argc, char *argv[]) { - START_EASYLOGGINGPP(argc, argv); encfs::initLogging(); SSL_load_error_strings(); diff --git a/model/logging.c b/model/logging.c index f7724c6..967ad0b 100644 --- a/model/logging.c +++ b/model/logging.c @@ -1,12 +1,10 @@ -void CHECK(bool cond) { - if (!cond) { - __coverity_panic__(); +#define rAssert(cond) \ + if (!(cond)) { \ + __coverity_panic__(); \ } -} -void CHECK_EQ(int l, int r) { - if (l != r) { - __coverity_panic__(); +#define CHECK_EQ(l, r) \ + if ((l) != (r)) { \ + __coverity_panic__(); \ } -}