Add security access policy framework
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 13 Aug 2008 00:22:38 +0000 (02:22 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 13 Aug 2008 00:22:38 +0000 (02:22 +0200)
include/Makefile.am
include/security.h [new file with mode: 0644]
src/Makefile.am
src/connman.h
src/security.c [new file with mode: 0644]

index 89c5aa5..76057be 100644 (file)
@@ -1,7 +1,8 @@
 
 includedir = @includedir@/connman
 
-include_HEADERS = log.h plugin.h driver.h element.h property.h rtnl.h dbus.h
+include_HEADERS = log.h plugin.h security.h driver.h element.h property.h \
+                                                               rtnl.h dbus.h
 
 MAINTAINERCLEANFILES = Makefile.in
 
diff --git a/include/security.h b/include/security.h
new file mode 100644 (file)
index 0000000..104ca7c
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2008  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef __CONNMAN_SECURITY_H
+#define __CONNMAN_SECURITY_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <connman/element.h>
+
+#define CONNMAN_SECURITY_PRIORITY_LOW      -100
+#define CONNMAN_SECURITY_PRIORITY_DEFAULT     0
+#define CONNMAN_SECURITY_PRIORITY_HIGH      100
+
+struct connman_security {
+       const char *name;
+       int priority;
+       int (*authorize_sender) (const char *sender);
+};
+
+extern int connman_security_register(struct connman_security *security);
+extern void connman_security_unregister(struct connman_security *security);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_SECURITY_H */
index 9518f28..ea4a21d 100644 (file)
@@ -12,7 +12,7 @@ DISTCLEANFILES = $(service_DATA)
 sbin_PROGRAMS = connmand
 
 connmand_SOURCES = main.c connman.h log.c plugin.c profile.c element.c \
-                                       storage.c manager.c agent.c rtnl.c
+                               security.c storage.c manager.c agent.c rtnl.c
 
 connmand_LDADD = @GDBUS_LIBS@ @GLIB_LIBS@ @GMODULE_LIBS@ @GTHREAD_LIBS@
 
index 22616f5..fde2bd3 100644 (file)
@@ -54,6 +54,8 @@ void __connman_log_cleanup(void);
 int __connman_plugin_init(void);
 void __connman_plugin_cleanup(void);
 
+#include <connman/security.h>
+
 #include <connman/driver.h>
 #include <connman/element.h>
 
diff --git a/src/security.c b/src/security.c
new file mode 100644 (file)
index 0000000..4539ba1
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2007-2008  Intel Corporation. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "connman.h"
+
+static GStaticRWLock security_lock = G_STATIC_RW_LOCK_INIT;
+static GSList *security_list = NULL;
+
+static gint compare_priority(gconstpointer a, gconstpointer b)
+{
+       const struct connman_security *security1 = a;
+       const struct connman_security *security2 = b;
+
+       return security2->priority - security1->priority;
+}
+
+int connman_security_register(struct connman_security *security)
+{
+       DBG("security %p name %s", security, security->name);
+
+       g_static_rw_lock_writer_lock(&security_lock);
+
+       security_list = g_slist_insert_sorted(security_list, security,
+                                                       compare_priority);
+
+       g_static_rw_lock_writer_unlock(&security_lock);
+
+       return 0;
+}
+
+void connman_security_unregister(struct connman_security *security)
+{
+       DBG("security %p name %s", security, security->name);
+
+       g_static_rw_lock_writer_lock(&security_lock);
+
+       security_list = g_slist_remove(security_list, security);
+
+       g_static_rw_lock_writer_unlock(&security_lock);
+}