summaryrefslogtreecommitdiff
path: root/usr/src/lib/libldap4/include/fe.h
blob: 4e2772ec14e82ce58f0d50555d85302ec13a7a4f (plain)
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
/*
 *
 * Copyright %G% Sun Microsystems, Inc. 
 * All Rights Reserved
 *
 */

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#ifndef _FE_H
#define _FE_H

/*
 * Get context const . Used to retreive info in context : fe_get_ctx
 * Return values depend on requested info :
 */
#define CTX_FENAME	1	/* To get the Front End name */
				/* return value is (char *) */
#define CTX_NBTABLE	2	/* To get the number of sub-section  */
				/* return value is (int *) */
#define CTX_TABLENAME	3	/* To get name(s) of sub section */
				/* return value is (char **) */
#define CTX_TABLEPTR	4	/* To get the ptr to a sub section definition */
				/* return value is (FE_Table *) */
				/* !! This is not a copy */
#define CTX_CUSTOMS	5	/* get customs attributes */
				/*   third parameter is the variable name (char *) */

/*
 * Get Tables const 
 */
#define TABLE_NAME	1	/* table or subsection name, return value is (char *) */
				/*   third parms is null  */
#define TABLE_OBJ_LST	2	/* object class list, return value is (char **)  */
				/*   third parms is null  */
#define TABLE_COM_HLD	3	/* stored ldap, connection return value is (LDAP *) */
#define TABLE_CUSTOMS	4	/* get customs attributes */
				/*   third parameter is the variable name (char *) */
                                /*   return value is an array of string (char **) */
#define TABLE_FEATTR	5	/* to get the attribute definition. If no attribute name */
				/*   is provided to get the list of attributes */
				/*   third parms is the attribute name */
				/*   return a FE_Attr * if attribute name provided */
				/*   return a char ** (null term) if no attribute name provided */

#define TABLE_SUNDSATTR	6	/* idem TABLE_FEATTR but for SunDS definition */

/*
 * Tokens/Attributes 
 */
#define FETABLE		0
#define SUNDSTABLE	1
#define SUNDSATTRLIST	2
#define SUNDSTOKENLIST	3
#define FEATTRLIST	4
#define FETOKENLIST	5
#define FEBUILDLIST	6
#define SUNDSBUILDLIST	7

/*
 * Errors consts
 */
#define NOERROR		0
#define INVALID_PARMS	1
#define VALUE_NOT_FOUND	2
#define CREATE_FAILED	3
#define SYNTAX_ERROR	4

/*
 * SPLIT way
 */
#define LEFT2RIGHT     	0     
#define RIGHT2LEFT	1
/*
 * Data structures
 */

/*
 * This struct is used to run regex with "reg_expression"
 * and assigned values (braelist) with "token" links
 * Functional schema :
 *    step(input,reg_expression)
 *      => token[0] = braslist[0]..braelist[0]
 *	=> token[1] = braslist[1]..braelist[1]
 *	=> ...
 *	=> token[i] = braslist[i]..braelist[i]
 */
typedef struct _reg_mapp {
	char	*reg_expression;	/* Compiled regular expression */
	int	Nbra;			/* nbra result */
	int	NbToken_Defined;	/* Nb tokens defined in reg_expression */
	int	*Token_ID;		/* Tokens place (index) in input value */
} Reg_Map;

/*
 * Tokens definition, including input attribute and number of expressions
 * and link to each rule.
 */
typedef struct _tokens_def {
	int	attr_ID;		/* Attributes ID (in SD or FE Table) */
					/* Used as input in regular expression */
	int	NbRules;		/* Number of expressions seperated by | */
	Reg_Map	**TokenRules;		/* Array of tokens rules */
} Token_Def;

/*
 * Attribute mapping definition. SD attributes are composed of FE attributes and
 * SD tokens. 
 */
