Mercurial > trustbridge > nss-cmake-static
annotate nss/lib/softoken/legacydb/lginit.c @ 4:b513267f632f tip
Build DBM module
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 05 Aug 2014 18:58:03 +0200 |
parents | 150b72113545 |
children |
rev | line source |
---|---|
3
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1 /* |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
2 * NSS utility functions |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
3 * |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
4 * This Source Code Form is subject to the terms of the Mozilla Public |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
7 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 #include "lowkeyi.h" |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
9 #include "pcert.h" |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
10 #include "keydbi.h" |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
11 #include "lgdb.h" |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
12 #include "secoid.h" |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
13 #include "prenv.h" |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
14 #include "softkver.h" |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
15 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
16 /* Library identity and versioning */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
17 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 #if defined(DEBUG) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
19 #define _DEBUG_STRING " (debug)" |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
20 #else |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
21 #define _DEBUG_STRING "" |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
22 #endif |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
23 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
24 /* |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
25 * Version information for the 'ident' and 'what commands |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 * |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
27 * NOTE: the first component of the concatenated rcsid string |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
28 * must not end in a '$' to prevent rcs keyword substitution. |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
29 */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
30 const char __nss_dbm_rcsid[] = "$Header: NSS " SOFTOKEN_VERSION _DEBUG_STRING |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
31 " " __DATE__ " " __TIME__ " $"; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
32 const char __nss_dbm_sccsid[] = "@(#)NSS " SOFTOKEN_VERSION _DEBUG_STRING |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
33 " " __DATE__ " " __TIME__; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
34 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
35 typedef struct LGPrivateStr { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
36 NSSLOWCERTCertDBHandle *certDB; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
37 NSSLOWKEYDBHandle *keyDB; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
38 PRLock *dbLock; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
39 PLHashTable *hashTable; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
40 } LGPrivate; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
41 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
42 static char * |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
43 lg_certdb_name_cb(void *arg, int dbVersion) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
44 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
45 const char *configdir = (const char *)arg; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
46 const char *dbver; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
47 char *smpname = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
48 char *dbname = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
49 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
50 switch (dbVersion) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
51 case 8: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
52 dbver = "8"; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
53 break; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
54 case 7: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
55 dbver = "7"; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
56 break; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
57 case 6: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
58 dbver = "6"; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
59 break; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
60 case 5: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
61 dbver = "5"; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
62 break; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
63 case 4: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
64 default: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
65 dbver = ""; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
66 break; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
67 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
68 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
69 /* make sure we return something allocated with PORT_ so we have properly |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
70 * matched frees at the end */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
71 smpname = PR_smprintf(CERT_DB_FMT, configdir, dbver); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
72 if (smpname) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
73 dbname = PORT_Strdup(smpname); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
74 PR_smprintf_free(smpname); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
75 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
76 return dbname; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
77 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
78 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
79 static char * |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
80 lg_keydb_name_cb(void *arg, int dbVersion) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
81 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
82 const char *configdir = (const char *)arg; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
83 const char *dbver; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
84 char *smpname = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
85 char *dbname = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
86 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
87 switch (dbVersion) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
88 case 4: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
89 dbver = "4"; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
90 break; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
91 case 3: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
92 dbver = "3"; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
93 break; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
94 case 1: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
95 dbver = "1"; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
96 break; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
97 case 2: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
98 default: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
99 dbver = ""; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
100 break; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
101 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
102 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
103 smpname = PR_smprintf(KEY_DB_FMT, configdir, dbver); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
104 if (smpname) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
105 dbname = PORT_Strdup(smpname); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
106 PR_smprintf_free(smpname); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
107 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
108 return dbname; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
109 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
110 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
111 const char * |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
112 lg_EvaluateConfigDir(const char *configdir,char **appName) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
113 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
114 if (PORT_Strncmp(configdir, MULTIACCESS, sizeof(MULTIACCESS)-1) == 0) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
115 char *cdir; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
116 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
117 *appName = PORT_Strdup(configdir+sizeof(MULTIACCESS)-1); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
118 if (*appName == NULL) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
119 return configdir; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
120 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
121 cdir = *appName; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
122 while (*cdir && *cdir != ':') { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
123 cdir++; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
124 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
125 if (*cdir == ':') { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
126 *cdir = 0; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
127 cdir++; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
128 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
129 configdir = cdir; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
130 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
131 return configdir; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
132 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
133 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
134 static int rdbmapflags(int flags); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
135 static rdbfunc lg_rdbfunc = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
136 static rdbstatusfunc lg_rdbstatusfunc = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
137 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
138 /* NOTE: SHLIB_SUFFIX is defined on the command line */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
139 #define RDBLIB SHLIB_PREFIX"rdb."SHLIB_SUFFIX |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
140 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
141 DB * rdbopen(const char *appName, const char *prefix, |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
142 const char *type, int flags, int *status) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
143 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
144 PRLibrary *lib; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
145 DB *db; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
146 char *disableUnload = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
147 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
148 if (lg_rdbfunc) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
149 db = (*lg_rdbfunc)(appName,prefix,type,rdbmapflags(flags)); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
150 if (!db && status && lg_rdbstatusfunc) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
151 *status = (*lg_rdbstatusfunc)(); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
152 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
153 return db; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
154 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
155 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
156 /* |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
157 * try to open the library. |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
158 */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
159 lib = PR_LoadLibrary(RDBLIB); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
160 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
161 if (!lib) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
162 return NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
163 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
164 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
165 /* get the entry points */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
166 lg_rdbstatusfunc = (rdbstatusfunc) PR_FindSymbol(lib,"rdbstatus"); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
167 lg_rdbfunc = (rdbfunc) PR_FindSymbol(lib,"rdbopen"); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
168 if (lg_rdbfunc) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
169 db = (*lg_rdbfunc)(appName,prefix,type,rdbmapflags(flags)); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
170 if (!db && status && lg_rdbstatusfunc) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
171 *status = (*lg_rdbstatusfunc)(); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
172 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
173 return db; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
174 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
175 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
176 /* couldn't find the entry point, unload the library and fail */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
177 disableUnload = PR_GetEnv("NSS_DISABLE_UNLOAD"); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
178 if (!disableUnload) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
179 PR_UnloadLibrary(lib); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
180 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
181 return NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
182 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
183 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
184 /* |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
185 * the following data structures are from rdb.h. |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
186 */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
187 struct RDBStr { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
188 DB db; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
189 int (*xactstart)(DB *db); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
190 int (*xactdone)(DB *db, PRBool abort); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
191 int version; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
192 int (*dbinitcomplete)(DB *db); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
193 }; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
194 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
195 #define DB_RDB ((DBTYPE) 0xff) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
196 #define RDB_RDONLY 1 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
197 #define RDB_RDWR 2 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
198 #define RDB_CREATE 4 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
199 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
200 static int |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
201 rdbmapflags(int flags) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
202 switch (flags) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
203 case NO_RDONLY: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
204 return RDB_RDONLY; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
205 case NO_RDWR: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
206 return RDB_RDWR; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
207 case NO_CREATE: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
208 return RDB_CREATE; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
209 default: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
210 break; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
211 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
212 return 0; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
213 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
214 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
215 PRBool |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
216 db_IsRDB(DB *db) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
217 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
218 return (PRBool) db->type == DB_RDB; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
219 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
220 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
221 int |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
222 db_BeginTransaction(DB *db) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
223 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
224 struct RDBStr *rdb = (struct RDBStr *)db; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
225 if (db->type != DB_RDB) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
226 return 0; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
227 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
228 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
229 return rdb->xactstart(db); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
230 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
231 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
232 int |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
233 db_FinishTransaction(DB *db, PRBool abort) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
234 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
235 struct RDBStr *rdb = (struct RDBStr *)db; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
236 if (db->type != DB_RDB) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
237 return 0; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
238 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
239 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
240 return rdb->xactdone(db, abort); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
241 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
242 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
243 static DB * |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
244 lg_getRawDB(SDB *sdb) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
245 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
246 NSSLOWCERTCertDBHandle *certDB; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
247 NSSLOWKEYDBHandle *keyDB; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
248 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
249 certDB = lg_getCertDB(sdb); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
250 if (certDB) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
251 return certDB->permCertDB; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
252 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
253 keyDB = lg_getKeyDB(sdb); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
254 if (keyDB) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
255 return keyDB->db; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
256 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
257 return NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
258 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
259 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
260 CK_RV |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
261 lg_Begin(SDB *sdb) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
262 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
263 DB *db = lg_getRawDB(sdb); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
264 int ret; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
265 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
266 if (db == NULL) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
267 return CKR_GENERAL_ERROR; /* shouldn't happen */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
268 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
269 ret = db_BeginTransaction(db); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
270 if (ret != 0) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
271 return CKR_GENERAL_ERROR; /* could happen */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
272 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
273 return CKR_OK; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
274 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
275 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
276 CK_RV |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
277 lg_Commit(SDB *sdb) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
278 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
279 DB *db = lg_getRawDB(sdb); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
280 int ret; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
281 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
282 if (db == NULL) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
283 return CKR_GENERAL_ERROR; /* shouldn't happen */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
284 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
285 ret = db_FinishTransaction(db, PR_FALSE); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
286 if (ret != 0) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
287 return CKR_GENERAL_ERROR; /* could happen */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
288 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
289 return CKR_OK; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
290 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
291 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
292 CK_RV |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
293 lg_Abort(SDB *sdb) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
294 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
295 DB *db = lg_getRawDB(sdb); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
296 int ret; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
297 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
298 if (db == NULL) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
299 return CKR_GENERAL_ERROR; /* shouldn't happen */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
300 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
301 ret = db_FinishTransaction(db, PR_TRUE); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
302 if (ret != 0) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
303 return CKR_GENERAL_ERROR; /* could happen */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
304 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
305 return CKR_OK; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
306 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
307 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
308 int |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
309 db_InitComplete(DB *db) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
310 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
311 struct RDBStr *rdb = (struct RDBStr *)db; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
312 if (db->type != DB_RDB) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
313 return 0; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
314 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
315 /* we should have added a version number to the RDBS structure. Since we |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
316 * didn't, we detect that we have and 'extended' structure if the rdbstatus |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
317 * func exists */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
318 if (!lg_rdbstatusfunc) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
319 return 0; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
320 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
321 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
322 return rdb->dbinitcomplete(db); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
323 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
324 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
325 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
326 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
327 SECStatus |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
328 db_Copy(DB *dest,DB *src) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
329 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
330 int ret; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
331 DBT key,data; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
332 ret = (*src->seq)(src, &key, &data, R_FIRST); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
333 if (ret) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
334 return SECSuccess; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
335 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
336 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
337 do { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
338 (void)(*dest->put)(dest,&key,&data, R_NOOVERWRITE); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
339 } while ( (*src->seq)(src, &key, &data, R_NEXT) == 0); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
340 (void)(*dest->sync)(dest,0); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
341 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
342 return SECSuccess; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
343 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
344 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
345 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
346 static CK_RV |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
347 lg_OpenCertDB(const char * configdir, const char *prefix, PRBool readOnly, |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
348 NSSLOWCERTCertDBHandle **certdbPtr) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
349 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
350 NSSLOWCERTCertDBHandle *certdb = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
351 CK_RV crv = CKR_NETSCAPE_CERTDB_FAILED; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
352 SECStatus rv; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
353 char * name = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
354 char * appName = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
355 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
356 if (prefix == NULL) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
357 prefix = ""; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
358 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
359 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
360 configdir = lg_EvaluateConfigDir(configdir, &appName); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
361 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
362 name = PR_smprintf("%s" PATH_SEPARATOR "%s",configdir,prefix); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
363 if (name == NULL) goto loser; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
364 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
365 certdb = (NSSLOWCERTCertDBHandle*)PORT_ZAlloc(sizeof(NSSLOWCERTCertDBHandle)); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
366 if (certdb == NULL) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
367 goto loser; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
368 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
369 certdb->ref = 1; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
370 /* fix when we get the DB in */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
371 rv = nsslowcert_OpenCertDB(certdb, readOnly, appName, prefix, |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
372 lg_certdb_name_cb, (void *)name, PR_FALSE); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
373 if (rv == SECSuccess) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
374 crv = CKR_OK; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
375 *certdbPtr = certdb; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
376 certdb = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
377 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
378 loser: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
379 if (certdb) PR_Free(certdb); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
380 if (name) PR_smprintf_free(name); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
381 if (appName) PORT_Free(appName); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
382 return crv; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
383 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
384 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
385 static CK_RV |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
386 lg_OpenKeyDB(const char * configdir, const char *prefix, PRBool readOnly, |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
387 NSSLOWKEYDBHandle **keydbPtr) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
388 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
389 NSSLOWKEYDBHandle *keydb; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
390 char * name = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
391 char * appName = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
392 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
393 if (prefix == NULL) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
394 prefix = ""; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
395 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
396 configdir = lg_EvaluateConfigDir(configdir, &appName); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
397 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
398 name = PR_smprintf("%s" PATH_SEPARATOR "%s",configdir,prefix); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
399 if (name == NULL) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
400 return CKR_HOST_MEMORY; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
401 keydb = nsslowkey_OpenKeyDB(readOnly, appName, prefix, |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
402 lg_keydb_name_cb, (void *)name); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
403 PR_smprintf_free(name); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
404 if (appName) PORT_Free(appName); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
405 if (keydb == NULL) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
406 return CKR_NETSCAPE_KEYDB_FAILED; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
407 *keydbPtr = keydb; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
408 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
409 return CKR_OK; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
410 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
411 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
412 /* |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
413 * Accessors for the private parts of the sdb structure. |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
414 */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
415 void |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
416 lg_DBLock(SDB *sdb) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
417 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
418 LGPrivate *lgdb_p = (LGPrivate *)sdb->private; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
419 SKIP_AFTER_FORK(PR_Lock(lgdb_p->dbLock)); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
420 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
421 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
422 void |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
423 lg_DBUnlock(SDB *sdb) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
424 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
425 LGPrivate *lgdb_p = (LGPrivate *)sdb->private; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
426 SKIP_AFTER_FORK(PR_Unlock(lgdb_p->dbLock)); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
427 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
428 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
429 PLHashTable * |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
430 lg_GetHashTable(SDB *sdb) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
431 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
432 LGPrivate *lgdb_p = (LGPrivate *)sdb->private; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
433 return lgdb_p->hashTable; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
434 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
435 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
436 NSSLOWCERTCertDBHandle * |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
437 lg_getCertDB(SDB *sdb) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
438 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
439 LGPrivate *lgdb_p = (LGPrivate *)sdb->private; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
440 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
441 return lgdb_p->certDB; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
442 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
443 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
444 NSSLOWKEYDBHandle * |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
445 lg_getKeyDB(SDB *sdb) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
446 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
447 LGPrivate *lgdb_p = (LGPrivate *)sdb->private; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
448 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
449 return lgdb_p->keyDB; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
450 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
451 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
452 PRBool lg_parentForkedAfterC_Initialize; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
453 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
454 void lg_SetForkState(PRBool forked) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
455 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
456 lg_parentForkedAfterC_Initialize = forked; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
457 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
458 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
459 CK_RV |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
460 lg_Close(SDB *sdb) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
461 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
462 LGPrivate *lgdb_p = (LGPrivate *)sdb->private; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
463 lg_ClearTokenKeyHashTable(sdb); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
464 if (lgdb_p) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
465 if (lgdb_p->certDB) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
466 nsslowcert_ClosePermCertDB(lgdb_p->certDB); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
467 } else if (lgdb_p->keyDB) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
468 nsslowkey_CloseKeyDB(lgdb_p->keyDB); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
469 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
470 if (lgdb_p->dbLock) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
471 SKIP_AFTER_FORK(PR_DestroyLock(lgdb_p->dbLock)); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
472 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
473 if (lgdb_p->hashTable) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
474 PL_HashTableDestroy(lgdb_p->hashTable); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
475 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
476 PORT_Free(lgdb_p); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
477 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
478 PORT_Free(sdb); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
479 return CKR_OK; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
480 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
481 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
482 static PLHashNumber |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
483 lg_HashNumber(const void *key) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
484 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
485 return (PLHashNumber) key; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
486 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
487 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
488 PRIntn |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
489 lg_CompareValues(const void *v1, const void *v2) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
490 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
491 PLHashNumber value1 = (PLHashNumber) v1; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
492 PLHashNumber value2 = (PLHashNumber) v2; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
493 return (value1 == value2); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
494 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
495 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
496 /* |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
497 * helper function to wrap a NSSLOWCERTCertDBHandle or a NSSLOWKEYDBHandle |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
498 * with and sdb structure. |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
499 */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
500 CK_RV |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
501 lg_init(SDB **pSdb, int flags, NSSLOWCERTCertDBHandle *certdbPtr, |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
502 NSSLOWKEYDBHandle *keydbPtr) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
503 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
504 SDB *sdb = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
505 LGPrivate *lgdb_p = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
506 CK_RV error = CKR_HOST_MEMORY; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
507 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
508 *pSdb = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
509 sdb = (SDB *) PORT_Alloc(sizeof(SDB)); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
510 if (sdb == NULL) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
511 goto loser; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
512 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
513 lgdb_p = (LGPrivate *) PORT_Alloc(sizeof(LGPrivate)); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
514 if (lgdb_p == NULL) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
515 goto loser; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
516 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
517 /* invariant fields */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
518 lgdb_p->certDB = certdbPtr; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
519 lgdb_p->keyDB = keydbPtr; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
520 lgdb_p->dbLock = PR_NewLock(); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
521 if (lgdb_p->dbLock == NULL) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
522 goto loser; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
523 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
524 lgdb_p->hashTable = PL_NewHashTable(64, lg_HashNumber, lg_CompareValues, |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
525 SECITEM_HashCompare, NULL, 0); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
526 if (lgdb_p->hashTable == NULL) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
527 goto loser; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
528 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
529 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
530 sdb->private = lgdb_p; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
531 sdb->version = 0; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
532 /*sdb->sdb_type = SDB_LEGACY; */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
533 sdb->sdb_flags = flags; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
534 sdb->app_private = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
535 sdb->sdb_FindObjectsInit = lg_FindObjectsInit; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
536 sdb->sdb_FindObjects = lg_FindObjects; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
537 sdb->sdb_FindObjectsFinal = lg_FindObjectsFinal; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
538 sdb->sdb_GetAttributeValue = lg_GetAttributeValue; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
539 sdb->sdb_SetAttributeValue = lg_SetAttributeValue; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
540 sdb->sdb_CreateObject = lg_CreateObject; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
541 sdb->sdb_DestroyObject = lg_DestroyObject; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
542 sdb->sdb_GetMetaData = lg_GetMetaData; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
543 sdb->sdb_PutMetaData = lg_PutMetaData; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
544 sdb->sdb_Begin = lg_Begin; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
545 sdb->sdb_Commit = lg_Commit; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
546 sdb->sdb_Abort = lg_Abort; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
547 sdb->sdb_Reset = lg_Reset; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
548 sdb->sdb_Close = lg_Close; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
549 sdb->sdb_SetForkState = lg_SetForkState; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
550 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
551 *pSdb = sdb; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
552 return CKR_OK; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
553 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
554 loser: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
555 if (sdb) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
556 PORT_Free(sdb); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
557 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
558 if (lgdb_p) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
559 if (lgdb_p->dbLock) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
560 PR_DestroyLock(lgdb_p->dbLock); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
561 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
562 if (lgdb_p->hashTable) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
563 PL_HashTableDestroy(lgdb_p->hashTable); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
564 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
565 PORT_Free(lgdb_p); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
566 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
567 return error; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
568 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
569 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
570 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
571 /* |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
572 * OK there are now lots of options here, lets go through them all: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
573 * |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
574 * configdir - base directory where all the cert, key, and module datbases live. |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
575 * certPrefix - prefix added to the beginning of the cert database example: " |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
576 * "https-server1-" |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
577 * keyPrefix - prefix added to the beginning of the key database example: " |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
578 * "https-server1-" |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
579 * secmodName - name of the security module database (usually "secmod.db"). |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
580 * readOnly - Boolean: true if the databases are to be openned read only. |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
581 * nocertdb - Don't open the cert DB and key DB's, just initialize the |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
582 * Volatile certdb. |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
583 * nomoddb - Don't open the security module DB, just initialize the |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
584 * PKCS #11 module. |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
585 * forceOpen - Continue to force initializations even if the databases cannot |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
586 * be opened. |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
587 */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
588 CK_RV |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
589 legacy_Open(const char *configdir, const char *certPrefix, |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
590 const char *keyPrefix, int certVersion, int keyVersion, |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
591 int flags, SDB **certDB, SDB **keyDB) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
592 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
593 CK_RV crv = CKR_OK; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
594 SECStatus rv; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
595 PRBool readOnly = (flags == SDB_RDONLY)? PR_TRUE: PR_FALSE; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
596 volatile char c; /* force a reference that won't get optimized away */ |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
597 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
598 c = __nss_dbm_rcsid[0] + __nss_dbm_sccsid[0]; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
599 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
600 rv = SECOID_Init(); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
601 if (SECSuccess != rv) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
602 return CKR_DEVICE_ERROR; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
603 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
604 nsslowcert_InitLocks(); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
605 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
606 if (keyDB) *keyDB = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
607 if (certDB) *certDB = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
608 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
609 if (certDB) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
610 NSSLOWCERTCertDBHandle *certdbPtr; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
611 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
612 crv = lg_OpenCertDB(configdir, certPrefix, readOnly, &certdbPtr); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
613 if (crv != CKR_OK) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
614 goto loser; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
615 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
616 crv = lg_init(certDB, flags, certdbPtr, NULL); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
617 if (crv != CKR_OK) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
618 nsslowcert_ClosePermCertDB(certdbPtr); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
619 goto loser; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
620 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
621 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
622 if (keyDB) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
623 NSSLOWKEYDBHandle *keydbPtr; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
624 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
625 crv = lg_OpenKeyDB(configdir, keyPrefix, readOnly, &keydbPtr); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
626 if (crv != CKR_OK) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
627 goto loser; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
628 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
629 crv = lg_init(keyDB, flags, NULL, keydbPtr); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
630 if (crv != CKR_OK) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
631 nsslowkey_CloseKeyDB(keydbPtr); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
632 goto loser; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
633 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
634 if (certDB && *certDB) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
635 LGPrivate *lgdb_p = (LGPrivate *)(*certDB)->private; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
636 lgdb_p->keyDB = keydbPtr; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
637 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
638 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
639 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
640 loser: |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
641 if (crv != CKR_OK) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
642 if (keyDB && *keyDB) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
643 lg_Close(*keyDB); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
644 *keyDB = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
645 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
646 if (certDB && *certDB) { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
647 lg_Close(*certDB); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
648 *certDB = NULL; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
649 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
650 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
651 return crv; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
652 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
653 |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
654 CK_RV |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
655 legacy_Shutdown(PRBool forked) |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
656 { |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
657 lg_SetForkState(forked); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
658 nsslowcert_DestroyFreeLists(); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
659 nsslowcert_DestroyGlobalLocks(); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
660 SECOID_Shutdown(); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
661 lg_SetForkState(PR_FALSE); |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
662 return CKR_OK; |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
663 } |
150b72113545
Add DBM and legacydb support
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
664 |