~ubuntu-branches/ubuntu/lucid/nss/lucid-security

« back to all changes in this revision

Viewing changes to nss/lib/ckfw/dbm/slot.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2013-11-15 08:08:08 UTC
  • mfrom: (1.2.7)
  • Revision ID: package-import@ubuntu.com-20131115080808-dba1asgnjl9tc66s
Tags: 3.15.3-0ubuntu0.10.04.1
* SECURITY UPDATE: New upstream release to fix multiple security issues
  and add TLSv1.2 support.
  - CVE-2013-1739
  - CVE-2013-1741
  - CVE-2013-5605
  - CVE-2013-5606
* Adjusted packaging for 3.15.3:
  - debian/patches/*: refreshed.
  - debian/patches/01_dont_build_nspr.patch: removed, changed build
    options in debian/rules instead.
  - debian/libnss3-1d.symbols: added new symbols.
  - debian/rules: updated for new source layout.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This Source Code Form is subject to the terms of the Mozilla Public
 
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
4
 
 
5
#include "ckdbm.h"
 
6
 
 
7
static CK_RV
 
8
nss_dbm_mdSlot_Initialize
 
9
(
 
10
  NSSCKMDSlot *mdSlot,
 
11
  NSSCKFWSlot *fwSlot,
 
12
  NSSCKMDInstance *mdInstance,                                    
 
13
  NSSCKFWInstance *fwInstance
 
14
)
 
15
{
 
16
  nss_dbm_slot_t *slot = (nss_dbm_slot_t *)mdSlot->etc;
 
17
  nss_dbm_instance_t *instance = (nss_dbm_instance_t *)mdInstance->etc;
 
18
  CK_RV rv = CKR_OK;
 
19
 
 
20
  slot->token_db = nss_dbm_db_open(instance->arena, fwInstance, slot->filename, 
 
21
                                   slot->flags, &rv);
 
22
  if( (nss_dbm_db_t *)NULL == slot->token_db ) {
 
23
    if( CKR_TOKEN_NOT_PRESENT == rv ) {
 
24
      /* This is not an error-- just means "the token isn't there" */
 
25
      rv = CKR_OK;
 
26
    }
 
27
  }
 
28
 
 
29
  return rv;
 
30
}
 
31
 
 
32
static void
 
33
nss_dbm_mdSlot_Destroy
 
34
(
 
35
  NSSCKMDSlot *mdSlot,
 
36
  NSSCKFWSlot *fwSlot,
 
37
  NSSCKMDInstance *mdInstance,                                    
 
38
  NSSCKFWInstance *fwInstance
 
39
)
 
40
{
 
41
  nss_dbm_slot_t *slot = (nss_dbm_slot_t *)mdSlot->etc;
 
42
 
 
43
  if( (nss_dbm_db_t *)NULL != slot->token_db ) {
 
44
    nss_dbm_db_close(slot->token_db);
 
45
    slot->token_db = (nss_dbm_db_t *)NULL;
 
46
  }
 
47
}
 
48
 
 
49
static NSSUTF8 *
 
50
nss_dbm_mdSlot_GetSlotDescription
 
51
(
 
52
  NSSCKMDSlot *mdSlot,
 
53
  NSSCKFWSlot *fwSlot,
 
54
  NSSCKMDInstance *mdInstance,                                    
 
55
  NSSCKFWInstance *fwInstance,
 
56
  CK_RV *pError
 
57
)
 
58
{
 
59
  return "Database";
 
60
}
 
61
 
 
62
static NSSUTF8 *
 
63
nss_dbm_mdSlot_GetManufacturerID
 
64
(
 
65
  NSSCKMDSlot *mdSlot,
 
66
  NSSCKFWSlot *fwSlot,
 
67
  NSSCKMDInstance *mdInstance,                                    
 
68
  NSSCKFWInstance *fwInstance,
 
69
  CK_RV *pError
 
70
)
 
71
{
 
72
  return "Berkeley";
 
73
}
 
74
 
 
75
static CK_BBOOL
 
76
nss_dbm_mdSlot_GetTokenPresent
 
77
(
 
78
  NSSCKMDSlot *mdSlot,
 
79
  NSSCKFWSlot *fwSlot,
 
80
  NSSCKMDInstance *mdInstance,                                    
 
81
  NSSCKFWInstance *fwInstance
 
82
)
 
