Initial implementation of DN-String and DN-Binary syntax.
[nivanova/openldap.git] / contrib / slapd-modules / samba4 / dnsyntax.c
1
2 #include "portable.h"
3
4 #ifdef SLAPD_OVER_DNSYNTAX
5
6 #include <stdio.h>
7
8 #include <ac/string.h>
9 #include <ac/ctype.h>
10
11 #include "slap.h"
12 #include "config.h"
13 #include "lutil.h"
14
15 static slap_overinst dnsyntax;
16
17 static int
18 dnStringSyntaxValidate(
19         Syntax          *syntax,
20         struct berval   *val )
21 {
22         /* TODO, in samba this is most likely validated in a module, check */
23         return LDAP_SUCCESS;
24 }
25
26 static int
27 dnBinarySyntaxValidate(
28         Syntax          *syntax,
29         struct berval   *val )
30 {
31         return LDAP_SUCCESS;
32 }
33
34 static char     *dnsyntaxMRs[] = {
35         "octetStringMatch",
36         NULL
37 };
38
39 static struct {
40         char                    *oid;
41         slap_syntax_defs_rec    syn;
42         char                    **mrs;
43 } dnsyntaxes[] = {
44         { "1.2.840.113556.1.4.903" ,
45                 { "( 1.2.840.113556.1.4.903 DESC 'DN-String, String + DN' )",
46                         0,
47                         NULL,
48                         dnStringSyntaxValidate,
49                         NULL },
50                 dnsyntaxMRs },
51         { "1.2.840.113556.1.4.904" ,
52                 { "( 1.2.840.113556.1.4.904 DESC 'DN-Binary, Binary blob + DN' )",
53                         0,
54                         NULL,
55                         dnBinarySyntaxValidate,
56                         NULL },
57                 dnsyntaxMRs },
58         { NULL }
59 };
60
61 int dnsyntax_initialize()
62 {
63         int i;
64
65         dnsyntax.on_bi.bi_type = "dnsyntax";
66
67         for ( i=0; dnsyntaxes[i].oid; i++ ) {
68                 int code;
69
70                 code = register_syntax( &dnsyntaxes[ i ].syn );
71                 if ( code != 0 ) {
72                         Debug( LDAP_DEBUG_ANY,
73                                 "dnsyntax_init: register_syntax failed\n",
74                                 0, 0, 0 );
75                         return code;
76                 }
77
78                 if ( dnsyntaxes[i].mrs != NULL ) {
79                         code = mr_make_syntax_compat_with_mrs(
80                                 dnsyntaxes[i].oid, dnsyntaxes[i].mrs );
81                         if ( code < 0 ) {
82                                 Debug( LDAP_DEBUG_ANY,
83                                         "dnsyntax_init: "
84                                         "mr_make_syntax_compat_with_mrs "
85                                         "failed\n",
86                                         0, 0, 0 );
87                                 return code;
88                         }
89                 }
90         }
91
92
93
94         return overlay_register(&dnsyntax);
95 }
96
97 #if SLAPD_OVER_DNSYNTAX == SLAPD_MOD_DYNAMIC
98 int
99 init_module( int argc, char *argv[] )
100 {
101         return dnsyntax_initialize();
102 }
103 #endif
104
105 #endif /* SLAPD_OVER_DNSYNTAX */