[asterisk-commits] russell: branch group/security_events r192210 - in /team/group/security_event...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon May 4 16:07:53 CDT 2009


Author: russell
Date: Mon May  4 16:07:45 2009
New Revision: 192210

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=192210
Log:
Random code that might do some stuff, but definitely does not do things

Added:
    team/group/security_events/include/asterisk/security_events.h   (with props)
    team/group/security_events/main/security_events.c   (with props)
Modified:
    team/group/security_events/include/asterisk/event_defs.h
    team/group/security_events/main/Makefile

Modified: team/group/security_events/include/asterisk/event_defs.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/security_events/include/asterisk/event_defs.h?view=diff&rev=192210&r1=192209&r2=192210
==============================================================================
--- team/group/security_events/include/asterisk/event_defs.h (original)
+++ team/group/security_events/include/asterisk/event_defs.h Mon May  4 16:07:45 2009
@@ -48,8 +48,9 @@
 	/*! The state of a device has changed on _one_ server.  This should not be used
 	 *  directly, in general.  Use AST_EVENT_DEVICE_STATE instead. */
 	AST_EVENT_DEVICE_STATE_CHANGE = 0x06,
+	AST_EVENT_SECURITY            = 0x07,
 	/*! Number of event types.  This should be the last event type + 1 */
-	AST_EVENT_TOTAL               = 0x07,
+	AST_EVENT_TOTAL               = 0x08,
 };
 
 /*! \brief Event Information Element types */
@@ -62,43 +63,43 @@
 	 * Used by: AST_EVENT_MWI 
 	 * Payload type: UINT
 	 */
-	AST_EVENT_IE_NEWMSGS   = 0x01,
+	AST_EVENT_IE_NEWMSGS   = 0x0001,
 	/*! 
 	 * \brief Number of
 	 * Used by: AST_EVENT_MWI 
 	 * Payload type: UINT
 	 */
-	AST_EVENT_IE_OLDMSGS   = 0x02,
+	AST_EVENT_IE_OLDMSGS   = 0x0002,
 	/*! 
 	 * \brief Mailbox name \verbatim (mailbox[@context]) \endverbatim
 	 * Used by: AST_EVENT_MWI 
 	 * Payload type: STR
 	 */
-	AST_EVENT_IE_MAILBOX   = 0x03,
+	AST_EVENT_IE_MAILBOX   = 0x0003,
 	/*! 
 	 * \brief Unique ID
 	 * Used by: AST_EVENT_SUB, AST_EVENT_UNSUB
 	 * Payload type: UINT
 	 */
-	AST_EVENT_IE_UNIQUEID  = 0x04,
+	AST_EVENT_IE_UNIQUEID  = 0x0004,
 	/*! 
 	 * \brief Event type 
 	 * Used by: AST_EVENT_SUB, AST_EVENT_UNSUB
 	 * Payload type: UINT
 	 */
-	AST_EVENT_IE_EVENTTYPE = 0x05,
+	AST_EVENT_IE_EVENTTYPE = 0x0005,
 	/*!
 	 * \brief Hint that someone cares that an IE exists
 	 * Used by: AST_EVENT_SUB
 	 * Payload type: UINT (ast_event_ie_type)
 	 */
-	AST_EVENT_IE_EXISTS    = 0x06,
+	AST_EVENT_IE_EXISTS    = 0x0006,
 	/*!
 	 * \brief Device Name
 	 * Used by AST_EVENT_DEVICE_STATE_CHANGE
 	 * Payload type: STR
 	 */
-	AST_EVENT_IE_DEVICE    = 0x07,
+	AST_EVENT_IE_DEVICE    = 0x0007,
 	/*!
 	 * \brief Generic State IE
 	 * Used by AST_EVENT_DEVICE_STATE_CHANGE
@@ -106,20 +107,31 @@
 	 * The actual state values depend on the event which
 	 * this IE is a part of.
 	 */
-	 AST_EVENT_IE_STATE    = 0x08,
+	 AST_EVENT_IE_STATE    = 0x0008,
 	 /*!
 	  * \brief Context IE
 	  * Used by AST_EVENT_MWI
 	  * Payload type: str
 	  */
-	 AST_EVENT_IE_CONTEXT  = 0x09,
+	 AST_EVENT_IE_CONTEXT  = 0x0009,
 	 /*!
 	  * \brief Entity ID
 	  * Used by All events
 	  * Payload type: RAW
 	  * This IE indicates which server the event originated from
 	  */
