1.x: backport support for std::shared_ptr, use __APPLE__ instead of __FreeBSD__

git-svn-id: http://encfs.googlecode.com/svn/branches/1.x@130 db9cf616-1c43-0410-9cb8-a902689de0d6
This commit is contained in:
Valient Gough 2013-11-16 18:24:07 +00:00
parent 3373886fdf
commit b5352f2381
32 changed files with 111 additions and 113 deletions

View File

@ -32,7 +32,6 @@
using namespace rlog;
using namespace rel;
using namespace boost;
static RLogChannel * Info = DEF_CHANNEL( "info/nameio", Log_Info );

View File

@ -23,8 +23,7 @@
#include "NameIO.h"
#include "CipherKey.h"
#include <boost/shared_ptr.hpp>
#include "shared_ptr.h"
class Cipher;
@ -39,7 +38,7 @@ public:
static rel::Interface CurrentInterface(bool caseSensitive = false);
BlockNameIO( const rel::Interface &iface,
const boost::shared_ptr<Cipher> &cipher,
const shared_ptr<Cipher> &cipher,
const CipherKey &key, int blockSize,
bool caseSensitiveEncoding = false );
virtual ~BlockNameIO();
@ -60,7 +59,7 @@ protected:
private:
int _interface;
int _bs;
boost::shared_ptr<Cipher> _cipher;
shared_ptr<Cipher> _cipher;
CipherKey _key;
bool _caseSensitive;
};

View File

@ -37,7 +37,6 @@
using namespace std;
using namespace rel;
using boost::shared_ptr;
#define REF_MODULE(TYPE) \
if( !TYPE::Enabled() ) \

View File

