1
0

cb_test.c 2.1 KB

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