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