Adding a new feature that makes process jailing rules more fine-grained - we can...
[iot2.git] / iotjava / iotruntime / master / ProcessJailConfig.java
index 4781fbd38753c2462e7807bbf251fd386210c3b4..fba8cad773436bbf2d57f21f3bf0953b46a6367f 100644 (file)
@@ -36,6 +36,7 @@ public final class ProcessJailConfig {
        private static final String STR_TCPGW_PROTOCOL = "tcpgw";
        private static final String STR_NO_PROTOCOL = "nopro";
 
+       private static final String STR_ADD_MAC_EXT             = ".tomoyo";
        private static final String STR_MAC_POLICY_EXT          = ".tomoyo.pol";
        private static final String STR_OBJECT_NAME             = "<object-name>";
        private static final String STR_OBJECT_CLASS_NAME       = "<object-class-name>";
@@ -46,6 +47,9 @@ public final class ProcessJailConfig {
        private static final String STR_DEV_IP_ADDRESS          = "<dev-ip-address>";
        private static final String STR_DEV_COM_PORT            = "<dev-com-port>";
        private static final String STR_DEV_PORT                        = "<dev-port>";
+       
+    private static final int INT_HTTP_PORT = 80;
+    private static final int INT_DNS_PORT  = 53;
 
 
        /**
@@ -101,6 +105,19 @@ public final class ProcessJailConfig {
                }
        }
        
+       
+       /**
+        * flush() flushes all PrintWriter objects
+        *
+        * @return  void
+        */
+       public void flush() {
+
+               for(PrintWriter pwConfig: mapHostToFile.values()) {
+                       pwConfig.flush();
+               }
+       }
+       
 
        /**
         * close() closes all PrintWriter objects
@@ -326,12 +343,13 @@ public final class ProcessJailConfig {
         * @param   iPort                                       Integer port
         * @return  void
         */
-       public void configureProcessJailGWDevicePolicies(String strConfigHost, String strRouterAddress, int iPort) {
+       public void configureProcessJailGWDevicePolicies(String strConfigHost, String strRouterAddress, String strDeviceIPAddress, int iPort) {
 
                PrintWriter pwConfig = getPrintWriter(strConfigHost);
                pwConfig.println("file read /home/iotuser/iot2/iotjava/iotruntime/\\*.jks");
                pwConfig.println("file read /etc/resolv.conf");
                pwConfig.println("file read /etc/hosts");
+       pwConfig.println("network inet stream connect ::ffff:" + strDeviceIPAddress + " " + String.valueOf(INT_HTTP_PORT));     // HTTP access for this address
                pwConfig.println("network inet dgram send " + strRouterAddress + " " + String.valueOf(iPort));
        }
 
@@ -344,11 +362,15 @@ public final class ProcessJailConfig {
         * @param   strAddress          String device IP address
         * @return  void
         */
-       public void configureProcessJailInetAddressPolicies(String strConfigHost, String strAddress) {
+       public void configureProcessJailInetAddressPolicies(String strConfigHost, String strRouterAddress, String strAddress) {
 
                PrintWriter pwConfig = getPrintWriter(strConfigHost);
                //System.out.println("\n\nDEBUG: Writing the config host address setup!!!\n\n");
-               pwConfig.println("network inet stream connect ::ffff:" + strAddress + " " + String.valueOf(80));        // HTTP access for this address
+               pwConfig.println("file read /etc/resolv.conf");
+               pwConfig.println("file read /etc/hosts");
+               pwConfig.println("file read /etc/host.conf");
+               pwConfig.println("network inet dgram send " + strRouterAddress + " " + String.valueOf(INT_DNS_PORT));   // TCP/UDP access through router
+               pwConfig.println("network inet stream connect ::ffff:" + strAddress + " " + String.valueOf(INT_HTTP_PORT));     // HTTP access for this address
        }
 
 
@@ -395,6 +417,21 @@ public final class ProcessJailConfig {
        }
 
 
+       /**
+        * combineAdditionalMACPolicy() method combines the additional MAC policies into the right host policy file
+        *
+        * @param   strConfigHost                       String hostname to be configured
+        * @param   strFileName                         String policy file path and name
+        * @return  void
+        */
+       public void combineAdditionalMACPolicy(String strMACCfgPath, String strObjectName, String strConfigHost) {
+
+               PrintWriter pwConfig = getPrintWriter(strConfigHost);
+               String strPolicyList = readFile(strMACCfgPath + strObjectName + STR_ADD_MAC_EXT);
+               pwConfig.println(strPolicyList);
+       }
+
+
        /**
         * combineControllerMACPolicies() method combines the controller MAC policies into the right host policy file
         *