Пример #1
0
static int _check_if_device_is_supported( int st,uid_t uid,char ** dev )
{
	string_t fs ;
	if( st == 0 ){
		seteuid( 0 ) ;
		/*
		* zuluCryptGetFileSystemFromDevice() is defined in mount_volume.c
		*/
		fs = zuluCryptGetFileSystemFromDevice( *dev ) ;
		seteuid( uid ) ;
		if( fs != StringVoid ){
			if( StringHasAtLeastOneComponent( fs,"member","swap",NULL ) ){
				st = 100 ;
			}
			StringDelete( &fs ) ;
		}
	}else{
		/*
		 * safely do free( *dev ) followed by *dev = NULL
		 */
		StringFree_1( dev ) ;
	}

	return st ;
}
Пример #2
0
int zuluCryptMountVolume( const char * path,const char * m_point,unsigned long mount_opts,const char * fs_opts,uid_t uid )
{
	int h ;

	string_t opts = StringVoid ;
	string_t fs   = StringVoid ;
	string_t loop = StringVoid ;

	int fd = -1 ;

	m_struct mst ;
	mst.device = path ;
	mst.m_point = m_point ;
	mst.uid = uid ;
	mst.m_flags = mount_opts ;

	/*
	 * zuluCryptGetFileSystemFromDevice() is defined in this source file
	 */
	fs = zuluCryptGetFileSystemFromDevice( path ) ;

	if( fs == StringVoid ){
		/*
		 * failed to read file system,probably because the volume does have any or
		 * a plain volume was opened with a wrong key
		 */
		return zuluExit( 4,fd,opts,fs,loop ) ;
	}

	if( StringStartsWith( fs,"crypto" ) ){
		/*
		 * we cant mount an encrypted volume, exiting
		 */
		return zuluExit( 4,fd,opts,fs,loop ) ;
	}

	/*
	 * zuluCryptMountHasNotAllowedFileSystemOptions() is defined in ./mount_fs_options.c
	 */
	if( zuluCryptMountHasNotAllowedFileSystemOptions( uid,fs_opts,fs ) ){
		return zuluExit( -1,fd,opts,fs,loop ) ;
	}

	mst.fs_flags = fs_opts ;
	mst.fs = StringContent( fs ) ;
	opts = set_mount_options( &mst ) ;

	if( StringPrefixNotEqual( path,"/dev/" ) ){
		/*
		 * zuluCryptAttachLoopDeviceToFile() is defined in ./create_loop_device.c
		 */
		if( zuluCryptAttachLoopDeviceToFile( mst.device,O_RDWR,&fd,&loop ) ){
			mst.device = StringContent( loop ) ;
		}else{
			return zuluExit( -1,fd,opts,fs,loop ) ;
		}
	}

	if( zuluCryptFileSystemIsFUSEbased( path ) ){
		/*
		 * These file systems dont see to work with mount() command for some reason.
		 * Them being FUSE based could be a reason.
		 */
		switch( mount_FUSEfs( &mst ) ){
			case 0  : return zuluExit( 0,fd,opts,fs,loop )  ;
			case 16 : return zuluExit( 12,fd,opts,fs,loop ) ;
			default : return zuluExit( 1,fd,opts,fs,loop )  ;
		}
	}else{
		h = mount_volume( &mst ) ;
	}

	return zuluExit( h,fd,opts,fs,loop ) ;
}