1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
* The contents of this file are subject to the Mozilla Public License Version
5
* 1.1 (the "License"); you may not use this file except in compliance with
6
* the License. You may obtain a copy of the License at
7
* http://www.mozilla.org/MPL/
9
* Software distributed under the License is distributed on an "AS IS" basis,
10
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
* for the specific language governing rights and limitations under the
14
* The Original Code is the Netscape security libraries.
16
* The Initial Developer of the Original Code is
17
* Netscape Communications Corporation.
18
* Portions created by the Initial Developer are Copyright (C) 1994-2000
19
* the Initial Developer. All Rights Reserved.
22
* Sonja Mirtitsch Sun Microsystems
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
41
** QA test for cert and key databases, especially to open
42
** database readonly (NSS_INIT_READONLY) and force initializations
43
** even if the databases cannot be opened (NSS_INIT_FORCEOPEN)
64
#include "../modutil/modutil.h"
68
static char *progName;
72
static char *dbName[]={"secmod.db", "cert8.db", "key3.db"};
73
static char* dbprefix = "";
74
static char* secmodName = "secmod.db";
78
static void Usage(const char *progName)
80
printf("Usage: %s [-r] [-f] [-d dbdir ] \n",
82
printf("%-20s open database readonly (NSS_INIT_READONLY)\n", "-r");
83
printf("%-20s Continue to force initializations even if the\n", "-f");
84
printf("%-20s databases cannot be opened (NSS_INIT_FORCEOPEN)\n", " ");
85
printf("%-20s Directory with cert database (default is .\n",
90
int main(int argc, char **argv)
93
PLOptStatus optstatus;
98
char * dbString = NULL;
101
progName = strrchr(argv[0], '/');
103
progName = strrchr(argv[0], '\\');
104
progName = progName ? progName+1 : argv[0];
106
optstate = PL_CreateOptState(argc, argv, "rfd:h");
108
while ((optstatus = PL_GetNextOpt(optstate)) == PL_OPT_OK) {
109
switch (optstate->option) {
111
default : Usage(progName); break;
113
case 'r': flags |= NSS_INIT_READONLY; break;
115
case 'f': flags |= NSS_INIT_FORCEOPEN; break;
118
dbDir = PORT_Strdup(optstate->value);
123
if (optstatus == PL_OPT_BAD)
127
dbDir = SECU_DefaultSSLDir(); /* Look in $SSL_DIR */
129
dbDir = SECU_ConfigDirectory(dbDir);
130
PR_fprintf(PR_STDERR, "dbdir selected is %s\n\n", dbDir);
132
if( dbDir[0] == '\0') {
133
PR_fprintf(PR_STDERR, errStrings[DIR_DOESNT_EXIST_ERR], dbDir);
134
ret= DIR_DOESNT_EXIST_ERR;
139
PR_Init( PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
141
/* get the status of the directory and databases and output message */
142
if(PR_Access(dbDir, PR_ACCESS_EXISTS) != PR_SUCCESS) {
143
PR_fprintf(PR_STDERR, errStrings[DIR_DOESNT_EXIST_ERR], dbDir);
144
} else if(PR_Access(dbDir, PR_ACCESS_READ_OK) != PR_SUCCESS) {
145
PR_fprintf(PR_STDERR, errStrings[DIR_NOT_READABLE_ERR], dbDir);
147
if( !( flags & NSS_INIT_READONLY ) &&
148
PR_Access(dbDir, PR_ACCESS_WRITE_OK) != PR_SUCCESS) {
149
PR_fprintf(PR_STDERR, errStrings[DIR_NOT_WRITEABLE_ERR], dbDir);
152
dbString=PR_smprintf("%s/%s",dbDir,dbName[i]);
153
PR_fprintf(PR_STDOUT, "database checked is %s\n",dbString);
154
if(PR_Access(dbString, PR_ACCESS_EXISTS) != PR_SUCCESS) {
155
PR_fprintf(PR_STDERR, errStrings[FILE_DOESNT_EXIST_ERR],
157
} else if(PR_Access(dbString, PR_ACCESS_READ_OK) != PR_SUCCESS) {
158
PR_fprintf(PR_STDERR, errStrings[FILE_NOT_READABLE_ERR],
160
} else if( !( flags & NSS_INIT_READONLY ) &&
161
PR_Access(dbString, PR_ACCESS_WRITE_OK) != PR_SUCCESS) {
162
PR_fprintf(PR_STDERR, errStrings[FILE_NOT_WRITEABLE_ERR],
168
rv = NSS_Initialize(SECU_ConfigDirectory(dbDir), dbprefix, dbprefix,
170
if (rv != SECSuccess) {
171
SECU_PrintPRandOSError(progName);
172
ret=NSS_INITIALIZE_FAILED_ERR;
174
if (NSS_Shutdown() != SECSuccess) {