"Fossies" - the Fresh Open Source Software Archive

Member "zuluCrypt-5.7.1/zuluMount-cli/main.c" (15 Jan 2020, 21125 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 "main.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) 2012-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 <signal.h>
   22 #include "../zuluCrypt-cli/lib/includes.h"
   23 #include "../zuluCrypt-cli/bin/includes.h"
   24 #include <sys/resource.h>
   25 #include <signal.h>
   26 #include <sys/resource.h>
   27 #include <locale.h>
   28 #include <libintl.h>
   29 #include <locale.h>
   30 #include <stdio.h>
   31 #include <sys/types.h>
   32 #include <unistd.h>
   33 
   34 #include <grp.h>
   35 
   36 static void _seteuid( uid_t uid )
   37 {
   38     if( seteuid( uid ) ){;}
   39 }
   40 
   41 static void _setuid( uid_t uid )
   42 {
   43     if( setuid( uid ) ){;}
   44 }
   45 
   46 /*
   47  * All functions with "EXE" in their names are defined somewhere in ../zuluCrypt-cli/bin
   48  */
   49 
   50 static int _mount_get_opts( int argc,char * argv[],ARGS * args )
   51 {
   52     int c ;
   53     int k = 0 ;
   54 
   55     while( ( c = getopt( argc,argv,"cEMLnASNshlPmuDd:z:e:Y:p:f:G:o:F:t:B:b:K:" ) ) != -1 ){
   56 
   57         switch( c ){
   58 
   59             case 'M' : args->share   = 1      ; break ;
   60             case 'n' : args->mpo     = 1      ; break ;
   61             case 'E' : args->action  = "-E"   ; break ;
   62             case 'D' : args->action  = "-D"   ; break ;
   63             case 's' : args->action  = "-s"   ; break ;
   64             case 'l' : args->action  = "-l"   ; break ;
   65             case 'L' : args->action  = "-L"   ; break ;
   66             case 'P' : args->action  = "-P"   ; break ;
   67             case 'A' : args->action  = "-A"   ; break ;
   68             case 'S' : args->action  = "-S"   ; break ;
   69             case 'N' : args->action  = "-N"   ; break ;
   70             case 'm' : args->action  = "-m"   ; break ;
   71             case 'u' : args->action  = "-u"   ; break ;
   72             case 'c' : args->action  = "-c"   ; break ;
   73             case 'B' : args->action  = "-B"   ;
   74                        args->m_point = optarg ; break ;
   75             case 'b' : args->action  = "-b"   ;
   76                    args->m_point = optarg ; break ;
   77             case 't' : args->type    = optarg ; break ;
   78             case 'o' : args->offset  = optarg ; break ;
   79             case 'd' : args->device  = optarg ; break ;
   80             case 'z' : args->m_point = optarg ; break ;
   81             case 'e' : args->m_opts  = optarg ; break ;
   82             case 'K' : args->u_id    = optarg ; break ;
   83             case 'Y' : args->fs_opts = optarg ; break ;
   84             case 'p' : args->key     = optarg ;
   85                    args->key_source = "-p"; break ;
   86             case 'f' : args->key     = optarg ;
   87                    args->key_source = "-f"; break ;
   88             case 'G' : args->key     = optarg ;
   89                    args->key_source = "-G"; break ;
   90             case 'F' :
   91                    if( k < TRUECRYPT_MAX_KEYFILES ){
   92 
   93                        /*
   94                         * TRUECRYPT_MAX_KEYFILES is set at ../zuluCrypt-cli/bin/libzuluCrypt-exe.h
   95                         */
   96 
   97                     args->tcrypt_multiple_keyfiles[ k ] = optarg ;
   98                     k++ ;
   99                    }
  100                    break ;
  101             default  : return -1 ;
  102         }
  103     }
  104 
  105     return 0 ;
  106 }
  107 
  108 int _zuluExit( int st,string_t z,char * q,const char * msg )
  109 {
  110     StringFree( q ) ;
  111 
  112     StringDelete( &z ) ;
  113 
  114     if( msg != NULL ){
  115 
  116         printf( "%s\n",msg ) ;
  117     }
  118     return st ;
  119 }
  120 
  121 static int _zuluExit_2( int st,stringList_t z,stringList_t q,const char * msg )
  122 {
  123     zuluCryptSecurityUnlockMemory( z ) ;
  124 
  125     StringListMultipleDelete( &q,&z,NULL ) ;
  126 
  127     if( msg != NULL ){
  128 
  129         printf( "%s\n",msg ) ;
  130     }
  131     return st ;
  132 }
  133 
  134 int _zuluExit_1( int st,stringList_t z,char * q,const char * msg )
  135 {
  136     StringFree( q ) ;
  137 
  138     zuluCryptSecurityUnlockMemory( z ) ;
  139 
  140     StringListDelete( &z ) ;
  141 
  142     if( msg != NULL ){
  143 
  144         printf( "%s\n",msg ) ;
  145     }
  146 
  147     return st ;
  148 }
  149 
  150 static int _zuluMountDeviceList( uid_t uid )
  151 {
  152     /*
  153      * zuluCryptPrintPartitions() is defined in ../zuluCrypt-cli/partitions.c
  154      * ZULUCRYPTallPartitions is set in ../zuluCrypt-cli/constants.h
  155      */
  156     return zuluCryptPrintPartitions( ZULUCRYPTallPartitions,0,uid ) ;
  157 }
  158 
  159 
  160 static int _zuluMountNonSystemDeviceList( uid_t uid )
  161 {
  162     /*
  163      * zuluCryptPrintPartitions() is defined in ../zuluCrypt-cli/partitions.c
  164      * ZULUCRYPTallPartitions is set in ../zuluCrypt-cli/constants.h
  165      */
  166     return zuluCryptPrintPartitions( ZULUCRYPTnonSystemPartitions,0,uid ) ;
  167 }
  168 
  169 static int _zuluMountSystemDeviceList( uid_t uid )
  170 {
  171     /*
  172      * zuluCryptPrintPartitions() is defined in ../zuluCrypt-cli/partitions.c
  173      * ZULUCRYPTallPartitions is set in ../zuluCrypt-cli/constants.h
  174      */
  175     return zuluCryptPrintPartitions( ZULUCRYPTsystemPartitions,0,uid ) ;
  176 }
  177 
  178 static int _zuluMountMountedList( uid_t uid )
  179 {
  180     /*
  181      * zuluMountPrintVolumesProperties() is defined in volume_status.c
  182      */
  183     return zuluMountPrintVolumesProperties( uid ) ;
  184 }
  185 
  186 static string_t _zuluCryptGetFileSystemFromDevice( const char * device )
  187 {
  188     string_t st ;
  189 
  190     zuluCryptSecurityGainElevatedPrivileges() ;
  191     st = zuluCryptGetFileSystemFromDevice( device ) ;
  192     zuluCryptSecurityDropElevatedPrivileges() ;
  193 
  194     return st ;
  195 }
  196 
  197 static int _zuluPartitionHasCryptoFs( const char * device )
  198 {
  199     int r ;
  200     /*
  201      * zuluCryptSecurityGainElevatedPrivileges() is defined in ../zuluCrypt-cli/bin/security.c
  202      */
  203     zuluCryptSecurityGainElevatedPrivileges() ;
  204 
  205     /*
  206      * zuluCryptDeviceHasEncryptedFileSystem() is defined in ../zuluCrypt-cli/lib/blkid_evaluate_tag.c
  207      */
  208     r = zuluCryptDeviceHasEncryptedFileSystem( device ) ;
  209 
  210     /*
  211      * zuluCryptSecurityDropElevatedPrivileges() is defined in ../zuluCrypt-cli/bin/security.c
  212      */
  213     zuluCryptSecurityDropElevatedPrivileges() ;
  214 
  215     return r ;
  216 }
  217 
  218 static int _zuluMountPrintVolumeDeviceName( const char * device )
  219 {
  220     char * c ;
  221 
  222     /*
  223      * zuluCryptSecurityGainElevatedPrivileges() is defined in ../zuluCrypt-cli/bin/security.c
  224      */
  225     zuluCryptSecurityGainElevatedPrivileges() ;
  226     /*
  227     * zuluCryptVolumeDeviceName() is defined in ../lib/status.c
  228     */
  229     c = zuluCryptVolumeDeviceName( device ) ;
  230 
  231     /*
  232      * zuluCryptSecurityDropElevatedPrivileges() is defined in ../zuluCrypt-cli/bin/security.c
  233      */
  234     zuluCryptSecurityDropElevatedPrivileges() ;
  235 
  236     if( c == NULL ){
  237 
  238         return 1 ;
  239     }else{
  240         printf( "%s\n",c ) ;
  241         StringFree( c ) ;
  242         return 0 ;
  243     }
  244 }
  245 
  246 /*
  247  * This is an emergency function,to be used when a device was unplugged uncleanly causing the device
  248  * old path to be "locked" as pluggin in the device again will give it a different path
  249  */
  250 static int _checkUnmount( const char * device,uid_t uid )
  251 {
  252     stringList_t stx ;
  253     stringList_t stl ;
  254 
  255     ssize_t index ;
  256     int r ;
  257     char * m_point = NULL ;
  258     string_t st ;
  259     const char * g ;
  260 
  261     if( StringPrefixEqual( device,"/dev/mapper/zuluCrypt-" ) ){
  262         /*
  263          * encrypted volumes are handled someplace else
  264          */
  265         return 0 ;
  266     }
  267     /*
  268      * zuluCryptGetMoutedList() is defined in ../lib/process_mountinfo.c
  269      */
  270     stx = zuluCryptGetMoutedList() ;
  271 
  272     st = String( device ) ;
  273     index = StringListHasStartSequence( stx,StringAppend( st," " ) ) ;
  274     StringDelete( &st ) ;
  275 
  276     if( index != -1 ){
  277 
  278         st = StringListStringAt( stx,index ) ;
  279         stl = StringListStringSplit( st,' ' ) ;
  280 
  281         device = StringListContentAtFirstPlace( stl ) ;
  282         /*
  283          * zuluCryptBindUnmountVolume() is defined in ../zuluCrypt-cli/bin/bind.c
  284          */
  285         r = zuluCryptBindUnmountVolume( stx,device,uid ) ;
  286 
  287         if( r != 3 || r != 4 ){
  288 
  289             st = StringListStringAtSecondPlace( stl ) ;
  290             /*
  291              * zuluCryptDecodeMountEntry() is defined in ../zuluCrypt-cli/lib/mount_volume.c
  292              */
  293             g  = zuluCryptDecodeMountEntry( st ) ;
  294             /*
  295              * zuluCryptMountPointPrefixMatch() is defined in ../zuluCrypt-cli/lib/create_mount_point.c
  296              */
  297             r = zuluCryptMountPointPrefixMatch( g,uid,NULL ) ;
  298 
  299             if( r == 1 ){
  300 
  301                 zuluCryptSecurityGainElevatedPrivileges() ;
  302                 /*
  303                  * zuluCryptUnmountVolume() is defined in ../zuluCrypt-cli/lib/unmount_volume.c
  304                  */
  305                 if( zuluCryptUnmountVolume( device,&m_point ) == 0 ){
  306 
  307                     if( m_point != NULL ){
  308 
  309                         rmdir( m_point ) ;
  310                         StringFree( m_point ) ;
  311                     }
  312                 }
  313                 zuluCryptSecurityDropElevatedPrivileges() ;
  314             }
  315         }
  316 
  317         StringListDelete( &stl ) ;
  318     }else{
  319         /*
  320          * Either the volume is not mounted or is encrypted.
  321          * If it is encrypted,then it is handled someplace else
  322          */
  323         ;
  324     }
  325 
  326     StringListDelete( &stx ) ;
  327 
  328     return 0 ;
  329 }
  330 
  331 static int _zuluMountExe( ARGS * args )
  332 {
  333     const char * device = args->device ;
  334     const char * action = args->action ;
  335     const char * uuid   = args->uuid   ;
  336     const char * offset = args->offset ;
  337     uid_t        uid    = args->uid    ;
  338 
  339     string_t st ;
  340 
  341     int r ;
  342 
  343     if( StringsAreEqual( action,"-L" ) ){
  344 
  345         return zuluMountPrintDeviceProperties( device,uuid,uid ) ;
  346     }
  347 
  348     if( StringsAreEqual( action,"-s" ) ){
  349 
  350         st = _zuluCryptGetFileSystemFromDevice( device ) ;
  351 
  352         zuluCryptSecurityGainElevatedPrivileges() ;
  353 
  354         r = zuluCryptDeviceManagedByDislocker( device,uid ) ;
  355 
  356         zuluCryptSecurityDropElevatedPrivileges() ;
  357 
  358         if( StringContains( st,zuluCryptBitLockerType() ) && r ){
  359 
  360             r = zuluMountPrintBitLockerProperties( device,uid ) ;
  361 
  362         }else if( offset != NULL ||
  363               st == StringVoid ||
  364               StringsAreEqual_2( st,"Nil" ) ||
  365               StringStartsWith( st,"crypto_" ) ){
  366 
  367             r = zuluMountVolumeStatus( device,uuid,uid ) ;
  368         }else{
  369             r = zuluMountUnEncryptedVolumeStatus( device,NULL,NULL ) ;
  370         }
  371 
  372         StringDelete( &st ) ;
  373 
  374         return r ;
  375     }
  376 
  377     if( StringsAreEqual( action,"-m" ) ){
  378 
  379         if( offset != NULL || _zuluPartitionHasCryptoFs( device ) ){
  380             /*
  381              * zuluMountMount() is defined in crypto_mount.c
  382              */
  383             return zuluMountCryptoMount( args ) ;
  384         }else{
  385             /*
  386              * zuluMountMount() is defined in mount.c
  387              */
  388             return zuluMountMount( args ) ;
  389         }
  390     }
  391 
  392     if( StringsAreEqual( action,"-u" ) ){
  393 
  394         if( offset != NULL || _zuluPartitionHasCryptoFs( device ) ){
  395             /*
  396              * zuluMountMount() is defined in crypto_umount.c
  397              */
  398             return zuluMountCryptoUMount( args ) ;
  399         }else{
  400             /*
  401              * zuluMountMount() is defined in umount.c
  402              */
  403             return zuluMountUMount( args ) ;
  404         }
  405     }
  406 
  407     return _zuluExit_1( 200,StringListVoid,NULL,gettext( "ERROR: unrecognized argument encountered" ) ) ;
  408 }
  409 
  410 static int _mount_help()
  411 {
  412     const char * doc6 ;
  413     const char * doc5 ;
  414     const char * doc4 ;
  415     const char * doc3 ;
  416     const char * doc2 ;
  417     const char * doc1 = gettext( "\
  418 options:\n\
  419 -m -- mount a volume : arguments: -d volume_path -z mount_point -e mode(rw/ro)\n\
  420       -- additional arguments for crypto_LUKS,crypto_PLAIN,crypto_TCRYPT volumes, -p passphrase/-f keyfile\n\
  421 -z -- mount point component to append to \"/run/media/private/$USER/\"\n\
  422 -Y -- file system options\n\
  423 -e -- mount options\n" ) ;
  424 
  425     doc2 = gettext( "\
  426 -u -- unmount a volume: arguments: -d volume_path\n\
  427 -s -- print properties of a volume: arguments: -d partition_path\n\
  428 -M -- this option will create a mount point in \"/run/media/private/$USER\" and a publicly accessible \"mirror\" in \"/run/media/public/\'\n" ) ;
  429 
  430     doc3 = gettext( "\
  431 -l -- print expanded list of all volumes\n\
  432 -L -- must be used with -d,print properties of a volume specified by d option\n\
  433 -P -- print a list of all volumes\n\
  434 -D -- get a device node address from its mapper path( mapper paths are usually located in /dev/mapper ). Required argument: -d\n" ) ;
  435 
  436     doc4 = gettext( "\
  437 -A -- print a list of all volumes\n\
  438 -S -- print a list of system volumes\n\
  439 -N -- print a list of non system volumes\n\
  440 -E -- print a list of mounted volumes\n\
  441 -t -- to unlock a volume as VeraCrypt volume,use \"-t vera\"\n" ) ;
  442 
  443     doc5= gettext( "\
  444 -o -- offset in sectors on where the volume starts in the volume.The volume is assumed to be plain type with this option \
  445 and the option must be given when -u or -s arguments are used with a volume opened with this option\n\
  446 -F -- path to truecrypt multiple keyfiles.Keyfiles are separated by \":\" character\n\n" ) ;
  447 
  448     doc6= gettext( "\
  449 examples:\n\
  450 mount a volume  : zuluMount-cli -m -d /dev/sdc1\n\
  451 unmount a volume: zuluMount-cli -u -d /dev/sdc1\n\
  452 mount and encrypted volume with a key \"xyz\" : zuluMount-cli -m -d /dev/sdc2 -p xyz\n" ) ;
  453 
  454       printf( "%s%s%s%s%s%s",doc1,doc2,doc3,doc4,doc5,doc6 ) ;
  455 
  456     return 201 ;
  457 }
  458 
  459 static void ExitOnMemoryExaustion( void )
  460 {
  461     printf( gettext( "Unexpected exiting because you have run out of memory\n" ) ) ;
  462     exit( 1 ) ;
  463 }
  464 
  465 static int _zuluMountDoAction( ARGS * args )
  466 {
  467     int fd = -1 ;
  468     int fd1 = -1 ;
  469     int status ;
  470     char * dev = NULL ;
  471     const char * msg = gettext( "ERROR: A non supported device encountered,device is missing or permission denied\n\
  472 Possible reasons for getting the error are:\n1.Device path is invalid.\n2.The device has LVM or MDRAID signature\n"  ) ;
  473     /*
  474      * zuluCryptGetDeviceFileProperties is defined in ../zuluCrypt-lib/file_path_security.c
  475      */
  476     switch( zuluCryptGetDeviceFileProperties( args->device,&fd,&fd1,&dev,args->uid ) ){
  477 
  478         case 0 : args->device = dev ;
  479              /*
  480               * zuluCryptDeviceIsSupported() is defined in ../zuluCrypt-cli/bin/volumes.c
  481               */
  482              if( zuluCryptDeviceIsSupported( dev,args->uid ) ){
  483 
  484                 status = _zuluMountExe( args ) ;
  485              }else{
  486                 printf( "%s",msg ) ;
  487                 status = 224 ;
  488              }
  489              if( dev != NULL ){
  490 
  491                  StringFree( dev ) ;
  492              }
  493              if( fd1 != -1 ){
  494 
  495                  close( fd ) ;
  496              }
  497              if( fd != -1 ){
  498 
  499                  close( fd ) ;
  500              }
  501              return status ;
  502         case 1 : printf( gettext( "ERROR: Devices in /dev/shm path is not suppored\n" ) ) ; return 220 ;
  503         case 2 : printf( gettext( "ERROR: Given path is a directory\n" ) ) ;            return 221 ;
  504         case 3 : printf( gettext( "ERROR: A file can have only one hard link\n" ) ) ;       return 222 ;
  505         case 4 : printf( gettext( "ERROR: Insufficient privilges to access the device\n" ) ) ;  return 223 ;
  506         default: printf( "%s",msg ) ;                               return 224 ;
  507     }
  508 }
  509 
  510 static void _privilegeEvelationError( const char * msg )
  511 {
  512     puts( msg ) ;
  513     exit( 255 ) ;
  514 }
  515 
  516 static void _forceTerminateOnSeriousError( int sig )
  517 {
  518     if( sig ){;}
  519     puts( "SIGSEGV caught,exiting" ) ;
  520     exit( 255 ) ;
  521 }
  522 
  523 static int _create_mount_point( const char * label,const char * m_opts,uid_t uid )
  524 {
  525     /*
  526      * zuluCryptCreateMountPoint() is defined in ../zuluCrypt-cli/bin/create_mount_point.c
  527      */
  528     string_t st = zuluCryptCreateMountPoint( NULL,label,m_opts,uid ) ;
  529 
  530     int r ;
  531 
  532     if( st != StringVoid ){
  533 
  534         r = 0 ;
  535 
  536         StringDelete( &st ) ;
  537     }else{
  538         r = 1 ;
  539     }
  540 
  541     return r ;
  542 }
  543 
  544 static int _delete_mount_point( const char * m_path,uid_t uid )
  545 {
  546     string_t st ;
  547 
  548     int r = 0 ;
  549 
  550     /*
  551      * zuluCryptReuseMountPoint() is defined in ../zuluCrypt-cli/bin/create_mount_point.c
  552      */
  553 
  554     if( !zuluCryptReuseMountPoint() ){
  555 
  556         /*
  557          * zuluCryptGetUserName() is defined in ../zuluCrypt-cli/lib/user_home_path.c
  558          */
  559         st = zuluCryptGetUserName( uid ) ;
  560 
  561         if( StringPrefixEqual( m_path,StringPrepend( st,"/run/media/private/" ) ) ){
  562 
  563             zuluCryptSecurityGainElevatedPrivileges() ;
  564 
  565             r = rmdir( m_path ) ;
  566 
  567             zuluCryptSecurityDropElevatedPrivileges() ;
  568 
  569         }else{
  570             zuluCryptSecurityDropElevatedPrivileges() ;
  571 
  572             r = rmdir( m_path ) ;
  573         }
  574 
  575         StringDelete( &st ) ;
  576     }
  577 
  578     return r ;
  579 }
  580 
  581 int main( int argc,char * argv[] )
  582 {
  583     char * action ;
  584     char * device ;
  585     string_t * k ;
  586     stringList_t stl ;
  587     stringList_t stx ;
  588     int status ;
  589 
  590     int i ;
  591 
  592     uid_t uid = getuid() ;
  593     gid_t gid = getgid() ;
  594 
  595     /*
  596      * ARGS structure is declared in ./includes.h
  597      */
  598     ARGS args ;
  599 
  600     struct sigaction sa ;
  601     memset( &sa,'\0',sizeof( struct sigaction ) ) ;
  602     sa.sa_handler = _forceTerminateOnSeriousError ;
  603     sigaction( SIGSEGV,&sa,NULL ) ;
  604 
  605     setlocale( LC_ALL,"" ) ;
  606     bindtextdomain( "zuluMount-cli",TRANSLATION_PATH ) ;
  607     textdomain( "zuluMount-cli" );
  608 
  609     zuluCryptExeSetOriginalUID( uid ) ;
  610 
  611     if( argc < 2 ){
  612 
  613         return _mount_help() ;
  614     }
  615     if( argc == 2 ){
  616 
  617         action = argv[ 1 ] ;
  618 
  619         if( StringAtLeastOneMatch_1( action,"-h","--help","-help",NULL ) ){
  620 
  621             return _mount_help() ;
  622         }
  623         if( StringAtLeastOneMatch_1( action,"-v","-version","--version",NULL ) ){
  624 
  625             printf( "%s\n",zuluCryptVersion() );
  626             return 0 ;
  627         }
  628         if( StringsAreEqual( action,"--clear-dead-mount-points" ) ){
  629 
  630             zuluCryptClearDeadMappers( uid,1 ) ;
  631             return 0 ;
  632         }
  633     }
  634 
  635     memset( &args,'\0',sizeof( args ) ) ;
  636 
  637     /*
  638      * setgroups() requires seteuid(0) ;
  639      */
  640     _seteuid( 0 ) ;
  641     if( setgroups( 1,&gid ) != 0 ){
  642 
  643         _privilegeEvelationError( gettext( "ERROR: setgroups() failed" ) ) ;
  644     }
  645     if( setegid( uid ) != 0 ){
  646 
  647         _privilegeEvelationError( gettext( "ERROR: setegid() failed" ) ) ;
  648     }
  649     if( _mount_get_opts( argc,argv,&args ) != 0 ){
  650 
  651         return _mount_help() ;
  652     }
  653 
  654     i = zuluCryptSecurityConvertUID( uid,args.u_id ) ;
  655 
  656     if( i == -1 ){
  657 
  658         puts( gettext( "ERROR: user is not root privileged" ) ) ;
  659         return 255 ;
  660     }else{
  661         args.uid = uid = i ;
  662     }
  663 
  664     /*
  665      * Run with higher priority to speed things up
  666      */
  667     setpriority( PRIO_PROCESS,0,-15 ) ;
  668     _setuid( 0 ) ;
  669     _seteuid( uid ) ;
  670 
  671     /*
  672      * zuluCryptDisableMetadataLocking() is defined in ..zuluCrypt-cli/lib/create_luks.c
  673      */
  674     zuluCryptDisableMetadataLocking() ;
  675 
  676     /*
  677      * zuluCryptClearDeadMappers() is defined in ../zuluCrypt-cli/bin/clear_dead_mapper.c
  678      */
  679     zuluCryptClearDeadMappers( uid,0 ) ;
  680 
  681     /*
  682      * zuluCryptSecuritySetPrivilegeElevationErrorFunction() is defined in ../zuluCrypt-cli/bin/security.c
  683      * _privilegeEvelationError() function will be called when functions that elevate or drop privileges fail
  684      */
  685     zuluCryptSecuritySetPrivilegeElevationErrorFunction( _privilegeEvelationError ) ;
  686 
  687     /*
  688      * zuluCryptSetUserUIDForPrivilegeManagement() is defined in ../zuluCrypt-bin/security.c
  689      */
  690     zuluCryptSetUserUIDForPrivilegeManagement( uid ) ;
  691     /*
  692      * zuluCryptSecurityDropElevatedPrivileges() is defined in ../zuluCrypt-cli/bin/security.c
  693      */
  694     zuluCryptSecurityDropElevatedPrivileges() ;
  695 
  696     StringExitOnMemoryExaustion( ExitOnMemoryExaustion ) ;
  697     StringListExitOnMemoryExaustion( ExitOnMemoryExaustion ) ;
  698     SocketExitOnMemoryExaustion( ExitOnMemoryExaustion ) ;
  699     ProcessExitOnMemoryExaustion( ExitOnMemoryExaustion ) ;
  700 
  701     stl = StringListInit() ;
  702     /*
  703      * zuluCryptSecuritySanitizeTheEnvironment() is defined in ../zuluCrypt-cli/bin/security.c
  704      */
  705     zuluCryptSecuritySanitizeTheEnvironment( global_variable_user_uid,&stx ) ;
  706 
  707     #define _hide( z ) strncpy( ( char * )z,"x",StringLength( *k ) )
  708 
  709     if( args.device != NULL ){
  710 
  711         k = StringListAssign( stl ) ;
  712         *k = String( args.device ) ;
  713         _hide( args.device ) ;
  714         args.device = StringContent( *k ) ;
  715     }
  716 
  717     if( args.key != NULL ){
  718 
  719         k = StringListAssign( stl ) ;
  720         *k = String( args.key ) ;
  721         _hide( args.key ) ;
  722         args.key = StringContent( *k ) ;
  723     }
  724 
  725     if( args.type != NULL ){
  726 
  727         k = StringListAssign( stl ) ;
  728         *k = String( args.type ) ;
  729         _hide( args.type ) ;
  730         args.type = StringContent( *k ) ;
  731     }
  732 
  733     for( i = 0 ; args.tcrypt_multiple_keyfiles[ i ] != NULL ; i++ ){
  734 
  735         k = StringListAssign( stl ) ;
  736         *k = String( args.tcrypt_multiple_keyfiles[ i ] ) ;
  737         _hide( args.tcrypt_multiple_keyfiles[ i ] ) ;
  738         args.tcrypt_multiple_keyfiles[ i ] = StringContent( *k ) ;
  739     }
  740 
  741     zuluCryptSecurityLockMemory( stl ) ;
  742 
  743     if( args.action == NULL ){
  744 
  745         return _zuluExit_2( 212,stl,stx,gettext( "ERROR: Action not specified" ) ) ;
  746     }
  747     if( StringsAreEqual( args.action,"-E" ) ){
  748 
  749         return _zuluExit_2(  zuluMountprintAListOfMountedVolumes( uid ),stl,stx,NULL ) ;
  750     }
  751     if( StringsAreEqual( args.action,"-c" ) ){
  752 
  753         return _zuluExit_2( _checkUnmount( args.device,uid ),stl,stx,NULL ) ;
  754     }
  755     if( StringsAreEqual( args.action,"-l" ) ){
  756 
  757         return _zuluExit_2( _zuluMountMountedList( uid ),stl,stx,NULL ) ;
  758     }
  759     if( StringsAreEqual( args.action,"-P" ) || StringsAreEqual( args.action,"-A" ) ){
  760 
  761         return _zuluExit_2( _zuluMountDeviceList( uid ),stl,stx,NULL ) ;
  762     }
  763     if( StringsAreEqual( args.action,"-S" ) ){
  764 
  765         return _zuluExit_2( _zuluMountSystemDeviceList( uid ),stl,stx,NULL ) ;
  766     }
  767     if( StringsAreEqual( args.action,"-N" ) ){
  768         return _zuluExit_2( _zuluMountNonSystemDeviceList( uid ),stl,stx,NULL ) ;
  769     }
  770     if( StringsAreEqual( args.action,"-B" ) ){
  771 
  772         return _zuluExit_2( _create_mount_point( args.m_point,args.m_opts,args.uid ),stl,stx,NULL ) ;
  773     }
  774     if( StringsAreEqual( args.action,"-b" ) ){
  775 
  776         return _zuluExit_2( _delete_mount_point( args.m_point,args.uid ),stl,stx,NULL ) ;
  777     }
  778     if( StringsAreEqual( args.action,"-h" ) ){
  779 
  780         return _zuluExit_2( _mount_help(),stl,stx,NULL ) ;
  781     }
  782     if( args.device == NULL ){
  783 
  784         return _zuluExit_2( 213,stl,stx,gettext( "ERROR: device argument missing" ) ) ;
  785     }
  786     if( StringsAreEqual( args.action,"-D" ) ){
  787 
  788         return _zuluMountPrintVolumeDeviceName( args.device ) ;
  789     }
  790     if( args.m_opts == NULL ){
  791 
  792         args.m_opts = "rw" ;
  793     }
  794 
  795     args.env = stx ;
  796 
  797     /*
  798      * zuluCryptEvaluateDeviceTags() is defined in ../zuluCrypt-cli/bin/path_access.c
  799      */
  800     if( StringPrefixEqual( args.device,"UUID=" ) ){
  801 
  802         device = zuluCryptEvaluateDeviceTags( "UUID",args.device + 5 ) ;
  803 
  804         if( device != NULL ){
  805 
  806             args.uuid = args.device ;
  807             args.device = device ;
  808             status = _zuluMountDoAction( &args ) ;
  809             StringFree( device ) ;
  810         }else{
  811             printf( gettext( "Could not resolve UUID\n" ) ) ;
  812             status = 214 ;
  813         }
  814     }else if( StringPrefixEqual( args.device,"LABEL=" ) ){
  815 
  816         device = zuluCryptEvaluateDeviceTags( "LABEL",args.device + 6 ) ;
  817 
  818         if( device != NULL ){
  819 
  820             args.device = device ;
  821             status = _zuluMountDoAction( &args ) ;
  822             StringFree( device ) ;
  823         }else{
  824             printf( gettext( "Could not resolve LABEL\n" ) ) ;
  825             status = 215 ;
  826         }
  827     }else{
  828         status = _zuluMountDoAction( &args ) ;
  829     }
  830 
  831     return _zuluExit_2( status,stl,stx,NULL ) ;
  832 }