Comment 57 for bug 543183

Revision history for this message
In , Elio (elio-redhat-bugs) wrote :

The patch as it is works in fedora but one should consider portability as eventually it needs to be submitted upstream to mozilla. To start I would suggest using the NSPR types and NSPR functions.
Adding
+#include "prio.h" to pickup the NSPR functions
using PRBool instead of int for the boolean variable, and replacing the use of ::fopen, ::fgets, ::strcomp, and ::flose with PR_Open, PR_Read, PORT_Strcmp, and PR_Close

It would look like this:
+#define NSS_SYSTEM_DB "/etc/pki/nssdb"
+ SECStatus init_rv = SECFailure;
+ const char *nssdb = profileStr.get();
+
+ FILE *f = PR_Open(NSS_DEFAULT_SYSTEM "/pkcs11.txt", PR_RDONLY, 0);
+ if (f) {
+ PRBool found = PR_FALSE;
+ char buf[80];
+ /* Check whether the system NSS db is actually enabled */
+ while (PR_Read(f, buf, 80) && !found) {
+ if (!PORT_Strcmp(buf, "library=libnsssysinit.so\n"))
+ found = PR_TRUE;
+ }
+ PR_Close(f);
+ if (found) {
+ nssdb = "sql:"NSS_SYSTEM_DB;
+ init_rv = ::NSS_InitWithMerge(nssdb,
+ "", "", SECMOD_DB,
+ profileStr.get(), "", "",
+ profileStr.get(), profileStr.get(), 0);
+ }
+ }
+ /* If no sysdb found, or opening it failed, try opening the
+ old db from the profile directory. If that fails, subsequent
+ (readonly, nodb) attempts will be on the system db */
+ if (init_rv == SECFailure)
+ init_rv = ::NSS_InitReadWrite(profileStr.get());
The NSS_DEFAULT_SYSTEM is a unix/linux path so a function like find_default_system_db_dir() may be needed to be even more cross-platform.