Skip to content

Commit

Permalink
Bug 1609673 - Conditionally compile out all libnssdbm glue if NSS_DIS…
Browse files Browse the repository at this point in the history
…ABLE_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
  • Loading branch information
jcjones committed Feb 5, 2020
1 parent 99b6221 commit c046b13
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
10 changes: 8 additions & 2 deletions lib/softoken/exports.gyp
Expand Up @@ -19,15 +19,21 @@
},
{
'files': [
'lgglue.h',
'pkcs11ni.h',
'sdb.h',
'sftkdbt.h',
'softkver.h',
'softoken.h',
'softoknt.h'
],
'destination': '<(nss_private_dist_dir)/<(module)'
'destination': '<(nss_private_dist_dir)/<(module)',
'conditions': [
[ 'disable_dbm==0', {
'files': [
'lgglue.h',
]
}]
]
}
]
}
Expand Down
7 changes: 5 additions & 2 deletions lib/softoken/manifest.mn
Expand Up @@ -23,7 +23,6 @@ EXPORTS = \
$(NULL)

PRIVATE_EXPORTS = \
lgglue.h \
pkcs11ni.h \
softoken.h \
softoknt.h \
Expand All @@ -37,7 +36,6 @@ CSRCS = \
fipstest.c \
fipstokn.c \
kbkdf.c \
lgglue.c \
lowkey.c \
lowpbe.c \
padbuf.c \
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/softoken/pkcs11.c
Expand Up @@ -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);
Expand All @@ -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 */

Expand Down Expand Up @@ -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;
}

Expand Down
14 changes: 14 additions & 0 deletions lib/softoken/sftkdb.c
Expand Up @@ -2693,6 +2693,7 @@ sftkdb_ResetKeyDB(SFTKDBHandle *handle)
return SECSuccess;
}

#ifndef NSS_DISABLE_DBM
static PRBool
sftk_oldVersionExists(const char *dir, int version)
{
Expand Down Expand Up @@ -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.
Expand All @@ -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;

Expand All @@ -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);
Expand All @@ -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;

/*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -2970,6 +2980,8 @@ sftk_DBInit(const char *configdir, const char *certPrefix,
}
}
}
#endif /* NSS_DISABLE_DBM */

done:
if (appName) {
PORT_Free(appName);
Expand All @@ -2984,6 +2996,8 @@ CK_RV
sftkdb_Shutdown(void)
{
s_shutdown();
#ifndef NSS_DISABLE_DBM
sftkdbCall_Shutdown();
#endif /* NSS_DISABLE_DBM */
return CKR_OK;
}
8 changes: 7 additions & 1 deletion lib/softoken/softoken.gyp
Expand Up @@ -49,7 +49,6 @@
'fipstokn.c',
'jpakesftk.c',
'kbkdf.c',
'lgglue.c',
'lowkey.c',
'lowpbe.c',
'padbuf.c',
Expand All @@ -65,6 +64,13 @@
'softkver.c',
'tlsprf.c'
],
'conditions': [
[ 'disable_dbm==0', {
'sources': [
'lgglue.c',
]
}]
]
},
},
{
Expand Down

0 comments on commit c046b13

Please sign in to comment.