@ -31,8 +31,6 @@
#include <list>
#include <inttypes.h>
using boost::shared_ptr;
/*
Mostly pure virtual interface defining operations on a cipher.
@ -44,8 +42,8 @@ class Cipher
public:
// if no key length was indicated when cipher was registered, then keyLen
// <= 0 will be used.
typedef boost::shared_ptr<Cipher> (*CipherConstructor)( const rel::Interface &iface,
int keyLenBits );
typedef shared_ptr<Cipher> (*CipherConstructor)( const rel::Interface &iface,
int keyLenBits );
struct CipherAlgorithm
{
@ -61,9 +59,9 @@ public:
static AlgorithmList GetAlgorithmList( bool includeHidden = false );
static boost::shared_ptr<Cipher> New( const rel::Interface &iface,
static shared_ptr<Cipher> New( const rel::Interface &iface,
int keyLen = -1);
static boost::shared_ptr<Cipher> New( const std::string &cipherName,
static shared_ptr<Cipher> New( const std::string &cipherName,
int keyLen = -1 );

View File

@ -29,8 +29,6 @@
#include <fcntl.h>
#include <cerrno>
using boost::shared_ptr;
/*
- Version 2:0 adds support for a per-file initialization vector with a
fixed 8 byte header. The headers are enabled globally within a

View File

@ -37,7 +37,7 @@ class Cipher;
class CipherFileIO : public BlockFileIO
{
public:
CipherFileIO( const boost::shared_ptr<FileIO> &base,
CipherFileIO( const shared_ptr<FileIO> &base,
const FSConfigPtr &cfg);
virtual ~CipherFileIO();
@ -71,7 +71,7 @@ private:
bool streamWrite( unsigned char *buf, int size,
uint64_t iv64 ) const;
boost::shared_ptr<FileIO> base;
shared_ptr<FileIO> base;
FSConfigPtr fsConfig;
@ -82,7 +82,7 @@ private:
uint64_t fileIV;
int lastFlags;
boost::shared_ptr<Cipher> cipher;
shared_ptr<Cipher> cipher;
CipherKey key;
};

View File

@ -21,7 +21,7 @@
#ifndef _CipherKey_incl_
#define _CipherKey_incl_
#include <boost/shared_ptr.hpp>
#include "shared_ptr.h"
class AbstractCipherKey
{
@ -30,7 +30,7 @@ public:
virtual ~AbstractCipherKey();
};
typedef boost::shared_ptr<AbstractCipherKey> CipherKey;
typedef shared_ptr<AbstractCipherKey> CipherKey;
#endif

View File

@ -22,9 +22,7 @@
#define _ConfigVar_incl_
#include <string>
#include <boost/shared_ptr.hpp>
using boost::shared_ptr;
#include "shared_ptr.h"
class ConfigVar
{

View File

@ -140,7 +140,7 @@ shared_ptr<FileNode> EncFS_Context::getNode(void *pl)
}
void *EncFS_Context::putNode(const char *path,
const boost::shared_ptr<FileNode> &node)
const shared_ptr<FileNode> &node)
{
Lock lock( contextMutex );
Placeholder *pl = new Placeholder( node );

View File

@ -21,8 +21,6 @@
#ifndef _Context_incl_
#define _Context_incl_
#include "encfs.h"
#include <boost/shared_ptr.hpp>
#include <set>
#ifdef USE_HASHMAP
@ -31,7 +29,9 @@
#include <map>
#endif
using boost::shared_ptr;
#include "encfs.h"
#include "shared_ptr.h"
struct EncFS_Args;
struct EncFS_Opts;
class FileNode;

View File

@ -101,7 +101,7 @@ bool _nextName(struct dirent *&de, const shared_ptr<DIR> &dir,
{
if(fileType)
{
#if defined(_DIRENT_HAVE_D_TYPE) || defined(__FreeBSD__)
#if defined(_DIRENT_HAVE_D_TYPE) || defined(__FreeBSD__) || defined(__APPLE__)
*fileType = de->d_type;
#else
#warning "struct dirent.d_type not supported"

View File

@ -35,8 +35,6 @@
#include "CipherKey.h"
#include "FSConfig.h"
using boost::shared_ptr;
class Cipher;
class RenameOp;
struct RenameEl;
@ -73,7 +71,7 @@ private:
uint64_t iv;
shared_ptr<NameIO> naming;
};
inline bool DirTraverse::valid() const { return dir != 0; }
inline bool DirTraverse::valid() const { return dir.get() != 0; }
#ifdef USE_HASHMAP
namespace __gnu_cxx

View File

@ -21,12 +21,12 @@
#ifndef _FSConfig_incl_
#define _FSConfig_incl_
#include <vector>
#include "encfs.h"
#include "Interface.h"
#include "CipherKey.h"
#include <vector>
#include <boost/shared_ptr.hpp>
#include "shared_ptr.h"
enum ConfigType
{
@ -93,7 +93,7 @@ struct EncFSConfig
const std::string &rootDir);
CipherKey getNewUserKey();
boost::shared_ptr<Cipher> getCipher() const;
shared_ptr<Cipher> getCipher() const;
// deprecated
void assignKeyData(const std::string &in);
@ -113,12 +113,12 @@ std::istream &operator >> (std::istream &os, EncFSConfig &cfg);
struct FSConfig
{
boost::shared_ptr<EncFSConfig> config;
boost::shared_ptr<EncFS_Opts> opts;
shared_ptr<EncFSConfig> config;
shared_ptr<EncFS_Opts> opts;
boost::shared_ptr<Cipher> cipher;
shared_ptr<Cipher> cipher;
CipherKey key;
boost::shared_ptr<NameIO> nameCoding;
shared_ptr<NameIO> nameCoding;
bool forceDecode; // force decode on MAC block failures
bool reverseEncryption; // reverse encryption operation
@ -126,7 +126,7 @@ struct FSConfig
bool idleTracking; // turn on idle monitoring of filesystem
};
typedef boost::shared_ptr<FSConfig> FSConfigPtr;
typedef shared_ptr<FSConfig> FSConfigPtr;
#endif

View File

@ -53,7 +53,6 @@
using namespace std;
using namespace rel;
using namespace rlog;
using boost::dynamic_pointer_cast;
/*
TODO: locking at the FileNode level is inefficient, since this precludes

View File

@ -32,7 +32,6 @@
class Cipher;
class FileIO;
class DirNode;
using boost::shared_ptr;
class FileNode
{

View File

@ -110,10 +110,10 @@ struct ConfigInfo
ConfigType type;
const char *environmentOverride;
bool (*loadFunc)(const char *fileName,
const boost::shared_ptr<EncFSConfig> &config,
const shared_ptr<EncFSConfig> &config,
ConfigInfo *cfg);
bool (*saveFunc)(const char *fileName,
const boost::shared_ptr<EncFSConfig> &config);
const shared_ptr<EncFSConfig> &config);
int currentSubVersion;
int defaultSubVersion;
} ConfigFileMapping[] = {
@ -362,7 +362,7 @@ bool userAllowMkdir(int promptno, const char *path, mode_t mode )
}
ConfigType readConfig_load( ConfigInfo *nm, const char *path,
const boost::shared_ptr<EncFSConfig> &config )
const shared_ptr<EncFSConfig> &config )
{
if( nm->loadFunc )
{
@ -389,7 +389,7 @@ ConfigType readConfig_load( ConfigInfo *nm, const char *path,
}
ConfigType readConfig( const string &rootDir,
const boost::shared_ptr<EncFSConfig> &config )
const shared_ptr<EncFSConfig> &config )
{
ConfigInfo *nm = ConfigFileMapping;
while(nm->fileName)
@ -413,7 +413,7 @@ ConfigType readConfig( const string &rootDir,
}
bool readV6Config( const char *configFile,
const boost::shared_ptr<EncFSConfig> &config,
const shared_ptr<EncFSConfig> &config,
ConfigInfo *info)
{
(void)info;
@ -440,7 +440,7 @@ bool readV6Config( const char *configFile,
}
bool readV5Config( const char *configFile,
const boost::shared_ptr<EncFSConfig> &config,
const shared_ptr<EncFSConfig> &config,
ConfigInfo *info)
{
bool ok = false;
@ -498,7 +498,7 @@ bool readV5Config( const char *configFile,
}
bool readV4Config( const char *configFile,
const boost::shared_ptr<EncFSConfig> &config,
const shared_ptr<EncFSConfig> &config,
ConfigInfo *info)
{
bool ok = false;
@ -539,7 +539,7 @@ bool readV4Config( const char *configFile,
}
bool saveConfig( ConfigType type, const string &rootDir,
const boost::shared_ptr<EncFSConfig> &config )
const shared_ptr<EncFSConfig> &config )
{
bool ok = false;
@ -574,7 +574,7 @@ bool saveConfig( ConfigType type, const string &rootDir,
}
bool writeV6Config( const char *configFile,
const boost::shared_ptr<EncFSConfig> &config )
const shared_ptr<EncFSConfig> &config )
{
fs::ofstream st( configFile );
if(!st.is_open())
@ -601,7 +601,7 @@ std::istream &operator >> (std::istream &st, EncFSConfig &cfg)
}
bool writeV5Config( const char *configFile,
const boost::shared_ptr<EncFSConfig> &config )
const shared_ptr<EncFSConfig> &config )
{
ConfigReader cfg;
@ -624,7 +624,7 @@ bool writeV5Config( const char *configFile,
}
bool writeV4Config( const char *configFile,
const boost::shared_ptr<EncFSConfig> &config )
const shared_ptr<EncFSConfig> &config )
{
ConfigReader cfg;
@ -1262,7 +1262,7 @@ RootPtr createV6Config( EncFS_Context *ctx,
return rootInfo;
}
void showFSInfo( const boost::shared_ptr<EncFSConfig> &config )
void showFSInfo( const shared_ptr<EncFSConfig> &config )
{
shared_ptr<Cipher> cipher = Cipher::New( config->cipherIface, -1 );
{
@ -1615,7 +1615,7 @@ CipherKey EncFSConfig::getNewUserKey()
RootPtr initFS( EncFS_Context *ctx, const shared_ptr<EncFS_Opts> &opts )
{
RootPtr rootInfo;
boost::shared_ptr<EncFSConfig> config(new EncFSConfig);
shared_ptr<EncFSConfig> config(new EncFSConfig);
if(readConfig( opts->rootDir, config ) != Config_None)
{

View File

@ -47,15 +47,15 @@ class DirNode;
struct EncFS_Root
{
boost::shared_ptr<Cipher> cipher;
shared_ptr<Cipher> cipher;
CipherKey volumeKey;
boost::shared_ptr<DirNode> root;
shared_ptr<DirNode> root;
EncFS_Root();
~EncFS_Root();
};
typedef boost::shared_ptr<EncFS_Root> RootPtr;
typedef shared_ptr<EncFS_Root> RootPtr;
enum ConfigMode
{
@ -105,40 +105,40 @@ struct EncFS_Opts
Read existing config file. Looks for any supported configuration version.
*/
ConfigType readConfig( const std::string &rootDir,
const boost::shared_ptr<EncFSConfig> &config );
const shared_ptr<EncFSConfig> &config );
/*
Save the configuration. Saves back as the same configuration type as was
read from.
*/
bool saveConfig( ConfigType type, const std::string &rootdir,
const boost::shared_ptr<EncFSConfig> &config );
const shared_ptr<EncFSConfig> &config );
class EncFS_Context;
RootPtr initFS( EncFS_Context *ctx, const boost::shared_ptr<EncFS_Opts> &opts );
RootPtr initFS( EncFS_Context *ctx, const shared_ptr<EncFS_Opts> &opts );
RootPtr createV6Config( EncFS_Context *ctx,
const boost::shared_ptr<EncFS_Opts> &opts );
const shared_ptr<EncFS_Opts> &opts );
void showFSInfo( const boost::shared_ptr<EncFSConfig> &config );
void showFSInfo( const shared_ptr<EncFSConfig> &config );
bool readV4Config( const char *configFile,
const boost::shared_ptr<EncFSConfig> &config,
const shared_ptr<EncFSConfig> &config,
struct ConfigInfo *);
bool writeV4Config( const char *configFile,
const boost::shared_ptr<EncFSConfig> &config);
const shared_ptr<EncFSConfig> &config);
bool readV5Config( const char *configFile,
const boost::shared_ptr<EncFSConfig> &config,
const shared_ptr<EncFSConfig> &config,
struct ConfigInfo *);
bool writeV5Config( const char *configFile,
const boost::shared_ptr<EncFSConfig> &config);
const shared_ptr<EncFSConfig> &config);
bool readV6Config( const char *configFile,
const boost::shared_ptr<EncFSConfig> &config,
const shared_ptr<EncFSConfig> &config,
struct ConfigInfo *);
bool writeV6Config( const char *configFile,
const boost::shared_ptr<EncFSConfig> &config);
const shared_ptr<EncFSConfig> &config);
#endif

