Changeset 2055

Show
Ignore:
Timestamp:
04/14/08 07:53:04 (7 months ago)
Author:
dsugar
Message:

begin work on parsing .fnet file

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/networking/src/com/tresys/framework/compiler/Compiler.java

    r2049 r2055  
    1818import java.io.FileOutputStream; 
    1919import java.io.FileNotFoundException; 
     20import java.io.FileReader; 
    2021import java.io.OutputStream; 
    2122import java.io.PrintStream; 
     
    2930import com.tresys.framework.compiler.dictionary.DictionaryValidator; 
    3031import com.tresys.framework.compiler.linkage.Linkage; 
     32import com.tresys.framework.compiler.linkage.net.FNETParser; 
     33import com.tresys.framework.compiler.linkage.net.NetworkConfig; 
    3134import com.tresys.framework.compiler.mls.MLSInitializationException; 
    3235import com.tresys.framework.compiler.mls.MLSSupport; 
     
    8285        static String ipsecFilename = null; 
    8386         
     87        static String netConfigFilename = null; 
     88         
    8489        private static void getOpt (String[] args) 
    8590        { 
     
    259264                                } 
    260265                        } 
    261                         else if ( args[x].equals ("-secmark")) 
     266                        else if (args[x].equals ("-n")) 
     267                        { 
     268                                x++; 
     269                                if (x < args.length) 
     270                                { 
     271                                        netConfigFilename = args[x];  
     272                                } 
     273                                else 
     274                                { 
     275                                        printUsage (); 
     276                                        System.exit (1); 
     277                                } 
     278                        } 
     279                        else if (args[x].equals ("-secmark")) 
    262280                        { 
    263281                                x++; 
     
    272290                                } 
    273291                        } 
    274                         else if ( args[x].equals ("-ipsec")) 
     292                        else if (args[x].equals ("-ipsec")) 
    275293                        { 
    276294                                x++; 
     
    372390                System.out.println (); 
    373391                System.out.println ("Network arguments:"); 
     392                System.out.println ("  -n <network config> specify networking configuration file"); 
    374393                System.out.println ("  -ipsec <output file> specify output file for generated ipsec "); 
    375394                System.out.println ("           (Labeled Networking) Security Associations"); 
     
    494513                errorCount = 0; 
    495514                /* for(String policyFilename : polSourceFilenames) */ 
    496                 Iterator iter = polSourceFilenames.iterator (); 
    497                 while (iter.hasNext ()) 
     515                for (Iterator iter = polSourceFilenames.iterator (); iter.hasNext (); ) 
    498516                { 
    499517                        String policyFilename = (String) iter.next (); 
     
    531549                errorCount = 0; 
    532550                /* for(String systemResFile : sysSourceFilenames) */ 
    533                 iter = sysSourceFilenames.iterator (); 
    534                 while (iter.hasNext ()) 
     551                for (Iterator iter = sysSourceFilenames.iterator (); iter.hasNext (); ) 
    535552                { 
    536553                        String systemResFile = (String) iter.next (); 
     
    591608                                 
    592609                        } 
     610                } 
     611                 
     612                if (netConfigFilename != null) 
     613                { 
     614                        System.out.println ("Parsing network configuration from " + netConfigFilename); 
     615                        NetworkConfig config = new NetworkConfig (); 
    593616                         
    594                 } 
    595                 if ( customPolicyFileName != null ) 
     617                        File file = new File (netConfigFilename); 
     618                        FNETParser parser = new FNETParser (config); 
     619                        try 
     620                        { 
     621                                CLIErrorHandler netErrorHandler = new CLIErrorHandler (netConfigFilename); 
     622                                parser.Parse (new FileReader (file), netErrorHandler); 
     623                                errorCount += netErrorHandler.errorCount; 
     624                        } 
     625                        catch (FileNotFoundException fnfe) 
     626                        { 
     627                                fnfe.printStackTrace (); 
     628                                errorCount ++; 
     629                        } 
     630                } 
     631                 
     632                if (errorCount > 0) 
     633                { 
     634                        ErrorExit ("Errors encountered while parsing netowrk configuraiton, exiting..."); 
     635                } 
     636                 
     637                if (customPolicyFileName != null) 
    596638                { 
    597639                        File file = new File(customPolicyFileName); 
    598                         if( file != null
     640                        if (file != null
    599641                        { 
    600642                                HashMap interfaces = null; 
     
    603645                                        interfaces = MacroParser.parseM4File (file, MacroParser.TEMPLATE, new BasePartCreator()); 
    604646                                } 
    605                                 catch(MacroParseException pe) 
    606                                 { 
    607                                         if( debug)  
     647                                catch (MacroParseException pe) 
     648                                { 
     649                                        if (debug)  
    608650                                                pe.printStackTrace (); 
    609651                                        ErrorExit (pe.getMessage ()); 
    610652                                } 
    611                                 catch(FileNotFoundException fe) 
    612                                 { 
    613                                         if( debug) 
     653                                catch (FileNotFoundException fe) 
     654                                { 
     655                                        if (debug) 
    614656                                                fe.printStackTrace (); 
    615657                                        ErrorExit (fe.getMessage ()); 
    616658                                } 
    617                                 if( interfaces != null
     659                                if (interfaces != null
    618660                                { 
    619661                                        CPolicyRefresher cpr = new CPolicyRefresher(interfaces.keySet (),SELinuxPolicy.CUSTOM_PREFIX,moduleName); 
     
    739781                                { 
    740782                                        File secmarkFile = new File (secmarkFilename); 
    741                                         PrintStream secmarkStream = new PrintStream (secmarkFile); 
     783                                         
     784                                        PrintStream secmarkStream = new PrintStream (new FileOutputStream (secmarkFile)); 
    742785                                        secmarkStream.print (networkData.toString ()); 
    743786                                        secmarkStream.flush (); 
  • branches/networking/src/com/tresys/framework/compiler/policy/PolicyParser.jj

    r2016 r2055  
    197197        } 
    198198 
    199         public PolicyParser(Policy policy, com.tresys.framework.compiler.dictionary.Dictionary dict)  
     199        public PolicyParser(Policy policy, Dictionary dict)  
    200200        { 
    201201                this(System.in); 
  • branches/networking/src/com/tresys/framework/compiler/systemResources/NetworkInfo.java

    r2049 r2055  
    2222        protected final int [] m_nPorts; 
    2323         
    24         NetworkInfo (String i_sNode, String i_sIP, int [] i_aPorts) 
     24        public NetworkInfo (String i_sNode, String i_sIP, int [] i_aPorts) 
    2525        { 
    2626                m_sNode = i_sNode; 
  • branches/networking/src/com/tresys/framework/compiler/systemResources/SystemResourcesParser.jj

    r2045 r2055  
    209209        |<NR_RBRACE : "}"> { SwitchTo(--depth < 2 ? DEFAULT : NORES_STATE); } 
    210210        |<NR_LBRACE : "{" > { depth++; } 
    211         |<NETWORK : "network"> 
     211        |<NETWORK : "secmark"|"ipsec"> 
    212212        |<COLON : ":"> 
    213213        |<PROTOCOL : "udp" | "tcp" >