Asterisk - The Open Source Telephony Project GIT-master-1f1c5bb
Macros | Functions | Variables
tn_config.c File Reference
#include "asterisk.h"
#include <sys/stat.h>
#include "asterisk/cli.h"
#include "asterisk/module.h"
#include "asterisk/sorcery.h"
#include "stir_shaken.h"
Include dependency graph for tn_config.c:

Go to the source code of this file.

Macros

#define CONFIG_TYPE   "tn"
 
#define DEFAULT_attest_level   attest_level_NOT_SET
 
#define DEFAULT_check_tn_cert_public_url   check_tn_cert_public_url_NO
 
#define DEFAULT_private_key_file   NULL
 
#define DEFAULT_public_cert_url   NULL
 
#define DEFAULT_send_mky   send_mky_NO
 

Functions

static char * cli_tn_show (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * cli_tn_show_all (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static void * etn_alloc (const char *name)
 
 generate_sorcery_enum_from_str (generate_sorcery_enum_to_str(tn_cfg, generate_sorcery_enum_to_str(acfg_common., check_tn_cert_public_url, UNKNOWN)
 
static struct ao2_containerget_tn_all (void)
 
static int init_tn (struct tn_cfg *cfg)
 
static void * tn_alloc (const char *name)
 
static int tn_apply (const struct ast_sorcery *sorcery, void *obj)
 
int tn_config_load (void)
 
int tn_config_reload (void)
 
int tn_config_unload (void)
 
struct tn_cfgtn_get_cfg (const char *id)
 
struct tn_cfgtn_get_etn (const char *id, struct profile_cfg *eprofile)
 

Variables

static struct ast_cli_entry stir_shaken_certificate_cli []
 

Macro Definition Documentation

◆ CONFIG_TYPE

#define CONFIG_TYPE   "tn"

Definition at line 29 of file tn_config.c.

◆ DEFAULT_attest_level

#define DEFAULT_attest_level   attest_level_NOT_SET

Definition at line 34 of file tn_config.c.

◆ DEFAULT_check_tn_cert_public_url

#define DEFAULT_check_tn_cert_public_url   check_tn_cert_public_url_NO

Definition at line 31 of file tn_config.c.

◆ DEFAULT_private_key_file

#define DEFAULT_private_key_file   NULL

Definition at line 32 of file tn_config.c.

◆ DEFAULT_public_cert_url

#define DEFAULT_public_cert_url   NULL

Definition at line 33 of file tn_config.c.

◆ DEFAULT_send_mky

#define DEFAULT_send_mky   send_mky_NO

Definition at line 35 of file tn_config.c.

Function Documentation

◆ cli_tn_show()

static char * cli_tn_show ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 203 of file tn_config.c.

204{
205 struct tn_cfg *cfg;
206 struct config_object_cli_data data = {
207 .title = "TN",
208 .object_type = config_object_type_tn,
209 };
210
211 switch(cmd) {
212 case CLI_INIT:
213 e->command = "stir_shaken show tn";
214 e->usage =
215 "Usage: stir_shaken show tn <id>\n"
216 " Show the settings for a given TN\n";
217 return NULL;
218 case CLI_GENERATE:
219 if (a->pos == 3) {
221 } else {
222 return NULL;
223 }
224 }
225
226 if (a->argc != 4) {
227 return CLI_SHOWUSAGE;
228 }
229
230 cfg = tn_get_cfg(a->argv[3]);
231 config_object_cli_show(cfg, a, &data, 0);
232 ao2_cleanup(cfg);
233
234 return CLI_SUCCESS;
235}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define CLI_SHOWUSAGE
Definition: cli.h:45
#define CLI_SUCCESS
Definition: cli.h:44
@ CLI_INIT
Definition: cli.h:152
@ CLI_GENERATE
Definition: cli.h:153
int config_object_cli_show(void *obj, void *arg, void *data, int flags)
Output configuration settings to the Asterisk CLI.
char * config_object_tab_complete_name(const char *word, struct ao2_container *container)
Tab completion for name matching with STIR/SHAKEN CLI commands.
@ config_object_type_tn
#define NULL
Definition: resample.c:96
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
TN configuration for stir/shaken.
static struct test_val a
static struct ao2_container * get_tn_all(void)
Definition: tn_config.c:42
struct tn_cfg * tn_get_cfg(const char *id)
Definition: tn_config.c:37

References a, ao2_cleanup, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, config_object_cli_show(), config_object_tab_complete_name(), config_object_type_tn, get_tn_all(), NULL, config_object_cli_data::title, tn_get_cfg(), and ast_cli_entry::usage.

◆ cli_tn_show_all()

static char * cli_tn_show_all ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 167 of file tn_config.c.

168{
169 struct ao2_container *container;
170 struct config_object_cli_data data = {
171 .title = "TN",
172 .object_type = config_object_type_tn,
173 };
174
175 switch(cmd) {
176 case CLI_INIT:
177 e->command = "stir_shaken show tns";
178 e->usage =
179 "Usage: stir_shaken show tns\n"
180 " Show all attestation TNs\n";
181 return NULL;
182 case CLI_GENERATE:
183 return NULL;
184 }
185
186 if (a->argc != 3) {
187 return CLI_SHOWUSAGE;
188 }
189
192 ast_cli(a->fd, "No stir/shaken TNs found\n");
194 return CLI_SUCCESS;
195 }
196
198 ao2_ref(container, -1);
199
200 return CLI_SUCCESS;
201}
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define ao2_callback_data(container, flags, cb_fn, arg, data)
Definition: astobj2.h:1723
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
@ OBJ_NODATA
Definition: astobj2.h:1044
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
struct ao2_container * container
Definition: res_fax.c:501
Generic container type.

References a, ao2_callback_data, ao2_cleanup, ao2_container_count(), ao2_ref, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, config_object_cli_show(), config_object_type_tn, container, get_tn_all(), NULL, OBJ_NODATA, config_object_cli_data::title, and ast_cli_entry::usage.

◆ etn_alloc()

static void * etn_alloc ( const char *  name)
static

Definition at line 100 of file tn_config.c.

101{
102 struct tn_cfg *cfg;
103
104 cfg = ao2_alloc_options(sizeof(*cfg), tn_destructor, AO2_ALLOC_OPT_LOCK_NOLOCK);
105 if (!cfg) {
106 return NULL;
107 }
108
109 if (init_tn(cfg) != 0) {
110 ao2_cleanup(cfg);
111 cfg = NULL;
112 }
113 return cfg;
114}
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:404
static int init_tn(struct tn_cfg *cfg)
Definition: tn_config.c:65

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_cleanup, init_tn(), and NULL.

Referenced by tn_get_etn().

◆ generate_sorcery_enum_from_str()

generate_sorcery_enum_from_str ( generate_sorcery_enum_to_str tn_cfg,
generate_sorcery_enum_to_str acfg_common.,
check_tn_cert_public_url  ,
UNKNOWN   
)

Definition at line 48 of file tn_config.c.

58{
59 struct tn_cfg *cfg = obj;
60
63}
void acfg_cleanup(struct attestation_cfg_common *acfg_common)
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:374
struct attestation_cfg_common acfg_common

References acfg_cleanup(), tn_cfg::acfg_common, and ast_string_field_free_memory.

◆ get_tn_all()

static struct ao2_container * get_tn_all ( void  )
static

Definition at line 42 of file tn_config.c.

43{
46}
struct ast_sorcery * get_sorcery(void)
Retrieve the stir/shaken sorcery context.
Definition: common_config.c:34
@ AST_RETRIEVE_FLAG_MULTIPLE
Return all matching objects.
Definition: sorcery.h:120
@ AST_RETRIEVE_FLAG_ALL
Perform no matching, return all objects.
Definition: sorcery.h:123
void * ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields)
Retrieve an object or multiple objects using specific fields.
Definition: sorcery.c:1897
#define CONFIG_TYPE
Definition: tn_config.c:29

References AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_FLAG_MULTIPLE, ast_sorcery_retrieve_by_fields(), CONFIG_TYPE, get_sorcery(), and NULL.

Referenced by cli_tn_show(), and cli_tn_show_all().

◆ init_tn()

static int init_tn ( struct tn_cfg cfg)
static

Definition at line 65 of file tn_config.c.

66{
67 if (ast_string_field_init(cfg, 1024)) {
68 return -1;
69 }
70
71 /*
72 * The memory for the commons actually comes from cfg
73 * due to the weirdness of the STRFLDSET macro used with
74 * sorcery. We just use a token amount of memory in
75 * this call so the initialize doesn't fail.
76 */
77 if (ast_string_field_init(&cfg->acfg_common, 8)) {
78 return -1;
79 }
80
81 return 0;
82}
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359

References tn_cfg::acfg_common, and ast_string_field_init.

Referenced by etn_alloc(), and tn_alloc().

◆ tn_alloc()

static void * tn_alloc ( const char *  name)
static

Definition at line 84 of file tn_config.c.

85{
86 struct tn_cfg *cfg;
87
88 cfg = ast_sorcery_generic_alloc(sizeof(*cfg), tn_destructor);
89 if (!cfg) {
90 return NULL;
91 }
92
93 if (init_tn(cfg) != 0) {
94 ao2_cleanup(cfg);
95 cfg = NULL;
96 }
97 return cfg;
98}
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
Definition: sorcery.c:1728

References ao2_cleanup, ast_sorcery_generic_alloc(), init_tn(), and NULL.

Referenced by tn_config_load().

◆ tn_apply()

static int tn_apply ( const struct ast_sorcery sorcery,
void *  obj 
)
static

Definition at line 154 of file tn_config.c.

155{
156 struct tn_cfg *cfg = obj;
157 const char *id = ast_sorcery_object_get_id(cfg);
158 int rc = 0;
159
160 if (as_check_common_config(id, &cfg->acfg_common) != 0) {
161 return -1;
162 }
163
164 return rc;
165}
int as_check_common_config(const char *id, struct attestation_cfg_common *acfg_common)
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2317

References tn_cfg::acfg_common, as_check_common_config(), and ast_sorcery_object_get_id().

Referenced by tn_config_load().

◆ tn_config_load()

int tn_config_load ( void  )

Definition at line 258 of file tn_config.c.

259{
260 struct ast_sorcery *sorcery = get_sorcery();
261
262 ast_sorcery_apply_default(sorcery, CONFIG_TYPE, "config", "stir_shaken.conf,criteria=type=tn");
263
265 NULL, tn_apply)) {
266 ast_log(LOG_ERROR, "stir/shaken - failed to register '%s' sorcery object\n", CONFIG_TYPE);
268 }
269
271 OPT_NOOP_T, 0, 0);
272
274
276
279
281}
#define ast_log
Definition: astobj2.c:42
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
#define register_common_attestation_fields(sorcery, object, CONFIG_TYPE, nodoc)
@ OPT_NOOP_T
Type for a default handler that should do nothing.
#define LOG_ERROR
@ 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
static struct ast_sorcery * sorcery
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
Definition: sorcery.h:837
void ast_sorcery_load_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to load persistent objects.
Definition: sorcery.c:1393
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
Definition: sorcery.h:955
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition: sorcery.h:476
Full structure for sorcery.
Definition: sorcery.c:230
static struct ast_cli_entry stir_shaken_certificate_cli[]
Definition: tn_config.c:238
static void * tn_alloc(const char *name)
Definition: tn_config.c:84
static int tn_apply(const struct ast_sorcery *sorcery, void *obj)
Definition: tn_config.c:154
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_cli_register_multiple, ast_log, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_sorcery_apply_default, ast_sorcery_load_object(), ast_sorcery_object_field_register, ast_sorcery_object_register, CONFIG_TYPE, get_sorcery(), LOG_ERROR, NULL, OPT_NOOP_T, register_common_attestation_fields, sorcery, stir_shaken_certificate_cli, tn_alloc(), and tn_apply().

