Wed Apr 6 11:30:09 2011

Asterisk developer's documentation


res_security_log.c File Reference

Security Event Logging. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/logger.h"
#include "asterisk/event.h"
#include "asterisk/threadstorage.h"
#include "asterisk/strings.h"
#include "asterisk/security_events.h"

Go to the source code of this file.

Enumerations

enum  ie_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: 206021 $")
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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .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 <russell@digium.com>
Todo:
Make informational security events optional

Escape quotes in string payload IE contents

Definition in file res_security_log.c.


Enumeration Type Documentation

enum ie_required

Enumerator:
NOT_REQUIRED 
REQUIRED 

Definition at line 50 of file res_security_log.c.

00050                  {
00051    NOT_REQUIRED,
00052    REQUIRED
00053 };


Function Documentation

static void __init_security_event_buf ( void   )  [static]

Definition at line 47 of file res_security_log.c.

00050 {

static void __reg_module ( void   )  [static]

Definition at line 163 of file res_security_log.c.

static void __unreg_module ( void   )  [static]

Definition at line 163 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 61 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(), LOG_WARNING, and str.

Referenced by append_ies().

00063 {
00064    if (!required && !ie_is_present(event, ie_type)) {
00065       /* Optional IE isn't present.  Ignore. */
00066       return;
00067    }
00068 
00069    /* At this point, it _better_ be there! */
00070    ast_assert(ie_is_present(event, ie_type));
00071 
00072    switch (ast_event_get_ie_pltype(ie_type)) {
00073    case AST_EVENT_IE_PLTYPE_UINT:
00074       ast_str_append(str, 0, ",%s=\"%u\"",
00075             ast_event_get_ie_type_name(ie_type),
00076             ast_event_get_ie_uint(event, ie_type));
00077       break;
00078    case AST_EVENT_IE_PLTYPE_STR:
00079       ast_str_append(str, 0, ",%s=\"%s\"",
00080             ast_event_get_ie_type_name(ie_type),
00081             ast_event_get_ie_str(event, ie_type));
00082       break;
00083    case AST_EVENT_IE_PLTYPE_BITFLAGS:
00084       ast_str_append(str, 0, ",%s=\"%u\"",
00085             ast_event_get_ie_type_name(ie_type),
00086             ast_event_get_ie_bitflags(event, ie_type));
00087       break;
00088    case AST_EVENT_IE_PLTYPE_UNKNOWN:
00089    case AST_EVENT_IE_PLTYPE_EXISTS:
00090    case AST_EVENT_IE_PLTYPE_RAW:
00091       ast_log(LOG_WARNING, "Unexpected payload type for IE '%s'\n",
00092             ast_event_get_ie_type_name(ie_type));
00093       break;
00094    }
00095 }

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 97 of file res_security_log.c.

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

Referenced by security_event_cb().

00099 {
00100    unsigned int i;
00101 
00102    for (i = 0; ies[i].ie_type != AST_EVENT_IE_END; i++) {
00103       append_ie(str, event, ies[i].ie_type, required);
00104    }
00105 }

ASTERISK_FILE_VERSION ( __FILE__  ,
"$Revision: 206021 $"   
)

static int ie_is_present ( const struct ast_event event,
const enum ast_event_ie_type  ie_type 
) [static]

Definition at line 55 of file res_security_log.c.

References ast_event_get_ie_raw().

Referenced by append_ie().

00057 {
00058    return (ast_event_get_ie_raw(event, ie_type) != NULL);
00059 }

static int load_module ( void   )  [static]

Definition at line 133 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, security_event_cb(), and security_event_sub.

00134 {
00135    if ((LOG_SECURITY = ast_logger_register_level(LOG_SECURITY_NAME)) == -1) {
00136       return AST_MODULE_LOAD_DECLINE;
00137    }
00138 
00139    if (!(security_event_sub = ast_event_subscribe(AST_EVENT_SECURITY,
00140          security_event_cb, "Security Event Logger",
00141          NULL, AST_EVENT_IE_END))) {
00142       ast_logger_unregister_level(LOG_SECURITY_NAME);
00143       LOG_SECURITY = -1;
00144       return AST_MODULE_LOAD_DECLINE;
00145    }
00146 
00147    ast_verb(3, "Security Logging Enabled\n");
00148 
00149    return AST_MODULE_LOAD_SUCCESS;
00150 }

static void security_event_cb ( const struct ast_event event,
void *  data 
) [static]

Definition at line 107 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().

00108 {
00109    struct ast_str *str;
00110    enum ast_security_event_type event_type;
00111 
00112    if (!(str = ast_str_thread_get(&security_event_buf,
00113          SECURITY_EVENT_BUF_INIT_LEN))) {
00114       return;
00115    }
00116 
00117    /* Note that the event type is guaranteed to be valid here. */
00118    event_type = ast_event_get_ie_uint(event, AST_EVENT_IE_SECURITY_EVENT);
00119    ast_assert(event_type >= 0 && event_type < AST_SECURITY_EVENT_NUM_TYPES);
00120 
00121    ast_str_set(&str, 0, "%s=\"%s\"",
00122          ast_event_get_ie_type_name(AST_EVENT_IE_SECURITY_EVENT),
00123          ast_security_event_get_name(event_type));
00124 
00125    append_ies(&str, event,
00126          ast_security_event_get_required_ies(event_type), REQUIRED);
00127    append_ies(&str, event,
00128          ast_security_event_get_optional_ies(event_type), NOT_REQUIRED);
00129 
00130    ast_log_dynamic_level(LOG_SECURITY, "%s\n", ast_str_buffer(str));
00131 }

static int unload_module ( void   )  [static]

Definition at line 152 of file res_security_log.c.

References ast_event_unsubscribe(), ast_verb, and security_event_sub.

00153 {
00154    if (security_event_sub) {
00155       security_event_sub = ast_event_unsubscribe(security_event_sub);
00156    }
00157 
00158    ast_verb(3, "Security Logging Disabled\n");
00159 
00160    return 0;
00161 }


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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static]

Definition at line 163 of file res_security_log.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 163 of file res_security_log.c.

int LOG_SECURITY [static]

Definition at line 43 of file res_security_log.c.

Referenced by load_module(), and security_event_cb().

const char LOG_SECURITY_NAME[] = "SECURITY" [static]

Definition at line 41 of file res_security_log.c.

Referenced by load_module().

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

Definition at line 47 of file res_security_log.c.

Referenced by security_event_cb().

const size_t SECURITY_EVENT_BUF_INIT_LEN = 256 [static]

Definition at line 48 of file res_security_log.c.

Referenced by security_event_cb().

struct ast_event_sub* security_event_sub [static]

Definition at line 45 of file res_security_log.c.

Referenced by load_module(), and unload_module().


Generated on Wed Apr 6 11:30:09 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7