~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * The contents of this file are subject to the Mozilla Public
 
3
 * License Version 1.1 (the "License"); you may not use this file
 
4
 * except in compliance with the License. You may obtain a copy of
 
5
 * the License at http://www.mozilla.org/MPL/
 
6
 * 
 
7
 * Software distributed under the License is distributed on an "AS
 
8
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
9
 * implied. See the License for the specific language governing
 
10
 * rights and limitations under the License.
 
11
 * 
 
12
 * The Original Code is the Netscape security libraries.
 
13
 * 
 
14
 * The Initial Developer of the Original Code is Netscape
 
15
 * Communications Corporation.  Portions created by Netscape are 
 
16
 * Copyright (C) 1994-2000 Netscape Communications Corporation.  All
 
17
 * Rights Reserved.
 
18
 * 
 
19
 * Contributor(s):
 
20
 * 
 
21
 * Alternatively, the contents of this file may be used under the
 
22
 * terms of the GNU General Public License Version 2 or later (the
 
23
 * "GPL"), in which case the provisions of the GPL are applicable 
 
24
 * instead of those above.  If you wish to allow use of your 
 
25
 * version of this file only under the terms of the GPL and not to
 
26
 * allow others to use your version of this file under the MPL,
 
27
 * indicate your decision by deleting the provisions above and
 
28
 * replace them with the notice and other provisions required by
 
29
 * the GPL.  If you do not delete the provisions above, a recipient
 
30
 * may use your version of this file under either the MPL or the
 
31
 * GPL.
 
32
 */
 
33
 
 
34
#ifdef DEBUG
 
35
static const char CVS_ID[] = "@(#) $RCSfile: slot.c,v $ $Revision: 1.1 $ $Date: 2000/05/15 20:39:57 $ $Name: FIREFOX_1_0_RELEASE $";
 
36
#endif /* DEBUG */
 
37
 
 
38
#include "ckdbm.h"
 
39
 
 
40
static CK_RV
 
41
nss_dbm_mdSlot_Initialize
 
42
(
 
43
  NSSCKMDSlot *mdSlot,
 
44
  NSSCKFWSlot *fwSlot,
 
45
  NSSCKMDInstance *mdInstance,                                    
 
46
  NSSCKFWInstance *fwInstance
 
47
)
 
48
{
 
49
  nss_dbm_slot_t *slot = (nss_dbm_slot_t *)mdSlot->etc;
 
50
  nss_dbm_instance_t *instance = (nss_dbm_instance_t *)mdInstance->etc;
 
51
  CK_RV rv = CKR_OK;
 
52
 
 
53
  slot->token_db = nss_dbm_db_open(instance->arena, fwInstance, slot->filename, 
 
54
                                   slot->flags, &rv);
 
55
  if( (nss_dbm_db_t *)NULL == slot->token_db ) {
 
56
    if( CKR_TOKEN_NOT_PRESENT == rv ) {
 
57
      /* This is not an error-- just means "the token isn't there" */
 
58
      rv = CKR_OK;
 
59
    }
 
60
  }
 
61
 
 
62
  return rv;
 
63
}
 
64
 
 
65
static void
 
66
nss_dbm_mdSlot_Destroy
 
67
(
 
68
  NSSCKMDSlot *mdSlot,
 
69
  NSSCKFWSlot *fwSlot,
 
70
  NSSCKMDInstance *mdInstance,                                    
 
71
  NSSCKFWInstance *fwInstance
 
72
)
 
73
{
 
74
  nss_dbm_slot_t *slot = (nss_dbm_slot_t *)mdSlot->etc;
 
75
 
 
76
  if( (nss_dbm_db_t *)NULL != slot->token_db ) {
 
77
    nss_dbm_db_close(slot->token_db);
 
78
    slot->token_db = (nss_dbm_db_t *)NULL;
 
79
  }
 
80
}
 
81
 
 
82
static NSSUTF8 *
 
83
nss_dbm_mdSlot_GetSlotDescription
 
84
(
 
85
  NSSCKMDSlot *mdSlot,
 
86
  NSSCKFWSlot *fwSlot,
 
87
  NSSCKMDInstance *mdInstance,                                    
 
88
  NSSCKFWInstance *fwInstance,
 
89
  CK_RV *pError
 
90
)
 
91
{
 
92
  return "Database";
 
93
}
 
94
 
 
95
static NSSUTF8 *
 
96
nss_dbm_mdSlot_GetManufacturerID
 
97
(
 
98
  NSSCKMDSlot *mdSlot,
 
99
  NSSCKFWSlot *fwSlot,
 
100
  NSSCKMDInstance *mdInstance,                                    
 
101
  NSSCKFWInstance *fwInstance,
 
102
  CK_RV *pError
 
103
)
 
104
{
 
105
  return "Berkeley";
 
106
}
 
107
 
 
108
static CK_BBOOL
 
109
nss_dbm_mdSlot_GetTokenPresent
 
