mirror of
https://github.com/vgough/encfs.git
synced 2024-11-25 01:13:12 +01:00
modernize: use C++ headers, auto, make_shared
This commit is contained in:
parent
b04c4124d4
commit
5a99506ea8
@ -18,10 +18,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <stddef.h>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
@ -184,13 +184,13 @@ bool Cipher::nameDecode(unsigned char *data, int len, uint64_t iv64,
|
||||
string Cipher::encodeAsString(const CipherKey &key,
|
||||
const CipherKey &encodingKey) {
|
||||
int encodedKeySize = this->encodedKeySize();
|
||||
unsigned char *keyBuf = new unsigned char[encodedKeySize];
|
||||
auto *keyBuf = new unsigned char[encodedKeySize];
|
||||
|
||||
// write the key, encoding it with itself.
|
||||
this->writeKey(key, keyBuf, encodingKey);
|
||||
|
||||
int b64Len = B256ToB64Bytes(encodedKeySize);
|
||||
unsigned char *b64Key = new unsigned char[b64Len + 1];
|
||||
auto *b64Key = new unsigned char[b64Len + 1];
|
||||
|
||||
changeBase2(keyBuf, encodedKeySize, 8, b64Key, b64Len, 6);
|
||||
B64ToAscii(b64Key, b64Len);
|
||||
|
@ -22,11 +22,11 @@
|
||||
|
||||
#include "internal/easylogging++.h"
|
||||
#include <cerrno>
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <memory>
|
||||
#include <openssl/sha.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "BlockFileIO.h"
|
||||
|
@ -49,7 +49,7 @@ bool ConfigReader::load(const char *fileName) {
|
||||
int fd = open(fileName, O_RDONLY);
|
||||
if (fd < 0) return false;
|
||||
|
||||
char *buf = new char[size];
|
||||
auto *buf = new char[size];
|
||||
|
||||
int res = ::read(fd, buf, size);
|
||||
close(fd);
|
||||
@ -126,7 +126,7 @@ ConfigVar ConfigReader::toVar() const {
|
||||
|
||||
ConfigVar ConfigReader::operator[](const std::string &varName) const {
|
||||
// read only
|
||||
map<string, ConfigVar>::const_iterator it = vars.find(varName);
|
||||
auto it = vars.find(varName);
|
||||
if (it == vars.end())
|
||||
return ConfigVar();
|
||||
else
|
||||
|
@ -112,7 +112,7 @@ void ConfigVar::writeInt(int val) {
|
||||
}
|
||||
|
||||
int ConfigVar::readInt() const {
|
||||
const unsigned char *buf = (const unsigned char *)buffer();
|
||||
const auto *buf = (const unsigned char *)buffer();
|
||||
int bytes = this->size();
|
||||
int offset = at();
|
||||
int value = 0;
|
||||
@ -184,7 +184,7 @@ const ConfigVar &operator>>(const ConfigVar &src, std::string &result) {
|
||||
|
||||
unsigned char tmpBuf[32];
|
||||
if (length > (int)sizeof(tmpBuf)) {
|
||||
unsigned char *ptr = new unsigned char[length];
|
||||
auto *ptr = new unsigned char[length];
|
||||
readLen = src.read(ptr, length);
|
||||
result.assign((char *)ptr, length);
|
||||
delete[] ptr;
|
||||
|
@ -87,7 +87,7 @@ void EncFS_Context::getAndResetUsageCounter(int *usage, int *openCount) {
|
||||
std::shared_ptr<FileNode> EncFS_Context::lookupNode(const char *path) {
|
||||
Lock lock(contextMutex);
|
||||
|
||||
FileMap::iterator it = openFiles.find(std::string(path));
|
||||
auto it = openFiles.find(std::string(path));
|
||||
if (it != openFiles.end()) {
|
||||
// every entry in the list is fine... so just use the
|
||||
// first
|
||||
@ -99,7 +99,7 @@ std::shared_ptr<FileNode> EncFS_Context::lookupNode(const char *path) {
|
||||
void EncFS_Context::renameNode(const char *from, const char *to) {
|
||||
Lock lock(contextMutex);
|
||||
|
||||
FileMap::iterator it = openFiles.find(std::string(from));
|
||||
auto it = openFiles.find(std::string(from));
|
||||
if (it != openFiles.end()) {
|
||||
auto val = it->second;
|
||||
openFiles.erase(it);
|
||||
@ -123,7 +123,7 @@ void EncFS_Context::eraseNode(const char *path,
|
||||
std::shared_ptr<FileNode> fnode) {
|
||||
Lock lock(contextMutex);
|
||||
|
||||
FileMap::iterator it = openFiles.find(std::string(path));
|
||||
auto it = openFiles.find(std::string(path));
|
||||
rAssert(it != openFiles.end());
|
||||
auto &list = it->second;
|
||||
|
||||
|
@ -219,7 +219,7 @@ void RenameOp::undo() {
|
||||
// list has to be processed backwards, otherwise we may rename
|
||||
// directories and directory contents in the wrong order!
|
||||
int undoCount = 0;
|
||||
list<RenameEl>::const_iterator it = last;
|
||||
auto it = last;
|
||||
|
||||
while (it != renameList->begin()) {
|
||||
--it;
|
||||
@ -485,7 +485,7 @@ std::shared_ptr<RenameOp> DirNode::newRenameOp(const char *fromP,
|
||||
RLOG(WARNING) << "Error during generation of recursive rename list";
|
||||
return std::shared_ptr<RenameOp>();
|
||||
} else
|
||||
return std::shared_ptr<RenameOp>(new RenameOp(this, renameList));
|
||||
return std::make_shared<RenameOp>(this, renameList);
|
||||
}
|
||||
|
||||
int DirNode::mkdir(const char *plaintextPath, mode_t mode, uid_t uid,
|
||||
|
@ -21,7 +21,7 @@ class Error : public std::runtime_error {
|
||||
RLOG(ERROR) << "Assert failed: " << STR(cond); \
|
||||
throw encfs::Error(STR(cond)); \
|
||||
} \
|
||||
} while (0)
|
||||
} while (false)
|
||||
|
||||
void initLogging(bool enable_debug = false, bool is_daemon = false);
|
||||
|
||||
|
@ -18,9 +18,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <cerrno>
|
||||
#include <cinttypes>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
@ -323,7 +323,7 @@ bool readV6Config(const char *configFile, EncFSConfig *cfg, ConfigInfo *info) {
|
||||
|
||||
int encodedSize;
|
||||
config->read("encodedKeySize", &encodedSize);
|
||||
unsigned char *key = new unsigned char[encodedSize];
|
||||
auto *key = new unsigned char[encodedSize];
|
||||
config->readB64("encodedKeyData", key, encodedSize);
|
||||
cfg->assignKeyData(key, encodedSize);
|
||||
delete[] key;
|
||||
@ -331,7 +331,7 @@ bool readV6Config(const char *configFile, EncFSConfig *cfg, ConfigInfo *info) {
|
||||
if (cfg->subVersion >= 20080816) {
|
||||
int saltLen;
|
||||
config->read("saltLen", &saltLen);
|
||||
unsigned char *salt = new unsigned char[saltLen];
|
||||
auto *salt = new unsigned char[saltLen];
|
||||
config->readB64("saltData", salt, saltLen);
|
||||
cfg->assignSaltData(salt, saltLen);
|
||||
delete[] salt;
|
||||
@ -1161,7 +1161,7 @@ RootPtr createV6Config(EncFS_Context *ctx,
|
||||
"later using encfsctl.\n\n");
|
||||
|
||||
int encodedKeySize = cipher->encodedKeySize();
|
||||
unsigned char *encodedKey = new unsigned char[encodedKeySize];
|
||||
auto *encodedKey = new unsigned char[encodedKeySize];
|
||||
|
||||
CipherKey volumeKey = cipher->newRandomKey();
|
||||
|
||||
@ -1216,11 +1216,10 @@ RootPtr createV6Config(EncFS_Context *ctx,
|
||||
fsConfig->idleTracking = enableIdleTracking;
|
||||
fsConfig->opts = opts;
|
||||
|
||||
rootInfo = RootPtr(new EncFS_Root);
|
||||
rootInfo = std::make_shared<encfs::EncFS_Root>();
|
||||
rootInfo->cipher = cipher;
|
||||
rootInfo->volumeKey = volumeKey;
|
||||
rootInfo->root =
|
||||
std::shared_ptr<DirNode>(new DirNode(ctx, rootDir, fsConfig));
|
||||
rootInfo->root = std::make_shared<DirNode>(ctx, rootDir, fsConfig);
|
||||
|
||||
return rootInfo;
|
||||
}
|
||||
@ -1576,7 +1575,7 @@ RootPtr initFS(EncFS_Context *ctx, const std::shared_ptr<EncFS_Opts> &opts) {
|
||||
}
|
||||
|
||||
if (opts->delayMount) {
|
||||
rootInfo = RootPtr(new EncFS_Root);
|
||||
rootInfo = std::make_shared<encfs::EncFS_Root>();
|
||||
rootInfo->cipher = cipher;
|
||||
rootInfo->root = std::shared_ptr<DirNode>();
|
||||
return rootInfo;
|
||||
@ -1632,11 +1631,10 @@ RootPtr initFS(EncFS_Context *ctx, const std::shared_ptr<EncFS_Opts> &opts) {
|
||||
fsConfig->reverseEncryption = opts->reverseEncryption;
|
||||
fsConfig->opts = opts;
|
||||
|
||||
rootInfo = RootPtr(new EncFS_Root);
|
||||
rootInfo = std::make_shared<encfs::EncFS_Root>();
|
||||
rootInfo->cipher = cipher;
|
||||
rootInfo->volumeKey = volumeKey;
|
||||
rootInfo->root =
|
||||
std::shared_ptr<DirNode>(new DirNode(ctx, opts->rootDir, fsConfig));
|
||||
rootInfo->root = std::make_shared<DirNode>(ctx, opts->rootDir, fsConfig);
|
||||
} else {
|
||||
if (opts->createIfNotFound) {
|
||||
// creating a new encrypted filesystem
|
||||
|
@ -21,8 +21,8 @@
|
||||
#include "MACFileIO.h"
|
||||
|
||||
#include "internal/easylogging++.h"
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <inttypes.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "BlockFileIO.h"
|
||||
|
@ -44,7 +44,7 @@ struct BlockList {
|
||||
};
|
||||
|
||||
static BlockList *allocBlock(int size) {
|
||||
BlockList *block = new BlockList;
|
||||
auto *block = new BlockList;
|
||||
block->size = size;
|
||||
block->data = BUF_MEM_new();
|
||||
BUF_MEM_grow(block->data, size);
|
||||
@ -98,7 +98,7 @@ MemBlock MemoryPool::allocate(int size) {
|
||||
void MemoryPool::release(const MemBlock &mb) {
|
||||
pthread_mutex_lock(&gMPoolMutex);
|
||||
|
||||
BlockList *block = (BlockList *)mb.internalData;
|
||||
auto *block = (BlockList *)mb.internalData;
|
||||
|
||||
// just to be sure there's nothing important left in buffers..
|
||||
VALGRIND_MAKE_MEM_UNDEFINED(block->data->data, block->size);
|
||||
|
@ -23,9 +23,9 @@
|
||||
#endif
|
||||
#include "internal/easylogging++.h"
|
||||
#include <cerrno>
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -479,7 +479,7 @@ static uint64_t _checksum_64(SSLKey *key, const unsigned char *data,
|
||||
for (unsigned int i = 0; i < (mdLen - 1); ++i)
|
||||
h[i % 8] ^= (unsigned char)(md[i]);
|
||||
|
||||
uint64_t value = (uint64_t)h[0];
|
||||
auto value = (uint64_t)h[0];
|
||||
for (int i = 1; i < 8; ++i) value = (value << 8) | (uint64_t)h[i];
|
||||
|
||||
return value;
|
||||
|
@ -145,7 +145,7 @@ class XmlNode : virtual public XmlValue {
|
||||
if (name[0] == '@') {
|
||||
const char *value = element->Attribute(name + 1);
|
||||
if (value)
|
||||
return XmlValuePtr(new XmlValue(value));
|
||||
return std::make_shared<encfs::XmlValue>(value);
|
||||
else
|
||||
return XmlValuePtr();
|
||||
} else {
|
||||
@ -182,13 +182,13 @@ XmlValuePtr XmlReader::operator[](const char *name) const {
|
||||
tinyxml2::XMLNode *node = pd->doc->FirstChildElement(name);
|
||||
if (node == nullptr) {
|
||||
RLOG(ERROR) << "Xml node " << name << " not found";
|
||||
return XmlValuePtr(new XmlValue());
|
||||
return std::make_shared<encfs::XmlValue>();
|
||||
}
|
||||
|
||||
tinyxml2::XMLElement *element = node->ToElement();
|
||||
if (element == nullptr) {
|
||||
RLOG(ERROR) << "Xml node " << name << " not element";
|
||||
return XmlValuePtr(new XmlValue());
|
||||
return std::make_shared<encfs::XmlValue>();
|
||||
}
|
||||
|
||||
return XmlValuePtr(new XmlNode(element));
|
||||
|
@ -27,10 +27,10 @@
|
||||
/* Specification. */
|
||||
#include "autosprintf.h"
|
||||
|
||||
#include <stdarg.h> // for va_list
|
||||
#include <stdio.h> // for NULL, vasprintf
|
||||
#include <stdlib.h> // for free
|
||||
#include <string.h> // for strdup
|
||||
#include <cstdarg> // for va_list
|
||||
#include <cstdio> // for NULL, vasprintf
|
||||
#include <cstdlib> // for free
|
||||
#include <cstring> // for strdup
|
||||
|
||||
namespace gnu {
|
||||
|
||||
@ -54,7 +54,7 @@ autosprintf::~autosprintf() { free(str); }
|
||||
autosprintf::operator char *() const {
|
||||
if (str != nullptr) {
|
||||
size_t length = strlen(str) + 1;
|
||||
char *copy = new char[length];
|
||||
auto *copy = new char[length];
|
||||
memcpy(copy, str, length);
|
||||
return copy;
|
||||
} else
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#include "base64.h"
|
||||
|
||||
#include <ctype.h> // for toupper
|
||||
#include <cctype> // for toupper
|
||||
|
||||
#include "Error.h"
|
||||
|
||||
@ -248,7 +248,7 @@ std::string B64StandardEncode(std::vector<unsigned char> inputBuffer) {
|
||||
std::string encodedString;
|
||||
encodedString.reserve(B256ToB64Bytes(inputBuffer.size()));
|
||||
long temp;
|
||||
std::vector<unsigned char>::iterator cursor = inputBuffer.begin();
|
||||
auto cursor = inputBuffer.begin();
|
||||
for (size_t idx = 0; idx < inputBuffer.size() / 3; idx++) {
|
||||
temp = (*cursor++) << 16; // Convert to big endian
|
||||
temp += (*cursor++) << 8;
|
||||
|
@ -18,17 +18,17 @@
|
||||
#include "encfs.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <cinttypes>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <utime.h>
|
||||
#ifdef linux
|
||||
|
@ -18,18 +18,18 @@
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <exception>
|
||||
#include <getopt.h>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <pthread.h>
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "Context.h"
|
||||
@ -493,7 +493,7 @@ static bool processArgs(int argc, char *argv[],
|
||||
static void *idleMonitor(void *);
|
||||
|
||||
void *encfs_init(fuse_conn_info *conn) {
|
||||
EncFS_Context *ctx = (EncFS_Context *)fuse_get_context()->private_data;
|
||||
auto *ctx = (EncFS_Context *)fuse_get_context()->private_data;
|
||||
|
||||
// set fuse connection options
|
||||
conn->async_read = true;
|
||||
@ -599,7 +599,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
// context is not a smart pointer because it will live for the life of
|
||||
// the filesystem.
|
||||
auto ctx = std::shared_ptr<EncFS_Context>(new EncFS_Context);
|
||||
auto ctx = std::make_shared<EncFS_Context>();
|
||||
ctx->publicFilesystem = encfsArgs->opts->ownerCreate;
|
||||
RootPtr rootInfo = initFS(ctx.get(), encfsArgs->opts);
|
||||
|
||||
@ -709,7 +709,7 @@ const int ActivityCheckInterval = 10;
|
||||
static bool unmountFS(EncFS_Context *ctx);
|
||||
|
||||
static void *idleMonitor(void *_arg) {
|
||||
EncFS_Context *ctx = (EncFS_Context *)_arg;
|
||||
auto *ctx = (EncFS_Context *)_arg;
|
||||
std::shared_ptr<EncFS_Args> arg = ctx->args;
|
||||
|
||||
const int timeoutCycles = 60 * arg->idleTimeout / ActivityCheckInterval;
|
||||
|
@ -20,9 +20,9 @@
|
||||
|
||||
#include "openssl.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <openssl/crypto.h>
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define NO_DES
|
||||
#include <openssl/rand.h>
|
||||
|
Loading…
Reference in New Issue
Block a user