Referenced by common_config_load().

◆ tn_config_reload()

int tn_config_reload ( void  )

Definition at line 243 of file tn_config.c.

244{
245 struct ast_sorcery *sorcery = get_sorcery();
248}
void ast_sorcery_force_reload_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to reload persistent objects even if no changes determin...
Definition: sorcery.c:1457

References AST_MODULE_LOAD_SUCCESS, ast_sorcery_force_reload_object(), CONFIG_TYPE, get_sorcery(), and sorcery.

Referenced by common_config_reload().

◆ tn_config_unload()

int tn_config_unload ( void  )

Definition at line 250 of file tn_config.c.

251{
254
255 return 0;
256}
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30

References ARRAY_LEN, ast_cli_unregister_multiple(), and stir_shaken_certificate_cli.

Referenced by common_config_unload().

◆ tn_get_cfg()

struct tn_cfg * tn_get_cfg ( const char *  id)

Definition at line 37 of file tn_config.c.

38{
40}
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853

References ast_sorcery_retrieve_by_id(), CONFIG_TYPE, and get_sorcery().

Referenced by cli_tn_show().

◆ tn_get_etn()

struct tn_cfg * tn_get_etn ( const char *  id,
struct profile_cfg eprofile 
)

Definition at line 116 of file tn_config.c.

