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