Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Data Structures | Macros | Functions | Variables
common_config.c File Reference
#include "asterisk.h"
#include "asterisk/cli.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
#include "asterisk/stasis.h"
#include "asterisk/security_events.h"
#include "stir_shaken.h"
Include dependency graph for common_config.c:

Go to the source code of this file.

Data Structures

struct  enum_name_xref_entry
 

Macros

#define AST_API_MODULE
 
#define generate_bool_handler_functions(param_name)
 
#define generate_enum_string_functions(param_name, default_value, ...)
 
#define print_acl_cert_store(cfg, a, max_name_len)
 

Functions

int common_config_load (void)
 
int common_config_reload (void)
 
int common_config_unload (void)
 
int config_object_cli_show (void *obj, void *arg, void *data, int flags)
 Output configuration settings to the Asterisk CLI. More...
 
char * config_object_tab_complete_name (const char *word, struct ao2_container *container)
 Tab completion for name matching with STIR/SHAKEN CLI commands. More...
 
 generate_bool_handler_functions (check_tn_cert_public_url)
 
 generate_bool_handler_functions (load_system_certs)
 
 generate_bool_handler_functions (relax_x5u_path_restrictions)
 
 generate_bool_handler_functions (relax_x5u_port_scheme_restrictions)
 
 generate_bool_handler_functions (send_mky)
 
 generate_bool_handler_functions (use_rfc9410_responses)
 
 generate_enum_string_functions (attest_level, UNKNOWN, {attest_level_A, "A"}, {attest_level_B, "B"}, {attest_level_C, "C"},)
 
 generate_enum_string_functions (endpoint_behavior, OFF, {endpoint_behavior_OFF, "off"}, {endpoint_behavior_OFF, "none"}, {endpoint_behavior_ATTEST, "attest"}, {endpoint_behavior_VERIFY, "verify"}, {endpoint_behavior_ON, "on"}, {endpoint_behavior_ON, "both"})
 
 generate_enum_string_functions (stir_shaken_failure_action, CONTINUE, {stir_shaken_failure_action_CONTINUE, "continue"}, {stir_shaken_failure_action_REJECT_REQUEST, "reject_request"}, {stir_shaken_failure_action_CONTINUE_RETURN_REASON, "continue_return_reason"},)
 
struct ast_sorceryget_sorcery (void)
 Retrieve the stir/shaken sorcery context. More...
 
static void named_acl_changed_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void print_acl (int fd, struct ast_acl_list *acl_list, const char *prefix)
 
static const char * translate_value (const char *val)
 

Variables

struct stasis_subscriptionnamed_acl_changed_sub = NULL
 
static struct ast_sorcerysorcery
 

Macro Definition Documentation

◆ AST_API_MODULE

#define AST_API_MODULE

Definition at line 28 of file common_config.c.

◆ generate_bool_handler_functions

#define generate_bool_handler_functions (   param_name)

Definition at line 39 of file common_config.c.

◆ generate_enum_string_functions

#define generate_enum_string_functions (   param_name,
  default_value,
  ... 
)

Definition at line 77 of file common_config.c.

◆ print_acl_cert_store

#define print_acl_cert_store (   cfg,
  a,
  max_name_len 
)

Definition at line 150 of file common_config.c.

Function Documentation

◆ common_config_load()

int common_config_load ( void  )

Definition at line 311 of file common_config.c.

312{
313 SCOPE_ENTER(2, "Stir Shaken Load\n");
314
315 if (!(sorcery = ast_sorcery_open())) {
317 SCOPE_EXIT_RTN_VALUE(AST_MODULE_LOAD_DECLINE, "Stir Shaken sorcery load failed\n");
318 }
319
320 if (vs_load()) {
322 SCOPE_EXIT_RTN_VALUE(AST_MODULE_LOAD_DECLINE, "Stir Shaken VS load failed\n");
323 }
324
325 if (as_load()) {
327 SCOPE_EXIT_RTN_VALUE(AST_MODULE_LOAD_DECLINE, "Stir Shaken AS load failed\n");
328 }
329
330 if (tn_config_load()) {
332 SCOPE_EXIT_RTN_VALUE(AST_MODULE_LOAD_DECLINE, "Stir Shaken TN load failed\n");
333 }
334
335 if (profile_load()) {
337 SCOPE_EXIT_RTN_VALUE(AST_MODULE_LOAD_DECLINE, "Stir Shaken profile load failed\n");
338 }
339
345 SCOPE_EXIT_RTN_VALUE(AST_MODULE_LOAD_DECLINE, "Stir Shaken acl change subscribe failed\n");
346 }
349 }
350
351 SCOPE_EXIT_RTN_VALUE(AST_MODULE_LOAD_SUCCESS, "Stir Shaken Load Done\n");
352}
struct stasis_message_type * ast_named_acl_change_type(void)
a stasis_message_type for changes against a named ACL or the set of all named ACLs
int as_load()
Load the stir/shaken attestation service.
Definition: attestation.c:436
int common_config_unload(void)
struct stasis_subscription * named_acl_changed_sub
Definition: common_config.c:32
static void named_acl_changed_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
static struct ast_sorcery * sorcery
Definition: common_config.c:31
int profile_load(void)
int tn_config_load(void)
Definition: tn_config.c:257
#define SCOPE_EXIT_RTN_VALUE(__return_value,...)
#define SCOPE_ENTER(level,...)
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
#define NULL
Definition: resample.c:96
struct stasis_topic * ast_security_topic(void)
A stasis_topic which publishes messages for security related issues.
#define ast_sorcery_open()
Open a new sorcery structure.
Definition: sorcery.h:406
int stasis_subscription_accept_message_type(struct stasis_subscription *subscription, const struct stasis_message_type *type)
Indicate to a subscription that we are interested in a message type.
Definition: stasis.c:1023
#define stasis_subscribe(topic, callback, data)
Definition: stasis.h:649
int vs_load()
Load the stir/shaken verification service.

