예제 #1
0
static void _print_list( stringList_t stl )
{
	const char * e ;
	char * z ;

	StringListIterator it  ;
	StringListIterator end ;

	StringListGetIterators( stl,&it,&end ) ;

	while( it != end ){
		e = StringContent( *it ) ;
		it++ ;
		if( StringPrefixEqual( e,"/dev/loop" ) ){
			/*
			 * zuluCryptLoopDeviceAddress_1() is defined in ../lib/create_loop_device.c
			 */
			z = zuluCryptLoopDeviceAddress_1( e ) ;
			if( z != NULL ){
				puts( z ) ;
				StringFree( z ) ;
			}else{
				puts( e ) ;
			}
		}else{
			puts( e ) ;
		}
	}
}
예제 #2
0
파일: status.c 프로젝트: DarkDare/zuluCrypt
static void _device_info( string_t p,const char * device )
{
	char * path ;

	if( device == NULL ){

		StringMultipleAppend( p,"\n device:   \t","Nil","\n loop:   \t","Nil",NULL ) ;

	}else if( StringPrefixEqual( device,"/dev/loop" ) ){

		path = zuluCryptLoopDeviceAddress_1( device ) ;

		if( path != NULL ){

			StringMultipleAppend( p,"\n device:   \t",device,"\n loop:   \t",path,NULL ) ;
			StringFree( path ) ;
		}else{
			StringMultipleAppend( p,"\n device:   \t",device,"\n loop:   \tNil",NULL ) ;
		}
	}else{
		/*
		 * zuluCryptResolvePath() is defined in resolve_path.c
		 */
		path = zuluCryptResolvePath( device ) ;
		StringMultipleAppend( p,"\n device:   \t",path,"\n loop:   \tNil",NULL ) ;
		StringFree( path ) ;
	}
}
예제 #3
0
char * zuluCryptGetALoopDeviceAssociatedWithAnImageFile( const char * path )
{
	int i ;
	string_t st = String( "" ) ;
	const char * e ;
	char * f ;

	for( i = 0 ; i < 255 ; i++ ){

		StringReplace( st,"/dev/loop" ) ;

		e = StringAppendInt( st,i ) ;

		f = zuluCryptLoopDeviceAddress_1( e ) ;

		if( StringsAreEqual( path,f ) ){

			StringFree( f ) ;

			return StringDeleteHandle( &st ) ;
		}else{
			StringFree( f ) ;
		}
	}

	StringDelete( &st ) ;
	return NULL ;
}
예제 #4
0
char * zuluCryptGetLoopDeviceAddress( const char * device )
{
	char * z = NULL ;
	const char * e ;

	string_t st = StringVoid ;
	string_t xt = StringVoid ;

	int i ;
	int r ;

	z = zuluCryptLoopDeviceAddress_1( device ) ;

	if( z == NULL ){
		return NULL ;
	}else{
		st = String( "" ) ;

		for( i = 0 ; i < 255 ; i++ ){

			StringReplace( st,"/sys/block/loop" ) ;
			StringAppendInt( st,i ) ;

			xt = StringGetFromVirtualFile( StringAppend( st,"/loop/backing_file" ) ) ;

			e = StringRemoveRight( xt,1 ) ;
			r = StringsAreEqual( e,z ) ;

			StringDelete( &xt ) ;

			if( r ){

				StringReplace( st,"/dev/loop" ) ;
				e = StringAppendInt( st,i ) ;

				if( StringsAreNotEqual( device,e ) ){

					break ;
				}
			}else{
				StringReset( st ) ;
			}
		}

		StringFree( z ) ;

		if( StringIsEmpty( st ) ){

			StringDelete( &st ) ;
			return NULL ;
		}else{
			return StringDeleteHandle( &st ) ;
		}
	}
}
예제 #5
0
char * zuluCryptResolvePath_3( const char * path )
{
	if( StringPrefixEqual( path,"/dev/loop" ) ){
		/*
		 * zuluCryptLoopDeviceAddress_1() is defined in create_loop_device.c
		 */
		return zuluCryptLoopDeviceAddress_1( path ) ;
	}else{
		return zuluCryptResolvePath( path ) ;
	}
}
int zuluMountCryptoUMount( ARGS * args )
{
	const char * device    = args->device ;
	const char * UUID      = args->uuid   ;
	uid_t        uid       = args->uid    ;

	const char * mapping_name ;
	char * path = NULL ;

	int st  ;

	string_t str = StringVoid ;

	if( UUID == NULL ){

		if( StringPrefixEqual( device,"/dev/loop" ) ){

			/*
			 * zuluCryptLoopDeviceAddress_1() is defined in ../zuluCrypt-cli/create_loop_device.c
			 */

			path = zuluCryptLoopDeviceAddress_1( device ) ;

			if( path == NULL ){

				return 20 ;
			}else{
				device = path ;
			}
		}

		mapping_name = device + StringLastIndexOfChar_1( device,'/' ) + 1 ;
	}else{
		str = String( UUID ) ;
		StringRemoveString( str,"\"" ) ;
		mapping_name = StringSubChar( str,4,'-' ) ;
	}

	/*
	 * zuluCryptEXECloseVolume() is defined in ../zuluCrypt-cli/bin/close_volume.c
	 */
	st = zuluCryptEXECloseVolume( device,mapping_name,uid ) ;

	StringDelete( &str ) ;

	StringFree( path ) ;

	return st ;
}
예제 #7
0
static string_t _create_mount_point_1( const char * device,uid_t uid,string_t path,int need_privileges )
{
	string_t st ;
	char * loop_path = NULL ;

	if( StringPrefixEqual( device,"/dev/loop" ) ){
		/*
		 * zuluCryptLoopDeviceAddress_1() is defined in ../lib/create_loop_device.c
		 */
		device = loop_path = zuluCryptLoopDeviceAddress_1( device ) ;
	}

	StringMultipleAppend( path,device + StringLastIndexOfChar_1( device,'/' ) + 1,NULL ) ;

	st = _create_path( uid,path,need_privileges ) ;

	StringFree( loop_path ) ;

	return st ;
}
예제 #8
0
int zuluCryptPartitionIsSystemPartition( const char * device,uid_t uid )
{
	char * dev ;
	int r ;
	if( StringPrefixEqual( device,"/dev/loop" ) ){
		/*
		 * zuluCryptLoopDeviceAddress_1() is defined in ../lib/create_loop_device.c
		 */
		dev = zuluCryptLoopDeviceAddress_1( device ) ;
		if( dev == NULL ){
			return 0 ;
		}else{
			r = _zuluCryptPartitionIsSystemPartition( dev,uid ) ;
			StringFree( dev ) ;
			return r ;
		}
	}else{
		return _zuluCryptPartitionIsSystemPartition( device,uid ) ;
	}
}
예제 #9
0
/*
 * 1-permissions denied
 * 2-invalid path
 * 3-shenanigans
 * 4-common error
 */
