1 /* slap.h - stand alone ldap server include file */
12 #include <sys/types.h>
13 #include <ac/syslog.h>
22 #define ldap_debug slap_debug
26 extern int bdb2i_do_timing;
32 #include "../../libraries/liblber/lber-int.h"
35 #include "ldap_pvt_thread.h"
38 #undef f_next /* name conflict between sys/file.h on SCO and struct filter */
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) == '"')
57 extern int slap_debug;
63 * represents an attribute value assertion (i.e., attr=value)
67 struct berval ava_value;
71 * represents a search filter
73 typedef struct filter {
74 unsigned long f_choice; /* values taken from ldap.h */
80 /* equality, lessorequal, greaterorequal, approx */
84 struct filter *f_un_complex;
89 char *f_un_sub_initial;
94 #define f_type f_un.f_un_type
95 #define f_ava f_un.f_un_ava
96 #define f_avtype f_un.f_un_ava.ava_type
97 #define f_avvalue f_un.f_un_ava.ava_value
98 #define f_and f_un.f_un_complex
99 #define f_or f_un.f_un_complex
100 #define f_not f_un.f_un_complex
101 #define f_list f_un.f_un_complex
102 #define f_sub f_un.f_un_sub
103 #define f_sub_type f_un.f_un_sub.f_un_sub_type
104 #define f_sub_initial f_un.f_un_sub.f_un_sub_initial
105 #define f_sub_any f_un.f_un_sub.f_un_sub_any
106 #define f_sub_final f_un.f_un_sub.f_un_sub_final
108 struct filter *f_next;
112 * represents an attribute (type + values + syntax)
114 typedef struct attr {
116 struct berval **a_vals;
122 * the attr_syntax() routine returns one of these values
123 * telling what kind of syntax an attribute supports.
125 #define SYNTAX_CIS 0x01 /* case insensitive string */
126 #define SYNTAX_CES 0x02 /* case sensitive string */
127 #define SYNTAX_BIN 0x04 /* binary data */
128 #define SYNTAX_TEL 0x08 /* telephone number string */
129 #define SYNTAX_DN 0x10 /* dn string */
132 * the id used in the indexes to refer to an entry
134 typedef unsigned long ID;
135 #define NOID ((unsigned long)-1)
138 * represents an entry in core
140 typedef struct entry {
141 ldap_pvt_thread_rdwr_t e_rdwr; /* reader/writer lock */
143 char *e_dn; /* DN of this entry */
144 char *e_ndn; /* normalized DN of this entry */
145 Attribute *e_attrs; /* list of attributes + values */
149 * The ID field should only be changed before entry is
150 * inserted into a cache. The ID value is backend
153 ID e_id; /* id of this entry - this should */
154 /* really be private to back-ldbm */
157 * remaining fields require backend cache lock to access
158 * These items are specific to the LDBM backend and should
161 char e_state; /* for the cache */
162 #define ENTRY_STATE_DELETED 1
163 #define ENTRY_STATE_CREATING 2
165 int e_refcnt; /* # threads ref'ing this entry */
166 struct entry *e_lrunext; /* for cache lru list */
167 struct entry *e_lruprev;
171 * represents an access control list
176 #define ACL_NONE 0x01
177 #define ACL_COMPARE 0x02
178 #define ACL_SEARCH 0x04
179 #define ACL_READ 0x08
180 #define ACL_WRITE 0x10
181 #define ACL_SELF 0x40
189 #ifdef SLAPD_ACLGROUPS
191 char *a_objectclassvalue;
192 char *a_groupattrname;
194 struct access *a_next;
199 /* "to" part: the entries this acl applies to */
205 /* "by" part: list of who has what access to the entries */
206 struct access *acl_access;
208 struct acl *acl_next;
214 typedef struct ldapmodlist {
215 struct ldapmod ml_mod;
216 struct ldapmodlist *ml_next;
217 #define ml_op ml_mod.mod_op
218 #define ml_type ml_mod.mod_type
219 #define ml_values ml_mod.mod_values
220 #define ml_bvalues ml_mod.mod_bvalues
224 * represents schema information for a database
231 struct objclass *oc_next;
236 * represents a backend
239 typedef struct backend_info BackendInfo; /* per backend type */
240 typedef struct backend_db BackendDB; /* per backend database */
242 extern int nBackendInfo;
243 extern int nBackendDB;
244 extern BackendInfo *backendInfo;
245 extern BackendDB *backendDB;
248 #define SLAP_UNDEFINED_MODE 0
249 #define SLAP_SERVER_MODE 1
250 #define SLAP_TOOL_MODE 2
252 /* temporary aliases */
253 typedef BackendDB Backend;
254 #define nbackends nBackendDB
255 #define backends backendDB
258 BackendInfo *bd_info; /* pointer to shared backend info */
260 /* BackendInfo accessors */
261 #define be_config bd_info->bi_db_config
262 #define be_type bd_info->bi_type
264 #define be_bind bd_info->bi_op_bind
265 #define be_unbind bd_info->bi_op_unbind
266 #define be_add bd_info->bi_op_add
267 #define be_compare bd_info->bi_op_compare
268 #define be_delete bd_info->bi_op_delete
269 #define be_modify bd_info->bi_op_modify
270 #define be_modrdn bd_info->bi_op_modrdn
271 #define be_search bd_info->bi_op_search
273 #define be_group bd_info->bi_acl_group
275 /* these should be renamed from be_ to bd_ */
276 char **be_suffix; /* the DN suffixes of data in this backend */
277 char **be_suffixAlias; /* the DN suffix aliases of data in this backend */
278 char *be_root_dn; /* the magic "root" dn for this db */
279 char *be_root_ndn; /* the magic "root" normalized dn for this db */
280 char *be_root_pw; /* the magic "root" password for this db */
281 int be_readonly; /* 1 => db is in "read only" mode */
282 int be_maxDerefDepth; /* limit for depth of an alias deref */
283 int be_sizelimit; /* size limit for this backend */
284 int be_timelimit; /* time limit for this backend */
285 struct acl *be_acl; /* access control list for this backend */
286 int be_dfltaccess; /* access given if no acl matches */
287 char **be_replica; /* replicas of this backend (in master) */
288 char *be_replogfile; /* replication log file (in master) */
289 char *be_update_ndn; /* allowed to make changes (in replicas) */
290 int be_lastmod; /* keep track of lastmodified{by,time} */
292 void *be_private; /* anything the backend database needs */
295 struct backend_info {
296 char *bi_type; /* type of backend */
299 * per backend type routines:
300 * bi_init: called to allocate a backend_info structure,
301 * called once BEFORE configuration file is read.
302 * bi_init() initializes this structure hence is
303 * called directly from be_initialize()
304 * bi_config: called per 'backend' specific option
305 * all such options must before any 'database' options
306 * bi_config() is called only from read_config()
307 * bi_open: called to open each database, called
308 * once AFTER configuration file is read but
309 * BEFORE any bi_db_open() calls.
310 * bi_open() is called from backend_startup()
311 * bi_close: called to close each database, called
312 * once during shutdown after all bi_db_close calls.
313 * bi_close() is called from backend_shutdown()
314 * bi_destroy: called to destroy each database, called
315 * once during shutdown after all bi_db_destroy calls.
316 * bi_destory() is called from backend_destroy()
318 int (*bi_init) LDAP_P((BackendInfo *bi));
319 int (*bi_config) LDAP_P((BackendInfo *bi,
320 char *fname, int lineno, int argc, char **argv ));
321 int (*bi_open) LDAP_P((BackendInfo *bi));
322 int (*bi_close) LDAP_P((BackendInfo *bi));
323 int (*bi_destroy) LDAP_P((BackendInfo *bi));
326 * per database routines:
327 * bi_db_init: called to initialize each database,
328 * called upon reading 'database <type>'
329 * called only from backend_db_init()
330 * bi_db_config: called to configure each database,
331 * called per database to handle per database options
332 * called only from read_config()
333 * bi_db_open: called to open each database
334 * called once per database immediately AFTER bi_open()
335 * calls but before daemon startup.
336 * called only by backend_startup()
337 * bi_db_close: called to close each database
338 * called once per database during shutdown but BEFORE
340 * called only by backend_shutdown()
341 * bi_db_destroy: called to destroy each database
342 * called once per database during shutdown AFTER all
343 * bi_close calls but before bi_destory calls.
344 * called only by backend_destory()
346 int (*bi_db_init) LDAP_P((Backend *bd));
347 int (*bi_db_config) LDAP_P((Backend *bd,
348 char *fname, int lineno, int argc, char **argv ));
349 int (*bi_db_open) LDAP_P((Backend *bd));
350 int (*bi_db_close) LDAP_P((Backend *bd));
351 int (*bi_db_destroy) LDAP_P((Backend *db));
353 /* LDAP Operations Handling Routines */
354 int (*bi_op_bind) LDAP_P(( BackendDB *bd,
355 struct slap_conn *c, struct slap_op *o,
356 char *dn, int method, struct berval *cred, char** edn ));
357 int (*bi_op_unbind) LDAP_P((BackendDB *bd,
358 struct slap_conn *c, struct slap_op *o ));
359 int (*bi_op_search) LDAP_P((BackendDB *bd,
360 struct slap_conn *c, struct slap_op *o,
361 char *base, int scope, int deref, int slimit, int tlimit,
362 Filter *f, char *filterstr, char **attrs, int attrsonly));
363 int (*bi_op_compare)LDAP_P((BackendDB *bd,
364 struct slap_conn *c, struct slap_op *o,
365 char *dn, Ava *ava));
366 int (*bi_op_modify) LDAP_P((BackendDB *bd,
367 struct slap_conn *c, struct slap_op *o,
368 char *dn, LDAPModList *m));
369 int (*bi_op_modrdn) LDAP_P((BackendDB *bd,
370 struct slap_conn *c, struct slap_op *o,
371 char *dn, char *newrdn, int deleteoldrdn ));
372 int (*bi_op_add) LDAP_P((BackendDB *bd,
373 struct slap_conn *c, struct slap_op *o,
375 int (*bi_op_delete) LDAP_P((BackendDB *bd,
376 struct slap_conn *c, struct slap_op *o,
378 /* Bug: be_op_abandon in unused! */
379 int (*bi_op_abandon) LDAP_P((BackendDB *bd,
380 struct slap_conn *c, struct slap_op *o,
383 /* Auxilary Functions */
384 #ifdef SLAPD_ACLGROUPS
385 int (*bi_acl_group) LDAP_P((Backend *bd,
386 Entry *e, char *bdn, char *edn,
387 char *objectclassValue, char *groupattrName ));
390 unsigned int bi_nDB; /* number of databases of this type */
391 void *bi_private; /* anything the backend type needs */
395 * represents an operation pending from an ldap client
398 typedef struct slap_op {
399 BerElement *o_ber; /* ber of the request */
400 long o_msgid; /* msgid of the request */
401 unsigned long o_tag; /* tag of the request */
402 time_t o_time; /* time op was initiated */
403 char *o_dn; /* dn bound when op was initiated */
404 char *o_ndn; /* normalized dn bound when op was initiated */
405 int o_authtype; /* auth method used to bind dn */
406 /* values taken from ldap.h */
408 int o_opid; /* id of this operation */
409 int o_connid; /* id of conn initiating this op */
410 #ifdef LDAP_CONNECTIONLESS
411 int o_cldap; /* != 0 if this came in via CLDAP */
412 struct sockaddr o_clientaddr; /* client address if via CLDAP */
413 char o_searchbase; /* search base if via CLDAP */
415 struct slap_op *o_next; /* next operation pending */
416 ldap_pvt_thread_t o_tid; /* thread handling this op */
417 int o_abandon; /* signals op has been abandoned */
418 ldap_pvt_thread_mutex_t o_abandonmutex; /* signals op has been abandoned */
420 void *o_private; /* anything the backend needs */
424 * represents a connection from an ldap client
427 typedef struct slap_conn {
428 Sockbuf c_sb; /* ber connection stuff */
429 char *c_cdn; /* DN provided by the client */
430 char *c_dn; /* DN bound to this conn */
431 ldap_pvt_thread_mutex_t c_dnmutex; /* mutex for c_dn field */
432 int c_protocol; /* version of the LDAP protocol used by client */
433 int c_authtype; /* auth method used to bind c_dn */
435 int c_version; /* for compatibility w/2.0, 3.0 */
437 char *c_addr; /* address of client on this conn */
438 char *c_domain; /* domain of client on this conn */
439 Operation *c_ops; /* list of pending operations */
440 ldap_pvt_thread_mutex_t c_opsmutex; /* mutex for c_ops list & stats */
441 ldap_pvt_thread_mutex_t c_pdumutex; /* only one pdu written at a time */
442 ldap_pvt_thread_cond_t c_wcv; /* used to wait for sd write-ready*/
443 int c_gettingber; /* in the middle of ber_get_next */
444 BerElement *c_currentber; /* ber we're getting */
445 int c_writewaiter; /* signals write-ready sd waiter */
446 int c_pduwaiters; /* signals threads waiting 4 pdu */
447 time_t c_starttime; /* when the connection was opened */
448 int c_connid; /* id of this connection for stats*/
449 int c_opsinitiated; /* # ops initiated/next op id */
450 int c_opscompleted; /* # ops completed */
453 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
454 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 ) \
456 if ( ldap_debug & level ) \
457 fprintf( stderr, fmt, connid, opid, arg1, arg2, arg3 );\
458 if ( ldap_syslog & level ) \
459 syslog( ldap_syslog_level, fmt, connid, opid, arg1, \
463 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
466 #include "proto-slap.h"
470 #endif /* _slap_h_ */