51b98ef57e37252df6b8020286b32bb8d7c097e5
[trust_router.git] / include / tr_config.h
1 /*
2  * Copyright (c) 2012, JANET(UK)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of JANET(UK) nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31  * OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34
35 #ifndef TR_CONFIG_H
36 #define TR_CONFIG_H
37
38 #include <stdio.h>
39 #include <dirent.h>
40 #include <jansson.h>
41 #include <syslog.h>
42 #include <sys/time.h>
43 #include <talloc.h>
44 #include <glib.h>
45
46 #include <tr_comm.h>
47 #include <tr_rp.h>
48 #include <tr_rp_client.h>
49 #include <tr_idp.h>
50 #include <trp_ptable.h>
51 #include <trp_internal.h>
52
53 #define TR_DEFAULT_MAX_TREE_DEPTH 12
54 #define TR_DEFAULT_TRPS_PORT 12308
55 #define TR_DEFAULT_TIDS_PORT 12309
56 #define TR_DEFAULT_MONITORING_PORT 0 /* defaults to being turned off */
57 #define TR_DEFAULT_LOG_THRESHOLD LOG_INFO
58 #define TR_DEFAULT_CONSOLE_THRESHOLD LOG_NOTICE
59 #define TR_DEFAULT_APC_EXPIRATION_INTERVAL 43200
60 #define TR_DEFAULT_TRP_CONNECT_INTERVAL 10
61 #define TR_DEFAULT_TRP_UPDATE_INTERVAL 30
62 #define TR_DEFAULT_TRP_SWEEP_INTERVAL 30
63 #define TR_DEFAULT_TID_REQ_TIMEOUT 5
64 #define TR_DEFAULT_TID_RESP_NUMER 2
65 #define TR_DEFAULT_TID_RESP_DENOM 3
66
67 /* limits on values for validations */
68 #define TR_MIN_TRP_CONNECT_INTERVAL 5
69 #define TR_MIN_TRP_SWEEP_INTERVAL 5
70 #define TR_MIN_TRP_UPDATE_INTERVAL 5
71 #define TR_MIN_CFG_POLL_INTERVAL 1
72 #define TR_MIN_CFG_SETTLING_TIME 0
73 #define TR_MIN_TID_REQ_TIMEOUT 1
74
75 #define TR_CFG_INVALID_SERIAL -1
76
77 typedef enum tr_cfg_rc {
78   TR_CFG_SUCCESS = 0,   /* No error */
79   TR_CFG_ERROR,         /* General processing error */
80   TR_CFG_BAD_PARAMS,    /* Bad parameters passed to tr_config function */
81   TR_CFG_NOPARSE,       /* Parsing error */
82   TR_CFG_NOMEM,         /* Memory allocation error */
83 } TR_CFG_RC;
84
85 typedef struct tr_cfg_internal {
86   unsigned int max_tree_depth;
87   int tids_port;
88   int trps_port;
89   int mons_port;
90   const char *hostname;
91   int log_threshold;
92   int console_threshold;
93   unsigned int cfg_poll_interval;
94   unsigned int cfg_settling_time;
95   unsigned int trp_sweep_interval;
96   unsigned int trp_update_interval;
97   unsigned int trp_connect_interval;
98   unsigned int tid_req_timeout;
99   unsigned int tid_resp_numer; /* numerator of fraction of AAA servers to wait for in unshared mode */
100   unsigned int tid_resp_denom; /* denominator of fraction of AAA servers to wait for in unshared mode */
101   TR_GSS_NAMES *monitoring_credentials;
102 } TR_CFG_INTERNAL;
103
104 /* record of files loaded for this configuration */
105 typedef struct tr_cfg_file {
106   const char *name;
107   json_int_t serial;
108 } TR_CFG_FILE;
109
110 typedef struct tr_cfg {
111   TR_CFG_INTERNAL *internal;            /* internal trust router config */
112   TR_RP_CLIENT *rp_clients;             /* locally associated RP Clients */
113   TRP_PTABLE *peers; /* TRP peer table */
114   TR_COMM_TABLE *ctable; /* communities/realms */
115   TR_AAA_SERVER *default_servers;       /* default server list */
116
117   GArray *files; /* files loaded to make this configuration */
118 } TR_CFG;
119
120 typedef struct tr_cfg_mgr {
121   TR_CFG *active;
122   TR_CFG *new;
123 } TR_CFG_MGR;
124
125 int tr_find_config_files(const char *config_dir, struct dirent ***cfg_files);
126 void tr_free_config_file_list(int n, struct dirent ***cfg_files);
127 TR_CFG_RC tr_parse_config(TR_CFG_MGR *cfg_mgr, unsigned int n_files, char **files_with_paths);
128 TR_CFG_RC tr_apply_new_config (TR_CFG_MGR *cfg_mgr);
129 TR_CFG_RC tr_cfg_validate (TR_CFG *trc);
130 TR_CFG *tr_cfg_new(TALLOC_CTX *mem_ctx);
131 TR_CFG_MGR *tr_cfg_mgr_new(TALLOC_CTX *mem_ctx);
132 void tr_cfg_free(TR_CFG *cfg);
133 void tr_cfg_mgr_free(TR_CFG_MGR *cfg);
134
135 void tr_print_config(TR_CFG *cfg);
136 void tr_print_comms(TR_COMM_TABLE *ctab);
137 void tr_print_comm_idps(TR_COMM_TABLE *ctab, TR_COMM *comm);
138 void tr_print_comm_rps(TR_COMM_TABLE *ctab, TR_COMM *comm);
139
140 /* tr_config_internal.c */
141 TR_CFG_RC tr_cfg_parse_internal(TR_CFG *trc, json_t *jint);
142 TR_CFG_RC tr_cfg_validate_internal(TR_CFG_INTERNAL *int_cfg);
143
144 /* tr_config_comms.c */
145 TR_IDP_REALM *tr_cfg_find_idp (TR_CFG *tr_cfg, TR_NAME *idp_id, TR_CFG_RC *rc);
146 TR_RP_CLIENT *tr_cfg_find_rp (TR_CFG *tr_cfg, TR_NAME *rp_gss, TR_CFG_RC *rc);
147 TR_CFG_RC tr_cfg_parse_comms (TR_CFG *trc, json_t *jcfg);
148 TR_CFG_RC tr_cfg_parse_default_servers (TR_CFG *trc, json_t *jcfg);
149
150 /* tr_config_filters.c */
151 TR_FILTER_SET *tr_cfg_parse_filters(TALLOC_CTX *mem_ctx, json_t *jfilts, TR_CFG_RC *rc);
152
153 /* tr_config_orgs.c */
154 TR_CFG_RC tr_cfg_parse_local_orgs(TR_CFG *trc, json_t *jcfg);
155 TR_CFG_RC tr_cfg_parse_peer_orgs(TR_CFG *trc, json_t *jcfg);
156
157 /* tr_config_realms.c */
158 TR_IDP_REALM *tr_cfg_parse_idp_realms(TALLOC_CTX *mem_ctx, json_t *jrealms, TR_CFG_RC *rc);
159 TR_AAA_SERVER *tr_cfg_parse_one_aaa_server(TALLOC_CTX *mem_ctx, json_t *jaddr, TR_CFG_RC *rc);
160 TR_APC *tr_cfg_parse_apcs(TALLOC_CTX *mem_ctx, json_t *japcs, TR_CFG_RC *rc);
161
162 /* tr_config_rp_clients.c */
163 TR_RP_CLIENT *tr_cfg_parse_rp_clients(TALLOC_CTX *mem_ctx, json_t *jrealms, TR_CFG_RC *rc);
164 TR_CFG_RC tr_cfg_parse_gss_names(TALLOC_CTX *mem_ctx, json_t *jgss_names, TR_GSS_NAMES **gssn_out);
165
166 /* tr_config_encoders.c */
167 json_t *tr_cfg_files_to_json_array(TR_CFG *cfg);
168
169 #endif