cos.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 <stdio.h>
  7. #include <string.h>
  8. #include "portable.h"
  9. #include "nspr.h"
  10. #include "slapi-plugin.h"
  11. #include "slapi-private.h"
  12. #include <dirlite_strings.h> /* PLUGIN_MAGIC_VENDOR_STR */
  13. #include "dirver.h"
  14. #include "cos_cache.h"
  15. #include "vattr_spi.h"
  16. /* get file mode flags for unix */
  17. #ifndef _WIN32
  18. #include <sys/stat.h>
  19. #endif
  20. /*** secret slapd stuff ***/
  21. /*
  22. these are required here because they are not available
  23. in any public header. They must exactly match their
  24. counterparts in the server or they will fail to work
  25. correctly.
  26. */
  27. /*** from proto-slap.h ***/
  28. int slapd_log_error_proc( char *subsystem, char *fmt, ... );
  29. /*** from ldaplog.h ***/
  30. /* edited ldaplog.h for LDAPDebug()*/
  31. #ifndef _LDAPLOG_H
  32. #define _LDAPLOG_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. #define LDAP_DEBUG_TRACE 0x00001 /* 1 */
  37. #define LDAP_DEBUG_ANY 0x04000 /* 16384 */
  38. #define LDAP_DEBUG_PLUGIN 0x10000 /* 65536 */
  39. /* debugging stuff */
  40. # ifdef _WIN32
  41. extern int *module_ldap_debug;
  42. # define LDAPDebug( level, fmt, arg1, arg2, arg3 ) \
  43. { \
  44. if ( *module_ldap_debug & level ) { \
  45. slapd_log_error_proc( NULL, fmt, arg1, arg2, arg3 ); \
  46. } \
  47. }
  48. # else /* _WIN32 */
  49. extern int slapd_ldap_debug;
  50. # define LDAPDebug( level, fmt, arg1, arg2, arg3 ) \
  51. { \
  52. if ( slapd_ldap_debug & level ) { \
  53. slapd_log_error_proc( NULL, fmt, arg1, arg2, arg3 ); \
  54. } \
  55. }
  56. # endif /* Win32 */
  57. #ifdef __cplusplus
  58. }
  59. #endif
  60. #endif /* _LDAP_H */
  61. /*** end secrets ***/
  62. #define COS_PLUGIN_SUBSYSTEM "cos-plugin" /* used for logging */
  63. /* subrelease in the following version info is for odd-ball cos releases
  64. * which do not fit into a general release, this can be used for beta releases
  65. * and other (this version stuff is really to help outside applications which
  66. * may wish to update cos decide whether the cos version they want to update to
  67. * is a higher release than the installed plugin)
  68. *
  69. * note: release origin is 00 for directory server
  70. * sub-release should be:
  71. * 50 for initial RTM products
  72. * from 0 increasing for alpha/beta releases
  73. * from 51 increasing for patch releases
  74. */
  75. #define COS_VERSION 0x00050050 /* version format: 0x release origin 00 major 05 minor 00 sub-release 00 */
  76. /* other function prototypes */
  77. int cos_init( Slapi_PBlock *pb );
  78. int cos_compute(computed_attr_context *c,char* type,Slapi_Entry *e,slapi_compute_output_t outputfn);
  79. int cos_start( Slapi_PBlock *pb );
  80. int cos_close( Slapi_PBlock *pb );
  81. int cos_post_op( Slapi_PBlock *pb );
  82. static Slapi_PluginDesc pdesc = { "cos", PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  83. "class of service plugin" };
  84. static void * cos_plugin_identity = NULL;
  85. #ifdef _WIN32
  86. int *module_ldap_debug = 0;
  87. void plugin_init_debug_level(int *level_ptr)
  88. {
  89. module_ldap_debug = level_ptr;
  90. }
  91. #endif
  92. /*
  93. ** Plugin identity mgmt
  94. */
  95. void cos_set_plugin_identity(void * identity)
  96. {
  97. cos_plugin_identity=identity;
  98. }
  99. void * cos_get_plugin_identity()
  100. {
  101. return cos_plugin_identity;
  102. }
  103. int cos_version()
  104. {
  105. return COS_VERSION;
  106. }
  107. /*
  108. cos_init
  109. --------
  110. adds our callbacks to the list
  111. */
  112. int cos_init( Slapi_PBlock *pb )
  113. {
  114. int ret = 0;
  115. void * plugin_identity=NULL;
  116. LDAPDebug( LDAP_DEBUG_TRACE, "--> cos_init\n",0,0,0);
  117. /*
  118. ** Store the plugin identity for later use.
  119. ** Used for internal operations
  120. */
  121. slapi_pblock_get (pb, SLAPI_PLUGIN_IDENTITY, &plugin_identity);
  122. PR_ASSERT (plugin_identity);
  123. cos_set_plugin_identity(plugin_identity);
  124. if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  125. SLAPI_PLUGIN_VERSION_01 ) != 0 ||
  126. slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN,
  127. (void *) cos_start ) != 0 ||
  128. slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODIFY_FN,
  129. (void *) cos_post_op ) != 0 ||
  130. slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODRDN_FN,
  131. (void *) cos_post_op ) != 0 ||
  132. slapi_pblock_set(pb, SLAPI_PLUGIN_POST_ADD_FN,
  133. (void *) cos_post_op ) != 0 ||
  134. slapi_pblock_set(pb, SLAPI_PLUGIN_POST_DELETE_FN,
  135. (void *) cos_post_op ) != 0 ||
  136. slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN,
  137. (void *) cos_close ) != 0 ||
  138. slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  139. (void *)&pdesc ) != 0 )
  140. {
  141. slapi_log_error( SLAPI_LOG_FATAL, COS_PLUGIN_SUBSYSTEM,
  142. "cos_init: failed to register plugin\n" );
  143. ret = -1;
  144. }
  145. LDAPDebug( LDAP_DEBUG_TRACE, "<-- cos_init\n",0,0,0);
  146. return ret;
  147. }
  148. /*
  149. cos_start
  150. ---------
  151. This function registers the computed attribute evaluator
  152. and inits the cos cache.
  153. It is called after cos_init.
  154. */
  155. int cos_start( Slapi_PBlock *pb )
  156. {
  157. int ret = 0;
  158. LDAPDebug( LDAP_DEBUG_TRACE, "--> cos_start\n",0,0,0);
  159. if( !cos_cache_init() )
  160. {
  161. LDAPDebug( LDAP_DEBUG_PLUGIN, "cos: ready for service\n",0,0,0);
  162. }
  163. else
  164. {
  165. /* problems we are hosed */
  166. cos_cache_stop();
  167. LDAPDebug( LDAP_DEBUG_ANY, "cos_start: failed to initialise\n",0,0,0);
  168. ret = -1;
  169. }
  170. LDAPDebug( LDAP_DEBUG_TRACE, "<-- cos_start\n",0,0,0);
  171. return ret;
  172. }
  173. /*
  174. cos_close
  175. ---------
  176. closes down the cache
  177. */
  178. int cos_close( Slapi_PBlock *pb )
  179. {
  180. LDAPDebug( LDAP_DEBUG_TRACE, "--> cos_close\n",0,0,0);
  181. cos_cache_stop();
  182. LDAPDebug( LDAP_DEBUG_TRACE, "<-- cos_close\n",0,0,0);
  183. return 0;
  184. }
  185. /*
  186. cos_compute
  187. -----------
  188. called when evaluating named attributes in a search
  189. and attributes remain unfound in the entry,
  190. this function checks the attribute for a match with
  191. those in the class of service definitions, and if a
  192. match is found, adds the attribute and value to the
  193. output list
  194. returns
  195. 0 on success
  196. 1 on outright failure
  197. -1 when doesn't know about attribute
  198. */
  199. int cos_compute(computed_attr_context *c,char* type,Slapi_Entry *e,slapi_compute_output_t outputfn)
  200. {
  201. int ret = -1;
  202. return ret;
  203. }
  204. /*
  205. cos_post_op
  206. -----------
  207. Catch all for all post operations that change entries
  208. in some way - this simply notifies the cache of a
  209. change - the cache decides if action is necessary
  210. */
  211. int cos_post_op( Slapi_PBlock *pb )
  212. {
  213. LDAPDebug( LDAP_DEBUG_TRACE, "--> cos_post_op\n",0,0,0);
  214. cos_cache_change_notify(pb);
  215. LDAPDebug( LDAP_DEBUG_TRACE, "<-- cos_post_op\n",0,0,0);
  216. return 0; /* always succeed */
  217. }