security/nss/lib/softoken/legacydb/lgdb.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/lib/softoken/legacydb/lgdb.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,177 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +/*
     1.8 + * Internal data structures and functions used by pkcs11.c
     1.9 + */
    1.10 +#ifndef _LGDB_H_
    1.11 +#define _LGDB_H_ 1
    1.12 +
    1.13 +#include "nssilock.h"
    1.14 +#include "seccomon.h"
    1.15 +#include "secoidt.h"
    1.16 +#include "lowkeyti.h"
    1.17 +#include "pkcs11t.h"
    1.18 +#include "sdb.h"
    1.19 +#include "cdbhdl.h" 
    1.20 +
    1.21 +
    1.22 +#define MULTIACCESS "multiaccess:"
    1.23 +
    1.24 +
    1.25 +/* path stuff (was machine dependent) used by dbinit.c and pk11db.c */
    1.26 +#define PATH_SEPARATOR "/"
    1.27 +#define SECMOD_DB "secmod.db"
    1.28 +#define CERT_DB_FMT "%scert%s.db"
    1.29 +#define KEY_DB_FMT "%skey%s.db"
    1.30 +
    1.31 +SEC_BEGIN_PROTOS
    1.32 +
    1.33 +
    1.34 +/* internal utility functions used by pkcs11.c */
    1.35 +extern const CK_ATTRIBUTE *lg_FindAttribute(CK_ATTRIBUTE_TYPE type,
    1.36 +			const CK_ATTRIBUTE *templ, CK_ULONG count);
    1.37 +extern CK_RV lg_Attribute2SecItem(PLArenaPool *,CK_ATTRIBUTE_TYPE type,
    1.38 +			const CK_ATTRIBUTE *templ, CK_ULONG count,
    1.39 +			SECItem *item);
    1.40 +extern CK_RV lg_Attribute2SSecItem(PLArenaPool *,CK_ATTRIBUTE_TYPE type,
    1.41 +			const CK_ATTRIBUTE *templ, CK_ULONG count,
    1.42 +			SECItem *item);
    1.43 +extern CK_RV lg_PrivAttr2SecItem(PLArenaPool *,CK_ATTRIBUTE_TYPE type,
    1.44 +			const CK_ATTRIBUTE *templ, CK_ULONG count,
    1.45 +			SECItem *item, SDB *sdbpw);
    1.46 +extern CK_RV lg_PrivAttr2SSecItem(PLArenaPool *,CK_ATTRIBUTE_TYPE type,
    1.47 +			const CK_ATTRIBUTE *templ, CK_ULONG count,
    1.48 +			SECItem *item, SDB *sdbpw);
    1.49 +extern CK_RV lg_GetULongAttribute(CK_ATTRIBUTE_TYPE type,
    1.50 +			const CK_ATTRIBUTE *templ, CK_ULONG count, 
    1.51 +			CK_ULONG *out);
    1.52 +extern PRBool lg_hasAttribute(CK_ATTRIBUTE_TYPE type,
    1.53 +			const CK_ATTRIBUTE *templ, CK_ULONG count);
    1.54 +extern PRBool lg_isTrue(CK_ATTRIBUTE_TYPE type,
    1.55 +			const CK_ATTRIBUTE *templ, CK_ULONG count);
    1.56 +extern PRBool lg_isSensitive(CK_ATTRIBUTE_TYPE type, CK_OBJECT_CLASS inClass);
    1.57 +extern char *lg_getString(CK_ATTRIBUTE_TYPE type,
    1.58 +			const CK_ATTRIBUTE *templ, CK_ULONG count);
    1.59 +extern unsigned int lg_MapTrust(CK_TRUST trust, PRBool clientAuth);
    1.60 +
    1.61 +/* clear out all the existing object ID to database key mappings.
    1.62 + * used to reinit a token */
    1.63 +extern CK_RV lg_ClearTokenKeyHashTable(SDB *sdb);
    1.64 +
    1.65 +
    1.66 +extern void lg_FreeSearch(SDBFind *search);
    1.67 +
    1.68 +NSSLOWCERTCertDBHandle *lg_getCertDB(SDB *sdb);
    1.69 +NSSLOWKEYDBHandle *lg_getKeyDB(SDB *sdb);
    1.70 +
    1.71 +const char *lg_EvaluateConfigDir(const char *configdir, char **domain);
    1.72 +
    1.73 +
    1.74 +/*
    1.75 + * object handle modifiers
    1.76 + */
    1.77 +#define LG_TOKEN_MASK		0xc0000000L
    1.78 +#define LG_TOKEN_TYPE_MASK	0x38000000L
    1.79 +#define LG_TOKEN_TYPE_SHIFT	27
    1.80 +/* keydb (high bit == 0) */
    1.81 +#define LG_TOKEN_TYPE_PRIV	0x08000000L
    1.82 +#define LG_TOKEN_TYPE_PUB	0x10000000L
    1.83 +#define LG_TOKEN_TYPE_KEY	0x18000000L
    1.84 +/* certdb (high bit == 1) */
    1.85 +#define LG_TOKEN_TYPE_TRUST	0x20000000L
    1.86 +#define LG_TOKEN_TYPE_CRL	0x28000000L
    1.87 +#define LG_TOKEN_TYPE_SMIME	0x30000000L
    1.88 +#define LG_TOKEN_TYPE_CERT	0x38000000L
    1.89 +
    1.90 +#define LG_TOKEN_KRL_HANDLE	(LG_TOKEN_TYPE_CRL|1)
    1.91 +
    1.92 +#define LG_SEARCH_BLOCK_SIZE   10
    1.93 +#define LG_BUF_SPACE	  50
    1.94 +#define LG_STRICT   PR_FALSE
    1.95 +
    1.96 +/*
    1.97 + * token object utilities
    1.98 + */
    1.99 +void lg_addHandle(SDBFind *search, CK_OBJECT_HANDLE handle);
   1.100 +PRBool lg_poisonHandle(SDB *sdb, SECItem *dbkey, CK_OBJECT_HANDLE handle);
   1.101 +PRBool lg_tokenMatch(SDB *sdb, const SECItem *dbKey, CK_OBJECT_HANDLE class,
   1.102 +				const CK_ATTRIBUTE *templ, CK_ULONG count);
   1.103 +const SECItem *lg_lookupTokenKeyByHandle(SDB *sdb, CK_OBJECT_HANDLE handle);
   1.104 +CK_OBJECT_HANDLE lg_mkHandle(SDB *sdb, SECItem *dbKey, CK_OBJECT_HANDLE class);
   1.105 +SECStatus lg_deleteTokenKeyByHandle(SDB *sdb, CK_OBJECT_HANDLE handle);
   1.106 +
   1.107 +SECStatus lg_util_encrypt(PLArenaPool *arena, SDB *sdbpw, 
   1.108 +			  SECItem *plainText, SECItem **cipherText);
   1.109 +SECStatus lg_util_decrypt(SDB *sdbpw, 
   1.110 +			  SECItem *cipherText, SECItem **plainText);
   1.111 +PLHashTable *lg_GetHashTable(SDB *sdb);
   1.112 +void lg_DBLock(SDB *sdb);
   1.113 +void lg_DBUnlock(SDB *sdb);
   1.114 +
   1.115 +typedef void (*LGFreeFunc)(void *);
   1.116 +
   1.117 +
   1.118 +/*
   1.119 + * database functions
   1.120 + */
   1.121 +
   1.122 +/* lg_FindObjectsInit initializes a search for token and session objects 
   1.123 + * that match a template. */
   1.124 +CK_RV lg_FindObjectsInit(SDB *sdb, const CK_ATTRIBUTE *pTemplate, 
   1.125 +			 CK_ULONG ulCount, SDBFind **search);
   1.126 +/* lg_FindObjects continues a search for token and session objects 
   1.127 + * that match a template, obtaining additional object handles. */
   1.128 +CK_RV lg_FindObjects(SDB *sdb, SDBFind *search, 
   1.129 +    CK_OBJECT_HANDLE *phObject,CK_ULONG ulMaxObjectCount,
   1.130 +    CK_ULONG *pulObjectCount);
   1.131 +
   1.132 +/* lg_FindObjectsFinal finishes a search for token and session objects. */
   1.133 +CK_RV lg_FindObjectsFinal(SDB* lgdb, SDBFind *search);
   1.134 +
   1.135 +/* lg_CreateObject parses the template and create an object stored in the 
   1.136 + * DB that reflects the object specified in the template.  */
   1.137 +CK_RV lg_CreateObject(SDB *sdb, CK_OBJECT_HANDLE *handle,
   1.138 +			const CK_ATTRIBUTE *templ, CK_ULONG count);
   1.139 +
   1.140 +CK_RV lg_GetAttributeValue(SDB *sdb, CK_OBJECT_HANDLE object_id, 
   1.141 +				CK_ATTRIBUTE *template, CK_ULONG count);
   1.142 +CK_RV lg_SetAttributeValue(SDB *sdb, CK_OBJECT_HANDLE object_id, 
   1.143 +			const CK_ATTRIBUTE *template, CK_ULONG count);
   1.144 +CK_RV lg_DestroyObject(SDB *sdb, CK_OBJECT_HANDLE object_id);
   1.145 +
   1.146 +CK_RV lg_Close(SDB *sdb);
   1.147 +CK_RV lg_Reset(SDB *sdb);
   1.148 +
   1.149 +/*
   1.150 + * The old database doesn't share and doesn't support
   1.151 + * transactions.
   1.152 + */
   1.153 +CK_RV lg_Begin(SDB *sdb);
   1.154 +CK_RV lg_Commit(SDB *sdb);
   1.155 +CK_RV lg_Abort(SDB *sdb);
   1.156 +CK_RV lg_GetMetaData(SDB *sdb, const char *id, SECItem *item1, SECItem *item2);
   1.157 +CK_RV lg_PutMetaData(SDB *sdb, const char *id, 
   1.158 +			const SECItem *item1, const SECItem *item2);
   1.159 +
   1.160 +SEC_END_PROTOS
   1.161 +
   1.162 +#ifndef XP_UNIX
   1.163 +
   1.164 +#define NO_FORK_CHECK
   1.165 +
   1.166 +#endif
   1.167 +
   1.168 +#ifndef NO_FORK_CHECK
   1.169 +
   1.170 +extern PRBool lg_parentForkedAfterC_Initialize;
   1.171 +#define SKIP_AFTER_FORK(x) if (!lg_parentForkedAfterC_Initialize) x
   1.172 +
   1.173 +#else
   1.174 +
   1.175 +#define SKIP_AFTER_FORK(x) x
   1.176 +
   1.177 +#endif /* NO_FORK_CHECK */
   1.178 +
   1.179 +#endif /* _LGDB_H_ */
   1.180 +

mercurial