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