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
27 #include "../../libraries/liblber/lber-int.h"
30 #include "ldap_pvt_thread.h"
33 #undef f_next /* name conflict between sys/file.h on SCO and struct filter */
43 #define MAXREMATCHES 10
45 #define DNSEPARATOR(c) ((c) == ',' || (c) == ';')
46 #define SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '+')
47 #define SPACE(c) ((c) == ' ' || (c) == '\n')
48 #define NEEDSESCAPE(c) ((c) == '\\' || (c) == '"')
52 extern int slap_debug;
58 * represents an attribute value assertion (i.e., attr=value)
62 struct berval ava_value;
66 * represents a search filter
68 typedef struct filter {
69 unsigned long f_choice; /* values taken from ldap.h */
75 /* equality, lessorequal, greaterorequal, approx */
79 struct filter *f_un_complex;
84 char *f_un_sub_initial;
89 #define f_type f_un.f_un_type
90 #define f_ava f_un.f_un_ava
91 #define f_avtype f_un.f_un_ava.ava_type
92 #define f_avvalue f_un.f_un_ava.ava_value
93 #define f_and f_un.f_un_complex
94 #define f_or f_un.f_un_complex
95 #define f_not f_un.f_un_complex
96 #define f_list f_un.f_un_complex
97 #define f_sub f_un.f_un_sub
98 #define f_sub_type f_un.f_un_sub.f_un_sub_type
99 #define f_sub_initial f_un.f_un_sub.f_un_sub_initial
100 #define f_sub_any f_un.f_un_sub.f_un_sub_any
101 #define f_sub_final f_un.f_un_sub.f_un_sub_final
103 struct filter *f_next;
107 * represents an attribute (type + values + syntax)
109 typedef struct attr {
111 struct berval **a_vals;
117 * the attr_syntax() routine returns one of these values
118 * telling what kind of syntax an attribute supports.
120 #define SYNTAX_CIS 0x01 /* case insensitive string */
121 #define SYNTAX_CES 0x02 /* case sensitive string */
122 #define SYNTAX_BIN 0x04 /* binary data */
123 #define SYNTAX_TEL 0x08 /* telephone number string */
124 #define SYNTAX_DN 0x10 /* dn string */
127 * the id used in the indexes to refer to an entry
129 typedef unsigned long ID;
130 #define NOID ((unsigned long)-1)
133 * represents an entry in core
135 typedef struct entry {
136 ldap_pvt_thread_rdwr_t e_rdwr; /* reader/writer lock */
138 char *e_dn; /* DN of this entry */
139 char *e_ndn; /* normalized DN of this entry */
140 Attribute *e_attrs; /* list of attributes + values */
144 * The ID field should only be changed before entry is
145 * inserted into a cache. The ID value is backend
148 ID e_id; /* id of this entry - this should */
149 /* really be private to back-ldbm */
152 * remaining fields require backend cache lock to access
153 * These items are specific to the LDBM backend and should
154 * and should be hidden.
156 char e_state; /* for the cache */
157 #define ENTRY_STATE_DELETED 1
158 #define ENTRY_STATE_CREATING 2
160 int e_refcnt; /* # threads ref'ing this entry */
161 struct entry *e_lrunext; /* for cache lru list */
162 struct entry *e_lruprev;
166 * represents an access control list
171 #define ACL_NONE 0x01
172 #define ACL_COMPARE 0x02
173 #define ACL_SEARCH 0x04
174 #define ACL_READ 0x08
175 #define ACL_WRITE 0x10
176 #define ACL_SELF 0x40
184 #ifdef SLAPD_ACLGROUPS
186 char *a_objectclassvalue;
187 char *a_groupattrname;
189 struct access *a_next;
194 /* "to" part: the entries this acl applies to */
200 /* "by" part: list of who has what access to the entries */
201 struct access *acl_access;
203 struct acl *acl_next;
209 typedef struct ldapmodlist {
210 struct ldapmod ml_mod;
211 struct ldapmodlist *ml_next;
212 #define ml_op ml_mod.mod_op
213 #define ml_type ml_mod.mod_type
214 #define ml_values ml_mod.mod_values
215 #define ml_bvalues ml_mod.mod_bvalues
219 * represents schema information for a database
226 struct objclass *oc_next;
231 * represents a backend
234 typedef struct backend_info BackendInfo; /* per backend type */
235 typedef struct backend_db BackendDB; /* per backend database */
237 extern int nBackendInfo;
238 extern int nBackendDB;
239 extern BackendInfo *backendInfo;
240 extern BackendDB *backendDB;
243 #define SLAP_UNDEFINED_MODE 0
244 #define SLAP_SERVER_MODE 1
245 #define SLAP_TOOL_MODE 2
247 /* temporary aliases */
248 typedef BackendDB Backend;
249 #define nbackends nBackendDB
250 #define backends backendDB
253 BackendInfo *bd_info; /* pointer to shared backend info */
255 /* BackendInfo accessors */
256 #define be_config bd_info->bi_db_config
257 #define be_type bd_info->bi_type
259 #define be_bind bd_info->bi_op_bind
260 #define be_unbind bd_info->bi_op_unbind
261 #define be_add bd_info->bi_op_add
262 #define be_compare bd_info->bi_op_compare
263 #define be_delete bd_info->bi_op_delete
264 #define be_modify bd_info->bi_op_modify
265 #define be_modrdn bd_info->bi_op_modrdn
266 #define be_search bd_info->bi_op_search
268 #define be_group bd_info->bi_acl_group
270 /* these should be renamed from be_ to bd_ */
271 char **be_suffix; /* the DN suffixes of data in this backend */
272 char **be_suffixAlias; /* the DN suffix aliases of data in this backend */
273 char *be_root_dn; /* the magic "root" dn for this db */
274 char *be_root_ndn; /* the magic "root" normalized dn for this db */
275 char *be_root_pw; /* the magic "root" password for this db */
276 int be_readonly; /* 1 => db is in "read only" mode */
277 int be_maxDerefDepth; /* limit for depth of an alias deref */
278 int be_sizelimit; /* size limit for this backend */
279 int be_timelimit; /* time limit for this backend */
280 struct acl *be_acl; /* access control list for this backend */
281 int be_dfltaccess; /* access given if no acl matches */
282 char **be_replica; /* replicas of this backend (in master) */
283 char *be_replogfile; /* replication log file (in master) */
284 char *be_update_ndn; /* allowed to make changes (in replicas) */
285 int be_lastmod; /* keep track of lastmodified{by,time} */
287 void *be_private; /* anything the backend needs */
290 struct backend_info {
291 char *bi_type; /* type of backend */
294 * per backend type routines:
295 * bi_init: called to allocate a backend_info structure,
296 * called once BEFORE configuration file is read.
297 * bi_init() initializes this structure hence is
298 * called directly from be_initialize()
299 * bi_config: called per 'backend' specific option
300 * all such options must before any 'database' options
301 * bi_config() is called only from read_config()
302 * bi_open: called to open each database, called
303 * once AFTER configuration file is read but
304 * BEFORE any bi_db_open() calls.
305 * bi_open() is called from backend_startup()
306 * bi_close: called to close each database, called
307 * once during shutdown after all bi_db_close calls.
308 * bi_close() is called from backend_shutdown()
309 * bi_destroy: called to destroy each database, called
310 * once during shutdown after all bi_db_destroy calls.
311 * bi_destory() is called from backend_destroy()
313 int (*bi_init) LDAP_P((BackendInfo *bi));
314 int (*bi_config) LDAP_P((BackendInfo *bi,
315 char *fname, int lineno, int argc, char **argv ));
316 int (*bi_open) LDAP_P((BackendInfo *bi));
317 int (*bi_close) LDAP_P((BackendInfo *bi));
318 int (*bi_destroy) LDAP_P((BackendInfo *bi));
321 * per database routines:
322 * bi_db_init: called to initialize each database,
323 * called upon reading 'database <type>'
324 * called only from backend_db_init()
325 * bi_db_config: called to configure each database,
326 * called per database to handle per database options
327 * called only from read_config()
328 * bi_db_open: called to open each database
329 * called once per database immediately AFTER bi_open()
330 * calls but before daemon startup.
331 * called only by backend_startup()
332 * bi_db_close: called to close each database
333 * called once per database during shutdown but BEFORE
335 * called only by backend_shutdown()
336 * bi_db_destroy: called to destroy each database
337 * called once per database during shutdown AFTER all
338 * bi_close calls but before bi_destory calls.
339 * called only by backend_destory()
341 int (*bi_db_init) LDAP_P((Backend *bd));
342 int (*bi_db_config) LDAP_P((Backend *bd,
343 char *fname, int lineno, int argc, char **argv ));
344 int (*bi_db_open) LDAP_P((Backend *bd));
345 int (*bi_db_close) LDAP_P((Backend *bd));
346 int (*bi_db_destroy) LDAP_P((Backend *db));
348 /* LDAP Operations Handling Routines */
349 int (*bi_op_bind) LDAP_P(( BackendDB *bd,
350 struct slap_conn *c, struct slap_op *o,
351 char *dn, int method, struct berval *cred, char** edn ));
352 int (*bi_op_unbind) LDAP_P((BackendDB *bd,
353 struct slap_conn *c, struct slap_op *o ));
354 int (*bi_op_search) LDAP_P((BackendDB *bd,
355 struct slap_conn *c, struct slap_op *o,
356 char *base, int scope, int deref, int slimit, int tlimit,
357 Filter *f, char *filterstr, char **attrs, int attrsonly));
358 int (*bi_op_compare)LDAP_P((BackendDB *bd,
359 struct slap_conn *c, struct slap_op *o,
360 char *dn, Ava *ava));
361 int (*bi_op_modify) LDAP_P((BackendDB *bd,
362 struct slap_conn *c, struct slap_op *o,
363 char *dn, LDAPModList *m));
364 int (*bi_op_modrdn) LDAP_P((BackendDB *bd,
365 struct slap_conn *c, struct slap_op *o,
366 char *dn, char *newrdn, int deleteoldrdn ));
367 int (*bi_op_add) LDAP_P((BackendDB *bd,
368 struct slap_conn *c, struct slap_op *o,
370 int (*bi_op_delete) LDAP_P((BackendDB *bd,
371 struct slap_conn *c, struct slap_op *o,
373 /* Bug: be_op_abandon in unused! */
374 int (*bi_op_abandon) LDAP_P((BackendDB *bd,
375 struct slap_conn *c, struct slap_op *o,
378 /* Auxilary Functions */
379 #ifdef SLAPD_ACLGROUPS
380 int (*bi_acl_group) LDAP_P((Backend *bd,
381 Entry *e, char *bdn, char *edn,
382 char *objectclassValue, char *groupattrName ));
385 void *bi_private; /* anything the backend needs */
389 * represents an operation pending from an ldap client
392 typedef struct slap_op {
393 BerElement *o_ber; /* ber of the request */
394 long o_msgid; /* msgid of the request */
395 unsigned long o_tag; /* tag of the request */
396 time_t o_time; /* time op was initiated */
397 char *o_dn; /* dn bound when op was initiated */
398 char *o_ndn; /* normalized dn bound when op was initiated */
399 int o_authtype; /* auth method used to bind dn */
400 /* values taken from ldap.h */
402 int o_opid; /* id of this operation */
403 int o_connid; /* id of conn initiating this op */
404 #ifdef LDAP_CONNECTIONLESS
405 int o_cldap; /* != 0 if this came in via CLDAP */
406 struct sockaddr o_clientaddr; /* client address if via CLDAP */
407 char o_searchbase; /* search base if via CLDAP */
409 struct slap_op *o_next; /* next operation pending */
410 ldap_pvt_thread_t o_tid; /* thread handling this op */
411 int o_abandon; /* signals op has been abandoned */
412 ldap_pvt_thread_mutex_t o_abandonmutex; /* signals op has been abandoned */
414 void *o_private; /* anything the backend needs */
418 * represents a connection from an ldap client
421 typedef struct slap_conn {
422 Sockbuf c_sb; /* ber connection stuff */
423 char *c_cdn; /* DN provided by the client */
424 char *c_dn; /* DN bound to this conn */
425 ldap_pvt_thread_mutex_t c_dnmutex; /* mutex for c_dn field */
426 int c_protocol; /* version of the LDAP protocol used by client */
427 int c_authtype; /* auth method used to bind c_dn */
429 int c_version; /* for compatibility w/2.0, 3.0 */
431 char *c_addr; /* address of client on this conn */
432 char *c_domain; /* domain of client on this conn */
433 Operation *c_ops; /* list of pending operations */
434 ldap_pvt_thread_mutex_t c_opsmutex; /* mutex for c_ops list & stats */
435 ldap_pvt_thread_mutex_t c_pdumutex; /* only one pdu written at a time */
436 ldap_pvt_thread_cond_t c_wcv; /* used to wait for sd write-ready*/
437 int c_gettingber; /* in the middle of ber_get_next */
438 BerElement *c_currentber; /* ber we're getting */
439 int c_writewaiter; /* signals write-ready sd waiter */
440 int c_pduwaiters; /* signals threads waiting 4 pdu */
441 time_t c_starttime; /* when the connection was opened */
442 int c_connid; /* id of this connection for stats*/
443 int c_opsinitiated; /* # ops initiated/next op id */
444 int c_opscompleted; /* # ops completed */
447 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
448 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 ) \
450 if ( ldap_debug & level ) \
451 fprintf( stderr, fmt, connid, opid, arg1, arg2, arg3 );\
452 if ( ldap_syslog & level ) \
453 syslog( ldap_syslog_level, fmt, connid, opid, arg1, \
457 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
460 #include "proto-slap.h"
464 #endif /* _slap_h_ */