typedef struct _attr_mapping {
	char		*AttrName;		/* Attribute Name */
	char		*Expr;			/* Value expression */
	int		AttrStatus;		/* Store several attr's info such as */
						/* Key || Exist || Frozen */
						/* Key is used to generate wizard filter */
						/* Exist is used to generate wizard filter */
						/* Frozen is used control access on attribute */
	int		NbItem;			/* Nb Attributes & Tokens need to build val */
	int		*AttrID;		/* Set of attributes including tokens */
} Attr_Mapping;

/*
 * Builder_map : defined builder expression 
 */
typedef struct _builder_map {
	char		*build_exp;		/* the sentence to build */
	int		NbInput;
	int		*Input_ID;		/* List of attr ID to used as input in semtence */
}Builder_map;
 
/*
 * Data used for split/string2instances/instances2string/exclude functions
 */
typedef struct _builder_fct {
        int             Input_ID;
	char		*value;		/* input data						*/
        char            *prefix;	/* string2instances and reverse : prefix	  	*/
					/* exclude		        : val 2 exclude		*/
	int		Parm_ID;	/* only for exclude funct       : ID of val 2 exclude	*/
        char            *suffix;
        char            *separator;
	int		readIndicator;
} Builder_fct;

/* 
 * Builder tokens : used to build special value (named builder token) from other tokens
 * or input value. They look like ouput attributes, but they allow to apply rules, if
 * input value does exist. They also permit to split input sentence into attribute instances
 */
typedef struct _builder {
        char		*builder_name;
	int		builder_ID;
	int		NbRules;
	int		BuilderType;
	Builder_map	*Mapp;
	Builder_fct     *Fct;
} Build_def;


/*
 * Full definition of table mapping.
 */
typedef struct _table_mapping {
	int		NbTokens;		/* Nb extract tokens defined */
	int		NbAttributes;		/* Nb attributes in the entry */
	int		NbBuilder;		/* Nb builder tokens defined */
	Token_Def	**Tokens_list;		/* Array of tokens needed for translation */
	Build_def	*Build_list;		/* Array of builder tokens */
	Attr_Mapping	**Attr_list;		/* Array of Attributes defined in an entry */
} Table_Mapping;

typedef struct _custo_info {
	char			*InfoName;
	int			NbValues;
	char			**Values;	/* Null terminated array of instance */
} Cust_Info;

typedef struct _sds_com {
	LDAP		*lhd;			/* LDAP communication handle */
	char		**fe_object_list;	/* Array of ObjectClasses (null term list) */
} SDS_Com;

typedef struct _dynrule {
	char	*ResName;			/* Result (or Rule) name			*/
	int	opType;				/* Extrac, Cond, split, str2ins, ins2str,	*/
						/* getrdn, exclude				*/
	int	NbExpr;				/* Nb rules found use only in extract & cond	*/
	int	*NbItems;			/* Nb variable in expression, usefull for	*/
						/* extract and cond. IT's a null terminated	*/
						/* array which contains the Number of var in  	*/
	char	**Expression;			/* The sentence	(make sense only in cond)     	*/
	char	**ConstVal;			/* use when funct parm are const not used for	*/
						/* extract and cond cases			*/
	char	**VarName;			/* Var can be 1)DynRule 2)InputData 3)Common	*/
} DynRule;

typedef struct _fe_table {
	char		*fe_section;		/* Section table name				*/
	int		nb_fe_attr;		/* Nb FE attributes defined			*/
	int		nb_sds_attr;		/* Nb SDS attributes defined			*/
	int		nb_fe_tokens;		/* Nb tokens defined in FE section		*/
	int		nb_sds_tokens;		/* Nb tokens defined in SunDS section		*/ 
	int		nb_cust;		/* Nb custom attributes in common section	*/ 
	int		nb_fe_build;		/* Nb tokens build in FE section		*/
	int		nb_sds_build;		/* Nb tokens build in SUNDS section		*/
	int		nb_dyn_rules;		/* Nb dynamic rules in Dynamic section		*/
	char		**fe_token_list;	/* Array of FE token				*/
	char		**sds_token_list;	/* List of SunDS token				*/
	char		**fe_attr_list;		/* Array of attributes (null term list)		*/
	char		**sds_attr_list;	/* Array of attributes (null term list)		*/
	char		**fe_build_list;	/* Array of FE build				*/
	char		**sds_build_list;	/* List of SunDS build				*/
	Table_Mapping	*sds_schema;		/* SDS attributes definition			*/
	Table_Mapping	*fe_schema;		/* FE attributes definition			*/
	SDS_Com		*comm_items;		/* Communication attributes			*/
	Cust_Info	**custo_info;		/* Customs info					*/
	DynRule		*dyn_rules;		/* Ordered dynamic rules			*/
} FE_Table;

