@@ -501,34 +501,39 @@ fn config_translate_keywords(
501501 & config. agent . agent_data_path ,
502502 keylime_dir,
503503 DEFAULT_AGENT_DATA_PATH ,
504+ false ,
504505 ) ;
505506
506507 let mut ima_ml_path = config_get_file_path (
507508 "ima_ml_path" ,
508509 & config. agent . ima_ml_path ,
509510 root_path,
510511 DEFAULT_IMA_ML_PATH ,
512+ false ,
511513 ) ;
512514
513515 let mut measuredboot_ml_path = config_get_file_path (
514516 "measuredboot_ml_path" ,
515517 & config. agent . measuredboot_ml_path ,
516518 root_path,
517519 DEFAULT_MEASUREDBOOT_ML_PATH ,
520+ false ,
518521 ) ;
519522
520523 let mut server_key = config_get_file_path (
521524 "server_key" ,
522525 & config. agent . server_key ,
523526 keylime_dir,
524527 DEFAULT_SERVER_KEY ,
528+ false ,
525529 ) ;
526530
527531 let mut server_cert = config_get_file_path (
528532 "server_cert" ,
529533 & config. agent . server_cert ,
530534 keylime_dir,
531535 DEFAULT_SERVER_CERT ,
536+ false ,
532537 ) ;
533538
534539 let trusted_client_ca: String =
@@ -540,6 +545,7 @@ fn config_translate_keywords(
540545 t,
541546 keylime_dir,
542547 DEFAULT_TRUSTED_CLIENT_CA ,
548+ false ,
543549 )
544550 } )
545551 . collect :: < Vec < _ > > ( )
@@ -550,13 +556,15 @@ fn config_translate_keywords(
550556 & config. agent . iak_cert ,
551557 keylime_dir,
552558 DEFAULT_IAK_CERT ,
559+ true ,
553560 ) ;
554561
555562 let mut idevid_cert = config_get_file_path (
556563 "idevid_cert" ,
557564 & config. agent . idevid_cert ,
558565 keylime_dir,
559566 DEFAULT_IDEVID_CERT ,
567+ true ,
560568 ) ;
561569
562570 let ek_handle = match config. agent . ek_handle . as_ref ( ) {
@@ -630,6 +638,7 @@ fn config_translate_keywords(
630638 & config. agent . revocation_cert ,
631639 keylime_dir,
632640 & format ! ( "secure/unzipped/{DEFAULT_REVOCATION_CERT}" ) ,
641+ false ,
633642 ) ;
634643
635644 Ok ( KeylimeConfig {
@@ -657,18 +666,23 @@ fn config_translate_keywords(
657666/// Expand a file path from the configuration file.
658667///
659668/// If the string is set as "default", return the provided default path relative from the provided work_dir.
660- /// If the string is empty, use again the default value
669+ /// If the string is empty, use the default value unless the 'leave_empty' is 'true'
661670/// If the string is a relative path, return the path relative from the provided work_dir
662671/// If the string is an absolute path, return the path without change.
663672fn config_get_file_path (
664673 option : & str ,
665674 path : & str ,
666675 work_dir : & Path ,
667676 default : & str ,
677+ leave_empty : bool ,
668678) -> String {
669679 match path {
670680 "default" => work_dir. join ( default) . display ( ) . to_string ( ) ,
671681 "" => {
682+ if leave_empty {
683+ return "" . to_string ( ) ;
684+ }
685+
672686 warn ! ( "Empty string provided in configuration option {option}, using default {default}" ) ;
673687 work_dir. join ( default) . display ( ) . to_string ( )
674688 }
@@ -1107,7 +1121,7 @@ mod tests {
11071121
11081122 let translated: Vec < String > = list
11091123 . iter ( )
1110- . map ( |e| config_get_file_path ( "test" , e, workdir, default) )
1124+ . map ( |e| config_get_file_path ( "test" , e, workdir, default, false ) )
11111125 . collect ( ) ;
11121126
11131127 assert_eq ! (
@@ -1122,5 +1136,13 @@ mod tests {
11221136 ] ,
11231137 translated
11241138 ) ;
1139+
1140+ let translated =
1141+ config_get_file_path ( "test" , "" , workdir, "default" , true ) ;
1142+ assert_eq ! ( "" , translated) ;
1143+
1144+ let translated =
1145+ config_get_file_path ( "test" , "" , workdir, "default" , false ) ;
1146+ assert_eq ! ( "/workdir/default" , translated) ;
11251147 }
11261148}
0 commit comments