1/*	$NetBSD: config.h,v 1.1.1.3 2010/12/12 15:22:26 adam Exp $	*/
2
3/* config.h - configuration abstraction structure */
4/* OpenLDAP: pkg/ldap/servers/slapd/config.h,v 1.34.2.20 2010/04/13 20:23:13 kurt Exp */
5/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 *
7 * Copyright 1998-2010 The OpenLDAP Foundation.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
12 * Public License.
13 *
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
17 */
18
19#ifndef CONFIG_H
20#define CONFIG_H
21
22#include<ac/string.h>
23
24LDAP_BEGIN_DECL
25
26typedef struct ConfigTable {
27	const char *name;
28	const char *what;
29	int min_args;
30	int max_args;
31	int length;
32	unsigned int arg_type;
33	void *arg_item;
34	const char *attribute;
35	AttributeDescription *ad;
36	void *notify;
37} ConfigTable;
38
39/* search entries are returned according to this order */
40typedef enum {
41	Cft_Abstract = 0,
42	Cft_Global,
43	Cft_Module,
44	Cft_Schema,
45	Cft_Backend,
46	Cft_Database,
47	Cft_Overlay,
48	Cft_Misc	/* backend/overlay defined */
49} ConfigType;
50
51#define ARGS_USERLAND	0x00000fff
52
53/* types are enumerated, not a bitmask */
54#define ARGS_TYPES	0x0000f000
55#define ARG_INT		0x00001000
56#define ARG_LONG	0x00002000
57#define ARG_BER_LEN_T	0x00003000
58#define ARG_ON_OFF	0x00004000
59#define ARG_STRING	0x00005000
60#define ARG_BERVAL	0x00006000
61#define ARG_DN		0x00007000
62#define ARG_UINT	0x00008000
63#define ARG_ATDESC	0x00009000
64#define ARG_ULONG	0x0000a000
65
66#define ARGS_SYNTAX	0xffff0000
67#define ARG_IGNORED	0x00080000
68#define ARG_PRE_BI	0x00100000
69#define ARG_PRE_DB	0x00200000
70#define ARG_DB		0x00400000	/* Only applies to DB */
71#define ARG_MAY_DB	0x00800000	/* May apply to DB */
72#define ARG_PAREN	0x01000000
73#define ARG_NONZERO	0x02000000
74#define	ARG_NO_INSERT	0x04000000	/* no arbitrary inserting */
75#define	ARG_NO_DELETE	0x08000000	/* no runtime deletes */
76#define ARG_UNIQUE	0x10000000
77#define	ARG_QUOTE	0x20000000	/* wrap with quotes before parsing */
78#define ARG_OFFSET	0x40000000
79#define ARG_MAGIC	0x80000000
80
81#define ARG_BAD_CONF	0xdead0000	/* overload return values */
82
83/* This is a config entry's e_private data */
84typedef struct CfEntryInfo {
85	struct CfEntryInfo *ce_parent;
86	struct CfEntryInfo *ce_sibs;
87	struct CfEntryInfo *ce_kids;
88	Entry *ce_entry;
89	ConfigType ce_type;
90	BackendInfo *ce_bi;
91	BackendDB *ce_be;
92	void *ce_private;
93} CfEntryInfo;
94
95struct config_args_s;
96
97/* Check if the child is allowed to be LDAPAdd'd to the parent */
98typedef int (ConfigLDAPadd)(
99	CfEntryInfo *parent, Entry *child, struct config_args_s *ca);
100
101/* Let the object create children out of slapd.conf */
102typedef int (ConfigCfAdd)(
103	Operation *op, SlapReply *rs, Entry *parent, struct config_args_s *ca );
104
105typedef struct ConfigOCs {
106	const char *co_def;
107	ConfigType co_type;
108	ConfigTable *co_table;
109	ConfigLDAPadd *co_ldadd;
110	ConfigCfAdd *co_cfadd;
111	ObjectClass *co_oc;
112	struct berval *co_name;
113} ConfigOCs;
114
115typedef int (ConfigDriver)(struct config_args_s *c);
116
117struct config_reply_s {
118	int err;
119	char msg[SLAP_TEXT_BUFLEN];
120};
121
122typedef struct config_args_s {
123	int argc;
124	char **argv;
125	int argv_size;
126	char *line;
127	char *tline;
128	const char *fname;
129	int lineno;
130	char log[MAXPATHLEN + STRLENOF(": line ") + LDAP_PVT_INTTYPE_CHARS(unsigned long)];
131#define cr_msg reply.msg
132	ConfigReply reply;
133	int depth;
134	int valx;	/* multi-valued value index */
135	/* parsed first val for simple cases */
136	union {
137		int v_int;
138		unsigned v_uint;
139		long v_long;
140		unsigned long v_ulong;
141		ber_len_t v_ber_t;
142		char *v_string;
143		struct berval v_bv;
144		struct {
145			struct berval vdn_dn;
146			struct berval vdn_ndn;
147		} v_dn;
148		AttributeDescription *v_ad;
149	} values;
150	/* return values for emit mode */
151	BerVarray rvalue_vals;
152	BerVarray rvalue_nvals;
153#define	SLAP_CONFIG_EMIT	0x2000	/* emit instead of set */
154#define SLAP_CONFIG_ADD		0x4000	/* config file add vs LDAP add */
155	int op;
156	int type;	/* ConfigTable.arg_type & ARGS_USERLAND */
157	Operation *ca_op;
158	BackendDB *be;
159	BackendInfo *bi;
160	Entry *ca_entry;	/* entry being modified */
161	void *ca_private;	/* anything */
162	ConfigDriver *cleanup;
163	ConfigType table;	/* which config table did we come from */
164} ConfigArgs;
165
166/* If lineno is zero, we have an actual LDAP Add request from a client.
167 * Otherwise, we're reading a config file or a config dir.
168 */
169#define CONFIG_ONLINE_ADD(ca)	(!((ca)->lineno))
170
171#define value_int values.v_int
172#define value_uint values.v_uint
173#define value_long values.v_long
174#define value_ulong values.v_ulong
175#define value_ber_t values.v_ber_t
176#define value_string values.v_string
177#define value_bv values.v_bv
178#define value_dn values.v_dn.vdn_dn
179#define value_ndn values.v_dn.vdn_ndn
180#define value_ad values.v_ad
181
182int config_fp_parse_line(ConfigArgs *c);
183
184int config_register_schema(ConfigTable *ct, ConfigOCs *co);
185int config_del_vals(ConfigTable *cf, ConfigArgs *c);
186int config_get_vals(ConfigTable *ct, ConfigArgs *c);
187int config_add_vals(ConfigTable *ct, ConfigArgs *c);
188
189void init_config_argv( ConfigArgs *c );
190int init_config_attrs(ConfigTable *ct);
191int init_config_ocs( ConfigOCs *ocs );
192int config_parse_vals(ConfigTable *ct, ConfigArgs *c, int valx);
193int config_parse_add(ConfigTable *ct, ConfigArgs *c, int valx);
194int read_config_file(const char *fname, int depth, ConfigArgs *cf,
195	ConfigTable *cft );
196
197ConfigTable * config_find_keyword(ConfigTable *ct, ConfigArgs *c);
198Entry * config_build_entry( Operation *op, SlapReply *rs, CfEntryInfo *parent,
199	ConfigArgs *c, struct berval *rdn, ConfigOCs *main, ConfigOCs *extra );
200
201Listener *config_check_my_url(const char *url, LDAPURLDesc *lud);
202int config_shadow( ConfigArgs *c, slap_mask_t flag );
203#define	config_slurp_shadow(c)	config_shadow((c), SLAP_DBFLAG_SLURP_SHADOW)
204#define	config_sync_shadow(c)	config_shadow((c), SLAP_DBFLAG_SYNC_SHADOW)
205
206	/* Make sure we don't exceed the bits reserved for userland */
207#define	config_check_userland(last) \
208	assert( ( ( (last) - 1 ) & ARGS_USERLAND ) == ( (last) - 1 ) );
209
210#define	SLAP_X_ORDERED_FMT	"{%d}"
211
212LDAP_SLAPD_V (slap_verbmasks *) slap_ldap_response_code;
213extern int slap_ldap_response_code_register( struct berval *bv, int err );
214
215LDAP_SLAPD_V (ConfigTable) olcDatabaseDummy[];
216
217LDAP_END_DECL
218
219#endif /* CONFIG_H */
220