예제 #1
0
char * zuluCryptLoopDeviceAddress_1( const char * device )
{
	int fd ;
	char * path ;
	struct loop_info64 l_info ;

	string_t st = String_1( "/sys/block/",device + 5,"/loop/backing_file",NULL ) ;

	string_t xt = _StringGetFromVirtualFile( &st ) ;

	if( xt == StringVoid ){

		memset( &l_info,'\0',sizeof( struct loop_info64 ) ) ;

		fd = open( device,O_RDONLY ) ;

		ioctl( fd,LOOP_GET_STATUS64,&l_info ) ;

		path = zuluCryptRealPath( ( char * ) l_info.lo_file_name ) ;

		close( fd ) ;

		return path ;
	}else{
		StringRemoveRight( xt,1 ) ;
		return StringDeleteHandle( &xt ) ;
	}
}
예제 #2
0
static stringList_t _get_mount_entries( const char * device )
{
	/*
	 * zuluCryptGetMountEntry() is defined in mountinfo.c
	 */
	stringList_t stl = zuluCryptGetMoutedList() ;

	StringListIterator it ;
	StringListIterator end ;

	string_t st = String_1( device," ",NULL ) ;

	StringListGetIterators( stl,&it,&end ) ;

	while( it != end ){

		if( StringStartsWith_1( *it,st ) ){

			it++ ;
		}else{
			StringListRemoveAt_1( stl,it,&end ) ;
		}
	}

	StringDelete( &st ) ;

	return stl ;
}
예제 #3
0
string_t zuluCryptLoopDeviceAddress_2( const char * device )
{
	int fd ;
	char * path ;
	struct loop_info64 l_info ;

	string_t st = String_1( "/sys/block/",device + 5,"/loop/backing_file",NULL ) ;

	string_t xt = _StringGetFromVirtualFile( &st ) ;

	if( xt == StringVoid ){

		memset( &l_info,'\0',sizeof( struct loop_info64 ) ) ;

		fd = open( device,O_RDONLY ) ;

		ioctl( fd,LOOP_GET_STATUS64,&l_info ) ;

		path = zuluCryptRealPath( ( char * ) l_info.lo_file_name ) ;

		close( fd ) ;

		xt = StringInherit( &path ) ;
	}else{
		StringRemoveRight( xt,1 ) ;
	}
	/*
	 * zuluCryptEncodeMountEntry() is defined in mount_volume.c
	 */
	zuluCryptEncodeMountEntry( xt ) ;
	return xt ;
}
예제 #4
0
파일: status.c 프로젝트: DarkDare/zuluCrypt
char * zuluCryptGetUUIDFromMapper( const char * mapper )
{
	string_t uuid ;
	struct crypt_device * cd ;

	const char * id ;
	const char * e = " UUID:   \t\"Nil\"" ;

	char * f ;

	if( crypt_init_by_name( &cd,mapper ) < 0 ){

		uuid = String( e ) ;
	}else{
		id = crypt_get_uuid( cd ) ;

		if( id == NULL ){

			/*
			 * Either not a LUKS volume or a LUKS volume but with a detached header.
			 * consult udev to see if it can sort this volume out.
			 */

			f = _get_uuid_from_udev( mapper ) ;

			if( f == NULL ){

				uuid = String( e ) ;
			}else{
				uuid = String_1( " UUID:   \t\"",f,"\"",NULL ) ;
				StringFree( f ) ;
			}

		}else{
			uuid = String_1( " UUID:   \t\"",id,"\"",NULL ) ;
		}

		crypt_free( cd ) ;
	}

	return StringDeleteHandle( &uuid ) ;
}
예제 #5
0
파일: status.c 프로젝트: DarkDare/zuluCrypt
char * zuluCryptGetVolumeTypeFromMapperPath( const char * mapper )
{
	struct crypt_device * cd ;
	const char * type ;
	char * r ;
	string_t st ;

	if( StringPrefixNotEqual( mapper,crypt_get_dir() ) ){

		return StringCopy_2( "Nil" ) ;
	}

	if( crypt_init_by_name( &cd,mapper ) < 0 ){

		return StringCopy_2( "Nil" ) ;
	}

	type = crypt_get_type( cd ) ;

	if( type == NULL ){

		if( StringHasComponent( mapper,"veracrypt" ) ){

			r = StringCopy_2( "crypto_VCRYPT" ) ;

		}else if( StringHasComponent( mapper,"truecrypt" ) ){

			r = StringCopy_2( "crypto_TCRYPT" ) ;
		}else{
			r = _get_type_from_udev( mapper ) ;
		}
	}else{
		st = String_1( "crypto_",type,NULL ) ;
		r = StringDeleteHandle( &st ) ;
	}

	crypt_free( cd ) ;
	return r ;
}
예제 #6
0
string_t zuluCryptCreateKeyFile( const char * key,size_t key_len,const char * fileName )
{
	string_t st = StringVoid ;
	int fd ;
	const char * file ;

	struct stat statstr ;

	if( key == NULL || key_len == 0 || fileName == NULL ){
		return StringVoid ;
	}

	#define path_does_not_exist( x ) stat( x,&statstr ) != 0

	if( path_does_not_exist( "/run" ) ){
		mkdir( "/run",S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH | S_IROTH ) ;
		chown( "/run",0,0 ) ;
	}
	if( path_does_not_exist( "/run/zuluCrypt" ) ){
		mkdir( "/run/zuluCrypt",S_IRWXU ) ;
		chown( "/run/zuluCrypt",0,0 ) ;
	}

	st = String_1( "/run/zuluCrypt/",fileName,NULL ) ;
	file = StringAppendInt( st,syscall( SYS_gettid ) ) ;
	fd = open( file,O_WRONLY | O_CREAT,S_IRUSR | S_IWUSR | S_IRGRP |S_IROTH ) ;

	if( fd == -1 ){
		StringDelete( &st ) ;
	}else{
		write( fd,key,key_len ) ;
		close( fd ) ;
		chown( file,0,0 ) ;
		chmod( file,S_IRWXU ) ;
	}

	return st ;
}
예제 #7
0
stringList_t zuluCryptOpenedVolumesList( uid_t uid )
{
    const char * e ;
    const char * c ;
    const char * d ;
    const char * t ;

    char * f ;
    char * g ;

    StringListIterator it  ;
    StringListIterator end ;

    ssize_t k ;

    string_t q ;
    string_t z ;

    string_t j ;

    stringList_t stx ;
    stringList_t list = StringListVoid ;
    stringList_t stl = zuluCryptGetMoutedList() ;

    if( uid ) {
        ;
    }

    /*
     * zuluCryptMapperPrefix() is defined in create_mapper_name.c
     */
    j = String_1( zuluCryptMapperPrefix(),"/zuluCrypt-",NULL ) ;
    /*
     * t will probably contain "/dev/mapper/zuluCrypt-"
     */
    t = StringContent( j ) ;

    StringListGetIterators( stl,&it,&end ) ;

    while( it != end ) {

        c = StringContent( *it ) ;

        it++ ;

        if( StringPrefixNotEqual( c,t ) ) {

            /*
             * we only care about zuluCrypt volumes and these volumes that we care about starts with
             * "/dev/mapper/zuluCrypt-"
             */

            continue ;
        }
        if( StringHasComponent( c,"/run/media/public/" ) ) {

            /*
             * dont show mirror images due to bind mounts
             */

            continue ;
        }

        stx = StringListSplit( c,' ' ) ;

        e = StringListContentAtFirstPlace( stx ) ;

        k = StringHasComponent_1( e,"-UUID-" ) ;

        if( k != -1 ) {

            q = StringListStringAtFirstPlace( stx ) ;
            /*
             * zuluCryptDecodeMountEntry() is defined in mount_volume.c
             */
            d = zuluCryptDecodeMountEntry( StringListStringAtSecondPlace( stx ) ) ;

            /*
             * zuluCryptGetVolumeTypeFromMapperPath() is defined in status.c
             */
            f = zuluCryptGetVolumeTypeFromMapperPath( StringContent( q ) ) ;
            e = StringSubChar( q,StringLastIndexOfChar( q,'-' ),'\0' ) + k + 6 ;
            z = String_1( "UUID=\"",e,"\"\t",d,"\t",f,NULL ) ;
            list = StringListAppendString_1( list,&z ) ;
            StringFree( f ) ;
        } else {
            /*
             * zuluCryptVolumeDeviceName() is defined in status.c
             */
            g = zuluCryptVolumeDeviceName( e ) ;

            if( g != NULL ) {

                d = zuluCryptDecodeMountEntry( StringListStringAtSecondPlace( stx ) ) ;
                /*
                 * zuluCryptGetVolumeTypeFromMapperPath() is defined in status.c
                 */
                f = zuluCryptGetVolumeTypeFromMapperPath( StringListContentAtFirstPlace( stx ) ) ;
                z = String_1( g,"\t",d,"\t",f,NULL ) ;
                list = StringListAppendString_1( list,&z ) ;
                StringFree( f ) ;
                StringFree( g ) ;
            }
        }

        StringListDelete( &stx ) ;
    }
    StringListDelete( &stl ) ;
    StringDelete( &j ) ;
    return list ;
}
예제 #8
0
int zuluCryptPartitionIsMounted( const char * path )
{
    return _mounted( StringListHasStartSequence,String_1( path," ",NULL ) ) ;
}
예제 #9
0
int zuluCryptMountPointIsActive( const char * m_point )
{
    return _mounted( StringListHasSequence,String_1( " ",m_point," ",NULL ) ) ;
}