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