r25068: Older samba3 DCs will return DCERPC_FAULT_OP_RNG_ERROR for every opcode on the
[Samba.git] / source / lib / ldb / ldb_sqlite3 / schema
blob08dc50de089a05098c11828c554959c400495f44
1                 -- ------------------------------------------------------
3                 PRAGMA auto_vacuum=1;
5                 -- ------------------------------------------------------
7                 BEGIN EXCLUSIVE;
9                 -- ------------------------------------------------------
11                 CREATE TABLE ldb_info AS 
12                   SELECT 'LDB' AS database_type, 
13                          '1.0' AS version;
15                 /*
16                  * Get the next USN value with:
17                  *   BEGIN EXCLUSIVE;
18                  *   UPDATE usn SET value = value + 1;
19                  *   SELECT value FROM usn;
20                  *   COMMIT;
21                  */
22                 CREATE TABLE usn
23                 (
24                   value           INTEGER
25                 );
27                 CREATE TABLE ldb_object
28                 (
29                   /* tree_key is auto-generated by the insert trigger */
30                   tree_key        TEXT PRIMARY KEY,
32                   parent_tree_key TEXT,
33                   dn              TEXT,
35                   attr_name       TEXT REFERENCES ldb_attributes,
36                   attr_value      TEXT,
38                   /*
39                    * object_type can take on these values (to date):
40                    *   1: object is a node of a DN
41                    *   2: object is an attribute/value pair of its parent DN
42                    */
43                   object_type     INTEGER,
45                   /*
46                    * if object_type is 1, the node can have children.
47                    * this tracks the maximum previously assigned child
48                    * number so we can generate a new unique tree key for
49                    * a new child object.  note that this is always incremented,
50                    * so if children are deleted, this will not represent
51                    * the _number_ of children.
52                    */
53                   max_child_num   INTEGER,
55                   /*
56                    * Automatically maintained meta-data (a gift for metze)
57                    */
58                   object_guid     TEXT UNIQUE,
59                   timestamp       INTEGER,  -- originating_time
60                   invoke_id       TEXT,     -- GUID: originating_invocation_id
61                   usn             INTEGER,  -- hyper: originating_usn
63                   /* do not allow duplicate name/value pairs */
64                   UNIQUE (parent_tree_key, attr_name, attr_value, object_type)
65                 );
67                 CREATE TABLE ldb_attributes
68                 (
69                   attr_name             TEXT PRIMARY KEY,
70                   parent_tree_key       TEXT,
72                   objectclass_p         BOOLEAN DEFAULT 0,
74                   case_insensitive_p    BOOLEAN DEFAULT 0,
75                   wildcard_p            BOOLEAN DEFAULT 0,
76                   hidden_p              BOOLEAN DEFAULT 0,
77                   integer_p             BOOLEAN DEFAULT 0,
79                   /* tree_key is auto-generated by the insert trigger */
80                   tree_key              TEXT, -- null if not a object/sub class
81                                               -- level 1 if an objectclass
82                                               -- level 1-n if a subclass
83                   max_child_num         INTEGER
84                 );
86                 -- ------------------------------------------------------
88                 CREATE INDEX ldb_object_dn_idx
89                   ON ldb_object (dn);
91                 CREATE INDEX ldb_attributes_tree_key_ids
92                   ON ldb_attributes (tree_key);
94                 -- ------------------------------------------------------
96                 /* Gifts for metze.  Automatically updated meta-data */
97                 CREATE TRIGGER ldb_object_insert_tr
98                   AFTER INSERT
99                   ON ldb_object
100                   FOR EACH ROW
101                     BEGIN
102                       UPDATE ldb_object
103                         SET max_child_num = max_child_num + 1
104                         WHERE tree_key = new.parent_tree_key;
105                       UPDATE usn SET value = value + 1;
106                       UPDATE ldb_object
107                         SET tree_key =
108                               (SELECT
109                                  new.tree_key ||
110                                  base160(SELECT max_child_num
111                                            FROM ldb_object
112                                            WHERE tree_key =
113                                                  new.parent_tree_key));
114                             max_child_num = 0,
115                             object_guid = random_guid(),
116                             timestamp = strftime('%s', 'now'),
117                             usn = (SELECT value FROM usn);
118                         WHERE tree_key = new.tree_key;
119                     END;
121                 CREATE TRIGGER ldb_object_update_tr
122                   AFTER UPDATE
123                   ON ldb_object
124                   FOR EACH ROW
125                     BEGIN
126                       UPDATE usn SET value = value + 1;
127                       UPDATE ldb_object
128                         SET timestamp = strftime('%s', 'now'),
129                             usn = (SELECT value FROM usn);
130                         WHERE tree_key = new.tree_key;
131                     END;
133                 CREATE TRIGGER ldb_attributes_insert_tr
134                   AFTER INSERT
135                   ON ldb_attributes
136                   FOR EACH ROW
137                     BEGIN
138                       UPDATE ldb_attributes
139                         SET max_child_num = max_child_num + 1
140                         WHERE tree_key = new.parent_tree_key;
141                       UPDATE ldb_attributes
142                         SET tree_key =
143                               (SELECT
144                                  new.tree_key ||
145                                  base160(SELECT max_child_num
146                                            FROM ldb_attributes
147                                            WHERE tree_key =
148                                                  new.parent_tree_key));
149                             max_child_num = 0
150                         WHERE tree_key = new.tree_key;
151                     END;
154                 -- ------------------------------------------------------
156                 /* Initialize usn */
157                 INSERT INTO usn (value) VALUES (0);
159                 /* Create root object */
160                 INSERT INTO ldb_object
161                     (tree_key, parent_tree_key,
162                      dn,
163                      object_type, max_child_num)
164                   VALUES ('', NULL,
165                           '',
166                           1, 0);
168                 /* We need an implicit "top" level object class */
169                 INSERT INTO ldb_attributes (attr_name,
170                                             parent_tree_key)
171                   SELECT 'top', '';
173                 -- ------------------------------------------------------
175                 COMMIT;
177                 -- ------------------------------------------------------
180  * dn: o=University of Michigan,c=US
181  * objectclass: organization
182  * objectclass: domainRelatedObject
183  */
184 -- newDN
185 BEGIN;
187 INSERT OR IGNORE INTO ldb_object
188     (parent_tree_key
189      dn,
190      attr_name, attr_value, object_type, max_child_num)
191   VALUES ('',
192           'c=US',
193           'c', 'US', 1, 0);
195 INSERT INTO ldb_object
196     (parent_tree_key,
197      dn,
198      attr_name, attr_value, object_type, max_child_num)
199   VALUES ('0001',
200           'o=University of Michigan,c=US',
201           'o', 'University of Michigan', 1, 0);
203 -- newObjectClass
204 INSERT OR IGNORE INTO ldb_attributes
205     (attr_name, parent_tree_key, objectclass_p)
206   VALUES
207     ('objectclass', '', 1);
209 INSERT INTO ldb_object
210     (parent_tree_key,
211      dn,
212      attr_name, attr_value, object_type, max_child_num)
213   VALUES ('00010001',
214           NULL,
215           'objectclass', 'organization', 2, 0);
217 INSERT OR IGNORE INTO ldb_attributes
218     (attr_name, parent_tree_key, objectclass_p)
219   VALUES
220     ('objectclass', '', 1);
222 INSERT INTO ldb_object
223     (parent_tree_key,
224      dn,
225      attr_name, attr_value, object_type, max_child_num)
226   VALUES ('00010001',
227           NULL,
228           'objectclass', 'domainRelatedObject', 2, 0);
230 COMMIT;
234  * dn: o=University of Michigan,c=US
235  * l: Ann Arbor, Michigan
236  * st: Michigan
237  * o: University of Michigan
238  * o: UMICH
239  * seeAlso:
240  * telephonenumber: +1 313 764-1817
241  */
242 -- addAttrValuePair
243 BEGIN;
245 INSERT INTO ldb_object
246     (parent_tree_key, dn,
247      attr_name, attr_value, object_type, max_child_num)
248   VALUES ('00010001', NULL,
249           'l', 'Ann Arbor, Michigan', 2, 0);
251 INSERT INTO ldb_object
252     (parent_tree_key, dn,
253      attr_name, attr_value, object_type, max_child_num)
254   VALUES ('00010001', NULL,
255           'st', 'Michigan', 2, 0);
257 INSERT INTO ldb_object
258     (parent_tree_key, dn,
259      attr_name, attr_value, object_type, max_child_num)
260   VALUES ('00010001', NULL,
261           'o', 'University of Michigan', 2, 0);
263 INSERT INTO ldb_object
264     (parent_tree_key, dn,
265      attr_name, attr_value, object_type, max_child_num)
266   VALUES ('00010001', NULL,
267           'o', 'UMICH', 2, 0);
269 INSERT INTO ldb_object
270     (parent_tree_key, dn,
271      attr_name, attr_value, object_type, max_child_num)
272   VALUES ('00010001', NULL,
273           'seeAlso', '', 2, 0);
275 INSERT INTO ldb_object
276     (parent_tree_key, dn,
277      attr_name, attr_value, object_type, max_child_num)
278   VALUES ('00010001', NULL,
279           'telephonenumber', '+1 313 764-1817', 2, 0);
281 COMMIT;
283 -- ----------------------------------------------------------------------
286  * dn: @ATTRIBUTES
287  * uid: CASE_INSENSITIVE WILDCARD
288  * cn: CASE_INSENSITIVE
289  * ou: CASE_INSENSITIVE
290  * dn: CASE_INSENSITIVE
291  */
292 -- newAttribute
294 BEGIN;
296 INSERT OR IGNORE INTO ldb_attributes
297     (attr_name, parent_tree_key, objectclass_p)
298   VALUES
299     ('uid', '', 0);
301 UPDATE ldb_attributes
302   SET case_insensitive_p = 1,
303       wildcard_p = 1,
304       hidden_p = 0,
305       integer_p = 0
306   WHERE attr_name = 'uid'
308 UPDATE ldb_attributes
309   SET case_insensitive_p = 1,
310       wildcard_p = 0,
311       hidden_p = 0,
312       integer_p = 0
313   WHERE attr_name = 'cn'
315 UPDATE ldb_attributes
316   SET case_insensitive_p = 1,
317       wildcard_p = 0,
318       hidden_p = 0,
319       integer_p = 0
320   WHERE attr_name = 'ou'
322 UPDATE ldb_attributes
323   SET case_insensitive_p = 1,
324       wildcard_p = 0,
325       hidden_p = 0,
326       integer_p = 0
327   WHERE attr_name = 'dn'
329 -- ----------------------------------------------------------------------
332  * dn: @SUBCLASSES
333  * top: domain
334  * top: person
335  * domain: domainDNS
336  * person: organizationalPerson
337  * person: fooPerson
338  * organizationalPerson: user
339  * organizationalPerson: OpenLDAPperson
340  * user: computer
341  */
342 -- insertSubclass
344 /* NOT YET UPDATED!!! *
347 INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
348   SELECT 'domain', /* next_tree_key('top') */ '00010001';
349 INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
350   SELECT 'person', /* next_tree_key('top') */ '00010002';
351 INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
352   SELECT 'domainDNS', /* next_tree_key('domain') */ '000100010001';
353 INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
354   SELECT 'organizationalPerson', /* next_tree_key('person') */ '000100020001';
355 INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
356   SELECT 'fooPerson', /* next_tree_key('person') */ '000100020002';
357 INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
358   SELECT 'user', /* next_tree_key('organizationalPerson') */ '0001000200010001';
359 INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
360   SELECT 'OpenLDAPperson', /* next_tree_key('organizationPerson') */ '0001000200010002';
361 INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
362   SELECT 'computer', /* next_tree_key('user') */ '0001000200010001';