83
{
 
84
  nss_dbm_slot_t *slot = (nss_dbm_slot_t *)mdSlot->etc;
 
85
 
 
86
  if( (nss_dbm_db_t *)NULL == slot->token_db ) {
 
87
    return CK_FALSE;
 
88
  } else {
 
89
    return CK_TRUE;
 
90
  }
 
91
}
 
92
 
 
93
static CK_BBOOL
 
94
nss_dbm_mdSlot_GetRemovableDevice
 
95
(
 
96
  NSSCKMDSlot *mdSlot,
 
97
  NSSCKFWSlot *fwSlot,
 
98
  NSSCKMDInstance *mdInstance,                                    
 
99
  NSSCKFWInstance *fwInstance
 
100
)
 
101
{
 
102
  /*
 
103
   * Well, this supports "tokens" (databases) that aren't there, so in
 
104
   * that sense they're removable.  It'd be nice to handle databases
 
105
   * that suddenly disappear (NFS-mounted home directories and network
 
106
   * errors, for instance) but that's a harder problem.  We'll say
 
107
   * we support removable devices, badly.
 
108
   */
 
109
 
 
110
  return CK_TRUE;
 
111
}
 
112
 
 
113
/* nss_dbm_mdSlot_GetHardwareSlot defaults to CK_FALSE */
 
114
/* 
 
115
 * nss_dbm_mdSlot_GetHardwareVersion
 
116
 * nss_dbm_mdSlot_GetFirmwareVersion
 
117
 *
 
118
 * These are kinda fuzzy concepts here.  I suppose we could return the
 
119
 * Berkeley DB version for one of them, if we had an actual number we
 
120
 * were confident in.  But mcom's "dbm" has been hacked enough that I
 
121
 * don't really know from what "real" version it stems..
 
122
 */
 
123
 
 
124
static NSSCKMDToken *
 
125
nss_dbm_mdSlot_GetToken
 
126
(
 
127
  NSSCKMDSlot *mdSlot,
 
128
  NSSCKFWSlot *fwSlot,
 
129
  NSSCKMDInstance *mdInstance,                                    
 
130
  NSSCKFWInstance *fwInstance,
 
131
  CK_RV *pError
 
132
)
 
133
{
 
134
  nss_dbm_slot_t *slot = (nss_dbm_slot_t *)mdSlot->etc;
 
135
  return nss_dbm_mdToken_factory(slot, pError);
 
136
}
 
137
 
 
138
NSS_IMPLEMENT NSSCKMDSlot *
 
139
nss_dbm_mdSlot_factory
 
140
(
 
141
  nss_dbm_instance_t *instance,
 
142
  char *filename,
 
143
  int flags,
 
144
  CK_RV *pError
 
145
)
 
146
{
 
147
  nss_dbm_slot_t *slot;
 
148
  NSSCKMDSlot *rv;
 
149
 
 
150
  slot = nss_ZNEW(instance->arena, nss_dbm_slot_t);
 
151
  if( (nss_dbm_slot_t *)NULL == slot ) {
 
152
    *pError = CKR_HOST_MEMORY;
 
153
    return (NSSCKMDSlot *)NULL;
 
154
  }
 
155
 
 
156
  slot->instance = instance;
 
157
  slot->filename = filename;
 
158
  slot->flags = flags;
 
159
  slot->token_db = (nss_dbm_db_t *)NULL;
 
160
 
 
161
  rv = nss_ZNEW(instance->arena, NSSCKMDSlot);
 
162
  if( (NSSCKMDSlot *)NULL == rv ) {
 
163
    *pError = CKR_HOST_MEMORY;
 
164
    return (NSSCKMDSlot *)NULL;
 
165
  }
 
166
 
 
167
  rv->etc = (void *)slot;
 
168
  rv->Initialize = nss_dbm_mdSlot_Initialize;
 
169
  rv->Destroy = nss_dbm_mdSlot_Destroy;
 
170
  rv->GetSlotDescription = nss_dbm_mdSlot_GetSlotDescription;
 
171
  rv->GetManufacturerID = nss_dbm_mdSlot_GetManufacturerID;
 
172
  rv->GetTokenPresent = nss_dbm_mdSlot_GetTokenPresent;
 
173
  rv->GetRemovableDevice = nss_dbm_mdSlot_GetRemovableDevice;
 
174
  /*  GetHardwareSlot */
 
175
  /*  GetHardwareVersion */
 
176
  /*  GetFirmwareVersion */
 
177
  rv->GetToken = nss_dbm_mdSlot_GetToken;
 
178
  rv->null = (void *)NULL;
 
179
 
 
180
  return rv;
 
181
}