Beispiel #1
0
/*
 * An assumption is made here that the path is an LVM path if "path"
 * is in /dev/mapper/abc-def format and there exist a path at /dev/abc/def.
 *
 * Info in lvm path structures can be found here:
 * https://www.redhat.com/archives/linux-lvm/2014-January/msg00014.html
 */
string_t zuluCryptConvertIfPathIsLVM( const char * path )
{
	const char * e ;
	const char ** z ;

	struct stat st ;

	StringIterator a ;
	StringIterator b ;
	StringIterator c ;
	StringIterator d ;

	string_t q = String( path ) ;

	StringGetIterators( q,&c,&d ) ;

	for( c = c + 3 ; c < d ; c++ ){

		a = c - 2 ;
		b = c - 1 ;

		if( *a != '-' && *b == '-' && *c != '-' ){
			/*
			 * found a place with a single dash,replace the dash with a slash
			 */
			*b = '/' ;
			/*
			 * replace double dashes if present.
			 */
			z = StringPointer( q ) ;

			while( StringHasComponent( *z,"--" ) ){

				StringReplaceString( q,"--","-" ) ;
			}

			e = StringReplaceString( q,"/dev/mapper/","/dev/" ) ;

			if( stat( e,&st ) == 0 ){
				/*
				 * The path appear to be an LVM path since
				 * "/dev/mapper/ABC-DEF" input path has a corresponding
				 * "/dev/ABC/DEF" path
				 */
			}else{
				/*
				 * Not an LVM volume,replace the string to its original
				 */
				StringReplace( q,path ) ;
			}
			break ;
		}
	}

	return q ;
}
Beispiel #2
0
static const char * _remove_duplicates( string_t st )
{
	const char ** z = StringPointer( st ) ;
	while( StringHasComponent( *z,",," ) ){
		StringReplaceString( st,",,","," ) ;
	}
	if( StringEndsWithChar( st,',' ) ){
		return StringRemoveRight( st,1 ) ;
	}else{
		return StringContent( st ) ;
	}
}