cb_test.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright 2001 Sun Microsystems, Inc.
  3. * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
  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_calloc(1,strlen(aSuffixString)+20);
  34. sprintf(theTarget,"cn=test,%s",aSuffixString);
  35. /* XXXSD make sure chaining allowed for this plugin... */
  36. slapi_search_internal_set_pb (apb, theTarget, LDAP_SCOPE_BASE, "objectclass=*", NULL, 0, NULL, NULL,
  37. cb->identity,0 );
  38. slapi_search_internal_pb (apb);
  39. slapi_ch_free((void **)&theTarget);
  40. if ( NULL == apb ) {
  41. printf("Can't contact farm server. (Internal error).\n");
  42. rc=-1;
  43. goto the_end;
  44. }
  45. slapi_pblock_get(apb, SLAPI_PLUGIN_INTOP_RESULT, &res);
  46. /* OPERATIONS ERRORS also returned when bind failed */
  47. if (CB_LDAP_CONN_ERROR(res) || (res==LDAP_OPERATIONS_ERROR ))
  48. {
  49. printf("Can't contact the remote farm server %s. (%s).\n",inst->pool->hostname,ldap_err2string(res));
  50. rc=-1;
  51. goto the_end;
  52. } else {
  53. printf("Connection established with the remote farm server %s.\n",inst->pool->hostname);
  54. }
  55. the_end:
  56. if (apb)
  57. {
  58. slapi_free_search_results_internal(apb);
  59. slapi_pblock_destroy (apb);
  60. }
  61. return rc;
  62. }