@@ -498,20 +498,6 @@ static CONFIG: LazyLock<RwLock<GlobalConfig>> = LazyLock::new(|| {
498498 } )
499499} ) ;
500500
501- /// loads the default configuration if available
502- fn load_default_config ( gconf : & mut GlobalConfig ) {
503- let conf = match Config :: default_config ( ) {
504- Ok ( conf) => conf,
505- Err ( _) => Config :: new ( ) ,
506- } ;
507-
508- /* if there is no config file or the configuration is malformed,
509- * sets an empty config, an error will be returned later at
510- * fn_initialize() time */
511- gconf. conf = conf;
512- gconf. conf . load_env_vars_overrides ( ) ;
513- }
514-
515501/// tests helper
516502#[ cfg( test) ]
517503pub fn add_slot ( slot : config:: Slot ) -> CK_RV {
@@ -527,14 +513,14 @@ pub fn add_slot(slot: config::Slot) -> CK_RV {
527513/// Version 3.1 Specification: [https://docs.oasis-open.org/pkcs11/pkcs11-spec/v3.1/os/pkcs11-spec-v3.1-os.html#_Toc111203255](https://docs.oasis-open.org/pkcs11/pkcs11-spec/v3.1/os/pkcs11-spec-v3.1-os.html#_Toc111203255)
528514
529515extern "C" fn fn_initialize ( _init_args : CK_VOID_PTR ) -> CK_RV {
516+ eprintln ! ( "Initialize" ) ;
530517 let mut gconf = global_wlock ! ( noinitcheck; ( * CONFIG ) ) ;
531-
532- if gconf. conf . slots . is_empty ( ) {
533- load_default_config ( & mut gconf) ;
534- }
518+ eprintln ! ( "Got gconf" ) ;
535519
536520 let mut ret: CK_RV = CKR_OK ;
537521
522+ /* Before loading the default config see if there is a cutsom config
523+ * provided via reserved ag pointer */
538524 if !_init_args. is_null ( ) {
539525 let args = unsafe { * ( _init_args as * const CK_C_INITIALIZE_ARGS ) } ;
540526
@@ -549,6 +535,18 @@ extern "C" fn fn_initialize(_init_args: CK_VOID_PTR) -> CK_RV {
549535 }
550536 }
551537
538+ if gconf. conf . slots . is_empty ( ) {
539+ eprintln ! ( "Reading default conf" ) ;
540+ let conf = match Config :: default_config ( ) {
541+ Ok ( conf) => conf,
542+ Err ( _) => Config :: new ( ) ,
543+ } ;
544+ /* if there is no config file or the configuration is malformed,
545+ * sets an empty config, an Token initialization will fail later */
546+ }
547+
548+ gconf. conf . load_env_vars_overrides ( ) ;
549+
552550 let mut wstate = global_wlock ! ( noinitcheck; ( * STATE ) ) ;
553551 if wstate. is_initialized ( ) {
554552 ret = CKR_CRYPTOKI_ALREADY_INITIALIZED ;
@@ -615,8 +613,11 @@ fn set_fips_behavior(slot_id: CK_SLOT_ID, val: config::FipsBehavior) -> CK_RV {
615613/// Version 3.1 Specification: [https://docs.oasis-open.org/pkcs11/pkcs11-spec/v3.1/os/pkcs11-spec-v3.1-os.html#_Toc111203256](https://docs.oasis-open.org/pkcs11/pkcs11-spec/v3.1/os/pkcs11-spec-v3.1-os.html#_Toc111203256)
616614
617615extern "C" fn fn_finalize ( _reserved : CK_VOID_PTR ) -> CK_RV {
616+ eprintln ! ( "Finalize" ) ;
618617 let ret = global_wlock ! ( ( * STATE ) ) . finalize ( ) ;
618+ eprintln ! ( "Got gconf" ) ;
619619 let mut gconf = global_wlock ! ( noinitcheck; ( * CONFIG ) ) ;
620+ eprintln ! ( "Wiping conf" ) ;
620621 gconf. conf = Config :: new ( ) ;
621622 ret
622623}
0 commit comments