369 * parameters:
370 * p - entry point
371 */
372 int sasl_server_add_plugin(const char *plugname,
373 sasl_server_plug_init_t *p)
374 #ifdef _SUN_SDK_
375 {
376 return (_sasl_server_add_plugin(_sasl_gbl_ctx(), plugname, p));
377 }
378
379 int _sasl_server_add_plugin(void *ctx,
380 const char *plugname,
381 sasl_server_plug_init_t *p)
382 {
383 int nplug = 0;
384 int i;
385 mechanism_t *m;
386 _sasl_global_context_t *gctx = ctx == NULL ? _sasl_gbl_ctx() : ctx;
387 mech_list_t *mechlist = gctx->mechlist;
388
389 /* EXPORT DELETE START */
390 /* CRYPT DELETE START */
391 #ifdef _INTEGRATED_SOLARIS_
392 int sun_reg;
393 #endif /* _INTEGRATED_SOLARIS_ */
394 /* CRYPT DELETE END */
395 /* EXPORT DELETE END */
396 #else
397 {
398 #endif /* _SUN_SDK_ */
399 int plugcount;
400 sasl_server_plug_t *pluglist;
401 mechanism_t *mech;
402 sasl_server_plug_init_t *entry_point;
403 int result;
404 int version;
405 int lupe;
406
407 if(!plugname || !p) return SASL_BADPARAM;
408
409 #ifdef _SUN_SDK_
410 if (mechlist == NULL) return SASL_BADPARAM;
411
412 /* Check to see if this plugin has already been registered */
413 m = mechlist->mech_list;
414 for (i = 0; i < mechlist->mech_length; i++) {
415 if (strcmp(plugname, m->plugname) == 0)
416 return SASL_OK;
417 m = m->next;
418 }
419
420 result = LOCK_MUTEX(&server_plug_mutex);
421 if (result != SASL_OK)
422 return result;
423
424 #endif /* _SUN_SDK_ */
425 entry_point = (sasl_server_plug_init_t *)p;
426
427 /* call into the shared library asking for information about it */
428 /* version is filled in with the version of the plugin */
429 result = entry_point(mechlist->utils, SASL_SERVER_PLUG_VERSION, &version,
430 &pluglist, &plugcount);
431
432 /* EXPORT DELETE START */
433 /* CRYPT DELETE START */
434 #ifdef _INTEGRATED_SOLARIS_
435 sun_reg = _is_sun_reg(pluglist);
436 #endif /* _INTEGRATED_SOLARIS_ */
437 /* CRYPT DELETE END */
438 /* EXPORT DELETE END */
439
440 #ifdef _SUN_SDK_
441 if (result != SASL_OK) {
442 UNLOCK_MUTEX(&server_plug_mutex);
443 __sasl_log(gctx, gctx->server_global_callbacks.callbacks,
444 SASL_LOG_DEBUG,
445 "server add_plugin entry_point error %z", result);
446 #else
447 if ((result != SASL_OK) && (result != SASL_NOUSER)) {
448 _sasl_log(NULL, SASL_LOG_DEBUG,
449 "server add_plugin entry_point error %z\n", result);
450 #endif /* _SUN_SDK_ */
451 return result;
452 }
453
454 /* Make sure plugin is using the same SASL version as us */
455 if (version != SASL_SERVER_PLUG_VERSION)
456 {
457 #ifdef _SUN_SDK_
458 UNLOCK_MUTEX(&server_plug_mutex);
496 if (! mech) {
497 UNLOCK_MUTEX(&server_plug_mutex);
498 return SASL_NOMEM;
499 }
500
501 mech->glob_context = pluglist->glob_context;
502 #else
503 if (! mech) return SASL_NOMEM;
504 #endif /* _SUN_SDK_ */
505
506 mech->plug=pluglist++;
507 if(_sasl_strdup(plugname, &mech->plugname, NULL) != SASL_OK) {
508 #ifdef _SUN_SDK_
509 UNLOCK_MUTEX(&server_plug_mutex);
510 #endif /* _SUN_SDK_ */
511 sasl_FREE(mech);
512 return SASL_NOMEM;
513 }
514 mech->version = version;
515 #ifdef _SUN_SDK_
516 /* EXPORT DELETE START */
517 /* CRYPT DELETE START */
518 #ifdef _INTEGRATED_SOLARIS_
519 mech->sun_reg = sun_reg;
520 #endif /* _INTEGRATED_SOLARIS_ */
521 /* CRYPT DELETE END */
522 /* EXPORT DELETE END */
523
524 /* whether this mech actually has any users in it's db */
525 mech->condition = SASL_OK;
526 #else
527 /* whether this mech actually has any users in it's db */
528 mech->condition = result; /* SASL_OK or SASL_NOUSER */
529 #endif /* _SUN_SDK_ */
530
531 mech->next = mechlist->mech_list;
532 mechlist->mech_list = mech;
533 mechlist->mech_length++;
534 }
535
536 #ifdef _SUN_SDK_
537 UNLOCK_MUTEX(&server_plug_mutex);
538 return (nplug == 0) ? SASL_NOMECH : SASL_OK;
539 #else
540 return SASL_OK;
541 #endif /* _SUN_SDK_ */
542 }
1474 if (!*mlist) return 0; /* reached EOS -> not in our list */
1475 }
1476 }
1477
1478 /* setup parameters for the call to mech_avail */
1479 s_conn->sparams->serverFQDN=conn->serverFQDN;
1480 s_conn->sparams->service=conn->service;
1481 s_conn->sparams->user_realm=s_conn->user_realm;
1482 s_conn->sparams->props=conn->props;
1483 s_conn->sparams->external_ssf=conn->external.ssf;
1484
1485 /* Check if we have banished this one already */
1486 for(cur = s_conn->mech_contexts; cur; cur=cur->next) {
1487 if(cur->mech == mech) {
1488 /* If it's not mech_avail'd, then stop now */
1489 if(!cur->context) return 0;
1490 break;
1491 }
1492 }
1493
1494 /* EXPORT DELETE START */
1495 /* CRYPT DELETE START */
1496 #ifdef _INTEGRATED_SOLARIS_
1497 if (!mech->sun_reg) {
1498 s_conn->sparams->props.min_ssf = 0;
1499 s_conn->sparams->props.max_ssf = 0;
1500 }
1501 s_conn->base.sun_reg = mech->sun_reg;
1502 #endif /* _INTEGRATED_SOLARIS_ */
1503 /* CRYPT DELETE END */
1504 /* EXPORT DELETE END */
1505 if (conn->props.min_ssf < conn->external.ssf) {
1506 minssf = 0;
1507 } else {
1508 minssf = conn->props.min_ssf - conn->external.ssf;
1509 }
1510
1511 /* Generic mechanism */
1512 /* EXPORT DELETE START */
1513 /* CRYPT DELETE START */
1514 #ifdef _INTEGRATED_SOLARIS_
1515 /* If not SUN supplied mech, it has no strength */
1516 if (plug->max_ssf < minssf || (minssf > 0 && !mech->sun_reg)) {
1517 #else
1518 /* CRYPT DELETE END */
1519 /* EXPORT DELETE END */
1520 if (plug->max_ssf < minssf) {
1521 /* EXPORT DELETE START */
1522 /* CRYPT DELETE START */
1523 #endif /* _INTEGRATED_SOLARIS_ */
1524 /* CRYPT DELETE END */
1525 /* EXPORT DELETE END */
1526 #ifdef _INTEGRATED_SOLARIS_
1527 sasl_seterror(conn, SASL_NOLOG,
1528 gettext("mech %s is too weak"), plug->mech_name);
1529 #else
1530 sasl_seterror(conn, SASL_NOLOG,
1531 "mech %s is too weak", plug->mech_name);
1532 #endif /* _INTEGRATED_SOLARIS_ */
1533 return 0; /* too weak */
1534 }
1535
1536 context = NULL;
1537 if(plug->mech_avail
1538 #ifdef _SUN_SDK_
1539 && plug->mech_avail(mech->glob_context,
1540 #else
1541 && plug->mech_avail(plug->glob_context,
1542 #endif /* _SUN_SDK_ */
1543 s_conn->sparams, (void **)&context) != SASL_OK ) {
1544 /* Mark this mech as no good for this connection */
1545 cur = sasl_ALLOC(sizeof(context_list_t));
1559 /* Error should be set by mech_avail call */
1560 return 0;
1561 } else if(context) {
1562 /* Save this context */
1563 cur = sasl_ALLOC(sizeof(context_list_t));
1564 if(!cur) {
1565 #ifdef _SUN_SDK_
1566 if(conn) _sasl_log(conn, SASL_LOG_WARN, "Out of Memory");
1567 #else
1568 MEMERROR(conn);
1569 #endif /* _SUN_SDK_ */
1570 return 0;
1571 }
1572 cur->context = context;
1573 cur->mech = mech;
1574 cur->next = s_conn->mech_contexts;
1575 s_conn->mech_contexts = cur;
1576 }
1577
1578 /* Generic mechanism */
1579 /* EXPORT DELETE START */
1580 /* CRYPT DELETE START */
1581 #ifdef _INTEGRATED_SOLARIS_
1582 /* If not SUN supplied mech, it has no strength */
1583 if (plug->max_ssf < minssf || (minssf > 0 && !mech->sun_reg)) {
1584 #else
1585 /* CRYPT DELETE END */
1586 /* EXPORT DELETE END */
1587 if (plug->max_ssf < minssf) {
1588 /* EXPORT DELETE START */
1589 /* CRYPT DELETE START */
1590 #endif /* _INTEGRATED_SOLARIS_ */
1591 /* CRYPT DELETE END */
1592 /* EXPORT DELETE END */
1593 #ifdef _INTEGRATED_SOLARIS_
1594 sasl_seterror(conn, SASL_NOLOG, gettext("too weak"));
1595 #else
1596 sasl_seterror(conn, SASL_NOLOG, "too weak");
1597 #endif /* _INTEGRATED_SOLARIS_ */
1598 return 0; /* too weak */
1599 }
1600
1601 #ifndef _SUN_SDK_
1602 /* if there are no users in the secrets database we can't use this
1603 mechanism */
1604 if (mech->condition == SASL_NOUSER) {
1605 sasl_seterror(conn, 0, "no users in secrets db");
1606 return 0;
1607 }
1608 #endif /* !_SUN_SDK_ */
1609
1610 /* Can it meet our features? */
1611 if ((conn->flags & SASL_NEED_PROXY) &&
1612 !(plug->features & SASL_FEAT_ALLOWS_PROXY)) {
|
369 * parameters:
370 * p - entry point
371 */
372 int sasl_server_add_plugin(const char *plugname,
373 sasl_server_plug_init_t *p)
374 #ifdef _SUN_SDK_
375 {
376 return (_sasl_server_add_plugin(_sasl_gbl_ctx(), plugname, p));
377 }
378
379 int _sasl_server_add_plugin(void *ctx,
380 const char *plugname,
381 sasl_server_plug_init_t *p)
382 {
383 int nplug = 0;
384 int i;
385 mechanism_t *m;
386 _sasl_global_context_t *gctx = ctx == NULL ? _sasl_gbl_ctx() : ctx;
387 mech_list_t *mechlist = gctx->mechlist;
388
389 #ifdef _INTEGRATED_SOLARIS_
390 int sun_reg;
391 #endif /* _INTEGRATED_SOLARIS_ */
392 #else
393 {
394 #endif /* _SUN_SDK_ */
395 int plugcount;
396 sasl_server_plug_t *pluglist;
397 mechanism_t *mech;
398 sasl_server_plug_init_t *entry_point;
399 int result;
400 int version;
401 int lupe;
402
403 if(!plugname || !p) return SASL_BADPARAM;
404
405 #ifdef _SUN_SDK_
406 if (mechlist == NULL) return SASL_BADPARAM;
407
408 /* Check to see if this plugin has already been registered */
409 m = mechlist->mech_list;
410 for (i = 0; i < mechlist->mech_length; i++) {
411 if (strcmp(plugname, m->plugname) == 0)
412 return SASL_OK;
413 m = m->next;
414 }
415
416 result = LOCK_MUTEX(&server_plug_mutex);
417 if (result != SASL_OK)
418 return result;
419
420 #endif /* _SUN_SDK_ */
421 entry_point = (sasl_server_plug_init_t *)p;
422
423 /* call into the shared library asking for information about it */
424 /* version is filled in with the version of the plugin */
425 result = entry_point(mechlist->utils, SASL_SERVER_PLUG_VERSION, &version,
426 &pluglist, &plugcount);
427
428 #ifdef _INTEGRATED_SOLARIS_
429 sun_reg = _is_sun_reg(pluglist);
430 #endif /* _INTEGRATED_SOLARIS_ */
431
432 #ifdef _SUN_SDK_
433 if (result != SASL_OK) {
434 UNLOCK_MUTEX(&server_plug_mutex);
435 __sasl_log(gctx, gctx->server_global_callbacks.callbacks,
436 SASL_LOG_DEBUG,
437 "server add_plugin entry_point error %z", result);
438 #else
439 if ((result != SASL_OK) && (result != SASL_NOUSER)) {
440 _sasl_log(NULL, SASL_LOG_DEBUG,
441 "server add_plugin entry_point error %z\n", result);
442 #endif /* _SUN_SDK_ */
443 return result;
444 }
445
446 /* Make sure plugin is using the same SASL version as us */
447 if (version != SASL_SERVER_PLUG_VERSION)
448 {
449 #ifdef _SUN_SDK_
450 UNLOCK_MUTEX(&server_plug_mutex);
488 if (! mech) {
489 UNLOCK_MUTEX(&server_plug_mutex);
490 return SASL_NOMEM;
491 }
492
493 mech->glob_context = pluglist->glob_context;
494 #else
495 if (! mech) return SASL_NOMEM;
496 #endif /* _SUN_SDK_ */
497
498 mech->plug=pluglist++;
499 if(_sasl_strdup(plugname, &mech->plugname, NULL) != SASL_OK) {
500 #ifdef _SUN_SDK_
501 UNLOCK_MUTEX(&server_plug_mutex);
502 #endif /* _SUN_SDK_ */
503 sasl_FREE(mech);
504 return SASL_NOMEM;
505 }
506 mech->version = version;
507 #ifdef _SUN_SDK_
508 #ifdef _INTEGRATED_SOLARIS_
509 mech->sun_reg = sun_reg;
510 #endif /* _INTEGRATED_SOLARIS_ */
511
512 /* whether this mech actually has any users in it's db */
513 mech->condition = SASL_OK;
514 #else
515 /* whether this mech actually has any users in it's db */
516 mech->condition = result; /* SASL_OK or SASL_NOUSER */
517 #endif /* _SUN_SDK_ */
518
519 mech->next = mechlist->mech_list;
520 mechlist->mech_list = mech;
521 mechlist->mech_length++;
522 }
523
524 #ifdef _SUN_SDK_
525 UNLOCK_MUTEX(&server_plug_mutex);
526 return (nplug == 0) ? SASL_NOMECH : SASL_OK;
527 #else
528 return SASL_OK;
529 #endif /* _SUN_SDK_ */
530 }
1462 if (!*mlist) return 0; /* reached EOS -> not in our list */
1463 }
1464 }
1465
1466 /* setup parameters for the call to mech_avail */
1467 s_conn->sparams->serverFQDN=conn->serverFQDN;
1468 s_conn->sparams->service=conn->service;
1469 s_conn->sparams->user_realm=s_conn->user_realm;
1470 s_conn->sparams->props=conn->props;
1471 s_conn->sparams->external_ssf=conn->external.ssf;
1472
1473 /* Check if we have banished this one already */
1474 for(cur = s_conn->mech_contexts; cur; cur=cur->next) {
1475 if(cur->mech == mech) {
1476 /* If it's not mech_avail'd, then stop now */
1477 if(!cur->context) return 0;
1478 break;
1479 }
1480 }
1481
1482 #ifdef _INTEGRATED_SOLARIS_
1483 if (!mech->sun_reg) {
1484 s_conn->sparams->props.min_ssf = 0;
1485 s_conn->sparams->props.max_ssf = 0;
1486 }
1487 s_conn->base.sun_reg = mech->sun_reg;
1488 #endif /* _INTEGRATED_SOLARIS_ */
1489 if (conn->props.min_ssf < conn->external.ssf) {
1490 minssf = 0;
1491 } else {
1492 minssf = conn->props.min_ssf - conn->external.ssf;
1493 }
1494
1495 /* Generic mechanism */
1496 #ifdef _INTEGRATED_SOLARIS_
1497 /* If not SUN supplied mech, it has no strength */
1498 if (plug->max_ssf < minssf || (minssf > 0 && !mech->sun_reg)) {
1499 #else
1500 if (plug->max_ssf < minssf) {
1501 #endif /* _INTEGRATED_SOLARIS_ */
1502 #ifdef _INTEGRATED_SOLARIS_
1503 sasl_seterror(conn, SASL_NOLOG,
1504 gettext("mech %s is too weak"), plug->mech_name);
1505 #else
1506 sasl_seterror(conn, SASL_NOLOG,
1507 "mech %s is too weak", plug->mech_name);
1508 #endif /* _INTEGRATED_SOLARIS_ */
1509 return 0; /* too weak */
1510 }
1511
1512 context = NULL;
1513 if(plug->mech_avail
1514 #ifdef _SUN_SDK_
1515 && plug->mech_avail(mech->glob_context,
1516 #else
1517 && plug->mech_avail(plug->glob_context,
1518 #endif /* _SUN_SDK_ */
1519 s_conn->sparams, (void **)&context) != SASL_OK ) {
1520 /* Mark this mech as no good for this connection */
1521 cur = sasl_ALLOC(sizeof(context_list_t));
1535 /* Error should be set by mech_avail call */
1536 return 0;
1537 } else if(context) {
1538 /* Save this context */
1539 cur = sasl_ALLOC(sizeof(context_list_t));
1540 if(!cur) {
1541 #ifdef _SUN_SDK_
1542 if(conn) _sasl_log(conn, SASL_LOG_WARN, "Out of Memory");
1543 #else
1544 MEMERROR(conn);
1545 #endif /* _SUN_SDK_ */
1546 return 0;
1547 }
1548 cur->context = context;
1549 cur->mech = mech;
1550 cur->next = s_conn->mech_contexts;
1551 s_conn->mech_contexts = cur;
1552 }
1553
1554 /* Generic mechanism */
1555 #ifdef _INTEGRATED_SOLARIS_
1556 /* If not SUN supplied mech, it has no strength */
1557 if (plug->max_ssf < minssf || (minssf > 0 && !mech->sun_reg)) {
1558 #else
1559 if (plug->max_ssf < minssf) {
1560 #endif /* _INTEGRATED_SOLARIS_ */
1561 #ifdef _INTEGRATED_SOLARIS_
1562 sasl_seterror(conn, SASL_NOLOG, gettext("too weak"));
1563 #else
1564 sasl_seterror(conn, SASL_NOLOG, "too weak");
1565 #endif /* _INTEGRATED_SOLARIS_ */
1566 return 0; /* too weak */
1567 }
1568
1569 #ifndef _SUN_SDK_
1570 /* if there are no users in the secrets database we can't use this
1571 mechanism */
1572 if (mech->condition == SASL_NOUSER) {
1573 sasl_seterror(conn, 0, "no users in secrets db");
1574 return 0;
1575 }
1576 #endif /* !_SUN_SDK_ */
1577
1578 /* Can it meet our features? */
1579 if ((conn->flags & SASL_NEED_PROXY) &&
1580 !(plug->features & SASL_FEAT_ALLOWS_PROXY)) {
|