typedef struct _fe_context {
	char		*fe_name;		/* Is it really usefull ?? */
	int		NbSection;		/* Nb section */
	int		NbGlobals;		/* Nb global customs info */
	Cust_Info	**globals;		/* Customs info */
	FE_Table	**fe_section_list;	/* All sub-section in mapping file */
} FE_Context;

/* Entries values definition */
/* Instance values definition */
typedef struct _fe_values {
	int	Length;
	void	*Val;
} FE_Values;

/* Attribute value definition */
typedef struct _fe_attr {
	char		*AttrType;
	int		NbInstance;
	FE_Values	**ValInstances;
} FE_Attr;

/* Full entry definition */
typedef struct _fe_entry {
	char	*DN;
	int	Nb_items;
	FE_Attr	**AttributesArray;
} FE_Entry;

typedef struct _fe_couple {
	char	*Value2Subst;
	char	*SubstValue;
} FE_Couple;

/*
 * libfe.a exported functions 
 */

/*
 * Read config file and create "fe_name" context
 * NB : This init read all tables mapping
 * libldap context use : before all action
 */
extern FE_Context	*fe_ctx_init(char *config_path, char *fe_name);

/*
 * Free All fe context all tables ...
 * libldap context usage : ldap_close
 */
extern int		fe_ctx_free(FE_Context **Ctx);

/*
 * Return the pointer to requested item in context 
 * libldap context usage : before all action
 */
extern void		 *fe_ctx_get(FE_Context *Ctx, int FieldID, void *Value);

/*
 * Search for information from Subsection/Table ? 
 * You can check also Get/Table/Paragraph
 * libldap context usage : ldap_*
 */
extern void		 *fe_table_get(FE_Table *MapTable, int FieldID, void *Void);

/*
 * Set tables item is mainly used for communication items. other information 
 * sets will be forbid
 * libldap context usage : after ldap_open or ldap_bind
 */ 
/*
extern int		  fe_table_set(FE_Table *MapTable, int FieldID, void *Void);
*/
/*
 * You have the attribute name ?! fe_ent_get_attr returns pointer to the requested
 * attributes with instances, status... from a specific entry
 * libldap context usage : after ldap_search
 */
extern FE_Attr		 *fe_ent_get_attr(FE_Table *MapTable, FE_Entry *fe_item, char *AttrName);

/*
 * Create the entry according to the "schema" defined in mapping file for a specific table
 * libladp context usage : before ldap_add
 */
extern FE_Entry		 *fe_ent_create(FE_Table *MapTable, int TableType);

/*
 * Add new attributes in a new entry
 * libladp context usage : before ldap_add
 */
extern FE_Attr           *fe_ent_get_attr(FE_Table *MapTable,FE_Entry *Entry, char *AttrName);

/*
 * Add new instance value 
 * libladp context usage : before ldap_add
 */
extern int		  fe_ent_add_val(FE_Table *MapTable, FE_Attr *attr, int ValLength, void *Val);
extern  FE_Attr		  *fe_ent_add_attr_val(FE_Table *MapTable, FE_Entry *Entry, char *AttrName, int ValLength, void *Val);

/*
 * explode DN into an attributes array 
 * libladp context usage : after ldap_search
 */
extern FE_Attr		**fe_ent_show_dn(FE_Table *MapTable, FE_Entry *Entry);

/*
 *  free entry (including attributes) 
 */
