Changeset 2022
- 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
| r1989 |
r2022 |
|
| 20 | 20 | import java.io.PrintStream; |
|---|
| 21 | 21 | import java.io.File; |
|---|
| | 22 | import java.util.HashMap; |
|---|
| 22 | 23 | import java.util.Iterator; |
|---|
| 23 | 24 | import java.util.Vector; |
|---|
| 24 | 25 | |
|---|
| | 26 | import com.tresys.framework.compiler.custom.CPolicyRefresher; |
|---|
| 25 | 27 | import com.tresys.framework.compiler.dictionary.Dictionary; |
|---|
| 26 | 28 | import com.tresys.framework.compiler.dictionary.DictionaryValidator; |
|---|
| … | … | |
| 34 | 36 | import com.tresys.framework.compiler.translator.SELinuxDictionary; |
|---|
| 35 | 37 | import com.tresys.framework.compiler.translator.SELinuxPolicy; |
|---|
| | 38 | import com.tresys.slide.utility.policyxmlparser.BasePartCreator; |
|---|
| | 39 | import com.tresys.slide.utility.policyxmlparser.MacroParseException; |
|---|
| | 40 | import com.tresys.slide.utility.policyxmlparser.MacroParser; |
|---|
| 36 | 41 | |
|---|
| 37 | 42 | /** |
|---|
| … | … | |
| 68 | 73 | static boolean debug = false; |
|---|
| 69 | 74 | |
|---|
| | 75 | // an interface file name that holds customization |
|---|
| | 76 | private static String customPolicyFileName; |
|---|
| | 77 | |
|---|
| 70 | 78 | private static void getOpt (String[] args) |
|---|
| 71 | 79 | { |
|---|
| … | … | |
| 231 | 239 | { |
|---|
| 232 | 240 | 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 | } |
|---|
| 233 | 254 | } |
|---|
| 234 | 255 | else |
|---|
| … | … | |
| 311 | 332 | System.out.println (" -if <interface file> specify interface file for linkage to reference policy"); |
|---|
| 312 | 333 | 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"); |
|---|
| 313 | 335 | System.out.println (); |
|---|
| 314 | 336 | System.out.println ("System resource arguments:"); |
|---|
| … | … | |
| 533 | 555 | |
|---|
| 534 | 556 | } |
|---|
| | 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 | } |
|---|
| 535 | 587 | translator = new SELinuxPolicy (linkage, moduleName, fcFile); |
|---|
| 536 | 588 | |
|---|
| r2009 |
r2022 |
|
| 74 | 74 | import com.tresys.slide.plugin.nature.SystemProjectNature; |
|---|
| 75 | 75 | import com.tresys.slide.plugin.nature.PolicyXMLContainer.PolicyXMLListener; |
|---|
| 76 | | import com.tresys.slide.utility.MacroParseException; |
|---|
| 77 | | import com.tresys.slide.utility.MacroParser; |
|---|
| | 76 | import com.tresys.slide.utility.policyxmlparser.BasePartCreator; |
|---|
| | 77 | import com.tresys.slide.utility.policyxmlparser.MacroParseException; |
|---|
| | 78 | import com.tresys.slide.utility.policyxmlparser.MacroParser; |
|---|
| 78 | 79 | |
|---|
| 79 | 80 | public class SELinuxSystem |
|---|
| … | … | |
| 772 | 773 | |
|---|
| 773 | 774 | /** Three module IFiles */ |
|---|
| 774 | | protected IFile[] mModule = new IFile [3]; |
|---|
| | 775 | protected IFile[] mModule; |
|---|
| 775 | 776 | |
|---|
| 776 | 777 | public CPolicyContainer(String i_sModuleName) |
|---|
| … | … | |
| 809 | 810 | } |
|---|
| 810 | 811 | |
|---|
| | 812 | void dispose() |
|---|
| | 813 | { |
|---|
| | 814 | ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); |
|---|
| | 815 | mModule = null; |
|---|
| | 816 | } |
|---|
| | 817 | |
|---|
| 811 | 818 | public void refreshPolicy () |
|---|
| 812 | 819 | { |
|---|
| … | … | |
| 817 | 824 | try |
|---|
| 818 | 825 | { |
|---|
| | 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 | |
|---|
| 819 | 839 | IPath interfacePath = mModule[IF_FILE].getLocation (); |
|---|
| 820 | 840 | 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 ()); |
|---|
| 822 | 843 | CPolicyRefresher refresher = new CPolicyRefresher(modified_templates.keySet(), SELinuxPolicy.CUSTOM_PREFIX, SELinuxSystem.this.getName ()); |
|---|
| 823 | 844 | getPolicy ().Accept(refresher); |
|---|
| … | … | |
| 838 | 859 | parseFileJob.schedule(); |
|---|
| 839 | 860 | } |
|---|
| 840 | | /* |
|---|
| 841 | | public final String getCustomModuleName() |
|---|
| 842 | | { |
|---|
| 843 | | return m_sModuleName; |
|---|
| 844 | | } |
|---|
| 845 | | */ |
|---|
| | 861 | |
|---|
| 846 | 862 | public IFile[] getCustomModuleFiles() |
|---|
| 847 | 863 | { |
|---|
| … | … | |
| 914 | 930 | IResourceDelta interested_root = rootDelta.findMember(path); |
|---|
| 915 | 931 | |
|---|
| 916 | | // final ArrayList changed = new ArrayList(); |
|---|
| 917 | | |
|---|
| 918 | 932 | IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() |
|---|
| 919 | 933 | { |
|---|
| … | … | |
| 937 | 951 | && resource.getName ().equals (mModule[IF_FILE].getName ())) |
|---|
| 938 | 952 | { |
|---|
| 939 | | // changed.add(resource); |
|---|
| | 953 | if( delta.getKind () == IResourceDelta.REMOVED ) |
|---|
| | 954 | { |
|---|
| | 955 | dispose (); |
|---|
| | 956 | return false; |
|---|
| | 957 | } |
|---|
| 940 | 958 | refreshPolicy (); |
|---|
| 941 | 959 | } |
|---|
| … | … | |
| 952 | 970 | e.printStackTrace(); |
|---|
| 953 | 971 | } |
|---|
| 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 | | */ |
|---|
| 992 | 972 | } |
|---|
| 993 | 973 | } |
|---|
Download in other formats:
* Generating other formats may take time.