Changeset 1947

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

Move the policy Validate functions into PolicyValidator? visitor

Files:

Legend:

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

    r1946 r1947  
    2626import com.tresys.framework.compiler.linkage.Linkage; 
    2727import com.tresys.framework.compiler.policy.Policy; 
     28import com.tresys.framework.compiler.policy.PolicyValidator; 
    2829import com.tresys.framework.compiler.systemResources.SystemResources; 
    2930import com.tresys.framework.compiler.translator.SELinuxDictionary; 
     
    410411                } 
    411412 
    412                 System.out.println ("Validating policy..."); 
    413                 if (!policy.Validate ()) 
    414                 { 
    415                         ErrorExit ("Policy validation failed, exiting..."); 
    416                 } 
    417  
     413                { 
     414                        System.out.println ("Validating policy..."); 
     415                         
     416                        CLIErrorHandler policyHandler = new CLIErrorHandler ("policy_validator"); 
     417                        PolicyValidator policyValidator = new PolicyValidator (policy, policyHandler); 
     418                        policy.Accept (policyValidator); 
     419                         
     420                         
     421        //              if (!policy.Validate ()) 
     422                        if (policyValidator.hasErrors ()) 
     423                        { 
     424                                ErrorExit ("Policy validation failed, exiting..."); 
     425                        } 
     426                } 
     427                 
    418428                sysres = new SystemResources (policy); 
    419429                errorCount = 0; 
     
    563573                if (translator.GetErrorState ()) 
    564574                { 
    565                         System.err.println ("Errors encountered during translation!"); 
     575                        System.out.println ("Errors encountered during translation!"); 
    566576                        if (polOutputFilename != null) 
    567577                        { 
    568                                 System.err.println ("Cleaning up generated policy..."); 
     578                                System.out.println ("Cleaning up generated policy..."); 
    569579                                File pc = new File (polOutputFilename); 
    570580 
     
    573583                        if (fcOutputFilename != null) 
    574584                        { 
    575                                 System.err.println ("Cleaning up generated file context..."); 
     585                                System.out.println ("Cleaning up generated file context..."); 
    576586                                File fc = new File (fcOutputFilename); 
    577587 
     
    592602        public static void ErrorExit (String message) 
    593603        { 
    594                 System.err.println (message); 
     604                System.out.println (message); 
    595605                System.exit (1); 
    596606        } 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/FSysGenerator.java

    r1938 r1947  
    2121import com.tresys.framework.compiler.dictionary.Rdef; 
    2222import com.tresys.framework.compiler.dictionary.SysResourceState; 
    23 import com.tresys.framework.compiler.linkage.flnkage.Ability; 
     23import com.tresys.framework.compiler.policy.Ability; 
    2424import com.tresys.framework.compiler.policy.AccessBaseResource; 
     25import com.tresys.framework.compiler.policy.AccessBoolean; 
    2526import com.tresys.framework.compiler.policy.AccessResource; 
    2627import com.tresys.framework.compiler.policy.BaseDomain; 
     
    3233import com.tresys.framework.compiler.policy.Enter; 
    3334import com.tresys.framework.compiler.policy.EntrypointResource; 
     35import com.tresys.framework.compiler.policy.IPolicyVisitor; 
    3436import com.tresys.framework.compiler.policy.Policy; 
    3537import com.tresys.framework.compiler.policy.Resource; 
     
    230232        {} 
    231233         
     234        public void Visit (AccessBoolean i_access) 
     235        {} 
     236 
    232237        public void Visit (Ability i_ability) 
    233238        {} 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/PolicyGenerator.java

    r1878 r1947  
    2020import com.tresys.framework.compiler.dictionary.EntryAccessDefn; 
    2121import com.tresys.framework.compiler.dictionary.Rdef; 
    22 import com.tresys.framework.compiler.linkage.flnkage.Ability; 
    2322import com.tresys.framework.compiler.linkage.flnkage.BaseAccessDefn; 
     23import com.tresys.framework.compiler.policy.Ability; 
    2424import com.tresys.framework.compiler.policy.AccessBaseResource; 
     25import com.tresys.framework.compiler.policy.AccessBoolean; 
    2526import com.tresys.framework.compiler.policy.AccessResource; 
    2627import com.tresys.framework.compiler.policy.BaseDomain; 
     
    3233import com.tresys.framework.compiler.policy.Enter; 
    3334import com.tresys.framework.compiler.policy.EntrypointResource; 
     35import com.tresys.framework.compiler.policy.IPolicyVisitor; 
    3436import com.tresys.framework.compiler.policy.Policy; 
    3537import com.tresys.framework.compiler.policy.Resource; 
     
    381383        } 
    382384 
     385         
     386        public void Visit (AccessBoolean i_access) 
     387        {} 
     388         
    383389        public void Visit (Ability i_ability) 
    384390        {} 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/linkage/Linkage.java

    r1938 r1947  
    1717import java.util.Iterator; 
    1818 
    19 import com.tresys.framework.compiler.linkage.flnkage.Ability; 
     19import com.tresys.framework.compiler.policy.Ability; 
    2020import com.tresys.framework.compiler.policy.BaseDomain; 
    2121import com.tresys.framework.compiler.policy.BaseResource; 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/linkage/flnkage/FLNKParser.jj

    r1939 r1947  
    2626import com.tresys.framework.compiler.ErrorHandler; 
    2727import com.tresys.framework.compiler.ParserBase; 
     28import com.tresys.framework.compiler.policy.Ability; 
    2829import com.tresys.framework.compiler.policy.BaseDomain; 
    2930import com.tresys.framework.compiler.policy.BaseResource; 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/linkage/flnkage/ILinkageItem.java

    r1878 r1947  
    1212import java.util.Map; 
    1313 
    14 import com.tresys.framework.compiler.IPolicyVisitor; 
    1514import com.tresys.framework.compiler.dictionary.NameValuePair; 
     15import com.tresys.framework.compiler.policy.IPolicyVisitor; 
    1616 
    1717public interface ILinkageItem 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/Ability.java

    r1939 r1947  
    77 */ 
    88 
    9 package com.tresys.framework.compiler.linkage.flnkage
     9package com.tresys.framework.compiler.policy
    1010 
    1111import java.util.HashMap; 
    12 import java.util.Iterator; 
    1312import java.util.Map; 
    1413import java.util.TreeMap; 
    1514 
    1615import com.tresys.framework.compiler.AbstractToken; 
    17 import com.tresys.framework.compiler.IPolicyVisitor; 
    1816import com.tresys.framework.compiler.dictionary.AccessTarget; 
    1917import com.tresys.framework.compiler.dictionary.INameValue; 
     
    2119import com.tresys.framework.compiler.dictionary.PermVector; 
    2220import com.tresys.framework.compiler.dictionary.Target; 
     21import com.tresys.framework.compiler.linkage.flnkage.ILinkageItem; 
    2322 
    2423import com.tresys.slide.utility.policyxmlparser.Interface; 
     
    130129         * @return              <code>true</code> if definition is valid. 
    131130         */ 
     131/* 
    132132        final boolean Validate()  
    133133        { 
    134134                boolean valid = true; 
    135135 
    136                 /*for (PermVector pv:at.GetPermVectors().values())*/ 
    137136                for (Iterator iter = accessTarget.GetPermVectors().values().iterator(); iter.hasNext(); )  
    138137                { 
     
    148147                return valid; 
    149148        } 
    150  
     149*/ 
    151150         
    152151        /** 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/Access.java

    r1878 r1947  
    1515import java.util.Collection; 
    1616 
    17 import com.tresys.framework.compiler.IPolicyVisitable; 
    18 import com.tresys.framework.compiler.IPolicyVisitor; 
    1917import com.tresys.framework.compiler.AbstractToken; 
    2018import com.tresys.framework.compiler.dictionary.Verb; 
     
    108106                        Domain.Add(this); 
    109107        } 
    110          
    111         public abstract boolean Validate(); 
    112108 
    113109        public abstract void Accept(IPolicyVisitor i_visitor); 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/AccessBaseResource.java

    r1878 r1947  
    1313import java.util.HashSet; 
    1414import java.util.Iterator; 
    15 import java.util.Map; 
    1615import java.util.Set; 
    1716import java.util.TreeSet; 
    1817 
    19 import com.tresys.framework.compiler.ErrorHandler; 
    20 import com.tresys.framework.compiler.IPolicyVisitor; 
    2118import com.tresys.framework.compiler.AbstractToken; 
    2219import com.tresys.framework.compiler.Utility; 
     
    176173        } 
    177174 
    178         public boolean Validate()  
    179         { 
    180                 if (getDomain().GetChildDomains().size() > 0)  
    181                 { 
    182                         /*for (Domain child: Domain.GetChildDomains())*/ 
    183                         Iterator iter = getDomain().GetChildDomains().values().iterator(); 
    184                         while (iter.hasNext())  
    185                         { 
    186                                 Domain child = (Domain) iter.next(); 
    187                                 /*for (Access childAccess: child.GetAccess(verb).values())*/ 
    188                                 Iterator iter2 = child.GetAccesses().iterator(); 
    189                                 while (iter2.hasNext())  
    190                                 { 
    191                                         Access childAccess = (Access) iter2.next(); 
    192                                         if (childAccess instanceof AccessBaseResource 
    193                                                 && ((AccessBaseResource) childAccess).GetBaseResource() == GetBaseResource())  
    194                                         { 
    195                                                 return true; 
    196                                         } 
    197                                 } 
    198                         } 
    199                          
    200                         Token.Error ("Access from parent not used by any children", ErrorHandler.ERROR_UNUSED_ACCESS, toString()); 
    201                         return false; 
    202                 } 
    203  
    204                 // If the domain and the resource have the same parent, there are no constraints 
    205                 Domain domainParent = getDomain().getParent(); 
    206  
    207                 if(domainParent != null) { 
    208  
    209                         Map parentAccesses = domainParent.GetAccessMap(m_verb.intValue()); 
    210  
    211                         if (parentAccesses.isEmpty())  
    212                         { 
    213                                 Token.Warning("Constraint violation: Child domain has attempted to exceed parent domain \"" 
    214                                                 + domainParent.getName() 
    215                                                 + "\"'s access to interface \"" 
    216                                                 + GetBaseResource().getName() + "\"", 
    217                                                 ErrorHandler.ERROR_INVALID_ACCESS, toString()); 
    218                                 return false; 
    219                         } 
    220  
    221                         Access parentToResource = (Access) parentAccesses.get(GetBaseResource()); 
    222  
    223                         if (parentToResource == null)  
    224                         { 
    225                                 Token.Warning("Constraint violation: Child domain has attempted to exceed parent domain \"" 
    226                                                 + domainParent.getName() 
    227                                                 + "\"'s access to resource \"" 
    228                                                 + GetBaseResource().getName() + "\"", 
    229                                                 ErrorHandler.ERROR_INVALID_ACCESS, toString ()); 
    230                                 return false; 
    231                         } 
    232  
    233                         if (parentToResource.m_bool != null 
    234                                 && !parentToResource.m_bool.equals(m_bool))  
    235                         { 
    236                                 Token.Warning("Constraint violation: Parent's permission on resource are wrapped in the boolean " 
    237                                                 + parentToResource.m_bool 
    238                                                 + ", child permission must also be wrapped by the same boolean", 
    239                                                 ErrorHandler.ERROR_MISSING_BOOLEAN, toString()); 
    240                                 return false; 
    241                         } 
    242  
    243                 } 
    244  
    245                 return true; 
    246         } 
    247  
    248175        public boolean equals(Object arg0)  
    249176        { 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/AccessBoolean.java

    r1939 r1947  
    1010 
    1111import java.util.Collection; 
    12 import java.util.Map; 
    1312 
    1413import com.tresys.framework.compiler.AbstractToken; 
    15 import com.tresys.framework.compiler.IPolicyVisitor; 
    1614 
    1715public class AccessBoolean 
     
    2523 
    2624        public void Accept (IPolicyVisitor i_visitor) 
    27         {} 
     25        { 
     26                i_visitor.Visit (this); 
     27        } 
    2828 
    2929        public boolean isDefault () 
     
    4646        // throws VerbMismatchException, UnrevokableException 
    4747        {} 
    48  
    49         public boolean Validate () 
    50         { 
    51                 // If the domain and the resource have the same parent, there are no 
    52                 // constraints 
    53                 Domain domainParent = getDomain ().getParent (); 
    54  
    55                 if (domainParent != null) 
    56                 { 
    57  
    58                         Map/* <Component, Access> */parentAccesses = domainParent.GetAccessMap (m_verb.intValue ()); 
    59  
    60                         if (parentAccesses.isEmpty ()) 
    61                         { 
    62                                 Token 
    63                                         .Warning ("Constraint violation: Child domain has attempted to exceed parent domain \"" 
    64                                                 + domainParent.getName () 
    65                                                 + "\"'s access to interface \"" 
    66                                                 + getResource ().getName () + "\""); 
    67                                 return false; 
    68                         } 
    69  
    70                         Access parentToResource = (Access) parentAccesses.get (getResource ()); 
    71  
    72                         if (parentToResource == null) 
    73                         { 
    74                                 Token.Warning ("Constraint violation: Child domain has attempted to exceed parent domain \"" 
    75                                                 + domainParent.getName () 
    76                                                 + "\"'s access to resource \"" 
    77                                                 + getResource ().getName () + "\""); 
    78                                 return false; 
    79                         } 
    80  
    81                         if (parentToResource.m_bool != null && !parentToResource.m_bool.equals (m_bool)) 
    82                         { 
    83                                 Token 
    84                                         .Warning ("Constraint violation: Parent's permission on resource are wrapped in the boolean " 
    85                                                 + parentToResource.m_bool 
    86                                                 + ", child permission must also be wrapped by the same boolean"); 
    87                                 return false; 
    88                         } 
    89  
    90                 } 
    91                 return true; 
    92         } 
    9348} 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/AccessResource.java

    r1878 r1947  
    1313package com.tresys.framework.compiler.policy; 
    1414 
    15 import com.tresys.framework.compiler.ErrorHandler; 
    16 import com.tresys.framework.compiler.IPolicyVisitor; 
    1715import com.tresys.framework.compiler.AbstractToken; 
    1816import com.tresys.framework.compiler.Utility; 
     
    293291        } 
    294292 
    295         public boolean Validate()  
    296         { 
    297                 if (getDomain().GetChildDomains().size() > 0)  
    298                 { 
    299                         /*for (Domain child: Domain.GetChildDomains())*/ 
    300                         Iterator iter = getDomain().GetChildDomains().values().iterator(); 
    301                         boolean isUsed = false; 
    302                         while(iter.hasNext() && !isUsed)  
    303                         { 
    304                                 Domain child = (Domain) iter.next(); 
    305                                 /*for (Access childAccess: child.GetAccess(verb).values())*/ 
    306                                 Iterator iter2 = child.GetAccesses(m_verb.intValue()).iterator(); 
    307                                 while(iter2.hasNext() && !isUsed) 
    308                                 { 
    309                                         Access childAccess = (Access) iter2.next(); 
    310                                         if (childAccess instanceof AccessResource 
    311                                                 && ((AccessResource) childAccess).getResource() == getResource())  
    312                                         { 
    313                                                 isUsed = true; 
    314                                         } 
    315                                 } 
    316                         } 
    317                         if(!isUsed) { 
    318                                 Token.Error("Access from parent not used by any children",  
    319                                         ErrorHandler.ERROR_UNUSED_ACCESS, toString()); 
    320                                 return false; 
    321                         } 
    322                 } 
    323                  
    324                 if(accessDefs == null || accessDefs.isEmpty()) 
    325                         Token.Warning("No RDef in the resource " + getResource().getName() 
    326                                 + " defines a " + Verb.toString(this.m_verb) + " access", 
    327                                 ErrorHandler.ERROR_INVALID_ACCESS, toString()); 
    328  
    329                 // If the domain and the resource have the same parent, there are no constraints 
    330                 Domain domainParent = getDomain().getParent(); 
    331  
    332                 if(domainParent != null && domainParent != getResource ().getParent()) { 
    333  
    334                         Map/*<Component, Access>*/parentAccesses = domainParent.GetAccessMap(m_verb.intValue()); 
    335  
    336                         if (parentAccesses == null)  
    337                         { 
    338                                 Token.Warning("Constraint violation: Child domain has attempted to exceed parent domain \"" 
    339                                                 + domainParent.getName() 
    340                                                 + "\"'s access to resource \"" 
    341                                                 + getResource ().getName() + "\"", 
    342                                                 ErrorHandler.ERROR_INVALID_ACCESS, toString()); 
    343                                 return false; 
    344                         } 
    345                         AccessResource parentToResource = (AccessResource) parentAccesses.get(getResource ()); 
    346  
    347                         if (parentToResource == null)  
    348                         { 
    349                                 Token.Warning("Constraint violation: Child domain has attempted to exceed parent domain \"" 
    350                                                 + domainParent.getName() 
    351                                                 + "\"'s access to resource \"" 
    352                                                 + getResource ().getName() + "\"", 
    353                                                 ErrorHandler.ERROR_CHILD_EXCEED_ACCESS, toString()); 
    354                                 return false; 
    355                         } 
    356  
    357                         if (!IsSubsetOf(parentToResource))  
    358                         { 
    359                                 Token.Error("Constraint violation: child's access: " 
    360                                         + toString().replace(Utility.DELIM, ' ') 
    361                                         + ", Parent's access: " 
    362                                         + parentToResource.toString().replace(Utility.DELIM, ' ')); 
    363                                 return false; 
    364                         } 
    365                          
    366                         if (parentToResource.m_bool != null 
    367                                 && (m_bool == null || !parentToResource.m_bool.image.equals(m_bool.image)))  
    368                         { 
    369                                 Token.Warning("Constraint violation: Parent's permission on resource is wrapped in the boolean " 
    370                                         + parentToResource.m_bool 
    371                                         + ", child permission must also be wrapped by the same boolean", 
    372                                         ErrorHandler.ERROR_MISSING_BOOLEAN, toString ()); 
    373                                 return false; 
    374                         } 
    375                 } 
    376  
    377                 return true; 
    378         } 
    379  
    380293        public boolean equals(Object arg0) { 
    381294                if(!(arg0 instanceof AccessResource)) 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/BaseDomain.java

    r1878 r1947  
    1919import java.util.Vector; 
    2020 
    21 import com.tresys.framework.compiler.IPolicyVisitor; 
    2221import com.tresys.framework.compiler.AbstractToken; 
    2322import com.tresys.framework.compiler.dictionary.INameValue; 
    2423import com.tresys.framework.compiler.dictionary.NameValuePair; 
    25 import com.tresys.framework.compiler.linkage.Linkage; 
    2624import com.tresys.framework.compiler.linkage.flnkage.ILinkageItem; 
    2725 
     
    123121        } 
    124122 
    125         public boolean IsEnterPresent(IDomain src, Domain dest, EntrypointResource ep)  
     123        public boolean IsEnterPresent(IDomain src, IDomain dest, EntrypointResource ep)  
    126124        { 
    127125                /*for (Enter enter: entries)*/ 
     
    161159        } 
    162160 
    163         public boolean Validate(Linkage linkage)  
    164         { 
    165                 return super.Validate(linkage); 
    166         } 
    167  
    168161        public boolean ValidateSystemResources()  
    169162        { 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/BaseResource.java

    r1878 r1947  
    1212 
    1313import java.util.HashMap; 
    14 import java.util.Iterator; 
    1514import java.util.Map; 
    1615import java.util.Set; 
    1716import java.util.TreeMap; 
    1817 
    19 import com.tresys.framework.compiler.IPolicyVisitor; 
    2018import com.tresys.framework.compiler.AbstractToken; 
    2119import com.tresys.framework.compiler.dictionary.AccessDefn; 
     
    160158        } 
    161159 
    162         public boolean Validate(Policy pol)  
    163         { 
    164                 if(pol.getValidInterfaces() == null) 
    165                         return true; 
    166                 Iterator itr = interfaces.values().iterator(); 
    167                 while(itr.hasNext())  
    168                 { 
    169                         Interface iFace = (Interface) itr.next(); 
    170                         if(!pol.getValidInterfaces().containsKey(iFace.getName()))  
    171                         { 
    172                                 m_token.Error("The baseResource \"" + getName() + "\" calls the " 
    173                                         + iFace.getClass().getName() + " " + iFace.getName() 
    174                                         + " which is not defined in the base policy"); 
    175                                 return false; 
    176                         } 
    177                         if(iFace.GetParameters().size() != ((Interface) pol 
    178                                 .getValidInterfaces().get(iFace.getName())).GetParameters() 
    179                                 .size())  
    180                         { 
    181                                 m_token.Error("The baseResource \"" 
    182                                         + getName() 
    183                                         + "\" calls the " 
    184                                         + iFace.getClass().getName() 
    185                                         + " " 
    186                                         + iFace.getName() 
    187                                         + " with " 
    188                                         + iFace.GetParameters().size() 
    189                                         + " parameters, the correct number of parameters is " 
    190                                         + ((Interface) pol.getValidInterfaces() 
    191                                                 .get(iFace.getName())).GetParameters().size()); 
    192                                 return false; 
    193                         } 
    194  
    195                 } 
    196                 return true; 
    197         } 
    198  
    199160        public void Accept(IPolicyVisitor i_visitor)  
    200161        { 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/Comment.java

    r1939 r1947  
    1111 
    1212import com.tresys.framework.compiler.AbstractToken; 
    13 import com.tresys.framework.compiler.IPolicyVisitable; 
    14 import com.tresys.framework.compiler.IPolicyVisitor; 
    1513 
    1614public class Comment 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/Component.java

    r1878 r1947  
    2121 
    2222import com.tresys.framework.compiler.ErrorHandler; 
    23 import com.tresys.framework.compiler.IPolicyVisitable; 
    24 import com.tresys.framework.compiler.IPolicyVisitor; 
    2523import com.tresys.framework.compiler.AbstractToken; 
    26 import com.tresys.framework.compiler.linkage.Linkage; 
    2724 
    2825/** 
     
    192189        } 
    193190 
    194         public boolean Validate(Linkage linkage)  
    195         { 
    196                 boolean valid = true; 
    197  
    198                 return valid; 
    199         } 
    200  
    201191        /** 
    202192         * Get the token with location information 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/ComponentWithDictObjects.java

    r1938 r1947  
    327327        } 
    328328 
    329         public boolean Validate(Linkage linkage)  
    330         { 
    331                 boolean valid = true; 
    332  
    333                 valid &= super.Validate(linkage); 
    334  
    335                 return valid; 
    336         } 
    337  
    338329        /** 
    339330         * Reset the system resource associations defined 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/Conditional.java

    r1878 r1947  
    99package com.tresys.framework.compiler.policy; 
    1010 
    11 import com.tresys.framework.compiler.IPolicyVisitor; 
    1211import com.tresys.framework.compiler.AbstractToken; 
    1312 
  • branches/dictionary_changes/src/com/tresys/framework/compiler/policy/ControlResource.java

    r1878 r1947  
    1313 
    1414import com.tresys.framework.compiler.ErrorHandler; 
    15 import com.tresys.framework.compiler.IPolicyVisitor; 
    1615import com.tresys.framework.compiler.AbstractToken; 
    1716import com.tresys.framework.compiler.dictionary.Rdef; 
    18 import com.tresys.framework.compiler.linkage.Linkage; 
    1917 
    2018/** 
     
    160158        } 
    161159 
    162