Wed Jan 8 2020 09:50:19

Asterisk developer's documentation


res_security_log.c File Reference

Security Event Logging. More...

Go to the source code of this file.

Enumerations

enum  ie_required { NOT_REQUIRED, REQUIRED, NOT_REQUIRED, REQUIRED }
 

Functions

static void __init_security_event_buf (void)
 
static void __reg_module (void)
 
static void __unreg_module (void)
 
static void append_ie (struct ast_str **str, const struct ast_event *event, const enum ast_event_ie_type ie_type, enum ie_required required)
 
static void append_ies (struct ast_str **str, const struct ast_event *event, const struct ast_security_event_ie_type *ies, enum ie_required required)
 
 ASTERISK_FILE_VERSION (__FILE__,"$Revision: 398102 $")
 
static int ie_is_present (const struct ast_event *event, const enum ast_event_ie_type ie_type)
 
static int load_module (void)
 
static void security_event_cb (const struct ast_event *event, void *data)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Security Event Logging" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static struct ast_module_infoast_module_info = &__mod_info
 
static int LOG_SECURITY
 
static const char LOG_SECURITY_NAME [] = "SECURITY"
 
static struct ast_threadstorage security_event_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_security_event_buf , .custom_init = NULL , }
 
static const size_t SECURITY_EVENT_BUF_INIT_LEN = 256
 
static struct ast_event_subsecurity_event_sub
 

Detailed Description

Security Event Logging.

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

Make informational security events optional

Escape quotes in string payload IE contents

Definition in file res_security_log.c.

Enumeration Type Documentation

Enumerator
NOT_REQUIRED 
REQUIRED 
NOT_REQUIRED 
REQUIRED 

Definition at line 54 of file res_security_log.c.

Function Documentation

static void __init_security_event_buf ( void  )
static

Definition at line 51 of file res_security_log.c.

54 {
static void __reg_module ( void  )
static

Definition at line 169 of file res_security_log.c.

static void __unreg_module ( void  )
static

Definition at line 169 of file res_security_log.c.

static void append_ie ( struct ast_str **  str,
const struct ast_event event,
const enum ast_event_ie_type  ie_type,
enum ie_required  required 
)
static

Definition at line 65 of file res_security_log.c.

References ast_assert, ast_event_get_ie_bitflags(), ast_event_get_ie_pltype(), ast_event_get_ie_str(), ast_event_get_ie_type_name(), ast_event_get_ie_uint(), AST_EVENT_IE_PLTYPE_BITFLAGS, AST_EVENT_IE_PLTYPE_EXISTS, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_IE_PLTYPE_UNKNOWN, ast_log(), ast_str_append(), ie_is_present(), and LOG_WARNING.

Referenced by append_ies().

67 {
68  if (!required && !ie_is_present(event, ie_type)) {
69  /* Optional IE isn't present. Ignore. */
70  return;
71  }
72 
73  /* At this point, it _better_ be there! */
74  ast_assert(ie_is_present(event, ie_type));
75 
76  switch (ast_event_get_ie_pltype(ie_type)) {
78  ast_str_append(str, 0, ",%s=\"%u\"",
80  ast_event_get_ie_uint(event, ie_type));
81  break;
83  ast_str_append(str, 0, ",%s=\"%s\"",
85  ast_event_get_ie_str(event, ie_type));
86  break;
88  ast_str_append(str, 0, ",%s=\"%u\"",
90  ast_event_get_ie_bitflags(event, ie_type));
91  break;
95  ast_log(LOG_WARNING, "Unexpected payload type for IE '%s'\n",
97  break;
98  }
99 }
static int ie_is_present(const struct ast_event *event, const enum ast_event_ie_type ie_type)
uint32_t ast_event_get_ie_bitflags(const struct ast_event *event, enum ast_event_ie_type ie_type)
Get the value of an information element that has a bitflags payload.
Definition: event.c:1084
#define LOG_WARNING
Definition: logger.h:144
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:900
#define ast_assert(a)
Definition: utils.h:738
enum ast_event_ie_pltype ast_event_get_ie_pltype(enum ast_event_ie_type ie_type)
Get the payload type for a given information element type.
Definition: event.c:314
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
uint32_t ast_event_get_ie_uint(const struct ast_event *event, enum ast_event_ie_type ie_type)
Get the value of an information element that has an integer payload.
Definition: event.c:1075
const char * ast_event_get_ie_type_name(enum ast_event_ie_type ie_type)
Get the string representation of an information element type.
Definition: event.c:304
const char * ast_event_get_ie_str(const struct ast_event *event, enum ast_event_ie_type ie_type)
Get the value of an information element that has a string payload.
Definition: event.c:1102
static void append_ies ( struct ast_str **  str,
const struct ast_event event,
const struct ast_security_event_ie_type ies,
enum ie_required  required 
)
static

Definition at line 101 of file res_security_log.c.

References append_ie(), AST_EVENT_IE_END, and ast_security_event_ie_type::ie_type.

Referenced by security_event_cb().

103 {
104  unsigned int i;
105 
106  for (i = 0; ies[i].ie_type != AST_EVENT_IE_END; i++) {
107  append_ie(str, event, ies[i].ie_type, required);
108  }
109 }
enum ast_event_ie_type ie_type
static void append_ie(struct ast_str **str, const struct ast_event *event, const enum ast_event_ie_type ie_type, enum ie_required required)
ASTERISK_FILE_VERSION ( __FILE__  ,
"$Revision: 398102 $"   
)
static int ie_is_present ( const struct ast_event event,
const enum ast_event_ie_type  ie_type 
)
static

Definition at line 59 of file res_security_log.c.

References ast_event_get_ie_raw().

Referenced by append_ie().

61 {
62  return (ast_event_get_ie_raw(event, ie_type) != NULL);
63 }
const void * ast_event_get_ie_raw(const struct ast_event *event, enum ast_event_ie_type ie_type)
Get the value of an information element that has a raw payload.
Definition: event.c:1111
static int load_module ( void  )
static

Definition at line 137 of file res_security_log.c.

References AST_EVENT_IE_END, AST_EVENT_SECURITY, ast_event_subscribe(), ast_logger_register_level(), ast_logger_unregister_level(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_verb, LOG_SECURITY, LOG_SECURITY_NAME, and security_event_cb().

138 {
141  }
142 
144  security_event_cb, "Security Event Logger",
145  NULL, AST_EVENT_IE_END))) {
147  LOG_SECURITY = -1;
149  }
150 
151  ast_verb(3, "Security Logging Enabled\n");
152 
154 }
static struct ast_event_sub * security_event_sub
#define ast_verb(level,...)
Definition: logger.h:243
void ast_logger_unregister_level(const char *name)
Unregister a previously registered logger level.
Definition: logger.c:1670
static const char LOG_SECURITY_NAME[]
int ast_logger_register_level(const char *name)
Register a new logger level.
Definition: logger.c:1627
static void security_event_cb(const struct ast_event *event, void *data)
struct ast_event_sub * ast_event_subscribe(enum ast_event_type event_type, ast_event_cb_t cb, const char *description, void *userdata,...)
Subscribe to events.
Definition: event.c:909
static int LOG_SECURITY
static void security_event_cb ( const struct ast_event event,
void *  data 
)
static