extern void		  fe_ent_free(FE_Entry **Entry);

/*
 * Substitute all vars defined in inputString (with syntax ${varName}) by values found in 
 * fe_couple array. For errors returned check the errors consts upper
 */
extern int		fe_subst(char *inputString, char **outputString, FE_Couple **fe_couple);

/*
 * Split a sentence, add prefix (for each token) and suffix (exept for the last)
 */
extern char		*fe_split(char *inputData, char *Separator, char *Prefix, char *Suffix, int  way );

/* 
 * Dynamic translation, use only definition in dynamic section 
 */
extern char		**fe_dynamic(FE_Table *MapTable, char *Var2stop, char **DynVal);

/*
 * Return the translated attribute. TableType is the original table of AttrName.
 * if translation rules is one to one translation, the function return a copy of translated 
 * attribute name.
 * else the function return a copy of the rules 
 */ 
extern char		**fe_trans_attrName(FE_Table *MapTable, char *AttrName, int TableType);
extern int		*fe_trans_attrID(FE_Table *MapTable, char *AttrName, int TableType);

/*	
 * Return the translated SD entry 
 * libladp context usage : after ldap_search
 */
extern FE_Entry		 *fe_trans_all_sds2fe(FE_Table *MapTable, LDAP *ld, LDAPMessage *sd_entry);

/*
 * Return the translated FE entry
 * libladp context usage : after ldap_search
 */ 
extern LDAPMod		 **fe_trans_all_fe2sds(FE_Table *MapTable, LDAP *ld, FE_Entry *fe_entry);

/*	
 * Close to "fe_trans_all_sds2fe" but output is Entry pointer as defined in SunDS server
 */
extern FE_Entry		*fe_trans_all_sunds2fe(FE_Table *MapTable, Entry *sd_entry);
extern Entry		*fe_trans_all_fe2sunds(FE_Table *MapTable, FE_Entry *fe_entry);

/* An example an example ....
 * Translation from fe to sunds 
 *
 * FE_Context      *MyContext = NULL;
 * FE_Table        *HostTable = NULL;
 * FE_Entry        *fe_entry = NULL;
 * FE_Attr         *fe_attr = NULL;
 * Entry           *lentry = NULL;
 *
 * if((MyContext = fe_ctx_init("..../sunds_map.conf","NIS")) == NULL){
 *	ldaplog(LDAP_DEBUG_CONFIG,"Can't load mapping file\n", 0, 0, 0);
 *	exit(1);
 * }
 * if((HostTable = fe_ctx_get(MyContext,CTX_TABLEPTR,"dummy")) == NULL) 
 * {
 *	ldaplog(LDAP_DEBUG_CONFIG,"Can't retreive HOSTS table\n", 0, 0, 0);
 *	exit(1);
 * } 
 * if((fe_entry = fe_ent_create(HostTable, FETABLE))==NULL)
 * {
 *	ldaplog(LDAP_DEBUG_CONFIG,"Can't create entry\n", 0, 0, 0);
 *	exit(1);
 * }
 * if ((fe_attr = fe_ent_add_attr_val(HostTable, fe_entry, "niskey", 16, "109.107.179.131")) == NULL)
 * {
 *	ldaplog(LDAP_DEBUG_CONFIG,"Can't add attr=%s, val=%s\n", "niskey", "109.107.179.131", 0);
 *	exit(1);
 * } 
 * if((fe_attr = fe_ent_add_attr_val(HostTable, 
 *					fe_entry, 
 *					"NISVALUE", 
 *					strlen("olivaw OLIVAW oLiVaW # regis Host") +1, 
 *					"olivaw OLIVAW oLiVaW # regis Host")) == NULL)
 * {
 *	ldaplog(...);
 *	exit(1);
 * }
 * if((lentry = fe_trans_all_fe2sunds(HostTable, fe_entry)) ==NULL)
 * {
 *	ldaplog(LDAP_DEBUG_CONFIG,".... \n", 0);
 * }
 *
 */

#endif /* _FE_H */