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"
31 #include "lthread_rdwr.h"
34 #undef f_next /* name conflict between sys/file.h on SCO and struct filter */
44 #define MAXREMATCHES 10
46 #define DNSEPARATOR(c) ((c) == ',' || (c) == ';')
47 #define SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '+')
48 #define SPACE(c) ((c) == ' ' || (c) == '\n')
49 #define NEEDSESCAPE(c) ((c) == '\\' || (c) == '"')
53 extern int slap_debug;
59 * represents an attribute value assertion (i.e., attr=value)
63 struct berval ava_value;
67 * represents a search filter
69 typedef struct filter {
70 unsigned long f_choice; /* values taken from ldap.h */
76 /* equality, lessorequal, greaterorequal, approx */
80 struct filter *f_un_complex;
85 char *f_un_sub_initial;
90 #define f_type f_un.f_un_type
91 #define f_ava f_un.f_un_ava
92 #define f_avtype f_un.f_un_ava.ava_type
93 #define f_avvalue f_un.f_un_ava.ava_value
94 #define f_and f_un.f_un_complex
95 #define f_or f_un.f_un_complex
96 #define f_not f_un.f_un_complex
97 #define f_list f_un.f_un_complex
98 #define f_sub f_un.f_un_sub
99 #define f_sub_type f_un.f_un_sub.f_un_sub_type
100 #define f_sub_initial f_un.f_un_sub.f_un_sub_initial
101 #define f_sub_any f_un.f_un_sub.f_un_sub_any
102 #define f_sub_final f_un.f_un_sub.f_un_sub_final
104 struct filter *f_next;
108 * represents an attribute (type + values + syntax)
110 typedef struct attr {
112 struct berval **a_vals;
118 * the attr_syntax() routine returns one of these values
119 * telling what kind of syntax an attribute supports.
121 #define SYNTAX_CIS 0x01 /* case insensitive string */
122 #define SYNTAX_CES 0x02 /* case sensitive string */
123 #define SYNTAX_BIN 0x04 /* binary data */
124 #define SYNTAX_TEL 0x08 /* telephone number string */
125 #define SYNTAX_DN 0x10 /* dn string */
128 * the id used in the indexes to refer to an entry
130 typedef unsigned long ID;
131 #define NOID ((unsigned long)-1)
134 * represents an entry in core
136 typedef struct entry {
137 char *e_dn; /* DN of this entry */
138 char *e_ndn; /* normalized DN of this entry */
139 Attribute *e_attrs; /* list of attributes + values */
141 ID e_id; /* id of this entry - this should */
142 /* really be private to back-ldbm */
143 char e_state; /* for the cache */
145 pthread_rdwr_t e_rdwr; /* reader/writer lock */
147 #define ENTRY_STATE_DELETED 1
148 #define ENTRY_STATE_CREATING 2
149 int e_refcnt; /* # threads ref'ing this entry */
150 struct entry *e_lrunext; /* for cache lru list */
151 struct entry *e_lruprev;
155 * represents an access control list
166 #ifdef SLAPD_ACLGROUPS
168 char *a_objectclassvalue;
169 char *a_groupattrname;
172 #define ACL_NONE 0x01
173 #define ACL_COMPARE 0x02
174 #define ACL_SEARCH 0x04
175 #define ACL_READ 0x08
176 #define ACL_WRITE 0x10
177 #define ACL_SELF 0x40
178 struct access *a_next;
183 /* "to" part: the entries this acl applies to */
189 /* "by" part: list of who has what access to the entries */
190 struct access *acl_access;
192 struct acl *acl_next;
198 typedef struct ldapmodlist {
199 struct ldapmod ml_mod;
200 struct ldapmodlist *ml_next;
201 #define ml_op ml_mod.mod_op
202 #define ml_type ml_mod.mod_type
203 #define ml_values ml_mod.mod_values
204 #define ml_bvalues ml_mod.mod_bvalues
208 * represents schema information for a database
215 struct objclass *oc_next;
219 * represents a "database"
222 typedef struct backend Backend;
224 char **be_suffix; /* the DN suffixes of data in this backend */
225 char **be_suffixAlias; /* the DN suffix aliases of data in this backend */
226 char *be_root_dn; /* the magic "root" dn for this db */
227 char *be_root_ndn; /* the magic "root" normalized dn for this db */
228 char *be_root_pw; /* the magic "root" password for this db */
229 int be_readonly; /* 1 => db is in "read only" mode */
230 int be_maxDerefDepth; /* limit for depth of an alias deref */
231 int be_sizelimit; /* size limit for this backend */
232 int be_timelimit; /* time limit for this backend */
233 struct acl *be_acl; /* access control list for this backend */
234 int be_dfltaccess; /* access given if no acl matches */
235 char **be_replica; /* replicas of this backend (in master) */
236 char *be_replogfile; /* replication log file (in master) */
237 char *be_update_ndn; /* allowed to make changes (in replicas) */
238 int be_lastmod; /* keep track of lastmodified{by,time} */
239 char *be_type; /* type of database */
241 void *be_private; /* anything the backend needs */
243 /* backend routines */
244 int (*be_bind) LDAP_P((Backend *be,
245 struct slap_conn *c, struct slap_op *o,
246 char *dn, int method, struct berval *cred, char** edn ));
247 void (*be_unbind) LDAP_P((Backend *be,
248 struct slap_conn *c, struct slap_op *o ));
249 int (*be_search) LDAP_P((Backend *be,
250 struct slap_conn *c, struct slap_op *o,
251 char *base, int scope, int deref, int slimit, int tlimit,
252 Filter *f, char *filterstr, char **attrs, int attrsonly));
253 int (*be_compare)LDAP_P((Backend *be,
254 struct slap_conn *c, struct slap_op *o,
255 char *dn, Ava *ava));
256 int (*be_modify) LDAP_P((Backend *be,
257 struct slap_conn *c, struct slap_op *o,
258 char *dn, LDAPModList *m));
259 int (*be_modrdn) LDAP_P((Backend *be,
260 struct slap_conn *c, struct slap_op *o,
261 char *dn, char *newrdn, int deleteoldrdn ));
262 int (*be_add) LDAP_P((Backend *be,
263 struct slap_conn *c, struct slap_op *o,
265 int (*be_delete) LDAP_P((Backend *be,
266 struct slap_conn *c, struct slap_op *o,
268 /* Bug: be_abandon in unused! */
269 void (*be_abandon)LDAP_P((Backend *be,
270 struct slap_conn *c, struct slap_op *o,
272 void (*be_config) LDAP_P((Backend *be,
273 char *fname, int lineno, int argc, char **argv ));
274 void (*be_init) LDAP_P((Backend *be));
275 void (*be_close) LDAP_P((Backend *be));
277 #ifdef SLAPD_ACLGROUPS
278 int (*be_group) LDAP_P((Backend *be, Entry *e,
279 char *bdn, char *edn,
280 char *objectclassValue, char *groupattrName ));
285 * represents an operation pending from an ldap client
288 typedef struct slap_op {
289 BerElement *o_ber; /* ber of the request */
290 long o_msgid; /* msgid of the request */
291 unsigned long o_tag; /* tag of the request */
292 time_t o_time; /* time op was initiated */
293 char *o_dn; /* dn bound when op was initiated */
294 char *o_ndn; /* normalized dn bound when op was initiated */
295 int o_authtype; /* auth method used to bind dn */
296 /* values taken from ldap.h */
298 int o_opid; /* id of this operation */
299 int o_connid; /* id of conn initiating this op */
300 #ifdef LDAP_CONNECTIONLESS
301 int o_cldap; /* != 0 if this came in via CLDAP */
302 struct sockaddr o_clientaddr; /* client address if via CLDAP */
303 char o_searchbase; /* search base if via CLDAP */
305 struct slap_op *o_next; /* next operation pending */
306 pthread_t o_tid; /* thread handling this op */
307 int o_abandon; /* signals op has been abandoned */
308 pthread_mutex_t o_abandonmutex; /* signals op has been abandoned */
310 int o_private; /* anything the backend needs */
314 * represents a connection from an ldap client
317 typedef struct slap_conn {
318 Sockbuf c_sb; /* ber connection stuff */
319 char *c_cdn; /* DN provided by the client */
320 char *c_dn; /* DN bound to this conn */
321 pthread_mutex_t c_dnmutex; /* mutex for c_dn field */
322 int c_authtype; /* auth method used to bind c_dn */
324 int c_version; /* for compatibility w/2.0, 3.0 */
326 char *c_addr; /* address of client on this conn */
327 char *c_domain; /* domain of client on this conn */
328 Operation *c_ops; /* list of pending operations */
329 pthread_mutex_t c_opsmutex; /* mutex for c_ops list & stats */
330 pthread_mutex_t c_pdumutex; /* only one pdu written at a time */
331 pthread_cond_t c_wcv; /* used to wait for sd write-ready*/
332 int c_gettingber; /* in the middle of ber_get_next */
333 BerElement *c_currentber; /* ber we're getting */
334 int c_writewaiter; /* signals write-ready sd waiter */
335 int c_pduwaiters; /* signals threads waiting 4 pdu */
336 time_t c_starttime; /* when the connection was opened */
337 int c_connid; /* id of this connection for stats*/
338 int c_opsinitiated; /* # ops initiated/next op id */
339 int c_opscompleted; /* # ops completed */
342 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
343 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 ) \
345 if ( ldap_debug & level ) \
346 fprintf( stderr, fmt, connid, opid, arg1, arg2, arg3 );\
347 if ( ldap_syslog & level ) \
348 syslog( ldap_syslog_level, fmt, connid, opid, arg1, \
352 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
355 #include "proto-slap.h"
359 #endif /* _slap_h_ */