static string_t _root_device( const char * device,const char ** sys_device ) { size_t e ; ssize_t r ; string_t st = String( device ) ; if( StringStartsWithAtLeastOne( st,"/dev/sd","/dev/hd",NULL ) ){ /* * this path will convert something like: "/dev/sdc12" to "/dev/sdc". * basically,it removes digits from the end of the string to give the root device * required by tcplay's system volume or fde volume */ *sys_device = StringRemoveDigits( st ) ; }else if( StringStartsWith( st,"/dev/mmc" ) ){ /* * device path will be something like "/dev/mmcblk0p2" and what we want to do * is cut off the string from p to end iwth "/dev/mmcblk0" */ r = StringIndexOfChar( st,0,'p' ) ; if( r != -1 ){ e = StringLength( st ) - ( size_t )r ; *sys_device = StringRemoveRight( st,e ) ; }else{ *sys_device = StringContent( st ) ; } }else{ *sys_device = StringContent( st ) ; } return st ; }
void zuluCryptSecuritySanitizeTheEnvironment( uid_t uid,stringList_t * stx ) { extern char ** environ ; const char ** env = ( const char ** ) environ ; ssize_t index ; stringList_t stl = StringListVoid ; string_t st ; StringListIterator it ; StringListIterator end ; if( uid ){;} /* * First,we make a copy of the enviromental varibales * Second,we clear the enviromental variable because we dont want it * Third,we return a copy of the enviromental variable because we want to pass it along * the plugins */ while( *env ){ stl = StringListAppend( stl,*env ) ; env++ ; } StringListGetIterators( stl,&it,&end ) ; while( it != end ){ st = *it ; it++ ; index = StringIndexOfChar( st,0,'=' ) ; if( index >= 0 ){ unsetenv( StringSubChar( st,index,'\0' ) ) ; StringSubChar( st,index,'=' ) ; } } *stx = stl ; }
static int _zuluCryptCheckSYSifDeviceIsSystem( const char * device ) { /* * UDEV_SUPPORT is set at configure time by "-DUDEVSUPPORT=true" option,the option being absent equals "-DUDEVSUPPORT=false" * To set the option, configure with "-DUDEVSUPPORT=true" */ #if UDEV_SUPPORT /* * udev support is enabled */ int r ; size_t e ; ssize_t k ; string_t xt ; string_t st ; char dev[ PATH_MAX + 1 ] ; const char * path ; if( StringPrefixNotEqual( device,"/dev/" ) ){ /* * udev doesnt work with path to image files so return early */ return 0 ; } if( StringPrefixEqual( device,"/dev/loop" ) ){ /* * udev thinks all loop devices are system devices and we disagree and hence we return early */ return 0 ; } path = realpath( device,dev ) ; if( path != NULL ){ st = String( path ) ; }else{ st = String( device ) ; } if( StringStartsWithAtLeastOne( st,"/dev/sd","/dev/hd",NULL ) ){ /* * this path will convert something like: "/dev/sdc12" to "/dev/sdc" */ StringRemoveDigits( st ) ; }else if( StringStartsWith( st,"/dev/mmc" ) ){ /* * device path will be something like "/dev/mmcblk0p2" and what we want to do * is cut off the string from p to end iwth "/dev/mmcblk0" */ k = StringIndexOfChar( st,0,'p' ) ; if( k != -1 ){ e = StringLength( st ) - ( size_t )k ; StringRemoveRight( st,e ) ; } } StringReplaceString( st,"/dev/","/sys/block/" ) ; path = StringAppend( st,"/removable" ) ; /* * path will be something like "/sys/block/sda/removable" */ xt = StringGetFromVirtualFile( path ) ; StringDelete( &st ) ; if( xt == StringVoid ){ return 0 ; }else{ r = StringEqual( xt,"0\n" ) ; StringDelete( &xt ) ; return r ; } #else if( device ){;} /* * udev support is disabled */ return 0 ; #endif }