cis.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. /* cis.c - caseignorestring syntax routines */
  39. /*
  40. * This file actually implements three syntax plugins:
  41. * DirectoryString
  42. * Boolean
  43. * GeneralizedTime
  44. *
  45. * We treat them identically for now. XXXmcs: we could do some validation on
  46. * Boolean and GeneralizedTime values (someday, maybe).
  47. */
  48. #include <stdio.h>
  49. #include <string.h>
  50. #include <sys/types.h>
  51. #include "syntax.h"
  52. static int cis_filter_ava( Slapi_PBlock *pb, struct berval *bvfilter,
  53. Slapi_Value **bvals, int ftype, Slapi_Value **retVal );
  54. static int cis_filter_sub( Slapi_PBlock *pb, char *initial, char **any,
  55. char *final, Slapi_Value **bvals );
  56. static int cis_values2keys( Slapi_PBlock *pb, Slapi_Value **val,
  57. Slapi_Value ***ivals, int ftype );
  58. static int cis_assertion2keys_ava( Slapi_PBlock *pb, Slapi_Value *val,
  59. Slapi_Value ***ivals, int ftype );
  60. static int cis_assertion2keys_sub( Slapi_PBlock *pb, char *initial, char **any,
  61. char *final, Slapi_Value ***ivals );
  62. static int cis_compare(struct berval *v1, struct berval *v2);
  63. /*
  64. * Attribute syntaxes. We treat all of these the same for now, even though
  65. * the specifications (e.g., RFC 2252) impose various constraints on the
  66. * the format for each of these.
  67. *
  68. * Note: the first name is the official one from RFC 2252.
  69. */
  70. static char *dirstring_names[] = { "DirectoryString", "cis",
  71. "caseignorestring", DIRSTRING_SYNTAX_OID, 0 };
  72. static char *boolean_names[] = { "Boolean", BOOLEAN_SYNTAX_OID, 0 };
  73. static char *time_names[] = { "GeneralizedTime", "time",
  74. GENERALIZEDTIME_SYNTAX_OID, 0 };
  75. static char *country_names[] = { "Country String",
  76. COUNTRYSTRING_SYNTAX_OID, 0};
  77. static char *postal_names[] = { "Postal Address",
  78. POSTALADDRESS_SYNTAX_OID, 0};
  79. static char *oid_names[] = { "OID",
  80. OID_SYNTAX_OID, 0};
  81. /*
  82. TBD (XXX)
  83. "1.3.6.1.4.1.1466.115.121.1.16 \"DIT Content Rule Description
  84. \" "
  85. "1.3.6.1.4.1.1466.115.121.1.17 \"DIT Structure Rule Descripti
  86. on\" "
  87. "1.3.6.1.4.1.1466.115.121.1.20 \"DSE Type\" "
  88. "1.3.6.1.4.1.1466.115.121.1.30 \"Matching Rule Description\"
  89. "
  90. "1.3.6.1.4.1.1466.115.121.1.31 \"Matching Rule Use Descriptio
  91. n\" "
  92. "1.3.6.1.4.1.1466.115.121.1.35 \"Name Form Description\" "
  93. "1.3.6.1.4.1.1466.115.121.1.44 \"Printable String\" "
  94. "1.3.6.1.4.1.1466.115.121.1.45 \"Subtree Specification\" "
  95. "1.3.6.1.4.1.1466.115.121.1.54 \"LDAP Syntax Description\" "
  96. "1.3.6.1.4.1.1466.115.121.1.55 \"Modify Rights\" "
  97. "1.3.6.1.4.1.1466.115.121.1.56 \"LDAP Schema Description\" "
  98. "1.3.6.1.4.1.1466.115.121.1.25 \"Guide\" "
  99. "1.3.6.1.4.1.1466.115.121.1.52 \"Telex Number\" "
  100. "1.3.6.1.4.1.1466.115.121.1.51 \"Teletex Terminal Identifier\
  101. " "
  102. "1.3.6.1.4.1.1466.115.121.1.14 \"Delivery Method\" "
  103. "1.3.6.1.4.1.1466.115.121.1.43 \"Presentation Address\" "
  104. "1.3.6.1.4.1.1466.115.121.1.21 \"Enhanced Guide\" "
  105. "1.3.6.1.4.1.1466.115.121.1.34 \"Name and Optional UID\" "
  106. "1.2.840.113556.1.4.905 \"CaseIgnoreString\" "
  107. "1.3.6.1.1.1.0.0 \"nisNetgroupTripleSyntax\" "
  108. "1.3.6.1.1.1.0.1 \"bootParameterSyntax\" ");
  109. */
  110. static Slapi_PluginDesc dirstring_pdesc = { "directorystring-syntax",
  111. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  112. "DirectoryString attribute syntax plugin" };
  113. static Slapi_PluginDesc boolean_pdesc = { "boolean-syntax",
  114. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  115. "Boolean attribute syntax plugin" };
  116. static Slapi_PluginDesc time_pdesc = { "time-syntax",
  117. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  118. "GeneralizedTime attribute syntax plugin" };
  119. static Slapi_PluginDesc country_pdesc = { "countrystring-syntax",
  120. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  121. "Country String attribute syntax plugin" };
  122. static Slapi_PluginDesc postal_pdesc = { "postaladdress-syntax",
  123. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  124. "Postal Address attribute syntax plugin" };
  125. static Slapi_PluginDesc oid_pdesc = { "oid-syntax",
  126. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  127. "OID attribute syntax plugin" };
  128. /*
  129. * register_cis_like_plugin(): register all items for a cis-like plugin.
  130. */
  131. static int
  132. register_cis_like_plugin( Slapi_PBlock *pb, Slapi_PluginDesc *pdescp,
  133. char **names, char *oid )
  134. {
  135. int rc, flags;
  136. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  137. (void *) SLAPI_PLUGIN_VERSION_01 );
  138. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  139. (void *) pdescp );
  140. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_FILTER_AVA,
  141. (void *) cis_filter_ava );
  142. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_FILTER_SUB,
  143. (void *) cis_filter_sub );
  144. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALUES2KEYS,
  145. (void *) cis_values2keys );
  146. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_ASSERTION2KEYS_AVA,
  147. (void *) cis_assertion2keys_ava );
  148. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_ASSERTION2KEYS_SUB,
  149. (void *) cis_assertion2keys_sub );
  150. flags = SLAPI_PLUGIN_SYNTAX_FLAG_ORDERING;
  151. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_FLAGS,
  152. (void *) &flags );
  153. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NAMES,
  154. (void *) names );
  155. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_OID,
  156. (void *) oid );
  157. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_COMPARE,
  158. (void *) cis_compare );
  159. return( rc );
  160. }
  161. int
  162. cis_init( Slapi_PBlock *pb )
  163. {
  164. int rc;
  165. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> cis_init\n", 0, 0, 0 );
  166. rc = register_cis_like_plugin( pb, &dirstring_pdesc, dirstring_names,
  167. DIRSTRING_SYNTAX_OID );
  168. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= cis_init %d\n", rc, 0, 0 );
  169. return( rc );
  170. }
  171. int
  172. boolean_init( Slapi_PBlock *pb )
  173. {
  174. int rc;
  175. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> boolean_init\n", 0, 0, 0 );
  176. rc = register_cis_like_plugin( pb, &boolean_pdesc, boolean_names,
  177. BOOLEAN_SYNTAX_OID );
  178. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= boolean_init %d\n", rc, 0, 0 );
  179. return( rc );
  180. }
  181. int
  182. time_init( Slapi_PBlock *pb )
  183. {
  184. int rc;
  185. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> time_init\n", 0, 0, 0 );
  186. rc = register_cis_like_plugin( pb, &time_pdesc, time_names,
  187. GENERALIZEDTIME_SYNTAX_OID );
  188. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= time_init %d\n", rc, 0, 0 );
  189. return( rc );
  190. }
  191. int
  192. country_init( Slapi_PBlock *pb )
  193. {
  194. int rc;
  195. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> country_init\n", 0, 0, 0 );
  196. rc = register_cis_like_plugin( pb, &country_pdesc, country_names,
  197. COUNTRYSTRING_SYNTAX_OID );
  198. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= country_init %d\n", rc, 0, 0 );
  199. return( rc );
  200. }
  201. int
  202. postal_init( Slapi_PBlock *pb )
  203. {
  204. int rc;
  205. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> postal_init\n", 0, 0, 0 );
  206. rc = register_cis_like_plugin( pb, &postal_pdesc, postal_names,
  207. POSTALADDRESS_SYNTAX_OID );
  208. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= postal_init %d\n", rc, 0, 0 );
  209. return( rc );
  210. }
  211. int
  212. oid_init( Slapi_PBlock *pb )
  213. {
  214. int rc;
  215. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> oid_init\n", 0, 0, 0 );
  216. rc = register_cis_like_plugin( pb, &oid_pdesc, oid_names, OID_SYNTAX_OID );
  217. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= oid_init %d\n", rc, 0, 0 );
  218. return( rc );
  219. }
  220. static int
  221. cis_filter_ava(
  222. Slapi_PBlock *pb,
  223. struct berval *bvfilter,
  224. Slapi_Value **bvals,
  225. int ftype,
  226. Slapi_Value **retVal
  227. )
  228. {
  229. return( string_filter_ava( bvfilter, bvals, SYNTAX_CIS, ftype,
  230. retVal ) );
  231. }
  232. static int
  233. cis_filter_sub(
  234. Slapi_PBlock *pb,
  235. char *initial,
  236. char **any,
  237. char *final,
  238. Slapi_Value **bvals
  239. )
  240. {
  241. return( string_filter_sub( pb, initial, any, final, bvals, SYNTAX_CIS ) );
  242. }
  243. static int
  244. cis_values2keys(
  245. Slapi_PBlock *pb,
  246. Slapi_Value **vals,
  247. Slapi_Value ***ivals,
  248. int ftype
  249. )
  250. {
  251. return( string_values2keys( pb, vals, ivals, SYNTAX_CIS, ftype ) );
  252. }
  253. static int
  254. cis_assertion2keys_ava(
  255. Slapi_PBlock *pb,
  256. Slapi_Value *val,
  257. Slapi_Value ***ivals,
  258. int ftype
  259. )
  260. {
  261. return(string_assertion2keys_ava( pb, val, ivals, SYNTAX_CIS, ftype ));
  262. }
  263. static int
  264. cis_assertion2keys_sub(
  265. Slapi_PBlock *pb,
  266. char *initial,
  267. char **any,
  268. char *final,
  269. Slapi_Value ***ivals
  270. )
  271. {
  272. return( string_assertion2keys_sub( pb, initial, any, final, ivals,
  273. SYNTAX_CIS ) );
  274. }
  275. static int cis_compare(
  276. struct berval *v1,
  277. struct berval *v2
  278. )
  279. {
  280. return value_cmp(v1,v2,SYNTAX_CIS,3 /* Normalise both values */);
  281. }