246 /* |
246 /* |
247 * Fill out the URI structure. We do not accept duplicit |
247 * Fill out the URI structure. We do not accept duplicit |
248 * attributes. |
248 * attributes. |
249 */ |
249 */ |
250 if (strcmp(name, PK11_TOKEN) == 0) |
250 if (strcmp(name, PK11_TOKEN) == 0) |
|
251 { |
251 if (uri_struct->token == NULL) |
252 if (uri_struct->token == NULL) |
252 { |
253 { |
253 if ((uri_struct->token = strdup(l2)) == NULL) |
254 if ((uri_struct->token = strdup(l2)) == NULL) |
254 goto no_mem; |
255 goto no_mem; |
255 } |
256 } |
256 else |
257 else |
257 goto bad_uri; |
258 goto bad_uri; |
|
259 } |
258 else if (strcmp(name, PK11_MANUF) == 0) |
260 else if (strcmp(name, PK11_MANUF) == 0) |
|
261 { |
259 if (uri_struct->manuf == NULL) |
262 if (uri_struct->manuf == NULL) |
260 { |
263 { |
261 if ((uri_struct->manuf = strdup(l2)) == NULL) |
264 if ((uri_struct->manuf = strdup(l2)) == NULL) |
262 goto no_mem; |
265 goto no_mem; |
263 } |
266 } |
264 else |
267 else |
265 goto bad_uri; |
268 goto bad_uri; |
|
269 } |
266 else if (strcmp(name, PK11_SERIAL) == 0) |
270 else if (strcmp(name, PK11_SERIAL) == 0) |
|
271 { |
267 if (uri_struct->serial == NULL) |
272 if (uri_struct->serial == NULL) |
268 { |
273 { |
269 if ((uri_struct->serial = strdup(l2)) == NULL) |
274 if ((uri_struct->serial = strdup(l2)) == NULL) |
270 goto no_mem; |
275 goto no_mem; |
271 } |
276 } |
272 else |
277 else |
273 goto bad_uri; |
278 goto bad_uri; |
|
279 } |
274 else if (strcmp(name, PK11_MODEL) == 0) |
280 else if (strcmp(name, PK11_MODEL) == 0) |
|
281 { |
275 if (uri_struct->model == NULL) |
282 if (uri_struct->model == NULL) |
276 { |
283 { |
277 if ((uri_struct->model = strdup(l2)) == NULL) |
284 if ((uri_struct->model = strdup(l2)) == NULL) |
278 goto no_mem; |
285 goto no_mem; |
279 } |
286 } |
280 else |
287 else |
281 goto bad_uri; |
288 goto bad_uri; |
|
289 } |
282 else if (strcmp(name, PK11_OBJECT) == 0) |
290 else if (strcmp(name, PK11_OBJECT) == 0) |
|
291 { |
283 if (uri_struct->object == NULL) |
292 if (uri_struct->object == NULL) |
284 { |
293 { |
285 if ((uri_struct->object = strdup(l2)) == NULL) |
294 if ((uri_struct->object = strdup(l2)) == NULL) |
286 goto no_mem; |
295 goto no_mem; |
287 } |
296 } |
288 else |
297 else |
289 goto bad_uri; |
298 goto bad_uri; |
|
299 } |
290 else if (strcmp(name, PK11_OBJECTTYPE) == 0) |
300 else if (strcmp(name, PK11_OBJECTTYPE) == 0) |
|
301 { |
291 if (uri_struct->objecttype == NULL) |
302 if (uri_struct->objecttype == NULL) |
292 { |
303 { |
293 uri_struct->objecttype = strdup(l2); |
304 uri_struct->objecttype = strdup(l2); |
294 if (uri_struct->objecttype == NULL) |
305 if (uri_struct->objecttype == NULL) |
295 goto no_mem; |
306 goto no_mem; |
296 } |
307 } |
297 else |
308 else |
298 goto bad_uri; |
309 goto bad_uri; |
|
310 } |
299 else if (strcmp(name, PK11_ASKPASS) == 0) |
311 else if (strcmp(name, PK11_ASKPASS) == 0) |
|
312 { |
300 if (uri_struct->askpass == NULL) |
313 if (uri_struct->askpass == NULL) |
301 { |
314 { |
302 if ((uri_struct->askpass = strdup(l2)) == NULL) |
315 if ((uri_struct->askpass = strdup(l2)) == NULL) |
303 goto no_mem; |
316 goto no_mem; |
304 } |
317 } |
305 else |
318 else |
306 goto bad_uri; |
319 goto bad_uri; |
|
320 } |
307 else |
321 else |
308 goto bad_uri; |
322 goto bad_uri; |
309 } |
323 } |
310 |
324 |
311 /* The "object" token is mandatory in the PKCS#11 URI. */ |
325 /* The "object" token is mandatory in the PKCS#11 URI. */ |
492 /* We set the PIN only once since all URIs must have it the same. */ |
506 /* We set the PIN only once since all URIs must have it the same. */ |
493 if (token_pin != NULL) |
507 if (token_pin != NULL) |
494 goto ok; |
508 goto ok; |
495 |
509 |
496 if (pk11_get_pin_caching_policy() == POLICY_MEMORY) |
510 if (pk11_get_pin_caching_policy() == POLICY_MEMORY) |
|
511 { |
497 if ((token_pin = strdup(pin)) == NULL) |
512 if ((token_pin = strdup(pin)) == NULL) |
498 { |
513 { |
499 PK11err(PK11_F_CACHE_PIN, PK11_R_MALLOC_FAILURE); |
514 PK11err(PK11_F_CACHE_PIN, PK11_R_MALLOC_FAILURE); |
500 goto err; |
515 goto err; |
501 } |
516 } |
|
517 } |
502 else |
518 else |
|
519 { |
503 if (pk11_get_pin_caching_policy() == POLICY_MLOCKED_MEMORY) |
520 if (pk11_get_pin_caching_policy() == POLICY_MLOCKED_MEMORY) |
504 { |
521 { |
505 if (mlock_pin_in_memory(pin) == 0) |
522 if (mlock_pin_in_memory(pin) == 0) |
506 goto err; |
523 goto err; |
507 } |
524 } |
|
525 } |
508 |
526 |
509 ok: |
527 ok: |
510 (void) pthread_mutex_unlock(uri_lock); |
528 (void) pthread_mutex_unlock(uri_lock); |
511 return (1); |
529 return (1); |
512 err: |
530 err: |