References as_load(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_named_acl_change_type(), ast_security_topic(), ast_sorcery_open, common_config_unload(), named_acl_changed_cb(), named_acl_changed_sub, NULL, profile_load(), SCOPE_ENTER, SCOPE_EXIT_RTN_VALUE, sorcery, stasis_subscribe, stasis_subscription_accept_message_type(), tn_config_load(), and vs_load().

Referenced by load_module().

◆ common_config_reload()

int common_config_reload ( void  )

Definition at line 262 of file common_config.c.

263{
264 SCOPE_ENTER(2, "Stir Shaken Reload\n");
265 if (vs_reload()) {
266 SCOPE_EXIT_RTN_VALUE(AST_MODULE_LOAD_DECLINE, "Stir Shaken VS Reload failed\n");
267 }
268
269 if (as_reload()) {
270 SCOPE_EXIT_RTN_VALUE(AST_MODULE_LOAD_DECLINE, "Stir Shaken AS Reload failed\n");
271 }
272
273 if (tn_config_reload()) {
274 SCOPE_EXIT_RTN_VALUE(AST_MODULE_LOAD_DECLINE, "Stir Shaken TN Reload failed\n");
275 }
276
277 if (profile_reload()) {
278 SCOPE_EXIT_RTN_VALUE(AST_MODULE_LOAD_DECLINE, "Stir Shaken Profile Reload failed\n");
279 }
280
281 SCOPE_EXIT_RTN_VALUE(AST_MODULE_LOAD_SUCCESS, "Stir Shaken Reload Done\n");
282}
int as_reload()
Load the stir/shaken attestation service.
Definition: attestation.c:423
int tn_config_reload(void)
Definition: tn_config.c:242
int profile_reload(void)
int vs_reload()
Reload the stir/shaken verification service.

References as_reload(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, profile_reload(), SCOPE_ENTER, SCOPE_EXIT_RTN_VALUE, tn_config_reload(), and vs_reload().

Referenced by named_acl_changed_cb(), and reload_module().

◆ common_config_unload()

int common_config_unload ( void  )

Definition at line 284 of file common_config.c.

285{
288 as_unload();
289 vs_unload();
290
294 }
296 sorcery = NULL;
297
298 return 0;
299}
int as_unload()
Load the stir/shaken attestation service.
Definition: attestation.c:430
int profile_unload(void)
int tn_config_unload(void)
Definition: tn_config.c:249
#define ast_sorcery_unref(sorcery)
Decrease the reference count of a sorcery structure.
Definition: sorcery.h:1500
struct stasis_subscription * stasis_unsubscribe(struct stasis_subscription *subscription)
Cancel a subscription.
Definition: stasis.c:971
int vs_unload()
Unload the stir/shaken verification service.

References as_unload(), ast_sorcery_unref, named_acl_changed_sub, NULL, profile_unload(), sorcery, stasis_unsubscribe(), tn_config_unload(), and vs_unload().

Referenced by common_config_load(), and unload_module().

◆ config_object_cli_show()

int config_object_cli_show ( void *  obj,
void *  arg,
void *  data,
int  flags 
)

Output configuration settings to the Asterisk CLI.

Parameters
objA sorcery object containing configuration data
argAsterisk CLI argument object
flagsao2 container flags
Return values
0

Definition at line 171 of file common_config.c.

172{
173 struct ast_cli_args *a = arg;
174 struct config_object_cli_data *cli_data = data;
175 struct ast_variable *options;
176 struct ast_variable *i;
177 const char *title = NULL;
178 const char *cfg_name = NULL;
179 int max_name_len = 0;
180
181 if (!obj) {
182 ast_cli(a->fd, "No stir/shaken configuration found\n");
183 return 0;
184 }
185
186 if (!ast_strlen_zero(cli_data->title)) {
187 title = cli_data->title;
188 } else {
189 title = ast_sorcery_object_get_type(obj);
190 }
191 max_name_len = strlen(title);
192
194 || cli_data->object_type == config_object_type_tn) {
195 cfg_name = ast_sorcery_object_get_id(obj);
196 max_name_len += strlen(cfg_name) + 2 /* ": " */;
197 }
198
201 if (!options) {
202 return 0;
203 }
204
205 for (i = options; i; i = i->next) {
206 int nlen = strlen(i->name);
207 max_name_len = (nlen > max_name_len) ? nlen : max_name_len;
208 }
209
210 ast_cli(a->fd, "\n==============================================================================\n");
211 if (ast_strlen_zero(cfg_name)) {
212 ast_cli(a->fd, "%s\n", title);
213 } else {
214 ast_cli(a->fd, "%s: %s\n", title, cfg_name);
215 }
216 ast_cli(a->fd, "------------------------------------------------------------------------------\n");
217
218 for (i = options; i; i = i->next) {
219 if (!ast_strings_equal(i->name, "x5u_acl")) {
220 ast_cli(a->fd, "%-*s: %s\n", max_name_len, i->name,
222 }
223 }
224
226
227 if (cli_data->object_type == config_object_type_profile) {
228 struct profile_cfg *cfg = obj;
229 print_acl_cert_store(cfg, a, max_name_len);
230 } else if (cli_data->object_type == config_object_type_verification) {
231 struct verification_cfg *cfg = obj;
232 print_acl_cert_store(cfg, a, max_name_len);
233 }
234 ast_cli(a->fd, "---------------------------------------------\n\n"); \
235
236 return 0;
237}
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
static const char * translate_value(const char *val)
#define print_acl_cert_store(cfg, a, max_name_len)
struct ast_sorcery * get_sorcery(void)
Retrieve the stir/shaken sorcery context.
Definition: common_config.c:34
@ config_object_type_tn
@ config_object_type_profile
@ config_object_type_verification
struct ast_variable * ast_variable_list_sort(struct ast_variable *head)
Performs an in-place sort on the variable list by ascending name.
Definition: main/config.c:620
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1262
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2317
const char * ast_sorcery_object_get_type(const void *object)
Get the type of a sorcery object.
Definition: sorcery.c:2329
@ AST_HANDLER_ONLY_STRING
Use string handler only.
Definition: sorcery.h:137
struct ast_variable * ast_sorcery_objectset_create2(const struct ast_sorcery *sorcery, const void *object, enum ast_sorcery_field_handler_flags flags)
Create an object set (KVP list) for an object.
Definition: sorcery.c:1511
int ast_strings_equal(const char *str1, const char *str2)
Compare strings for equality checking for NULL.
Definition: strings.c:238
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
enum config_object_type object_type
Profile configuration for stir/shaken.
static struct test_options options
static struct test_val a

References a, ast_cli(), AST_HANDLER_ONLY_STRING, ast_sorcery_object_get_id(), ast_sorcery_object_get_type(), ast_sorcery_objectset_create2(), ast_strings_equal(), ast_strlen_zero(), ast_variable_list_sort(), ast_variables_destroy(), config_object_type_profile, config_object_type_tn, config_object_type_verification, get_sorcery(), ast_variable::name, ast_variable::next, NULL, config_object_cli_data::object_type, options, print_acl_cert_store, config_object_cli_data::title, translate_value(), and ast_variable::value.

Referenced by attestation_show(), cli_eprofile_show(), cli_eprofile_show_all(), cli_profile_show(), cli_profile_show_all(), cli_tn_show(), cli_tn_show_all(), and cli_verification_show().

◆ config_object_tab_complete_name()

char * config_object_tab_complete_name ( const char *  word,
struct ao2_container container 
)

Tab completion for name matching with STIR/SHAKEN CLI commands.

Parameters
wordThe word to tab complete on
containerThe sorcery container to iterate through
Return values
Thetab completion options

Definition at line 239 of file common_config.c.

240{
241 void *obj;
242 struct ao2_iterator it;
243 int wordlen = strlen(word);
244 int ret;
245
247 while ((obj = ao2_iterator_next(&it))) {
248 if (!strncasecmp(word, ast_sorcery_object_get_id(obj), wordlen)) {
250 if (ret) {
251 ao2_ref(obj, -1);
252 break;
253 }
254 }
255 ao2_ref(obj, -1);
256 }
258
259 return NULL;
260}
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ao2_iterator_next(iter)
Definition: astobj2.h:1911
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
Definition: main/cli.c:2756
short word
struct ao2_container * container
Definition: res_fax.c:501
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_cli_completion_add(), ast_sorcery_object_get_id(), ast_strdup, container, and NULL.

Referenced by cli_eprofile_show(), cli_profile_show(), and cli_tn_show().

◆ generate_bool_handler_functions() [1/6]

generate_bool_handler_functions ( check_tn_cert_public_url  )

◆ generate_bool_handler_functions() [2/6]

generate_bool_handler_functions ( load_system_certs  )

◆ generate_bool_handler_functions() [3/6]

generate_bool_handler_functions ( relax_x5u_path_restrictions  )

◆ generate_bool_handler_functions() [4/6]

generate_bool_handler_functions ( relax_x5u_port_scheme_restrictions  )

◆ generate_bool_handler_functions() [5/6]

generate_bool_handler_functions ( send_mky  )

◆ generate_bool_handler_functions() [6/6]

generate_bool_handler_functions ( use_rfc9410_responses  )

◆ generate_enum_string_functions() [1/3]

generate_enum_string_functions ( attest_level  ,
UNKNOWN  ,
{attest_level_A, "A"}  ,
{attest_level_B, "B"}  ,
{attest_level_C, "C"}   
)

◆ generate_enum_string_functions() [2/3]

generate_enum_string_functions ( endpoint_behavior  ,
OFF  ,
{endpoint_behavior_OFF, "off"}  ,
{endpoint_behavior_OFF, "none"}  ,
{endpoint_behavior_ATTEST, "attest"}  ,
{endpoint_behavior_VERIFY, "verify"}  ,
{endpoint_behavior_ON, "on"}  ,
{endpoint_behavior_ON, "both"}   
)

◆ generate_enum_string_functions() [3/3]

generate_enum_string_functions ( stir_shaken_failure_action  ,
CONTINUE  ,
{stir_shaken_failure_action_CONTINUE, "continue"}  ,
{stir_shaken_failure_action_REJECT_REQUEST, "reject_request"}  ,
{stir_shaken_failure_action_CONTINUE_RETURN_REASON, "continue_return_reason"}   
)

◆ get_sorcery()

struct ast_sorcery * get_sorcery ( void  )

◆ named_acl_changed_cb()

static void named_acl_changed_cb ( void *  data,
struct stasis_subscription sub,
struct stasis_message message 
)
static

Definition at line 301 of file common_config.c.

303{
305 return;
306 }
307 ast_log(LOG_NOTICE, "Named acl changed. Reloading verification and profile\n");
309}
#define ast_log
Definition: astobj2.c:42
int common_config_reload(void)
#define LOG_NOTICE
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.

