Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
dbinit.c File Reference
#include <ctype.h>
#include "seccomon.h"
#include "prinit.h"
#include "prprf.h"
#include "prmem.h"
#include "pratom.h"
#include "pcertt.h"
#include "lowkeyi.h"
#include "pcert.h"
#include "cdbhdl.h"
#include "keydbi.h"
#include "pkcs11i.h"

Go to the source code of this file.

Classes

struct  RDBStr

Defines

#define RDBLIB   SHLIB_PREFIX"rdb."SHLIB_SUFFIX
#define DB_RDB   ((DBTYPE) 0xff)
#define RDB_RDONLY   1
#define RDB_RDWR   2
#define RDB_CREATE   4

Functions

static char * sftk_certdb_name_cb (void *arg, int dbVersion)
static char * sftk_keydb_name_cb (void *arg, int dbVersion)
const char * sftk_EvaluateConfigDir (const char *configdir, char **appName)
static CK_RV sftk_OpenCertDB (const char *configdir, const char *prefix, PRBool readOnly, NSSLOWCERTCertDBHandle **certdbPtr)
static CK_RV sftk_OpenKeyDB (const char *configdir, const char *prefix, PRBool readOnly, NSSLOWKEYDBHandle **keydbPtr)
CK_RV sftk_DBInit (const char *configdir, const char *certPrefix, const char *keyPrefix, PRBool readOnly, PRBool noCertDB, PRBool noKeyDB, PRBool forceOpen, NSSLOWCERTCertDBHandle **certdbPtr, NSSLOWKEYDBHandle **keydbPtr)
NSSLOWCERTCertDBHandle * sftk_getCertDB (SFTKSlot *slot)
NSSLOWKEYDBHandle * sftk_getKeyDB (SFTKSlot *slot)
void sftk_freeCertDB (NSSLOWCERTCertDBHandle *certHandle)
void sftk_freeKeyDB (NSSLOWKEYDBHandle *keyHandle)
static int rdbmapflags (int flags)
DBrdbopen (const char *appName, const char *prefix, const char *type, int flags, int *status)
PRBool db_IsRDB (DB *db)
int db_BeginTransaction (DB *db)
int db_FinishTransaction (DB *db, PRBool abort)
int db_InitComplete (DB *db)
SECStatus db_Copy (DB *dest, DB *src)

Variables

static rdbfunc sftk_rdbfunc = NULL
static rdbstatusfunc sftk_rdbstatusfunc = NULL

Define Documentation

#define DB_RDB   ((DBTYPE) 0xff)

Definition at line 365 of file dbinit.c.

#define RDB_CREATE   4

Definition at line 368 of file dbinit.c.

#define RDB_RDONLY   1

Definition at line 366 of file dbinit.c.

#define RDB_RDWR   2

Definition at line 367 of file dbinit.c.

#define RDBLIB   SHLIB_PREFIX"rdb."SHLIB_SUFFIX

Definition at line 313 of file dbinit.c.


Function Documentation

Definition at line 393 of file dbinit.c.

{
    struct RDBStr *rdb = (struct RDBStr *)db;
    if (db->type != DB_RDB) {
       return 0;
    }

    return rdb->xactstart(db);
}

Here is the caller graph for this function:

SECStatus db_Copy ( DB dest,
DB src 
)

Definition at line 434 of file dbinit.c.

{
    int ret;
    DBT key,data;
    ret = (*src->seq)(src, &key, &data, R_FIRST);
    if (ret)  {
       return SECSuccess;
    }

    do {
       (void)(*dest->put)(dest,&key,&data, R_NOOVERWRITE);
    } while ( (*src->seq)(src, &key, &data, R_NEXT) == 0);
    (void)(*dest->sync)(dest,0);

    return SECSuccess;
}

Here is the caller graph for this function:

int db_FinishTransaction ( DB db,
PRBool  abort 
)

Definition at line 404 of file dbinit.c.

{
    struct RDBStr *rdb = (struct RDBStr *)db;
    if (db->type != DB_RDB) {
       return 0;
    }

    return rdb->xactdone(db, abort);
}

Here is the caller graph for this function:

int db_InitComplete ( DB db)

Definition at line 415 of file dbinit.c.

{
    struct RDBStr *rdb = (struct RDBStr *)db;
    if (db->type != DB_RDB) {
       return 0;
    }
    /* we should have addes a version number to the RDBS structure. Since we
     * didn't, we detect that we have and 'extended' structure if the rdbstatus
     * func exists */
    if (!sftk_rdbstatusfunc) {
       return 0;
    }

    return rdb->dbinitcomplete(db);
}

Here is the caller graph for this function:

PRBool db_IsRDB ( DB db)

Definition at line 387 of file dbinit.c.

