0 ; ˆl–Ým_Jµ!®Å8 Cp Üiå1hßÄ „ �8×Ãa–ß=¿JJj"Tâ�ÆY¸ÛŠbÑ¿Â?÷ # Authors: Karl MacMillan # # Copyright (C) 2006 Red Hat # see file 'COPYING' for use and warranty information # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; version 2 only # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # """ Classes for representing and manipulating interfaces. """ import copy import itertools from . import access from . import refpolicy from . import objectmodel from . import matching from .sepolgeni18n import _ class Param: """ Object representing a parameter for an interface. """ def __init__(self): self.__name = "" self.type = refpolicy.SRC_TYPE self.obj_classes = refpolicy.IdSet() self.required = True def set_name(self, name): if not access.is_idparam(name): raise ValueError("Name [%s] is not a param" % name) self.__name = name def get_name(self): return self.__name name = property(get_name, set_name) num = property(fget=lambda self: int(self.name[1:])) def __repr__(self): return "" % \ (self.name, refpolicy.field_to_str[self.type], " ".join(self.obj_classes)) # Helper for extract perms def __param_insert(name, type, av, params): ret = 0 if name in params: p = params[name] # The entries are identical - we're done if type == p.type: return # Handle implicitly typed objects (like process) if (type == refpolicy.SRC_TYPE or type == refpolicy.TGT_TYPE) and \ (p.type == refpolicy.TGT_TYPE or p.type == refpolicy.SRC_TYPE): #print name, refpolicy.field_to_str[p.type] # If the object is not implicitly typed, tell the # caller there is a likely conflict. ret = 1 if av: avobjs = [av.obj_class] else: avobjs = [] for obj in itertools.chain(p.obj_classes, avobjs): if obj in objectmodel.implicitly_typed_objects: ret = 0 break # "Promote" to a SRC_TYPE as this is the likely usage. # We do this even if the above test fails on purpose # as there is really no sane way to resolve the conflict # here. The caller can take other actions if needed. p.type = refpolicy.SRC_TYPE else: # There is some conflict - no way to resolve it really # so we just leave the first entry and tell the caller # there was a conflict. ret = 1 else: p = Param() p.name = name p.type = type params[p.name] = p if av: p.obj_classes.add(av.obj_class) return ret def av_extract_params(av, params): """Extract the parameters from an access vector. Extract the parameters (in the form $N) from an access vector, storing them as Param objects in a dictionary. Some attempt is made at resolving conflicts with other entries in the dict, but if an unresolvable conflict is found it is reported to the caller. The goal here is to figure out how interface parameters are actually used in the interface - e.g., that $1 is a domain used as a SRC_TYPE. In general an interface will look like this: interface(`foo', ` allow $1 foo : file read; ') This is simple to figure out - $1 is a SRC_TYPE.