117{
118 RAII_VAR(struct tn_cfg *, tn,
121 struct tn_cfg *etn = etn_alloc(id);
122 int rc = 0;
123
124 if (!tn || !eprofile || !etn) {
125 ao2_cleanup(etn);
126 return NULL;
127 }
128
129 /* Initialize with the acfg from the eprofile first */
130 rc = as_copy_cfg_common(id, &etn->acfg_common,
131 &eprofile->acfg_common);
132 if (rc != 0) {
133 ao2_cleanup(etn);
134 return NULL;
135 }
136
137 /* Overwrite with anything in the TN itself */
138 rc = as_copy_cfg_common(id, &etn->acfg_common,
139 &tn->acfg_common);
140 if (rc != 0) {
141 ao2_cleanup(etn);
142 return NULL;
143 }
144
145 /*
146 * Unlike profile, we're not going to actually add a
147 * new object to sorcery because, although unlikely,
148 * the same TN could be used with multiple profiles.
149 */
150
151 return etn;
152}
int as_copy_cfg_common(const char *id, struct attestation_cfg_common *cfg_dst, struct attestation_cfg_common *cfg_src)
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
struct attestation_cfg_common acfg_common
static void * etn_alloc(const char *name)
Definition: tn_config.c:100
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941

References profile_cfg::acfg_common, tn_cfg::acfg_common, ao2_cleanup, as_copy_cfg_common(), ast_sorcery_retrieve_by_id(), CONFIG_TYPE, etn_alloc(), get_sorcery(), NULL, RAII_VAR, and S_OR.

Referenced by ast_stir_shaken_as_ctx_create().

Variable Documentation

◆ stir_shaken_certificate_cli

struct ast_cli_entry stir_shaken_certificate_cli[]
static
Initial value:
= {
{ .handler = cli_tn_show , .summary = "Show stir/shaken TN configuration by id" ,},
{ .handler = cli_tn_show_all , .summary = "Show all stir/shaken attestation TN configurations" ,},
}
static char * cli_tn_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: tn_config.c:203
static char * cli_tn_show_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: tn_config.c:167

Definition at line 238 of file tn_config.c.

Referenced by tn_config_load(), and tn_config_unload().