mirror of
https://github.com/vgough/encfs.git
synced 2025-02-16 09:49:46 +01:00
add extpass option and multi-argument support to encode and decode encfsctl commands. closes issue 33
git-svn-id: http://encfs.googlecode.com/svn/trunk@50 db9cf616-1c43-0410-9cb8-a902689de0d6
This commit is contained in:
parent
72cbe023d5
commit
8b5cd78695
@ -345,6 +345,12 @@ DirNode::cipherPath( const char *plaintextPath )
|
||||
return rootDir + naming->encodePath( plaintextPath );
|
||||
}
|
||||
|
||||
string
|
||||
DirNode::cipherPathWithoutRoot( const char *plaintextPath )
|
||||
{
|
||||
return naming->encodePath( plaintextPath );
|
||||
}
|
||||
|
||||
string
|
||||
DirNode::plainPath( const char *cipherPath_ )
|
||||
{
|
||||
@ -844,4 +850,3 @@ int DirNode::unlink( const char *plaintextName )
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -140,6 +140,7 @@ public:
|
||||
shared_ptr<FileNode> directLookup( const char *realPath );
|
||||
|
||||
std::string cipherPath( const char *plaintextPath );
|
||||
std::string cipherPathWithoutRoot( const char *plaintextPath );
|
||||
std::string plainPath( const char *cipherPath );
|
||||
|
||||
// relative cipherPath is the same as cipherPath except that it doesn't
|
||||
@ -213,4 +214,3 @@ private:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <getopt.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
@ -97,10 +98,10 @@ struct CommandOpts
|
||||
{"cat", 2, 2, cmd_cat, "(root dir) path",
|
||||
// xgroup(usage)
|
||||
gettext_noop(" -- decodes the file and cats it to standard out")},
|
||||
{"decode", 1, 2, cmd_decode, "(root dir) encoded-name",
|
||||
{"decode", 1, 100, cmd_decode, "[--extpass=prog] (root dir) [encoded-name ...]",
|
||||
// xgroup(usage)
|
||||
gettext_noop(" -- decodes name and prints plaintext version")},
|
||||
{"encode", 1, 2, cmd_encode, "(root dir) [plaintext-name]",
|
||||
{"encode", 1, 100, cmd_encode, "[--extpass=prog] (root dir) [plaintext-name ...]",
|
||||
// xgroup(usage)
|
||||
gettext_noop(" -- encodes a filename and print result")},
|
||||
{"export", 2, 2, cmd_export, "(root dir) path",
|
||||
@ -217,6 +218,61 @@ static int showInfo( int argc, char **argv )
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static RootPtr initRootInfo(int &argc, char ** &argv)
|
||||
{
|
||||
RootPtr result;
|
||||
shared_ptr<EncFS_Opts> opts( new EncFS_Opts() );
|
||||
opts->createIfNotFound = false;
|
||||
opts->checkKey = false;
|
||||
|
||||
static struct option long_options[] = {
|
||||
{"extpass", 1, 0, 'p'},
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
for(;;)
|
||||
{
|
||||
int option_index = 0;
|
||||
|
||||
int res = getopt_long( argc, argv, "",
|
||||
long_options, &option_index);
|
||||
if(res == -1)
|
||||
break;
|
||||
|
||||
switch(res)
|
||||
{
|
||||
case 'p':
|
||||
opts->passwordProgram.assign(optarg);
|
||||
break;
|
||||
default:
|
||||
rWarning(_("getopt error: %i"), res);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if(argc == 0)
|
||||
{
|
||||
cerr << _("Incorrect number of arguments") << "\n";
|
||||
} else
|
||||
{
|
||||
opts->rootDir = string( argv[0] );
|
||||
|
||||
--argc;
|
||||
++argv;
|
||||
|
||||
if(checkDir( opts->rootDir ))
|
||||
result = initFS( NULL, opts );
|
||||
|
||||
if(!result)
|
||||
cerr << _("Unable to initialize encrypted filesystem - check path.\n");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static RootPtr initRootInfo(const char* crootDir)
|
||||
{
|
||||
string rootDir(crootDir);
|
||||
@ -257,54 +313,48 @@ static int cmd_showKey( int argc, char **argv )
|
||||
|
||||
static int cmd_decode( int argc, char **argv )
|
||||
{
|
||||
RootPtr rootInfo = initRootInfo(argv[1]);
|
||||
|
||||
RootPtr rootInfo = initRootInfo(argc, argv);
|
||||
if(!rootInfo)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if( argc > 2 )
|
||||
if(argc > 0)
|
||||
{
|
||||
string name = rootInfo->root->plainPath( argv[2] );
|
||||
cout << name << "\n";
|
||||
for(int i=0; i<argc; ++i)
|
||||
{
|
||||
string name = rootInfo->root->plainPath( argv[i] );
|
||||
cout << name << "\n";
|
||||
}
|
||||
} else
|
||||
{
|
||||
do
|
||||
char buf[PATH_MAX+1];
|
||||
while(cin.getline(buf,PATH_MAX))
|
||||
{
|
||||
string name;
|
||||
cin >> name;
|
||||
if(name.empty())
|
||||
break;
|
||||
|
||||
name = rootInfo->root->plainPath( name.c_str() );
|
||||
cout << name << "\n";
|
||||
} while(1);
|
||||
cout << rootInfo->root->plainPath( buf ) << "\n";
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static int cmd_encode( int argc, char **argv )
|
||||
{
|
||||
RootPtr rootInfo = initRootInfo(argv[1]);
|
||||
|
||||
RootPtr rootInfo = initRootInfo(argc, argv);
|
||||
if(!rootInfo)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if( argc > 2 )
|
||||
if(argc > 0)
|
||||
{
|
||||
string name = rootInfo->root->cipherPath( argv[2] );
|
||||
cout << name << "\n";
|
||||
for(int i=0; i<argc; ++i)
|
||||
{
|
||||
string name = rootInfo->root->cipherPathWithoutRoot(argv[i]);
|
||||
cout << name << "\n";
|
||||
}
|
||||
} else
|
||||
{
|
||||
do
|
||||
char buf[PATH_MAX+1];
|
||||
while(cin.getline(buf,PATH_MAX))
|
||||
{
|
||||
string name;
|
||||
cin >> name;
|
||||
if(name.empty())
|
||||
break;
|
||||
|
||||
name = rootInfo->root->cipherPath( name.c_str() );
|
||||
cout << name << "\n";
|
||||
} while(1);
|
||||
cout << rootInfo->root->cipherPathWithoutRoot( buf ) << "\n";
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@ -800,5 +850,3 @@ int main(int argc, char **argv)
|
||||
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -25,7 +25,9 @@ B<encfsctl> passwd I<rootdir>
|
||||
|
||||
B<encfsctl> showcruft I<rootdir>
|
||||
|
||||
B<encfsctl> decode I<rootdir> [encoded name]
|
||||
B<encfsctl> decode [--extpass=prog] I<rootdir> [encoded name ...]
|
||||
|
||||
B<encfsctl> encode [--extpass=prog] I<rootdir> [plaintext name ...]
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
@ -58,14 +60,29 @@ files which are not decodable under the primary key.
|
||||
|
||||
=item B<decode>
|
||||
|
||||
Allows you to specify an encoded name on the command line, and displayed a
|
||||
Allows you to specify an encoded name on the command line, and displays
|
||||
decoded version. This is mostly useful for debugging, as debug messages always
|
||||
display encrypted filenames (to avoid leaking sensitive data through the debug
|
||||
channels). So this command provides a way to decode the filenames.
|
||||
|
||||
If no name is specified on the command line, then a list of filenames will be
|
||||
The B<--extpass> option can be used to specify the program which returns the
|
||||
password - just like with encfs.
|
||||
|
||||
If no names are specified on the command line, then a list of filenames will be
|
||||
read from stdin and decoded.
|
||||
|
||||
=item B<encode>
|
||||
|
||||
Allows you to specify a filename on the command line, and displays its
|
||||
encoded version. This is useful if e.g. you are taking a backup of an
|
||||
encrypted directory and would like to exclude some files.
|
||||
|
||||
The B<--extpass> option can be used to specify the program which returns the
|
||||
password - just like with encfs.
|
||||
|
||||
If no names are specified on the command line, then a list of filenames
|
||||
will be read from stdin and encoded.
|
||||
|
||||
=back
|
||||
|
||||
=head1 EXAMPLES
|
||||
@ -96,4 +113,3 @@ EncFS was written by Valient Gough <vgough@pobox.com>.
|
||||
=head1 SEE ALSO
|
||||
|
||||
encfs(1)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user