Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
ckdbm.h File Reference
#include "nssckmdt.h"
#include "nssckfw.h"
#include "base.h"
#include "ckt.h"
#include "mcom_db.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  nss_dbm_db_struct
struct  nss_dbm_dbt_struct
struct  nss_dbm_instance_struct
struct  nss_dbm_slot_struct
struct  nss_dbm_token_struct
struct  nss_dbm_dbt_node
struct  nss_dbm_session_struct
struct  nss_dbm_object_struct
struct  nss_dbm_find_struct

Defines

#define CKDBM_H

Typedefs

typedef struct nss_dbm_db_struct
typedef struct nss_dbm_dbt_struct
typedef struct nss_dbm_instance_struct
typedef struct nss_dbm_slot_struct
typedef struct nss_dbm_token_struct
typedef struct nss_dbm_session_struct
typedef struct nss_dbm_object_struct
typedef struct nss_dbm_find_struct

Functions

NSS_EXTERN NSSCKMDSlot * nss_dbm_mdSlot_factory (nss_dbm_instance_t *instance, char *filename, int flags, CK_RV *pError)
NSS_EXTERN NSSCKMDToken * nss_dbm_mdToken_factory (nss_dbm_slot_t *slot, CK_RV *pError)
NSS_EXTERN NSSCKMDSession * nss_dbm_mdSession_factory (nss_dbm_token_t *token, NSSCKFWSession *fwSession, NSSCKFWInstance *fwInstance, CK_BBOOL rw, CK_RV *pError)
NSS_EXTERN NSSCKMDObject * nss_dbm_mdObject_factory (nss_dbm_object_t *object, CK_RV *pError)
NSS_EXTERN NSSCKMDFindObjects * nss_dbm_mdFindObjects_factory (nss_dbm_find_t *find, CK_RV *pError)
NSS_EXTERN nss_dbm_db_t * nss_dbm_db_open (NSSArena *arena, NSSCKFWInstance *fwInstance, char *filename, int flags, CK_RV *pError)
NSS_EXTERN void nss_dbm_db_close (nss_dbm_db_t *db)
NSS_EXTERN CK_VERSION nss_dbm_db_get_format_version (nss_dbm_db_t *db)
NSS_EXTERN CK_RV nss_dbm_db_set_label (nss_dbm_db_t *db, NSSUTF8 *label)
NSS_EXTERN NSSUTF8nss_dbm_db_get_label (nss_dbm_db_t *db, NSSArena *arena, CK_RV *pError)
NSS_EXTERN CK_RV nss_dbm_db_delete_object (nss_dbm_dbt_t *dbt)
NSS_EXTERN nss_dbm_dbt_t * nss_dbm_db_create_object (NSSArena *arena, nss_dbm_db_t *db, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulAttributeCount, CK_RV *pError, CK_ULONG *pdbrv)
NSS_EXTERN CK_RV nss_dbm_db_find_objects (nss_dbm_find_t *find, nss_dbm_db_t *db, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulAttributeCount, CK_ULONG *pdbrv)
NSS_EXTERN CK_BBOOL nss_dbm_db_object_still_exists (nss_dbm_dbt_t *dbt)
NSS_EXTERN CK_ULONG nss_dbm_db_get_object_attribute_count (nss_dbm_dbt_t *dbt, CK_RV *pError, CK_ULONG *pdbrv)
NSS_EXTERN CK_RV nss_dbm_db_get_object_attribute_types (nss_dbm_dbt_t *dbt, CK_ATTRIBUTE_TYPE_PTR typeArray, CK_ULONG ulCount, CK_ULONG *pdbrv)
NSS_EXTERN CK_ULONG nss_dbm_db_get_object_attribute_size (nss_dbm_dbt_t *dbt, CK_ATTRIBUTE_TYPE type, CK_RV *pError, CK_ULONG *pdbrv)
NSS_EXTERN NSSItem * nss_dbm_db_get_object_attribute (nss_dbm_dbt_t *dbt, NSSArena *arena, CK_ATTRIBUTE_TYPE type, CK_RV *pError, CK_ULONG *pdbrv)
NSS_EXTERN CK_RV nss_dbm_db_set_object_attribute (nss_dbm_dbt_t *dbt, CK_ATTRIBUTE_TYPE type, NSSItem *value, CK_ULONG *pdbrv)

Variables

NSS_EXTERN_DATA NSSCKMDInstance nss_dbm_mdInstance

Class Documentation

struct nss_dbm_db_struct

Definition at line 67 of file ckdbm.h.

Collaboration diagram for nss_dbm_db_struct:
Class Members
NSSCKFWMutex * crustylock
DB * db
struct nss_dbm_dbt_struct

Definition at line 73 of file ckdbm.h.

