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