1
0

cis.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. #define GENERALIZEDTIMEMATCH_OID "2.5.13.27"
  79. #define GENERALIZEDTIMEORDERINGMATCH_OID "2.5.13.28"
  80. static Slapi_MatchingRuleEntry
  81. generalizedTimeMatch = { GENERALIZEDTIMEMATCH_OID, NULL /* no alias? */,
  82. "generalizedTimeMatch", "The rule evaluates to TRUE if and only if the attribute value represents the same universal coordinated time as the assertion value.",
  83. GENERALIZEDTIME_SYNTAX_OID, 0 /* not obsolete */ };
  84. static Slapi_MatchingRuleEntry
  85. generalizedTimeOrderingMatch = { GENERALIZEDTIMEORDERINGMATCH_OID, NULL /* no alias? */,
  86. "generalizedTimeOrderingMatch", "The rule evaluates to TRUE if and only if the attribute value represents a universal coordinated time that is earlier than the universal coordinated time represented by the assertion value.",
  87. GENERALIZEDTIME_SYNTAX_OID, 0 /* not obsolete */ };
  88. static char *country_names[] = { "Country String",
  89. COUNTRYSTRING_SYNTAX_OID, 0};
  90. static char *postal_names[] = { "Postal Address",
  91. POSTALADDRESS_SYNTAX_OID, 0};
  92. static char *oid_names[] = { "OID",
  93. OID_SYNTAX_OID, 0};
  94. /*
  95. TBD (XXX)
  96. "1.3.6.1.4.1.1466.115.121.1.16 \"DIT Content Rule Description
  97. \" "
  98. "1.3.6.1.4.1.1466.115.121.1.17 \"DIT Structure Rule Descripti
  99. on\" "
  100. "1.3.6.1.4.1.1466.115.121.1.20 \"DSE Type\" "
  101. "1.3.6.1.4.1.1466.115.121.1.30 \"Matching Rule Description\"
  102. "
  103. "1.3.6.1.4.1.1466.115.121.1.31 \"Matching Rule Use Descriptio
  104. n\" "
  105. "1.3.6.1.4.1.1466.115.121.1.35 \"Name Form Description\" "
  106. "1.3.6.1.4.1.1466.115.121.1.44 \"Printable String\" "
  107. "1.3.6.1.4.1.1466.115.121.1.45 \"Subtree Specification\" "
  108. "1.3.6.1.4.1.1466.115.121.1.54 \"LDAP Syntax Description\" "
  109. "1.3.6.1.4.1.1466.115.121.1.55 \"Modify Rights\" "
  110. "1.3.6.1.4.1.1466.115.121.1.56 \"LDAP Schema Description\" "
  111. "1.3.6.1.4.1.1466.115.121.1.25 \"Guide\" "
  112. "1.3.6.1.4.1.1466.115.121.1.52 \"Telex Number\" "
  113. "1.3.6.1.4.1.1466.115.121.1.51 \"Teletex Terminal Identifier\
  114. " "
  115. "1.3.6.1.4.1.1466.115.121.1.14 \"Delivery Method\" "
  116. "1.3.6.1.4.1.1466.115.121.1.43 \"Presentation Address\" "
  117. "1.3.6.1.4.1.1466.115.121.1.21 \"Enhanced Guide\" "
  118. "1.3.6.1.4.1.1466.115.121.1.34 \"Name and Optional UID\" "
  119. "1.2.840.113556.1.4.905 \"CaseIgnoreString\" "
  120. "1.3.6.1.1.1.0.0 \"nisNetgroupTripleSyntax\" "
  121. "1.3.6.1.1.1.0.1 \"bootParameterSyntax\" ");
  122. */
  123. static Slapi_PluginDesc dirstring_pdesc = { "directorystring-syntax",
  124. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  125. "DirectoryString attribute syntax plugin" };
  126. static Slapi_PluginDesc boolean_pdesc = { "boolean-syntax",
  127. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  128. "Boolean attribute syntax plugin" };
  129. static Slapi_PluginDesc time_pdesc = { "time-syntax",
  130. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  131. "GeneralizedTime attribute syntax plugin" };
  132. static Slapi_PluginDesc country_pdesc = { "countrystring-syntax",
  133. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  134. "Country String attribute syntax plugin" };
  135. static Slapi_PluginDesc postal_pdesc = { "postaladdress-syntax",
  136. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  137. "Postal Address attribute syntax plugin" };
  138. static Slapi_PluginDesc oid_pdesc = { "oid-syntax",
  139. PLUGIN_MAGIC_VENDOR_STR, PRODUCTTEXT,
  140. "OID attribute syntax plugin" };
  141. /*
  142. * register_cis_like_plugin(): register all items for a cis-like plugin.
  143. */
  144. static int
  145. register_cis_like_plugin( Slapi_PBlock *pb, Slapi_PluginDesc *pdescp,
  146. char **names, char *oid )
  147. {
  148. int rc, flags;
  149. rc = slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
  150. (void *) SLAPI_PLUGIN_VERSION_01 );
  151. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
  152. (void *) pdescp );
  153. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_FILTER_AVA,
  154. (void *) cis_filter_ava );
  155. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_FILTER_SUB,
  156. (void *) cis_filter_sub );
  157. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_VALUES2KEYS,
  158. (void *) cis_values2keys );
  159. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_ASSERTION2KEYS_AVA,
  160. (void *) cis_assertion2keys_ava );
  161. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_ASSERTION2KEYS_SUB,
  162. (void *) cis_assertion2keys_sub );
  163. flags = SLAPI_PLUGIN_SYNTAX_FLAG_ORDERING;
  164. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_FLAGS,
  165. (void *) &flags );
  166. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_NAMES,
  167. (void *) names );
  168. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_OID,
  169. (void *) oid );
  170. rc |= slapi_pblock_set( pb, SLAPI_PLUGIN_SYNTAX_COMPARE,
  171. (void *) cis_compare );
  172. return( rc );
  173. }
  174. int
  175. cis_init( Slapi_PBlock *pb )
  176. {
  177. int rc;
  178. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> cis_init\n", 0, 0, 0 );
  179. rc = register_cis_like_plugin( pb, &dirstring_pdesc, dirstring_names,
  180. DIRSTRING_SYNTAX_OID );
  181. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= cis_init %d\n", rc, 0, 0 );
  182. return( rc );
  183. }
  184. int
  185. boolean_init( Slapi_PBlock *pb )
  186. {
  187. int rc;
  188. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> boolean_init\n", 0, 0, 0 );
  189. rc = register_cis_like_plugin( pb, &boolean_pdesc, boolean_names,
  190. BOOLEAN_SYNTAX_OID );
  191. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= boolean_init %d\n", rc, 0, 0 );
  192. return( rc );
  193. }
  194. int
  195. time_init( Slapi_PBlock *pb )
  196. {
  197. int rc;
  198. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> time_init\n", 0, 0, 0 );
  199. rc = register_cis_like_plugin( pb, &time_pdesc, time_names,
  200. GENERALIZEDTIME_SYNTAX_OID );
  201. /* also register this plugin for matching rules */
  202. rc |= slapi_matchingrule_register(&generalizedTimeMatch);
  203. rc |= slapi_matchingrule_register(&generalizedTimeOrderingMatch);
  204. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= time_init %d\n", rc, 0, 0 );
  205. return( rc );
  206. }
  207. int
  208. country_init( Slapi_PBlock *pb )
  209. {
  210. int rc;
  211. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> country_init\n", 0, 0, 0 );
  212. rc = register_cis_like_plugin( pb, &country_pdesc, country_names,
  213. COUNTRYSTRING_SYNTAX_OID );
  214. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= country_init %d\n", rc, 0, 0 );
  215. return( rc );
  216. }
  217. int
  218. postal_init( Slapi_PBlock *pb )
  219. {
  220. int rc;
  221. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> postal_init\n", 0, 0, 0 );
  222. rc = register_cis_like_plugin( pb, &postal_pdesc, postal_names,
  223. POSTALADDRESS_SYNTAX_OID );
  224. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= postal_init %d\n", rc, 0, 0 );
  225. return( rc );
  226. }
  227. int
  228. oid_init( Slapi_PBlock *pb )
  229. {
  230. int rc;
  231. LDAPDebug( LDAP_DEBUG_PLUGIN, "=> oid_init\n", 0, 0, 0 );
  232. rc = register_cis_like_plugin( pb, &oid_pdesc, oid_names, OID_SYNTAX_OID );
  233. LDAPDebug( LDAP_DEBUG_PLUGIN, "<= oid_init %d\n", rc, 0, 0 );
  234. return( rc );
  235. }
  236. static int
  237. cis_filter_ava(
  238. Slapi_PBlock *pb,
  239. struct berval *bvfilter,
  240. Slapi_Value **bvals,
  241. int ftype,
  242. Slapi_Value **retVal
  243. )
  244. {
  245. return( string_filter_ava( bvfilter, bvals, SYNTAX_CIS, ftype,
  246. retVal ) );
  247. }
  248. static int
  249. cis_filter_sub(
  250. Slapi_PBlock *pb,
  251. char *initial,
  252. char **any,
  253. char *final,
  254. Slapi_Value **bvals
  255. )
  256. {
  257. return( string_filter_sub( pb, initial, any, final, bvals, SYNTAX_CIS ) );
  258. }
  259. static int
  260. cis_values2keys(
  261. Slapi_PBlock *pb,
  262. Slapi_Value **vals,
  263. Slapi_Value ***ivals,
  264. int ftype
  265. )
  266. {
  267. return( string_values2keys( pb, vals, ivals, SYNTAX_CIS, ftype ) );
  268. }
  269. static int
  270. cis_assertion2keys_ava(
  271. Slapi_PBlock *pb,
  272. Slapi_Value *val,
  273. Slapi_Value ***ivals,
  274. int ftype
  275. )
  276. {
  277. return(string_assertion2keys_ava( pb, val, ivals, SYNTAX_CIS, ftype ));
  278. }
  279. static int
  280. cis_assertion2keys_sub(
  281. Slapi_PBlock *pb,
  282. char *initial,
  283. char **any,
  284. char *final,
  285. Slapi_Value ***ivals
  286. )
  287. {
  288. return( string_assertion2keys_sub( pb, initial, any, final, ivals,
  289. SYNTAX_CIS ) );
  290. }
  291. static int cis_compare(
  292. struct berval *v1,
  293. struct berval *v2
  294. )
  295. {
  296. return value_cmp(v1,v2,SYNTAX_CIS,3 /* Normalise both values */);
  297. }