{
    return (PRBool) db->type == DB_RDB;
}
static int rdbmapflags ( int  flags) [static]

Definition at line 371 of file dbinit.c.

                       {
   switch (flags) {
   case NO_RDONLY:
       return RDB_RDONLY;
   case NO_RDWR:
       return RDB_RDWR;
   case NO_CREATE:
       return RDB_CREATE;
   default:
       break;
   }
   return 0;
}

Here is the caller graph for this function:

DB* rdbopen ( const char *  appName,
const char *  prefix,
const char *  type,
int  flags,
int status 
)

Definition at line 315 of file dbinit.c.

{
    PRLibrary *lib;
    DB *db;

    if (sftk_rdbfunc) {
       db = (*sftk_rdbfunc)(appName,prefix,type,rdbmapflags(flags));
       if (!db && status && sftk_rdbstatusfunc) {
           *status = (*sftk_rdbstatusfunc)();
       }
       return db;
    }

    /*
     * try to open the library.
     */
    lib = PR_LoadLibrary(RDBLIB);

    if (!lib) {
       return NULL;
    }

    /* get the entry points */
    sftk_rdbstatusfunc = (rdbstatusfunc) PR_FindSymbol(lib,"rdbstatus");
    sftk_rdbfunc = (rdbfunc) PR_FindSymbol(lib,"rdbopen");
    if (sftk_rdbfunc) {
       db = (*sftk_rdbfunc)(appName,prefix,type,rdbmapflags(flags));
       if (!db && status && sftk_rdbstatusfunc) {
           *status = (*sftk_rdbstatusfunc)();
       }
       return db;
    }

    /* couldn't find the entry point, unload the library and fail */
    PR_UnloadLibrary(lib);
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* sftk_certdb_name_cb ( void arg,
int  dbVersion 
) [static]

Definition at line 55 of file dbinit.c.

{
    const char *configdir = (const char *)arg;
    const char *dbver;
    char *smpname = NULL;
    char *dbname = NULL;

    switch (dbVersion) {
      case 8:
       dbver = "8";
       break;
      case 7:
       dbver = "7";
       break;
      case 6:
       dbver = "6";
       break;
      case 5:
       dbver = "5";
       break;
      case 4:
      default:
       dbver = "";
       break;
    }

    /* make sure we return something allocated with PORT_ so we have properly
     * matched frees at the end */
    smpname = PR_smprintf(CERT_DB_FMT, configdir, dbver);
    if (smpname) {
       dbname = PORT_Strdup(smpname);
       PR_smprintf_free(smpname);
    }
    return dbname;
}

Here is the call graph for this function:

Here is the caller graph for this function:

CK_RV sftk_DBInit ( const char *  configdir,
const char *  certPrefix,
const char *  keyPrefix,
PRBool  readOnly,
PRBool  noCertDB,
PRBool  noKeyDB,
PRBool  forceOpen,
NSSLOWCERTCertDBHandle **  certdbPtr,
NSSLOWKEYDBHandle **  keydbPtr 
)

Definition at line 231 of file dbinit.c.

{
    CK_RV crv = CKR_OK;


    if (!noCertDB) {
       crv = sftk_OpenCertDB(configdir, certPrefix, readOnly, certdbPtr);
       if (crv != CKR_OK) {
           if (!forceOpen) goto loser;
           crv = CKR_OK;
       }
    }
    if (!noKeyDB) {

       crv = sftk_OpenKeyDB(configdir, keyPrefix, readOnly, keydbPtr);
       if (crv != CKR_OK) {
           if (!forceOpen) goto loser;
           crv = CKR_OK;
       }
    }


loser:
    return crv;
}

Here is the call graph for this function:

const char* sftk_EvaluateConfigDir ( const char *  configdir,
char **  appName 
)

Definition at line 124 of file dbinit.c.

{
    if (PORT_Strncmp(configdir, MULTIACCESS, sizeof(MULTIACCESS)-1) == 0) {
       char *cdir;

       *appName = PORT_Strdup(configdir+sizeof(MULTIACCESS)-1);
       if (*appName == NULL) {
           return configdir;
       }
       cdir = *appName;
       while (*cdir && *cdir != ':') {
           cdir++;
       }
       if (*cdir == ':') {
          *cdir = 0;
          cdir++;
       }
       configdir = cdir;
    }
    return configdir;
}

Here is the call graph for this function:

void sftk_freeCertDB ( NSSLOWCERTCertDBHandle *  certHandle)

Definition at line 289 of file dbinit.c.

{
   PRInt32 ref = PR_AtomicDecrement(&certHandle->ref);
   if (ref == 0) {
       nsslowcert_ClosePermCertDB(certHandle);
       PORT_Free(certHandle);
   }
}

Here is the call graph for this function:

void sftk_freeKeyDB ( NSSLOWKEYDBHandle *  keyHandle)

Definition at line 299 of file dbinit.c.

{
   PRInt32 ref = PR_AtomicDecrement(&keyHandle->ref);
   if (ref == 0) {
       nsslowkey_CloseKeyDB(keyHandle);
   }
}

Here is the call graph for this function:

NSSLOWCERTCertDBHandle* sftk_getCertDB ( SFTKSlot *  slot)

Definition at line 261 of file dbinit.c.

{
    NSSLOWCERTCertDBHandle *certHandle;

    PZ_Lock(slot->slotLock);
    certHandle = slot->certDB;
    if (certHandle) {
       PR_AtomicIncrement(&certHandle->ref);
    }
    PZ_Unlock(slot->slotLock);
    return certHandle;
}

Here is the call graph for this function:

NSSLOWKEYDBHandle* sftk_getKeyDB ( SFTKSlot *  slot)

Definition at line 275 of file dbinit.c.

{
    NSSLOWKEYDBHandle *keyHandle;

    PZ_Lock(slot->slotLock);
    keyHandle = slot->keyDB;
    if (keyHandle) {
       PR_AtomicIncrement(&keyHandle->ref);
    }
    PZ_Unlock(slot->slotLock);
    return keyHandle;
}

Here is the call graph for this function:

static char* sftk_keydb_name_cb ( void arg,
int  dbVersion 
) [static]

Definition at line 92 of file dbinit.c.

{
    const char *configdir = (const char *)arg;
    const char *dbver;
    char *smpname = NULL;
    char *dbname = NULL;
    
    switch (dbVersion) {
      case 4:
       dbver = "4";
       break;
      case 3:
       dbver = "3";
       break;
      case 1:
       dbver = "1";
       break;
      case 2:
      default:
       dbver = "";
       break;
    }

    smpname = PR_smprintf(KEY_DB_FMT, configdir, dbver);
    if (smpname) {
       dbname = PORT_Strdup(smpname);
       PR_smprintf_free(smpname);
    }
    return dbname;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static CK_RV sftk_OpenCertDB ( const char *  configdir,
const char *  prefix,
PRBool  readOnly,
NSSLOWCERTCertDBHandle **  certdbPtr 
) [static]

Definition at line 147 of file dbinit.c.

{
    NSSLOWCERTCertDBHandle *certdb = NULL;
    CK_RV        crv = CKR_NETSCAPE_CERTDB_FAILED;
    SECStatus    rv;
    char * name = NULL;
    char * appName = NULL;

    if (prefix == NULL) {
       prefix = "";
    }

    configdir = sftk_EvaluateConfigDir(configdir, &appName);

    name = PR_smprintf("%s" PATH_SEPARATOR "%s",configdir,prefix);
    if (name == NULL) goto loser;

    certdb = (NSSLOWCERTCertDBHandle*)PORT_ZAlloc(sizeof(NSSLOWCERTCertDBHandle));
    if (certdb == NULL) 
       goto loser;

    certdb->ref = 1;
/* fix when we get the DB in */
    rv = nsslowcert_OpenCertDB(certdb, readOnly, appName, prefix,
                            sftk_certdb_name_cb, (void *)name, PR_FALSE);
    if (rv == SECSuccess) {
       crv = CKR_OK;
       *certdbPtr = certdb;
       certdb = NULL;
    }
loser: 
    if (certdb) PR_Free(certdb);
    if (name) PR_smprintf_free(name);
    if (appName) PORT_Free(appName);
    return crv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static CK_RV sftk_OpenKeyDB ( const char *  configdir,
const char *  prefix,
PRBool  readOnly,
NSSLOWKEYDBHandle **  keydbPtr 
) [static]

Definition at line 186 of file dbinit.c.

{
    NSSLOWKEYDBHandle *keydb;
    char * name = NULL;
    char * appName = NULL;

    if (prefix == NULL) {
       prefix = "";
    }
    configdir = sftk_EvaluateConfigDir(configdir, &appName);

    name = PR_smprintf("%s" PATH_SEPARATOR "%s",configdir,prefix);    
    if (name == NULL) 
       return CKR_HOST_MEMORY;
    keydb = nsslowkey_OpenKeyDB(readOnly, appName, prefix, 
                                   sftk_keydb_name_cb, (void *)name);
    PR_smprintf_free(name);
    if (appName) PORT_Free(appName);
    if (keydb == NULL)
       return CKR_NETSCAPE_KEYDB_FAILED;
    *keydbPtr = keydb;

    return CKR_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 309 of file dbinit.c.

Definition at line 310 of file dbinit.c.