From c046b1309bfdf11742c656d1370abdd87c6a4766 Mon Sep 17 00:00:00 2001 From: "J.C. Jones" Date: Wed, 5 Feb 2020 22:12:30 +0000 Subject: [PATCH] Bug 1609673 - Conditionally compile out all libnssdbm glue if NSS_DISABLE_DBM is set r=mt Remove `lgglue` from compilation entirely if DBM is disabled Differential Revision: https://phabricator.services.mozilla.com/D61759 --HG-- extra : moz-landing-system : lando --- lib/softoken/exports.gyp | 10 ++++++++-- lib/softoken/manifest.mn | 7 +++++-- lib/softoken/pkcs11.c | 4 ++++ lib/softoken/sftkdb.c | 14 ++++++++++++++ lib/softoken/softoken.gyp | 8 +++++++- 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/lib/softoken/exports.gyp b/lib/softoken/exports.gyp index d11d8e49a8..82b9817e6e 100644 --- a/lib/softoken/exports.gyp +++ b/lib/softoken/exports.gyp @@ -19,7 +19,6 @@ }, { 'files': [ - 'lgglue.h', 'pkcs11ni.h', 'sdb.h', 'sftkdbt.h', @@ -27,7 +26,14 @@ 'softoken.h', 'softoknt.h' ], - 'destination': '<(nss_private_dist_dir)/<(module)' + 'destination': '<(nss_private_dist_dir)/<(module)', + 'conditions': [ + [ 'disable_dbm==0', { + 'files': [ + 'lgglue.h', + ] + }] + ] } ] } diff --git a/lib/softoken/manifest.mn b/lib/softoken/manifest.mn index b481799a01..fed4e62eca 100644 --- a/lib/softoken/manifest.mn +++ b/lib/softoken/manifest.mn @@ -23,7 +23,6 @@ EXPORTS = \ $(NULL) PRIVATE_EXPORTS = \ - lgglue.h \ pkcs11ni.h \ softoken.h \ softoknt.h \ @@ -37,7 +36,6 @@ CSRCS = \ fipstest.c \ fipstokn.c \ kbkdf.c \ - lgglue.c \ lowkey.c \ lowpbe.c \ padbuf.c \ @@ -55,6 +53,11 @@ CSRCS = \ jpakesftk.c \ $(NULL) +ifndef NSS_DISABLE_DBM +PRIVATE_EXPORTS += lgglue.h +CSRCS += lgglue.c +endif + ifdef SQLITE_UNSAFE_THREADS DEFINES += -DSQLITE_UNSAFE_THREADS endif diff --git a/lib/softoken/pkcs11.c b/lib/softoken/pkcs11.c index 133c7b9c79..7eb86869b2 100644 --- a/lib/softoken/pkcs11.c +++ b/lib/softoken/pkcs11.c @@ -2937,12 +2937,14 @@ SFTK_DestroySlotData(SFTKSlot *slot) char ** NSC_ModuleDBFunc(unsigned long function, char *parameters, void *args) { +#ifndef NSS_DISABLE_DBM char *secmod = NULL; char *appName = NULL; char *filename = NULL; NSSDBType dbType = NSS_DB_TYPE_NONE; PRBool rw; static char *success = "Success"; +#endif /* NSS_DISABLE_DBM */ char **rvstr = NULL; rvstr = NSSUTIL_DoModuleDBFunction(function, parameters, args); @@ -2954,6 +2956,7 @@ NSC_ModuleDBFunc(unsigned long function, char *parameters, void *args) return NULL; } +#ifndef NSS_DISABLE_DBM /* The legacy database uses the old dbm, which is only linked with the * legacy DB handler, which is only callable from softoken */ @@ -3045,6 +3048,7 @@ NSC_ModuleDBFunc(unsigned long function, char *parameters, void *args) PORT_Free(appName); if (filename) PORT_Free(filename); +#endif /* NSS_DISABLE_DBM */ return rvstr; } diff --git a/lib/softoken/sftkdb.c b/lib/softoken/sftkdb.c index e7c9f93872..3985fc510a 100644 --- a/lib/softoken/sftkdb.c +++ b/lib/softoken/sftkdb.c @@ -2693,6 +2693,7 @@ sftkdb_ResetKeyDB(SFTKDBHandle *handle) return SECSuccess; } +#ifndef NSS_DISABLE_DBM static PRBool sftk_oldVersionExists(const char *dir, int version) { @@ -2796,6 +2797,7 @@ sftk_hasLegacyDB(const char *confdir, const char *certPrefix, PR_smprintf_free(dir); return exists; } +#endif /* NSS_DISABLE_DBM */ /* * initialize certificate and key database handles as a pair. @@ -2819,7 +2821,9 @@ sftk_DBInit(const char *configdir, const char *certPrefix, CK_RV crv = CKR_OK; int flags = SDB_RDONLY; PRBool newInit = PR_FALSE; +#ifndef NSS_DISABLE_DBM PRBool needUpdate = PR_FALSE; +#endif /* NSS_DISABLE_DBM */ char *nconfdir = NULL; PRBool legacy = PR_TRUE; @@ -2842,6 +2846,7 @@ sftk_DBInit(const char *configdir, const char *certPrefix, * now initialize the appropriate database */ switch (dbType) { +#ifndef NSS_DISABLE_DBM case NSS_DB_TYPE_LEGACY: crv = sftkdbCall_open(confdir, certPrefix, keyPrefix, 8, 3, flags, noCertDB ? NULL : &certSDB, noKeyDB ? NULL : &keySDB); @@ -2850,10 +2855,13 @@ sftk_DBInit(const char *configdir, const char *certPrefix, crv = sftkdbCall_open(configdir, certPrefix, keyPrefix, 8, 3, flags, noCertDB ? NULL : &certSDB, noKeyDB ? NULL : &keySDB); break; +#endif /* NSS_DISABLE_DBM */ case NSS_DB_TYPE_SQL: case NSS_DB_TYPE_EXTERN: /* SHOULD open a loadable db */ crv = s_open(confdir, certPrefix, keyPrefix, 9, 4, flags, noCertDB ? NULL : &certSDB, noKeyDB ? NULL : &keySDB, &newInit); + +#ifndef NSS_DISABLE_DBM legacy = PR_FALSE; /* @@ -2905,6 +2913,7 @@ sftk_DBInit(const char *configdir, const char *certPrefix, needUpdate = PR_TRUE; } } +#endif /* NSS_DISABLE_DBM */ break; default: crv = CKR_GENERAL_ERROR; /* can't happen, EvaluationConfigDir MUST @@ -2933,6 +2942,7 @@ sftk_DBInit(const char *configdir, const char *certPrefix, (*keyDB)->peerDB = *certDB; } +#ifndef NSS_DISABLE_DBM /* * if we need to update, open the legacy database and * mark the handle as needing update. @@ -2970,6 +2980,8 @@ sftk_DBInit(const char *configdir, const char *certPrefix, } } } +#endif /* NSS_DISABLE_DBM */ + done: if (appName) { PORT_Free(appName); @@ -2984,6 +2996,8 @@ CK_RV sftkdb_Shutdown(void) { s_shutdown(); +#ifndef NSS_DISABLE_DBM sftkdbCall_Shutdown(); +#endif /* NSS_DISABLE_DBM */ return CKR_OK; } diff --git a/lib/softoken/softoken.gyp b/lib/softoken/softoken.gyp index 9cd503799c..80fc7d75f1 100644 --- a/lib/softoken/softoken.gyp +++ b/lib/softoken/softoken.gyp @@ -49,7 +49,6 @@ 'fipstokn.c', 'jpakesftk.c', 'kbkdf.c', - 'lgglue.c', 'lowkey.c', 'lowpbe.c', 'padbuf.c', @@ -65,6 +64,13 @@ 'softkver.c', 'tlsprf.c' ], + 'conditions': [ + [ 'disable_dbm==0', { + 'sources': [ + 'lgglue.c', + ] + }] + ] }, }, {