OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 /* | 4 /* |
5 * The following code handles the storage of PKCS 11 modules used by the | 5 * The following code handles the storage of PKCS 11 modules used by the |
6 * NSS. For the rest of NSS, only one kind of database handle exists: | 6 * NSS. For the rest of NSS, only one kind of database handle exists: |
7 * | 7 * |
8 * SFTKDBHandle | 8 * SFTKDBHandle |
9 * | 9 * |
10 * There is one SFTKDBHandle for the each key database and one for each cert | 10 * There is one SFTKDBHandle for the each key database and one for each cert |
11 * database. These databases are opened as associated pairs, one pair per | 11 * database. These databases are opened as associated pairs, one pair per |
12 * slot. SFTKDBHandles are reference counted objects. | 12 * slot. SFTKDBHandles are reference counted objects. |
13 * | 13 * |
14 * Each SFTKDBHandle points to a low level database handle (SDB). This handle | 14 * Each SFTKDBHandle points to a low level database handle (SDB). This handle |
15 * represents the underlying physical database. These objects are not | 15 * represents the underlying physical database. These objects are not |
16 * reference counted, an are 'owned' by their respective SFTKDBHandles. | 16 * reference counted, an are 'owned' by their respective SFTKDBHandles. |
17 * | 17 * |
18 * | 18 * |
19 */ | 19 */ |
20 #include "sftkdb.h" | 20 #include "sftkdb.h" |
21 #include "sftkdbti.h" | 21 #include "sftkdbti.h" |
22 #include "pkcs11t.h" | 22 #include "pkcs11t.h" |
23 #include "pkcs11i.h" | 23 #include "pkcs11i.h" |
24 #include "sdb.h" | 24 #include "sdb.h" |
25 #include "prprf.h" | 25 #include "prprf.h" |
26 #include "secmodt.h" | |
27 #include "pratom.h" | 26 #include "pratom.h" |
28 #include "lgglue.h" | 27 #include "lgglue.h" |
29 #include "sftkpars.h" | 28 #include "utilpars.h" |
30 #include "secerr.h" | 29 #include "secerr.h" |
31 #include "softoken.h" | 30 #include "softoken.h" |
32 | 31 |
33 /* | 32 /* |
34 * We want all databases to have the same binary representation independent of | 33 * We want all databases to have the same binary representation independent of |
35 * endianness or length of the host architecture. In general PKCS #11 attributes | 34 * endianness or length of the host architecture. In general PKCS #11 attributes |
36 * are endian/length independent except those attributes that pass CK_ULONG. | 35 * are endian/length independent except those attributes that pass CK_ULONG. |
37 * | 36 * |
38 * The following functions fixes up the CK_ULONG type attributes so that the dat
a | 37 * The following functions fixes up the CK_ULONG type attributes so that the dat
a |
39 * base sees a machine independent view. CK_ULONGs are stored as 4 byte network | 38 * base sees a machine independent view. CK_ULONGs are stored as 4 byte network |
(...skipping 2528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2568 */ | 2567 */ |
2569 CK_RV | 2568 CK_RV |
2570 sftk_DBInit(const char *configdir, const char *certPrefix, | 2569 sftk_DBInit(const char *configdir, const char *certPrefix, |
2571 const char *keyPrefix, const char *updatedir, | 2570 const char *keyPrefix, const char *updatedir, |
2572 const char *updCertPrefix, const char *updKeyPrefix, | 2571 const char *updCertPrefix, const char *updKeyPrefix, |
2573 const char *updateID, PRBool readOnly, PRBool noCertDB, | 2572 const char *updateID, PRBool readOnly, PRBool noCertDB, |
2574 PRBool noKeyDB, PRBool forceOpen, PRBool isFIPS, | 2573 PRBool noKeyDB, PRBool forceOpen, PRBool isFIPS, |
2575 SFTKDBHandle **certDB, SFTKDBHandle **keyDB) | 2574 SFTKDBHandle **certDB, SFTKDBHandle **keyDB) |
2576 { | 2575 { |
2577 const char *confdir; | 2576 const char *confdir; |
2578 SDBType dbType; | 2577 NSSDBType dbType = NSS_DB_TYPE_NONE; |
2579 char *appName = NULL; | 2578 char *appName = NULL; |
2580 SDB *keySDB, *certSDB; | 2579 SDB *keySDB, *certSDB; |
2581 CK_RV crv = CKR_OK; | 2580 CK_RV crv = CKR_OK; |
2582 int flags = SDB_RDONLY; | 2581 int flags = SDB_RDONLY; |
2583 PRBool newInit = PR_FALSE; | 2582 PRBool newInit = PR_FALSE; |
2584 PRBool needUpdate = PR_FALSE; | 2583 PRBool needUpdate = PR_FALSE; |
2585 | 2584 |
2586 if (!readOnly) { | 2585 if (!readOnly) { |
2587 flags = SDB_CREATE; | 2586 flags = SDB_CREATE; |
2588 } | 2587 } |
2589 | 2588 |
2590 *certDB = NULL; | 2589 *certDB = NULL; |
2591 *keyDB = NULL; | 2590 *keyDB = NULL; |
2592 | 2591 |
2593 if (noKeyDB && noCertDB) { | 2592 if (noKeyDB && noCertDB) { |
2594 return CKR_OK; | 2593 return CKR_OK; |
2595 } | 2594 } |
2596 confdir = sftk_EvaluateConfigDir(configdir, &dbType, &appName); | 2595 confdir = _NSSUTIL_EvaluateConfigDir(configdir, &dbType, &appName); |
2597 | 2596 |
2598 /* | 2597 /* |
2599 * now initialize the appropriate database | 2598 * now initialize the appropriate database |
2600 */ | 2599 */ |
2601 switch (dbType) { | 2600 switch (dbType) { |
2602 case SDB_LEGACY: | 2601 case NSS_DB_TYPE_LEGACY: |
2603 crv = sftkdbCall_open(confdir, certPrefix, keyPrefix, 8, 3, flags, | 2602 crv = sftkdbCall_open(confdir, certPrefix, keyPrefix, 8, 3, flags, |
2604 isFIPS, noCertDB? NULL : &certSDB, noKeyDB ? NULL: &keySDB); | 2603 isFIPS, noCertDB? NULL : &certSDB, noKeyDB ? NULL: &keySDB); |
2605 break; | 2604 break; |
2606 case SDB_MULTIACCESS: | 2605 case NSS_DB_TYPE_MULTIACCESS: |
2607 crv = sftkdbCall_open(configdir, certPrefix, keyPrefix, 8, 3, flags, | 2606 crv = sftkdbCall_open(configdir, certPrefix, keyPrefix, 8, 3, flags, |
2608 isFIPS, noCertDB? NULL : &certSDB, noKeyDB ? NULL: &keySDB); | 2607 isFIPS, noCertDB? NULL : &certSDB, noKeyDB ? NULL: &keySDB); |
2609 break; | 2608 break; |
2610 case SDB_SQL: | 2609 case NSS_DB_TYPE_SQL: |
2611 case SDB_EXTERN: /* SHOULD open a loadable db */ | 2610 case NSS_DB_TYPE_EXTERN: /* SHOULD open a loadable db */ |
2612 crv = s_open(confdir, certPrefix, keyPrefix, 9, 4, flags, | 2611 crv = s_open(confdir, certPrefix, keyPrefix, 9, 4, flags, |
2613 noCertDB? NULL : &certSDB, noKeyDB ? NULL : &keySDB, &newInit); | 2612 noCertDB? NULL : &certSDB, noKeyDB ? NULL : &keySDB, &newInit); |
2614 | 2613 |
2615 /* | 2614 /* |
2616 * if we failed to open the DB's read only, use the old ones if | 2615 * if we failed to open the DB's read only, use the old ones if |
2617 * the exists. | 2616 * the exists. |
2618 */ | 2617 */ |
2619 if (crv != CKR_OK) { | 2618 if (crv != CKR_OK) { |
2620 if ((flags == SDB_RDONLY) && | 2619 if ((flags == SDB_RDONLY) && |
2621 sftk_hasLegacyDB(confdir, certPrefix, keyPrefix, 8, 3)) { | 2620 sftk_hasLegacyDB(confdir, certPrefix, keyPrefix, 8, 3)) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2729 } | 2728 } |
2730 | 2729 |
2731 CK_RV | 2730 CK_RV |
2732 sftkdb_Shutdown(void) | 2731 sftkdb_Shutdown(void) |
2733 { | 2732 { |
2734 s_shutdown(); | 2733 s_shutdown(); |
2735 sftkdbCall_Shutdown(); | 2734 sftkdbCall_Shutdown(); |
2736 return CKR_OK; | 2735 return CKR_OK; |
2737 } | 2736 } |
2738 | 2737 |
OLD | NEW |