cb_test.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. * END COPYRIGHT BLOCK **/
  6. #include "cb.h"
  7. int cb_back_test( Slapi_PBlock *pb )
  8. {
  9. Slapi_Backend * be;
  10. cb_backend * cb;
  11. cb_backend_instance * inst;
  12. Slapi_PBlock * apb;
  13. int res;
  14. int rc=0;
  15. const Slapi_DN *aSuffix=NULL;
  16. const char * aSuffixString;
  17. char * theTarget;
  18. slapi_pblock_get( pb, SLAPI_PLUGIN_PRIVATE, &cb );
  19. slapi_pblock_get( pb, SLAPI_BACKEND, &be );
  20. inst = cb_get_instance(be);
  21. apb = slapi_pblock_new();
  22. /*
  23. ** Try to open a connection to the farm server
  24. ** Try to get a dummy entry BELOW the suffix managed
  25. ** by the chaining backend, in case the local root is shared
  26. ** across different backend
  27. */
  28. printf("Begin test instance %s.\n",inst->inst_name);
  29. aSuffix = slapi_be_getsuffix(be,0);
  30. aSuffixString=slapi_sdn_get_dn(aSuffix);
  31. /* Remove leading white spaces */
  32. for (aSuffixString; *aSuffixString==' ';aSuffixString++) {}
  33. theTarget=slapi_ch_smprintf("cn=test,%s",aSuffixString);
  34. /* XXXSD make sure chaining allowed for this plugin... */
  35. slapi_search_internal_set_pb (apb, theTarget, LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, NULL, NULL,
  36. cb->identity,0 );
  37. slapi_search_internal_pb (apb);
  38. slapi_ch_free((void **)&theTarget);
  39. if ( NULL == apb ) {
  40. printf("Can't contact farm server. (Internal error).\n");
  41. rc=-1;
  42. goto the_end;
  43. }
  44. slapi_pblock_get(apb, SLAPI_PLUGIN_INTOP_RESULT, &res);
  45. /* OPERATIONS ERRORS also returned when bind failed */
  46. if (CB_LDAP_CONN_ERROR(res) || (res==LDAP_OPERATIONS_ERROR ))
  47. {
  48. printf("Can't contact the remote farm server %s. (%s).\n",inst->pool->hostname,ldap_err2string(res));
  49. rc=-1;
  50. goto the_end;
  51. } else {
  52. printf("Connection established with the remote farm server %s.\n",inst->pool->hostname);
  53. }
  54. the_end:
  55. if (apb)
  56. {
  57. slapi_free_search_results_internal(apb);
  58. slapi_pblock_destroy (apb);
  59. }
  60. return rc;
  61. }