Collaboration diagram for nss_dbm_dbt_struct:
Class Members
DBT dbt
nss_dbm_db_t * my_db
struct nss_dbm_instance_struct

Definition at line 79 of file ckdbm.h.

Class Members
NSSArena * arena
char ** filenames
int * flags
CK_ULONG nSlots
struct nss_dbm_slot_struct

Definition at line 87 of file ckdbm.h.

Collaboration diagram for nss_dbm_slot_struct:
Class Members
char * filename
int flags
nss_dbm_instance_t * instance
nss_dbm_db_t * token_db
struct nss_dbm_token_struct

Definition at line 95 of file ckdbm.h.

Class Members
NSSArena * arena
NSSUTF8 * label
nss_dbm_db_t * session_db
nss_dbm_slot_t * slot
struct nss_dbm_dbt_node

Definition at line 102 of file ckdbm.h.

Collaboration diagram for nss_dbm_dbt_node:
Class Members
nss_dbm_dbt_t * dbt
struct nss_dbm_dbt_node * next
struct nss_dbm_session_struct

Definition at line 108 of file ckdbm.h.

Collaboration diagram for nss_dbm_session_struct:
Class Members
NSSArena * arena
CK_ULONG deviceError
NSSCKFWMutex * list_lock
struct nss_dbm_dbt_node * session_objects
nss_dbm_token_t * token
struct nss_dbm_object_struct

Definition at line 117 of file ckdbm.h.

Class Members
NSSArena * arena
nss_dbm_dbt_t * handle
struct nss_dbm_find_struct

Definition at line 123 of file ckdbm.h.

Collaboration diagram for nss_dbm_find_struct:
Class Members
NSSArena * arena
struct nss_dbm_dbt_node * found
NSSCKFWMutex * list_lock

Define Documentation

Definition at line 42 of file ckdbm.h.


Typedef Documentation

typedef struct nss_dbm_db_struct

Definition at line 66 of file ckdbm.h.

typedef struct nss_dbm_dbt_struct

Definition at line 72 of file ckdbm.h.

typedef struct nss_dbm_find_struct

Definition at line 122 of file ckdbm.h.

typedef struct nss_dbm_instance_struct

Definition at line 78 of file ckdbm.h.

typedef struct nss_dbm_object_struct

Definition at line 116 of file ckdbm.h.

typedef struct nss_dbm_session_struct

Definition at line 107 of file ckdbm.h.

typedef struct nss_dbm_slot_struct

Definition at line 86 of file ckdbm.h.

typedef struct nss_dbm_token_struct

Definition at line 94 of file ckdbm.h.


Function Documentation

NSS_EXTERN void nss_dbm_db_close ( nss_dbm_db_t *  db)

Definition at line 95 of file db.c.

{
  if( (NSSCKFWMutex *)NULL != db->crustylock ) {
    (void)NSSCKFWMutex_Destroy(db->crustylock);
  }

  if( (DB *)NULL != db->db ) {
    (void)db->db->close(db->db);
  }

  nss_ZFreeIf(db);
}

Here is the caller graph for this function:

NSS_EXTERN nss_dbm_dbt_t* nss_dbm_db_create_object ( NSSArena *  arena,
nss_dbm_db_t *  db,
CK_ATTRIBUTE_PTR  pTemplate,
CK_ULONG  ulAttributeCount,
CK_RV pError,
CK_ULONG pdbrv 
)

Definition at line 555 of file db.c.

