Changeset 1948

Show
Ignore:
Timestamp:
02/22/08 11:54:07 (9 months ago)
Author:
dsugar
Message:

Last one - move ValidateSystemResources? -> SystemResourceValidator? visitor

Files:

Legend:

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

    r1947 r1948  
    2727import com.tresys.framework.compiler.policy.Policy; 
    2828import com.tresys.framework.compiler.policy.PolicyValidator; 
     29import com.tresys.framework.compiler.policy.SystemResourceValidator; 
    2930import com.tresys.framework.compiler.systemResources.SystemResources; 
    3031import com.tresys.framework.compiler.translator.SELinuxDictionary; 
     
    366367 
    367368                System.out.println ("Validating dictionary..."); 
     369                { 
     370                        DictionaryValidator validator = new DictionaryValidator (linkage, new CLIProjectErrorHandler ()); 
     371                        dictionary.Accept (validator); 
    368372                 
    369                 DictionaryValidator validator = new DictionaryValidator (linkage, new CLIProjectErrorHandler ()); 
    370                 dictionary.Accept (validator); 
     373                        if (validator.hasError ()) 
     374                        { 
     375                                ErrorExit ("Dictionary validation failed, exiting..."); 
     376                        } 
     377                } 
    371378                 
    372 //              if (!dictionary.Validate (linkage)) 
    373                 if (validator.hasError ()) 
    374                 { 
    375                         ErrorExit ("Dictionary validation failed, exiting..."); 
    376                 } 
    377  
    378379                /* 
    379380                 * only attempt to create policy if -p and -s flags were given note: 
     
    411412                } 
    412413 
    413                 { 
    414                         System.out.println ("Validating policy..."); 
    415                          
     414                System.out.println ("Validating policy..."); 
     415                { 
    416416                        CLIErrorHandler policyHandler = new CLIErrorHandler ("policy_validator"); 
    417417                        PolicyValidator policyValidator = new PolicyValidator (policy, policyHandler); 
    418418                        policy.Accept (policyValidator); 
    419419                         
    420                          
    421         //              if (!policy.Validate ()) 
    422420                        if (policyValidator.hasErrors ()) 
    423421                        { 
     
    447445 
    448446                System.out.println ("Validating system resources..."); 
    449                 if (!sysres.Validate ()) 
    450                 { 
    451                         ErrorExit ("SystemResource validation failed, exiting..."); 
    452                 } 
    453  
     447                { 
     448                        SystemResourceValidator validator = new SystemResourceValidator (new CLIErrorHandler ("system resources")); 
     449                        policy.Accept (validator); 
     450                         
     451                        if (validator.hasErrors ()) 
     452                        { 
     453                                ErrorExit ("SystemResource validation failed, exiting..."); 
     454                        } 
     455                } 
     456                 
    454457                File fcFile = null; 
    455458                if (fcFilename != null) 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/ErrorHandler.java

    r1946 r1948  
    6565        public void Error(String message, AbstractToken source, int i_nType, String i_sKey)  
    6666        { 
    67                 Error (message, source.beginLine, source.beginColumn, source.endColumn, i_nType, i_sKey); 
     67                int nBeginLine = 0; 
     68                int nBeginColumn = 0; 
     69                int nEndColumn = 0; 
     70                 
     71                if (source != null) 
     72                { 
     73                        nBeginLine = source.beginLine; 
     74                        nBeginColumn = source.beginColumn; 
     75                        nEndColumn = source.endColumn; 
     76                } 
     77 
     78                Error (message, nBeginLine, nBeginColumn, nEndColumn, i_nType, i_sKey); 
    6879        } 
    6980 
     
    8495        public void Warning (String message, AbstractToken source, int i_nType, String i_sKey) 
    8596        { 
    86                 Warning (message, source.beginLine, source.beginColumn, source.endColumn, i_nType, i_sKey); 
     97                int nBeginLine = 0; 
     98                int nBeginColumn = 0; 
     99                int nEndColumn = 0; 
     100                 
     101                if (source != null) 
     102                { 
     103                        nBeginLine = source.beginLine; 
     104                        nBeginColumn = source.beginColumn; 
     105                        nEndColumn = source.endColumn; 
     106                } 
     107 
     108                Warning (message, nBeginLine, nBeginColumn, nEndColumn, i_nType, i_sKey); 
    87109        } 
    88110         
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/BaseDomain.java

    r1947 r1948  
    159159        } 
    160160 
    161         public boolean ValidateSystemResources()  
    162         { 
    163                 return true; 
    164         } 
    165  
    166161        public void SetType(String i_sType)  
    167162        { 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/ComponentWithDictObjects.java

    r1947 r1948  
    1212package com.tresys.framework.compiler.policy; 
    1313 
    14 import java.util.Iterator; 
    1514import java.util.Map; 
    1615import java.util.TreeMap; 
     
    2120import com.tresys.framework.compiler.ErrorHandler; 
    2221import com.tresys.framework.compiler.AbstractToken; 
    23 import com.tresys.framework.compiler.Utility; 
    2422import com.tresys.framework.compiler.dictionary.Rdef; 
    2523import com.tresys.framework.compiler.dictionary.IDictionaryObject; 
    26 import com.tresys.framework.compiler.dictionary.SysResourceState; 
    2724import com.tresys.framework.compiler.linkage.Linkage; 
    28 import com.tresys.framework.compiler.systemResources.DirResource; 
    29 import com.tresys.framework.compiler.systemResources.FileResource; 
    3025import com.tresys.framework.compiler.systemResources.SystemResource; 
    31 import com.tresys.framework.compiler.systemResources.SystemResourceTypes; 
    3226 
    3327/** 
     
    235229        } 
    236230 
    237         public boolean ValidateSystemResources()  
    238         { 
    239                 boolean valid = true; 
    240  
    241                 /*for (Rdef _dobject:assocRdefs.values()) */ 
    242                 for (Iterator iter = assocRdefs.values().iterator(); iter.hasNext(); ) 
    243                 { 
    244                         Rdef _dobject = (Rdef) iter.next(); 
    245                         IDictionaryObject dobject = _dobject; 
    246  
    247                         if (dobject.GetSysResourceState(SystemResourceTypes.dir) == SysResourceState.Yes 
    248                                 || dobject.GetSysResourceState(SystemResourceTypes.file) == SysResourceState.Yes 
    249                                 || dobject.GetSysResourceState(SystemResourceTypes.network) == SysResourceState.Yes)  
    250                         { 
    251                                 boolean dirFound = false; 
    252                                 boolean fileFound = false; 
    253                                 boolean netFound = false; 
    254                                 if (GetSystemResources(dobject) != null)  
    255                                 { 
    256                                         /*for (SystemResource sr:GetSystemResources(dobject)) */ 
    257                                         for (Iterator iter2 = GetSystemResources(dobject).iterator(); iter2.hasNext(); ) 
    258                                         { 
    259                                                 SystemResource sr = (SystemResource) iter2.next(); 
    260                                                 if (sr instanceof DirResource)  
    261                                                 { 
    262                                                         dirFound = true; 
    263                                                 } 
    264                                                 if (sr instanceof FileResource) 
    265                                                 { 
    266                                                         fileFound = true; 
    267                                                 } 
    268                                         } 
    269                                 } 
    270                                  
    271                                 // if required but not found 
    272                                 if (dobject.GetSysResourceState(SystemResourceTypes.dir) == SysResourceState.Yes 
    273                                         && !dirFound)  
    274                                 { 
    275                                         AbstractToken tok = m_sysResToken; 
    276                                         if (tok == null) 
    277                                                 tok = m_token; 
    278                                          
    279                                         String sMsg = "The Rdef \"" + dobject.GetName() 
    280                                                                         + "\" associated with component \"" + getName() 
    281                                                                         + "\" requires a directory resource."; 
    282                                         if (tok != null)  
    283                                         { 
    284                                                 tok.Error(sMsg, ErrorHandler.ERROR_MISSING_DIRECTORY, getName()); 
    285                                         } 
    286                                         else  
    287                                         { 
    288                                                 Utility.ProjectError (sMsg); 
    289                                         } 
    290                                         valid = false; 
    291                                 } 
    292                                 else if (dobject.GetSysResourceState (SystemResourceTypes.file) == SysResourceState.Yes 
    293                                         && !fileFound) 
    294                                 { 
    295                                         AbstractToken tok = m_sysResToken; 
    296                                         if (tok == null) 
    297                                                 tok = m_token; 
    298                                          
    299                                         String sMsg = "The Rdef \"" + dobject.GetName() 
    300                                                                         + "\" associated with component \"" + getName() 
    301                                                                         + "\" requires a file resource."; 
    302                                         if (tok != null)  
    303                                         { 
    304                                                 tok.Error(sMsg, ErrorHandler.ERROR_MISSING_DIRECTORY, getName()); 
    305                                         } 
    306                                         else  
    307                                         { 
    308                                                 Utility.ProjectError (sMsg); 
    309                                         } 
    310                                         valid = false; 
    311                                 } 
    312                                 else if (dobject.GetSysResourceState(SystemResourceTypes.network) == SysResourceState.Yes 
    313                                         && !netFound)  
    314                                 { 
    315                                         GetDictionaryObjectLocation(dobject).Error( 
    316                                                 "The Rdef \"" + dobject.GetName() 
    317                                                         + "\" associated with component \"" + getName() 
    318                                                         + "\" requires a network resource.", 
    319                                                         ErrorHandler.ERROR_MISSING_NETWORK, getName ()); 
    320                                         valid = false; 
    321                                 } 
    322  
    323                         } 
    324                 } 
    325  
    326                 return valid; 
    327         } 
    328  
    329231        /** 
    330232         * Reset the system resource associations defined 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/EntrypointResource.java

    r1947 r1948  
    1414import java.util.HashSet; 
    1515 
    16 import com.tresys.framework.compiler.ErrorHandler; 
    1716import com.tresys.framework.compiler.AbstractToken; 
    1817import com.tresys.framework.compiler.dictionary.Entrypoint; 
     
    9493                files = i_resources; 
    9594        } 
    96          
    97         public boolean ValidateSystemResources() { 
    98                 boolean valid = true; 
    99  
    100                 if(GetSystemResources().size() == 0) { 
    101                         valid = false; 
    102                         m_token.Error("Entrypoint \"" + getName() 
    103                                 + "\" requires at least one file association", 
    104                                 ErrorHandler.ERROR_ENTRYPOINT_MISSING_FILE, getName ()); 
    105                 } 
    106  
    107                 return valid; 
    108         } 
    10995 
    11096        public void Accept(IPolicyVisitor i_visitor) { 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/IDomain.java

    r1947 r1948  
    104104        public Map/*<Component>*/GetChildren(); 
    105105 
    106         public boolean ValidateSystemResources(); 
    107  
    108106        public boolean equals(Object obj); 
    109107         
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/PolicyValidator.java

    r1947 r1948  
     1/*\ 
     2|*| Copyright (C) 2008 Tresys Technology, LLC 
     3|*| License: refer to COPYING file for license information. 
     4|*| Author:     David Sugar <dsugar@tresys.com> 
     5|*|   
     6|*| $Rev$ 
     7|*| $Date$ 
     8|*| 
     9|*| Visitor to validate all of the policy. 
     10|*| Moved from the 'Validate' functions on all of the policy objects 
     11\*/ 
     12 
    113package com.tresys.framework.compiler.policy; 
    214 
     
    3345         
    3446        public void PostVisit (Policy i_policy) 
    35         { 
    36         // TODO Auto-generated method stub 
    37  
    38         } 
     47        {} 
    3948 
    4049        public void PreVisit (Policy i_policy) 
    41         { 
    42  
    43         } 
     50        {} 
    4451 
    4552        public void Visit (Resource i_resource) 
    46         { 
    47         // TODO Auto-generated method stub 
    48  
    49         } 
     53        {} 
    5054 
    5155        public void Visit (Domain i_domain) 
     
    228232 
    229233        public void Visit (EntrypointResource point) 
    230         { 
    231         // TODO Auto-generated method stub 
    232  
    233         } 
     234        {} 
    234235 
    235236        public void Visit (AccessBaseResource i_access) 
     
    437438 
    438439        public void Visit (BaseDomain domain) 
    439         { 
    440         // TODO Auto-generated method stub 
    441  
    442         } 
     440        {} 
    443441 
    444442        public void Visit (BaseResource resource) 
     
    482480 
    483481        public void Visit (Comment i_comment) 
    484         { 
    485         // TODO Auto-generated method stub 
    486  
    487         } 
     482        {} 
    488483 
    489484        public void Visit (Conditional i_conditional) 
    490         { 
    491         // TODO Auto-generated method stub 
    492  
    493         } 
     485        {} 
    494486 
    495487        public void Visit (UserDomain dom) 
    496488        { 
    497         // TODO Auto-generated method stub 
    498  
     489                if (dom.getType () == null) 
     490                { 
     491                        m_errHandler.Error ("User Domain type undefined", dom.getToken ()); 
     492                } 
     493                 
     494                if (dom.GetRole () == null) 
     495                { 
     496                        m_errHandler.Error ("User Domain role undefined", dom.getToken ()); 
     497                } 
    499498        } 
    500499 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/UserDomain.java

    r1947 r1948  
    8686        } 
    8787 
    88         public boolean ValidateSystemResources() { 
    89                 return true; 
    90         } 
    91  
    9288        public String getType() { 
    9389                return getName() + "_t"; 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/systemResources/SystemResources.java

    r1825 r1948  
    1010 
    1111import com.tresys.framework.compiler.ErrorHandler; 
    12 import com.tresys.framework.compiler.policy.ControlResource; 
    13 import com.tresys.framework.compiler.policy.EntrypointResource; 
    14 import com.tresys.framework.compiler.policy.IDomain; 
    1512import com.tresys.framework.compiler.policy.Policy; 
    16 import com.tresys.framework.compiler.policy.Resource; 
    1713 
    1814import java.io.File; 
    1915import java.io.FileReader; 
    2016import java.io.Reader; 
    21 import java.util.Iterator; 
    2217 
    2318/** 
     
    6459                } 
    6560        } 
    66  
    67         /** 
    68          * Test policy for complete definition.  Some validation cannot 
    69          * occur until the entire policy is constructed, e.g., searching 
    70          * for orphaned entries and accesses.  That is an access or entry 
    71          * that enters a parent but is never used by the children.  This is  
    72          * because the SEFramework model requires that only non-decomposed  
    73          * domains can contain active entities, or processes. 
    74          *  
    75          * @return      <code>true</code> if policy is valid. 
    76          */ 
    77         public final boolean Validate() { 
    78                 boolean valid = true; 
    79                 try { 
    80                         /*for (IDomain domain: policy.GetDomains().values())*/ 
    81                         Iterator iter = policy.GetDomains().values().iterator(); 
    82                         while(iter.hasNext()) { 
    83                                 IDomain domain = (IDomain) iter.next(); 
    84                                 if(domain.GetChildren().size() == 0) { 
    85                                         valid &= domain.ValidateSystemResources(); 
    86                                 } 
    87                         } 
    88  
    89                         /*for (Resource resource: policy.GetResources().values())*/ 
    90                         iter = policy.GetResources().values().iterator(); 
    91                         while(iter.hasNext()) { 
    92                                 Resource resource = (Resource) iter.next(); 
    93                                 if(!(resource instanceof ControlResource)) { 
    94                                         valid &= resource.ValidateSystemResources(); 
    95                                 } 
    96                         } 
    97  
    98                         /*for (EntrypointResource ep: policy.GetEntrypoints().values())*/ 
    99                         iter = policy.GetEntrypoints().values().iterator(); 
    100                         while(iter.hasNext()) { 
    101                                 EntrypointResource ep = (EntrypointResource) iter.next(); 
    102                                 valid &= ep.ValidateSystemResources(); 
    103                         } 
    104                 } catch (Exception e) { 
    105                         e.printStackTrace(); 
    106                 } 
    107                 return valid; 
    108         } 
    10961} 
  • branches/dictionary_changes/src/com/tresys/framework/plugin/builder/SELinuxSystem.java

    r1947 r1948  
    4444import com.tresys.framework.compiler.policy.Policy; 
    4545import com.tresys.framework.compiler.policy.PolicyValidator; 
     46import com.tresys.framework.compiler.policy.SystemResourceValidator; 
    4647import com.tresys.framework.compiler.systemResources.SystemResources; 
    4748import com.tresys.framework.compiler.translator.SELinuxDictionary; 
     
    490491                if (getSystemResources() != null)  
    491492                { 
    492                         return getSystemResources().Validate(); 
     493                        SystemResourceValidator validator = new SystemResourceValidator (getFSYSErrorHandler ()); 
     494                        getPolicy ().Accept (validator); 
     495                         
     496                        return validator.hasErrors (); 
    493497                } 
    494498                return false;