-	 AST_EVENT_IE_EID      = 0x0A,
+	AST_EVENT_IE_EID            = 0x000A,
+	AST_EVENT_IE_SECURITY_EVENT = 0x000B,
+	AST_EVENT_IE_EVENT_VERSION  = 0x000C,
+	AST_EVENT_IE_SERVICE        = 0x000D,
+	AST_EVENT_IE_MODULE         = 0x000E,
+	AST_EVENT_IE_ACCOUNT_ID     = 0x000F,
+	AST_EVENT_IE_SESSION_ID     = 0x0010,
+	AST_EVENT_IE_SESSION_TV     = 0x0011,
+	AST_EVENT_IE_ACL_NAME       = 0x0012,
+	AST_EVENT_IE_LOCAL_ADDR     = 0x0013,
+	AST_EVENT_IE_REMOTE_ADDR    = 0x0014,
+	AST_EVENT_IE_EVENT_TV       = 0x0015,
 };
 
 #define AST_EVENT_IE_MAX AST_EVENT_IE_EID

Added: team/group/security_events/include/asterisk/security_events.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/security_events/include/asterisk/security_events.h?view=auto&rev=192210
==============================================================================
--- team/group/security_events/include/asterisk/security_events.h (added)
+++ team/group/security_events/include/asterisk/security_events.h Mon May  4 16:07:45 2009
@@ -1,0 +1,84 @@
+/*
+ * 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 Security Event Reporting Helpers
+ * 
+ * \author Russell Bryant <russell at digium.com>
+ */
+
+#ifndef __AST_SECURITY_EVENTS_H__
+#define __AST_SECURITY_EVENTS_H__
+
+#include "asterisk/event.h"
+#include "asterisk/network.h"
+
+#if defined(__cplusplus) || defined(c_plusplus)
+extern "C" {
+#endif
+
+enum ast_security_event_type {
+	AST_SECURITY_EVENT_FAILED_ACL,
+};
+
+enum ast_security_event_transport_type {
+	AST_SECURITY_EVENT_TRANSPORT_UDP,
+	AST_SECURITY_EVENT_TRANSPORT_TCP,
+};
+
+/*!
+ * \brief Common structure elements
+ */
+struct ast_security_event_common {
+	enum ast_security_event_type event_type;
+	uint32_t version;
+	const char *service;
+};
+
+struct ast_security_event_failed_acl {
+#define AST_SECURITY_FAILED_ACL_VERSION 1
+	struct ast_security_event_common common;
+	/*! \brief optional */
+	const char *module;
+	/*! \brief required */
+	const char *account_id;
+	/*! \brief required */
+	const char *session_id;
+	/*! \brief optional */
+	const char *acl_name;
+	/*! \brief optional */
+	const struct timeval *session_tv;
+	/*! \brief required */
+	const struct sockaddr_in *sin_local;
+	/*! \brief required */
+	enum ast_security_event_transport_type local_transport;
+	/*! \brief required */
+	const struct sockaddr_in *sin_remote;
+	/*! \brief required */
+	enum ast_security_event_transport_type remote_transport;
+};
+
+int ast_security_event_report(const struct ast_security_event_common *sec);
+
+#if defined(__cplusplus) || defined(c_plusplus)
+}
+#endif
+
+#endif /* __AST_SECURITY_EVENTS_H__ */

Propchange: team/group/security_events/include/asterisk/security_events.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/security_events/include/asterisk/security_events.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/security_events/include/asterisk/security_events.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/group/security_events/main/Makefile
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/security_events/main/Makefile?view=diff&rev=192210&r1=192209&r2=192210
==============================================================================
--- team/group/security_events/main/Makefile (original)
+++ team/group/security_events/main/Makefile Mon May  4 16:07:45 2009
@@ -20,7 +20,7 @@
 OBJS= tcptls.o io.o sched.o logger.o frame.o loader.o config.o channel.o \
 	translate.o file.o pbx.o cli.o md5.o term.o heap.o \
 	ulaw.o alaw.o callerid.o fskmodem.o image.o app.o \
-	cdr.o tdd.o acl.o udptl.o manager.o asterisk.o \
+	cdr.o tdd.o acl.o udptl.o manager.o asterisk.o security_events.o \
 	dsp.o chanvars.o indications.o autoservice.o db.o privacy.o \
 	astmm.o astfd.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
 	utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \

