Assign default group to newly created devices
authorAndreas Steffen <andreas.steffen@strongswan.org>
Tue, 25 Jun 2013 09:49:32 +0000 (11:49 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Tue, 25 Jun 2013 09:49:32 +0000 (11:49 +0200)
src/libimcv/imv/imv_policy_manager.c

index 8379105..737929a 100644 (file)
@@ -23,6 +23,9 @@
 #include <stdio.h>
 #include <time.h>
 
+/* The default policy group #1 is assumed to always exist */
+#define DEFAULT_GROUP_ID       1
+
 /**
  * global debug output variables
  */
@@ -113,6 +116,15 @@ bool policy_start(database_t *db, int session_id)
                }
        }
 
+       /* assign a newly created device to a default group */
+       if (device_id && !created)
+       {
+               db->execute(db, NULL,
+                       "INSERT INTO groups_members (device_id, group_id) "
+                       "VALUES (?, ?)", DB_INT, device_id,
+                       DB_INT, group_id ? group_id : DEFAULT_GROUP_ID);
+       }
+
        /* get iteratively enforcements for given group */
        while (group_id)
        {
@@ -291,4 +303,3 @@ int main(int argc, char *argv[])
 
        exit(EXIT_SUCCESS);
 }
-