static int path_is_accessible( const char * path,uid_t uid,int action )
{
	int st ;
	char * e ;

	if( uid ){;}

	if( StringPrefixEqual( path,"/dev/shm/" ) ){

		return 4 ;
	}
	if( StringPrefixEqual( path,"/dev/" ) ){

		if( StringPrefixEqual( path,"/dev/loop" ) ){

			/*
			 * zuluCryptLoopDeviceAddress_1() is defined in ../zuluCrypt-cli/create_loop_device.c
			 */
			e = zuluCryptLoopDeviceAddress_1( path ) ;

			if( e != NULL ){

				st = has_device_access( e,action ) ;
				StringFree( e ) ;
			}else{
				return 4 ;
			}
		}else{
			zuluCryptSecurityGainElevatedPrivileges() ;
			st = has_device_access( path,action ) ;
			zuluCryptSecurityDropElevatedPrivileges() ;
		}
		return st ;
	}else{
		zuluCryptSecurityDropElevatedPrivileges() ;
		return has_device_access( path,action ) ;
	}
}
예제 #10
0
static char * _device_path( const char * device )
{
	char * path ;

	if( StringPrefixEqual( device,"/dev/loop" ) ){

		zuluCryptSecurityGainElevatedPrivileges() ;
		/*
		 * zuluCryptLoopDeviceAddress_1() is defined in ../zuluCrypt-cli/create_loop_device.c
		 */
		path = zuluCryptLoopDeviceAddress_1( device ) ;

		zuluCryptSecurityDropElevatedPrivileges() ;

		if( path == NULL ){

			return StringCopy_2( device ) ;
		}else{
			return path ;
		}
	}else{
		return StringCopy_2( device ) ;
	}
}
int zuluMountCryptoMount( ARGS * args )
{
	const char * type       = args->type       ;
	const char * offset     = args->offset     ;
	const char * device     = args->device     ;
	const char * UUID       = args->uuid       ;
	const char * mode       = args->m_opts     ;
	uid_t        uid        = args->uid        ;
	const char * key        = args->key        ;
	const char * key_source = args->key_source ;
	const char * m_point    = args->m_point    ;
	const char * fs_opts    = args->fs_opts    ;
	int mount_point_option  = args->mpo        ;
	int share               = args->share      ;
	int st ;
	/*
	 * the struct is declared in ../zuluCrypt-cli/bin/libzuluCrypt-exe.h
	 */
	struct_opts opts ;

	const char * mapping_name ;
	char * path = NULL ;

	string_t str = StringVoid ;

	if( UUID == NULL ){

		if( StringPrefixEqual( device,"/dev/loop" ) ){
			/*
			* zuluCryptLoopDeviceAddress_1() is defined in ../zuluCrypt-cli/create_loop_device.c
			*/
			path = zuluCryptLoopDeviceAddress_1( device ) ;

			if( path == NULL ){

				return 20 ;
			}else{
				mapping_name = path + StringLastIndexOfChar_1( path,'/' ) + 1 ;
			}
		}else{
			mapping_name = device + StringLastIndexOfChar_1( device,'/' ) + 1 ;
		}
	}else{
		str = String( UUID ) ;
		StringRemoveString( str,"\"" ) ;
		mapping_name = StringReplaceString( str,"UUID=","UUID-" ) ;
	}

	/*
	 * zuluCryptEXEGetOptsSetDefault() is defined in ../zuluCrypt-cli/bin/get_opts.c
	 */
	zuluCryptEXEGetOptsSetDefault( &opts ) ;

	if( StringPrefixEqual( key_source,"-G" ) ){
		
		opts.plugin_path = key ;
	}

	opts.mount_point        = m_point ;
	opts.device             = device ;
	opts.m_opts             = mode ;
	opts.key                = key ;
	opts.key_source         = key_source ;
	opts.mount_point_option = mount_point_option ;
	opts.share              = share ;
	opts.fs_opts            = fs_opts ;
	opts.env                = StringListStringArray( args->env ) ;
	opts.offset             = offset ;
	opts.type               = type ;

	memcpy( opts.tcrypt_multiple_keyfiles,args->tcrypt_multiple_keyfiles,
		sizeof( args->tcrypt_multiple_keyfiles ) ) ;

	/*
	 * zuluCryptEXEOpenVolume() is defined in ../zuluCrypt-cli/bin/open_volume.c
	 */
	st = zuluCryptEXEOpenVolume( &opts,mapping_name,uid ) ;

	StringDelete( &str ) ;

	StringFree( opts.env ) ;

	StringFree( path ) ;

	return st ;
}
예제 #12
0
void zuluCryptPrintPartitionProperties( const char * device )
{
	#define SIZE 64
	char buffer[ SIZE ] ;

	const char * e ;
	u_int64_t size ;
	blkid_probe blkid ;

	zuluCryptSecurityGainElevatedPrivileges() ;

	if( StringPrefixEqual( device,"/dev/loop" ) ){
		/*
		 * zuluCryptLoopDeviceAddress_1() is defined in ../lib/create_loop_device.c
		 */
		e = zuluCryptLoopDeviceAddress_1( device ) ;
		if( e != NULL ){
			printf( "%s\t",e ) ;
			StringFree( e ) ;
		}else{
			printf( "%s\t",device ) ;
		}
	}else{
		printf( "%s\t",device ) ;
	}

	size = zuluCryptGetVolumeSize( device ) ;

	blkid = blkid_new_probe_from_filename( device ) ;

	if( blkid == NULL ){
		printf( "Nil\tNil\tNil\tNil\n" ) ;
	}else{
		/*
		 * zuluCryptFormatSize() is defined in ../lib/status.c
		 */
		zuluCryptFormatSize( size,buffer,SIZE ) ;

		printf( "%s\t",buffer ) ;

		blkid_do_probe( blkid ) ;

		if( blkid_probe_lookup_value( blkid,"LABEL",&e,NULL ) == 0 ){
			printf( "%s\t",e ) ;
		}else{
			printf( "Nil\t" ) ;
		}
		if( blkid_probe_lookup_value( blkid,"TYPE",&e,NULL ) == 0 ){
			printf( "%s\t",e ) ;
		}else{
			printf( "Nil\t" ) ;
		}
		if( blkid_probe_lookup_value( blkid,"UUID",&e,NULL ) == 0 ){
			printf( "%s\n",e ) ;
		}else{
			printf( "Nil\n" ) ;
		}
		blkid_free_probe( blkid ) ;
	}

	zuluCryptSecurityDropElevatedPrivileges() ;
}
예제 #13
0
static stringList_t _zuluCryptVolumeList_0( int resolve_loop_devices )
{
	const char * device ;

	const char * e ;

	ssize_t index ;

	StringListIterator it ;
	StringListIterator end ;

	stringList_t stz   = StringListVoid ;
	stringList_t stl   = StringListVoid ;
	stringList_t stl_1 = StringListVoid ;

	string_t st = StringGetFromVirtualFile( "/proc/partitions" ) ;
	string_t st_1 = String( "/dev/" ) ;

	stl = StringListStringSplit( st,'\n' ) ;

	StringDelete( &st ) ;

	if( stl == StringListVoid ){
		return StringListVoid ;
	}

	StringListGetIterators( stl,&it,&end ) ;

	/*
	 * skip the first entry
	 */
	it++ ;

	zuluCryptSecurityGainElevatedPrivileges() ;

	while( it != end ){

		st = *it ;
		it++ ;

		index = StringLastIndexOfChar( st,' ' ) ;

		if( index != -1 ){

			e = StringContent( st ) + index + 1 ;
			device = StringAppendAt( st_1,5,e ) ;

			if( _supported_device( device ) ){

				if( StringPrefixEqual( device,"/dev/loop" ) ){
					/*
					 * zuluCryptLoopDeviceAddress_1() id defined in ../lib/create_loop_device.c
					 */
					e = zuluCryptLoopDeviceAddress_1( device ) ;

					if( StringListHasNoEntry( stz,e ) ){
						/*
						 * Here we only keep one loop device if the volume file has
						 * more than one loop device
						 */
						if( resolve_loop_devices ){
							stl_1 = StringListAppend( stl_1,e ) ;
						}else{
							stl_1 = StringListAppend( stl_1,device ) ;
						}
						stz = StringListAppend( stz,e ) ;
					}
					StringFree( e ) ;
				}else{
					stl_1 = StringListAppendIfAbsent( stl_1,device ) ;
				}
			}
		}
	}
	zuluCryptSecurityDropElevatedPrivileges() ;
	StringListMultipleDelete( &stl,&stz,NULL ) ;
	StringDelete( &st_1 ) ;
	return _zuluCryptAddLVMVolumes( _zuluCryptAddMDRAIDVolumes( _remove_root_devices( stl_1 ) ) ) ;
}