[svn-commits] russell: branch group/security_events r199075 - in /team/group/security_event...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Thu Jun 4 10:23:15 CDT 2009
Author: russell
Date: Thu Jun 4 10:23:05 2009
New Revision: 199075
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=199075
Log:
Add a test module and fix a couple buglets
Added:
team/group/security_events/tests/test_security_events.c (with props)
Modified:
team/group/security_events/channels/chan_sip.c
team/group/security_events/include/asterisk/security_events_defs.h
team/group/security_events/main/security_events.c
team/group/security_events/res/res_security_log.c
Modified: team/group/security_events/channels/chan_sip.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/security_events/channels/chan_sip.c?view=diff&rev=199075&r1=199074&r2=199075
==============================================================================
--- team/group/security_events/channels/chan_sip.c (original)
+++ team/group/security_events/channels/chan_sip.c Thu Jun 4 10:23:05 2009
@@ -11922,8 +11922,7 @@
.transport = security_event_transport_type(pvt->socket.type),
};
- ast_security_event_report(
- (struct ast_security_event_common *) &failed_acl_event);
+ ast_security_event_report(AST_SEC_EVT(&failed_acl_event));
}
/*! \brief Parse contact header and save registration (peer registration) */
Modified: team/group/security_events/include/asterisk/security_events_defs.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/security_events/include/asterisk/security_events_defs.h?view=diff&rev=199075&r1=199074&r2=199075
==============================================================================
--- team/group/security_events/include/asterisk/security_events_defs.h (original)
+++ team/group/security_events/include/asterisk/security_events_defs.h Thu Jun 4 10:23:05 2009
@@ -62,6 +62,8 @@
AST_SECURITY_EVENT_TRANSPORT_TCP,
AST_SECURITY_EVENT_TRANSPORT_TLS,
};
+
+#define AST_SEC_EVT(e) ((struct ast_security_event_common *) e)
/*!
* \brief Common structure elements
Modified: team/group/security_events/main/security_events.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/security_events/main/security_events.c?view=diff&rev=199075&r1=199074&r2=199075
==============================================================================
--- team/group/security_events/main/security_events.c (original)
+++ team/group/security_events/main/security_events.c Thu Jun 4 10:23:05 2009
@@ -162,7 +162,7 @@
encode_timestamp(&str, tv);
- return ast_event_append_ie_str(event, ie_type, str->str);
+ return ast_event_append_ie_str(event, ie_type, ast_str_buffer(str));
}
static int add_ipv4_ie(struct ast_event **event, enum ast_event_ie_type ie_type,
@@ -189,7 +189,7 @@
ast_inet_ntoa(sin->sin_addr),
ntohs(sin->sin_port));
- return 0;
+ return ast_event_append_ie_str(event, ie_type, ast_str_buffer(str));
}
static int handle_failed_acl(const struct ast_security_event_common *sec)
Modified: team/group/security_events/res/res_security_log.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/security_events/res/res_security_log.c?view=diff&rev=199075&r1=199074&r2=199075
==============================================================================
--- team/group/security_events/res/res_security_log.c (original)
+++ team/group/security_events/res/res_security_log.c Thu Jun 4 10:23:05 2009
@@ -35,7 +35,7 @@
#include "asterisk/strings.h"
#include "asterisk/security_events.h"
-static const char LOG_SECURITY_NAME[] = "security";
+static const char LOG_SECURITY_NAME[] = "SECURITY";
static int LOG_SECURITY;
Added: team/group/security_events/tests/test_security_events.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/security_events/tests/test_security_events.c?view=auto&rev=199075
==============================================================================
--- team/group/security_events/tests/test_security_events.c (added)
+++ team/group/security_events/tests/test_security_events.c Thu Jun 4 10:23:05 2009
@@ -1,0 +1,139 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2009, Digium, Inc.
+ *
+ * Russell Bryant <russell at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Test security event generation
+ *
+ * \author Russell Bryant <russell at digium.com>
+ */
+
+/*** MODULEINFO
+ <defaultenabled>no</defaultenabled>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/cli.h"
+#include "asterisk/utils.h"
+#include "asterisk/security_events.h"
+
+static void evt_gen_failed_acl(void);
+
+typedef void (*evt_generator)(void);
+evt_generator evt_generators[AST_SECURITY_EVENT_NUM_TYPES] = {
+ [AST_SECURITY_EVENT_FAILED_ACL] = evt_gen_failed_acl,
+};
+
+static void evt_gen_failed_acl(void)
+{
+ struct sockaddr_in sin_local = {
+ .sin_family = AF_INET
+ };
+ struct sockaddr_in sin_remote = {
+ .sin_family = AF_INET
+ };
+ struct timeval session_tv = ast_tvnow();
+ struct ast_security_event_failed_acl failed_acl_event = {
+ .common.event_type = AST_SECURITY_EVENT_FAILED_ACL,
+ .common.version = AST_SECURITY_EVENT_FAILED_ACL_VERSION,
+ .common.service = "TEST",
+
+ .module = AST_MODULE,
+ .account_id = "Username",
+ .session_id = "Session123",
+ .acl_name = "TEST_ACL",
+ .session_tv = &session_tv,
+ .sin_local = &sin_local,
+ .sin_remote = &sin_remote,
+ .transport = AST_SECURITY_EVENT_TRANSPORT_UDP,
+ };
+
+ inet_aton("192.168.1.1", &sin_local.sin_addr);
+ sin_local.sin_port = htons(12121);
+
+ inet_aton("192.168.1.2", &sin_remote.sin_addr);
+ sin_local.sin_port = htons(12345);
+
+ ast_security_event_report(AST_SEC_EVT(&failed_acl_event));
+}
+
+static void gen_events(struct ast_cli_args *a)
+{
+ unsigned int i;
+
+ ast_cli(a->fd, "Generating some security events ...\n");
+
+ for (i = 0; i < ARRAY_LEN(evt_generators); i++) {
+ const char *event_type = ast_security_event_get_name(i);
+
+ if (!evt_generators[i]) {
+ ast_cli(a->fd, "*** No event generator for event type '%s' ***\n",
+ event_type);
+ continue;
+ }
+
+ ast_cli(a->fd, "Generating a '%s' security event ...\n", event_type);
+
+ evt_generators[i]();
+ }
+
+ ast_cli(a->fd, "Security event generation complete.\n");
+}
+
+static char *handle_cli_sec_evt_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "securityevents test generation";
+ e->usage = ""
+ "Usage: securityevents test generation"
+ "";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ case CLI_HANDLER:
+ gen_events(a);
+ return CLI_SUCCESS;
+ }
+
+ return CLI_FAILURE;
+}
+
+static struct ast_cli_entry cli_sec_evt[] = {
+ AST_CLI_DEFINE(handle_cli_sec_evt_test, "Test security event generation"),
+};
+
+static int unload_module(void)
+{
+ return ast_cli_unregister_multiple(cli_sec_evt, ARRAY_LEN(cli_sec_evt));
+}
+
+static int load_module(void)
+{
+ int res;
+
+ res = ast_cli_register_multiple(cli_sec_evt, ARRAY_LEN(cli_sec_evt));
+
+ return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Test Security Event Generation");
Propchange: team/group/security_events/tests/test_security_events.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/group/security_events/tests/test_security_events.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/group/security_events/tests/test_security_events.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the svn-commits
mailing list