Wed Jan 8 2020 09:50:20

Asterisk developer's documentation


security_events.h File Reference

Security Event Reporting API. More...

Go to the source code of this file.

Data Structures

struct  ast_security_event_ie_type
 

Functions

const char * ast_security_event_get_name (const enum ast_security_event_type event_type)
 Get the name of a security event sub-type. More...
 
struct ast_security_event_ie_typeast_security_event_get_optional_ies (const enum ast_security_event_type event_type)
 Get the list of optional IEs for a given security event sub-type. More...
 
struct ast_security_event_ie_typeast_security_event_get_required_ies (const enum ast_security_event_type event_type)
 Get the list of required IEs for a given security event sub-type. More...
 
int ast_security_event_report (const struct ast_security_event_common *sec)
 Report a security event. More...
 
const char * ast_security_event_severity_get_name (const enum ast_security_event_severity severity)
 Get the name of a security event severity. More...
 

Detailed Description

Security Event Reporting API.

Author
Russell Bryant russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com

Definition in file security_events.h.

Function Documentation

const char* ast_security_event_get_name ( const enum ast_security_event_type  event_type)

Get the name of a security event sub-type.

Parameters
[in]event_typesecurity event sub-type
Return values
NULLif event_type is invalid
non-NULLthe name of the security event type
Since
1.8

Definition at line 387 of file security_events.c.

References check_event_type(), and sec_events.

Referenced by security_event_cb().

388 {
389  if (check_event_type(event_type)) {
390  return NULL;
391  }
392 
393  return sec_events[event_type].name;
394 }
static struct @298 sec_events[AST_SECURITY_EVENT_NUM_TYPES]
static int check_event_type(const enum ast_security_event_type event_type)
struct ast_security_event_ie_type* ast_security_event_get_optional_ies ( const enum ast_security_event_type  event_type)

Get the list of optional IEs for a given security event sub-type.

Parameters
[in]event_typesecurity event sub-type
Return values
NULLinvalid event_type
non-NULLAn array terminated with the value AST_EVENT_IE_END
Since
1.8

Definition at line 406 of file security_events.c.

References check_event_type(), and sec_events.

Referenced by handle_security_event(), and security_event_cb().

408 {
409  if (check_event_type(event_type)) {
410  return NULL;
411  }
412 
413  return sec_events[event_type].optional_ies;
414 }
static struct @298 sec_events[AST_SECURITY_EVENT_NUM_TYPES]
static int check_event_type(const enum ast_security_event_type event_type)
struct ast_security_event_ie_type* ast_security_event_get_required_ies ( const enum ast_security_event_type  event_type)

Get the list of required IEs for a given security event sub-type.

Parameters
[in]event_typesecurity event sub-type
Return values
NULLinvalid event_type
non-NULLAn array terminated with the value AST_EVENT_IE_END
Since
1.8

Definition at line 396 of file security_events.c.

References check_event_type(), and sec_events.

Referenced by handle_security_event(), and security_event_cb().

398 {
399  if (check_event_type(event_type)) {
400  return NULL;
401  }
402 
403  return sec_events[event_type].required_ies;
404 }
static struct @298 sec_events[AST_SECURITY_EVENT_NUM_TYPES]
static int check_event_type(const enum ast_security_event_type event_type)
int ast_security_event_report ( const struct ast_security_event_common sec)

Report a security event.

Parameters
[in]secsecurity event data. Callers of this function should never declare an instance of ast_security_event_common directly. The argument should be an instance of a specific security event descriptor which has ast_security_event_common at the very beginning.
Return values
0success
non-zerofailure

Definition at line 625 of file security_events.c.

References ast_log(), AST_SECURITY_EVENT_NUM_TYPES, ast_security_event_common::event_type, handle_security_event(), LOG_ERROR, LOG_WARNING, sec_events, and ast_security_event_common::version.

Referenced by report_auth_success(), report_failed_acl(), report_failed_challenge_response(), report_inval_password(), report_invalid_user(), report_req_bad_format(), report_req_not_allowed(), and report_session_limit().

626 {
627  int res;
628 
629  if (sec->event_type < 0 || sec->event_type >= AST_SECURITY_EVENT_NUM_TYPES) {
630  ast_log(LOG_ERROR, "Invalid security event type\n");
631  return -1;
632  }
633 
634  if (!sec_events[sec->event_type].name) {
635  ast_log(LOG_WARNING, "Security event type %u not handled\n",
636  sec->event_type);
637  return -1;
638  }
639 
640  if (sec->version != sec_events[sec->event_type].version) {
641  ast_log(LOG_WARNING, "Security event %u version mismatch\n",
642  sec->event_type);
643  return -1;
644  }
645 
646  res = handle_security_event(sec);
647 
648  return res;
649 }
enum ast_security_event_type event_type
The security event sub-type.
#define LOG_WARNING
Definition: logger.h:144
uint32_t version
security event version
static struct @298 sec_events[AST_SECURITY_EVENT_NUM_TYPES]
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static int handle_security_event(const struct ast_security_event_common *sec)
const char* ast_security_event_severity_get_name ( const enum ast_security_event_severity  severity)

Get the name of a security event severity.

Parameters
[in]severitysecurity event severity
Return values
NULLif severity is invalid
non-NULLthe name of the security event severity
Since
1.8

Definition at line 363 of file security_events.c.

References ARRAY_LEN, and severities.

Referenced by alloc_event().

365 {
366  unsigned int i;
367 
368  for (i = 0; i < ARRAY_LEN(severities); i++) {
369  if (severities[i].severity == severity) {
370  return severities[i].str;
371  }
372  }
373 
374  return NULL;
375 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct @299 severities[]
enum ast_security_event_severity severity