Definition at line 111 of file res_security_log.c.

References append_ies(), ast_assert, ast_event_get_ie_type_name(), ast_event_get_ie_uint(), AST_EVENT_IE_SECURITY_EVENT, ast_log_dynamic_level, ast_security_event_get_name(), ast_security_event_get_optional_ies(), ast_security_event_get_required_ies(), AST_SECURITY_EVENT_NUM_TYPES, ast_str_buffer(), ast_str_set(), ast_str_thread_get(), LOG_SECURITY, NOT_REQUIRED, REQUIRED, security_event_buf, SECURITY_EVENT_BUF_INIT_LEN, and str.

Referenced by load_module().

112 {
113  struct ast_str *str;
114  enum ast_security_event_type event_type;
115 
118  return;
119  }
120 
121  /* Note that the event type is guaranteed to be valid here. */
123  ast_assert(event_type >= 0 && event_type < AST_SECURITY_EVENT_NUM_TYPES);
124 
125  ast_str_set(&str, 0, "%s=\"%s\"",
127  ast_security_event_get_name(event_type));
128 
129  append_ies(&str, event,
131  append_ies(&str, event,
133 
135 }
ast_security_event_type
Security event types.
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.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
#define ast_log_dynamic_level(level,...)
Send a log message to a dynamically registered log level.
Definition: logger.h:229
#define ast_assert(a)
Definition: utils.h:738
const char * str
Definition: app_jack.c:144
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.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:874
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
static const size_t SECURITY_EVENT_BUF_INIT_LEN
uint32_t ast_event_get_ie_uint(const struct ast_event *event, enum ast_event_ie_type ie_type)
Get the value of an information element that has an integer payload.
Definition: event.c:1075
const char * ast_event_get_ie_type_name(enum ast_event_ie_type ie_type)
Get the string representation of an information element type.
Definition: event.c:304
static void append_ies(struct ast_str **str, const struct ast_event *event, const struct ast_security_event_ie_type *ies, enum ie_required required)
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:669
const char * ast_security_event_get_name(const enum ast_security_event_type event_type)
Get the name of a security event sub-type.
static struct ast_threadstorage security_event_buf
static int LOG_SECURITY
static int unload_module ( void  )
static

Definition at line 156 of file res_security_log.c.

References ast_event_unsubscribe(), ast_logger_unregister_level(), ast_verb, and LOG_SECURITY_NAME.

157 {
158  if (security_event_sub) {
160  }
161 
163 
164  ast_verb(3, "Security Logging Disabled\n");
165 
166  return 0;
167 }
static struct ast_event_sub * security_event_sub
#define ast_verb(level,...)
Definition: logger.h:243
void ast_logger_unregister_level(const char *name)
Unregister a previously registered logger level.
Definition: logger.c:1670
static const char LOG_SECURITY_NAME[]
struct ast_event_sub * ast_event_unsubscribe(struct ast_event_sub *event_sub)
Un-subscribe from events.
Definition: event.c:987

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Security Event Logging" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 169 of file res_security_log.c.

Definition at line 169 of file res_security_log.c.

int LOG_SECURITY
static

Definition at line 47 of file res_security_log.c.

Referenced by load_module(), and security_event_cb().

const char LOG_SECURITY_NAME[] = "SECURITY"
static

Definition at line 45 of file res_security_log.c.

Referenced by load_module(), and unload_module().

struct ast_threadstorage security_event_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_security_event_buf , .custom_init = NULL , }
static

Definition at line 51 of file res_security_log.c.

Referenced by security_event_cb().

const size_t SECURITY_EVENT_BUF_INIT_LEN = 256
static

Definition at line 52 of file res_security_log.c.

Referenced by security_event_cb().

struct ast_event_sub* security_event_sub
static

Definition at line 49 of file res_security_log.c.