some attribute and session cleanup

This commit is contained in:
ian.mcgreer%sun.com 2001-11-05 17:18:48 +00:00
Родитель c423baa81d
Коммит cd5938ad76
5 изменённых файлов: 140 добавлений и 38 удалений

Просмотреть файл

@ -32,7 +32,7 @@
*/
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: ckhelper.c,v $ $Revision: 1.8 $ $Date: 2001-10-19 18:10:57 $ $Name: $";
static const char CVS_ID[] = "@(#) $RCSfile: ckhelper.c,v $ $Revision: 1.9 $ $Date: 2001-11-05 17:18:47 $ $Name: $";
#endif /* DEBUG */
#ifndef PKIT_H
@ -90,34 +90,38 @@ nssCKObject_GetAttributes
NSSSlot *slot
)
{
nssArenaMark *mark;
CK_SESSION_HANDLE hSession;
CK_ULONG i;
CK_RV ckrv;
PRStatus nssrv;
PRBool alloced = PR_FALSE;
hSession = session->handle;
if (arenaOpt) {
nssArenaMark *mark;
CK_SESSION_HANDLE hSession;
CK_ULONG i;
CK_RV ckrv;
PRStatus nssrv;
PRBool alloced = PR_FALSE;
hSession = session->handle;
if (arenaOpt) {
mark = nssArena_Mark(arenaOpt);
if (!mark) {
goto loser;
}
}
nssSession_EnterMonitor(session);
/* XXX kinda hacky, if the storage size is already in the first template
* item, then skip the alloc portion
*/
if (obj_template[0].ulValueLen == 0) {
}
nssSession_EnterMonitor(session);
/* XXX kinda hacky, if the storage size is already in the first template
* item, then skip the alloc portion
*/
if (obj_template[0].ulValueLen == 0) {
/* Get the storage size needed for each attribute */
ckrv = CKAPI(slot)->C_GetAttributeValue(hSession,
object, obj_template, count);
if (ckrv != CKR_OK) {
if (ckrv != CKR_OK &&
ckrv != CKR_ATTRIBUTE_TYPE_INVALID &&
ckrv != CKR_ATTRIBUTE_SENSITIVE)
{
nssSession_ExitMonitor(session);
/* set an error here */
goto loser;
}
/* Allocate memory for each attribute. */
for (i=0; i<count; i++) {
if ((CK_LONG)obj_template[i].ulValueLen <= 0) continue;
obj_template[i].pValue = nss_ZAlloc(arenaOpt,
obj_template[i].ulValueLen);
if (!obj_template[i].pValue) {
@ -126,25 +130,28 @@ nssCKObject_GetAttributes
}
}
alloced = PR_TRUE;
}
/* Obtain the actual attribute values. */
ckrv = CKAPI(slot)->C_GetAttributeValue(hSession,
object, obj_template, count);
nssSession_ExitMonitor(session);
if (ckrv != CKR_OK) {
}
/* Obtain the actual attribute values. */
ckrv = CKAPI(slot)->C_GetAttributeValue(hSession,
object, obj_template, count);
nssSession_ExitMonitor(session);
if (ckrv != CKR_OK &&
ckrv != CKR_ATTRIBUTE_TYPE_INVALID &&
ckrv != CKR_ATTRIBUTE_SENSITIVE)
{
/* set an error here */
goto loser;
}
if (alloced && arenaOpt) {
}
if (alloced && arenaOpt) {
nssrv = nssArena_Unmark(arenaOpt, mark);
if (nssrv != PR_SUCCESS) {
goto loser;
}
}
return PR_SUCCESS;
}
return PR_SUCCESS;
loser:
if (alloced) {
if (arenaOpt) {
if (alloced) {
if (arenaOpt) {
/* release all arena memory allocated before the failure. */
(void)nssArena_Release(arenaOpt, mark);
} else {
@ -154,8 +161,8 @@ loser:
nss_ZFreeIf(obj_template[j].pValue);
}
}
}
return PR_FAILURE;
}
return PR_FAILURE;
}
NSS_IMPLEMENT PRStatus
@ -230,3 +237,29 @@ nssCKObject_SetAttributes
}
}
/*
NSS_IMPLEMENT PRBool
nssCKObject_IsTokenObject
(
CK_OBJECT_HANDLE object
)
{
}
*/
NSS_IMPLEMENT PRBool
nssCKObject_IsTokenObjectTemplate
(
CK_ATTRIBUTE_PTR objectTemplate,
CK_ULONG otsize
)
{
CK_ULONG ul;
for (ul=0; ul<otsize; ul++) {
if (objectTemplate[ul].type == CKA_TOKEN) {
return (*((CK_BBOOL*)objectTemplate[ul].pValue) == CK_TRUE);
}
}
return PR_FALSE;
}

Просмотреть файл

