"Fossies" - the Fresh Open Source Software Archive

Member "zuluCrypt-5.7.1/zuluCrypt-cli/bin/open_volume.c" (15 Jan 2020, 19543 Bytes) of package /linux/misc/zuluCrypt-5.7.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "open_volume.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.7.0_vs_5.7.1.

    1 /*
    2  *
    3  *  Copyright (c) 2011-2015
    4  *  name : Francis Banyikwa
    5  *  email: mhogomchungu@gmail.com
    6  *  This program is free software: you can redistribute it and/or modify
    7  *  it under the terms of the GNU General Public License as published by
    8  *  the Free Software Foundation, either version 2 of the License, or
    9  *  (at your option) any later version.
   10  *
   11  *  This program is distributed in the hope that it will be useful,
   12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  *  GNU General Public License for more details.
   15  *
   16  *  You should have received a copy of the GNU General Public License
   17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
   18  */
   19 
   20 #include "includes.h"
   21 #include "../lib/includes.h"
   22 #include <sys/types.h>
   23 #include <string.h>
   24 #include <locale.h>
   25 #include <stdio.h>
   26 #include <libintl.h>
   27 #include <sys/stat.h>
   28 #include <unistd.h>
   29 
   30 stringList_t zuluCryptCreateKeyFiles( const char * const * list,int s )
   31 {
   32     #define buffer_size 32
   33     char buffer[ buffer_size ] ;
   34     const char * e ;
   35 
   36     int i ;
   37 
   38     stringList_t stz = StringListVoid ;
   39 
   40     string_t xt ;
   41     string_t zt ;
   42 
   43     for( i = 0 ; list[ i ] != NULL ; i++ ){
   44 
   45         e = *( list + i ) ;
   46 
   47         zuluCryptSecurityDropElevatedPrivileges() ;
   48         /*
   49          * TrueCrypt only uses the first 1MB of keyfile.
   50          */
   51         if( StringGetFromFile_3( &xt,e,0,1048576 ) == 0 ){
   52 
   53             zuluCryptSecurityGainElevatedPrivileges() ;
   54 
   55             e = StringIntToString_1( buffer,buffer_size,i + s ) ;
   56             /*
   57              * zuluCryptCreateKeyFile_1() is defined in ../lib/open_tcrypt.c
   58              */
   59             zt = zuluCryptCreateKeyFile_1( xt,e ) ;
   60 
   61             StringDelete( &xt ) ;
   62 
   63             StringListAppendString_1( &stz,&zt ) ;
   64         }
   65     }
   66 
   67     zuluCryptSecurityDropElevatedPrivileges() ;
   68     return stz ;
   69 }
   70 
   71 void zuluCryptDeleteKeyFiles( stringList_t stl )
   72 {
   73     StringListIterator it  ;
   74     StringListIterator end ;
   75 
   76     StringListGetIterators( stl,&it,&end ) ;
   77 
   78     zuluCryptSecurityGainElevatedPrivileges() ;
   79 
   80     while( it != end ){
   81         /*
   82          * zuluCryptDeleteFile_1() is defined in ../lib/file_path_security.c
   83          */
   84         zuluCryptDeleteFile_1( *it ) ;
   85         it++ ;
   86     }
   87 
   88     zuluCryptSecurityDropElevatedPrivileges() ;
   89 }
   90 
   91 static char * _device_path( const char * device )
   92 {
   93     char * path ;
   94 
   95     if( StringPrefixEqual( device,"/dev/loop" ) ){
   96 
   97         zuluCryptSecurityGainElevatedPrivileges() ;
   98         /*
   99          * zuluCryptLoopDeviceAddress_1() is defined in ../zuluCrypt-cli/create_loop_device.c
  100          */
  101         path = zuluCryptLoopDeviceAddress_1( device ) ;
  102 
  103         zuluCryptSecurityDropElevatedPrivileges() ;
  104 
  105         if( path == NULL ){
  106 
  107             return StringCopy_2( device ) ;
  108         }else{
  109             return path ;
  110         }
  111     }else{
  112         return StringCopy_2( device ) ;
  113     }
  114 }
  115 
  116 static void _printResult( const char * device,const char * m_point )
  117 {
  118     char * e ;
  119 
  120     zuluCryptSecurityGainElevatedPrivileges() ;
  121 
  122     /*
  123      * zuluCryptGetVolumeTypeFromMapperPath() is defined in ../lib/status.c
  124      */
  125     e = zuluCryptGetVolumeTypeFromMapperPath( device ) ;
  126 
  127     zuluCryptSecurityDropElevatedPrivileges() ;
  128 
  129     if( StringHasComponent( e,"LUKS" ) ){
  130 
  131         printf( gettext( "SUCCESS: %s volume opened successfully\n" ),"luks" ) ;
  132 
  133     }else if( StringHasComponent( e,"PLAIN" ) ){
  134 
  135         printf( gettext( "SUCCESS: %s volume opened successfully\n" ),"plain" ) ;
  136 
  137     }else if( StringHasComponent( e,"TCRYPT" ) ){
  138 
  139         printf( gettext( "SUCCESS: %s volume opened successfully\n" ),"tcrypt" ) ;
  140 
  141     }else if( StringHasComponent( e,"VCRYPT" ) ){
  142 
  143         printf( gettext( "SUCCESS: %s volume opened successfully\n" ),"vcrypt" ) ;
  144 
  145     }else if( StringHasComponent( e,"BITLK" ) ){
  146 
  147         printf( gettext( "SUCCESS: %s volume opened successfully\n" ),"bitlocker" ) ;
  148     }else{
  149         printf( gettext( "SUCCESS: volume opened successfully\n" ) ) ;
  150     }
  151 
  152     StringFree( e ) ;
  153 
  154     if( m_point != NULL ){
  155 
  156         printf( gettext( "volume mounted at: %s\n" ),m_point ) ;
  157     }
  158 }
  159 
  160 static int zuluExit( int st,const char * device,const char * m_point,stringList_t stl )
  161 {
  162     switch( st ){
  163 
  164         case 0 : _printResult( device,m_point ) ;                                           break ;
  165         case 1 : printf( gettext( "ERROR: Failed to mount ntfs/exfat file system using ntfs-3g,is ntfs-3g/exfat package installed?\n" ) )   ;break ;
  166         case 2 : printf( gettext( "ERROR: There seem to be an open volume accociated with given address\n" ) ) ;            break ;
  167         case 3 : printf( gettext( "ERROR: No file or device exist on given path\n" ) ) ;                        break ;
  168         case 4 : printf( gettext( "ERROR: Volume could not be opened with the presented key\n" ) ) ;                    break ;
  169         case 5 : printf( gettext( "ERROR: Insufficient privilege to mount the device with given options\n" ) ) ;            break ;
  170         case 6 : printf( gettext( "ERROR: Insufficient privilege to open device in read write mode or device does not exist\n" ) ) ;    break ;
  171         case 7 : printf( gettext( "ERROR: Only root user can perform this operation\n" ) ) ;                        break ;
  172         case 8 : printf( gettext( "ERROR: -O and -m options can not be used together\n" ) ) ;                       break ;
  173         case 9 : printf( gettext( "ERROR: Could not create mount point, invalid path or path already taken\n" ) ) ;         break ;
  174         case 10: printf( gettext( "ERROR: Shared mount point path aleady taken\n" ) ) ;                         break ;
  175         case 11: printf( gettext( "ERROR: There seem to be an opened mapper associated with the device\n" ) ) ;             break ;
  176         case 12: printf( gettext( "ERROR: Could not get a passphrase from the module\n" ) ) ;                       break ;
  177         case 13: printf( gettext( "ERROR: Could not get passphrase in silent mode\n" ) );                       break ;
  178         case 14: printf( gettext( "ERROR: Insufficient memory to hold passphrase\n" ) ) ;                       break ;
  179         case 15: printf( gettext( "ERROR: One or more required argument(s) for this operation is missing\n" ) ) ;           break ;
  180         case 16: printf( gettext( "ERROR: Invalid path to key file\n" ) ) ;                             break ;
  181         case 17: printf( gettext( "ERROR: Could not get enought memory to hold the key file\n" ) ) ;                    break ;
  182         case 18: printf( gettext( "ERROR: Insufficient privilege to open key file for reading\n" ) );                   break ;
  183         case 19: printf( gettext( "ERROR: Could not get a passphrase through a local socket\n" ) );                 break ;
  184         case 20: printf( gettext( "ERROR: Failed to mount a filesystem:invalid/unsupported mount option or unsupported file system encountered\n" ) );break ;
  185         case 21: printf( gettext( "ERROR: Could not create a lock on /etc/mtab\n" ) ) ;                         break ;
  186         case 22: printf( gettext( "ERROR: Insufficient privilege to open a system volume\n" ) ) ;                   break ;
  187         default: printf( gettext( "ERROR: Unrecognized error with status number %d encountered\n" ),st ) ;
  188     }
  189 
  190     zuluCryptSecurityUnlockMemory( stl ) ;
  191     StringListClearDelete( &stl ) ;
  192 
  193     return st ;
  194 }
  195 
  196 /*
  197  * open_volume function below can be devided into two, the first part is before the mount point folder is created and the
  198  * other part is after. This function is called after the mount point is created to see if it the mount point folder
  199  * should be removed first before calling the above function.The above function is called directly when "open_volume"
  200  * function is to be exited before the mount point is created. *
  201  */
  202 static int zuluExit_1( int st,const struct_opts * opts,const char * device,const char * m_point,stringList_t stl )
  203 {
  204     if( opts->open_mount && st != 0 ){
  205 
  206         zuluCryptSecurityGainElevatedPrivileges() ;
  207 
  208         rmdir( m_point ) ;
  209 
  210         zuluCryptSecurityDropElevatedPrivileges() ;
  211     }
  212     return zuluExit( st,device,m_point,stl ) ;
  213 }
  214 
  215 static int _open_volume( const open_struct_t * volume )
  216 {
  217     int r ;
  218     zuluCryptSecurityGainElevatedPrivileges() ;
  219     /*
  220      * zuluCryptOpenVolume_2() is defined in ../lib/open_volume.c
  221      */
  222     r = zuluCryptOpenVolume_2( volume ) ;
  223 
  224     zuluCryptSecurityDropElevatedPrivileges() ;
  225 
  226     return r ;
  227 }
  228 
  229 void zuluCryptTrueCryptVeraCryptVolumeInfo( const char * type,tvcrypt * e )
  230 {
  231     stringList_t stl = StringListSplit( type,'.' ) ;
  232 
  233     size_t p = StringListSize( stl ) ;
  234 
  235     const char * q ;
  236 
  237     memset( e,'\0',sizeof( tvcrypt ) ) ;
  238 
  239     if( p > 0 ){
  240 
  241         e->type = StringListCopyStringAtFirstPlace( stl ) ;
  242 
  243         if( p > 1 ){
  244 
  245             q = StringListContentAtSecondPlace( stl ) ;
  246 
  247             e->iteration_count = ( int )StringConvertToInt( q ) ;
  248         }
  249     }
  250 
  251     StringListDelete( &stl ) ;
  252 }
  253 
  254 int zuluCryptEXEOpenVolume( const struct_opts * opts,const char * mapping_name,uid_t uid )
  255 {
  256     int share                = opts->share ;
  257     int open_mount           = opts->open_mount ;
  258     const char * device      = opts->device ;
  259     const char * mount_point = opts->mount_point ;
  260     const char * m_opts      = opts->m_opts ;
  261     const char * source      = opts->key_source ;
  262     const char * pass        = opts->key ;
  263     const char * plugin_path = opts->plugin_path ;
  264     const char * fs_opts     = opts->fs_opts ;
  265     const char * const * tcrypt_keyfiles = opts->tcrypt_multiple_keyfiles ;
  266     /*
  267      * Below is a form of memory management.All strings are collected in a stringlist object to easily delete them
  268      * when the function returns.This allows for the function to have multiple exit points without risks of leaking
  269      * memory from manually examining each exit point to make sure all strings are deleted or go with multiple goto
  270      * code deleting blocks to take into account different exit points.
  271      */
  272     stringList_t stl ;
  273     string_t * stringArray = StringListArray( &stl,8 ) ;
  274     string_t * passphrase  =  &stringArray[ 0 ] ;
  275     string_t * m_name      =  &stringArray[ 1 ] ;
  276     string_t * data        =  &stringArray[ 2 ] ;
  277     string_t * m_point     =  &stringArray[ 3 ] ;
  278     string_t * mapper      =  &stringArray[ 4 ] ;
  279     string_t * mapper_path =  &stringArray[ 5 ] ;
  280     string_t * offset      =  &stringArray[ 6 ] ;
  281     string_t * bitlk       =  &stringArray[ 7 ] ;
  282 
  283     const char * key = NULL ;
  284     const char * mapper_name ;
  285     const char * path_mapper ;
  286 
  287     size_t key_len = 0 ;
  288     int st = 0 ;
  289 
  290     int bitlockerVolume ;
  291 
  292     stringList_t stz ;
  293     tvcrypt v_info ;
  294 
  295     unsigned long m_flags ;
  296 
  297     int tcrypt_keyfile  = 0 ;
  298 
  299     const char * uuid ;
  300     char * device_path ;
  301 
  302     /*
  303      * open_struct_t is declared in ../lib/include.h
  304      */
  305     open_struct_t volume ;
  306 
  307     struct stat statstr ;
  308 #if 0
  309     /*
  310      * zuluCryptVolumeIsInSystemVolumeList() is defined in volumes.c
  311      */
  312     if( zuluCryptVolumeIsInSystemVolumeList( device ) ){
  313         /*
  314          * check permissions only if volume is explicity mentioned as system.
  315          * This is an exception to avoid some udev bad behaviors on udev enabled build
  316          */
  317         if( !zuluCryptUserIsAMemberOfAGroup( uid,"zulucrypt" ) ){
  318             return zuluExit( 22,device,mount_point,stl ) ;
  319         }
  320     }
  321 #endif
  322     if( m_opts == NULL ){
  323 
  324         m_opts = "rw" ;
  325     }
  326     /*
  327      * zuluCryptMountFlagsAreNotCorrect() is defined in ./mount_flags.c
  328      */
  329     if( zuluCryptMountFlagsAreNotCorrect( m_opts,uid,&m_flags ) ){
  330 
  331         return zuluExit( 5,device,mount_point,stl ) ;
  332     }
  333     if( StringHasComponent( m_opts,"rw" ) ){
  334         /*
  335          * zuluCryptSecurityDeviceIsWritable() is defined in path_access.c
  336          */
  337         st = zuluCryptCanOpenPathForWriting( device,uid ) ;
  338     }else{
  339         /*
  340          * zuluCryptSecurityDeviceIsReadable() is defined in path_access.c
  341          */
  342         st = zuluCryptCanOpenPathForReading( device,uid ) ;
  343     }
  344 
  345     /*
  346      * 1-permissions denied
  347      * 2-invalid path
  348      * 3-shenanigans
  349      * 4-common error
  350      */
  351     switch( st ){
  352 
  353         case 0 :  break ;
  354         case 1 :  return zuluExit( 6,device,mount_point,stl ) ;
  355         case 2 :  return zuluExit( 6,device,mount_point,stl ) ;
  356         case 3 :  return zuluExit( 6,device,mount_point,stl ) ;
  357         case 4 :  return zuluExit( 6,device,mount_point,stl ) ;
  358         default:  return zuluExit( 6,device,mount_point,stl ) ;
  359     }
  360 
  361     if( open_mount ){
  362         /*
  363         * zuluCryptCreateMountPoint() is defined in create_mount_point.c
  364         */
  365         *m_point = zuluCryptCreateMountPoint( device,mount_point,m_opts,uid ) ;
  366 
  367         mount_point = StringContent( *m_point ) ;
  368 
  369         if( mount_point == NULL ){
  370 
  371             return zuluExit( 9,device,mount_point,stl ) ;
  372         }
  373     }else{
  374         if( uid != 0 ){
  375 
  376             return zuluExit( 7,device,mount_point,stl ) ;
  377         }
  378         if( mount_point != NULL ){
  379 
  380             return zuluExit( 8,device,mount_point,stl ) ;
  381         }
  382     }
  383 
  384     if( share ){
  385         /*
  386          * zuluCryptBindSharedMountPointPathTaken() is defined in bind.c
  387          */
  388         if( zuluCryptBindSharedMountPointPathTaken( *m_point ) ){
  389 
  390             return zuluExit_1( 10,opts,device,mount_point,stl ) ;
  391         }
  392     }
  393 
  394     zuluCryptSecurityGainElevatedPrivileges() ;
  395 
  396     bitlockerVolume = zuluCryptDeviceHasAgivenFileSystem( device,zuluCryptBitLockerType() ) ;
  397 
  398     zuluCryptSecurityDropElevatedPrivileges() ;
  399 
  400     if( bitlockerVolume && zuluCryptUseDislockerBitLocker( opts->use_cryptsetup_for_bitlocker ) ){
  401 
  402         *mapper_path = zuluCryptBitLockerMapperPath( uid ) ;
  403 
  404         zuluCryptSecurityGainElevatedPrivileges() ;
  405 
  406         *m_name = zuluCryptBitLockerMapperName( device ) ;
  407 
  408         mapper_name = StringContent( *m_name ) ;
  409         path_mapper = StringContent( *mapper_path ) ;
  410 
  411         zuluCryptCreateMountPointPrefix( uid ) ;
  412 
  413         zuluCryptSecurityDropElevatedPrivileges() ;
  414     }else{
  415         /*
  416          * zuluCryptCreateMapperName() is defined in ../lib/create_mapper_name.c
  417          */
  418         *m_name = zuluCryptCreateMapperName( device,mapping_name,uid,ZULUCRYPTshortMapperPath ) ;
  419 
  420         *mapper = StringCopy( *m_name ) ;
  421         mapper_name = StringContent( *m_name ) ;
  422 
  423         *mapper_path = String( zuluCryptMapperPrefix() ) ;
  424 
  425         path_mapper = StringMultipleAppend( *mapper_path,"/",mapper_name,NULL ) ;
  426 
  427         if( stat( path_mapper,&statstr ) == 0 ){
  428 
  429             return zuluExit_1( 11,opts,device,mount_point,stl ) ;
  430         }
  431     }
  432 
  433     if( plugin_path != NULL ){
  434 
  435         /*
  436          * zuluCryptPrepareSocketPath() is defined in path_access.c
  437          */
  438         zuluCryptPrepareSocketPath( uid ) ;
  439 
  440         /*
  441          * zuluCryptUUIDFromPath() is defined in path_access.c
  442          */
  443         uuid = zuluCryptUUIDFromPath( device ) ;
  444 
  445         device_path = _device_path( device ) ;
  446         /*
  447          * zuluCryptPluginManagerGetKeyFromModule is defined in ../pluginManager/zuluCryptPluginManager.c
  448          */
  449         *passphrase = zuluCryptPluginManagerGetKeyFromModule( device_path,
  450                                       plugin_path,
  451                                       uuid,
  452                                       uid,
  453                                       opts,
  454                                       zuluCryptRunTimePath(),
  455                                       &st ) ;
  456 
  457         StringFree( device_path ) ;
  458         StringFree( uuid ) ;
  459 
  460         if( st != 0 || *passphrase == StringVoid ){
  461 
  462             return zuluExit_1( 12,opts,device,mount_point,stl ) ;
  463         }
  464 
  465         key_len = StringLength( *passphrase ) ;
  466         key = StringContent( *passphrase ) ;
  467 
  468         zuluCryptSecurityLockMemory_1( *passphrase ) ;
  469 
  470     }else if( source == NULL && tcrypt_keyfiles[ 0 ] == NULL ){
  471 
  472         printf( gettext( "Enter passphrase: " ) ) ;
  473         /*
  474          * ZULUCRYPT_KEY_MAX_SIZE is set in ../constants.h
  475          */
  476         switch( StringSilentlyGetFromTerminal_1( passphrase,ZULUCRYPT_KEY_MAX_SIZE ) ){
  477 
  478             case 1 : return zuluExit_1( 13,opts,device,mount_point,stl ) ;
  479             case 2 : return zuluExit_1( 14,opts,device,mount_point,stl ) ;
  480         }
  481 
  482         printf( "\n" ) ;
  483         key = StringContent( *passphrase ) ;
  484         key_len = StringLength( *passphrase ) ;
  485 
  486         zuluCryptSecurityLockMemory_1( *passphrase ) ;
  487     }else{
  488         if( source == NULL || pass == NULL ){
  489 
  490             if( tcrypt_keyfiles == NULL ){
  491 
  492                 return zuluExit_1( 15,opts,device,mount_point,stl ) ;
  493             }
  494         }
  495         if( StringsAreEqual( source,"-p" ) ){
  496 
  497             key = pass ;
  498             key_len = StringSize( pass ) ;
  499 
  500         }else if( StringsAreEqual( source,"-f" ) ){
  501 
  502             if( StringHasNoComponent( pass,zuluCryptRunTimePath() ) ){
  503 
  504                 tcrypt_keyfile = 1 ;
  505             }
  506             /*
  507              * function is defined at "path_access.c"
  508              */
  509             switch( zuluCryptGetPassFromFile( NULL,pass,uid,data ) ){
  510 
  511                 case 1 : return zuluExit_1( 16,opts,device,mount_point,stl ) ;
  512                 case 2 : return zuluExit_1( 17,opts,device,mount_point,stl ) ;
  513                 case 4 : return zuluExit_1( 18,opts,device,mount_point,stl ) ;
  514                 case 5 : return zuluExit_1( 19,opts,device,mount_point,stl ) ;
  515             }
  516 
  517             if( *data == StringVoid ){
  518 
  519                 return zuluExit_1( 12,opts,device,mount_point,stl ) ;
  520             }
  521 
  522             key = StringContent( *data ) ;
  523             key_len = StringLength( *data ) ;
  524 
  525             zuluCryptSecurityLockMemory_1( *data ) ;
  526         }
  527     }
  528 
  529     memset( &volume,'\0',sizeof( open_struct_t ) ) ;
  530 
  531     if( key != NULL ){
  532 
  533         volume.key     = key ;
  534         volume.key_len = key_len ;
  535     }else{
  536         volume.key     = "" ;
  537         volume.key_len = 0 ;
  538     }
  539 
  540     volume.device      = device ;
  541     volume.mapper_name = mapper_name ;
  542     volume.mapper_path = path_mapper ;
  543     volume.m_point     = mount_point ;
  544     volume.fs_opts     = fs_opts ;
  545     volume.uid         = uid ;
  546     volume.m_opts      = m_opts ;
  547     volume.m_flags     = m_flags ;
  548     volume.bitlocker_volume = bitlockerVolume ;
  549     volume.luks_detached_header = opts->luks_external_header ;
  550     volume.use_cryptsetup_for_bitlocker = opts->use_cryptsetup_for_bitlocker ;
  551 
  552     /*
  553      * zuluCryptTrueCryptVeraCryptVolumeInfo() is defined in this source file.
  554      */
  555     zuluCryptTrueCryptVeraCryptVolumeInfo( opts->type,&v_info ) ;
  556 
  557     volume.iteration_count = v_info.iteration_count ;
  558 
  559     if( StringAtLeastOneMatch( v_info.type,"tcrypt","truecrypt",NULL ) ){
  560 
  561         volume.trueCrypt_volume = 1 ;
  562 
  563     }else if( StringAtLeastOneMatch( v_info.type,"vcrypt","veracrypt","vera",NULL ) ){
  564 
  565         volume.veraCrypt_volume = 1 ;
  566 
  567     }else if( StringAtLeastOneMatch( v_info.type,"vcrypt-sys","veracrypt-sys","vera-sys",NULL ) ){
  568 
  569         volume.veraCrypt_volume = 1 ;
  570         volume.system_volume = 1 ;
  571 
  572     }else if( StringAtLeastOneMatch( v_info.type,"vcrypt-hbk","veracrypt-hbk","vera-hbk",NULL ) ){
  573 
  574         volume.veraCrypt_volume = 1 ;
  575         volume.use_backup_header = 1 ;
  576 
  577     }else if( StringAtLeastOneMatch( v_info.type,"vcrypt-sys-hbk","veracrypt-sys-hbk","vera-sys-hbk",NULL ) ){
  578 
  579         volume.veraCrypt_volume = 1 ;
  580         volume.system_volume = 1 ;
  581         volume.use_backup_header = 1 ;
  582     }
  583 
  584     if( !volume.veraCrypt_volume && !volume.trueCrypt_volume ){
  585 
  586         if( opts->offset != NULL ){
  587 
  588             *offset = String( "/dev/urandom.aes.cbc-essiv:sha256.256.ripemd160." ) ;
  589             volume.plain_dm_properties = StringAppend( *offset,opts->offset ) ;
  590         }else{
  591             if( StringsAreEqual( opts->type,"plain" ) ){
  592 
  593                 volume.plain_dm_properties = "aes.cbc-essiv:sha256.256.sha256.0" ;
  594 
  595             }else if( StringsAreNotEqual( opts->type,"luks" ) ){
  596 
  597                 volume.plain_dm_properties = opts->type ;
  598             }
  599         }
  600     }
  601 
  602     StringDelete( &v_info.type ) ;
  603 
  604     if( plugin_path != NULL ){
  605 
  606         plugin_path = plugin_path + StringLastIndexOfChar_1( plugin_path,'/' ) + 1 ;
  607     }
  608 
  609     if( tcrypt_keyfile ){
  610 
  611         volume.key_source = TCRYPT_KEYFILE ;
  612     }
  613 
  614     if( tcrypt_keyfiles[ 0 ] != NULL ){
  615 
  616         /*
  617          * Here, we take a list of keyfiles supplied by the user and then copy them to a safe
  618          * location at "/run/zuluCrypt" and then we pass these safe copies to cryptsetup.
  619          *
  620          * The idea is not to let cryptsetup, a privileged process handle user managed files.
  621          */
  622 
  623         stz = zuluCryptCreateKeyFiles( tcrypt_keyfiles,0 ) ;
  624 
  625         volume.tcrypt_keyfiles_count = StringListSize( stz ) ;
  626         volume.tcrypt_keyfiles       = StringListStringArray_0( stz ) ;
  627 
  628         st = _open_volume( &volume ) ;
  629 
  630         zuluCryptDeleteKeyFiles( stz ) ;
  631 
  632         StringFree( volume.tcrypt_keyfiles ) ;
  633         StringListDelete( &stz ) ;
  634     }else{
  635         st = _open_volume( &volume ) ;
  636     }
  637     /*
  638      * below two return values comes from ../lib/mount_volume.c
  639      */
  640     if( st == -1 ){
  641         st = 20 ;
  642     }
  643     if( st == 12 ){
  644         st = 21 ;
  645     }
  646     if( st == 8 || st == 3 ){
  647         st = 3 ;
  648     }
  649 
  650     if( volume.bitlocker_volume ){
  651 
  652         if( zuluCryptUseCryptsetupBitLocker( opts->use_cryptsetup_for_bitlocker ) ){
  653 
  654             device = StringMultiplePrepend( *mapper,"/",zuluCryptMapperPrefix(),NULL ) ;
  655         }else{
  656             *bitlk = zuluCryptBitLockerFullMapperPath( uid,device ) ;
  657 
  658             device = StringContent( *bitlk ) ;
  659         }
  660     }else{
  661         device = StringMultiplePrepend( *mapper,"/",zuluCryptMapperPrefix(),NULL ) ;
  662     }
  663 
  664     if( st == 0 && share ){
  665 
  666         /*
  667          * user wish to share the mount point bind the mount point to a publicly accessed path at /run/media/public/
  668          */
  669         /*
  670          * zuluCryptBindMountVolume() is defined in ../zuluCrypt-cli/bin/bind.c
  671          */
  672         zuluCryptBindMountVolume( device,*m_point,m_flags ) ;
  673     }
  674 
  675     /*
  676      * zuluCryptCheckInvalidKey() is defined in check_invalid_key.c
  677      */
  678     zuluCryptCheckInvalidKey( opts->device ) ;
  679     return zuluExit_1( st,opts,device,mount_point,stl ) ;
  680 }