summaryrefslogtreecommitdiff
path: root/usr.sbin/ldapd/schema.h
diff options
context:
space:
mode:
authorMartin Hedenfal <martinh@cvs.openbsd.org>2010-06-29 02:45:47 +0000
committerMartin Hedenfal <martinh@cvs.openbsd.org>2010-06-29 02:45:47 +0000
commit166c6674ba30863af6aaed61d390552332f569a7 (patch)
tree8e6194d97affdda4e666af1071456579edf64caa /usr.sbin/ldapd/schema.h
parent6c3eb79a9477bb18f4d31b8751097558c1b078f2 (diff)
Rewrite the schema parser, as it's not a context-free grammar.
This also brings the config parser more in line with other parse.y in the tree. The new schema parser also supports symbolic OID names. You need to update your /etc/ldapd.conf. Schema files are no longer included with the 'include' keyword, you have to use 'schema' for that. Moves schema-related structures to a separate include file to ease reuse.
Diffstat (limited to 'usr.sbin/ldapd/schema.h')
-rw-r--r--usr.sbin/ldapd/schema.h139
1 files changed, 139 insertions, 0 deletions
diff --git a/usr.sbin/ldapd/schema.h b/usr.sbin/ldapd/schema.h
new file mode 100644
index 00000000000..271a1038d4e
--- /dev/null
+++ b/usr.sbin/ldapd/schema.h
@@ -0,0 +1,139 @@
+/* $OpenBSD: schema.h,v 1.1 2010/06/29 02:45:46 martinh Exp $ */
+
+/*
+ * Copyright (c) 2010 Martin Hedenfalk <martinh@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _schema_h_
+#define _schema_h_
+
+enum usage {
+ USAGE_USER_APP,
+ USAGE_DIR_OP, /* operational attribute */
+ USAGE_DIST_OP, /* operational attribute */
+ USAGE_DSA_OP /* operational attribute */
+};
+
+struct name {
+ SLIST_ENTRY(name) next;
+ const char *name;
+};
+SLIST_HEAD(name_list, name);
+
+struct attr_type {
+ RB_ENTRY(attr_type) link;
+ char *oid;
+ struct name_list *names;
+ char *desc;
+ int obsolete;
+ struct attr_type *sup;
+ char *equality;
+ char *ordering;
+ char *substr;
+ char *syntax;
+ int single;
+ int collective;
+ int immutable; /* no-user-modification */
+ enum usage usage;
+};
+RB_HEAD(attr_type_tree, attr_type);
+RB_PROTOTYPE(attr_type_tree, attr_type, link, attr_oid_cmp);
+
+struct attr_ptr {
+ SLIST_ENTRY(attr_ptr) next;
+ struct attr_type *attr_type;
+};
+SLIST_HEAD(attr_list, attr_ptr);
+
+enum object_kind {
+ KIND_ABSTRACT,
+ KIND_STRUCTURAL,
+ KIND_AUXILIARY
+};
+
+struct object;
+struct obj_ptr {
+ SLIST_ENTRY(obj_ptr) next;
+ struct object *object;
+};
+SLIST_HEAD(obj_list, obj_ptr);
+
+struct object {
+ RB_ENTRY(object) link;
+ char *oid;
+ struct name_list *names;
+ char *desc;
+ int obsolete;
+ struct obj_list *sup;
+ enum object_kind kind;
+ struct attr_list *must;
+ struct attr_list *may;
+};
+RB_HEAD(object_tree, object);
+RB_PROTOTYPE(object_tree, object, link, obj_oid_cmp);
+
+struct oidname {
+ RB_ENTRY(oidname) link;
+ const char *on_name;
+#define on_attr_type on_ptr.ou_attr_type
+#define on_object on_ptr.ou_object
+ union {
+ struct attr_type *ou_attr_type;
+ struct object *ou_object;
+ } on_ptr;
+};
+RB_HEAD(oidname_tree, oidname);
+RB_PROTOTYPE(oidname_tree, oidname, link, oidname_cmp);
+
+struct symoid {
+ RB_ENTRY(symoid) link;
+ char *name; /* symbolic name */
+ char *oid;
+};
+RB_HEAD(symoid_tree, symoid);
+RB_PROTOTYPE(symoid_tree, symoid, link, symoid_cmp);
+
+#define SCHEMA_MAXPUSHBACK 128
+
+struct schema
+{
+ struct attr_type_tree attr_types;
+ struct oidname_tree attr_names;
+ struct object_tree objects;
+ struct oidname_tree object_names;
+ struct symoid_tree symbolic_oids;
+
+ FILE *fp;
+ const char *filename;
+ char pushback_buffer[SCHEMA_MAXPUSHBACK];
+ int pushback_index;
+ int lineno;
+ int error;
+};
+
+struct schema *schema_new(void);
+int schema_parse(struct schema *schema,
+ const char *filename);
+
+struct attr_type *lookup_attribute_by_oid(struct schema *schema, char *oid);
+struct attr_type *lookup_attribute_by_name(struct schema *schema, char *name);
+struct attr_type *lookup_attribute(struct schema *schema, char *oid_or_name);
+struct object *lookup_object_by_oid(struct schema *schema, char *oid);
+struct object *lookup_object_by_name(struct schema *schema, char *name);
+struct object *lookup_object(struct schema *schema, char *oid_or_name);
+int is_oidstr(const char *oidstr);
+
+#endif
+