Skip to content

Commit

Permalink
add annotation option. patch by Werner Koch
Browse files Browse the repository at this point in the history
git-svn-id: http://encfs.googlecode.com/svn/trunk@68 db9cf616-1c43-0410-9cb8-a902689de0d6
  • Loading branch information
vgough committed Dec 7, 2010
1 parent f6e3639 commit b20b71a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 9 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

Tue Dec 7 2010 Valient Gough <[email protected]>
* add annotation option, patch by Werner Koch.

Sun Sep 5 2010 Valient Gough <[email protected]>
* fix mount failures when using certain options, due to changes in
option passing mechanism in 1.7
Expand Down
32 changes: 30 additions & 2 deletions encfs/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,32 @@ std::string parentDirectory( const std::string &path )
return path.substr(0, last);
}

bool userAllowMkdir( const char *path, mode_t mode )
bool userAllowMkdir(const char *path, mode_t mode )
{
return userAllowMkdir(0, path, mode);
}

bool userAllowMkdir(int promptno, const char *path, mode_t mode )
{
// TODO: can we internationalize the y/n names? Seems strange to prompt in
// their own language but then have to respond 'y' or 'n'.
// xgroup(setup)
cerr << autosprintf( _("The directory \"%s\" does not exist. Should it be created? (y,n) "), path );
char answer[10];
char *res = fgets( answer, sizeof(answer), stdin );
char *res;

switch (promptno)
{
case 1:
cerr << endl << "$PROMPT$ create_root_dir" << endl;
break;
case 2:
cerr << endl << "$PROMPT$ create_mount_point" << endl;
break;
default:
break;
}
res = fgets( answer, sizeof(answer), stdin );

if(res != 0 && toupper(answer[0]) == 'Y')
{
Expand Down Expand Up @@ -976,6 +994,7 @@ RootPtr createV6Config( EncFS_Context *ctx,
bool useStdin = opts->useStdin;
bool reverseEncryption = opts->reverseEncryption;
ConfigMode configMode = opts->configMode;
bool annotate = opts->annotate;

RootPtr rootInfo;

Expand All @@ -994,6 +1013,9 @@ RootPtr createV6Config( EncFS_Context *ctx,
" anything else, or an empty line will select standard mode.\n"
"?> ");

if (annotate)
cerr << "$PROMPT$ config_option" << endl;

char *res = fgets( answer, sizeof(answer), stdin );
(void)res;
cout << "\n";
Expand Down Expand Up @@ -1179,7 +1201,11 @@ RootPtr createV6Config( EncFS_Context *ctx,
CipherKey userKey;
rDebug( "useStdin: %i", useStdin );
if(useStdin)
{
if (annotate)
cerr << "$PROMPT$ new_passwd" << endl;
userKey = config->getUserKey( useStdin );
}
else if(!passwordProgram.empty())
userKey = config->getUserKey( passwordProgram, rootDir );
else
Expand Down Expand Up @@ -1618,6 +1644,8 @@ RootPtr initFS( EncFS_Context *ctx, const shared_ptr<EncFS_Opts> &opts )
if(opts->passwordProgram.empty())
{
rDebug( "useStdin: %i", opts->useStdin );
if (opts->annotate)
cerr << "$PROMPT$ passwd" << endl;
userKey = config->getUserKey( opts->useStdin );
} else
userKey = config->getUserKey( opts->passwordProgram, opts->rootDir );
Expand Down
5 changes: 4 additions & 1 deletion encfs/FileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ std::string parentDirectory( const std::string &path );

// ask the user for permission to create the directory. If they say ok, then
// do it and return true.
bool userAllowMkdir( const char *dirPath, mode_t mode );
bool userAllowMkdir(const char *dirPath, mode_t mode );
bool userAllowMkdir(int promptno, const char *dirPath, mode_t mode );

class Cipher;
class DirNode;
Expand Down Expand Up @@ -72,6 +73,7 @@ struct EncFS_Opts

std::string passwordProgram; // path to password program (or empty)
bool useStdin; // read password from stdin rather then prompting
bool annotate; // print annotation line prompt to stderr.

bool ownerCreate; // set owner of new files to caller

Expand All @@ -87,6 +89,7 @@ struct EncFS_Opts
checkKey = true;
forceDecode = false;
useStdin = false;
annotate = false;
ownerCreate = false;
reverseEncryption = false;
configMode = Config_Prompt;
Expand Down
12 changes: 9 additions & 3 deletions encfs/encfsctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ static int cmd_showcruft( int argc, char **argv )
return EXIT_SUCCESS;
}

static int do_chpasswd( bool useStdin, int argc, char **argv )
static int do_chpasswd( bool useStdin, bool annotate, int argc, char **argv )
{
(void)argc;
string rootDir = argv[1];
Expand Down Expand Up @@ -721,6 +721,8 @@ static int do_chpasswd( bool useStdin, int argc, char **argv )

// ask for existing password
cout << _("Enter current Encfs password\n");
if (annotate)
cerr << "$PROMPT$ passwd" << endl;
CipherKey userKey = config->getUserKey( useStdin );
if(!userKey)
return EXIT_FAILURE;
Expand All @@ -742,7 +744,11 @@ static int do_chpasswd( bool useStdin, int argc, char **argv )
config->kdfIterations = 0; // generate new

if( useStdin )
{
if (annotate)
cerr << "$PROMPT$ new_passwd" << endl;
userKey = config->getUserKey( true );
}
else
userKey = config->getNewUserKey();

Expand Down Expand Up @@ -781,12 +787,12 @@ static int do_chpasswd( bool useStdin, int argc, char **argv )

static int chpasswd( int argc, char **argv )
{
return do_chpasswd( false, argc, argv );
return do_chpasswd( false, false, argc, argv );
}

static int chpasswdAutomaticly( int argc, char **argv )
{
return do_chpasswd( true, argc, argv );
return do_chpasswd( true, false, argc, argv );
}


Expand Down
20 changes: 17 additions & 3 deletions encfs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ struct EncFS_Args
if(opts->forceDecode) ss << "(forceDecode) ";
if(opts->ownerCreate) ss << "(ownerCreate) ";
if(opts->useStdin) ss << "(useStdin) ";
if(opts->annotate) ss << "(annotate) ";
if(opts->reverseEncryption) ss << "(reverseEncryption) ";
if(opts->mountOnDemand) ss << "(mountOnDemand) ";
for(int i=0; i<fuseArgc; ++i)
Expand Down Expand Up @@ -196,6 +197,7 @@ bool processArgs(int argc, char *argv[], const shared_ptr<EncFS_Args> &out)
out->opts->forceDecode = false;
out->opts->ownerCreate = false;
out->opts->useStdin = false;
out->opts->annotate = false;
out->opts->reverseEncryption = false;

bool useDefaultFlags = true;
Expand Down Expand Up @@ -223,6 +225,7 @@ bool processArgs(int argc, char *argv[], const shared_ptr<EncFS_Args> &out)
{"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, 513}, // Print annotation lines to stderr
{"verbose", 0, 0, 'v'}, // verbose mode
{"version", 0, 0, 'V'}, //version
{"reverse", 0, 0, 'r'}, // reverse encryption
Expand Down Expand Up @@ -263,6 +266,9 @@ bool processArgs(int argc, char *argv[], const shared_ptr<EncFS_Args> &out)
case 'S':
out->opts->useStdin = true;
break;
case 513:
out->opts->annotate = true;
break;
case 'f':
out->isDaemon = false;
// this option was added in fuse 2.x
Expand Down Expand Up @@ -411,13 +417,15 @@ bool processArgs(int argc, char *argv[], const shared_ptr<EncFS_Args> &out)

// check that the directories exist, or that we can create them..
if(!isDirectory( out->opts->rootDir.c_str() ) &&
!userAllowMkdir( out->opts->rootDir.c_str() ,0700))
!userAllowMkdir( out->opts->annotate? 1:0,
out->opts->rootDir.c_str() ,0700))
{
rWarning(_("Unable to locate root directory, aborting."));
return false;
}
if(!isDirectory( out->mountPoint.c_str() ) &&
!userAllowMkdir( out->mountPoint.c_str(),0700))
!userAllowMkdir( out->opts->annotate? 2:0,
out->mountPoint.c_str(),0700))
{
rWarning(_("Unable to locate mount point, aborting."));
return false;
Expand Down Expand Up @@ -630,7 +638,10 @@ int main(int argc, char *argv[])
try
{
time_t startTime, endTime;


if (encfsArgs->opts->annotate)
cerr << "$STATUS$ fuse_main_start" << endl;

// FIXME: workaround for fuse_main returning an error on normal
// exit. Only print information if fuse_main returned
// immediately..
Expand All @@ -642,6 +653,9 @@ int main(int argc, char *argv[])
&encfs_oper, (void*)ctx);

time( &endTime );

if (encfsArgs->opts->annotate)
cerr << "$STATUS$ fuse_main_end" << endl;

if(res == 0)
returnCode = EXIT_SUCCESS;
Expand Down

0 comments on commit b20b71a

Please sign in to comment.