View File

@ -34,8 +34,6 @@
using namespace rlog;
using namespace rel;
using namespace std;
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
static RLogChannel *Info = DEF_CHANNEL("info/MACFileIO", Log_Info);
//

View File

@ -24,8 +24,6 @@
#include "BlockFileIO.h"
#include "Cipher.h"
using boost::shared_ptr;
class MACFileIO : public BlockFileIO
{
public:

View File

@ -5,14 +5,7 @@ ALL_INCLUDES = @RLOG_CFLAGS@ @OPENSSL_CFLAGS@ @BOOST_CPPFLAGS@
ALL_LDFLAGS = @RLOG_LIBS@ @OPENSSL_LIBS@ @BOOST_LDFLAGS@
ALL_LDFLAGS += @BOOST_SERIALIZATION_LIB@ @BOOST_FILESYSTEM_LIB@ @BOOST_SYSTEM_LIB@
INCLUDES = $(all_includes) -I../intl
AM_CXXFLAGS = -DRLOG_COMPONENT="encfs" $(ALL_INCLUDES)
if DARWIN
# needed to select correct API in fuse.h
AM_CXXFLAGS += -D__FreeBSD__=10
endif
AM_CXXFLAGS = -DRLOG_COMPONENT="encfs" $(ALL_INCLUDES) -I../intl
if BUILD_NLS
# define a C macro LOCALEDIR indicating where catalogs will be installed

View File

@ -29,7 +29,6 @@
#include "Interface.h"
#include "CipherKey.h"
using boost::shared_ptr;
class Cipher;
class NameIO

View File

@ -18,22 +18,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "NullCipher.h"
#include <cstring>
#include <rlog/rlog.h>
#include "Range.h"
#include "Interface.h"
#include <boost/shared_ptr.hpp>
#include <rlog/rlog.h>
#include <cstring>
#include "shared_ptr.h"
using namespace std;
using namespace rel;
using namespace rlog;
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
static Interface NullInterface( "nullCipher", 1, 0, 0 );
static Range NullKeyRange(0);

View File

@ -26,7 +26,6 @@
#include <cstring>
using namespace rel;
using boost::shared_ptr;
static shared_ptr<NameIO> NewNNIO( const Interface &,
const shared_ptr<Cipher> &, const CipherKey & )

View File

@ -296,7 +296,7 @@ int RawFileIO::truncate( off_t size )
if(fd >= 0 && canWrite)
{
res = ::ftruncate( fd, size );
#ifndef __FreeBSD__
#if !defined(__FreeBSD__) && !defined(__APPLE__)
::fdatasync( fd );
#endif
} else

View File

@ -48,9 +48,6 @@ using namespace std;
using namespace rel;
using namespace rlog;
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
const int MAX_KEYLENGTH = 32; // in bytes (256 bit)
const int MAX_IVLENGTH = 16;
const int KEY_CHECKSUM_BYTES = 4;

View File

@ -30,8 +30,6 @@ struct evp_cipher_st;
typedef struct evp_cipher_st EVP_CIPHER;
#endif
using boost::shared_ptr;
/*
Implements Cipher interface for OpenSSL's ciphers.

View File

@ -25,7 +25,6 @@
#include "CipherKey.h"
class Cipher;
using boost::shared_ptr;
class StreamNameIO : public NameIO
{

View File

@ -130,7 +130,7 @@ static int withFileNode( const char *opName,
else
fnode = FSRoot->lookupNode( path, opName );
rAssert(fnode != NULL);
rAssert(fnode.get() != NULL);
rLog(Info, "%s %s", opName, fnode->cipherName());
res = op( fnode.get(), data );

View File

@ -26,6 +26,7 @@
#include "Context.h"
#include "FileNode.h"
#include "DirNode.h"
#include "shared_ptr.h"
#include <rlog/rlog.h>
#include <rlog/StdioNode.h>
@ -51,8 +52,8 @@
using namespace rlog;
using namespace std;
using namespace boost;
using boost::format;
using boost::scoped_array;
static int showInfo( int argc, char **argv );
static int showVersion( int argc, char **argv );
@ -172,7 +173,7 @@ static int showInfo( int argc, char **argv )
if( !checkDir( rootDir ))
return EXIT_FAILURE;
boost::shared_ptr<EncFSConfig> config(new EncFSConfig);
shared_ptr<EncFSConfig> config(new EncFSConfig);
ConfigType type = readConfig( rootDir, config );
// show information stored in config..
@ -698,7 +699,7 @@ static int do_chpasswd( bool useStdin, bool annotate, int argc, char **argv )
if( !checkDir( rootDir ))
return EXIT_FAILURE;
boost::shared_ptr<EncFSConfig> config(new EncFSConfig);
shared_ptr<EncFSConfig> config(new EncFSConfig);
ConfigType cfgType = readConfig( rootDir, config );
if(cfgType == Config_None)

View File

@ -16,9 +16,6 @@
*
*/
#include "encfs.h"
#include "config.h"
#include <iostream>
#include <string>
#include <sstream>
@ -34,7 +31,6 @@
#include <boost/format.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <rlog/rlog.h>
#include <rlog/Error.h>
@ -43,13 +39,15 @@
#include <rlog/StdioNode.h>
#include "ConfigReader.h"
#include "Context.h"
#include "DirNode.h"
#include "FileUtils.h"
#include "Interface.h"
#include "MemoryPool.h"
#include "FileUtils.h"
#include "DirNode.h"
#include "Context.h"
#include "config.h"
#include "encfs.h"
#include "openssl.h"
#include "shared_ptr.h"
#include <locale.h>
@ -71,7 +69,6 @@ using namespace std;
using namespace rlog;
using namespace rel;
using boost::format;
using boost::shared_ptr;
using boost::scoped_ptr;
// Maximum number of arguments that we're going to pass on to fuse. Doesn't
@ -592,7 +589,7 @@ int main(int argc, char *argv[])
encfs_oper.utimens = encfs_utimens;
//encfs_oper.bmap = encfs_bmap;
#if (__FreeBSD__ >= 10)
#if (__FreeBSD__ >= 10) || defined(__APPLE__)
// encfs_oper.setvolname
// encfs_oper.exchange
// encfs_oper.getxtimes

37
encfs/shared_ptr.h Normal file
View File

@ -0,0 +1,37 @@
/*****************************************************************************
* Author: Valient Gough <vgough@pobox.com>
*
*****************************************************************************
* Copyright (c) 2012 Valient Gough
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _SHARED_PTR_incl_
#define _SHARED_PTR_incl_
#include "config.h"
#ifdef HAVE_STD_SHARED_PTR
#include <memory>
using std::shared_ptr;
using std::dynamic_pointer_cast;
#else
#include <boost/shared_ptr.hpp>
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
#endif
#endif

View File

@ -52,8 +52,6 @@ using namespace std;
using namespace rel;
using namespace rlog;
using boost::shared_ptr;
const int FSBlockSize = 256;
static