163
165
nssSession *session;
164
166
CK_SLOT_INFO slotInfo;
166
/* permanent slots are always present */
168
/* permanent slots are always present unless they're disabled */
167
169
if (nssSlot_IsPermanent(slot)) {
170
return !PK11_IsDisabled(slot->pk11slot);
170
172
/* avoid repeated calls to check token status within set interval */
171
173
if (within_token_delay_period(slot)) {
172
return (PRBool)((slot->ckFlags & CKF_TOKEN_PRESENT) != 0);
174
return ((slot->ckFlags & CKF_TOKEN_PRESENT) != 0);
175
177
/* First obtain the slot info */
188
190
/* check for the presence of the token */
189
191
if ((slot->ckFlags & CKF_TOKEN_PRESENT) == 0) {
190
192
if (!slot->token) {
191
/* token was ne'er present */
193
/* token was never present */
194
196
session = nssToken_GetDefaultSession(slot->token);
195
nssSession_EnterMonitor(session);
196
/* token is not present */
197
if (session->handle != CK_INVALID_SESSION) {
198
/* session is valid, close and invalidate it */
199
CKAPI(epv)->C_CloseSession(session->handle);
200
session->handle = CK_INVALID_SESSION;
198
nssSession_EnterMonitor(session);
199
/* token is not present */
200
if (session->handle != CK_INVALID_SESSION) {
201
/* session is valid, close and invalidate it */
202
CKAPI(epv)->C_CloseSession(session->handle);
203
session->handle = CK_INVALID_SESSION;
205
nssSession_ExitMonitor(session);
202
nssSession_ExitMonitor(session);
203
207
if (slot->token->base.name[0] != 0) {
204
208
/* notify the high-level cache that the token is removed */
205
209
slot->token->base.name[0] = 0; /* XXX */
214
218
* has been removed and reinserted.
216
220
session = nssToken_GetDefaultSession(slot->token);
217
nssSession_EnterMonitor(session);
218
if (session->handle != CK_INVALID_SESSION) {
219
CK_SESSION_INFO sessionInfo;
220
ckrv = CKAPI(epv)->C_GetSessionInfo(session->handle, &sessionInfo);
221
if (ckrv != CKR_OK) {
222
/* session is screwy, close and invalidate it */
223
CKAPI(epv)->C_CloseSession(session->handle);
224
session->handle = CK_INVALID_SESSION;
227
nssSession_ExitMonitor(session);
228
/* token not removed, finished */
229
if (session->handle != CK_INVALID_SESSION) {
232
/* the token has been removed, and reinserted, or the slot contains
233
* a token it doesn't recognize. invalidate all the old
234
* information we had on this token, if we can't refresh, clear
235
* the present flag */
236
nssToken_NotifyCertsNotVisible(slot->token);
237
nssToken_Remove(slot->token);
238
/* token has been removed, need to refresh with new session */
239
nssrv = nssSlot_Refresh(slot);
240
if (nssrv != PR_SUCCESS) {
241
slot->token->base.name[0] = 0; /* XXX */
242
slot->ckFlags &= ~CKF_TOKEN_PRESENT;
222
nssSession_EnterMonitor(session);
223
if (session->handle != CK_INVALID_SESSION) {
224
CK_SESSION_INFO sessionInfo;
225
ckrv = CKAPI(epv)->C_GetSessionInfo(session->handle, &sessionInfo);
226
if (ckrv != CKR_OK) {
227
/* session is screwy, close and invalidate it */
228
CKAPI(epv)->C_CloseSession(session->handle);
229
session->handle = CK_INVALID_SESSION;
232
nssSession_ExitMonitor(session);
233
/* token not removed, finished */
234
if (session->handle != CK_INVALID_SESSION)
237
/* the token has been removed, and reinserted, or the slot contains
238
* a token it doesn't recognize. invalidate all the old
239
* information we had on this token, if we can't refresh, clear
240
* the present flag */
241
nssToken_NotifyCertsNotVisible(slot->token);
242
nssToken_Remove(slot->token);
243
/* token has been removed, need to refresh with new session */
244
nssrv = nssSlot_Refresh(slot);
245
if (nssrv != PR_SUCCESS) {
246
slot->token->base.name[0] = 0; /* XXX */
247
slot->ckFlags &= ~CKF_TOKEN_PRESENT;
249
253
NSS_IMPLEMENT void *