Added: 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=auto&rev=192210
==============================================================================
--- team/group/security_events/main/security_events.c (added)
+++ team/group/security_events/main/security_events.c Mon May  4 16:07:45 2009
@@ -1,0 +1,162 @@
+/*
+ * 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 Security Event Reporting Helpers
+ *
+ * \author Russell Bryant <russell at digium.com>
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/utils.h"
+#include "asterisk/strings.h"
+#include "asterisk/network.h"
+#include "asterisk/security_events.h"
+
+#define TIMESTAMP_STR_LEN 32
+
+static int handle_failed_acl(const struct ast_security_event_common *sec);
+
+struct {
+	enum ast_security_event_type event_type;
+	uint32_t version;
+	int (*handler)(const struct ast_security_event_common *);
+} sec_events[] = {
+	{
+		.event_type = AST_SECURITY_EVENT_FAILED_ACL,
+		.version    = AST_SECURITY_FAILED_ACL_VERSION,
+		.handler    = handle_failed_acl,
+	},
+};
+
+static void encode_timestamp(struct ast_str **str, const struct timeval *tv)
+{
+	ast_str_set(str, 0, "%u-%u",
+			(unsigned int) tv->tv_sec,
+			(unsigned int) tv->tv_usec);
+}
+
+static struct ast_event *alloc_event(const struct ast_security_event_common *sec)
+{
+	struct ast_str *str = ast_str_alloca(TIMESTAMP_STR_LEN);
+	struct timeval tv = ast_tvnow();
+
+	encode_timestamp(&str, &tv);
+
+	return ast_event_new(AST_EVENT_SECURITY,
+		AST_EVENT_IE_SECURITY_EVENT, AST_EVENT_IE_PLTYPE_UINT, sec->event_type,
+		AST_EVENT_IE_EVENT_TV, AST_EVENT_IE_PLTYPE_STR, str->str,
+		AST_EVENT_IE_SERVICE, AST_EVENT_IE_PLTYPE_STR, sec->service,
+		AST_EVENT_IE_END);
+}
+
+int ast_security_event_report(const struct ast_security_event_common *sec)
+{
+	unsigned int i;
+	int res = -1;
+
+	for (i = 0; i < ARRAY_LEN(sec_events); i++) {
+		if (sec->event_type != sec_events[i].event_type) {
+			continue;
+		}
+
+		if (sec->version != sec_events[i].version) {
+			ast_log(LOG_WARNING, "Security event version mismatch\n");
+			break;
+		}
+
+		res = sec_events[i].handler(sec);
+		break;
+	}
+
+	return res;
+}
+
+static int add_timeval_ie(struct ast_event **event, enum ast_event_ie_type ie_type,
+		const struct timeval *tv)
+{
+	struct ast_str *str = ast_str_alloca(TIMESTAMP_STR_LEN);
+
+	encode_timestamp(&str, tv);
+
+	return ast_event_append_ie_str(event, ie_type, str->str);
+}
+
+static int add_ipv4_ie(struct ast_event **event, enum ast_event_ie_type ie_type,
+		const struct sockaddr_in *sin,
+		enum ast_security_event_transport_type transport_type)
+{
+	struct ast_str *str = ast_str_alloca(64);
+
+	ast_str_set(&str, 0, "IPV4/");
+
+	switch (transport_type) {
+	case AST_SECURITY_EVENT_TRANSPORT_UDP:
+		ast_str_append(&str, 0, "UDP/");
+		break;
+	case AST_SECURITY_EVENT_TRANSPORT_TCP:
+		ast_str_append(&str, 0, "TCP/");
+		break;
+	}
+
+	ast_str_append(&str, 0, "%s/%hu",
+			ast_inet_ntoa(sin->sin_addr),
+			ntohs(sin->sin_port));
+
+	return 0;
+}
+
+static int handle_failed_acl(const struct ast_security_event_common *sec)
+{
+	const struct ast_security_event_failed_acl *failed_acl;
+	struct ast_event *event;
+
+	failed_acl = (const struct ast_security_event_failed_acl *) sec;
+
+	if (!(event = alloc_event(sec))) {
+		return -1;
+	}
+
+	if (!ast_strlen_zero(failed_acl->module)) {
+		ast_event_append_ie_str(&event, AST_EVENT_IE_MODULE, failed_acl->module);
+	}
+
+	ast_event_append_ie_str(&event, AST_EVENT_IE_ACCOUNT_ID, failed_acl->account_id);
+	ast_event_append_ie_str(&event, AST_EVENT_IE_SESSION_ID, failed_acl->session_id);
+
+	if (!ast_strlen_zero(failed_acl->acl_name)) {
+		ast_event_append_ie_str(&event, AST_EVENT_IE_ACL_NAME,
+				failed_acl->acl_name);
+	}
+
+	if (failed_acl->session_tv) {
+		add_timeval_ie(&event, AST_EVENT_IE_SESSION_TV, failed_acl->session_tv);
+	}
+
+	add_ipv4_ie(&event, AST_EVENT_IE_LOCAL_ADDR,
+			failed_acl->sin_local, failed_acl->local_transport);
+	add_ipv4_ie(&event, AST_EVENT_IE_REMOTE_ADDR,
+			failed_acl->sin_remote, failed_acl->remote_transport);
+
+	return 0;
+}

Propchange: team/group/security_events/main/security_events.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/security_events/main/security_events.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/security_events/main/security_events.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list