1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
/*
*
* Copyright 1998 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* structs for storing and updating entries
*/
#if !defined(_ENTRY_H_) && !defined(_PROTO_SLAP)
#define _ENTRY_H_
#ifndef _SLDAPD_H_
/*
* represents an attribute (type + values + syntax + oid)
*/
typedef struct attr {
char *a_type;
struct berval **a_vals;
int a_syntax;
struct attr *a_next;
} Attribute;
/*
* the attr_syntax() routine returns one of these values
* telling what kind of syntax an attribute supports.
*
* NOTE: The syntax may not be available in libentry unless you have
* read the slapd.conf config file.
*/
#define SYNTAX_CIS 0x01 /* case insensitive string */
#define SYNTAX_CES 0x02 /* case sensitive string */
#define SYNTAX_BIN 0x04 /* binary data */
#define SYNTAX_TEL 0x08 /* telephone number string */
#define SYNTAX_DN 0x10 /* dn string */
#define SYNTAX_LONG 0x20 /* integer */
#define SYNTAX_ULONG 0x40 /* integer */
#define SYNTAX_CRYPT 0x80 /* crypted password */
#define SYNTAX_UTCTIME 0x0100 /* Utctime string YYMMDDhhmm[ss]Z */
#define SYNTAX_GENTIME 0x0200 /* gentime string YYYYMMDDhhmm[ss]Z */
/* These next two are used by libentry. They are overloaded into a_syntax
* because there's no extra room and we didn't want to enlarge the structure
* because of the performance hit.
*/
#define ATTRIBUTE_FOUND 0x1000 /* Set if attribute was found */
#define ATTRIBUTE_ADD 0x2000 /* Set if values are to be added instead of replaced */
#define DEFAULT_SYNTAX SYNTAX_CIS
typedef struct asyntaxinfo {
char **asi_names;
char *asi_oid;
int asi_options;
#define ATTR_OPT_SINGLE 0x01 /* Single Valued attr */
#define ATTR_OPT_OPERATIONAL 0x02 /* Operational attr */
#define ATTR_OPT_NAMING 0x10 /* Naming Attribute */
char *asi_default_oc;
int asi_maxlen;
int asi_syntax;
} AttrSyntaxInfo;
/*
* the id used in the indexes to refer to an entry
*/
typedef unsigned int ID;
#define NOID ((unsigned int)-1)
/*
* represents an entry in core
*/
typedef struct entry {
char *e_dn; /* DN of this entry */
Attribute *e_attrs; /* list of attributes + values */
ID e_id; /* not used in libentry */
char e_state; /* only ENTRY_FOUND is used below */
#define ENTRY_STATE_DELETED 0x01 /* value not used in libentry */
#define ENTRY_STATE_CREATING 0x02 /* value not used in libentry */
int e_refcnt; /* # threads ref'ing this entry */
pthread_mutex_t e_mutex; /* to lock for add/modify */
struct entry *e_lrunext;
struct entry *e_lruprev; /* not used in libentry, (could be added) */
} Entry;
/* This next #define is used by libentry. It is overloaded into e_state.
* It is used to mark entries as found/not found so that they can be deleted
* if they are not found (for example on a remote replica).
*/
#define ENTRY_FOUND 0x80
#endif _SLDAPD_H_
/* entry.c */
/* output_ldif takes a modlist structure and prints out ldif. Since there are 3 ways
* you can use a modlist structure, you need to tell this routine what you're doing.
* The three choices are:
* LDAP_MODIFY_ENTRY
* LDAP_ADD_ENTRY
* LDAP_DELETE_ENTRY
* ldif suitable for feeding to ldapmodify will be produced.
*/
/* op arg to output_ldif() */
#define LDAP_MODIFY_ENTRY 1
#define LDAP_ADD_ENTRY 2
#define LDAP_DELETE_ENTRY 3
void output_ldif(char *dn, int op, LDAPMod **modlist, FILE *out);
/* Checks that base exist. If not, create it.
* ld - ldap context, you must supply it because it's used in ldap_search
* out - file to output ldif to. If supplied, ldif will be printed here,
* if not supplied, ldap_mod will be called for you (using ld).
*
* returns number of entries created if all is ok, -1 if an error occured.
*
* mutex locks: if you are outputting to out from other threads, you need
* to lock output_mutex. output_ldif locks this mutex before outputting.
*/
int make_base(LDAP *ld, FILE *out, char *base);
/* Add an entry to ldap. You supply an Entry struct. Will either add entry
* to ldap or output ldif to an open file (stdout for example).
*
* ld - ldap context. Must be valid if you want entry_add to add entries to ldap
* for you.
* out - open file where to send ldif output. One of ld or out should be valid.
* new_entry is an Entry which you want added to ldap
*
* returns number of entries created or -1 if an error occured in ldap_add()
*/
int entry_add(LDAP *ld, FILE *out, Entry *new_entry);
/* Compares two entries and issue changes to make old look like new.
*
* ld - ldap context. Must be valid if you want entry_update to add entries to ldap
* for you.
* out - open file where to send ldif output. One of ld or out should be valid.
* new_entry is an Entry which you want old_entry to look like
*
* returns number of entries modified or -1 if an error occured in ldap_modify()
*/
int entry_update(LDAP *ld, FILE *out, Entry *old_entry, Entry *new_entry);
/* Deletes an entry.
* ld - ldap context. Must be valid if you want delete_entry to call ldap
* for you.
* out - open file where to send ldif output. One of ld or out should be valid.
* ldap_entry is an Entry which you want to delete
*
* returns number of entries deleted or -1 if an error occured in ldap_modify()
* usually one, but for future it might delete more than one.
*/
int entry_delete(LDAP *ld, FILE *out, Entry *ldap_entry);
/* attr.c */
void attr_free( Attribute *a );
int attr_merge_fast(
Entry *e,
char *type,
struct berval **vals,
int nvals,
int naddvals,
int *maxvals,
Attribute ***a
);
int attr_merge(
Entry *e,
char *type,
struct berval **vals
);
Attribute *attr_find(
Attribute *a,
char *type,
int ignoreOpt
);
int attr_delete(
Attribute **attrs,
char *type
);
int attr_syntax( char *type );
int attr_syntax_by_oid( char *oid );
void attr_syntax_config(
char *fname,
int lineno,
int argc,
char **argv
);
char * attr_normalize( char *s );
char * alias_normalize( char *s );
int type_compare(char * t1, char *t2);
int type_list_compare(
char **a,
char *s
);
int attr_cmp(Attribute *attr1, Attribute *attr2);
char * get_type_from_list(char **a, char *s);
int attr_single_valued_check(char *type, struct berval **vals);
AttrSyntaxInfo *get_attrSyntaxInfo(char *type);
char * attr_syntax2oid(int aSyntax);
/* value.c */
int value_add_fast(
struct berval ***vals,
struct berval **addvals,
int nvals,
int naddvals,
int *maxvals
);
int value_delete(
struct berval ***vals,
struct berval *v,
int syntax,
int normalize
);
int value_add_one(
struct berval ***vals,
struct berval *v,
int syntax,
int normalize
);
time_t utc2seconds(char * utctime);
int value_add(
struct berval ***vals,
struct berval **addvals
);
void value_normalize(
char *s,
int syntax
);
int value_cmp(
struct berval *v1,
struct berval *v2,
int syntax,
int normalize /* 1 => arg 1; 2 => arg 2; 3 => both */
);
int value_ncmp(
struct berval *v1,
struct berval *v2,
int syntax,
int len,
int normalize
);
int value_find(
struct berval **vals,
struct berval *v,
int syntax,
int normalize
);
int value_cnt(struct berval **vals);
/* dn.c */
char *dn_normalize( char *dn );
char *dn_normalize_case( char *dn );
int dn_issuffix(char *dn, char *suffix);
char *dn_upcase( char *dn );
#endif _ENTRY_H_
|