Changeset 2022

Show
Ignore:
Timestamp:
03/28/08 15:56:02 (8 months ago)
Author:
apatel
Message:

added custom policy option in the complier.
Adapted custome policy object to new M4Parser method signature.

Files:

Legend:

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

    r1989 r2022  
    2020import java.io.PrintStream; 
    2121import java.io.File; 
     22import java.util.HashMap; 
    2223import java.util.Iterator; 
    2324import java.util.Vector; 
    2425 
     26import com.tresys.framework.compiler.custom.CPolicyRefresher; 
    2527import com.tresys.framework.compiler.dictionary.Dictionary; 
    2628import com.tresys.framework.compiler.dictionary.DictionaryValidator; 
     
    3436import com.tresys.framework.compiler.translator.SELinuxDictionary; 
    3537import com.tresys.framework.compiler.translator.SELinuxPolicy; 
     38import com.tresys.slide.utility.policyxmlparser.BasePartCreator; 
     39import com.tresys.slide.utility.policyxmlparser.MacroParseException; 
     40import com.tresys.slide.utility.policyxmlparser.MacroParser; 
    3641 
    3742/** 
     
    6873        static boolean debug = false; 
    6974 
     75        // an interface file name that holds customization 
     76        private static String customPolicyFileName; 
     77 
    7078        private static void getOpt (String[] args) 
    7179        { 
     
    231239                        { 
    232240                                debug = true; 
     241                        } 
     242                        else if ( args[x].equals ("-cp")) 
     243                        { 
     244                                x++; 
     245                                if (x < args.length) 
     246                                { 
     247                                        customPolicyFileName = args[x];  
     248                                } 
     249                                else 
     250                                { 
     251                                        printUsage (); 
     252                                        System.exit (1); 
     253                                } 
    233254                        } 
    234255                        else 
     
    311332                System.out.println ("  -if <interface file> specify interface file for linkage to reference policy"); 
    312333                System.out.println ("       and exposing an external API (defaults to stdout if not specified)"); 
     334                System.out.println ("  -cp <custom interface file> specify interface file with custom template"); 
    313335                System.out.println (); 
    314336                System.out.println ("System resource arguments:"); 
     
    533555                         
    534556                } 
     557                if ( customPolicyFileName != null ) 
     558                { 
     559                        File file = new File(customPolicyFileName); 
     560                        if( file != null ) 
     561                        { 
     562                                HashMap interfaces = null; 
     563                                try 
     564                                { 
     565                                        interfaces = MacroParser.parseM4File (file, MacroParser.INTERFACE, new BasePartCreator()); 
     566                                } 
     567                                catch(MacroParseException pe) 
     568                                { 
     569                                        if( debug)  
     570                                                pe.printStackTrace (); 
     571                                        ErrorExit (pe.getMessage ()); 
     572                                } 
     573                                catch(FileNotFoundException fe) 
     574                                { 
     575                                        if( debug) 
     576                                                fe.printStackTrace (); 
     577                                        ErrorExit (fe.getMessage ()); 
     578                                } 
     579                                if( interfaces != null ) 
     580                                { 
     581                                        CPolicyRefresher cpr = new CPolicyRefresher(interfaces.keySet (),SELinuxPolicy.CUSTOM_PREFIX,moduleName); 
     582                                        policy.Accept (cpr); 
     583                                } 
     584                        } 
     585                         
     586                } 
    535587                translator = new SELinuxPolicy (linkage, moduleName, fcFile); 
    536588 
  • branches/custome_policy/framework-plugin/src/com/tresys/framework/plugin/builder/SELinuxSystem.java

    r2009 r2022  
    7474import com.tresys.slide.plugin.nature.SystemProjectNature; 
    7575import com.tresys.slide.plugin.nature.PolicyXMLContainer.PolicyXMLListener; 
    76 import com.tresys.slide.utility.MacroParseException; 
    77 import com.tresys.slide.utility.MacroParser; 
     76import com.tresys.slide.utility.policyxmlparser.BasePartCreator; 
     77import com.tresys.slide.utility.policyxmlparser.MacroParseException; 
     78import com.tresys.slide.utility.policyxmlparser.MacroParser; 
    7879 
    7980public class SELinuxSystem  
     
    772773                 
    773774                /** Three module IFiles */ 
    774                 protected IFile[] mModule = new IFile [3]
     775                protected IFile[] mModule
    775776 
    776777                public CPolicyContainer(String i_sModuleName) 
     
    809810                } 
    810811                 
     812                void dispose() 
     813                { 
     814                        ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); 
     815                        mModule = null; 
     816                } 
     817                 
    811818                public void refreshPolicy () 
    812819                { 
     
    817824                                        try 
    818825                                        { 
     826                                                IProject proj = getProject (); 
     827                                                if( proj == null || !proj.exists ()) 
     828                                                        return Status.CANCEL_STATUS; 
     829                                                 
     830                                                SLIDEProjectNature nat = SLIDEProjectNature.getNature(getProject ()); 
     831                                                 
     832                                                PolicyXMLContainer policyXML = nat.getPolicyXML (getFolder ()); 
     833                                                if ( policyXML == null ) 
     834                                                        return new Status(IStatus.ERROR, SEFramework_Plugin.getUniqueIdentifier (), "Can not load policy"); 
     835                                                 
     836                                                if( mModule == null || mModule[IF_FILE] == null ) 
     837                                                        return Status.CANCEL_STATUS; 
     838                                                         
    819839                                                IPath interfacePath = mModule[IF_FILE].getLocation (); 
    820840                                                File interfaceFile = interfacePath.toFile (); 
    821                                                 Map modified_templates = MacroParser.parseM4File (interfaceFile, MacroParser.TEMPLATE); 
     841                                                 
     842                                                Map modified_templates = MacroParser.parseM4File (interfaceFile, MacroParser.TEMPLATE, policyXML.getCreator ()); 
    822843                                                CPolicyRefresher refresher = new CPolicyRefresher(modified_templates.keySet(), SELinuxPolicy.CUSTOM_PREFIX, SELinuxSystem.this.getName ()); 
    823844                                                getPolicy ().Accept(refresher); 
     
    838859                        parseFileJob.schedule(); 
    839860                } 
    840 /*               
    841                 public final String getCustomModuleName() 
    842                 { 
    843                         return m_sModuleName; 
    844                 } 
    845 */               
     861                 
    846862                public IFile[] getCustomModuleFiles() 
    847863                { 
     
    914930                        IResourceDelta interested_root = rootDelta.findMember(path); 
    915931                         
    916 //                      final ArrayList changed = new ArrayList(); 
    917                          
    918932                        IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() 
    919933                        { 
     
    937951                                                && resource.getName ().equals (mModule[IF_FILE].getName ())) 
    938952                                        { 
    939 //                                              changed.add(resource); 
     953                                                if( delta.getKind () == IResourceDelta.REMOVED ) 
     954                                                { 
     955                                                        dispose (); 
     956                                                        return false; 
     957                                                } 
    940958                                                refreshPolicy (); 
    941959                                        } 
     
    952970                                e.printStackTrace(); 
    953971                        } 
    954 /*                       
    955                         //nothing more to do if there were no changed 'custom if' files 
    956                         if (changed.size() == 0) 
    957                                 return; 
    958  
    959                         Job parseFileJob = new Job("Parsing custom module files") 
    960                         { 
    961                                 public IStatus run(IProgressMonitor monitor) 
    962                                 { 
    963                                         for (int i = 0; i < changed.size(); i++) 
    964                                         { 
    965                                                 IResource res = (IResource) changed.get(i); 
    966  
    967                                                 if( !res.exists () ) 
    968                                                         continue; 
    969                                                  
    970 //                                              File changed_file = res.getLocation ().toFile (); 
    971  
    972                                                 try 
    973                                                 { 
    974                                                         refreshPolicy (); 
    975                                                 } 
    976                                                 catch (MacroParseException pe) 
    977                                                 { 
    978                                                         IStatus status = new Status(IStatus.ERROR, SEFramework_Plugin.getUniqueIdentifier (), pe.getLocalizedMessage ()); 
    979                                                         return status; 
    980                                                 } 
    981                                                 catch (FileNotFoundException fne) 
    982                                                 { 
    983                                                         IStatus status = new Status(IStatus.ERROR, SEFramework_Plugin.getUniqueIdentifier (), fne.getLocalizedMessage (), fne); 
    984                                                         return status; 
    985                                                 } 
    986                                         } 
    987                                         return Status.OK_STATUS; 
    988                                 } 
    989                         }; 
    990                         parseFileJob.schedule(); 
    991 */               
    992972                } 
    993973        }