Changeset 168
- 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
| r158 |
r168 |
|
| 38 | 38 | static String dictOutputFilename = null; |
|---|
| 39 | 39 | 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; |
|---|
| 41 | 44 | static String pcFilename = null; |
|---|
| 42 | 45 | static String fcFilename = null; |
|---|
| … | … | |
| 108 | 111 | System.exit(1); |
|---|
| 109 | 112 | } |
|---|
| 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]; |
|---|
| 114 | 141 | } else { |
|---|
| 115 | 142 | printUsage(); |
|---|
| … | … | |
| 149 | 176 | } |
|---|
| 150 | 177 | |
|---|
| | 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 | |
|---|
| 151 | 190 | // certain flags require a framework policy file |
|---|
| 152 | 191 | 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 " |
|---|
| 155 | 194 | + "policy to be provided by using the -p argument."); |
|---|
| 156 | 195 | getOptError = true; |
|---|
| … | … | |
| 162 | 201 | } |
|---|
| 163 | 202 | } |
|---|
| | 203 | |
|---|
| 164 | 204 | /** |
|---|
| 165 | 205 | * Display dictionary parser usage. |
|---|
| … | … | |
| 167 | 207 | private static void printUsage (){ |
|---|
| 168 | 208 | 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 | ); |
|---|
| 172 | 216 | System.out.println("\nGeneral arguments:"); |
|---|
| 173 | 217 | System.out.println(" -h display this message and exit"); |
|---|
| … | … | |
| 176 | 220 | System.out.println("\nGlobal arguments:"); |
|---|
| 177 | 221 | System.out.println(" -pc <policy.conf> specify base policy policy.conf"); |
|---|
| | 222 | System.out.println(" -fc <file_context> specify base policy file_context"); |
|---|
| 178 | 223 | System.out.println("\nDictionary arguments:"); |
|---|
| | 224 | System.out.println(" -dc <compiled dictionary> specify pre-compiled dictionary file created using the -do flag"); |
|---|
| 179 | 225 | System.out.println(" -ds <dictionary source> specify source file for dictionary"); |
|---|
| 180 | 226 | 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)"); |
|---|
| 186 | 234 | System.out.println("\nA single dictionary file must be specified (either source, or compiled)"); |
|---|
| 187 | 235 | } |
|---|
| … | … | |
| 204 | 252 | com.tresys.framework.dictionary.Config.SetDebug(debug); |
|---|
| 205 | 253 | com.tresys.framework.policy.Config.SetDebug(debug); |
|---|
| | 254 | com.tresys.framework.systemResources.Config.SetDebug(debug); |
|---|
| 206 | 255 | com.tresys.framework.dictionary.Config.SetWarn(warn); |
|---|
| 207 | 256 | com.tresys.framework.policy.Config.SetWarn(warn); |
|---|
| | 257 | com.tresys.framework.systemResources.Config.SetWarn(warn); |
|---|
| 208 | 258 | |
|---|
| 209 | 259 | // create linkage interface depending on compilation targets |
|---|
| 210 | 260 | try { |
|---|
| 211 | | if (polFilename != null){ |
|---|
| | 261 | if (fcFilename != null){ |
|---|
| 212 | 262 | linkage = new Linkage(pcFilename, fcFilename); |
|---|
| 213 | 263 | } else { |
|---|
| … | … | |
| 246 | 296 | |
|---|
| 247 | 297 | // 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..."); |
|---|
| 251 | 301 | System.exit(1); |
|---|
| 252 | 302 | } |
|---|
| … | … | |
| 267 | 317 | } |
|---|
| 268 | 318 | |
|---|
| 269 | | if (outFilename != null){ |
|---|
| | 319 | if (polOutputFilename != null){ |
|---|
| 270 | 320 | 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 + "..."); |
|---|
| 273 | 323 | } catch (FileNotFoundException e){ |
|---|
| 274 | | System.err.println("**UNABLE TO OPEN FILE " + outFilename + "**"); |
|---|
| | 324 | System.err.println("**UNABLE TO OPEN FILE " + polOutputFilename + "**"); |
|---|
| 275 | 325 | System.exit(1); |
|---|
| 276 | 326 | } |
|---|
Download in other formats:
* Generating other formats may take time.