Skip to content

Commit dca1287

Browse files
committed
WIP
Signed-off-by: Simo Sorce <simo@redhat.com>
1 parent 7c173fc commit dca1287

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ jobs:
188188
export TEST_PKCS11_MODULE
189189
190190
#TEST
191-
cargo test -vv $OPTS --features "$FEATURES"
191+
cargo test -vv $OPTS --features "$FEATURES" -- --no-capture
192192
193193
- uses: actions/upload-artifact@v4
194194
if: failure()

src/lib.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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)]
517503
pub 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
529515
extern "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
617615
extern "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
}

src/token.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ impl Token {
164164
CKR_CRYPTOKI_NOT_INITIALIZED => {
165165
token.uninitialized_token_info();
166166
}
167+
CKR_TOKEN_NOT_PRESENT => {
168+
eprintln!("WHAT THE ... dbtype: {}, dbargs: {:?}", dbtype, &dbargs);
169+
}
167170
_ => return Err(err),
168171
},
169172
}

0 commit comments

Comments
 (0)