110
(
 
111
  NSSCKMDSlot *mdSlot,
 
112
  NSSCKFWSlot *fwSlot,
 
113
  NSSCKMDInstance *mdInstance,                                    
 
114
  NSSCKFWInstance *fwInstance
 
115
)
 
116
{
 
117
  nss_dbm_slot_t *slot = (nss_dbm_slot_t *)mdSlot->etc;
 
118
 
 
119
  if( (nss_dbm_db_t *)NULL == slot->token_db ) {
 
120
    return CK_FALSE;
 
121
  } else {
 
122
    return CK_TRUE;
 
123
  }
 
124
}
 
125
 
 
126
static CK_BBOOL
 
127
nss_dbm_mdSlot_GetRemovableDevice
 
128
(
 
129
  NSSCKMDSlot *mdSlot,
 
130
  NSSCKFWSlot *fwSlot,
 
131
  NSSCKMDInstance *mdInstance,                                    
 
132
  NSSCKFWInstance *fwInstance
 
133
)
 
134
{
 
135
  /*
 
136
   * Well, this supports "tokens" (databases) that aren't there, so in
 
137
   * that sense they're removable.  It'd be nice to handle databases
 
138
   * that suddenly disappear (NFS-mounted home directories and network
 
139
   * errors, for instance) but that's a harder problem.  We'll say
 
140
   * we support removable devices, badly.
 
141
   */
 
142
 
 
143
  return CK_TRUE;
 
144
}
 
145
 
 
146
/* nss_dbm_mdSlot_GetHardwareSlot defaults to CK_FALSE */
 
147
/* 
 
148
 * nss_dbm_mdSlot_GetHardwareVersion
 
149
 * nss_dbm_mdSlot_GetFirmwareVersion
 
150
 *
 
151
 * These are kinda fuzzy concepts here.  I suppose we could return the
 
152
 * Berkeley DB version for one of them, if we had an actual number we
 
153
 * were confident in.  But mcom's "dbm" has been hacked enough that I
 
154
 * don't really know from what "real" version it stems..
 
155
 */
 
156
 
 
157
static NSSCKMDToken *
 
158
nss_dbm_mdSlot_GetToken
 
159
(
 
160
  NSSCKMDSlot *mdSlot,
 
161
  NSSCKFWSlot *fwSlot,
 
162
  NSSCKMDInstance *mdInstance,                                    
 
163
  NSSCKFWInstance *fwInstance,
 
164
  CK_RV *pError
 
165
)
 
166
{
 
167
  nss_dbm_slot_t *slot = (nss_dbm_slot_t *)mdSlot->etc;
 
168
  return nss_dbm_mdToken_factory(slot, pError);
 
169
}
 
170
 
 
171
NSS_IMPLEMENT NSSCKMDSlot *
 
172
nss_dbm_mdSlot_factory
 
173
(
 
174
  nss_dbm_instance_t *instance,
 
175
  char *filename,
 
176
  int flags,
 
177
  CK_RV *pError
 
178
)
 
179
{
 
180
  nss_dbm_slot_t *slot;
 
181
  NSSCKMDSlot *rv;
 
182
 
 
183
  slot = nss_ZNEW(instance->arena, nss_dbm_slot_t);
 
184
  if( (nss_dbm_slot_t *)NULL == slot ) {
 
185
    *pError = CKR_HOST_MEMORY;
 
186
    return (NSSCKMDSlot *)NULL;
 
187
  }
 
188
 
 
189
  slot->instance = instance;
 
190
  slot->filename = filename;
 
191
  slot->flags = flags;
 
192
  slot->token_db = (nss_dbm_db_t *)NULL;
 
193
 
 
194
  rv = nss_ZNEW(instance->arena, NSSCKMDSlot);
 
195
  if( (NSSCKMDSlot *)NULL == rv ) {
 
196
    *pError = CKR_HOST_MEMORY;
 
197
    return (NSSCKMDSlot *)NULL;
 
198
  }
 
199
 
 
200
  rv->etc = (void *)slot;
 
201
  rv->Initialize = nss_dbm_mdSlot_Initialize;
 
202
  rv->Destroy = nss_dbm_mdSlot_Destroy;
 
203
  rv->GetSlotDescription = nss_dbm_mdSlot_GetSlotDescription;
 
204
  rv->GetManufacturerID = nss_dbm_mdSlot_GetManufacturerID;
 
205
  rv->GetTokenPresent = nss_dbm_mdSlot_GetTokenPresent;
 
206
  rv->GetRemovableDevice = nss_dbm_mdSlot_GetRemovableDevice;
 
207
  /*  GetHardwareSlot */
 
208
  /*  GetHardwareVersion */
 
209
  /*  GetFirmwareVersion */
 
210
  rv->GetToken = nss_dbm_mdSlot_GetToken;
 
211
  rv->null = (void *)NULL;
 
212
 
 
213
  return rv;
 
214
}