1 /* slap.h - stand alone ldap server include file */
11 #include <ac/socket.h>
16 #define ldap_debug slap_debug
25 #include "ldap_schema.h"
27 #include "ldap_pvt_thread.h"
33 #undef f_next /* name conflict between sys/file.h on SCO and struct filter */
36 #define SERVICE_NAME OPENLDAP_PACKAGE "-slapd"
38 /* LDAPMod.mod_op value ===> Must be kept in sync with ldap.h!
40 * This is a value used internally by the backends. It is needed to allow
41 * adding values that already exist without getting an error as required by
42 * modrdn when the new rdn was already an attribute value itself.
43 * JCG 05/1999 (gomez@engr.sgi.com)
45 #define LDAP_MOD_SOFTADD 0x1000
54 #define MAXREMATCHES 10
56 #define DNSEPARATOR(c) ((c) == ',' || (c) == ';')
57 #define SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '+')
58 #define SPACE(c) ((c) == ' ' || (c) == '\n')
59 #define NEEDSESCAPE(c) ((c) == '\\' || (c) == '"')
61 #define SLAP_SCHERR_OUTOFMEM 1
62 #define SLAP_SCHERR_CLASS_NOT_FOUND 2
63 #define SLAP_SCHERR_ATTR_NOT_FOUND 3
64 #define SLAP_SCHERR_DUP_CLASS 4
65 #define SLAP_SCHERR_DUP_ATTR 5
66 #define SLAP_SCHERR_DUP_SYNTAX 6
67 #define SLAP_SCHERR_DUP_RULE 7
68 #define SLAP_SCHERR_NO_NAME 8
69 #define SLAP_SCHERR_ATTR_INCOMPLETE 9
70 #define SLAP_SCHERR_MR_NOT_FOUND 10
71 #define SLAP_SCHERR_SYN_NOT_FOUND 11
72 #define SLAP_SCHERR_MR_INCOMPLETE 12
74 extern int slap_debug;
80 * represents an attribute value assertion (i.e., attr=value)
84 struct berval ava_value;
88 * represents a search filter
90 typedef struct filter {
91 ber_tag_t f_choice; /* values taken from ldap.h */
97 /* equality, lessorequal, greaterorequal, approx */
101 struct filter *f_un_complex;
106 char *f_un_sub_initial;
108 char *f_un_sub_final;
111 #define f_type f_un.f_un_type
112 #define f_ava f_un.f_un_ava
113 #define f_avtype f_un.f_un_ava.ava_type
114 #define f_avvalue f_un.f_un_ava.ava_value
115 #define f_and f_un.f_un_complex
116 #define f_or f_un.f_un_complex
117 #define f_not f_un.f_un_complex
118 #define f_list f_un.f_un_complex
119 #define f_sub f_un.f_un_sub
120 #define f_sub_type f_un.f_un_sub.f_un_sub_type
121 #define f_sub_initial f_un.f_un_sub.f_un_sub_initial
122 #define f_sub_any f_un.f_un_sub.f_un_sub_any
123 #define f_sub_final f_un.f_un_sub.f_un_sub_final
125 struct filter *f_next;
129 * represents an attribute (type + values + syntax)
131 typedef struct attr {
133 struct berval **a_vals;
139 * the attr_syntax() routine returns one of these values
140 * telling what kind of syntax an attribute supports.
142 #define SYNTAX_CIS 0x01 /* case insensitive string */
143 #define SYNTAX_CES 0x02 /* case sensitive string */
144 #define SYNTAX_BIN 0x04 /* binary data */
145 #define SYNTAX_TEL 0x08 /* telephone number string */
146 #define SYNTAX_DN 0x10 /* dn string */
149 * the id used in the indexes to refer to an entry
151 typedef unsigned long ID;
152 #define NOID ((unsigned long)~0)
155 * represents an entry in core
157 typedef struct entry {
159 * The ID field should only be changed before entry is
160 * inserted into a cache. The ID value is backend
165 char *e_dn; /* DN of this entry */
166 char *e_ndn; /* normalized DN of this entry */
167 Attribute *e_attrs; /* list of attributes + values */
169 /* for use by the backend for any purpose */
174 * represents an access control list
179 #define ACL_NONE 0x0001
180 /* #define SLAPD_ACLAUTH 1 */
182 #define ACL_AUTH 0x0002
184 #define ACL_COMPARE 0x0004
185 #define ACL_SEARCH 0x0008
186 #define ACL_READ 0x0010
187 #define ACL_WRITE 0x0020
188 #define ACL_SELF 0x4000
189 #define ACL_INVALID -1
191 #define ACL_IS(lvl,a) (((a) & (lvl)) == (lvl))
193 #define ACL_IS_NONE(a) ACL_IS(ACL_SELF,(a))
194 #define ACL_IS_AUTH(a) ACL_IS(ACL_AUTH,(a))
195 #define ACL_IS_COMPARE(a) ACL_IS(ACL_COMPARE,(a))
196 #define ACL_IS_SEARCH(a) ACL_IS(ACL_SEARCH,(a))
197 #define ACL_IS_READ(a) ACL_IS(ACL_READ,(a))
198 #define ACL_IS_WRITE(a) ACL_IS(ACL_WRITE,(a))
199 #define ACL_IS_SELF(a) ACL_IS(ACL_SELF,(a))
200 #define ACL_IS_INVALID(a) ACL_IS(ACL_INVALID,(a))
203 #define ACL_CLR(a) ((a) = 0)
204 #define ACL_SET(lvl,a) ((a) |= (lvl))
205 #define ACL_SET_NONE(a) ACL_SET(ACL_SELF,(a))
206 #define ACL_SET_AUTH(a) ACL_SET(ACL_AUTH,(a))
207 #define ACL_SET_COMPARE(a) ACL_SET(ACL_COMPARE,(a))
208 #define ACL_SET_SEARCH(a) ACL_SET(ACL_SEARCH,(a))
209 #define ACL_SET_READ(a) ACL_SET(ACL_READ,(a))
210 #define ACL_SET_WRITE(a) ACL_SET(ACL_WRITE,(a))
211 #define ACL_SET_SELF(a) ACL_SET(ACL_SELF,(a))
212 #define ACL_SET_INVALID(a) ACL_SET(ACL_INVALID,(a))
214 #define ACL_PRIV_MASK 0x00ff
215 #define ACL_PRIV(a) ((a) & ACL_PRIV_MASK)
216 #define ACL_GRANT(lvl,a) (ACL_PRIV(a) >= (lvl))
227 #ifdef SLAPD_ACLGROUPS
232 struct access *a_next;
237 /* "to" part: the entries this acl applies to */
243 /* "by" part: list of who has what access to the entries */
244 struct access *acl_access;
246 struct acl *acl_next;
252 typedef struct ldapmodlist {
253 struct ldapmod ml_mod;
254 struct ldapmodlist *ml_next;
255 #define ml_op ml_mod.mod_op
256 #define ml_type ml_mod.mod_type
257 #define ml_values ml_mod.mod_values
258 #define ml_bvalues ml_mod.mod_bvalues
262 * represents schema information for a database
264 typedef int slap_syntax_check_func LDAP_P((struct berval * val));
266 typedef struct slap_syntax {
267 LDAP_SYNTAX ssyn_syn;
268 slap_syntax_check_func *ssyn_check;
269 struct slap_syntax *ssyn_next;
271 #define ssyn_oid ssyn_syn.syn_oid
272 #define ssyn_desc ssyn_syn.syn_desc
274 typedef int slap_mr_normalize_func LDAP_P((struct berval * val, struct berval **normalized));
275 typedef int slap_mr_compare_func LDAP_P((struct berval * val1, struct berval * val2));
277 typedef struct slap_matching_rule {
278 LDAP_MATCHING_RULE smr_mrule;
279 slap_mr_normalize_func *smr_normalize;
280 slap_mr_compare_func *smr_compare;
282 struct slap_matching_rule *smr_next;
284 #define smr_oid smr_mrule.mr_oid
285 #define smr_names smr_mrule.mr_names
286 #define smr_desc smr_mrule.mr_desc
287 #define smr_obsolete smr_mrule.mr_obsolete
288 #define smr_syntax_oid smr_mrule.mr_syntax_oid
290 typedef struct slap_attribute_type {
291 LDAP_ATTRIBUTE_TYPE sat_atype;
292 struct slap_attribute_type *sat_sup;
293 struct slap_attribute_type **sat_subtypes;
294 MatchingRule *sat_equality;
295 MatchingRule *sat_ordering;
296 MatchingRule *sat_substr;
298 /* The next one is created to help in the transition */
299 int sat_syntax_compat;
300 struct slap_attribute_type *sat_next;
302 #define sat_oid sat_atype.at_oid
303 #define sat_names sat_atype.at_names
304 #define sat_desc sat_atype.at_desc
305 #define sat_obsolete sat_atype.at_obsolete
306 #define sat_sup_oid sat_atype.at_sup_oid
307 #define sat_equality_oid sat_atype.at_equality_oid
308 #define sat_ordering_oid sat_atype.at_ordering_oid
309 #define sat_substr_oid sat_atype.at_substr_oid
310 #define sat_syntax_oid sat_atype.at_syntax_oid
311 #define sat_syntax_len sat_atype.at_syntax_len
312 #define sat_single_value sat_atype.at_single_value
313 #define sat_collective sat_atype.at_collective
314 #define sat_no_user_mods sat_atype.at_no_user_mods
315 #define sat_usage sat_atype.at_usage
317 typedef struct slap_object_class {
318 LDAP_OBJECT_CLASS soc_oclass;
319 struct slap_object_class **soc_sups;
320 AttributeType **soc_required;
321 AttributeType **soc_allowed;
322 struct slap_object_class *soc_next;
324 #define soc_oid soc_oclass.oc_oid
325 #define soc_names soc_oclass.oc_names
326 #define soc_desc soc_oclass.oc_desc
327 #define soc_obsolete soc_oclass.oc_obsolete
328 #define soc_sup_oids soc_oclass.oc_sup_oids
329 #define soc_kind soc_oclass.oc_kind
330 #define soc_at_oids_must soc_oclass.oc_at_oids_must
331 #define soc_at_oids_may soc_oclass.oc_at_oids_may
335 * represents a backend
338 typedef struct backend_info BackendInfo; /* per backend type */
339 typedef struct backend_db BackendDB; /* per backend database */
341 extern int nBackendInfo;
342 extern int nBackendDB;
343 extern BackendInfo *backendInfo;
344 extern BackendDB *backendDB;
347 #define SLAP_UNDEFINED_MODE 0
348 #define SLAP_SERVER_MODE 1
349 #define SLAP_TOOL_MODE 2
351 # define SLAP_TIMEDSERVER_MODE 3
352 # define SLAP_TOOLID_MODE 4
355 /* temporary aliases */
356 typedef BackendDB Backend;
357 #define nbackends nBackendDB
358 #define backends backendDB
361 BackendInfo *bd_info; /* pointer to shared backend info */
363 /* BackendInfo accessors */
364 #define be_config bd_info->bi_db_config
365 #define be_type bd_info->bi_type
367 #define be_bind bd_info->bi_op_bind
368 #define be_unbind bd_info->bi_op_unbind
369 #define be_add bd_info->bi_op_add
370 #define be_compare bd_info->bi_op_compare
371 #define be_delete bd_info->bi_op_delete
372 #define be_modify bd_info->bi_op_modify
373 #define be_modrdn bd_info->bi_op_modrdn
374 #define be_search bd_info->bi_op_search
376 #define be_release bd_info->bi_entry_release_rw
377 #define be_group bd_info->bi_acl_group
379 #define be_connection_init bd_info->bi_connection_init
380 #define be_connection_destroy bd_info->bi_connection_destroy
383 /* these should be renamed from be_ to bd_ */
384 char **be_suffix; /* the DN suffixes of data in this backend */
385 char **be_nsuffix; /* the normalized DN suffixes in this backend */
386 char **be_suffixAlias; /* the DN suffix aliases of data in this backend */
387 char *be_root_dn; /* the magic "root" dn for this db */
388 char *be_root_ndn; /* the magic "root" normalized dn for this db */
389 char *be_root_pw; /* the magic "root" password for this db */
390 int be_readonly; /* 1 => db is in "read only" mode */
391 int be_maxDerefDepth; /* limit for depth of an alias deref */
392 int be_sizelimit; /* size limit for this backend */
393 int be_timelimit; /* time limit for this backend */
394 struct acl *be_acl; /* access control list for this backend */
395 int be_dfltaccess; /* access given if no acl matches */
396 char **be_replica; /* replicas of this backend (in master) */
397 char *be_replogfile; /* replication log file (in master) */
398 char *be_update_ndn; /* allowed to make changes (in replicas) */
399 int be_lastmod; /* keep track of lastmodified{by,time} */
403 void *be_private; /* anything the backend database needs */
406 struct backend_info {
407 char *bi_type; /* type of backend */
410 * per backend type routines:
411 * bi_init: called to allocate a backend_info structure,
412 * called once BEFORE configuration file is read.
413 * bi_init() initializes this structure hence is
414 * called directly from be_initialize()
415 * bi_config: called per 'backend' specific option
416 * all such options must before any 'database' options
417 * bi_config() is called only from read_config()
418 * bi_open: called to open each database, called
419 * once AFTER configuration file is read but
420 * BEFORE any bi_db_open() calls.
421 * bi_open() is called from backend_startup()
422 * bi_close: called to close each database, called
423 * once during shutdown after all bi_db_close calls.
424 * bi_close() is called from backend_shutdown()
425 * bi_destroy: called to destroy each database, called
426 * once during shutdown after all bi_db_destroy calls.
427 * bi_destory() is called from backend_destroy()
429 int (*bi_init) LDAP_P((BackendInfo *bi));
430 int (*bi_config) LDAP_P((BackendInfo *bi,
431 char *fname, int lineno, int argc, char **argv ));
432 int (*bi_open) LDAP_P((BackendInfo *bi));
433 int (*bi_close) LDAP_P((BackendInfo *bi));
434 int (*bi_destroy) LDAP_P((BackendInfo *bi));
437 * per database routines:
438 * bi_db_init: called to initialize each database,
439 * called upon reading 'database <type>'
440 * called only from backend_db_init()
441 * bi_db_config: called to configure each database,
442 * called per database to handle per database options
443 * called only from read_config()
444 * bi_db_open: called to open each database
445 * called once per database immediately AFTER bi_open()
446 * calls but before daemon startup.
447 * called only by backend_startup()
448 * bi_db_close: called to close each database
449 * called once per database during shutdown but BEFORE
451 * called only by backend_shutdown()
452 * bi_db_destroy: called to destroy each database
453 * called once per database during shutdown AFTER all
454 * bi_close calls but before bi_destory calls.
455 * called only by backend_destory()
457 int (*bi_db_init) LDAP_P((Backend *bd));
458 int (*bi_db_config) LDAP_P((Backend *bd,
459 char *fname, int lineno, int argc, char **argv ));
460 int (*bi_db_open) LDAP_P((Backend *bd));
461 int (*bi_db_close) LDAP_P((Backend *bd));
462 int (*bi_db_destroy) LDAP_P((Backend *db));
464 /* LDAP Operations Handling Routines */
465 int (*bi_op_bind) LDAP_P(( BackendDB *bd,
466 struct slap_conn *c, struct slap_op *o,
467 char *dn, int method, char* mechanism,
468 struct berval *cred, char** edn ));
469 int (*bi_op_unbind) LDAP_P((BackendDB *bd,
470 struct slap_conn *c, struct slap_op *o ));
471 int (*bi_op_search) LDAP_P((BackendDB *bd,
472 struct slap_conn *c, struct slap_op *o,
473 char *base, int scope, int deref,
474 int slimit, int tlimit,
475 Filter *f, char *filterstr, char **attrs,
477 int (*bi_op_compare)LDAP_P((BackendDB *bd,
478 struct slap_conn *c, struct slap_op *o,
479 char *dn, Ava *ava));
480 int (*bi_op_modify) LDAP_P((BackendDB *bd,
481 struct slap_conn *c, struct slap_op *o,
482 char *dn, LDAPModList *m));
483 int (*bi_op_modrdn) LDAP_P((BackendDB *bd,
484 struct slap_conn *c, struct slap_op *o,
485 char *dn, char *newrdn, int deleteoldrdn,
487 int (*bi_op_add) LDAP_P((BackendDB *bd,
488 struct slap_conn *c, struct slap_op *o,
490 int (*bi_op_delete) LDAP_P((BackendDB *bd,
491 struct slap_conn *c, struct slap_op *o,
493 /* Bug: be_op_abandon in unused! */
494 int (*bi_op_abandon) LDAP_P((BackendDB *bd,
495 struct slap_conn *c, struct slap_op *o,
498 /* Auxilary Functions */
499 int (*bi_entry_release_rw) LDAP_P((BackendDB *bd, Entry *e, int rw));
500 #ifdef SLAPD_ACLGROUPS
501 int (*bi_acl_group) LDAP_P((Backend *bd,
502 Entry *e, char *bdn, char *edn,
503 char *objectclassValue, char *groupattrName ));
506 int (*bi_connection_init) LDAP_P((BackendDB *bd,
507 struct slap_conn *c));
508 int (*bi_connection_destroy) LDAP_P((BackendDB *bd,
509 struct slap_conn *c));
512 unsigned int bi_nDB; /* number of databases of this type */
513 void *bi_private; /* anything the backend type needs */
517 * represents an operation pending from an ldap client
520 typedef struct slap_op {
521 ber_int_t o_opid; /* id of this operation */
522 ber_int_t o_msgid; /* msgid of the request */
524 ldap_pvt_thread_t o_tid; /* thread handling this op */
526 BerElement *o_ber; /* ber of the request */
528 ber_tag_t o_tag; /* tag of the request */
529 time_t o_time; /* time op was initiated */
531 int o_bind_in_progress; /* multi-op bind in progress */
533 char *o_dn; /* dn bound when op was initiated */
534 char *o_ndn; /* normalized dn bound when op was initiated */
535 ber_int_t o_protocol; /* version of the LDAP protocol used by client */
536 ber_tag_t o_authtype; /* auth method used to bind dn */
537 /* values taken from ldap.h */
539 char *o_authmech; /* SASL mechanism used to bind dn */
541 LDAPControl **o_ctrls; /* controls */
543 /* long o_connid; *//* id of conn initiating this op */
545 #ifdef LDAP_CONNECTIONLESS
546 int o_cldap; /* != 0 if this came in via CLDAP */
547 struct sockaddr o_clientaddr; /* client address if via CLDAP */
548 char o_searchbase; /* search base if via CLDAP */
551 ldap_pvt_thread_mutex_t o_abandonmutex; /* protects o_abandon */
552 int o_abandon; /* abandon flag */
554 struct slap_op *o_next; /* next operation in list */
555 void *o_private; /* anything the backend needs */
559 * represents a connection from an ldap client
562 typedef struct slap_conn {
563 int c_struct_state; /* structure management state */
564 int c_conn_state; /* connection state */
566 ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
567 Sockbuf *c_sb; /* ber connection stuff */
569 /* only can be changed by connect_init */
570 time_t c_starttime; /* when the connection was opened */
571 time_t c_activitytime; /* when the connection was last used */
572 unsigned long c_connid; /* id of this connection for stats*/
573 char *c_client_addr; /* address of client */
574 char *c_client_name; /* name of client */
576 /* only can be changed by binding thread */
577 int c_bind_in_progress; /* multi-op bind in progress */
579 char *c_cdn; /* DN provided by the client */
580 char *c_dn; /* DN bound to this conn */
581 ber_int_t c_protocol; /* version of the LDAP protocol used by client */
582 ber_tag_t c_authtype;/* auth method used to bind c_dn */
583 char *c_authmech; /* SASL mechanism used to bind c_dn */
584 void *c_authstate; /* SASL state data */
586 Operation *c_ops; /* list of operations being processed */
587 Operation *c_pending_ops; /* list of pending operations */
589 ldap_pvt_thread_mutex_t c_write_mutex; /* only one pdu written at a time */
590 ldap_pvt_thread_cond_t c_write_cv; /* used to wait for sd write-ready*/
592 BerElement *c_currentber; /* ber we're attempting to read */
593 int c_writewaiter; /* true if writer is waiting */
595 long c_n_ops_received; /* num of ops received (next op_id) */
596 long c_n_ops_executing; /* num of ops currently executing */
597 long c_n_ops_pending; /* num of ops pending execution */
598 long c_n_ops_completed; /* num of ops completed */
600 long c_n_get; /* num of get calls */
601 long c_n_read; /* num of read calls */
602 long c_n_write; /* num of write calls */
605 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
606 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 ) \
608 if ( ldap_debug & (level) ) \
609 fprintf( stderr, (fmt), (connid), (opid), (arg1), (arg2), (arg3) );\
610 if ( ldap_syslog & (level) ) \
611 syslog( ldap_syslog_level, (fmt), (connid), (opid), (arg1), \
615 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
620 #include "proto-slap.h"
622 #endif /* _slap_h_ */