run clang-format

This commit is contained in:
Valient Gough 2015-06-17 21:16:50 -07:00
parent 0b813eb50b
commit 1682f365d9
17 changed files with 162 additions and 156 deletions

View File

@ -67,7 +67,7 @@ ssize_t BlockFileIO::cacheReadOneBlock(const IORequest &req) const {
* in the last block of a file, which may be smaller than the blocksize.
* For reverse encryption, the cache must not be used at all, because
* the lower file may have changed behind our back. */
if ( (_noCache == false) && (req.offset == _cache.offset) &&
if ((_noCache == false) && (req.offset == _cache.offset) &&
(_cache.dataLen != 0)) {
// satisfy request from cache
int len = req.dataLen;

View File

@ -151,7 +151,7 @@ int BlockNameIO::encodeName(const char *plaintextName, int length, uint64_t *iv,
// add checksum bytes
encodedName[0] = (mac >> 8) & 0xff;
encodedName[1] = (mac) & 0xff;
encodedName[1] = (mac)&0xff;
_cipher->blockEncode((unsigned char *)encodedName + 2, length + padding,
(uint64_t)mac ^ tmpIV, _key);
@ -184,8 +184,7 @@ int BlockNameIO::decodeName(const char *encodedName, int length, uint64_t *iv,
int decodedStreamLen = decLen256 - 2;
// don't bother trying to decode files which are too small
if (decodedStreamLen < _bs)
{
if (decodedStreamLen < _bs) {
rDebug("Rejecting filename '%s'", encodedName);
throw ERROR("Filename too small to decode");
}

View File

@ -144,15 +144,12 @@ int CipherFileIO::getAttr(struct stat *stbuf) const {
// adjust size if we have a file header
if ((res == 0) && haveHeader && S_ISREG(stbuf->st_mode) &&
(stbuf->st_size > 0)) {
if(!fsConfig->reverseEncryption)
{
if (!fsConfig->reverseEncryption) {
/* In normal mode, the upper file (plaintext) is smaller
* than the backing ciphertext file */
rAssert(stbuf->st_size >= HEADER_SIZE);
stbuf->st_size -= HEADER_SIZE;
}
else
{
} else {
/* In reverse mode, the upper file (ciphertext) is larger than
* the backing plaintext file */
stbuf->st_size += HEADER_SIZE;
@ -171,13 +168,10 @@ off_t CipherFileIO::getSize() const {
// No check on S_ISREG here -- don't call getSize over getAttr unless this
// is a normal file!
if (haveHeader && size > 0) {
if(!fsConfig->reverseEncryption)
{
if (!fsConfig->reverseEncryption) {
rAssert(size >= HEADER_SIZE);
size -= HEADER_SIZE;
}
else
{
} else {
size += HEADER_SIZE;
}
}
@ -278,13 +272,13 @@ bool CipherFileIO::writeHeader() {
* the IV. This guarantees unpredictability and prevents watermarking
* attacks.
*/
void CipherFileIO::generateReverseHeader(unsigned char* headerBuf) {
void CipherFileIO::generateReverseHeader(unsigned char *headerBuf) {
struct stat stbuf;
int res = getAttr(&stbuf);
rAssert( res == 0 );
rAssert(res == 0);
ino_t ino = stbuf.st_ino;
rAssert( ino != 0 );
rAssert(ino != 0);
rDebug("generating reverse file IV header from ino=%lu", (unsigned long)ino);
@ -300,7 +294,7 @@ void CipherFileIO::generateReverseHeader(unsigned char* headerBuf) {
* may lead to duplicate IVs (see readOneBlock) */
unsigned char md[20];
SHA1(inoBuf, sizeof(ino), md);
rAssert( HEADER_SIZE <= 20 );
rAssert(HEADER_SIZE <= 20);
memcpy(headerBuf, md, HEADER_SIZE);
// Save the IV in fileIV for internal use
@ -464,12 +458,14 @@ 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) ) {
rDebug("relaying request to base class: offset=%d, dataLen=%d", origReq.offset, origReq.dataLen);
if (!(fsConfig->reverseEncryption && haveHeader)) {
rDebug("relaying request to base class: offset=%d, dataLen=%d",
origReq.offset, origReq.dataLen);
return BlockFileIO::read(origReq);
}
rDebug("handling reverse unique IV read: offset=%d, dataLen=%d", origReq.offset, origReq.dataLen);
rDebug("handling reverse unique IV read: offset=%d, dataLen=%d",
origReq.offset, origReq.dataLen);
// generate the file IV header
// this is needed in any case - without IV the file cannot be decoded
@ -489,7 +485,7 @@ ssize_t CipherFileIO::read(const IORequest &origReq) const {
* to the data. */
if (req.offset < 0) {
headerBytes = -req.offset;
if ( req.dataLen < headerBytes )
if (req.dataLen < headerBytes)
headerBytes = req.dataLen; // only up to the number of bytes requested
rDebug("Adding %d header bytes", headerBytes);
@ -498,14 +494,13 @@ ssize_t CipherFileIO::read(const IORequest &origReq) const {
memcpy(req.data, &headerBuf[headerOffset], headerBytes);
// the read does not want data beyond the header
if ( headerBytes == req.dataLen)
return headerBytes;
if (headerBytes == req.dataLen) return headerBytes;
/* The rest of the request will be read from the backing file.
* As we have already generated n=headerBytes bytes, the request is
* shifted by headerBytes */
req.offset += headerBytes;
rAssert( req.offset == 0 );
rAssert(req.offset == 0);
req.data += headerBytes;
req.dataLen -= headerBytes;
}
@ -513,10 +508,9 @@ ssize_t CipherFileIO::read(const IORequest &origReq) const {
// read the payload
ssize_t readBytes = BlockFileIO::read(req);
rDebug("read %ld bytes from backing file", (long)readBytes);
if ( readBytes < 0)
if (readBytes < 0)
return readBytes; // Return error code
else
{
else {
ssize_t sum = headerBytes + readBytes;
rDebug("returning sum=%ld", (long)sum);
return sum;

View File

@ -57,7 +57,7 @@ class CipherFileIO : public BlockFileIO {
private:
virtual ssize_t readOneBlock(const IORequest &req) const;
virtual bool writeOneBlock(const IORequest &req);
virtual void generateReverseHeader(unsigned char* data);
virtual void generateReverseHeader(unsigned char *data);
void initHeader();
bool writeHeader();

View File

@ -311,7 +311,8 @@ string DirNode::plainPath(const char *cipherPath_) {
prefix = "+";
}
if (cipherPath_[0] == mark) {
return prefix + naming->decodeName(cipherPath_ + 1, strlen(cipherPath_ + 1));
return prefix +
naming->decodeName(cipherPath_ + 1, strlen(cipherPath_ + 1));
}
// Default.

View File

@ -122,7 +122,8 @@ struct FSConfig {
bool idleTracking; // turn on idle monitoring of filesystem
FSConfig() : forceDecode(false), reverseEncryption(false), idleTracking(false) {}
FSConfig()
: forceDecode(false), reverseEncryption(false), idleTracking(false) {}
};
typedef shared_ptr<FSConfig> FSConfigPtr;

View File

@ -66,7 +66,6 @@
#include "i18n.h"
// disable rlog section grouping for this file.. seems to cause problems
#undef RLOG_SECTION
#define RLOG_SECTION
@ -297,7 +296,8 @@ bool userAllowMkdir(int promptno, const char *path, mode_t mode) {
// xgroup(setup)
cerr << autosprintf(
_("The directory \"%s\" does not exist. Should it be created? "
"(y,n) "), path);
"(y,n) "),
path);
char answer[10];
char *res;
@ -338,8 +338,7 @@ ConfigType readConfig_load(ConfigInfo *nm, const char *path,
config->cfgType = nm->type;
return nm->type;
}
}
catch (rlog::Error &err) {
} catch (rlog::Error &err) {
err.log(_RLWarningChannel);
}
@ -364,8 +363,10 @@ ConfigType readConfig(const string &rootDir,
if (nm->environmentOverride != NULL) {
char *envFile = getenv(nm->environmentOverride);
if (envFile != NULL) {
if (! fileExists(envFile)) {
rError("fatal: config file specified by environment does not exist: %s", envFile);
if (!fileExists(envFile)) {
rError(
"fatal: config file specified by environment does not exist: %s",
envFile);
exit(1);
}
return readConfig_load(nm, envFile, config);
@ -397,8 +398,7 @@ bool readV6Config(const char *configFile, const shared_ptr<EncFSConfig> &config,
ia >> BOOST_SERIALIZATION_NVP(*config);
return true;
}
catch (boost::archive::archive_exception &e) {
} catch (boost::archive::archive_exception &e) {
rError("Archive exception: %s", e.what());
return false;
}
@ -453,8 +453,7 @@ bool readV5Config(const char *configFile, const shared_ptr<EncFSConfig> &config,
config->blockMACRandBytes = cfgRdr["blockMACRandBytes"].readInt(0);
ok = true;
}
catch (rlog::Error &err) {
} catch (rlog::Error &err) {
err.log(_RLWarningChannel);
rDebug("Error parsing data in config file %s", configFile);
ok = false;
@ -494,8 +493,7 @@ bool readV4Config(const char *configFile, const shared_ptr<EncFSConfig> &config,
config->chainedNameIV = false;
ok = true;
}
catch (rlog::Error &err) {
} catch (rlog::Error &err) {
err.log(_RLWarningChannel);
rDebug("Error parsing config file %s", configFile);
ok = false;
@ -521,8 +519,7 @@ bool saveConfig(ConfigType type, const string &rootDir,
try {
ok = (*nm->saveFunc)(path.c_str(), config);
}
catch (rlog::Error &err) {
} catch (rlog::Error &err) {
err.log(_RLWarningChannel);
ok = false;
}
@ -667,7 +664,8 @@ static Cipher::CipherAlgorithm selectCipherAlgorithm() {
Cipher::CipherAlgorithm alg = *it;
// xgroup(setup)
cout << autosprintf(_("Selected algorithm \"%s\""), alg.name.c_str()) << "\n\n";
cout << autosprintf(_("Selected algorithm \"%s\""), alg.name.c_str())
<< "\n\n";
return alg;
}
@ -707,7 +705,8 @@ static Interface selectNameCoding() {
++it;
// xgroup(setup)
cout << autosprintf(_("Selected algorithm \"%s\""), it->name.c_str()) << "\"\n\n";
cout << autosprintf(_("Selected algorithm \"%s\""), it->name.c_str())
<< "\"\n\n";
return it->iface;
}
@ -824,7 +823,7 @@ static bool boolDefault(const char *prompt, bool defaultValue) {
string response;
bool value;
while(true) {
while (true) {
cout << yesno;
getline(cin, response);
@ -867,7 +866,8 @@ static void selectBlockMAC(int *macBytes, int *macRandBytes, bool forceMac) {
"within a block will be caught and will cause a read error."));
} else {
cout << "\n\n" << _("You specified --require-macs. "
"Enabling block authentication code headers...") << "\n\n";
"Enabling block authentication code headers...")
<< "\n\n";
addMAC = true;
}
@ -877,7 +877,8 @@ static void selectBlockMAC(int *macBytes, int *macRandBytes, bool forceMac) {
*macBytes = 0;
// xgroup(setup)
cout << _("Add random bytes to each block header?\n"
cout << _(
"Add random bytes to each block header?\n"
"This adds a performance penalty, but ensures that blocks\n"
"have different authentication codes. Note that you can\n"
"have the same benefits by enabling per-file initialization\n"
@ -906,7 +907,8 @@ static bool selectUniqueIV(bool default_answer) {
_("Enable per-file initialization vectors?\n"
"This adds about 8 bytes per file to the storage requirements.\n"
"It should not affect performance except possibly with applications\n"
"which rely on block-aligned file io for performance."), default_answer);
"which rely on block-aligned file io for performance."),
default_answer);
}
/**
@ -964,7 +966,8 @@ RootPtr createV6Config(EncFS_Context *ctx, const shared_ptr<EncFS_Opts> &opts) {
char answer[10] = {0};
if (configMode == Config_Prompt) {
// xgroup(setup)
cout << _("Please choose from one of the following options:\n"
cout << _(
"Please choose from one of the following options:\n"
" enter \"x\" for expert configuration mode,\n"
" enter \"p\" for pre-configured paranoia mode,\n"
" anything else, or an empty line will select standard mode.\n"
@ -1037,7 +1040,8 @@ RootPtr createV6Config(EncFS_Context *ctx, const shared_ptr<EncFS_Opts> &opts) {
if (answer[0] == 'x' || alg.name.empty()) {
if (answer[0] != 'x') {
// xgroup(setup)
cout << _("Sorry, unable to locate cipher for predefined "
cout << _(
"Sorry, unable to locate cipher for predefined "
"configuration...\n"
"Falling through to Manual configuration mode.");
} else {
@ -1057,8 +1061,7 @@ RootPtr createV6Config(EncFS_Context *ctx, const shared_ptr<EncFS_Opts> &opts) {
/* Reverse mounts are read-only by default (set in main.cpp).
* If uniqueIV is off, writing can be allowed, because there
* is no header that could be overwritten */
if (uniqueIV == false)
opts->readOnly = false;
if (uniqueIV == false) opts->readOnly = false;
} else {
chainedIV = selectChainedIV();
uniqueIV = selectUniqueIV(true);
@ -1125,7 +1128,8 @@ RootPtr createV6Config(EncFS_Context *ctx, const shared_ptr<EncFS_Opts> &opts) {
}
// xgroup(setup)
cout << _("Now you will need to enter a password for your filesystem.\n"
cout << _(
"Now you will need to enter a password for your filesystem.\n"
"You will need to remember this password, as there is absolutely\n"
"no recovery mechanism. However, the password can be changed\n"
"later using encfsctl.\n\n");
@ -1198,9 +1202,8 @@ void showFSInfo(const shared_ptr<EncFSConfig> &config) {
cout << autosprintf(
// xgroup(diag)
_("Filesystem cipher: \"%s\", version %i:%i:%i"),
config->cipherIface.name().c_str(),
config->cipherIface.current(), config->cipherIface.revision(),
config->cipherIface.age());
config->cipherIface.name().c_str(), config->cipherIface.current(),
config->cipherIface.revision(), config->cipherIface.age());
// check if we support this interface..
if (!cipher)
cout << _(" (NOT supported)\n");
@ -1218,7 +1221,8 @@ void showFSInfo(const shared_ptr<EncFSConfig> &config) {
{
// xgroup(diag)
cout << autosprintf(_("Filename encoding: \"%s\", version %i:%i:%i"),
config->nameIface.name().c_str(), config->nameIface.current(),
config->nameIface.name().c_str(),
config->nameIface.current(),
config->nameIface.revision(), config->nameIface.age());
// check if we support the filename encoding interface..
@ -1249,7 +1253,8 @@ void showFSInfo(const shared_ptr<EncFSConfig> &config) {
if (config->kdfIterations > 0 && config->salt.size() > 0) {
cout << autosprintf(_("Using PBKDF2, with %i iterations"),
config->kdfIterations) << "\n";
cout << autosprintf(_("Salt Size: %i bits"), (int)(8 * config->salt.size())) << "\n";
cout << autosprintf(_("Salt Size: %i bits"), (int)(8 * config->salt.size()))
<< "\n";
}
if (config->blockMACBytes || config->blockMACRandBytes) {
if (config->subVersion < 20040813) {
@ -1448,7 +1453,7 @@ CipherKey EncFSConfig::getUserKey(const std::string &passProg,
snprintf(tmpBuf, sizeof(tmpBuf) - 1, "%i", stdErrCopy);
setenv(ENCFS_ENV_STDERR, tmpBuf, 1);
execvp(argv[0], (char * const *)argv); // returns only on error..
execvp(argv[0], (char *const *)argv); // returns only on error..
perror(_("Internal error: failed to exec program"));
exit(1);
@ -1502,17 +1507,16 @@ RootPtr initFS(EncFS_Context *ctx, const shared_ptr<EncFS_Opts> &opts) {
if (readConfig(opts->rootDir, config) != Config_None) {
if (config->blockMACBytes == 0 && opts->requireMac) {
cout
<< _("The configuration disabled MAC, but you passed --require-macs\n");
cout << _(
"The configuration disabled MAC, but you passed --require-macs\n");
return rootInfo;
}
if (opts->reverseEncryption) {
if (config->blockMACBytes != 0 || config->blockMACRandBytes != 0 ||
config->externalIVChaining ||
config->chainedNameIV) {
cout
<< _("The configuration loaded is not compatible with --reverse\n");
config->externalIVChaining || config->chainedNameIV) {
cout << _(
"The configuration loaded is not compatible with --reverse\n");
return rootInfo;
}
}
@ -1566,7 +1570,8 @@ RootPtr initFS(EncFS_Context *ctx, const shared_ptr<EncFS_Opts> &opts) {
config->nameIface.name().c_str(), config->nameIface.current(),
config->nameIface.revision(), config->nameIface.age());
// xgroup(diag)
cout << _("The requested filename coding interface is "
cout << _(
"The requested filename coding interface is "
"not available\n");
return rootInfo;
}

View File

@ -674,21 +674,21 @@ void SSL_Cipher::setIVec_old(unsigned char *ivec, unsigned int seed,
ivec[0] ^= (var1 >> 24) & 0xff;
ivec[1] ^= (var2 >> 16) & 0xff;
ivec[2] ^= (var1 >> 8) & 0xff;
ivec[3] ^= (var2) & 0xff;
ivec[3] ^= (var2)&0xff;
ivec[4] ^= (var2 >> 24) & 0xff;
ivec[5] ^= (var1 >> 16) & 0xff;
ivec[6] ^= (var2 >> 8) & 0xff;
ivec[7] ^= (var1) & 0xff;
ivec[7] ^= (var1)&0xff;
if (_ivLength > 8) {
ivec[8 + 0] ^= (var1) & 0xff;
ivec[8 + 0] ^= (var1)&0xff;
ivec[8 + 1] ^= (var2 >> 8) & 0xff;
ivec[8 + 2] ^= (var1 >> 16) & 0xff;
ivec[8 + 3] ^= (var2 >> 24) & 0xff;
ivec[8 + 4] ^= (var1 >> 24) & 0xff;
ivec[8 + 5] ^= (var2 >> 16) & 0xff;
ivec[8 + 6] ^= (var1 >> 8) & 0xff;
ivec[8 + 7] ^= (var2) & 0xff;
ivec[8 + 7] ^= (var2)&0xff;
}
}

View File

@ -101,12 +101,12 @@ int StreamNameIO::encodeName(const char *plaintextName, int length,
if (_interface >= 1) {
// current versions store the checksum at the beginning
encodedName[0] = (mac >> 8) & 0xff;
encodedName[1] = (mac) & 0xff;
encodedName[1] = (mac)&0xff;
encodeBegin = (unsigned char *)encodedName + 2;
} else {
// encfs 0.x stored checksums at the end.
encodedName[length] = (mac >> 8) & 0xff;
encodedName[length + 1] = (mac) & 0xff;
encodedName[length + 1] = (mac)&0xff;
encodeBegin = (unsigned char *)encodedName;
}

View File

@ -62,7 +62,7 @@ class iserializer<Archive, EncFSConfig> : public basic_iserializer {
virtual bool is_polymorphic() const {
return boost::is_polymorphic<EncFSConfig>::value;
}
virtual ~iserializer() {};
virtual ~iserializer(){};
};
template <class Archive>

View File

@ -76,8 +76,7 @@ static EncFS_Context *context() {
* if the argument is NULL.
*/
static bool isReadOnly(EncFS_Context *ctx) {
if (ctx == NULL)
ctx = (EncFS_Context *)fuse_get_context()->private_data;
if (ctx == NULL) ctx = (EncFS_Context *)fuse_get_context()->private_data;
return ctx->opts->readOnly;
}

View File

@ -592,7 +592,8 @@ static int cmd_showcruft(int argc, char **argv) {
int filesFound = showcruft(rootInfo, "/");
// TODO: the singular version should say "Found an invalid file", but all the translations
// TODO: the singular version should say "Found an invalid file", but all the
// translations
// depend upon this broken singular form, so it isn't easy to change.
cerr << autosprintf(ngettext("Found %i invalid file.",
"Found %i invalid files.", filesFound),

View File

@ -224,7 +224,8 @@ static bool processArgs(int argc, char *argv[],
{"extpass", 1, 0, 'p'}, // external password program
// {"single-thread", 0, 0, 's'}, // single-threaded mode
{"stdinpass", 0, 0, 'S'}, // read password from stdin
{"annotate", 0, 0, LONG_OPT_ANNOTATE}, // Print annotation lines to stderr
{"annotate", 0, 0,
LONG_OPT_ANNOTATE}, // Print annotation lines to stderr
{"nocache", 0, 0, LONG_OPT_NOCACHE}, // disable caching
{"verbose", 0, 0, 'v'}, // verbose mode
{"version", 0, 0, 'V'}, // version
@ -404,8 +405,8 @@ static bool processArgs(int argc, char *argv[],
// "default_permissions" comes with a performance cost. Only enable
// it if makes sense.
for(int i=0; i < out->fuseArgc; i++) {
if ( out->fuseArgv[i] == NULL ) {
for (int i = 0; i < out->fuseArgc; i++) {
if (out->fuseArgv[i] == NULL) {
continue;
} else if (strcmp(out->fuseArgv[i], "allow_other") == 0) {
PUSHARG("-o");
@ -415,7 +416,8 @@ static bool processArgs(int argc, char *argv[],
}
#if defined(__APPLE__)
// With OSXFuse, the 'local' flag selects a local filesystem mount icon in Finder.
// With OSXFuse, the 'local' flag selects a local filesystem mount icon in
// Finder.
PUSHARG("-o");
PUSHARG("local");
#endif
@ -700,7 +702,8 @@ int main(int argc, char *argv[]) {
// xgroup(usage)
fputs(_("fuse failed. Common problems:\n"
" - fuse kernel module not installed (modprobe fuse)\n"
" - invalid options -- see usage message\n"), out);
" - invalid options -- see usage message\n"),
out);
fclose(out);
}
} catch (std::exception &ex) {

View File

@ -1,4 +1,5 @@
/* $OpenBSD: readpassphrase.h,v 1.1 2000/11/21 00:48:38 millert Exp $ */
/* $OpenBSD: readpassphrase.h,v 1.1 2000/11/21 00:48:38 millert Exp $
*/
/*
* Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com>
@ -45,7 +46,8 @@
#ifdef __cplusplus
extern "C"
#endif
char *readpassphrase(const char *prompt, char *buf, size_t bufSize, int flags);
char *
readpassphrase(const char *prompt, char *buf, size_t bufSize, int flags);
#endif /* HAVE_READPASSPHRASE */

View File

@ -363,7 +363,8 @@ bool runTests(const shared_ptr<Cipher> &cipher, bool verbose) {
static bool testCipherSize(const string &name, int keySize, int blockSize,
bool verbose) {
cerr << name << ", key length " << keySize << ", block size " << blockSize << ": ";
cerr << name << ", key length " << keySize << ", block size " << blockSize
<< ": ";
shared_ptr<Cipher> cipher = Cipher::New(name, keySize);
if (!cipher) {