r17580: Add a new tools to convert back from AD-like schema to OpenLDAP.
[bbaumbach/samba-autobuild/.git] / source4 / lib / ldb / tools / convert.c
1 /* 
2    ldb database library
3
4    Copyright (C) Simo Sorce 2005
5
6      ** NOTE! The following LGPL license applies to the ldb
7      ** library. This does NOT imply that all of Samba is released
8      ** under the LGPL
9    
10    This library is free software; you can redistribute it and/or
11    modify it under the terms of the GNU Lesser General Public
12    License as published by the Free Software Foundation; either
13    version 2 of the License, or (at your option) any later version.
14
15    This library is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    Lesser General Public License for more details.
19
20    You should have received a copy of the GNU Lesser General Public
21    License along with this library; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 */
24
25 #include "convert.h"
26 #include "includes.h"
27 #include "ldb/include/includes.h"
28
29 /* Shared map for converting syntax between formats */
30 static const struct syntax_map syntax_map[] = {
31         { 
32                 .Standard_OID = "1.3.6.1.4.1.1466.115.121.1.12", 
33                 .AD_OID = "2.5.5.1", 
34                 .equality = "distinguishedNameMatch",
35                 .comment = "Object(DS-DN) == a DN" 
36         },
37         {
38                 .Standard_OID =  "1.3.6.1.4.1.1466.115.121.1.38",
39                 .AD_OID =  "2.5.5.2",
40                 .equality = "objectIdentifierMatch",
41                 .comment =  "OID String"
42         },
43         { 
44                 .Standard_OID =  "1.2.840.113556.1.4.905", 
45                 .AD_OID =  "2.5.5.4",
46                 .equality = "caseIgnoreMatch",
47                 .substring = "caseIgnoreSubstringsMatch",
48                 .comment =   "Case Insensitive String" 
49         },
50         {
51                 .Standard_OID =  "1.3.6.1.4.1.1466.115.121.1.44",
52                 .AD_OID =   "2.5.5.5",
53                 .equality = "caseExactIA5Match",
54                 .comment = "Printable String"
55         },
56         {
57                 .Standard_OID =  "1.3.6.1.4.1.1466.115.121.1.36",
58                 .AD_OID =   "2.5.5.6", 
59                 .equality = "numericStringMatch",
60                 .substring = "numericStringSubstringsMatch",
61                 .comment = "Numeric String" 
62         },
63         { 
64                 .Standard_OID =  "1.2.840.113556.1.4.903", 
65                 .AD_OID =  "2.5.5.7", 
66                 .equality = "distinguishedNameMatch",
67                 .comment = "OctetString: Binary+DN" 
68         },
69         { 
70                 .Standard_OID =  "1.3.6.1.4.1.1466.115.121.1.7",
71                 .AD_OID =   "2.5.5.8", 
72                 .equality = "booleanMatch",
73                 .comment = "Boolean" 
74         },
75         { 
76                 .Standard_OID =  "1.3.6.1.4.1.1466.115.121.1.27",
77                 .AD_OID =   "2.5.5.9", 
78                 .equality = "integerMatch",
79                 .comment = "Integer" 
80         },
81         { 
82                 .Standard_OID = "1.3.6.1.4.1.1466.115.121.1.40",
83                 .AD_OID       = "2.5.5.10",
84                 .equality     = "octetStringMatch",
85                 .comment      =  "Octet String"
86         },
87         {
88                 .Standard_OID =  "1.3.6.1.4.1.1466.115.121.1.24",
89                 .AD_OID =   "2.5.5.11", 
90                 .equality = "generalizedTimeMatch",
91                 .comment = "Generalized Time"
92         },
93         { 
94                 .Standard_OID =  "1.3.6.1.4.1.1466.115.121.1.53",
95                 .AD_OID =   "2.5.5.11", 
96                 .equality = "generalizedTimeMatch",
97                 .comment = "UTC Time" 
98         },
99         { 
100                 .Standard_OID =  "1.3.6.1.4.1.1466.115.121.1.15",
101                 .AD_OID =   "2.5.5.12", 
102                 .equality = "caseIgnoreMatch",
103                 .substring = "caseIgnoreSubstringsMatch",
104                 .comment = "Directory String"
105         },
106         {
107                 .Standard_OID =  "1.3.6.1.4.1.1466.115.121.1.43",
108                 .AD_OID =   "2.5.5.13", 
109                 .comment = "Presentation Address" 
110         },
111         {
112                 .Standard_OID =   "Not Found Yet", 
113                 .AD_OID =  "2.5.5.14", 
114                 .equality = "distinguishedNameMatch",
115                 .comment = "OctetString: String+DN" 
116         },
117         {
118                 .Standard_OID =  "1.2.840.113556.1.4.907",
119                 .AD_OID =   "2.5.5.15", 
120                 .equality     = "octetStringMatch",
121                 .comment = "NT Security Descriptor"
122         },
123         { 
124                 .Standard_OID =  "1.2.840.113556.1.4.906", 
125                 .AD_OID =  "2.5.5.16", 
126                 .equality = "integerMatch",
127                 .comment = "Large Integer" 
128         },
129         {
130                 .Standard_OID =  "1.3.6.1.4.1.1466.115.121.1.40",
131                 .AD_OID =   "2.5.5.17",
132                 .equality     = "octetStringMatch",
133                 .comment =  "Octet String - Security Identifier (SID)" 
134         },
135         { 
136                 .Standard_OID =  "1.3.6.1.4.1.1466.115.121.1.26", 
137                 .AD_OID =  "2.5.5.5", 
138                 .equality = "caseExactIA5Match",
139                 .comment = "IA5 String" 
140         },
141         {  }
142 };
143
144
145 const struct syntax_map *find_syntax_map_by_ad_oid(const char *ad_oid) 
146 {
147         int i;
148         for (i=0; syntax_map[i].Standard_OID; i++) {
149                 if (strcasecmp(ad_oid, syntax_map[i].AD_OID) == 0) {
150                         return &syntax_map[i];
151                 }
152         }
153         return NULL;
154 }
155
156 const struct syntax_map *find_syntax_map_by_standard_oid(const char *standard_oid) 
157 {
158         int i;
159         for (i=0; syntax_map[i].Standard_OID; i++) {
160                 if (strcasecmp(standard_oid, syntax_map[i].Standard_OID) == 0) {
161                         return &syntax_map[i];
162                 }
163         }
164         return NULL;
165 }