References ast_log, ast_named_acl_change_type(), common_config_reload(), LOG_NOTICE, and stasis_message_type().

Referenced by common_config_load().

◆ print_acl()

static void print_acl ( int  fd,
struct ast_acl_list acl_list,
const char *  prefix 
)
static

Definition at line 134 of file common_config.c.

135{
136 struct ast_acl *acl;
137
138 AST_LIST_LOCK(acl_list);
139 AST_LIST_TRAVERSE(acl_list, acl, list) {
140 if (ast_strlen_zero(acl->name)) {
141 ast_cli(fd, "%s(permit/deny)\n", prefix);
142 } else {
143 ast_cli(fd, "%s%s\n", prefix, acl->name);
144 }
145 ast_ha_output(fd, acl->acl, prefix);
146 }
147 AST_LIST_UNLOCK(acl_list);
148}
void ast_ha_output(int fd, const struct ast_ha *ha, const char *prefix)
output an HA to the provided fd
Definition: acl.c:1086
static char prefix[MAX_PREFIX]
Definition: http.c:144
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:40
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:140
Definition: test_acl.c:111
an ast_acl is a linked list node of ast_ha structs which may have names.
Definition: acl.h:67
struct ast_ha * acl
Definition: acl.h:68
struct ast_acl::@180 list

References ast_acl::acl, ast_cli(), ast_ha_output(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strlen_zero(), ast_acl::list, and prefix.

◆ translate_value()

static const char * translate_value ( const char *  val)
static

Definition at line 123 of file common_config.c.

124{
125 if (val[0] == '0'
126 || val[0] == '\0'
127 || strcmp(val, "not_set") == 0) {
128 return "";
129 }
130
131 return val;
132}
Definition: ast_expr2.c:325

Referenced by config_object_cli_show().

Variable Documentation

◆ named_acl_changed_sub

struct stasis_subscription* named_acl_changed_sub = NULL

Definition at line 32 of file common_config.c.

Referenced by common_config_load(), and common_config_unload().

◆ sorcery

struct ast_sorcery* sorcery
static

Definition at line 31 of file common_config.c.

Referenced by common_config_load(), common_config_unload(), and get_sorcery().