"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "zuluCrypt-cli/lib/open_tcrypt.c" between
zuluCrypt-5.7.0.tar.xz and zuluCrypt-5.7.1.tar.xz

About: zuluCrypt is a simple but feature rich solution for hard drives encryption. It can manage PLAIN dm-crypt, LUKS, TrueCrypt and VeraCrypt encrypted volumes.

open_tcrypt.c  (zuluCrypt-5.7.0.tar.xz):open_tcrypt.c  (zuluCrypt-5.7.1.tar.xz)
skipping to change at line 33 skipping to change at line 33
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include <string.h>
#include "zuluplay_support.h" #include "zuluplay_support.h"
#include "check_tcrypt.h" #include "check_tcrypt.h"
#include "veracrypt_pim.h"
static void _chown( const char * x,uid_t y,gid_t z ) static void _chown( const char * x,uid_t y,gid_t z )
{ {
if( chown( x,y,z ) ){;} if( chown( x,y,z ) ){}
} }
static void _chmod( const char * x,mode_t y ) static void _chmod( const char * x,mode_t y )
{ {
if( chmod( x,y ) ){;} if( chmod( x,y ) ){}
} }
static void _write( int x,const void * y,size_t z ) static void _write( int x,const void * y,size_t z )
{ {
if( write( x,y,z ) ){;} if( write( x,y,z ) ){}
} }
static void _close( int x ) static void _close( int x )
{ {
if( close( x ) ){;} if( close( x ) ){}
}
int zuluCryptUseZuluPlayTCRYPT()
{
#ifdef CRYPT_TCRYPT
return 0 ;
#else
return 1 ;
#endif
}
int zuluCryptUseZuluPlayVCRYPT()
{
#ifdef CRYPT_TCRYPT_VERA_MODES
return 0 ;
#else
return 1 ;
#endif
}
const char * zuluCryptCryptsetupTCRYPTType()
{
#ifdef CRYPT_TCRYPT
return CRYPT_TCRYPT ;
#else
return "" ;
#endif
}
void * zuluCryptCryptsetupTCryptVCrypt( const open_struct_t * opt )
{
#ifdef CRYPT_TCRYPT
struct crypt_params_tcrypt * m = malloc( sizeof( struct crypt_params_tcry
pt ) ) ;
memset( m,'\0',sizeof( struct crypt_params_tcrypt ) ) ;
m->passphrase = opt->key ;
m->passphrase_size = opt->key_len ;
m->keyfiles = ( const char ** ) opt->tcrypt_keyfiles ;
m->keyfiles_count = ( unsigned int ) opt->tcrypt_keyfiles_count ;
m->flags = CRYPT_TCRYPT_LEGACY_MODES ;
if( opt->system_volume ){
m->flags |= CRYPT_TCRYPT_SYSTEM_HEADER ;
}
if( opt->use_backup_header ){
m->flags |= CRYPT_TCRYPT_BACKUP_HEADER ;
}
if( opt->use_hidden_header ){
m->flags |= CRYPT_TCRYPT_HIDDEN_HEADER ;
}
#if SUPPORT_VERACRYPT_PIM
m->veracrypt_pim = ( unsigned int ) opt->iteration_count ;
#endif
#ifdef CRYPT_TCRYPT_VERA_MODES
if( opt->veraCrypt_volume ){
m->flags |= CRYPT_TCRYPT_VERA_MODES ;
}
#endif
return m ;
#else
return NULL ;
#endif
} }
string_t zuluCryptCreateKeyFile( const char * key,size_t key_len,const char * fi leName ) string_t zuluCryptCreateKeyFile( const char * key,size_t key_len,const char * fi leName )
{ {
string_t st = StringVoid ; string_t st = StringVoid ;
int fd ; int fd ;
const char * file ; const char * file ;
struct stat statstr ; struct stat statstr ;
skipping to change at line 97 skipping to change at line 172
} }
return st ; return st ;
} }
string_t zuluCryptCreateKeyFile_1( string_t st,const char * fileName ) string_t zuluCryptCreateKeyFile_1( string_t st,const char * fileName )
{ {
return zuluCryptCreateKeyFile( StringContent( st ),StringLength( st ),fil eName ) ; return zuluCryptCreateKeyFile( StringContent( st ),StringLength( st ),fil eName ) ;
} }
static int _open_tcrypt_volume( const char * device,const open_struct_t * opts ) static int zuluExit( int st,struct crypt_device * cd, void * m )
{
free( m ) ;
crypt_free( cd ) ;
return st ;
}
static int _open_tcrypt_volume_zuluplay( const char * device,const open_struct_t
* opts )
{ {
tc_api_task task ; tc_api_task task ;
int r = !TC_OK ; int r = !TC_OK ;
size_t i ; size_t i ;
size_t k ; size_t k ;
const char * const * z ; const char * const * z ;
const char * e ; const char * e ;
string_t st = StringVoid ; string_t st = StringVoid ;
if( opts->use_hidden_header ){
/*
* We return with an error here because zuluplay automatically ch
eck
* for this option.
*/
return r ;
}
if( tc_api_initialize() ){ if( tc_api_initialize() ){
if( tc_api_task_initialize( &task,"map" ) ){ if( tc_api_task_initialize( &task,"map" ) ){
tc_api_task_set( task,"use_backup_header",opts->use_backu p_header ) ; tc_api_task_set( task,"use_backup_header",opts->use_backu p_header ) ;
tc_api_task_set( task,"veracrypt_mode",opts->veraCrypt_vo lume ) ; tc_api_task_set( task,"veracrypt_mode",opts->veraCrypt_vo lume ) ;
tc_api_task_set( task,"map_name",opts->mapper_name ) ; tc_api_task_set( task,"map_name",opts->mapper_name ) ;
tc_api_task_set( task,"read_only",StringHasComponent( opt s->m_opts,"ro" ) ) ; tc_api_task_set( task,"read_only",StringHasComponent( opt s->m_opts,"ro" ) ) ;
tc_api_task_set( task,"dev",device ) ; tc_api_task_set( task,"dev",device ) ;
skipping to change at line 169 skipping to change at line 260
StringDelete( &st ) ; StringDelete( &st ) ;
} }
tc_api_uninit() ; tc_api_uninit() ;
} }
return r ; return r ;
} }
static int _open_tcrypt_volume_cryptsetup( const char * device,const open_struct
_t * opt )
{
struct crypt_device * cd ;
uint32_t flags ;
int st ;
void * m ;
if( crypt_init( &cd,device ) != 0 ){
return 2 ;
}
m = zuluCryptCryptsetupTCryptVCrypt( opt ) ;
if( crypt_load( cd,zuluCryptCryptsetupTCRYPTType(),m ) != 0 ){
return zuluExit( 2,cd,m ) ;
}
if( StringHasComponent( opt->m_opts,"ro" ) ){
flags = CRYPT_ACTIVATE_READONLY ;
}else{
flags = CRYPT_ACTIVATE_ALLOW_DISCARDS ;
}
st = crypt_activate_by_volume_key( cd,opt->mapper_name,NULL,0,flags ) ;
if( st == 0 ){
return zuluExit( 0,cd,m ) ;
}else{
return zuluExit( 1,cd,m ) ;
}
}
static int _open_tcrypt_volume( const char * device,const open_struct_t * opt )
{
if( opt->veraCrypt_volume ){
if( zuluCryptUseZuluPlayVCRYPT() ){
return _open_tcrypt_volume_zuluplay( device,opt ) ;
}else{
return _open_tcrypt_volume_cryptsetup( device,opt ) ;
}
}else{
if( zuluCryptUseZuluPlayTCRYPT() ){
return _open_tcrypt_volume_zuluplay( device,opt ) ;
}else{
return _open_tcrypt_volume_cryptsetup( device,opt ) ;
}
}
}
static int _open_tcrypt_volume_1( const char * device,const resolve_path_t * opt ) static int _open_tcrypt_volume_1( const char * device,const resolve_path_t * opt )
{ {
int r = _open_tcrypt_volume( device,opt->args ) ; int r ;
open_struct_t opts ; open_struct_t opts ;
if( r == 0 ){ memcpy( &opts,opt->args,sizeof( opts ) ) ;
return r ; if( opts.trueCrypt_volume ){
}else{
memcpy( &opts,opt->args,sizeof( opts ) ) ; r = _open_tcrypt_volume( device,&opts ) ;
if( r == 0 ){
return 0 ;
}
opts.use_backup_header = 1 ;
r = _open_tcrypt_volume( device,&opts ) ;
if( r == 0 ){
if( opts.trueCrypt_volume ){ return 0 ;
}
opts.use_backup_header = 0 ;
opts.use_hidden_header = 1 ;
opts.use_backup_header = 1 ; r = _open_tcrypt_volume( device,&opts ) ;
if( r == 0 ){
return 0 ;
}
opts.use_backup_header = 0 ;
opts.use_hidden_header = 0 ;
opts.system_volume = 1 ;
return _open_tcrypt_volume( device,&opts ) ;
}else{
if( opts.system_volume || opts.use_hidden_header ){
return _open_tcrypt_volume( device,&opts ) ; return _open_tcrypt_volume( device,&opts ) ;
}else{ }else{
return r ; if( _open_tcrypt_volume( device,&opts ) == 0 ){
return 0 ;
}else{
opts.use_hidden_header = 1 ;
return _open_tcrypt_volume( device,&opts ) ;
}
} }
} }
} }
static int _open_tcrypt_0( const open_struct_t * opt ) static int _open_tcrypt_0( const open_struct_t * opt )
{ {
/* /*
* zuluCryptResolveDevicePath_0() is defined in resolve_path.c * zuluCryptResolveDevicePath_0() is defined in resolve_path.c
*/ */
return zuluCryptResolveDevicePath_0( _open_tcrypt_volume_1,opt,1 ) ; return zuluCryptResolveDevicePath_0( _open_tcrypt_volume_1,opt,1 ) ;
skipping to change at line 266 skipping to change at line 448
} }
int zuluCryptOpenTcrypt_1( const open_struct_t * opts ) int zuluCryptOpenTcrypt_1( const open_struct_t * opts )
{ {
/* /*
* zuluCryptOpenVolume_0() is defined in open_volume.c * zuluCryptOpenVolume_0() is defined in open_volume.c
*/ */
return zuluCryptOpenVolume_0( _open_tcrypt_0,opts ) ; return zuluCryptOpenVolume_0( _open_tcrypt_0,opts ) ;
} }
#if CHECK_TCRYPT
static int zuluExit( int st,struct crypt_device * cd )
{
crypt_free( cd ) ;
return st ;
}
/* /*
* 1 is returned if a volume is a truecrypt volume. * 1 is returned if a volume is a truecrypt volume.
* 0 is returned if a volume is not a truecrypt volume or functionality is not s upported * 0 is returned if a volume is not a truecrypt volume or functionality is not s upported
*/ */
int zuluCryptVolumeIsTcrypt( const char * device,const char * key,int key_source ) int zuluCryptVolumeIsTcrypt( const char * device,const char * key,int key_source )
{ {
void * m ;
open_struct_t s ;
struct crypt_device * cd = NULL; struct crypt_device * cd = NULL;
struct crypt_params_tcrypt params ;
memset( &params,'\0',sizeof( struct crypt_params_tcrypt ) ) ; memset( &s,'\0',sizeof( open_struct_t ) ) ;
if( key_source ){;} if( key_source ){}
if( crypt_init( &cd,device ) < 0 ){ if( crypt_init( &cd,device ) < 0 ){
return 0 ; return 0 ;
}else{ }else{
params.passphrase = key ; s.key = key ;
params.passphrase_size = StringSize( key ) ; s.key_len = StringSize( key ) ;
params.flags = CRYPT_TCRYPT_LEGACY_MODES ;
if( crypt_load( cd,CRYPT_TCRYPT,&params ) == 0 ){ m = zuluCryptCryptsetupTCryptVCrypt( &s ) ;
return zuluExit( 1,cd ) ;
}else{
return zuluExit( 0,cd ) ;
}
}
}
#else if( m == NULL ){
int zuluCryptVolumeIsTcrypt( const char * device,const char * key,int key_source return 0 ;
) }
{
if( 0 && device && key && key_source ){;}
return 1 ; if( crypt_load( cd,zuluCryptCryptsetupTCRYPTType(),m ) == 0 ){
}
#endif return zuluExit( 1,cd,m ) ;
}else{
return zuluExit( 0,cd,m ) ;
}
}
}
 End of changes. 26 change blocks. 
40 lines changed or deleted 213 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)