Changeset 2055
- 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
| r2049 |
r2055 |
|
| 18 | 18 | import java.io.FileOutputStream; |
|---|
| 19 | 19 | import java.io.FileNotFoundException; |
|---|
| | 20 | import java.io.FileReader; |
|---|
| 20 | 21 | import java.io.OutputStream; |
|---|
| 21 | 22 | import java.io.PrintStream; |
|---|
| … | … | |
| 29 | 30 | import com.tresys.framework.compiler.dictionary.DictionaryValidator; |
|---|
| 30 | 31 | import com.tresys.framework.compiler.linkage.Linkage; |
|---|
| | 32 | import com.tresys.framework.compiler.linkage.net.FNETParser; |
|---|
| | 33 | import com.tresys.framework.compiler.linkage.net.NetworkConfig; |
|---|
| 31 | 34 | import com.tresys.framework.compiler.mls.MLSInitializationException; |
|---|
| 32 | 35 | import com.tresys.framework.compiler.mls.MLSSupport; |
|---|
| … | … | |
| 82 | 85 | static String ipsecFilename = null; |
|---|
| 83 | 86 | |
|---|
| | 87 | static String netConfigFilename = null; |
|---|
| | 88 | |
|---|
| 84 | 89 | private static void getOpt (String[] args) |
|---|
| 85 | 90 | { |
|---|
| … | … | |
| 259 | 264 | } |
|---|
| 260 | 265 | } |
|---|
| 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")) |
|---|
| 262 | 280 | { |
|---|
| 263 | 281 | x++; |
|---|
| … | … | |
| 272 | 290 | } |
|---|
| 273 | 291 | } |
|---|
| 274 | | else if ( args[x].equals ("-ipsec")) |
|---|
| | 292 | else if (args[x].equals ("-ipsec")) |
|---|
| 275 | 293 | { |
|---|
| 276 | 294 | x++; |
|---|
| … | … | |
| 372 | 390 | System.out.println (); |
|---|
| 373 | 391 | System.out.println ("Network arguments:"); |
|---|
| | 392 | System.out.println (" -n <network config> specify networking configuration file"); |
|---|
| 374 | 393 | System.out.println (" -ipsec <output file> specify output file for generated ipsec "); |
|---|
| 375 | 394 | System.out.println (" (Labeled Networking) Security Associations"); |
|---|
| … | … | |
| 494 | 513 | errorCount = 0; |
|---|
| 495 | 514 | /* for(String policyFilename : polSourceFilenames) */ |
|---|
| 496 | | Iterator iter = polSourceFilenames.iterator (); |
|---|
| 497 | | while (iter.hasNext ()) |
|---|
| | 515 | for (Iterator iter = polSourceFilenames.iterator (); iter.hasNext (); ) |
|---|
| 498 | 516 | { |
|---|
| 499 | 517 | String policyFilename = (String) iter.next (); |
|---|
| … | … | |
| 531 | 549 | errorCount = 0; |
|---|
| 532 | 550 | /* for(String systemResFile : sysSourceFilenames) */ |
|---|
| 533 | | iter = sysSourceFilenames.iterator (); |
|---|
| 534 | | while (iter.hasNext ()) |
|---|
| | 551 | for (Iterator iter = sysSourceFilenames.iterator (); iter.hasNext (); ) |
|---|
| 535 | 552 | { |
|---|
| 536 | 553 | String systemResFile = (String) iter.next (); |
|---|
| … | … | |
| 591 | 608 | |
|---|
| 592 | 609 | } |
|---|
| | 610 | } |
|---|
| | 611 | |
|---|
| | 612 | if (netConfigFilename != null) |
|---|
| | 613 | { |
|---|
| | 614 | System.out.println ("Parsing network configuration from " + netConfigFilename); |
|---|
| | 615 | NetworkConfig config = new NetworkConfig (); |
|---|
| 593 | 616 | |
|---|
| 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) |
|---|
| 596 | 638 | { |
|---|
| 597 | 639 | File file = new File(customPolicyFileName); |
|---|
| 598 | | if( file != null ) |
|---|
| | 640 | if (file != null) |
|---|
| 599 | 641 | { |
|---|
| 600 | 642 | HashMap interfaces = null; |
|---|
| … | … | |
| 603 | 645 | interfaces = MacroParser.parseM4File (file, MacroParser.TEMPLATE, new BasePartCreator()); |
|---|
| 604 | 646 | } |
|---|
| 605 | | catch(MacroParseException pe) |
|---|
| 606 | | { |
|---|
| 607 | | if( debug) |
|---|
| | 647 | catch (MacroParseException pe) |
|---|
| | 648 | { |
|---|
| | 649 | if (debug) |
|---|
| 608 | 650 | pe.printStackTrace (); |
|---|
| 609 | 651 | ErrorExit (pe.getMessage ()); |
|---|
| 610 | 652 | } |
|---|
| 611 | | catch(FileNotFoundException fe) |
|---|
| 612 | | { |
|---|
| 613 | | if( debug) |
|---|
| | 653 | catch (FileNotFoundException fe) |
|---|
| | 654 | { |
|---|
| | 655 | if (debug) |
|---|
| 614 | 656 | fe.printStackTrace (); |
|---|
| 615 | 657 | ErrorExit (fe.getMessage ()); |
|---|
| 616 | 658 | } |
|---|
| 617 | | if( interfaces != null ) |
|---|
| | 659 | if (interfaces != null) |
|---|
| 618 | 660 | { |
|---|
| 619 | 661 | CPolicyRefresher cpr = new CPolicyRefresher(interfaces.keySet (),SELinuxPolicy.CUSTOM_PREFIX,moduleName); |
|---|
| … | … | |
| 739 | 781 | { |
|---|
| 740 | 782 | File secmarkFile = new File (secmarkFilename); |
|---|
| 741 | | PrintStream secmarkStream = new PrintStream (secmarkFile); |
|---|
| | 783 | |
|---|
| | 784 | PrintStream secmarkStream = new PrintStream (new FileOutputStream (secmarkFile)); |
|---|
| 742 | 785 | secmarkStream.print (networkData.toString ()); |
|---|
| 743 | 786 | secmarkStream.flush (); |
|---|
| r2016 |
r2055 |
|
| 197 | 197 | } |
|---|
| 198 | 198 | |
|---|
| 199 | | public PolicyParser(Policy policy, com.tresys.framework.compiler.dictionary.Dictionary dict) |
|---|
| | 199 | public PolicyParser(Policy policy, Dictionary dict) |
|---|
| 200 | 200 | { |
|---|
| 201 | 201 | this(System.in); |
|---|
| r2049 |
r2055 |
|
| 22 | 22 | protected final int [] m_nPorts; |
|---|
| 23 | 23 | |
|---|
| 24 | | NetworkInfo (String i_sNode, String i_sIP, int [] i_aPorts) |
|---|
| | 24 | public NetworkInfo (String i_sNode, String i_sIP, int [] i_aPorts) |
|---|
| 25 | 25 | { |
|---|
| 26 | 26 | m_sNode = i_sNode; |
|---|
| r2045 |
r2055 |
|
| 209 | 209 | |<NR_RBRACE : "}"> { SwitchTo(--depth < 2 ? DEFAULT : NORES_STATE); } |
|---|
| 210 | 210 | |<NR_LBRACE : "{" > { depth++; } |
|---|
| 211 | | |<NETWORK : "network"> |
|---|
| | 211 | |<NETWORK : "secmark"|"ipsec"> |
|---|
| 212 | 212 | |<COLON : ":"> |
|---|
| 213 | 213 | |<PROTOCOL : "udp" | "tcp" > |
|---|
Download in other formats:
* Generating other formats may take time.