1 /* slap.h - stand alone ldap server include file */
11 #include <ac/socket.h> /* needed by LDAP_CONNECTIONLESS */
12 #include <ldap_schema.h>
17 #define ldap_debug slap_debug
26 #include "ldap_pvt_thread.h"
29 #undef f_next /* name conflict between sys/file.h on SCO and struct filter */
32 /* LDAPMod.mod_op value ===> Must be kept in sync with ldap.h!
34 * This is a value used internally by the backends. It is needed to allow
35 * adding values that already exist without getting an error as required by
36 * modrdn when the new rdn was already an attribute value itself.
37 * JCG 05/1999 (gomez@engr.sgi.com)
39 #define LDAP_MOD_SOFTADD 0x04
48 #define MAXREMATCHES 10
50 #define DNSEPARATOR(c) ((c) == ',' || (c) == ';')
51 #define SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '+')
52 #define SPACE(c) ((c) == ' ' || (c) == '\n')
53 #define NEEDSESCAPE(c) ((c) == '\\' || (c) == '"')
55 #define SLAP_SCHERR_OUTOFMEM 1
56 #define SLAP_SCHERR_CLASS_NOT_FOUND 2
57 #define SLAP_SCHERR_ATTR_NOT_FOUND 3
58 #define SLAP_SCHERR_DUP_CLASS 4
59 #define SLAP_SCHERR_DUP_ATTR 5
63 extern int slap_debug;
69 * represents an attribute value assertion (i.e., attr=value)
73 struct berval ava_value;
77 * represents a search filter
79 typedef struct filter {
80 unsigned long f_choice; /* values taken from ldap.h */
86 /* equality, lessorequal, greaterorequal, approx */
90 struct filter *f_un_complex;
95 char *f_un_sub_initial;
100 #define f_type f_un.f_un_type
101 #define f_ava f_un.f_un_ava
102 #define f_avtype f_un.f_un_ava.ava_type
103 #define f_avvalue f_un.f_un_ava.ava_value
104 #define f_and f_un.f_un_complex
105 #define f_or f_un.f_un_complex
106 #define f_not f_un.f_un_complex
107 #define f_list f_un.f_un_complex
108 #define f_sub f_un.f_un_sub
109 #define f_sub_type f_un.f_un_sub.f_un_sub_type
110 #define f_sub_initial f_un.f_un_sub.f_un_sub_initial
111 #define f_sub_any f_un.f_un_sub.f_un_sub_any
112 #define f_sub_final f_un.f_un_sub.f_un_sub_final
114 struct filter *f_next;
118 * represents an attribute (type + values + syntax)
120 typedef struct attr {
122 struct berval **a_vals;
128 * the attr_syntax() routine returns one of these values
129 * telling what kind of syntax an attribute supports.
131 #define SYNTAX_CIS 0x01 /* case insensitive string */
132 #define SYNTAX_CES 0x02 /* case sensitive string */
133 #define SYNTAX_BIN 0x04 /* binary data */
134 #define SYNTAX_TEL 0x08 /* telephone number string */
135 #define SYNTAX_DN 0x10 /* dn string */
138 * the id used in the indexes to refer to an entry
140 typedef unsigned long ID;
141 #define NOID ((unsigned long)-1)
144 * represents an entry in core
146 typedef struct entry {
148 * The ID field should only be changed before entry is
149 * inserted into a cache. The ID value is backend
154 char *e_dn; /* DN of this entry */
155 char *e_ndn; /* normalized DN of this entry */
156 Attribute *e_attrs; /* list of attributes + values */
158 /* for use by the backend for any purpose */
163 * represents an access control list
168 #define ACL_NONE 0x01
169 #define ACL_COMPARE 0x02
170 #define ACL_SEARCH 0x04
171 #define ACL_READ 0x08
172 #define ACL_WRITE 0x10
173 #define ACL_SELF 0x40
181 #ifdef SLAPD_ACLGROUPS
183 char *a_objectclassvalue;
184 char *a_groupattrname;
186 struct access *a_next;
191 /* "to" part: the entries this acl applies to */
197 /* "by" part: list of who has what access to the entries */
198 struct access *acl_access;
200 struct acl *acl_next;
206 typedef struct ldapmodlist {
207 struct ldapmod ml_mod;
208 struct ldapmodlist *ml_next;
209 #define ml_op ml_mod.mod_op
210 #define ml_type ml_mod.mod_type
211 #define ml_values ml_mod.mod_values
212 #define ml_bvalues ml_mod.mod_bvalues
216 * represents schema information for a database
219 typedef struct slap_matching_rule {
223 typedef struct slap_attribute_type {
224 LDAP_ATTRIBUTE_TYPE sat_atype;
225 struct slap_attribute_type *sat_sup;
226 struct slap_attribute_type **sat_subtypes;
227 MatchingRule *sat_equality;
228 MatchingRule *sat_ordering;
229 MatchingRule *sat_substr;
233 /* The next one is created to help in the transition */
234 int sat_syntax_compat;
235 struct slap_attribute_type *sat_next;
238 typedef struct slap_object_class {
239 LDAP_OBJECT_CLASS soc_oclass;
240 struct slap_object_class **soc_sups;
241 AttributeType **soc_required;
242 AttributeType **soc_allowed;
243 struct slap_object_class *soc_next;
248 * represents a backend
251 typedef struct backend_info BackendInfo; /* per backend type */
252 typedef struct backend_db BackendDB; /* per backend database */
254 extern int nBackendInfo;
255 extern int nBackendDB;
256 extern BackendInfo *backendInfo;
257 extern BackendDB *backendDB;
260 #define SLAP_UNDEFINED_MODE 0
261 #define SLAP_SERVER_MODE 1
262 #define SLAP_TOOL_MODE 2
264 # define SLAP_TIMEDSERVER_MODE 3
265 # define SLAP_TOOLID_MODE 4
268 /* temporary aliases */
269 typedef BackendDB Backend;
270 #define nbackends nBackendDB
271 #define backends backendDB
274 BackendInfo *bd_info; /* pointer to shared backend info */
276 /* BackendInfo accessors */
277 #define be_config bd_info->bi_db_config
278 #define be_type bd_info->bi_type
280 #define be_bind bd_info->bi_op_bind
281 #define be_unbind bd_info->bi_op_unbind
282 #define be_add bd_info->bi_op_add
283 #define be_compare bd_info->bi_op_compare
284 #define be_delete bd_info->bi_op_delete
285 #define be_modify bd_info->bi_op_modify
286 #define be_modrdn bd_info->bi_op_modrdn
287 #define be_search bd_info->bi_op_search
289 #define be_release bd_info->bi_entry_release_rw
290 #define be_group bd_info->bi_acl_group
292 /* these should be renamed from be_ to bd_ */
293 char **be_suffix; /* the DN suffixes of data in this backend */
294 char **be_nsuffix; /* the normalized DN suffixes in this backend */
295 char **be_suffixAlias; /* the DN suffix aliases of data in this backend */
296 char *be_root_dn; /* the magic "root" dn for this db */
297 char *be_root_ndn; /* the magic "root" normalized dn for this db */
298 char *be_root_pw; /* the magic "root" password for this db */
299 int be_readonly; /* 1 => db is in "read only" mode */
300 int be_maxDerefDepth; /* limit for depth of an alias deref */
301 int be_sizelimit; /* size limit for this backend */
302 int be_timelimit; /* time limit for this backend */
303 struct acl *be_acl; /* access control list for this backend */
304 int be_dfltaccess; /* access given if no acl matches */
305 char **be_replica; /* replicas of this backend (in master) */
306 char *be_replogfile; /* replication log file (in master) */
307 char *be_update_ndn; /* allowed to make changes (in replicas) */
308 int be_lastmod; /* keep track of lastmodified{by,time} */
310 void *be_private; /* anything the backend database needs */
313 struct backend_info {
314 char *bi_type; /* type of backend */
317 * per backend type routines:
318 * bi_init: called to allocate a backend_info structure,
319 * called once BEFORE configuration file is read.
320 * bi_init() initializes this structure hence is
321 * called directly from be_initialize()
322 * bi_config: called per 'backend' specific option
323 * all such options must before any 'database' options
324 * bi_config() is called only from read_config()
325 * bi_open: called to open each database, called
326 * once AFTER configuration file is read but
327 * BEFORE any bi_db_open() calls.
328 * bi_open() is called from backend_startup()
329 * bi_close: called to close each database, called
330 * once during shutdown after all bi_db_close calls.
331 * bi_close() is called from backend_shutdown()
332 * bi_destroy: called to destroy each database, called
333 * once during shutdown after all bi_db_destroy calls.
334 * bi_destory() is called from backend_destroy()
336 int (*bi_init) LDAP_P((BackendInfo *bi));
337 int (*bi_config) LDAP_P((BackendInfo *bi,
338 char *fname, int lineno, int argc, char **argv ));
339 int (*bi_open) LDAP_P((BackendInfo *bi));
340 int (*bi_close) LDAP_P((BackendInfo *bi));
341 int (*bi_destroy) LDAP_P((BackendInfo *bi));
344 * per database routines:
345 * bi_db_init: called to initialize each database,
346 * called upon reading 'database <type>'
347 * called only from backend_db_init()
348 * bi_db_config: called to configure each database,
349 * called per database to handle per database options
350 * called only from read_config()
351 * bi_db_open: called to open each database
352 * called once per database immediately AFTER bi_open()
353 * calls but before daemon startup.
354 * called only by backend_startup()
355 * bi_db_close: called to close each database
356 * called once per database during shutdown but BEFORE
358 * called only by backend_shutdown()
359 * bi_db_destroy: called to destroy each database
360 * called once per database during shutdown AFTER all
361 * bi_close calls but before bi_destory calls.
362 * called only by backend_destory()
364 int (*bi_db_init) LDAP_P((Backend *bd));
365 int (*bi_db_config) LDAP_P((Backend *bd,
366 char *fname, int lineno, int argc, char **argv ));
367 int (*bi_db_open) LDAP_P((Backend *bd));
368 int (*bi_db_close) LDAP_P((Backend *bd));
369 int (*bi_db_destroy) LDAP_P((Backend *db));
371 /* LDAP Operations Handling Routines */
372 int (*bi_op_bind) LDAP_P(( BackendDB *bd,
373 struct slap_conn *c, struct slap_op *o,
374 char *dn, int method, struct berval *cred, char** edn ));
375 int (*bi_op_unbind) LDAP_P((BackendDB *bd,
376 struct slap_conn *c, struct slap_op *o ));
377 int (*bi_op_search) LDAP_P((BackendDB *bd,
378 struct slap_conn *c, struct slap_op *o,
379 char *base, int scope, int deref, int slimit, int tlimit,
380 Filter *f, char *filterstr, char **attrs, int attrsonly));
381 int (*bi_op_compare)LDAP_P((BackendDB *bd,
382 struct slap_conn *c, struct slap_op *o,
383 char *dn, Ava *ava));
384 int (*bi_op_modify) LDAP_P((BackendDB *bd,
385 struct slap_conn *c, struct slap_op *o,
386 char *dn, LDAPModList *m));
387 int (*bi_op_modrdn) LDAP_P((BackendDB *bd,
388 struct slap_conn *c, struct slap_op *o,
389 char *dn, char *newrdn, int deleteoldrdn,
391 int (*bi_op_add) LDAP_P((BackendDB *bd,
392 struct slap_conn *c, struct slap_op *o,
394 int (*bi_op_delete) LDAP_P((BackendDB *bd,
395 struct slap_conn *c, struct slap_op *o,
397 /* Bug: be_op_abandon in unused! */
398 int (*bi_op_abandon) LDAP_P((BackendDB *bd,
399 struct slap_conn *c, struct slap_op *o,
402 /* Auxilary Functions */
403 int (*bi_entry_release_rw) LDAP_P((BackendDB *bd, Entry *e, int rw));
404 #ifdef SLAPD_ACLGROUPS
405 int (*bi_acl_group) LDAP_P((Backend *bd,
406 Entry *e, char *bdn, char *edn,
407 char *objectclassValue, char *groupattrName ));
410 unsigned int bi_nDB; /* number of databases of this type */
411 void *bi_private; /* anything the backend type needs */
415 * represents an operation pending from an ldap client
418 typedef struct slap_op {
419 long o_opid; /* id of this operation */
420 long o_msgid; /* msgid of the request */
422 ldap_pvt_thread_t o_tid; /* thread handling this op */
424 BerElement *o_ber; /* ber of the request */
426 unsigned long o_tag; /* tag of the request */
427 time_t o_time; /* time op was initiated */
428 char *o_dn; /* dn bound when op was initiated */
429 char *o_ndn; /* normalized dn bound when op was initiated */
430 int o_authtype; /* auth method used to bind dn */
431 /* values taken from ldap.h */
434 /* long o_connid; *//* id of conn initiating this op */
436 #ifdef LDAP_CONNECTIONLESS
437 int o_cldap; /* != 0 if this came in via CLDAP */
438 struct sockaddr o_clientaddr; /* client address if via CLDAP */
439 char o_searchbase; /* search base if via CLDAP */
442 ldap_pvt_thread_mutex_t o_abandonmutex; /* protects o_abandon */
443 int o_abandon; /* abandon flag */
445 struct slap_op *o_next; /* next operation in list */
446 void *o_private; /* anything the backend needs */
450 * represents a connection from an ldap client
453 typedef struct slap_conn {
454 int c_struct_state; /* structure management state */
455 int c_conn_state; /* connection state */
457 ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
458 Sockbuf *c_sb; /* ber connection stuff */
460 /* only can be changed by connect_init */
461 time_t c_starttime; /* when the connection was opened */
462 long c_connid; /* id of this connection for stats*/
463 char *c_client_addr; /* address of client */
464 char *c_client_name; /* name of client */
466 /* only can be changed by binding thread */
467 char *c_cdn; /* DN provided by the client */
468 char *c_dn; /* DN bound to this conn */
469 int c_protocol; /* version of the LDAP protocol used by client */
470 int c_authtype; /* auth method used to bind c_dn */
472 int c_version; /* for compatibility w/ U-Mich 2.0 & 3.0 */
475 Operation *c_ops; /* list of operations being processed */
476 Operation *c_pending_ops; /* list of pending operations */
478 ldap_pvt_thread_mutex_t c_write_mutex; /* only one pdu written at a time */
479 ldap_pvt_thread_cond_t c_write_cv; /* used to wait for sd write-ready*/
481 BerElement *c_currentber; /* ber we're attempting to read */
482 int c_writewaiter; /* true if writer is waiting */
484 long c_n_ops_received; /* num of ops received (next op_id) */
485 long c_n_ops_executing; /* num of ops currently executing */
486 long c_n_ops_pending; /* num of ops pending execution */
487 long c_n_ops_completed; /* num of ops completed */
490 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
491 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 ) \
493 if ( ldap_debug & (level) ) \
494 fprintf( stderr, (fmt), (connid), (opid), (arg1), (arg2), (arg3) );\
495 if ( ldap_syslog & (level) ) \
496 syslog( ldap_syslog_level, (fmt), (connid), (opid), (arg1), \
500 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
503 #include "proto-slap.h"
507 #endif /* _slap_h_ */