2
* The contents of this file are subject to the Mozilla Public
3
* License Version 1.1 (the "License"); you may not use this file
4
* except in compliance with the License. You may obtain a copy of
5
* the License at http://www.mozilla.org/MPL/
7
* Software distributed under the License is distributed on an "AS
8
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9
* implied. See the License for the specific language governing
10
* rights and limitations under the License.
12
* The Original Code is the Netscape security libraries.
14
* The Initial Developer of the Original Code is Netscape
15
* Communications Corporation. Portions created by Netscape are
16
* Copyright (C) 1994-2000 Netscape Communications Corporation. All
20
* Sonja Mirtitsch Sun Microsystems
22
* Alternatively, the contents of this file may be used under the
23
* terms of the GNU General Public License Version 2 or later (the
24
* "GPL"), in which case the provisions of the GPL are applicable
25
* instead of those above. If you wish to allow use of your
26
* version of this file only under the terms of the GPL and not to
27
* allow others to use your version of this file under the MPL,
28
* indicate your decision by deleting the provisions above and
29
* replace them with the notice and other provisions required by
30
* the GPL. If you do not delete the provisions above, a recipient
31
* may use your version of this file under either the MPL or the
38
** QA test for cert and key databases, especially to open
39
** database readonly (NSS_INIT_READONLY) and force initializations
40
** even if the databases cannot be opened (NSS_INIT_FORCEOPEN)
61
#include "../modutil/modutil.h"
65
static char *progName;
69
static char *dbName[]={"secmod.db", "cert8.db", "key3.db"};
70
static char* dbprefix = "";
71
static char* secmodName = "secmod.db";
75
static void Usage(const char *progName)
77
printf("Usage: %s [-r] [-f] [-d dbdir ] \n",
79
printf("%-20s open database readonly (NSS_INIT_READONLY)\n", "-r");
80
printf("%-20s Continue to force initializations even if the\n", "-f");
81
printf("%-20s databases cannot be opened (NSS_INIT_FORCEOPEN)\n", " ");
82
printf("%-20s Directory with cert database (default is .\n",
87
int main(int argc, char **argv)
90
PLOptStatus optstatus;
93
PRBool useCommandLinePassword = PR_FALSE;
96
char * dbString = NULL;
99
progName = strrchr(argv[0], '/');
101
progName = strrchr(argv[0], '\\');
102
progName = progName ? progName+1 : argv[0];
104
optstate = PL_CreateOptState(argc, argv, "rfd:h");
106
while ((optstatus = PL_GetNextOpt(optstate)) == PL_OPT_OK) {
107
switch (optstate->option) {
109
default : Usage(progName); break;
111
case 'r': flags |= NSS_INIT_READONLY; break;
113
case 'f': flags |= NSS_INIT_FORCEOPEN; break;
116
dbDir = PORT_Strdup(optstate->value);
121
if (optstatus == PL_OPT_BAD)
125
dbDir = SECU_DefaultSSLDir(); /* Look in $SSL_DIR */
127
dbDir = SECU_ConfigDirectory(dbDir);
128
PR_fprintf(PR_STDERR, "dbdir selected is %s\n\n", dbDir);
130
if( dbDir[0] == '\0') {
131
PR_fprintf(PR_STDERR, errStrings[DIR_DOESNT_EXIST_ERR], dbDir);
132
ret= DIR_DOESNT_EXIST_ERR;
137
PR_Init( PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
139
/* get the status of the directory and databases and output message */
140
if(PR_Access(dbDir, PR_ACCESS_EXISTS) != PR_SUCCESS) {
141
PR_fprintf(PR_STDERR, errStrings[DIR_DOESNT_EXIST_ERR], dbDir);
142
} else if(PR_Access(dbDir, PR_ACCESS_READ_OK) != PR_SUCCESS) {
143
PR_fprintf(PR_STDERR, errStrings[DIR_NOT_READABLE_ERR], dbDir);
145
if( !( flags & NSS_INIT_READONLY ) &&
146
PR_Access(dbDir, PR_ACCESS_WRITE_OK) != PR_SUCCESS) {
147
PR_fprintf(PR_STDERR, errStrings[DIR_NOT_WRITEABLE_ERR], dbDir);
150
dbString=PR_smprintf("%s/%s",dbDir,dbName[i]);
151
PR_fprintf(PR_STDOUT, "database checked is %s\n",dbString);
152
if(PR_Access(dbString, PR_ACCESS_EXISTS) != PR_SUCCESS) {
153
PR_fprintf(PR_STDERR, errStrings[FILE_DOESNT_EXIST_ERR],
155
} else if(PR_Access(dbString, PR_ACCESS_READ_OK) != PR_SUCCESS) {
156
PR_fprintf(PR_STDERR, errStrings[FILE_NOT_READABLE_ERR],
158
} else if( !( flags & NSS_INIT_READONLY ) &&
159
PR_Access(dbString, PR_ACCESS_WRITE_OK) != PR_SUCCESS) {
160
PR_fprintf(PR_STDERR, errStrings[FILE_NOT_WRITEABLE_ERR],
166
rv = NSS_Initialize(SECU_ConfigDirectory(dbDir), dbprefix, dbprefix,
168
if (rv != SECSuccess) {
169
SECU_PrintPRandOSError(progName);
170
ret=NSS_INITIALIZE_FAILED_ERR;
172
if (NSS_Shutdown() != SECSuccess) {