@@ -501,34 +501,39 @@ fn config_translate_keywords(
501
501
& config. agent . agent_data_path ,
502
502
keylime_dir,
503
503
DEFAULT_AGENT_DATA_PATH ,
504
+ false ,
504
505
) ;
505
506
506
507
let mut ima_ml_path = config_get_file_path (
507
508
"ima_ml_path" ,
508
509
& config. agent . ima_ml_path ,
509
510
root_path,
510
511
DEFAULT_IMA_ML_PATH ,
512
+ false ,
511
513
) ;
512
514
513
515
let mut measuredboot_ml_path = config_get_file_path (
514
516
"measuredboot_ml_path" ,
515
517
& config. agent . measuredboot_ml_path ,
516
518
root_path,
517
519
DEFAULT_MEASUREDBOOT_ML_PATH ,
520
+ false ,
518
521
) ;
519
522
520
523
let mut server_key = config_get_file_path (
521
524
"server_key" ,
522
525
& config. agent . server_key ,
523
526
keylime_dir,
524
527
DEFAULT_SERVER_KEY ,
528
+ false ,
525
529
) ;
526
530
527
531
let mut server_cert = config_get_file_path (
528
532
"server_cert" ,
529
533
& config. agent . server_cert ,
530
534
keylime_dir,
531
535
DEFAULT_SERVER_CERT ,
536
+ false ,
532
537
) ;
533
538
534
539
let trusted_client_ca: String =
@@ -540,6 +545,7 @@ fn config_translate_keywords(
540
545
t,
541
546
keylime_dir,
542
547
DEFAULT_TRUSTED_CLIENT_CA ,
548
+ false ,
543
549
)
544
550
} )
545
551
. collect :: < Vec < _ > > ( )
@@ -550,13 +556,15 @@ fn config_translate_keywords(
550
556
& config. agent . iak_cert ,
551
557
keylime_dir,
552
558
DEFAULT_IAK_CERT ,
559
+ true ,
553
560
) ;
554
561
555
562
let mut idevid_cert = config_get_file_path (
556
563
"idevid_cert" ,
557
564
& config. agent . idevid_cert ,
558
565
keylime_dir,
559
566
DEFAULT_IDEVID_CERT ,
567
+ true ,
560
568
) ;
561
569
562
570
let ek_handle = match config. agent . ek_handle . as_ref ( ) {
@@ -630,6 +638,7 @@ fn config_translate_keywords(
630
638
& config. agent . revocation_cert ,
631
639
keylime_dir,
632
640
& format ! ( "secure/unzipped/{DEFAULT_REVOCATION_CERT}" ) ,
641
+ false ,
633
642
) ;
634
643
635
644
Ok ( KeylimeConfig {
@@ -657,18 +666,23 @@ fn config_translate_keywords(
657
666
/// Expand a file path from the configuration file.
658
667
///
659
668
/// 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'
661
670
/// If the string is a relative path, return the path relative from the provided work_dir
662
671
/// If the string is an absolute path, return the path without change.
663
672
fn config_get_file_path (
664
673
option : & str ,
665
674
path : & str ,
666
675
work_dir : & Path ,
667
676
default : & str ,
677
+ leave_empty : bool ,
668
678
) -> String {
669
679
match path {
670
680
"default" => work_dir. join ( default) . display ( ) . to_string ( ) ,
671
681
"" => {
682
+ if leave_empty {
683
+ return "" . to_string ( ) ;
684
+ }
685
+
672
686
warn ! ( "Empty string provided in configuration option {option}, using default {default}" ) ;
673
687
work_dir. join ( default) . display ( ) . to_string ( )
674
688
}
@@ -1107,7 +1121,7 @@ mod tests {
1107
1121
1108
1122
let translated: Vec < String > = list
1109
1123
. iter ( )
1110
- . map ( |e| config_get_file_path ( "test" , e, workdir, default) )
1124
+ . map ( |e| config_get_file_path ( "test" , e, workdir, default, false ) )
1111
1125
. collect ( ) ;
1112
1126
1113
1127
assert_eq ! (
@@ -1122,5 +1136,13 @@ mod tests {
1122
1136
] ,
1123
1137
translated
1124
1138
) ;
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) ;
1125
1147
}
1126
1148
}
0 commit comments