{
  NSSArena *tmparena = (NSSArena *)NULL;
  nss_dbm_dbt_t *rv = (nss_dbm_dbt_t *)NULL;
  DBT object;

  rv = nss_ZNEW(arena, nss_dbm_dbt_t);
  if( (nss_dbm_dbt_t *)NULL == rv ) {
    *pError = CKR_HOST_MEMORY;
    return (nss_dbm_dbt_t *)NULL;
  }

  rv->my_db = db;
  rv->dbt.size = sizeof(struct handle);
  rv->dbt.data = nss_ZAlloc(arena, rv->dbt.size);
  if( (void *)NULL == rv->dbt.data ) {
    *pError = CKR_HOST_MEMORY;
    return (nss_dbm_dbt_t *)NULL;
  }

  *pdbrv = nss_dbm_db_new_handle(db, &rv->dbt, pError);
  if( 0 != *pdbrv ) {
    return (nss_dbm_dbt_t *)NULL;
  }

  tmparena = NSSArena_Create();
  if( (NSSArena *)NULL == tmparena ) {
    *pError = CKR_HOST_MEMORY;
    return (nss_dbm_dbt_t *)NULL;
  }

  *pError = nss_dbm_db_wrap_object(tmparena, pTemplate, ulAttributeCount, &object);
  if( CKR_OK != *pError ) {
    return (nss_dbm_dbt_t *)NULL;
  }
  
  /* Locked region */
  {
    *pError = NSSCKFWMutex_Lock(db->crustylock);
    if( CKR_OK != *pError ) {
      goto loser;
    }

    *pdbrv = db->db->put(db->db, &rv->dbt, &object, 0);
    if( 0 != *pdbrv ) {
      *pError = CKR_DEVICE_ERROR;
    }

    (void)db->db->sync(db->db, 0);

    (void)NSSCKFWMutex_Unlock(db->crustylock);
  }

 loser:  
  if( (NSSArena *)NULL != tmparena ) {
    (void)NSSArena_Destroy(tmparena);
  }

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN CK_RV nss_dbm_db_delete_object ( nss_dbm_dbt_t *  dbt)

Definition at line 240 of file db.c.

{
  CK_RV rv;
  int dbrv;

  /* Locked region */
  {
    rv = NSSCKFWMutex_Lock(dbt->my_db->crustylock);
    if( CKR_OK != rv ) {
      return rv;
    }

    dbrv = dbt->my_db->db->del(dbt->my_db->db, &dbt->dbt, 0);
    if( 0 != dbrv ) {
      rv = CKR_DEVICE_ERROR;
      goto done;
    }

    dbrv = dbt->my_db->db->sync(dbt->my_db->db, 0);
    if( 0 != dbrv ) {
      rv = CKR_DEVICE_ERROR;
      goto done;
    }

  done:
    (void)NSSCKFWMutex_Unlock(dbt->my_db->crustylock);
  }

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN CK_RV nss_dbm_db_find_objects ( nss_dbm_find_t *  find,
nss_dbm_db_t *  db,
CK_ATTRIBUTE_PTR  pTemplate,
CK_ULONG  ulAttributeCount,
CK_ULONG pdbrv 
)

Definition at line 626 of file db.c.

{
  CK_RV rv = CKR_OK;

  if( (nss_dbm_db_t *)NULL != db ) {
    DBT k, v;

    rv = NSSCKFWMutex_Lock(db->crustylock);
    if( CKR_OK != rv ) {
      return rv;
    }

    *pdbrv = db->db->seq(db->db, &k, &v, R_FIRST);
    while( 0 == *pdbrv ) {
      CK_ULONG i, j;
      NSSArena *tmparena = (NSSArena *)NULL;
      CK_ULONG ulac;
      CK_ATTRIBUTE_PTR pt;

      if( (k.size < 4) || (0 != memcmp(k.data, PREFIX_OBJECT, 4)) ) {
        goto nomatch;
      }

      tmparena = NSSArena_Create();

      rv = nss_dbm_db_unwrap_object(tmparena, &v, &pt, &ulac);
      if( CKR_OK != rv ) {
        goto loser;
      }

      for( i = 0; i < ulAttributeCount; i++ ) {
        for( j = 0; j < ulac; j++ ) {
          if( pTemplate[i].type == pt[j].type ) {
            if( pTemplate[i].ulValueLen != pt[j].ulValueLen ) {
              goto nomatch;
            }
            if( 0 != memcmp(pTemplate[i].pValue, pt[j].pValue, pt[j].ulValueLen) ) {
              goto nomatch;
            }
            break;
          }
        }
        if( j == ulac ) {
          goto nomatch;
        }
      }

      /* entire template matches */
      {
        struct nss_dbm_dbt_node *node;

        node = nss_ZNEW(find->arena, struct nss_dbm_dbt_node);
        if( (struct nss_dbm_dbt_node *)NULL == node ) {
          rv = CKR_HOST_MEMORY;
          goto loser;
        }

        node->dbt = nss_ZNEW(find->arena, nss_dbm_dbt_t);
        if( (nss_dbm_dbt_t *)NULL == node->dbt ) {
          rv = CKR_HOST_MEMORY;
          goto loser;
        }
        
        node->dbt->dbt.size = k.size;
        node->dbt->dbt.data = nss_ZAlloc(find->arena, k.size);
        if( (void *)NULL == node->dbt->dbt.data ) {
          rv = CKR_HOST_MEMORY;
          goto loser;
        }

        (void)memcpy(node->dbt->dbt.data, k.data, k.size);

        node->dbt->my_db = db;

        node->next = find->found;
        find->found = node;
      }

    nomatch:
      if( (NSSArena *)NULL != tmparena ) {
        (void)NSSArena_Destroy(tmparena);
      }
      *pdbrv = db->db->seq(db->db, &k, &v, R_NEXT);
    }

    if( *pdbrv < 0 ) {
      rv = CKR_DEVICE_ERROR;
      goto loser;
    }

    rv = CKR_OK;

  loser:
    (void)NSSCKFWMutex_Unlock(db->crustylock);
  }

  return rv;
}

Here is the caller graph for this function:

Definition at line 112 of file db.c.

{
  CK_VERSION rv;
  DBT k, v;
  int dbrv;
  char buffer[64];

  rv.major = rv.minor = 0;

  k.data = PREFIX_METADATA "FormatVersion";
  k.size = nssUTF8_Size((NSSUTF8 *)k.data, (PRStatus *)NULL);
  (void)memset(&v, 0, sizeof(v));

  /* Locked region */ 
  {
    if( CKR_OK != NSSCKFWMutex_Lock(db->crustylock) ) {
      return rv;
    }

    dbrv = db->db->get(db->db, &k, &v, 0);
    if( dbrv == 0 ) {
      CK_ULONG major = 0, minor = 0;
      (void)PR_sscanf(v.data, "%ld.%ld", &major, &minor);
      rv.major = major;
      rv.minor = minor;
    } else if( dbrv > 0 ) {
      (void)PR_snprintf(buffer, sizeof(buffer), "%ld.%ld", nss_dbm_db_format_version.major,
                        nss_dbm_db_format_version.minor);
      v.data = buffer;
      v.size = nssUTF8_Size((NSSUTF8 *)v.data, (PRStatus *)NULL);
      dbrv = db->db->put(db->db, &k, &v, 0);
      (void)db->db->sync(db->db, 0);
      rv = nss_dbm_db_format_version;
    } else {
      /* No error return.. */
      ;
    }

    (void)NSSCKFWMutex_Unlock(db->crustylock);
  }

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN NSSUTF8* nss_dbm_db_get_label ( nss_dbm_db_t *  db,
NSSArena *  arena,
CK_RV pError 
)

Definition at line 198 of file db.c.

{
  NSSUTF8 *rv = (NSSUTF8 *)NULL;
  DBT k, v;
  int dbrv;

  k.data = PREFIX_METADATA "Label";
  k.size = nssUTF8_Size((NSSUTF8 *)k.data, (PRStatus *)NULL);

  /* Locked region */ 
  {
    if( CKR_OK != NSSCKFWMutex_Lock(db->crustylock) ) {
      return rv;
    }

    dbrv = db->db->get(db->db, &k, &v, 0);
    if( 0 == dbrv ) {
      rv = nssUTF8_Duplicate((NSSUTF8 *)v.data, arena);
      if( (NSSUTF8 *)NULL == rv ) {
        *pError = CKR_HOST_MEMORY;
      }
    } else if( dbrv > 0 ) {
      /* Just return null */
      ;
    } else {
      *pError = CKR_DEVICE_ERROR;
      ;
    }


    (void)NSSCKFWMutex_Unlock(db->crustylock);
  }

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN NSSItem* nss_dbm_db_get_object_attribute ( nss_dbm_dbt_t *  dbt,
NSSArena *  arena,
CK_ATTRIBUTE_TYPE  type,
CK_RV pError,
CK_ULONG pdbrv 
)

Definition at line 905 of file db.c.

{
  NSSItem *rv = (NSSItem *)NULL;
  DBT object;
  CK_ULONG i;
  NSSArena *tmp = NSSArena_Create();
  CK_ATTRIBUTE_PTR pTemplate;
  CK_ULONG ulAttributeCount;

  /* Locked region */
  {
    *pError = NSSCKFWMutex_Lock(dbt->my_db->crustylock);
    if( CKR_OK != *pError ) {
      goto loser;
    }

    *pdbrv = dbt->my_db->db->get(dbt->my_db->db, &dbt->dbt, &object, 0);
    if( 0 == *pdbrv ) {
      ;
    } else if( *pdbrv > 0 ) {
      *pError = CKR_OBJECT_HANDLE_INVALID;
      goto done;
    } else {
      *pError = CKR_DEVICE_ERROR;
      goto done;
    }

    *pError = nss_dbm_db_unwrap_object(tmp, &object, &pTemplate, &ulAttributeCount);
    if( CKR_OK != *pError ) {
      goto done;
    }

    for( i = 0; i < ulAttributeCount; i++ ) {
      if( type == pTemplate[i].type ) {
        rv = nss_ZNEW(arena, NSSItem);
        if( (NSSItem *)NULL == rv ) {
          *pError = CKR_HOST_MEMORY;
          goto done;
        }
        rv->size = pTemplate[i].ulValueLen;
        rv->data = nss_ZAlloc(arena, rv->size);
        if( (void *)NULL == rv->data ) {
          *pError = CKR_HOST_MEMORY;
          goto done;
        }
        (void)memcpy(rv->data, pTemplate[i].pValue, rv->size);
        break;
      }
    }
    if( ulAttributeCount == i ) {
      *pError = CKR_ATTRIBUTE_TYPE_INVALID;
      goto done;
    }

  done:
    (void)NSSCKFWMutex_Unlock(dbt->my_db->crustylock);
  }

 loser:
  if( (NSSArena *)NULL != tmp ) {
    NSSArena_Destroy(tmp);
  }

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN CK_ULONG nss_dbm_db_get_object_attribute_count ( nss_dbm_dbt_t *  dbt,
CK_RV pError,
CK_ULONG pdbrv 
)

Definition at line 761 of file db.c.

{
  CK_ULONG rv = 0;
  DBT object;
  CK_ULONG *pulData;

  /* Locked region */
  {
    *pError = NSSCKFWMutex_Lock(dbt->my_db->crustylock);
    if( CKR_OK != *pError ) {
      return rv;
    }

    *pdbrv = dbt->my_db->db->get(dbt->my_db->db, &dbt->dbt, &object, 0);
    if( 0 == *pdbrv ) {
      ;
    } else if( *pdbrv > 0 ) {
      *pError = CKR_OBJECT_HANDLE_INVALID;
      goto done;
    } else {
      *pError = CKR_DEVICE_ERROR;
      goto done;
    }

    pulData = (CK_ULONG *)object.data;
    rv = ntohl(pulData[0]);

  done:
    (void)NSSCKFWMutex_Unlock(dbt->my_db->crustylock);
  }

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN CK_ULONG nss_dbm_db_get_object_attribute_size ( nss_dbm_dbt_t *  dbt,
CK_ATTRIBUTE_TYPE  type,
CK_RV pError,
CK_ULONG pdbrv 
)

Definition at line 852 of file db.c.

{
  CK_ULONG rv = 0;
  DBT object;
  CK_ULONG *pulData;
  CK_ULONG n, i;

  /* Locked region */
  {
    *pError = NSSCKFWMutex_Lock(dbt->my_db->crustylock);
    if( CKR_OK != *pError ) {
      return rv;
    }

    *pdbrv = dbt->my_db->db->get(dbt->my_db->db, &dbt->dbt, &object, 0);
    if( 0 == *pdbrv ) {
      ;
    } else if( *pdbrv > 0 ) {
      *pError = CKR_OBJECT_HANDLE_INVALID;
      goto done;
    } else {
      *pError = CKR_DEVICE_ERROR;
      goto done;
    }

    pulData = (CK_ULONG *)object.data;
    n = ntohl(pulData[0]);

    for( i = 0; i < n; i++ ) {
      if( type == ntohl(pulData[1 + i*3]) ) {
        rv = ntohl(pulData[2 + i*3]);
      }
    }

    if( i == n ) {
      *pError = CKR_ATTRIBUTE_TYPE_INVALID;
      goto done;
    }

  done:
    (void)NSSCKFWMutex_Unlock(dbt->my_db->crustylock);
  }

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN CK_RV nss_dbm_db_get_object_attribute_types ( nss_dbm_dbt_t *  dbt,
CK_ATTRIBUTE_TYPE_PTR  typeArray,
CK_ULONG  ulCount,
CK_ULONG pdbrv 
)

Definition at line 801 of file db.c.

{
  CK_RV rv = CKR_OK;
  DBT object;
  CK_ULONG *pulData;
  CK_ULONG n, i;

  /* Locked region */
  {
    rv = NSSCKFWMutex_Lock(dbt->my_db->crustylock);
    if( CKR_OK != rv ) {
      return rv;
    }

    *pdbrv = dbt->my_db->db->get(dbt->my_db->db, &dbt->dbt, &object, 0);
    if( 0 == *pdbrv ) {
      ;
    } else if( *pdbrv > 0 ) {
      rv = CKR_OBJECT_HANDLE_INVALID;
      goto done;
    } else {
      rv = CKR_DEVICE_ERROR;
      goto done;
    }

    pulData = (CK_ULONG *)object.data;
    n = ntohl(pulData[0]);

    if( ulCount < n ) {
      rv = CKR_BUFFER_TOO_SMALL;
      goto done;
    }

    for( i = 0; i < n; i++ ) {
      typeArray[i] = ntohl(pulData[1 + i*3]);
    }

  done:
    (void)NSSCKFWMutex_Unlock(dbt->my_db->crustylock);
  }

  return rv;
}

Here is the caller graph for this function:

Definition at line 733 of file db.c.

{
  CK_BBOOL rv;
  CK_RV ckrv;
  int dbrv;
  DBT object;

  ckrv = NSSCKFWMutex_Lock(dbt->my_db->crustylock);
  if( CKR_OK != ckrv ) {
    return CK_FALSE;
  }

  dbrv = dbt->my_db->db->get(dbt->my_db->db, &dbt->dbt, &object, 0);
  if( 0 == dbrv ) {
    rv = CK_TRUE;
  } else {
    rv = CK_FALSE;
  }

  (void)NSSCKFWMutex_Unlock(dbt->my_db->crustylock);

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN nss_dbm_db_t* nss_dbm_db_open ( NSSArena *  arena,
NSSCKFWInstance *  fwInstance,
char *  filename,
int  flags,
CK_RV pError 
)

Definition at line 55 of file db.c.

{
  nss_dbm_db_t *rv;
  CK_VERSION db_version;

  rv = nss_ZNEW(arena, nss_dbm_db_t);
  if( (nss_dbm_db_t *)NULL == rv ) {
    *pError = CKR_HOST_MEMORY;
    return (nss_dbm_db_t *)NULL;
  }

  rv->db = dbopen(filename, flags, 0600, DB_HASH, (const void *)NULL);
  if( (DB *)NULL == rv->db ) {
    *pError = CKR_TOKEN_NOT_PRESENT;
    return (nss_dbm_db_t *)NULL;
  }

  rv->crustylock = NSSCKFWInstance_CreateMutex(fwInstance, arena, pError);
  if( (NSSCKFWMutex *)NULL == rv->crustylock ) {
    return (nss_dbm_db_t *)NULL;
  }

  db_version = nss_dbm_db_get_format_version(rv);
  if( db_version.major != nss_dbm_db_format_version.major ) {
    nss_dbm_db_close(rv);
    *pError = CKR_TOKEN_NOT_RECOGNIZED;
    return (nss_dbm_db_t *)NULL;
  }

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN CK_RV nss_dbm_db_set_label ( nss_dbm_db_t *  db,
NSSUTF8 label 
)

Definition at line 160 of file db.c.

{
  CK_RV rv;
  DBT k, v;
  int dbrv;

  k.data = PREFIX_METADATA "Label";
  k.size = nssUTF8_Size((NSSUTF8 *)k.data, (PRStatus *)NULL);
  v.data = label;
  v.size = nssUTF8_Size((NSSUTF8 *)v.data, (PRStatus *)NULL);

  /* Locked region */ 
  {
    if( CKR_OK != NSSCKFWMutex_Lock(db->crustylock) ) {
      return rv;
    }

    dbrv = db->db->put(db->db, &k, &v, 0);
    if( 0 != dbrv ) {
      rv = CKR_DEVICE_ERROR;
    }

    dbrv = db->db->sync(db->db, 0);
    if( 0 != dbrv ) {
      rv = CKR_DEVICE_ERROR;
    }

    (void)NSSCKFWMutex_Unlock(db->crustylock);
  }

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN CK_RV nss_dbm_db_set_object_attribute ( nss_dbm_dbt_t *  dbt,
CK_ATTRIBUTE_TYPE  type,
NSSItem *  value,
CK_ULONG pdbrv 
)

Definition at line 979 of file db.c.

{
  CK_RV rv = CKR_OK;
  DBT object;
  CK_ULONG i;
  NSSArena *tmp = NSSArena_Create();
  CK_ATTRIBUTE_PTR pTemplate;
  CK_ULONG ulAttributeCount;

  /* Locked region */
  {
    rv = NSSCKFWMutex_Lock(dbt->my_db->crustylock);
    if( CKR_OK != rv ) {
      goto loser;
    }

    *pdbrv = dbt->my_db->db->get(dbt->my_db->db, &dbt->dbt, &object, 0);
    if( 0 == *pdbrv ) {
      ;
    } else if( *pdbrv > 0 ) {
      rv = CKR_OBJECT_HANDLE_INVALID;
      goto done;
    } else {
      rv = CKR_DEVICE_ERROR;
      goto done;
    }

    rv = nss_dbm_db_unwrap_object(tmp, &object, &pTemplate, &ulAttributeCount);
    if( CKR_OK != rv ) {
      goto done;
    }

    for( i = 0; i < ulAttributeCount; i++ ) {
      if( type == pTemplate[i].type ) {
        /* Replacing an existing attribute */
        pTemplate[i].ulValueLen = value->size;
        pTemplate[i].pValue = value->data;
        break;
      }
    }

    if( i == ulAttributeCount ) {
      /* Adding a new attribute */
      CK_ATTRIBUTE_PTR npt = nss_ZNEWARRAY(tmp, CK_ATTRIBUTE, ulAttributeCount+1);
      if( (CK_ATTRIBUTE_PTR)NULL == npt ) {
        rv = CKR_DEVICE_ERROR;
        goto done;
      }

      for( i = 0; i < ulAttributeCount; i++ ) {
        npt[i] = pTemplate[i];
      }

      npt[ulAttributeCount].type = type;
      npt[ulAttributeCount].ulValueLen = value->size;
      npt[ulAttributeCount].pValue = value->data;

      pTemplate = npt;
      ulAttributeCount++;
    }

    rv = nss_dbm_db_wrap_object(tmp, pTemplate, ulAttributeCount, &object);
    if( CKR_OK != rv ) {
      goto done;
    }

    *pdbrv = dbt->my_db->db->put(dbt->my_db->db, &dbt->dbt, &object, 0);
    if( 0 != *pdbrv ) {
      rv = CKR_DEVICE_ERROR;
      goto done;
    }

    (void)dbt->my_db->db->sync(dbt->my_db->db, 0);

  done:
    (void)NSSCKFWMutex_Unlock(dbt->my_db->crustylock);
  }

 loser:
  if( (NSSArena *)NULL != tmp ) {
    NSSArena_Destroy(tmp);
  }

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN NSSCKMDFindObjects* nss_dbm_mdFindObjects_factory ( nss_dbm_find_t *  find,
CK_RV pError 
)

Definition at line 151 of file find.c.

{
  NSSCKMDFindObjects *rv;

  rv = nss_ZNEW(find->arena, NSSCKMDFindObjects);
  if( (NSSCKMDFindObjects *)NULL == rv ) {
    *pError = CKR_HOST_MEMORY;
    return (NSSCKMDFindObjects *)NULL;
  }

  rv->etc = (void *)find;
  rv->Final = nss_dbm_mdFindObjects_Final;
  rv->Next = nss_dbm_mdFindObjects_Next;

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN NSSCKMDObject* nss_dbm_mdObject_factory ( nss_dbm_object_t *  object,
CK_RV pError 
)

Definition at line 182 of file object.c.

{
  NSSCKMDObject *rv;

  rv = nss_ZNEW(object->arena, NSSCKMDObject);
  if( (NSSCKMDObject *)NULL == rv ) {
    *pError = CKR_HOST_MEMORY;
    return (NSSCKMDObject *)NULL;
  }

  rv->etc = (void *)object;
  rv->Finalize = nss_dbm_mdObject_Finalize;
  rv->Destroy = nss_dbm_mdObject_Destroy;
  /*  IsTokenObject can be deferred */
  rv->GetAttributeCount = nss_dbm_mdObject_GetAttributeCount;
  rv->GetAttributeTypes = nss_dbm_mdObject_GetAttributeTypes;
  rv->GetAttributeSize = nss_dbm_mdObject_GetAttributeSize;
  rv->GetAttribute = nss_dbm_mdObject_GetAttribute;
  rv->SetAttribute = nss_dbm_mdObject_SetAttribute;
  /*  GetObjectSize can be deferred */

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN NSSCKMDSession* nss_dbm_mdSession_factory ( nss_dbm_token_t *  token,
NSSCKFWSession *  fwSession,
NSSCKFWInstance *  fwInstance,
CK_BBOOL  rw,
CK_RV pError 
)

Definition at line 252 of file session.c.

{
  NSSArena *arena;
  nss_dbm_session_t *session;
  NSSCKMDSession *rv;

  arena = NSSCKFWSession_GetArena(fwSession, pError);

  session = nss_ZNEW(arena, nss_dbm_session_t);
  if( (nss_dbm_session_t *)NULL == session ) {
    *pError = CKR_HOST_MEMORY;
    return (NSSCKMDSession *)NULL;
  }

  rv = nss_ZNEW(arena, NSSCKMDSession);
  if( (NSSCKMDSession *)NULL == rv ) {
    *pError = CKR_HOST_MEMORY;
    return (NSSCKMDSession *)NULL;
  }

  session->arena = arena;
  session->token = token;
  session->list_lock = NSSCKFWInstance_CreateMutex(fwInstance, arena, pError);
  if( (NSSCKFWMutex *)NULL == session->list_lock ) {
    return (NSSCKMDSession *)NULL;
  }

  rv->etc = (void *)session;
  rv->Close = nss_dbm_mdSession_Close;
  rv->GetDeviceError = nss_dbm_mdSession_GetDeviceError;
  /*  Login isn't needed */
  /*  Logout isn't needed */
  /*  InitPIN is irrelevant */
  /*  SetPIN is irrelevant */
  /*  GetOperationStateLen is irrelevant */
  /*  GetOperationState is irrelevant */
  /*  SetOperationState is irrelevant */
  rv->CreateObject = nss_dbm_mdSession_CreateObject;
  /*  CopyObject isn't needed; the framework will use CreateObject */
  rv->FindObjectsInit = nss_dbm_mdSession_FindObjectsInit;
  rv->null = NULL;

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN NSSCKMDSlot* nss_dbm_mdSlot_factory ( nss_dbm_instance_t *  instance,
char *  filename,
int  flags,
CK_RV pError 
)

Definition at line 176 of file slot.c.

{
  nss_dbm_slot_t *slot;
  NSSCKMDSlot *rv;

  slot = nss_ZNEW(instance->arena, nss_dbm_slot_t);
  if( (nss_dbm_slot_t *)NULL == slot ) {
    *pError = CKR_HOST_MEMORY;
    return (NSSCKMDSlot *)NULL;
  }

  slot->instance = instance;
  slot->filename = filename;
  slot->flags = flags;
  slot->token_db = (nss_dbm_db_t *)NULL;

  rv = nss_ZNEW(instance->arena, NSSCKMDSlot);
  if( (NSSCKMDSlot *)NULL == rv ) {
    *pError = CKR_HOST_MEMORY;
    return (NSSCKMDSlot *)NULL;
  }

  rv->etc = (void *)slot;
  rv->Initialize = nss_dbm_mdSlot_Initialize;
  rv->Destroy = nss_dbm_mdSlot_Destroy;
  rv->GetSlotDescription = nss_dbm_mdSlot_GetSlotDescription;
  rv->GetManufacturerID = nss_dbm_mdSlot_GetManufacturerID;
  rv->GetTokenPresent = nss_dbm_mdSlot_GetTokenPresent;
  rv->GetRemovableDevice = nss_dbm_mdSlot_GetRemovableDevice;
  /*  GetHardwareSlot */
  /*  GetHardwareVersion */
  /*  GetFirmwareVersion */
  rv->GetToken = nss_dbm_mdSlot_GetToken;
  rv->null = (void *)NULL;

  return rv;
}

Here is the caller graph for this function:

NSS_EXTERN NSSCKMDToken* nss_dbm_mdToken_factory ( nss_dbm_slot_t *  slot,
CK_RV pError 
)

Definition at line 265 of file token.c.

{
  nss_dbm_token_t *token;
  NSSCKMDToken *rv;

  token = nss_ZNEW(slot->instance->arena, nss_dbm_token_t);
  if( (nss_dbm_token_t *)NULL == token ) {
    *pError = CKR_HOST_MEMORY;
    return (NSSCKMDToken *)NULL;
  }

  rv = nss_ZNEW(slot->instance->arena, NSSCKMDToken);
  if( (NSSCKMDToken *)NULL == rv ) {
    *pError = CKR_HOST_MEMORY;
    return (NSSCKMDToken *)NULL;
  }

  token->slot = slot;

  rv->etc = (void *)token;
  rv->Setup = nss_dbm_mdToken_Setup;
  rv->Invalidate = nss_dbm_mdToken_Invalidate;
  rv->InitToken = nss_dbm_mdToken_InitToken;
  rv->GetLabel = nss_dbm_mdToken_GetLabel;
  rv->GetManufacturerID = nss_dbm_mdToken_GetManufacturerID;
  rv->GetModel = nss_dbm_mdToken_GetModel;
  /*  GetSerialNumber is irrelevant */
  /*  GetHasRNG defaults to CK_FALSE */
  rv->GetIsWriteProtected = nss_dbm_mdToken_GetIsWriteProtected;
  /*  GetLoginRequired defaults to CK_FALSE */
  /*  GetUserPinInitialized defaults to CK_FALSE */
  /*  GetRestoreKeyNotNeeded is irrelevant */
  /*  GetHasClockOnToken defaults to CK_FALSE */
  /*  GetHasProtectedAuthenticationPath defaults to CK_FALSE */
  /*  GetSupportsDualCryptoOperations is irrelevant */
  rv->GetMaxSessionCount = nss_dbm_mdToken_effectively_infinite;
  rv->GetMaxRwSessionCount = nss_dbm_mdToken_effectively_infinite;
  /*  GetMaxPinLen is irrelevant */
  /*  GetMinPinLen is irrelevant */
  /*  GetTotalPublicMemory defaults to CK_UNAVAILABLE_INFORMATION */
  /*  GetFreePublicMemory defaults to CK_UNAVAILABLE_INFORMATION */
  /*  GetTotalPrivateMemory defaults to CK_UNAVAILABLE_INFORMATION */
  /*  GetFreePrivateMemory defaults to CK_UNAVAILABLE_INFORMATION */
  rv->GetHardwareVersion = nss_dbm_mdToken_GetHardwareVersion;
  /*  GetFirmwareVersion is irrelevant */
  /*  GetUTCTime is irrelevant */
  rv->OpenSession = nss_dbm_mdToken_OpenSession;
  rv->null = NULL;

  return rv;
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 64 of file ckdbm.h.