fe.h revision 1
1N/A/*
1N/A * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
1N/A */
1N/A
1N/A#ifndef _FE_H
1N/A#define _FE_H
1N/A
1N/A/*
1N/A * Get context const . Used to retreive info in context : fe_get_ctx
1N/A * Return values depend on requested info :
1N/A */
1N/A#define CTX_FENAME 1 /* To get the Front End name */
1N/A /* return value is (char *) */
1N/A#define CTX_NBTABLE 2 /* To get the number of sub-section */
1N/A /* return value is (int *) */
1N/A#define CTX_TABLENAME 3 /* To get name(s) of sub section */
1N/A /* return value is (char **) */
1N/A#define CTX_TABLEPTR 4 /* To get the ptr to a sub section definition */
1N/A /* return value is (FE_Table *) */
1N/A /* !! This is not a copy */
1N/A#define CTX_CUSTOMS 5 /* get customs attributes */
1N/A /* third parameter is the variable name (char *) */
1N/A
1N/A/*
1N/A * Get Tables const
1N/A */
1N/A#define TABLE_NAME 1 /* table or subsection name, return value is (char *) */
1N/A /* third parms is null */
1N/A#define TABLE_OBJ_LST 2 /* object class list, return value is (char **) */
1N/A /* third parms is null */
1N/A#define TABLE_COM_HLD 3 /* stored ldap, connection return value is (LDAP *) */
1N/A#define TABLE_CUSTOMS 4 /* get customs attributes */
1N/A /* third parameter is the variable name (char *) */
1N/A /* return value is an array of string (char **) */
1N/A#define TABLE_FEATTR 5 /* to get the attribute definition. If no attribute name */
1N/A /* is provided to get the list of attributes */
1N/A /* third parms is the attribute name */
1N/A /* return a FE_Attr * if attribute name provided */
1N/A /* return a char ** (null term) if no attribute name provided */
1N/A
1N/A#define TABLE_SUNDSATTR 6 /* idem TABLE_FEATTR but for SunDS definition */
1N/A
1N/A/*
1N/A * Tokens/Attributes
1N/A */
1N/A#define FETABLE 0
1N/A#define SUNDSTABLE 1
1N/A#define SUNDSATTRLIST 2
1N/A#define SUNDSTOKENLIST 3
1N/A#define FEATTRLIST 4
1N/A#define FETOKENLIST 5
1N/A#define FEBUILDLIST 6
1N/A#define SUNDSBUILDLIST 7
1N/A
1N/A/*
1N/A * Errors consts
1N/A */
1N/A#define NOERROR 0
1N/A#define INVALID_PARMS 1
1N/A#define VALUE_NOT_FOUND 2
1N/A#define CREATE_FAILED 3
1N/A#define SYNTAX_ERROR 4
1N/A
1N/A/*
1N/A * SPLIT way
1N/A */
1N/A#define LEFT2RIGHT 0
1N/A#define RIGHT2LEFT 1
1N/A/*
1N/A * Data structures
1N/A */
1N/A
1N/A/*
1N/A * This struct is used to run regex with "reg_expression"
1N/A * and assigned values (braelist) with "token" links
1N/A * Functional schema :
1N/A * step(input,reg_expression)
1N/A * => token[0] = braslist[0]..braelist[0]
1N/A * => token[1] = braslist[1]..braelist[1]
1N/A * => ...
1N/A * => token[i] = braslist[i]..braelist[i]
1N/A */
1N/Atypedef struct _reg_mapp {
1N/A char *reg_expression; /* Compiled regular expression */
1N/A int Nbra; /* nbra result */
1N/A int NbToken_Defined; /* Nb tokens defined in reg_expression */
1N/A int *Token_ID; /* Tokens place (index) in input value */
1N/A} Reg_Map;
1N/A
1N/A/*
1N/A * Tokens definition, including input attribute and number of expressions
1N/A * and link to each rule.
1N/A */
1N/Atypedef struct _tokens_def {
1N/A int attr_ID; /* Attributes ID (in SD or FE Table) */
1N/A /* Used as input in regular expression */
1N/A int NbRules; /* Number of expressions separated by | */
1N/A Reg_Map **TokenRules; /* Array of tokens rules */
1N/A} Token_Def;
1N/A
1N/A/*
1N/A * Attribute mapping definition. SD attributes are composed of FE attributes and
1N/A * SD tokens.
1N/A */
1N/Atypedef struct _attr_mapping {
1N/A char *AttrName; /* Attribute Name */
1N/A char *Expr; /* Value expression */
1N/A int AttrStatus; /* Store several attr's info such as */
1N/A /* Key || Exist || Frozen */
1N/A /* Key is used to generate wizard filter */
1N/A /* Exist is used to generate wizard filter */
1N/A /* Frozen is used control access on attribute */
1N/A int NbItem; /* Nb Attributes & Tokens need to build val */
1N/A int *AttrID; /* Set of attributes including tokens */
1N/A} Attr_Mapping;
1N/A
1N/A/*
1N/A * Builder_map : defined builder expression
1N/A */
1N/Atypedef struct _builder_map {
1N/A char *build_exp; /* the sentence to build */
1N/A int NbInput;
1N/A int *Input_ID; /* List of attr ID to used as input in semtence */
1N/A}Builder_map;
1N/A
1N/A/*
1N/A * Data used for split/string2instances/instances2string/exclude functions
1N/A */
1N/Atypedef struct _builder_fct {
1N/A int Input_ID;
1N/A char *value; /* input data */
1N/A char *prefix; /* string2instances and reverse : prefix */
1N/A /* exclude : val 2 exclude */
1N/A int Parm_ID; /* only for exclude funct : ID of val 2 exclude */
1N/A char *suffix;
1N/A char *separator;
1N/A int readIndicator;
1N/A} Builder_fct;
1N/A
1N/A/*
1N/A * Builder tokens : used to build special value (named builder token) from other tokens
1N/A * or input value. They look like ouput attributes, but they allow to apply rules, if
1N/A * input value does exist. They also permit to split input sentence into attribute instances
1N/A */
1N/Atypedef struct _builder {
1N/A char *builder_name;
1N/A int builder_ID;
1N/A int NbRules;
1N/A int BuilderType;
1N/A Builder_map *Mapp;
1N/A Builder_fct *Fct;
1N/A} Build_def;
1N/A
1N/A
1N/A/*
1N/A * Full definition of table mapping.
1N/A */
1N/Atypedef struct _table_mapping {
1N/A int NbTokens; /* Nb extract tokens defined */
1N/A int NbAttributes; /* Nb attributes in the entry */
1N/A int NbBuilder; /* Nb builder tokens defined */
1N/A Token_Def **Tokens_list; /* Array of tokens needed for translation */
1N/A Build_def *Build_list; /* Array of builder tokens */
1N/A Attr_Mapping **Attr_list; /* Array of Attributes defined in an entry */
1N/A} Table_Mapping;
1N/A
1N/Atypedef struct _custo_info {
1N/A char *InfoName;
1N/A int NbValues;
1N/A char **Values; /* Null terminated array of instance */
1N/A} Cust_Info;
1N/A
1N/Atypedef struct _sds_com {
1N/A LDAP *lhd; /* LDAP communication handle */
1N/A char **fe_object_list; /* Array of ObjectClasses (null term list) */
1N/A} SDS_Com;
1N/A
1N/Atypedef struct _dynrule {
1N/A char *ResName; /* Result (or Rule) name */
1N/A int opType; /* Extrac, Cond, split, str2ins, ins2str, */
1N/A /* getrdn, exclude */
1N/A int NbExpr; /* Nb rules found use only in extract & cond */
1N/A int *NbItems; /* Nb variable in expression, usefull for */
1N/A /* extract and cond. IT's a null terminated */
1N/A /* array which contains the Number of var in */
1N/A char **Expression; /* The sentence (make sense only in cond) */
1N/A char **ConstVal; /* use when funct parm are const not used for */
1N/A /* extract and cond cases */
1N/A char **VarName; /* Var can be 1)DynRule 2)InputData 3)Common */
1N/A} DynRule;
1N/A
1N/Atypedef struct _fe_table {
1N/A char *fe_section; /* Section table name */
1N/A int nb_fe_attr; /* Nb FE attributes defined */
1N/A int nb_sds_attr; /* Nb SDS attributes defined */
1N/A int nb_fe_tokens; /* Nb tokens defined in FE section */
1N/A int nb_sds_tokens; /* Nb tokens defined in SunDS section */
1N/A int nb_cust; /* Nb custom attributes in common section */
1N/A int nb_fe_build; /* Nb tokens build in FE section */
1N/A int nb_sds_build; /* Nb tokens build in SUNDS section */
1N/A int nb_dyn_rules; /* Nb dynamic rules in Dynamic section */
1N/A char **fe_token_list; /* Array of FE token */
1N/A char **sds_token_list; /* List of SunDS token */
1N/A char **fe_attr_list; /* Array of attributes (null term list) */
1N/A char **sds_attr_list; /* Array of attributes (null term list) */
1N/A char **fe_build_list; /* Array of FE build */
1N/A char **sds_build_list; /* List of SunDS build */
1N/A Table_Mapping *sds_schema; /* SDS attributes definition */
1N/A Table_Mapping *fe_schema; /* FE attributes definition */
1N/A SDS_Com *comm_items; /* Communication attributes */
1N/A Cust_Info **custo_info; /* Customs info */
1N/A DynRule *dyn_rules; /* Ordered dynamic rules */
1N/A} FE_Table;
1N/A
1N/Atypedef struct _fe_context {
1N/A char *fe_name; /* Is it really usefull ?? */
1N/A int NbSection; /* Nb section */
1N/A int NbGlobals; /* Nb global customs info */
1N/A Cust_Info **globals; /* Customs info */
1N/A FE_Table **fe_section_list; /* All sub-section in mapping file */
1N/A} FE_Context;
1N/A
1N/A/* Entries values definition */
1N/A/* Instance values definition */
1N/Atypedef struct _fe_values {
1N/A int Length;
1N/A void *Val;
1N/A} FE_Values;
1N/A
1N/A/* Attribute value definition */
1N/Atypedef struct _fe_attr {
1N/A char *AttrType;
1N/A int NbInstance;
1N/A FE_Values **ValInstances;
1N/A} FE_Attr;
1N/A
1N/A/* Full entry definition */
1N/Atypedef struct _fe_entry {
1N/A char *DN;
1N/A int Nb_items;
1N/A FE_Attr **AttributesArray;
1N/A} FE_Entry;
1N/A
1N/Atypedef struct _fe_couple {
1N/A char *Value2Subst;
1N/A char *SubstValue;
1N/A} FE_Couple;
1N/A
1N/A/*
1N/A * libfe.a exported functions
1N/A */
1N/A
1N/A/*
1N/A * Read config file and create "fe_name" context
1N/A * NB : This init read all tables mapping
1N/A * libldap context use : before all action
1N/A */
1N/Aextern FE_Context *fe_ctx_init(char *config_path, char *fe_name);
1N/A
1N/A/*
1N/A * Free All fe context all tables ...
1N/A * libldap context usage : ldap_close
1N/A */
1N/Aextern int fe_ctx_free(FE_Context **Ctx);
1N/A
1N/A/*
1N/A * Return the pointer to requested item in context
1N/A * libldap context usage : before all action
1N/A */
1N/Aextern void *fe_ctx_get(FE_Context *Ctx, int FieldID, void *Value);
1N/A
1N/A/*
1N/A * Search for information from Subsection/Table ?
1N/A * You can check also Get/Table/Paragraph
1N/A * libldap context usage : ldap_*
1N/A */
1N/Aextern void *fe_table_get(FE_Table *MapTable, int FieldID, void *Void);
1N/A
1N/A/*
1N/A * Set tables item is mainly used for communication items. other information
1N/A * sets will be forbid
1N/A * libldap context usage : after ldap_open or ldap_bind
1N/A */
1N/A/*
1N/Aextern int fe_table_set(FE_Table *MapTable, int FieldID, void *Void);
1N/A*/
1N/A/*
1N/A * You have the attribute name ?! fe_ent_get_attr returns pointer to the requested
1N/A * attributes with instances, status... from a specific entry
1N/A * libldap context usage : after ldap_search
1N/A */
1N/Aextern FE_Attr *fe_ent_get_attr(FE_Table *MapTable, FE_Entry *fe_item, char *AttrName);
1N/A
1N/A/*
1N/A * Create the entry according to the "schema" defined in mapping file for a specific table
1N/A * libladp context usage : before ldap_add
1N/A */
1N/Aextern FE_Entry *fe_ent_create(FE_Table *MapTable, int TableType);
1N/A
1N/A/*
1N/A * Add new attributes in a new entry
1N/A * libladp context usage : before ldap_add
1N/A */
1N/Aextern FE_Attr *fe_ent_get_attr(FE_Table *MapTable,FE_Entry *Entry, char *AttrName);
1N/A
1N/A/*
1N/A * Add new instance value
1N/A * libladp context usage : before ldap_add
1N/A */
1N/Aextern int fe_ent_add_val(FE_Table *MapTable, FE_Attr *attr, int ValLength, void *Val);
1N/Aextern FE_Attr *fe_ent_add_attr_val(FE_Table *MapTable, FE_Entry *Entry, char *AttrName, int ValLength, void *Val);
1N/A
1N/A/*
1N/A * explode DN into an attributes array
1N/A * libladp context usage : after ldap_search
1N/A */
1N/Aextern FE_Attr **fe_ent_show_dn(FE_Table *MapTable, FE_Entry *Entry);
1N/A
1N/A/*
1N/A * free entry (including attributes)
1N/A */
1N/Aextern void fe_ent_free(FE_Entry **Entry);
1N/A
1N/A/*
1N/A * Substitute all vars defined in inputString (with syntax ${varName}) by values found in
1N/A * fe_couple array. For errors returned check the errors consts upper
1N/A */
1N/Aextern int fe_subst(char *inputString, char **outputString, FE_Couple **fe_couple);
1N/A
1N/A/*
1N/A * Split a sentence, add prefix (for each token) and suffix (exept for the last)
1N/A */
1N/Aextern char *fe_split(char *inputData, char *Separator, char *Prefix, char *Suffix, int way );
1N/A
1N/A/*
1N/A * Dynamic translation, use only definition in dynamic section
1N/A */
1N/Aextern char **fe_dynamic(FE_Table *MapTable, char *Var2stop, char **DynVal);
1N/A
1N/A/*
1N/A * Return the translated attribute. TableType is the original table of AttrName.
1N/A * if translation rules is one to one translation, the function return a copy of translated
1N/A * attribute name.
1N/A * else the function return a copy of the rules
1N/A */
1N/Aextern char **fe_trans_attrName(FE_Table *MapTable, char *AttrName, int TableType);
1N/Aextern int *fe_trans_attrID(FE_Table *MapTable, char *AttrName, int TableType);
1N/A
1N/A/*
1N/A * Return the translated SD entry
1N/A * libladp context usage : after ldap_search
1N/A */
1N/Aextern FE_Entry *fe_trans_all_sds2fe(FE_Table *MapTable, LDAP *ld, LDAPMessage *sd_entry);
1N/A
1N/A/*
1N/A * Return the translated FE entry
1N/A * libladp context usage : after ldap_search
1N/A */
1N/Aextern LDAPMod **fe_trans_all_fe2sds(FE_Table *MapTable, LDAP *ld, FE_Entry *fe_entry);
1N/A
1N/A/*
1N/A * Close to "fe_trans_all_sds2fe" but output is Entry pointer as defined in SunDS server
1N/A */
1N/Aextern FE_Entry *fe_trans_all_sunds2fe(FE_Table *MapTable, Entry *sd_entry);
1N/Aextern Entry *fe_trans_all_fe2sunds(FE_Table *MapTable, FE_Entry *fe_entry);
1N/A
1N/A/* An example an example ....
1N/A * Translation from fe to sunds
1N/A *
1N/A * FE_Context *MyContext = NULL;
1N/A * FE_Table *HostTable = NULL;
1N/A * FE_Entry *fe_entry = NULL;
1N/A * FE_Attr *fe_attr = NULL;
1N/A * Entry *lentry = NULL;
1N/A *
1N/A * if((MyContext = fe_ctx_init("..../sunds_map.conf","NIS")) == NULL){
1N/A * ldaplog(LDAP_DEBUG_CONFIG,"Can't load mapping file\n", 0, 0, 0);
1N/A * exit(1);
1N/A * }
1N/A * if((HostTable = fe_ctx_get(MyContext,CTX_TABLEPTR,"dummy")) == NULL)
1N/A * {
1N/A * ldaplog(LDAP_DEBUG_CONFIG,"Can't retreive HOSTS table\n", 0, 0, 0);
1N/A * exit(1);
1N/A * }
1N/A * if((fe_entry = fe_ent_create(HostTable, FETABLE))==NULL)
1N/A * {
1N/A * ldaplog(LDAP_DEBUG_CONFIG,"Can't create entry\n", 0, 0, 0);
1N/A * exit(1);
1N/A * }
1N/A * if ((fe_attr = fe_ent_add_attr_val(HostTable, fe_entry, "niskey", 16, "109.107.179.131")) == NULL)
1N/A * {
1N/A * ldaplog(LDAP_DEBUG_CONFIG,"Can't add attr=%s, val=%s\n", "niskey", "109.107.179.131", 0);
1N/A * exit(1);
1N/A * }
1N/A * if((fe_attr = fe_ent_add_attr_val(HostTable,
1N/A * fe_entry,
1N/A * "NISVALUE",
1N/A * strlen("olivaw OLIVAW oLiVaW # regis Host") +1,
1N/A * "olivaw OLIVAW oLiVaW # regis Host")) == NULL)
1N/A * {
1N/A * ldaplog(...);
1N/A * exit(1);
1N/A * }
1N/A * if((lentry = fe_trans_all_fe2sunds(HostTable, fe_entry)) ==NULL)
1N/A * {
1N/A * ldaplog(LDAP_DEBUG_CONFIG,".... \n", 0);
1N/A * }
1N/A *
1N/A */
1N/A
1N/A#endif /* _FE_H */
1N/A
1N/A
1N/A
1N/A