Example #1
0
static stringList_t _eval_path( string_t path,stringList_t stl_1 )
{
	string_t st ;
	const char * e ;
	char * ac ;
	if( StringStartsWith( path,"/" ) ){
		/*
		 * zuluCryptResolvePath_1() is defined in resolve_paths.c
		 */
		st = zuluCryptResolvePath_1( StringContent( path ) ) ;

		if( st != StringVoid ){
			stl_1 = StringListAppendString_1( stl_1,&st ) ;
		}
	}else if( StringStartsWith( path,"UUID=" ) ){
		/*
		 * check above did not find '/' character and we are in this block assuming the line uses UUID
		 */
		e = StringRemoveString( path,"\"" ) ;
		/*
		 * zuluCryptEvaluateDeviceTags() is defined in path_access.c
		 */
		ac = zuluCryptEvaluateDeviceTags( "UUID",e + 5 ) ;
		if( ac != NULL ){
			stl_1 = StringListAppend( stl_1,ac ) ;
			StringFree( ac ) ;
		}
	}
	return stl_1 ;
}
static const char * _clean_loop_path( string_t xt )
{
	if( StringEndsWith( xt," (deleted)\n" ) ){

		return StringRemoveString( xt," (deleted)\n" ) ;

	}else if( StringEndsWith( xt,"\n" ) ){

		return StringRemoveRight( xt,1 ) ;
	}else{
		return StringContent( xt ) ;
	}
}
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 ;
}
Example #4
0
static void _get_file_system_options_from_config_file( const char * device,string_t st )
{
	char * f ;
	const char * e ;

	StringListIterator it  ;
	StringListIterator end ;

	string_t xt = StringGetFromFile( "/etc/zuluCrypt/fs_options" ) ;

	stringList_t stl = StringListStringSplit( xt,'\n' ) ;

	stringList_t stz ;

	StringDelete( &xt ) ;

	f = _get_uuid_from_device( device ) ;

	StringListGetIterators( stl,&it,&end ) ;

	while( it != end  ){
		e = StringRemoveString( *it,"\"" ) ;
		it++ ;
		if( StringPrefixMatch( e,"UUID=",5 ) ){
			if( StringPrefixEqual( e + 5,f ) ){
				stz = StringListSplit( e,' ' ) ;
				e = StringListContentAtSecondPlace( stz ) ;
				StringMultipleAppend( st,",",e,NULL ) ;
				StringListDelete( &stz ) ;
				break ;
			}
		}
	}

	StringListDelete( &stl ) ;
	StringFree( f ) ;
}
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 ;
}
Example #6
0
static string_t set_mount_options( m_struct * mst )
{
	/*
	 * zuluCryptGetMountOptionsFromFstab() is defined in parse_fstab.c
	 */
	string_t opt = zuluCryptGetMountOptionsFromFstab( mst->device,MOUNTOPTIONS,mst->uid ) ;

	int fsFamily = fs_family( mst->fs ) ;

	const char * f[] = { "nouser","users","user","defaults","noauto","auto","nodev","dev",
		"noexec","exec","nosuid","suid","bind","mandlock","move","noatime","nodiratime","remount","silent",
		"synchronous",NULL } ;

	const char ** z = f ;
	const char * e ;

	if( opt == StringVoid ){
		opt = String( "" ) ;
		StringAppend( opt,mst->fs_flags ) ;
	}else{
		if( StringContains( opt,"ro" ) ){
			mst->m_flags |= MS_RDONLY ;
		}
		StringMultipleAppend( opt,",",mst->fs_flags,END ) ;
	}

	_get_file_system_options_from_config_file( mst->device,opt ) ;

	if( fsFamily == 1 ){
		if( !StringContains( opt,"dmask=" ) ){
			StringAppend( opt,",dmask=0000" ) ;
		}
		if( !StringContains( opt,"umask=" ) ){
			StringAppend( opt,",umask=0000" ) ;
		}
		if( !StringContains( opt,"uid=" ) ){
			StringAppend( opt,",uid=" ) ;
			StringAppendInt( opt,mst->uid ) ;
		}
		if( !StringContains( opt,"gid=" ) ){
			StringAppend( opt,",gid=" ) ;
			StringAppendInt( opt,mst->uid ) ;
		}
		if( !StringContains( opt,"fmask=" ) ){
			StringAppend( opt,",fmask=0111" ) ;
		}
		if( StringsAreEqual( mst->fs,"vfat" ) ){
			if( !StringContains( opt,"flush" ) ){
				StringAppend( opt,",flush" ) ;
			}
			if( !StringContains( opt,"shortname=" ) ){
				StringAppend( opt,",shortname=mixed" ) ;
			}
		}
	}else if( fsFamily == 2 ){
		if( !StringContains( opt,"uid=" ) ){
			StringAppend( opt,",uid=" ) ;
			StringAppendInt( opt,mst->uid ) ;
		}
		if( !StringContains( opt,"gid=" ) ){
			StringAppend( opt,",gid=" ) ;
			StringAppendInt( opt,mst->uid ) ;
		}
	}else if( fsFamily == 3 ){
		mst->m_flags |= MS_RDONLY ;
	}else{
		/*
		 * ext file systems and raiserfs among others go here
		 * we dont set any options for them.
		 */
		;
	}

	/*
	 * remove mount options to leave only file system options
	 */
	while( 1 ){
		e = *z ;
		z++ ;
		if( e == NULL ){
			break ;
		}else{
			StringRemoveString( opt,e ) ;
		}
	}
	/*
	 * remove below two now because we are going to add them below,reason for removing them
	 * and readding them is because we want to make sure they are at the beginning of the string
	 */
	StringRemoveString( opt,"ro" ) ;
	StringRemoveString( opt,"rw" ) ;

	if( mst->m_flags & MS_RDONLY ){
		StringPrepend( opt,"ro," ) ;
	}else{
		StringPrepend( opt,"rw," ) ;
	}

	mst->opts = _remove_duplicates( opt ) ;
	return opt;
}