cis.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /* cis.c - caseignorestring syntax routines */
  42. /*
  43. * This file actually implements three syntax plugins:
  44. * DirectoryString
  45. * Boolean
  46. * GeneralizedTime
  47. *
  48. * We treat them identically for now. XXXmcs: we could do some validation on
  49. * Boolean and GeneralizedTime values (someday, maybe).
  50. */
  51. #include <stdio.h>
  52. #include <string.h>
  53. #include <sys/types.h>
  54. #include "syntax.h"
  55. static int cis_filter_ava( Slapi_PBlock *pb, struct berval *bvfilter,
  56. Slapi_Value **bvals, int ftype, Slapi_Value **retVal );
  57. static int cis_filter_sub( Slapi_PBlock *pb, char *initial, char **any,
  58. char *final, Slapi_Value **bvals );
  59. static int cis_values2keys( Slapi_PBlock *pb, Slapi_Value **val,
  60. Slapi_Value ***ivals, int ftype );
  61. static int cis_assertion2keys_ava( Slapi_PBlock *pb, Slapi_Value *val,
  62. Slapi_Value ***ivals, int ftype );
  63. static int cis_assertion2keys_sub( Slapi_PBlock *pb, char *initial, char **any,
  64. char *final, Slapi_Value ***ivals );
  65. static int cis_compare(struct berval *v1, struct berval *v2);
  66. /*
  67. * Attribute syntaxes. We treat all of these the same for now, even though
  68. * the specifications (e.g., RFC 2252) impose various constraints on the
  69. * the format for each of these.
  70. *
  71. * Note: the first name is the official one from RFC 2252.
  72. */
  73. static char *dirstring_names[] = { "DirectoryString", "cis",
  74. "caseignorestring", DIRSTRING_SYNTAX_OID, 0 };
  75. static char *boolean_names[] = { "Boolean", BOOLEAN_SYNTAX_OID, 0 };
  76. static char *time_names[] = { "GeneralizedTime", "time",
  77. GENERALIZEDTIME_SYNTAX_OID, 0 };
  78. static char *country_names[] = { "Country String",
  79. COUNTRYSTRING_SYNTAX_OID, 0};
  80. static char *postal_names[] = { "Postal Address",
  81. POSTALADDRESS_SYNTAX_OID, 0};
  82. static char *oid_names[] = { "OID",
  83. OID_SYNTAX_OID, 0};
  84. /*
  85. TBD (XXX)
  86. "1.3.6.1.4.1.1466.115.121.1.16 \"DIT Content Rule Description
  87. \" "
  88. "1.3.6.1.4.1.1466.115.121.1.17 \"DIT Structure Rule Descripti
  89. on\" "
  90. "1.3.6.1.4.1.1466.115.121.1.20 \"DSE Type\" "
  91. "1.3.6.1.4.1.1466.115.121.1.30 \"Matching Rule Description\"
  92. "
  93. "1.3.6.1.4.1.1466.115.121.1.31 \"Matching Rule Use Descriptio
  94. n\" "
  95. "1.3.6.1.4.1.1466.115.121.1.35 \"Name Form Description\" "
  96. "1.3.6.1.4.1.1466.115.121.1.44 \"Printable String\" "
  97. "1.3.6.1.4.1.1466.115.121.1.45 \"Subtree Specification\" "
  98. "1.3.6.1.4.1.1466.115.121.1.54 \"LDAP Syntax Description\" "
  99. "1.3.6.1.4.1.1466.115.121.1.55 \"Modify Rights\" "
  100. "1.3.6.1.4.1.1466.115.121.1.56 \"LDAP Schema Description\" "
  101. "1.3.6.1.4.1.1466.115.121.1.25 \"Guide\" "
  102. "1.3.6.1.4.1.1466.115.121.1.52 \"Telex Number\" "
  103. "1.3.6.1.4.1.1466.115.121.1.51 \"Teletex Terminal Identifier\
  104. " "
  105. "1.3.6.1.4.1.1466.115.121.1.14 \"Delivery Method\" "
  106. "1.3.6.1.4.1.1466.115.121.1.43 \"Presentation Address\" "
  107. "1.3.6.1.4.1.1466.115.121.1.21 \"Enhanced Guide\" "
  108. "1.3.6.1.4.1.1466.115.121.1.34 \"Name and Optional UID\" "
  109. "1.2.840.113556.1.4.905 \"CaseIgnoreString\" "
  110. "1.3.6.1.1.1.0.0 \"nisNetgroupTripleSyntax\" "
  111. "1.3.6.1.1.1.0.1 \"bootParameterSyntax\" ");
  112. */
  113. static Slapi_PluginDesc dirstring_pdesc = { "directorystring-syntax",
  114. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  115. "DirectoryString attribute syntax plugin" };
  116. static Slapi_PluginDesc boolean_pdesc = { "boolean-syntax",
  117. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  118. "Boolean attribute syntax plugin" };
  119. static Slapi_PluginDesc time_pdesc = { "time-syntax",
  120. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  121. "GeneralizedTime attribute syntax plugin" };
  122. static Slapi_PluginDesc country_pdesc = { "countrystring-syntax",
  123. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  124. "Country String attribute syntax plugin" };
  125. static Slapi_PluginDesc postal_pdesc = { "postaladdress-syntax",
  126. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  127. "Postal Address attribute syntax plugin" };
  128. static Slapi_PluginDesc oid_pdesc = { "oid-syntax",
  129. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  130. "OID attribute syntax plugin" };
  131. /*
  132. * register_cis_like_plugin(): register all items for a cis-like plugin.
  133. */
  134. static int
  135. register_cis_like_plugin( Slapi_PBlock *pb, Slapi_PluginDesc *pdescp,
  136. char **names, char *oid )
  137. {
  138. int rc, flags;
  139. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  140. (void *) SLAPI_PLUGIN_VERSION_01 );
  141. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  142. (void *) pdescp );
  143. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_FILTER_AVA,
  144. (void *) cis_filter_ava );
  145. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_FILTER_SUB,
  146. (void *) cis_filter_sub );
  147. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALUES2KEYS,
  148. (void *) cis_values2keys );
  149. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_ASSERTION2KEYS_AVA,
  150. (void *) cis_assertion2keys_ava );
  151. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_ASSERTION2KEYS_SUB,
  152. (void *) cis_assertion2keys_sub );
  153. flags = SLAPI_PLUGIN_SYNTAX_FLAG_ORDERING;
  154. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_FLAGS,
  155. (void *) &flags );
  156. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NAMES,
  157. (void *) names );
  158. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_OID,
  159. (void *) oid );
  160. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_COMPARE,
  161. (void *) cis_compare );
  162. return( rc );
  163. }
  164. int
  165. cis_init( Slapi_PBlock *pb )
  166. {
  167. int rc;
  168. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> cis_init\n", 0, 0, 0 );
  169. rc = register_cis_like_plugin( pb, &dirstring_pdesc, dirstring_names,
  170. DIRSTRING_SYNTAX_OID );
  171. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= cis_init %d\n", rc, 0, 0 );
  172. return( rc );
  173. }
  174. int
  175. boolean_init( Slapi_PBlock *pb )
  176. {
  177. int rc;
  178. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> boolean_init\n", 0, 0, 0 );
  179. rc = register_cis_like_plugin( pb, &boolean_pdesc, boolean_names,
  180. BOOLEAN_SYNTAX_OID );
  181. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= boolean_init %d\n", rc, 0, 0 );
  182. return( rc );
  183. }
  184. int
  185. time_init( Slapi_PBlock *pb )
  186. {
  187. int rc;
  188. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> time_init\n", 0, 0, 0 );
  189. rc = register_cis_like_plugin( pb, &time_pdesc, time_names,
  190. GENERALIZEDTIME_SYNTAX_OID );
  191. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= time_init %d\n", rc, 0, 0 );
  192. return( rc );
  193. }
  194. int
  195. country_init( Slapi_PBlock *pb )
  196. {
  197. int rc;
  198. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> country_init\n", 0, 0, 0 );
  199. rc = register_cis_like_plugin( pb, &country_pdesc, country_names,
  200. COUNTRYSTRING_SYNTAX_OID );
  201. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= country_init %d\n", rc, 0, 0 );
  202. return( rc );
  203. }
  204. int
  205. postal_init( Slapi_PBlock *pb )
  206. {
  207. int rc;
  208. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> postal_init\n", 0, 0, 0 );
  209. rc = register_cis_like_plugin( pb, &postal_pdesc, postal_names,
  210. POSTALADDRESS_SYNTAX_OID );
  211. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= postal_init %d\n", rc, 0, 0 );
  212. return( rc );
  213. }
  214. int
  215. oid_init( Slapi_PBlock *pb )
  216. {
  217. int rc;
  218. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> oid_init\n", 0, 0, 0 );
  219. rc = register_cis_like_plugin( pb, &oid_pdesc, oid_names, OID_SYNTAX_OID );
  220. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= oid_init %d\n", rc, 0, 0 );
  221. return( rc );
  222. }
  223. static int
  224. cis_filter_ava(
  225. Slapi_PBlock *pb,
  226. struct berval *bvfilter,
  227. Slapi_Value **bvals,
  228. int ftype,
  229. Slapi_Value **retVal
  230. )
  231. {
  232. return( string_filter_ava( bvfilter, bvals, SYNTAX_CIS, ftype,
  233. retVal ) );
  234. }
  235. static int
  236. cis_filter_sub(
  237. Slapi_PBlock *pb,
  238. char *initial,
  239. char **any,
  240. char *final,
  241. Slapi_Value **bvals
  242. )
  243. {
  244. return( string_filter_sub( pb, initial, any, final, bvals, SYNTAX_CIS ) );
  245. }
  246. static int
  247. cis_values2keys(
  248. Slapi_PBlock *pb,
  249. Slapi_Value **vals,
  250. Slapi_Value ***ivals,
  251. int ftype
  252. )
  253. {
  254. return( string_values2keys( pb, vals, ivals, SYNTAX_CIS, ftype ) );
  255. }
  256. static int
  257. cis_assertion2keys_ava(
  258. Slapi_PBlock *pb,
  259. Slapi_Value *val,
  260. Slapi_Value ***ivals,
  261. int ftype
  262. )
  263. {
  264. return(string_assertion2keys_ava( pb, val, ivals, SYNTAX_CIS, ftype ));
  265. }
  266. static int
  267. cis_assertion2keys_sub(
  268. Slapi_PBlock *pb,
  269. char *initial,
  270. char **any,
  271. char *final,
  272. Slapi_Value ***ivals
  273. )
  274. {
  275. return( string_assertion2keys_sub( pb, initial, any, final, ivals,
  276. SYNTAX_CIS ) );
  277. }
  278. static int cis_compare(
  279. struct berval *v1,
  280. struct berval *v2
  281. )
  282. {
  283. return value_cmp(v1,v2,SYNTAX_CIS,3 /* Normalise both values */);
  284. }