1 /* slap.h - stand alone ldap server include file */
12 #include <sys/types.h>
13 #include <ac/syslog.h>
24 #include "ldap_pvt_thread.h"
28 #undef f_next /* name conflict between sys/file.h on SCO and struct filter */
31 /* LDAPMod.mod_op value ===> Must be kept in sync with ldap.h!
33 * This is a value used internally by the backends. It is needed to allow
34 * adding values that already exist without getting an error as required by
35 * modrdn when the new rdn was already an attribute value itself.
36 * JCG 05/1999 (gomez@engr.sgi.com)
38 #define LDAP_MOD_SOFTADD 0x04 /* Just make sure value is there */
49 #define MAXREMATCHES 10
51 #define DNSEPARATOR(c) ((c) == ',' || (c) == ';')
52 #define SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '+')
53 #define SPACE(c) ((c) == ' ' || (c) == '\n')
54 #define NEEDSESCAPE(c) ((c) == '\\' || (c) == '"')
62 * represents an attribute value assertion (i.e., attr=value)
66 struct berval ava_value;
70 * represents a search filter
72 typedef struct filter {
73 unsigned long f_choice; /* values taken from ldap.h */
79 /* equality, lessorequal, greaterorequal, approx */
83 struct filter *f_un_complex;
88 char *f_un_sub_initial;
93 #define f_type f_un.f_un_type
94 #define f_ava f_un.f_un_ava
95 #define f_avtype f_un.f_un_ava.ava_type
96 #define f_avvalue f_un.f_un_ava.ava_value
97 #define f_and f_un.f_un_complex
98 #define f_or f_un.f_un_complex
99 #define f_not f_un.f_un_complex
100 #define f_list f_un.f_un_complex
101 #define f_sub f_un.f_un_sub
102 #define f_sub_type f_un.f_un_sub.f_un_sub_type
103 #define f_sub_initial f_un.f_un_sub.f_un_sub_initial
104 #define f_sub_any f_un.f_un_sub.f_un_sub_any
105 #define f_sub_final f_un.f_un_sub.f_un_sub_final
107 struct filter *f_next;
111 * represents an attribute (type + values + syntax)
113 typedef struct attr {
115 struct berval **a_vals;
121 * the attr_syntax() routine returns one of these values
122 * telling what kind of syntax an attribute supports.
124 #define SYNTAX_CIS 0x01 /* case insensitive string */
125 #define SYNTAX_CES 0x02 /* case sensitive string */
126 #define SYNTAX_BIN 0x04 /* binary data */
127 #define SYNTAX_TEL 0x08 /* telephone number string */
128 #define SYNTAX_DN 0x10 /* dn string */
131 * the id used in the indexes to refer to an entry
133 typedef unsigned long ID;
134 #define NOID ((unsigned long)-1)
137 * represents an entry in core
139 typedef struct entry {
140 char *e_dn; /* DN of this entry */
141 char *e_ndn; /* normalized DN of this entry */
142 Attribute *e_attrs; /* list of attributes + values */
144 ID e_id; /* id of this entry - this should */
145 /* really be private to back-ldbm */
146 char e_state; /* for the cache */
148 ldap_pvt_thread_rdwr_t e_rdwr; /* reader/writer lock */
150 #define ENTRY_STATE_DELETED 1
151 #define ENTRY_STATE_CREATING 2
152 int e_refcnt; /* # threads ref'ing this entry */
153 struct entry *e_lrunext; /* for cache lru list */
154 struct entry *e_lruprev;
158 * represents an access control list
169 #ifdef SLAPD_ACLGROUPS
171 char *a_objectclassvalue;
172 char *a_groupattrname;
175 #define ACL_NONE 0x01
176 #define ACL_COMPARE 0x02
177 #define ACL_SEARCH 0x04
178 #define ACL_READ 0x08
179 #define ACL_WRITE 0x10
180 #define ACL_SELF 0x40
181 struct access *a_next;
186 /* "to" part: the entries this acl applies to */
192 /* "by" part: list of who has what access to the entries */
193 struct access *acl_access;
195 struct acl *acl_next;
199 * represents schema information for a database
206 struct objclass *oc_next;
210 * represents a "database"
213 typedef struct backend Backend;
215 char **be_suffix; /* the DN suffixes of data in this backend */
216 char **be_suffixAlias; /* the DN suffix aliases of data in this backend */
217 char *be_root_dn; /* the magic "root" dn for this db */
218 char *be_root_ndn; /* the magic "root" normalized dn for this db */
219 char *be_root_pw; /* the magic "root" password for this db */
220 int be_readonly; /* 1 => db is in "read only" mode */
221 int be_maxDerefDepth; /* limit for depth of an alias deref */
222 int be_sizelimit; /* size limit for this backend */
223 int be_timelimit; /* time limit for this backend */
224 struct acl *be_acl; /* access control list for this backend */
225 int be_dfltaccess; /* access given if no acl matches */
226 char **be_replica; /* replicas of this backend (in master) */
227 char *be_replogfile; /* replication log file (in master) */
228 char *be_update_ndn; /* allowed to make changes (in replicas) */
229 int be_lastmod; /* keep track of lastmodified{by,time} */
230 char *be_type; /* type of database */
232 void *be_private; /* anything the backend needs */
234 /* backend routines */
235 int (*be_bind) LDAP_P((Backend *be,
236 struct slap_conn *c, struct slap_op *o,
237 char *dn, int method, struct berval *cred, char** edn ));
238 void (*be_unbind) LDAP_P((Backend *be,
239 struct slap_conn *c, struct slap_op *o ));
240 int (*be_search) LDAP_P((Backend *be,
241 struct slap_conn *c, struct slap_op *o,
242 char *base, int scope, int deref, int slimit, int tlimit,
243 Filter *f, char *filterstr, char **attrs, int attrsonly));
244 int (*be_compare)LDAP_P((Backend *be,
245 struct slap_conn *c, struct slap_op *o,
246 char *dn, Ava *ava));
247 int (*be_modify) LDAP_P((Backend *be,
248 struct slap_conn *c, struct slap_op *o,
249 char *dn, LDAPMod *m));
250 int (*be_modrdn) LDAP_P((Backend *be,
251 struct slap_conn *c, struct slap_op *o,
252 char *dn, char *newrdn, int deleteoldrdn ));
253 int (*be_add) LDAP_P((Backend *be,
254 struct slap_conn *c, struct slap_op *o,
256 int (*be_delete) LDAP_P((Backend *be,
257 struct slap_conn *c, struct slap_op *o,
259 /* Bug: be_abandon in unused! */
260 void (*be_abandon)LDAP_P((Backend *be,
261 struct slap_conn *c, struct slap_op *o,
263 void (*be_config) LDAP_P((Backend *be,
264 char *fname, int lineno, int argc, char **argv ));
265 void (*be_init) LDAP_P((Backend *be));
266 void (*be_close) LDAP_P((Backend *be));
268 #ifdef SLAPD_ACLGROUPS
269 int (*be_group) LDAP_P((Backend *be, Entry *e,
270 char *bdn, char *edn,
271 char *objectclassValue, char *groupattrName ));
276 * represents an operation pending from an ldap client
279 typedef struct slap_op {
280 BerElement *o_ber; /* ber of the request */
281 long o_msgid; /* msgid of the request */
282 unsigned long o_tag; /* tag of the request */
283 time_t o_time; /* time op was initiated */
284 char *o_dn; /* dn bound when op was initiated */
285 char *o_ndn; /* normalized dn bound when op was initiated */
286 int o_authtype; /* auth method used to bind dn */
287 /* values taken from ldap.h */
289 int o_opid; /* id of this operation */
290 int o_connid; /* id of conn initiating this op */
291 #ifdef LDAP_CONNECTIONLESS
292 int o_cldap; /* != 0 if this came in via CLDAP */
293 struct sockaddr o_clientaddr; /* client address if via CLDAP */
294 char o_searchbase; /* search base if via CLDAP */
296 struct slap_op *o_next; /* next operation pending */
297 ldap_pvt_thread_t o_tid; /* thread handling this op */
298 int o_abandon; /* signals op has been abandoned */
299 ldap_pvt_thread_mutex_t o_abandonmutex; /* signals op has been abandoned */
301 void *o_private; /* anything the backend needs */
305 * represents a connection from an ldap client
308 typedef struct slap_conn {
309 Sockbuf c_sb; /* ber connection stuff */
310 char *c_cdn; /* DN provided by the client */
311 char *c_dn; /* DN bound to this conn */
312 ldap_pvt_thread_mutex_t c_dnmutex; /* mutex for c_dn field */
313 int c_authtype; /* auth method used to bind c_dn */
315 int c_version; /* for compatibility w/2.0, 3.0 */
317 char *c_addr; /* address of client on this conn */
318 char *c_domain; /* domain of client on this conn */
319 Operation *c_ops; /* list of pending operations */
320 ldap_pvt_thread_mutex_t c_opsmutex; /* mutex for c_ops list & stats */
321 ldap_pvt_thread_mutex_t c_pdumutex; /* only one pdu written at a time */
322 ldap_pvt_thread_cond_t c_wcv; /* used to wait for sd write-ready*/
323 int c_gettingber; /* in the middle of ber_get_next */
324 BerElement *c_currentber; /* ber we're getting */
325 int c_writewaiter; /* signals write-ready sd waiter */
326 int c_pduwaiters; /* signals threads waiting 4 pdu */
327 time_t c_starttime; /* when the connection was opened */
328 int c_connid; /* id of this connection for stats*/
329 int c_opsinitiated; /* # ops initiated/next op id */
330 int c_opscompleted; /* # ops completed */
333 #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
334 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 ) \
336 if ( ldap_debug & level ) \
337 fprintf( stderr, fmt, connid, opid, arg1, arg2, arg3 );\
338 if ( ldap_syslog & level ) \
339 syslog( ldap_syslog_level, fmt, connid, opid, arg1, \
343 #define Statslog( level, fmt, connid, opid, arg1, arg2, arg3 )
346 #include "proto-slap.h"
350 #endif /* _slap_h_ */