Return less EINVAL.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18876 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2006-10-24 19:57:16 +00:00
parent b80776d43c
commit 77e4ca555d

View File

@@ -248,15 +248,15 @@ p11_mech_info(hx509_context context,
ret = P11FUNC(p, GetMechanismList, (slot->id, NULL_PTR, &i)); ret = P11FUNC(p, GetMechanismList, (slot->id, NULL_PTR, &i));
if (ret) { if (ret) {
hx509_set_error_string(context, 0, EINVAL, hx509_set_error_string(context, 0, HX509_PKCS11_NO_MECH,
"Failed to get mech list count for slot %d", "Failed to get mech list count for slot %d",
num); num);
return EINVAL; return HX509_PKCS11_NO_MECH;
} }
if (i == 0) { if (i == 0) {
hx509_set_error_string(context, 0, EINVAL, hx509_set_error_string(context, 0, HX509_PKCS11_NO_MECH,
"no mech supported for slot %d", num); "no mech supported for slot %d", num);
return EINVAL; return HX509_PKCS11_NO_MECH;
} }
slot->mechs.list = calloc(i, sizeof(slot->mechs.list[0])); slot->mechs.list = calloc(i, sizeof(slot->mechs.list[0]));
if (slot->mechs.list == NULL) { if (slot->mechs.list == NULL) {
@@ -267,10 +267,10 @@ p11_mech_info(hx509_context context,
slot->mechs.num = i; slot->mechs.num = i;
ret = P11FUNC(p, GetMechanismList, (slot->id, slot->mechs.list, &i)); ret = P11FUNC(p, GetMechanismList, (slot->id, slot->mechs.list, &i));
if (ret) { if (ret) {
hx509_set_error_string(context, 0, EINVAL, hx509_set_error_string(context, 0, HX509_PKCS11_NO_MECH,
"Failed to get mech list for slot %d", "Failed to get mech list for slot %d",
num); num);
return EINVAL; return HX509_PKCS11_NO_MECH;
} }
assert(i == slot->mechs.num); assert(i == slot->mechs.num);
@@ -291,10 +291,10 @@ p11_mech_info(hx509_context context,
ret = P11FUNC(p, GetMechanismInfo, (slot->id, slot->mechs.list[i], ret = P11FUNC(p, GetMechanismInfo, (slot->id, slot->mechs.list[i],
slot->mechs.infos[i])); slot->mechs.infos[i]));
if (ret) { if (ret) {
hx509_set_error_string(context, 0, EINVAL, hx509_set_error_string(context, 0, HX509_PKCS11_NO_MECH,
"Failed to get mech info for slot %d", "Failed to get mech info for slot %d",
num); num);
return EINVAL; return HX509_PKCS11_NO_MECH;
} }
} }
@@ -319,10 +319,10 @@ p11_init_slot(hx509_context context,
ret = P11FUNC(p, GetSlotInfo, (slot->id, &slot_info)); ret = P11FUNC(p, GetSlotInfo, (slot->id, &slot_info));
if (ret) { if (ret) {
hx509_set_error_string(context, 0, EINVAL, hx509_set_error_string(context, 0, HX509_PKCS11_TOKEN_CONFUSED,
"Failed to init PKCS11 slot %d", "Failed to init PKCS11 slot %d",
num); num);
return EINVAL; return HX509_PKCS11_TOKEN_CONFUSED;
} }
for (i = sizeof(slot_info.slotDescription) - 1; i > 0; i--) { for (i = sizeof(slot_info.slotDescription) - 1; i > 0; i--) {
@@ -341,7 +341,7 @@ p11_init_slot(hx509_context context,
ret = P11FUNC(p, GetTokenInfo, (slot->id, &token_info)); ret = P11FUNC(p, GetTokenInfo, (slot->id, &token_info));
if (ret) { if (ret) {
hx509_set_error_string(context, 0, EINVAL, hx509_set_error_string(context, 0, HX509_PKCS11_NO_TOKEN,
"Failed to init PKCS11 slot %d " "Failed to init PKCS11 slot %d "
"with error 0x08x", "with error 0x08x",
num, ret); num, ret);
@@ -392,11 +392,11 @@ p11_get_session(hx509_context context,
&slot->session)); &slot->session));
if (ret != CKR_OK) { if (ret != CKR_OK) {
if (context) if (context)
hx509_set_error_string(context, 0, EINVAL, hx509_set_error_string(context, 0, HX509_PKCS11_OPEN_SESSION,
"Failed to OpenSession for slot id %d " "Failed to OpenSession for slot id %d "
"with error: 0x%08x", "with error: 0x%08x",
(int)slot->id, ret); (int)slot->id, ret);
return EINVAL; return HX509_PKCS11_OPEN_SESSION;
} }
slot->flags |= P11_SESSION; slot->flags |= P11_SESSION;
@@ -452,12 +452,12 @@ p11_get_session(hx509_context context,
(unsigned char*)pin, strlen(pin))); (unsigned char*)pin, strlen(pin)));
if (ret != CKR_OK) { if (ret != CKR_OK) {
if (context) if (context)
hx509_set_error_string(context, 0, EINVAL, hx509_set_error_string(context, 0, HX509_PKCS11_LOGIN,
"Failed to login on slot id %d " "Failed to login on slot id %d "
"with error: 0x%08x", "with error: 0x%08x",
(int)slot->id, ret); (int)slot->id, ret);
p11_put_session(p, slot, slot->session); p11_put_session(p, slot, slot->session);
return EINVAL; return HX509_PKCS11_LOGIN;
} }
if (slot->pin == NULL) { if (slot->pin == NULL) {
slot->pin = strdup(pin); slot->pin = strdup(pin);
@@ -847,49 +847,49 @@ p11_init(hx509_context context,
p->dl_handle = dlopen(list, RTLD_NOW); p->dl_handle = dlopen(list, RTLD_NOW);
free(list); free(list);
if (p->dl_handle == NULL) { if (p->dl_handle == NULL) {
hx509_set_error_string(context, 0, EINVAL, ret = HX509_PKCS11_LOAD;
hx509_set_error_string(context, 0, ret,
"Failed to open %s: %s", list, dlerror()); "Failed to open %s: %s", list, dlerror());
ret = EINVAL; /* XXX */
goto out; goto out;
} }
getFuncs = dlsym(p->dl_handle, "C_GetFunctionList"); getFuncs = dlsym(p->dl_handle, "C_GetFunctionList");
if (getFuncs == NULL) { if (getFuncs == NULL) {
hx509_set_error_string(context, 0, EINVAL, ret = HX509_PKCS11_LOAD;
hx509_set_error_string(context, 0, ret,
"C_GetFunctionList missing in %s: %s", "C_GetFunctionList missing in %s: %s",
list, dlerror()); list, dlerror());
ret = EINVAL;
goto out; goto out;
} }
ret = (*getFuncs)(&p->funcs); ret = (*getFuncs)(&p->funcs);
if (ret) { if (ret) {
hx509_set_error_string(context, 0, EINVAL, ret = HX509_PKCS11_LOAD;
hx509_set_error_string(context, 0, ret,
"C_GetFunctionList failed in %s", list); "C_GetFunctionList failed in %s", list);
ret = EINVAL;
goto out; goto out;
} }
ret = P11FUNC(p, Initialize, (NULL_PTR)); ret = P11FUNC(p, Initialize, (NULL_PTR));
if (ret != CKR_OK) { if (ret != CKR_OK) {
hx509_set_error_string(context, 0, EINVAL, ret = HX509_PKCS11_TOKEN_CONFUSED;
hx509_set_error_string(context, 0, ret,
"Failed initialize the PKCS11 module"); "Failed initialize the PKCS11 module");
ret = EINVAL;
goto out; goto out;
} }
ret = P11FUNC(p, GetSlotList, (FALSE, NULL, &p->num_slots)); ret = P11FUNC(p, GetSlotList, (FALSE, NULL, &p->num_slots));
if (ret) { if (ret) {
hx509_set_error_string(context, 0, EINVAL, ret = HX509_PKCS11_TOKEN_CONFUSED;
hx509_set_error_string(context, 0, ret,
"Failed to get number of PKCS11 slots"); "Failed to get number of PKCS11 slots");
ret = EINVAL;
goto out; goto out;
} }
if (p->num_slots == 0) { if (p->num_slots == 0) {
hx509_set_error_string(context, 0, HX509_PKCS11_NO_SLOT,
"Selected PKCS11 module have no slots");
ret = HX509_PKCS11_NO_SLOT; ret = HX509_PKCS11_NO_SLOT;
hx509_set_error_string(context, 0, ret,
"Selected PKCS11 module have no slots");
goto out; goto out;
} }
@@ -908,10 +908,10 @@ p11_init(hx509_context context,
ret = P11FUNC(p, GetSlotList, (FALSE, slot_ids, &p->num_slots)); ret = P11FUNC(p, GetSlotList, (FALSE, slot_ids, &p->num_slots));
if (ret) { if (ret) {
free(slot_ids); free(slot_ids);
hx509_set_error_string(context, 0, EINVAL, hx509_set_error_string(context, 0, HX509_PKCS11_TOKEN_CONFUSED,
"Failed getting slot-list from " "Failed getting slot-list from "
"PKCS11 module"); "PKCS11 module");
ret = EINVAL; ret = HX509_PKCS11_TOKEN_CONFUSED;
goto out; goto out;
} }