1 /* slap.h - stand alone ldap server include file */
12 #include <sys/types.h>
13 #include <ac/syslog.h>
19 #define ldap_debug slap_debug
25 #include "../../libraries/liblber/lber-int.h"
28 #include "ldap_pvt_thread.h"
31 #undef f_next /* name conflict between sys/file.h on SCO and struct filter */
41 #define MAXREMATCHES 10
43 #define DNSEPARATOR(c) ((c) == ',' || (c) == ';')
44 #define SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '+')
45 #define SPACE(c) ((c) == ' ' || (c) == '\n')
46 #define NEEDSESCAPE(c) ((c) == '\\' || (c) == '"')
50 extern int slap_debug;
56 * represents an attribute value assertion (i.e., attr=value)
60 struct berval ava_value;
64 * represents a search filter
66 typedef struct filter {
67 unsigned long f_choice; /* values taken from ldap.h */
73 /* equality, lessorequal, greaterorequal, approx */
77 struct filter *f_un_complex;
82 char *f_un_sub_initial;
87 #define f_type f_un.f_un_type
88 #define f_ava f_un.f_un_ava
89 #define f_avtype f_un.f_un_ava.ava_type
90 #define f_avvalue f_un.f_un_ava.ava_value
91 #define f_and f_un.f_un_complex
92 #define f_or f_un.f_un_complex
93 #define f_not f_un.f_un_complex
94 #define f_list f_un.f_un_complex
95 #define f_sub f_un.f_un_sub
96 #define f_sub_type f_un.f_un_sub.f_un_sub_type
97 #define f_sub_initial f_un.f_un_sub.f_un_sub_initial
98 #define f_sub_any f_un.f_un_sub.f_un_sub_any
99 #define f_sub_final f_un.f_un_sub.f_un_sub_final
101 struct filter *f_next;
105 * represents an attribute (type + values + syntax)
107 typedef struct attr {
109 struct berval **a_vals;
115 * the attr_syntax() routine returns one of these values
116 * telling what kind of syntax an attribute supports.
118 #define SYNTAX_CIS 0x01 /* case insensitive string */
119 #define SYNTAX_CES 0x02 /* case sensitive string */
120 #define SYNTAX_BIN 0x04 /* binary data */
121 #define SYNTAX_TEL 0x08 /* telephone number string */
122 #define SYNTAX_DN 0x10 /* dn string */
125 * the id used in the indexes to refer to an entry
127 typedef unsigned long ID;
128 #define NOID ((unsigned long)-1)
131 * represents an entry in core
133 typedef struct entry {
135 * The ID field should only be changed before entry is
136 * inserted into a cache. The ID value is backend
141 char *e_dn; /* DN of this entry */
142 char *e_ndn; /* normalized DN of this entry */
143 Attribute *e_attrs; /* list of attributes + values */
145 /* for use by the backend for any purpose */
150 * represents an access control list
155 #define ACL_NONE 0x01
156 #define ACL_COMPARE 0x02
157 #define ACL_SEARCH 0x04
158 #define ACL_READ 0x08
159 #define ACL_WRITE 0x10
160 #define ACL_SELF 0x40
168 #ifdef SLAPD_ACLGROUPS
170 char *a_objectclassvalue;
171 char *a_groupattrname;
173 struct access *a_next;
178 /* "to" part: the entries this acl applies to */
184 /* "by" part: list of who has what access to the entries */
185 struct access *acl_access;
187 struct acl *acl_next;
193 typedef struct ldapmodlist {
194 struct ldapmod ml_mod;
195 struct ldapmodlist *ml_next;
196 #define ml_op ml_mod.mod_op
197 #define ml_type ml_mod.mod_type
198 #define ml_values ml_mod.mod_values
199 #define ml_bvalues ml_mod.mod_bvalues
203 * represents schema information for a database
210 struct objclass *oc_next;
215 * represents a backend
218 typedef struct backend_info BackendInfo; /* per backend type */
219 typedef struct backend_db BackendDB; /* per backend database */
221 extern int nBackendInfo;
222 extern int nBackendDB;
223 extern BackendInfo *backendInfo;
224 extern BackendDB *backendDB;
227 #define SLAP_UNDEFINED_MODE 0
228 #define SLAP_SERVER_MODE 1
229 #define SLAP_TOOL_MODE 2
231 # define SLAP_TIMEDSERVER_MODE 3
232 # define SLAP_TOOLID_MODE 4
235 /* temporary aliases */
236 typedef BackendDB Backend;
237 #define nbackends nBackendDB
238 #define backends backendDB
241 BackendInfo *bd_info; /* pointer to shared backend info */
243 /* BackendInfo accessors */
244 #define be_config bd_info->bi_db_config
245 #define be_type bd_info->bi_type
247 #define be_bind bd_info->bi_op_bind
248 #define be_unbind bd_info->bi_op_unbind
249 #define be_add bd_info->bi_op_add
250 #define be_compare bd_info->bi_op_compare
251 #define be_delete bd_info->bi_op_delete
252 #define be_modify bd_info->bi_op_modify
253 #define be_modrdn bd_info->bi_op_modrdn
254 #define be_search bd_info->bi_op_search
256 #define be_group bd_info->bi_acl_group
258 /* these should be renamed from be_ to bd_ */
259 char **be_suffix; /* the DN suffixes of data in this backend */
260 char **be_suffixAlias; /* the DN suffix aliases of data in this backend */
261 char *be_root_dn; /* the magic "root" dn for this db */
262 char *be_root_ndn; /* the magic "root" normalized dn for this db */
263 char *be_root_pw; /* the magic "root" password for this db */
264 int be_readonly; /* 1 => db is in "read only" mode */
265 int be_maxDerefDepth; /* limit for depth of an alias deref */
266 int be_sizelimit; /* size limit for this backend */
267 int be_timelimit; /* time limit for this backend */
268 struct acl *be_acl; /* access control list for this backend */
269 int be_dfltaccess; /* access given if no acl matches */
270 char **be_replica; /* replicas of this backend (in master) */
271 char *be_replogfile; /* replication log file (in master) */
272 char *be_update_ndn; /* allowed to make changes (in replicas) */
273 int be_lastmod; /* keep track of lastmodified{by,time} */
275 void *be_private; /* anything the backend database needs */
278 struct backend_info {
279 char *bi_type; /* type of backend */
282 * per backend type routines:
283 * bi_init: called to allocate a backend_info structure,
284 * called once BEFORE configuration file is read.
285 * bi_init() initializes this structure hence is
286 * called directly from be_initialize()
287 * bi_config: called per 'backend' specific option
288 * all such options must before any 'database' options
289 * bi_config() is called only from read_config()
290 * bi_open: called to open each database, called
291 * once AFTER configuration file is read but
292 * BEFORE any bi_db_open() calls.
293 * bi_open() is called from backend_startup()
294 * bi_close: called to close each database, called
295 * once during shutdown after all bi_db_close calls.
296 * bi_close() is called from backend_shutdown()
297 * bi_destroy: called to destroy each database, called
298 * once during shutdown after all bi_db_destroy calls.
299 * bi_destory() is called from backend_destroy()
301 int (*bi_init) LDAP_P((BackendInfo *bi));
302 int (*bi_config) LDAP_P((BackendInfo *bi,
303 char *fname, int lineno, int argc, char **argv ));
304 int (*bi_open) LDAP_P((BackendInfo *bi));
305 int (*bi_close) LDAP_P((BackendInfo *bi));
306 int (*bi_destroy) LDAP_P((BackendInfo *bi));
309 * per database routines:
310 * bi_db_init: called to initialize each database,
311 * called upon reading 'database <type>'
312 * called only from backend_db_init()
313 * bi_db_config: called to configure each database,
314 * called per database to handle per database options
315 * called only from read_config()
316 * bi_db_open: called to open each database
317 * called once per database immediately AFTER bi_open()
318 * calls but before daemon startup.
319 * called only by backend_startup()
320 * bi_db_close: called to close each database
321 * called once per database during shutdown but BEFORE
323 * called only by backend_shutdown()
324 * bi_db_destroy: called to destroy each database
325 * called once per database during shutdown AFTER all
326 * bi_close calls but before bi_destory calls.
327 * called only by backend_destory()
329 int (*bi_db_init) LDAP_P((Backend *bd));
330 int (*bi_db_config) LDAP_P((Backend *bd,
331 char *fname, int lineno, int argc, char **argv ));
332 int (*bi_db_open) LDAP_P((Backend *bd));
333 int (*bi_db_close) LDAP_P((Backend *bd));
334 int (*bi_db_destroy) LDAP_P((Backend *db));
336 /* LDAP Operations Handling Routines */
337 int (*bi_op_bind) LDAP_P(( BackendDB *bd,
338 struct slap_conn *c, struct slap_op *o,
339 char *dn, int method, struct berval *cred, char** edn ));
340 int (*bi_op_unbind) LDAP_P((BackendDB *bd,
341 struct slap_conn *c, struct slap_op *o ));
342 int (*bi_op_search) LDAP_P((BackendDB *bd,
343 struct slap_conn *c, struct slap_op *o,
344 char *base, int scope, int deref, int slimit, int tlimit,
345 Filter *f, char *filterstr, char **attrs, int attrsonly));
346 int (*bi_op_compare)LDAP_P((BackendDB *bd,
347 struct slap_conn *c, struct slap_op *o,
348 char *dn, Ava *ava));
349 int (*bi_op_modify) LDAP_P((BackendDB *bd,
350 struct slap_conn *c, struct slap_op *o,
351 char *dn, LDAPModList *m));
352 int (*bi_op_modrdn) LDAP_P((BackendDB *bd,
353 struct slap_conn *c, struct slap_op *o,
354 char *dn, char *newrdn, int deleteoldrdn,
356 int (*bi_op_add) LDAP_P((BackendDB *bd,
357 struct slap_conn *c, struct slap_op *o,
359 int (*bi_op_delete) LDAP_P((BackendDB *bd,
360 struct slap_conn *c, struct slap_op *o,
362 /* Bug: be_op_abandon in unused! */
363 int (*bi_op_abandon) LDAP_P((BackendDB *bd,
364 struct slap_conn *c, struct slap_op *o,
367 /* Auxilary Functions */
368 #ifdef SLAPD_ACLGROUPS
369 int (*bi_acl_group) LDAP_P((Backend *bd,
370 Entry *e, char *bdn, char *edn,
371 char *objectclassValue, char *groupattrName ));
374 unsigned int bi_nDB; /* number of databases of this type */
375 void *bi_private; /* anything the backend type needs */
379 * represents an operation pending from an ldap client
382 typedef struct slap_op {
383 long o_opid; /* id of this operation */
384 long o_msgid; /* msgid of the request */
386 ldap_pvt_thread_t o_tid; /* thread handling this op */
388 BerElement *o_ber; /* ber of the request */
390 unsigned long o_tag; /* tag of the request */
391 time_t o_time; /* time op was initiated */
392 char *o_dn; /* dn bound when op was initiated */
393 char *o_ndn; /* normalized dn bound when op was initiated */
394 int o_authtype; /* auth method used to bind dn */
395 /* values taken from ldap.h */
398 /* long o_connid; *//* id of conn initiating this op */
400 #ifdef LDAP_CONNECTIONLESS
401 int o_cldap; /* != 0 if this came in via CLDAP */
402 struct sockaddr o_clientaddr; /* client address if via CLDAP */
403 char o_searchbase; /* search base if via CLDAP */
406 ldap_pvt_thread_mutex_t o_abandonmutex; /* protects o_abandon */
407 int o_abandon; /* abandon flag */
409 struct slap_op *o_next; /* next operation in list */
410 void *o_private; /* anything the backend needs */
414 * represents a connection from an ldap client
418 /* structure state (protected by connections_mutex) */
419 #define SLAP_C_UNINITIALIZED 0x0 /* MUST BE ZERO (0) */
420 #define SLAP_C_UNUSED 0x1
421 #define SLAP_C_USED 0x2
423 /* connection state (protected by c_mutex ) */
424 #define SLAP_C_INVALID 0x0 /* MUST BE ZERO (0) */
425 #define SLAP_C_INACTIVE 0x1 /* zero threads */
426 #define SLAP_C_ACTIVE 0x2 /* one or more threads */
427 #define SLAP_C_BINDING 0x3 /* binding */
428 #define SLAP_C_CLOSING 0x4 /* closing */
430 typedef struct slap_conn {
431 int c_struct_state; /* structure management state */
432 int c_conn_state; /* connection state */
434 ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
435 Sockbuf c_sb; /* ber connection stuff */
437 /* only can be changed by connect_init */
438 time_t c_starttime; /* when the connection was opened */
439 long c_connid; /* id of this connection for stats*/
440 char *c_client_addr; /* address of client */
441 char *c_client_name; /* name of client */
443 /* only can be changed by binding thread */
444 char *c_cdn; /* DN provided by the client */
445 char *c_dn; /* DN bound to this conn */
446 int c_protocol; /* version of the LDAP protocol used by client */
447 int c_authtype; /* auth method used to bind c_dn */
449 int c_version; /* for compatibility w/2.0, 3.0 */
452 Operation *c_ops; /* list of operations being processed */
453 Operation *c_pending_ops; /* list of pending operations */
455 ldap_pvt_thread_mutex_t c_write_mutex; /* only one pdu written at a time */
456 ldap_pvt_thread_cond_t c_write_cv; /* used to wait for sd write-ready*/
458 BerElement *c_currentber; /* ber we're attempting to read */
459 int c_writewaiter; /* true if writer is waiting */
461 long c_n_ops_received; /* num of ops received (next op_id) */
463 long c_n_ops_executing; /* num of ops currently executing */
464 long c_n_ops_pending; /* num of ops pending execution */
465 long c_n_ops_completed; /* num of ops completed */
469 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
470 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 ) \
472 if ( ldap_debug & level ) \
473 fprintf( stderr, fmt, connid, opid, arg1, arg2, arg3 );\
474 if ( ldap_syslog & level ) \
475 syslog( ldap_syslog_level, fmt, connid, opid, arg1, \
479 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
482 #include "proto-slap.h"
486 #endif /* _slap_h_ */