Changeset 168

Show
Ignore:
Timestamp:
06/24/05 07:21:18 (4 years ago)
Author:
sshimko
Message:

-Added and modified semantic checks applied to command line arguments

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/com/tresys/framework/Compiler.java

    r158 r168  
    3838        static String dictOutputFilename = null; 
    3939        static String polFilename = null; 
    40         static String outFilename = null; 
     40        static String polOutputFilename = null; 
     41        static String sysFilename = null; 
     42        static String ncOutputFilename = null; 
     43        static String fcOutputFilename = null; 
    4144        static String pcFilename = null; 
    4245        static String fcFilename = null; 
     
    108111                                        System.exit(1); 
    109112                                }                                
    110                         } else if (args[x].equals("-o")){ 
    111                                 x++; 
    112                                 if (x<args.length){ 
    113                                         outFilename = args[x]; 
     113                        } else if (args[x].equals("-po")){ 
     114                                x++; 
     115                                if (x<args.length){ 
     116                                        polOutputFilename = args[x]; 
     117                                } else { 
     118                                        printUsage(); 
     119                                        System.exit(1); 
     120                                } 
     121                        } else if (args[x].equals("-s")){ 
     122                                x++; 
     123                                if (x<args.length){ 
     124                                        sysFilename = args[x]; 
     125                                } else { 
     126                                        printUsage(); 
     127                                        System.exit(1); 
     128                                } 
     129                        } else if (args[x].equals("-sf")){ 
     130                                x++; 
     131                                if (x<args.length){ 
     132                                        fcOutputFilename = args[x]; 
     133                                } else { 
     134                                        printUsage(); 
     135                                        System.exit(1); 
     136                                } 
     137                        } else if (args[x].equals("-sn")){ 
     138                                x++; 
     139                                if (x<args.length){ 
     140                                        ncOutputFilename = args[x]; 
    114141                                } else { 
    115142                                        printUsage(); 
     
    149176                } 
    150177                 
     178                // system resources requires file context 
     179                if (sysFilename != null && fcFilename == null){ 
     180                        System.err.println("Error: the -fc flag is required when using the -s flag."); 
     181                        getOptError = true; 
     182                } 
     183                 
     184                // requires file_context file to generate .fc 
     185                if (fcOutputFilename != null && fcFilename == null){ 
     186                        System.err.println("Error: the -fc flag is required when using the -sf flag."); 
     187                        getOptError = true; 
     188                } 
     189                 
    151190                // certain flags require a framework policy file 
    152191                if (polFilename == null &&  
    153                                 (fcFilename != null || outFilename != null)){ 
    154                         System.err.println("Error: the -fc and -o flags require a Framework "  
     192                                (sysFilename != null || polOutputFilename != null)){ 
     193                        System.err.println("Error: the -po and -s flags require a Framework "  
    155194                                        + "policy to be provided by using the -p argument."); 
    156195                        getOptError = true; 
     
    162201                } 
    163202        } 
     203 
    164204        /** 
    165205         * Display dictionary parser usage. 
     
    167207        private static void printUsage (){ 
    168208                System.out.println("SEFramework compiler usage:\n"); 
    169                 System.out.println("java com.tresys.framework.Compiler [-h] [-v] [-q] -pc <policy.conf> [-ds <dictionary source> "  
    170                                 + "[-do <dictionary output>]] [-dc <compiled dictionary>] [-p <policy>] [-o output] "  
    171                                 + "[-fc <file_context>]"); 
     209                System.out.println("java com.tresys.framework.Compiler [-h] [-v] [-q]\n"   
     210                                + "[-fc <file_context>] -pc <policy.conf>\n"  
     211                                + "[-ds <dictionary source> [-do <dictionary output>]]\n"  
     212                                + "[-dc <compiled dictionary>]\n"  
     213                                + "[-p <policy>] [-po output]\n"  
     214                                + "[-s <system resource source>] [-so <generated file context output file>]"  
     215                                ); 
    172216                System.out.println("\nGeneral arguments:"); 
    173217                System.out.println("  -h display this message and exit"); 
     
    176220                System.out.println("\nGlobal arguments:"); 
    177221                System.out.println("  -pc <policy.conf> specify base policy policy.conf"); 
     222                System.out.println("  -fc <file_context> specify base policy file_context"); 
    178223                System.out.println("\nDictionary arguments:"); 
     224                System.out.println("  -dc <compiled dictionary> specify pre-compiled dictionary file created using the -do flag"); 
    179225                System.out.println("  -ds <dictionary source> specify source file for dictionary"); 
    180226                System.out.println("  -do <dictionary output> specify destination file for dictionary storage"); 
    181                 System.out.println("  -dc <compiled dictionary> specify pre-compiled dictionary file created using the -do flag"); 
    182                 System.out.println("\nPolicy and Translation arguments:"); 
    183                 System.out.println("  -p <policy source> specify source file for policy parsing (required for the following 3 options)"); 
    184                 System.out.println("  -o <output file> specify output file for translated policy output (defaults to stdout if not specified)"); 
    185                 System.out.println("  -fc <file_context> specify base policy file_context"); 
     227                System.out.println("\nPolicy arguments:"); 
     228                System.out.println("  -p <policy source> specify source file for policy parsing"); 
     229                System.out.println("  -po <output file> specify output file for translated policy output (defaults to stdout if not specified)"); 
     230                System.out.println("\nSystem resource arguments:"); 
     231                System.out.println("  -s <system resource source> specify source file for system parsing"); 
     232                System.out.println("  -sf <fcoutput file> specify output file for file context output (defaults to stdout if not specified)"); 
     233                System.out.println("  -sn <ncoutput file> specify output file for network context output (defaults to stdout if not specified)"); 
    186234                System.out.println("\nA single dictionary file must be specified (either source, or compiled)"); 
    187235        } 
     
    204252                com.tresys.framework.dictionary.Config.SetDebug(debug); 
    205253                com.tresys.framework.policy.Config.SetDebug(debug); 
     254                com.tresys.framework.systemResources.Config.SetDebug(debug); 
    206255                com.tresys.framework.dictionary.Config.SetWarn(warn); 
    207256                com.tresys.framework.policy.Config.SetWarn(warn); 
     257                com.tresys.framework.systemResources.Config.SetWarn(warn); 
    208258 
    209259                // create linkage interface depending on compilation targets 
    210260                try  { 
    211                         if (polFilename != null){ 
     261                        if (fcFilename != null){ 
    212262                                linkage = new Linkage(pcFilename, fcFilename); 
    213263                        } else {  
     
    246296                         
    247297                        // policy can only be translated in context of a file_context and policy.conf 
    248                         if (fcFilename == null || pcFilename == null){ 
    249                                 System.err.println("Error: policy.conf and file_context must be specified "  
    250                                                 + "using the -pc and -fc flags for translation and linkage to occur!"); 
     298                        if (fcFilename == null){ 
     299                                System.err.println("Warning: policy.conf and file_context must be specified "  
     300                                                + "using the -pc and -fc flags for proper translation and linkage to occur!  Will attempt to continue anyways..."); 
    251301                                System.exit(1); 
    252302                        } 
     
    267317                        } 
    268318 
    269                         if (outFilename != null){ 
     319                        if (polOutputFilename != null){ 
    270320                                try { 
    271                                         stream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outFilename))); 
    272                                         System.out.println("Writing translation to " + outFilename + "..."); 
     321                                        stream = new PrintStream(new BufferedOutputStream(new FileOutputStream(polOutputFilename))); 
     322                                        System.out.println("Writing translation to " + polOutputFilename + "..."); 
    273323                                } catch (FileNotFoundException e){ 
    274                                         System.err.println("**UNABLE TO OPEN FILE " +  outFilename + "**"); 
     324                                        System.err.println("**UNABLE TO OPEN FILE " +  polOutputFilename + "**"); 
    275325                                        System.exit(1); 
    276326                                }