xref: /onnv-gate/usr/src/lib/libldap4/include/fe.h (revision 3857:21b9b714e4ab)
1 /*
2  *
3  * Copyright 1999 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 #ifndef _FE_H
11 #define _FE_H
12 
13 /*
14  * Get context const . Used to retreive info in context : fe_get_ctx
15  * Return values depend on requested info :
16  */
17 #define CTX_FENAME	1	/* To get the Front End name */
18 				/* return value is (char *) */
19 #define CTX_NBTABLE	2	/* To get the number of sub-section  */
20 				/* return value is (int *) */
21 #define CTX_TABLENAME	3	/* To get name(s) of sub section */
22 				/* return value is (char **) */
23 #define CTX_TABLEPTR	4	/* To get the ptr to a sub section definition */
24 				/* return value is (FE_Table *) */
25 				/* !! This is not a copy */
26 #define CTX_CUSTOMS	5	/* get customs attributes */
27 				/*   third parameter is the variable name (char *) */
28 
29 /*
30  * Get Tables const
31  */
32 #define TABLE_NAME	1	/* table or subsection name, return value is (char *) */
33 				/*   third parms is null  */
34 #define TABLE_OBJ_LST	2	/* object class list, return value is (char **)  */
35 				/*   third parms is null  */
36 #define TABLE_COM_HLD	3	/* stored ldap, connection return value is (LDAP *) */
37 #define TABLE_CUSTOMS	4	/* get customs attributes */
38 				/*   third parameter is the variable name (char *) */
39                                 /*   return value is an array of string (char **) */
40 #define TABLE_FEATTR	5	/* to get the attribute definition. If no attribute name */
41 				/*   is provided to get the list of attributes */
42 				/*   third parms is the attribute name */
43 				/*   return a FE_Attr * if attribute name provided */
44 				/*   return a char ** (null term) if no attribute name provided */
45 
46 #define TABLE_SUNDSATTR	6	/* idem TABLE_FEATTR but for SunDS definition */
47 
48 /*
49  * Tokens/Attributes
50  */
51 #define FETABLE		0
52 #define SUNDSTABLE	1
53 #define SUNDSATTRLIST	2
54 #define SUNDSTOKENLIST	3
55 #define FEATTRLIST	4
56 #define FETOKENLIST	5
57 #define FEBUILDLIST	6
58 #define SUNDSBUILDLIST	7
59 
60 /*
61  * Errors consts
62  */
63 #define NOERROR		0
64 #define INVALID_PARMS	1
65 #define VALUE_NOT_FOUND	2
66 #define CREATE_FAILED	3
67 #define SYNTAX_ERROR	4
68 
69 /*
70  * SPLIT way
71  */
72 #define LEFT2RIGHT     	0
73 #define RIGHT2LEFT	1
74 /*
75  * Data structures
76  */
77 
78 /*
79  * This struct is used to run regex with "reg_expression"
80  * and assigned values (braelist) with "token" links
81  * Functional schema :
82  *    step(input,reg_expression)
83  *      => token[0] = braslist[0]..braelist[0]
84  *	=> token[1] = braslist[1]..braelist[1]
85  *	=> ...
86  *	=> token[i] = braslist[i]..braelist[i]
87  */
88 typedef struct _reg_mapp {
89 	char	*reg_expression;	/* Compiled regular expression */
90 	int	Nbra;			/* nbra result */
91 	int	NbToken_Defined;	/* Nb tokens defined in reg_expression */
92 	int	*Token_ID;		/* Tokens place (index) in input value */
93 } Reg_Map;
94 
95 /*
96  * Tokens definition, including input attribute and number of expressions
97  * and link to each rule.
98  */
99 typedef struct _tokens_def {
100 	int	attr_ID;		/* Attributes ID (in SD or FE Table) */
101 					/* Used as input in regular expression */
102 	int	NbRules;		/* Number of expressions seperated by | */
103 	Reg_Map	**TokenRules;		/* Array of tokens rules */
104 } Token_Def;
105 
106 /*
107  * Attribute mapping definition. SD attributes are composed of FE attributes and
108  * SD tokens.
109  */
110 typedef struct _attr_mapping {
111 	char		*AttrName;		/* Attribute Name */
112 	char		*Expr;			/* Value expression */
113 	int		AttrStatus;		/* Store several attr's info such as */
114 						/* Key || Exist || Frozen */
115 						/* Key is used to generate wizard filter */
116 						/* Exist is used to generate wizard filter */
117 						/* Frozen is used control access on attribute */
118 	int		NbItem;			/* Nb Attributes & Tokens need to build val */
119 	int		*AttrID;		/* Set of attributes including tokens */
120 } Attr_Mapping;
121 
122 /*
123  * Builder_map : defined builder expression
124  */
125 typedef struct _builder_map {
126 	char		*build_exp;		/* the sentence to build */
127 	int		NbInput;
128 	int		*Input_ID;		/* List of attr ID to used as input in semtence */
129 }Builder_map;
130 
131 /*
132  * Data used for split/string2instances/instances2string/exclude functions
133  */
134 typedef struct _builder_fct {
135         int             Input_ID;
136 	char		*value;		/* input data						*/
137         char            *prefix;	/* string2instances and reverse : prefix	  	*/
138 					/* exclude		        : val 2 exclude		*/
139 	int		Parm_ID;	/* only for exclude funct       : ID of val 2 exclude	*/
140         char            *suffix;
141         char            *separator;
142 	int		readIndicator;
143 } Builder_fct;
144 
145 /*
146  * Builder tokens : used to build special value (named builder token) from other tokens
147  * or input value. They look like ouput attributes, but they allow to apply rules, if
148  * input value does exist. They also permit to split input sentence into attribute instances
149  */
150 typedef struct _builder {
151         char		*builder_name;
152 	int		builder_ID;
153 	int		NbRules;
154 	int		BuilderType;
155 	Builder_map	*Mapp;
156 	Builder_fct     *Fct;
157 } Build_def;
158 
159 
160 /*
161  * Full definition of table mapping.
162  */
163 typedef struct _table_mapping {
164 	int		NbTokens;		/* Nb extract tokens defined */
165 	int		NbAttributes;		/* Nb attributes in the entry */
166 	int		NbBuilder;		/* Nb builder tokens defined */
167 	Token_Def	**Tokens_list;		/* Array of tokens needed for translation */
168 	Build_def	*Build_list;		/* Array of builder tokens */
169 	Attr_Mapping	**Attr_list;		/* Array of Attributes defined in an entry */
170 } Table_Mapping;
171 
172 typedef struct _custo_info {
173 	char			*InfoName;
174 	int			NbValues;
175 	char			**Values;	/* Null terminated array of instance */
176 } Cust_Info;
177 
178 typedef struct _sds_com {
179 	LDAP		*lhd;			/* LDAP communication handle */
180 	char		**fe_object_list;	/* Array of ObjectClasses (null term list) */
181 } SDS_Com;
182 
183 typedef struct _dynrule {
184 	char	*ResName;			/* Result (or Rule) name			*/
185 	int	opType;				/* Extrac, Cond, split, str2ins, ins2str,	*/
186 						/* getrdn, exclude				*/
187 	int	NbExpr;				/* Nb rules found use only in extract & cond	*/
188 	int	*NbItems;			/* Nb variable in expression, usefull for	*/
189 						/* extract and cond. IT's a null terminated	*/
190 						/* array which contains the Number of var in  	*/
191 	char	**Expression;			/* The sentence	(make sense only in cond)     	*/
192 	char	**ConstVal;			/* use when funct parm are const not used for	*/
193 						/* extract and cond cases			*/
194 	char	**VarName;			/* Var can be 1)DynRule 2)InputData 3)Common	*/
195 } DynRule;
196 
197 typedef struct _fe_table {
198 	char		*fe_section;		/* Section table name				*/
199 	int		nb_fe_attr;		/* Nb FE attributes defined			*/
200 	int		nb_sds_attr;		/* Nb SDS attributes defined			*/
201 	int		nb_fe_tokens;		/* Nb tokens defined in FE section		*/
202 	int		nb_sds_tokens;		/* Nb tokens defined in SunDS section		*/
203 	int		nb_cust;		/* Nb custom attributes in common section	*/
204 	int		nb_fe_build;		/* Nb tokens build in FE section		*/
205 	int		nb_sds_build;		/* Nb tokens build in SUNDS section		*/
206 	int		nb_dyn_rules;		/* Nb dynamic rules in Dynamic section		*/
207 	char		**fe_token_list;	/* Array of FE token				*/
208 	char		**sds_token_list;	/* List of SunDS token				*/
209 	char		**fe_attr_list;		/* Array of attributes (null term list)		*/
210 	char		**sds_attr_list;	/* Array of attributes (null term list)		*/
211 	char		**fe_build_list;	/* Array of FE build				*/
212 	char		**sds_build_list;	/* List of SunDS build				*/
213 	Table_Mapping	*sds_schema;		/* SDS attributes definition			*/
214 	Table_Mapping	*fe_schema;		/* FE attributes definition			*/
215 	SDS_Com		*comm_items;		/* Communication attributes			*/
216 	Cust_Info	**custo_info;		/* Customs info					*/
217 	DynRule		*dyn_rules;		/* Ordered dynamic rules			*/
218 } FE_Table;
219 
220 typedef struct _fe_context {
221 	char		*fe_name;		/* Is it really usefull ?? */
222 	int		NbSection;		/* Nb section */
223 	int		NbGlobals;		/* Nb global customs info */
224 	Cust_Info	**globals;		/* Customs info */
225 	FE_Table	**fe_section_list;	/* All sub-section in mapping file */
226 } FE_Context;
227 
228 /* Entries values definition */
229 /* Instance values definition */
230 typedef struct _fe_values {
231 	int	Length;
232 	void	*Val;
233 } FE_Values;
234 
235 /* Attribute value definition */
236 typedef struct _fe_attr {
237 	char		*AttrType;
238 	int		NbInstance;
239 	FE_Values	**ValInstances;
240 } FE_Attr;
241 
242 /* Full entry definition */
243 typedef struct _fe_entry {
244 	char	*DN;
245 	int	Nb_items;
246 	FE_Attr	**AttributesArray;
247 } FE_Entry;
248 
249 typedef struct _fe_couple {
250 	char	*Value2Subst;
251 	char	*SubstValue;
252 } FE_Couple;
253 
254 /*
255  * libfe.a exported functions
256  */
257 
258 /*
259  * Read config file and create "fe_name" context
260  * NB : This init read all tables mapping
261  * libldap context use : before all action
262  */
263 extern FE_Context	*fe_ctx_init(char *config_path, char *fe_name);
264 
265 /*
266  * Free All fe context all tables ...
267  * libldap context usage : ldap_close
268  */
269 extern int		fe_ctx_free(FE_Context **Ctx);
270 
271 /*
272  * Return the pointer to requested item in context
273  * libldap context usage : before all action
274  */
275 extern void		 *fe_ctx_get(FE_Context *Ctx, int FieldID, void *Value);
276 
277 /*
278  * Search for information from Subsection/Table ?
279  * You can check also Get/Table/Paragraph
280  * libldap context usage : ldap_*
281  */
282 extern void		 *fe_table_get(FE_Table *MapTable, int FieldID, void *Void);
283 
284 /*
285  * Set tables item is mainly used for communication items. other information
286  * sets will be forbid
287  * libldap context usage : after ldap_open or ldap_bind
288  */
289 /*
290 extern int		  fe_table_set(FE_Table *MapTable, int FieldID, void *Void);
291 */
292 /*
293  * You have the attribute name ?! fe_ent_get_attr returns pointer to the requested
294  * attributes with instances, status... from a specific entry
295  * libldap context usage : after ldap_search
296  */
297 extern FE_Attr		 *fe_ent_get_attr(FE_Table *MapTable, FE_Entry *fe_item, char *AttrName);
298 
299 /*
300  * Create the entry according to the "schema" defined in mapping file for a specific table
301  * libladp context usage : before ldap_add
302  */
303 extern FE_Entry		 *fe_ent_create(FE_Table *MapTable, int TableType);
304 
305 /*
306  * Add new attributes in a new entry
307  * libladp context usage : before ldap_add
308  */
309 extern FE_Attr           *fe_ent_get_attr(FE_Table *MapTable,FE_Entry *Entry, char *AttrName);
310 
311 /*
312  * Add new instance value
313  * libladp context usage : before ldap_add
314  */
315 extern int		  fe_ent_add_val(FE_Table *MapTable, FE_Attr *attr, int ValLength, void *Val);
316 extern  FE_Attr		  *fe_ent_add_attr_val(FE_Table *MapTable, FE_Entry *Entry, char *AttrName, int ValLength, void *Val);
317 
318 /*
319  * explode DN into an attributes array
320  * libladp context usage : after ldap_search
321  */
322 extern FE_Attr		**fe_ent_show_dn(FE_Table *MapTable, FE_Entry *Entry);
323 
324 /*
325  *  free entry (including attributes)
326  */
327 extern void		  fe_ent_free(FE_Entry **Entry);
328 
329 /*
330  * Substitute all vars defined in inputString (with syntax ${varName}) by values found in
331  * fe_couple array. For errors returned check the errors consts upper
332  */
333 extern int		fe_subst(char *inputString, char **outputString, FE_Couple **fe_couple);
334 
335 /*
336  * Split a sentence, add prefix (for each token) and suffix (exept for the last)
337  */
338 extern char		*fe_split(char *inputData, char *Separator, char *Prefix, char *Suffix, int  way );
339 
340 /*
341  * Dynamic translation, use only definition in dynamic section
342  */
343 extern char		**fe_dynamic(FE_Table *MapTable, char *Var2stop, char **DynVal);
344 
345 /*
346  * Return the translated attribute. TableType is the original table of AttrName.
347  * if translation rules is one to one translation, the function return a copy of translated
348  * attribute name.
349  * else the function return a copy of the rules
350  */
351 extern char		**fe_trans_attrName(FE_Table *MapTable, char *AttrName, int TableType);
352 extern int		*fe_trans_attrID(FE_Table *MapTable, char *AttrName, int TableType);
353 
354 /*
355  * Return the translated SD entry
356  * libladp context usage : after ldap_search
357  */
358 extern FE_Entry		 *fe_trans_all_sds2fe(FE_Table *MapTable, LDAP *ld, LDAPMessage *sd_entry);
359 
360 /*
361  * Return the translated FE entry
362  * libladp context usage : after ldap_search
363  */
364 extern LDAPMod		 **fe_trans_all_fe2sds(FE_Table *MapTable, LDAP *ld, FE_Entry *fe_entry);
365 
366 /*
367  * Close to "fe_trans_all_sds2fe" but output is Entry pointer as defined in SunDS server
368  */
369 extern FE_Entry		*fe_trans_all_sunds2fe(FE_Table *MapTable, Entry *sd_entry);
370 extern Entry		*fe_trans_all_fe2sunds(FE_Table *MapTable, FE_Entry *fe_entry);
371 
372 /* An example an example ....
373  * Translation from fe to sunds
374  *
375  * FE_Context      *MyContext = NULL;
376  * FE_Table        *HostTable = NULL;
377  * FE_Entry        *fe_entry = NULL;
378  * FE_Attr         *fe_attr = NULL;
379  * Entry           *lentry = NULL;
380  *
381  * if((MyContext = fe_ctx_init("..../sunds_map.conf","NIS")) == NULL){
382  *	ldaplog(LDAP_DEBUG_CONFIG,"Can't load mapping file\n", 0, 0, 0);
383  *	exit(1);
384  * }
385  * if((HostTable = fe_ctx_get(MyContext,CTX_TABLEPTR,"dummy")) == NULL)
386  * {
387  *	ldaplog(LDAP_DEBUG_CONFIG,"Can't retreive HOSTS table\n", 0, 0, 0);
388  *	exit(1);
389  * }
390  * if((fe_entry = fe_ent_create(HostTable, FETABLE))==NULL)
391  * {
392  *	ldaplog(LDAP_DEBUG_CONFIG,"Can't create entry\n", 0, 0, 0);
393  *	exit(1);
394  * }
395  * if ((fe_attr = fe_ent_add_attr_val(HostTable, fe_entry, "niskey", 16, "109.107.179.131")) == NULL)
396  * {
397  *	ldaplog(LDAP_DEBUG_CONFIG,"Can't add attr=%s, val=%s\n", "niskey", "109.107.179.131", 0);
398  *	exit(1);
399  * }
400  * if((fe_attr = fe_ent_add_attr_val(HostTable,
401  *					fe_entry,
402  *					"NISVALUE",
403  *					strlen("olivaw OLIVAW oLiVaW # regis Host") +1,
404  *					"olivaw OLIVAW oLiVaW # regis Host")) == NULL)
405  * {
406  *	ldaplog(...);
407  *	exit(1);
408  * }
409  * if((lentry = fe_trans_all_fe2sunds(HostTable, fe_entry)) ==NULL)
410  * {
411  *	ldaplog(LDAP_DEBUG_CONFIG,".... \n", 0);
412  * }
413  *
414  */
415 
416 #endif /* _FE_H */
417 
418 
419 
420 
421