@ -41,7 +41,7 @@
#define CKHELPER_H
#ifdef DEBUG
static const char CKHELPER_CVS_ID[] = "@(#) $RCSfile: ckhelper.h,v $ $Revision: 1.8 $ $Date: 2001-10-19 18:10:58 $ $Name: $";
static const char CKHELPER_CVS_ID[] = "@(#) $RCSfile: ckhelper.h,v $ $Revision: 1.9 $ $Date: 2001-11-05 17:18:47 $ $Name: $";
#endif /* DEBUG */
#ifdef NSS_3_4_CODE
@ -88,9 +88,11 @@ NSS_EXTERN_DATA const NSSItem g_ck_class_privkey;
*
* Convert a CK_ATTRIBUTE to an NSSItem.
*/
#define NSS_CK_ATTRIBUTE_TO_ITEM(attrib, item) \
(item)->data = (void *)(attrib)->pValue; \
(item)->size = (PRUint32)(attrib)->ulValueLen; \
#define NSS_CK_ATTRIBUTE_TO_ITEM(attrib, item) \
if ((CK_LONG)(attrib)->ulValueLen > 0) { \
(item)->data = (void *)(attrib)->pValue; \
(item)->size = (PRUint32)(attrib)->ulValueLen; \
}
/* NSS_CK_ATTRIBUTE_TO_UTF8(attrib, str)
*
@ -151,6 +153,13 @@ nssCKObject_SetAttributes
NSSSlot *slot
);
NSS_EXTERN PRBool
nssCKObject_IsTokenObjectTemplate
(
CK_ATTRIBUTE_PTR objectTemplate,
CK_ULONG otsize
);
PR_END_EXTERN_C
#endif /* CKHELPER_H */

Просмотреть файл

@ -32,7 +32,7 @@
*/
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: nss3hack.c,v $ $Revision: 1.1 $ $Date: 2001-10-11 16:33:38 $ $Name: $";
static const char CVS_ID[] = "@(#) $RCSfile: nss3hack.c,v $ $Revision: 1.2 $ $Date: 2001-11-05 17:18:48 $ $Name: $";
#endif /* DEBUG */
#ifndef PKIT_H
@ -67,6 +67,45 @@ nssSession_ImportNSS3Session(NSSArena *arenaOpt,
return rvSession;
}
NSS_IMPLEMENT nssSession *
nssSlot_CreateSession
(
NSSSlot *slot,
NSSArena *arenaOpt,
PRBool readWrite
)
{
nssSession *rvSession;
rvSession = nss_ZNEW(arenaOpt, nssSession);
if (!rvSession) {
return (nssSession *)NULL;
}
if (readWrite) {
rvSession->handle = PK11_GetRWSession(slot->pk11slot);
rvSession->isRW = PR_TRUE;
rvSession->slot = slot;
return rvSession;
} else {
return NULL;
}
}
NSS_IMPLEMENT PRStatus
nssSession_Destroy
(
nssSession *s
)
{
CK_RV ckrv = CKR_OK;
if (s) {
if (s->isRW) {
PK11_RestoreROSession(s->slot->pk11slot, s->handle);
}
nss_ZFreeIf(s);
}
return (ckrv == CKR_OK) ? PR_SUCCESS : PR_FAILURE;
}
static NSSSlot *
nssSlot_CreateFromPK11SlotInfo(NSSTrustDomain *td, PK11SlotInfo *nss3slot)
{
@ -117,6 +156,7 @@ nssToken_CreateFromPK11SlotInfo(NSSTrustDomain *td, PK11SlotInfo *nss3slot)
}
rvToken->slot = nssSlot_CreateFromPK11SlotInfo(td, nss3slot);
rvToken->slot->token = rvToken;
rvToken->defaultSession->slot = rvToken->slot;
return rvToken;
}

Просмотреть файл

@ -32,7 +32,7 @@
*/
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: slot.c,v $ $Revision: 1.9 $ $Date: 2001-10-11 16:33:38 $ $Name: $";
static const char CVS_ID[] = "@(#) $RCSfile: slot.c,v $ $Revision: 1.10 $ $Date: 2001-11-05 17:18:48 $ $Name: $";
#endif /* DEBUG */
#ifndef DEV_H
@ -438,6 +438,7 @@ nssSlot_SetPassword
return nssrv;
}
#ifdef PURE_STAN
NSS_IMPLEMENT nssSession *
nssSlot_CreateSession
(
@ -504,6 +505,7 @@ nssSession_Destroy
}
return (ckrv == CKR_OK) ? PR_SUCCESS : PR_FAILURE;
}
#endif
NSS_IMPLEMENT PRStatus
nssSession_EnterMonitor

Просмотреть файл

@ -32,7 +32,7 @@
*/
#ifdef DEBUG
static const char CVS_ID[] = "@(#) $RCSfile: token.c,v $ $Revision: 1.12 $ $Date: 2001-10-19 18:10:58 $ $Name: $";
static const char CVS_ID[] = "@(#) $RCSfile: token.c,v $ $Revision: 1.13 $ $Date: 2001-11-05 17:18:48 $ $Name: $";
#endif /* DEBUG */
#ifndef DEV_H
@ -241,16 +241,34 @@ nssToken_ImportObject
)
{
nssSession *session;
PRBool createdSession = PR_FALSE;
CK_OBJECT_HANDLE object;
CK_RV ckrv;
session = (sessionOpt) ? sessionOpt : tok->defaultSession;
if (nssCKObject_IsTokenObjectTemplate(objectTemplate, otsize)) {
if (sessionOpt) {
if (!nssSession_IsReadWrite(sessionOpt)) {
return CK_INVALID_HANDLE;
} else {
session = sessionOpt;
}
} else if (nssSession_IsReadWrite(tok->defaultSession)) {
session = tok->defaultSession;
} else {
session = nssSlot_CreateSession(tok->slot, NULL, PR_TRUE);
createdSession = PR_TRUE;
}
}
nssSession_EnterMonitor(session);
ckrv = CKAPI(tok->slot)->C_CreateObject(session->handle,
objectTemplate, otsize,
&object);
nssSession_ExitMonitor(session);
if (createdSession) {
nssSession_Destroy(session);
}
if (ckrv != CKR_OK) {
return CK_INVALID_KEY;
return CK_INVALID_HANDLE;
}
return object;
}