wmi-1.3.16 from opsview.com
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
trees.ps contains an explanation of the Genealogical Representation of Trees
|
||||
in Databases which is being used in ldb_sqlite3. Note that we use fgID
|
||||
representation with 4 bytes per level, so we can represent 6.5E+08 subclasses
|
||||
of any object class. This should be adequate for our purposes. :-)
|
||||
|
||||
The following document is the primary basis for the schema currently being
|
||||
used here: http://www.research.ibm.com/journal/sj/392/shi.html
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
base160 code used by ldb_sqlite3
|
||||
|
||||
Copyright (C) 2004 Derrell Lipman
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* ldb_sqlite3_base160()
|
||||
*
|
||||
* Convert an integer value to a string containing the base 160 representation
|
||||
* of the integer. We always convert to a string representation that is 4
|
||||
* bytes in length, and we always null terminate.
|
||||
*
|
||||
* Parameters:
|
||||
* val --
|
||||
* The value to be converted
|
||||
*
|
||||
* result --
|
||||
* Buffer in which the result is to be placed
|
||||
*
|
||||
* Returns:
|
||||
* nothing
|
||||
*/
|
||||
static unsigned char base160tab[161] =
|
||||
{
|
||||
48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , /* 0-9 */
|
||||
58 , 59 , 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 , /* : ; A-H */
|
||||
73 , 74 , 75 , 76 , 77 , 78 , 79 , 80 , 81 , 82 , /* I-R */
|
||||
83 , 84 , 85 , 86 , 87 , 88 , 89 , 90 , 97 , 98 , /* S-Z , a-b */
|
||||
99 , 100, 101, 102, 103, 104, 105, 106, 107, 108, /* c-l */
|
||||
109, 110, 111, 112, 113, 114, 115, 116, 117, 118, /* m-v */
|
||||
119, 120, 121, 122, 160, 161, 162, 163, 164, 165, /* w-z, latin1 */
|
||||
166, 167, 168, 169, 170, 171, 172, 173, 174, 175, /* latin1 */
|
||||
176, 177, 178, 179, 180, 181, 182, 183, 184, 185, /* latin1 */
|
||||
186, 187, 188, 189, 190, 191, 192, 193, 194, 195, /* latin1 */
|
||||
196, 197, 198, 199, 200, 201, 202, 203, 204, 205, /* latin1 */
|
||||
206, 207, 208, 209, 210, 211, 212, 213, 214, 215, /* latin1 */
|
||||
216, 217, 218, 219, 220, 221, 222, 223, 224, 225, /* latin1 */
|
||||
226, 227, 228, 229, 230, 231, 232, 233, 234, 235, /* latin1 */
|
||||
236, 237, 238, 239, 240, 241, 242, 243, 244, 245, /* latin1 */
|
||||
246, 247, 248, 249, 250, 251, 252, 253, 254, 255, /* latin1 */
|
||||
'\0'
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* lsqlite3_base160()
|
||||
*
|
||||
* Convert an unsigned long integer into a base160 representation of the
|
||||
* number.
|
||||
*
|
||||
* Parameters:
|
||||
* val --
|
||||
* value to be converted
|
||||
*
|
||||
* result --
|
||||
* character array, 5 bytes long, into which the base160 representation
|
||||
* will be placed. The result will be a four-digit representation of the
|
||||
* number (with leading zeros prepended as necessary), and null
|
||||
* terminated.
|
||||
*
|
||||
* Returns:
|
||||
* Nothing
|
||||
*/
|
||||
void
|
||||
lsqlite3_base160(unsigned long val,
|
||||
unsigned char result[5])
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 3; i >= 0; i--) {
|
||||
|
||||
result[i] = base160tab[val % 160];
|
||||
val /= 160;
|
||||
}
|
||||
|
||||
result[4] = '\0';
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* lsqlite3_base160Next()
|
||||
*
|
||||
* Retrieve the next-greater number in the base160 sequence for the terminal
|
||||
* tree node (the last four digits). Only one tree level (four digits) are
|
||||
* operated on.
|
||||
*
|
||||
* Parameters:
|
||||
* base160 -- a character array containing either an empty string (in which
|
||||
* case no operation is performed), or a string of base160 digits
|
||||
* with a length of a multiple of four digits.
|
||||
*
|
||||
* Upon return, the trailing four digits (one tree level) will
|
||||
* have been incremented by 1.
|
||||
*
|
||||
* Returns:
|
||||
* base160 -- the modified array
|
||||
*/
|
||||
char *
|
||||
lsqlite3_base160Next(char base160[])
|
||||
{
|
||||
int i;
|
||||
int len;
|
||||
unsigned char * pTab;
|
||||
char * pBase160 = base160;
|
||||
|
||||
/*
|
||||
* We need a minimum of four digits, and we will always get a multiple of
|
||||
* four digits.
|
||||
*/
|
||||
if (len = strlen(pBase160)) >= 4)
|
||||
{
|
||||
pBase160 += strlen(pBase160) - 1;
|
||||
|
||||
/* We only carry through four digits: one level in the tree */
|
||||
for (i = 0; i < 4; i++) {
|
||||
|
||||
/* What base160 value does this digit have? */
|
||||
pTab = strchr(base160tab, *pBase160);
|
||||
|
||||
/* Is there a carry? */
|
||||
if (pTab < base160tab + sizeof(base160tab) - 1) {
|
||||
|
||||
/* Nope. Just increment this value and we're done. */
|
||||
*pBase160 = *++pTab;
|
||||
break;
|
||||
} else {
|
||||
|
||||
/*
|
||||
* There's a carry. This value gets base160tab[0], we
|
||||
* decrement the buffer pointer to get the next higher-order
|
||||
* digit, and continue in the loop.
|
||||
*/
|
||||
*pBase160-- = base160tab[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return base160;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,363 @@
|
||||
-- ------------------------------------------------------
|
||||
|
||||
PRAGMA auto_vacuum=1;
|
||||
|
||||
-- ------------------------------------------------------
|
||||
|
||||
BEGIN EXCLUSIVE;
|
||||
|
||||
-- ------------------------------------------------------
|
||||
|
||||
CREATE TABLE ldb_info AS
|
||||
SELECT 'LDB' AS database_type,
|
||||
'1.0' AS version;
|
||||
|
||||
/*
|
||||
* Get the next USN value with:
|
||||
* BEGIN EXCLUSIVE;
|
||||
* UPDATE usn SET value = value + 1;
|
||||
* SELECT value FROM usn;
|
||||
* COMMIT;
|
||||
*/
|
||||
CREATE TABLE usn
|
||||
(
|
||||
value INTEGER
|
||||
);
|
||||
|
||||
CREATE TABLE ldb_object
|
||||
(
|
||||
/* tree_key is auto-generated by the insert trigger */
|
||||
tree_key TEXT PRIMARY KEY,
|
||||
|
||||
parent_tree_key TEXT,
|
||||
dn TEXT,
|
||||
|
||||
attr_name TEXT REFERENCES ldb_attributes,
|
||||
attr_value TEXT,
|
||||
|
||||
/*
|
||||
* object_type can take on these values (to date):
|
||||
* 1: object is a node of a DN
|
||||
* 2: object is an attribute/value pair of its parent DN
|
||||
*/
|
||||
object_type INTEGER,
|
||||
|
||||
/*
|
||||
* if object_type is 1, the node can have children.
|
||||
* this tracks the maximum previously assigned child
|
||||
* number so we can generate a new unique tree key for
|
||||
* a new child object. note that this is always incremented,
|
||||
* so if children are deleted, this will not represent
|
||||
* the _number_ of children.
|
||||
*/
|
||||
max_child_num INTEGER,
|
||||
|
||||
/*
|
||||
* Automatically maintained meta-data (a gift for metze)
|
||||
*/
|
||||
object_guid TEXT UNIQUE,
|
||||
timestamp INTEGER, -- originating_time
|
||||
invoke_id TEXT, -- GUID: originating_invocation_id
|
||||
usn INTEGER, -- hyper: originating_usn
|
||||
|
||||
/* do not allow duplicate name/value pairs */
|
||||
UNIQUE (parent_tree_key, attr_name, attr_value, object_type)
|
||||
);
|
||||
|
||||
CREATE TABLE ldb_attributes
|
||||
(
|
||||
attr_name TEXT PRIMARY KEY,
|
||||
parent_tree_key TEXT,
|
||||
|
||||
objectclass_p BOOLEAN DEFAULT 0,
|
||||
|
||||
case_insensitive_p BOOLEAN DEFAULT 0,
|
||||
wildcard_p BOOLEAN DEFAULT 0,
|
||||
hidden_p BOOLEAN DEFAULT 0,
|
||||
integer_p BOOLEAN DEFAULT 0,
|
||||
|
||||
/* tree_key is auto-generated by the insert trigger */
|
||||
tree_key TEXT, -- null if not a object/sub class
|
||||
-- level 1 if an objectclass
|
||||
-- level 1-n if a subclass
|
||||
max_child_num INTEGER
|
||||
);
|
||||
|
||||
-- ------------------------------------------------------
|
||||
|
||||
CREATE INDEX ldb_object_dn_idx
|
||||
ON ldb_object (dn);
|
||||
|
||||
CREATE INDEX ldb_attributes_tree_key_ids
|
||||
ON ldb_attributes (tree_key);
|
||||
|
||||
-- ------------------------------------------------------
|
||||
|
||||
/* Gifts for metze. Automatically updated meta-data */
|
||||
CREATE TRIGGER ldb_object_insert_tr
|
||||
AFTER INSERT
|
||||
ON ldb_object
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE ldb_object
|
||||
SET max_child_num = max_child_num + 1
|
||||
WHERE tree_key = new.parent_tree_key;
|
||||
UPDATE usn SET value = value + 1;
|
||||
UPDATE ldb_object
|
||||
SET tree_key =
|
||||
(SELECT
|
||||
new.tree_key ||
|
||||
base160(SELECT max_child_num
|
||||
FROM ldb_object
|
||||
WHERE tree_key =
|
||||
new.parent_tree_key));
|
||||
max_child_num = 0,
|
||||
object_guid = random_guid(),
|
||||
timestamp = strftime('%s', 'now'),
|
||||
usn = (SELECT value FROM usn);
|
||||
WHERE tree_key = new.tree_key;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER ldb_object_update_tr
|
||||
AFTER UPDATE
|
||||
ON ldb_object
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE usn SET value = value + 1;
|
||||
UPDATE ldb_object
|
||||
SET timestamp = strftime('%s', 'now'),
|
||||
usn = (SELECT value FROM usn);
|
||||
WHERE tree_key = new.tree_key;
|
||||
END;
|
||||
|
||||
CREATE TRIGGER ldb_attributes_insert_tr
|
||||
AFTER INSERT
|
||||
ON ldb_attributes
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
UPDATE ldb_attributes
|
||||
SET max_child_num = max_child_num + 1
|
||||
WHERE tree_key = new.parent_tree_key;
|
||||
UPDATE ldb_attributes
|
||||
SET tree_key =
|
||||
(SELECT
|
||||
new.tree_key ||
|
||||
base160(SELECT max_child_num
|
||||
FROM ldb_attributes
|
||||
WHERE tree_key =
|
||||
new.parent_tree_key));
|
||||
max_child_num = 0
|
||||
WHERE tree_key = new.tree_key;
|
||||
END;
|
||||
|
||||
|
||||
-- ------------------------------------------------------
|
||||
|
||||
/* Initialize usn */
|
||||
INSERT INTO usn (value) VALUES (0);
|
||||
|
||||
/* Create root object */
|
||||
INSERT INTO ldb_object
|
||||
(tree_key, parent_tree_key,
|
||||
dn,
|
||||
object_type, max_child_num)
|
||||
VALUES ('', NULL,
|
||||
'',
|
||||
1, 0);
|
||||
|
||||
/* We need an implicit "top" level object class */
|
||||
INSERT INTO ldb_attributes (attr_name,
|
||||
parent_tree_key)
|
||||
SELECT 'top', '';
|
||||
|
||||
-- ------------------------------------------------------
|
||||
|
||||
COMMIT;
|
||||
|
||||
-- ------------------------------------------------------
|
||||
|
||||
/*
|
||||
* dn: o=University of Michigan,c=US
|
||||
* objectclass: organization
|
||||
* objectclass: domainRelatedObject
|
||||
*/
|
||||
-- newDN
|
||||
BEGIN;
|
||||
|
||||
INSERT OR IGNORE INTO ldb_object
|
||||
(parent_tree_key
|
||||
dn,
|
||||
attr_name, attr_value, object_type, max_child_num)
|
||||
VALUES ('',
|
||||
'c=US',
|
||||
'c', 'US', 1, 0);
|
||||
|
||||
INSERT INTO ldb_object
|
||||
(parent_tree_key,
|
||||
dn,
|
||||
attr_name, attr_value, object_type, max_child_num)
|
||||
VALUES ('0001',
|
||||
'o=University of Michigan,c=US',
|
||||
'o', 'University of Michigan', 1, 0);
|
||||
|
||||
-- newObjectClass
|
||||
INSERT OR IGNORE INTO ldb_attributes
|
||||
(attr_name, parent_tree_key, objectclass_p)
|
||||
VALUES
|
||||
('objectclass', '', 1);
|
||||
|
||||
INSERT INTO ldb_object
|
||||
(parent_tree_key,
|
||||
dn,
|
||||
attr_name, attr_value, object_type, max_child_num)
|
||||
VALUES ('00010001',
|
||||
NULL,
|
||||
'objectclass', 'organization', 2, 0);
|
||||
|
||||
INSERT OR IGNORE INTO ldb_attributes
|
||||
(attr_name, parent_tree_key, objectclass_p)
|
||||
VALUES
|
||||
('objectclass', '', 1);
|
||||
|
||||
INSERT INTO ldb_object
|
||||
(parent_tree_key,
|
||||
dn,
|
||||
attr_name, attr_value, object_type, max_child_num)
|
||||
VALUES ('00010001',
|
||||
NULL,
|
||||
'objectclass', 'domainRelatedObject', 2, 0);
|
||||
|
||||
COMMIT;
|
||||
|
||||
|
||||
/*
|
||||
* dn: o=University of Michigan,c=US
|
||||
* l: Ann Arbor, Michigan
|
||||
* st: Michigan
|
||||
* o: University of Michigan
|
||||
* o: UMICH
|
||||
* seeAlso:
|
||||
* telephonenumber: +1 313 764-1817
|
||||
*/
|
||||
-- addAttrValuePair
|
||||
BEGIN;
|
||||
|
||||
INSERT INTO ldb_object
|
||||
(parent_tree_key, dn,
|
||||
attr_name, attr_value, object_type, max_child_num)
|
||||
VALUES ('00010001', NULL,
|
||||
'l', 'Ann Arbor, Michigan', 2, 0);
|
||||
|
||||
INSERT INTO ldb_object
|
||||
(parent_tree_key, dn,
|
||||
attr_name, attr_value, object_type, max_child_num)
|
||||
VALUES ('00010001', NULL,
|
||||
'st', 'Michigan', 2, 0);
|
||||
|
||||
INSERT INTO ldb_object
|
||||
(parent_tree_key, dn,
|
||||
attr_name, attr_value, object_type, max_child_num)
|
||||
VALUES ('00010001', NULL,
|
||||
'o', 'University of Michigan', 2, 0);
|
||||
|
||||
INSERT INTO ldb_object
|
||||
(parent_tree_key, dn,
|
||||
attr_name, attr_value, object_type, max_child_num)
|
||||
VALUES ('00010001', NULL,
|
||||
'o', 'UMICH', 2, 0);
|
||||
|
||||
INSERT INTO ldb_object
|
||||
(parent_tree_key, dn,
|
||||
attr_name, attr_value, object_type, max_child_num)
|
||||
VALUES ('00010001', NULL,
|
||||
'seeAlso', '', 2, 0);
|
||||
|
||||
INSERT INTO ldb_object
|
||||
(parent_tree_key, dn,
|
||||
attr_name, attr_value, object_type, max_child_num)
|
||||
VALUES ('00010001', NULL,
|
||||
'telephonenumber', '+1 313 764-1817', 2, 0);
|
||||
|
||||
COMMIT;
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* dn: @ATTRIBUTES
|
||||
* uid: CASE_INSENSITIVE WILDCARD
|
||||
* cn: CASE_INSENSITIVE
|
||||
* ou: CASE_INSENSITIVE
|
||||
* dn: CASE_INSENSITIVE
|
||||
*/
|
||||
-- newAttribute
|
||||
|
||||
BEGIN;
|
||||
|
||||
INSERT OR IGNORE INTO ldb_attributes
|
||||
(attr_name, parent_tree_key, objectclass_p)
|
||||
VALUES
|
||||
('uid', '', 0);
|
||||
|
||||
UPDATE ldb_attributes
|
||||
SET case_insensitive_p = 1,
|
||||
wildcard_p = 1,
|
||||
hidden_p = 0,
|
||||
integer_p = 0
|
||||
WHERE attr_name = 'uid'
|
||||
|
||||
UPDATE ldb_attributes
|
||||
SET case_insensitive_p = 1,
|
||||
wildcard_p = 0,
|
||||
hidden_p = 0,
|
||||
integer_p = 0
|
||||
WHERE attr_name = 'cn'
|
||||
|
||||
UPDATE ldb_attributes
|
||||
SET case_insensitive_p = 1,
|
||||
wildcard_p = 0,
|
||||
hidden_p = 0,
|
||||
integer_p = 0
|
||||
WHERE attr_name = 'ou'
|
||||
|
||||
UPDATE ldb_attributes
|
||||
SET case_insensitive_p = 1,
|
||||
wildcard_p = 0,
|
||||
hidden_p = 0,
|
||||
integer_p = 0
|
||||
WHERE attr_name = 'dn'
|
||||
|
||||
-- ----------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* dn: @SUBCLASSES
|
||||
* top: domain
|
||||
* top: person
|
||||
* domain: domainDNS
|
||||
* person: organizationalPerson
|
||||
* person: fooPerson
|
||||
* organizationalPerson: user
|
||||
* organizationalPerson: OpenLDAPperson
|
||||
* user: computer
|
||||
*/
|
||||
-- insertSubclass
|
||||
|
||||
/* NOT YET UPDATED!!! *
|
||||
|
||||
|
||||
INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
|
||||
SELECT 'domain', /* next_tree_key('top') */ '00010001';
|
||||
INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
|
||||
SELECT 'person', /* next_tree_key('top') */ '00010002';
|
||||
INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
|
||||
SELECT 'domainDNS', /* next_tree_key('domain') */ '000100010001';
|
||||
INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
|
||||
SELECT 'organizationalPerson', /* next_tree_key('person') */ '000100020001';
|
||||
INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
|
||||
SELECT 'fooPerson', /* next_tree_key('person') */ '000100020002';
|
||||
INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
|
||||
SELECT 'user', /* next_tree_key('organizationalPerson') */ '0001000200010001';
|
||||
INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
|
||||
SELECT 'OpenLDAPperson', /* next_tree_key('organizationPerson') */ '0001000200010002';
|
||||
INSERT OR REPLACE INTO ldb_object_classes (class_name, tree_key)
|
||||
SELECT 'computer', /* next_tree_key('user') */ '0001000200010001';
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user