Spade
Mini Shell
| Directory:~$ /proc/self/root/usr/lib64/python2.7/site-packages/sepolgen/ |
| [Home] [System Details] [Kill Me] |
�
��^c@s�dZddlZddlZddlmZddlmZddlmZddlmZddlm Z d dd
��YZ
d�Zd�Zd
�Z
d�Zd�Zddd��YZddd��YZddd��YZddd��YZdS(s7
Classes for representing and manipulating interfaces.
i����Ni(taccess(t refpolicy(tobjectmodel(tmatching(t_tParamcBsSeZdZd�Zd�Zd�Zeee�Zedd��Zd�Z RS(s;
Object representing a paramater for an interface.
cCs1d|_tj|_tj�|_t|_dS(Nt(t_Param__nameRtSRC_TYPEttypetIdSettobj_classestTruetrequired(tself((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyt__init__&s cCs/tj|�s"td|��n||_dS(NsName
[%s] is not a param(Rt
is_idparamt
ValueErrorR(Rtname((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pytset_name,scCs|jS(N(R(R((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pytget_name1stfgetcCst|jd�S(Ni(tintR(R((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyt<lambda>6scCs*d|jtj|jdj|j�fS(Ns0<sepolgen.policygen.Param
instance [%s, %s, %s]>t
(RRtfield_to_strR tjoinR(R((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyt__repr__8s(
t__name__t
__module__t__doc__RRRtpropertyRtnumR(((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyR"s cCs+d}||kr�||}||jkr/dS|tjksM|tjkr�|jtjksq|jtjkr�d}|r�|jg}ng}x6tj|j|�D]}|tj kr�d}Pq�q�Wtj|_qd}n(t
�}||_||_|||j<|r'|jj|j�n|S(Nii(
R RRtTGT_TYPEt obj_classt itertoolstchainRRtimplicitly_typed_objectsRRtadd(RR tavtparamstrettptavobjstobj((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyt__param_insert>s0
$
cCsd}t}tj|j�rKt|jtj||�dkrKd}qKntj|j�r�t|jtj||�dkr�d}q�ntj|j �r�t|j tj
||�dkr�d}q�nxA|jD]6}tj|�r�t|t�dkr d}q q�q�W|S(sjExtract
the paramaters from an access vector.
Extract the paramaters (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 paramaters 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. A few interfaces
are more complex, for example:
interface(`foo_trans',`
domain_auto_trans($1,fingerd_exec_t,fingerd_t)
allow $1 fingerd_t:fd use;
allow fingerd_t $1:fd use;
allow fingerd_t $1:fifo_file rw_file_perms;
allow fingerd_t $1:process sigchld;
')
Here the usage seems ambigious, but it is not. $1 is still domain
and therefore should be returned as a SRC_TYPE.
Returns:
0 - success
1 - conflict found
ii(
tFalseRRtsrc_typeR-RRttgt_typeR!R"t OBJ_CLASStpermstPERM(R'R(R)t found_srctperm((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pytav_extract_paramsjs
$!!!cCs/tj|j�r+t|jtjd|�SdS(N(RRtroleR-RtROLEtNone(R7R(((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pytrole_extract_params�scs��fd�}d}||jtj�r3d}n||jtj�rQd}n||jtj�rod}ntj|j �r�t
|j tjd��r�d}q�n|S(NcsKd}x>|D]6}tj|�r
t||d��rCd}qCq
q
W|S(Nii(RRR-R9(tsetR R)tx(R((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pytextract_from_set�s
ii(
t src_typesRRt tgt_typesR!RR1RRt dest_typeR-t DEST_TYPER9(truleR(R=R)((R(s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyttype_rule_extract_params�s cCsQd}xD|jD]9}tj|�rt|tjd|�rId}qIqqW|S(Nii(targsRRR-RRR9(tifcallR(R)targ((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pytifcall_extract_params�stAttributeVectorcBseZd�Zd�ZRS(cCsd|_tj�|_dS(NR(RRtAccessVectorSet(R((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyR�s cCs|jj|�dS(N(Rtadd_av(RR'((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyRJ�s(RRRRJ(((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyRH�s tAttributeSetcBs#eZd�Zd�Zd�ZRS(cCs
i|_dS(N(t
attributes(R((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyR�scCs||j|j<dS(N(RLR(Rtattr((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pytadd_attr�scCs�d�}d}x�|D]y}|d
}|ddkr[|rL|j|�n||�}q|r|jd�}tj|�}|j|�qqW|r�|j|�ndS(NcSsb|dd!j�}t|�dks5|ddkrHtd|��nt�}|d|_|S(Nii����iit Attributes#Syntax
error Attribute statement
%s(tsplittlentSyntaxErrorRHR(tlinetfieldsta((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyt
parse_attr�s"
i����it[t,(R9RNRPRtAccessVectorRJ(RtfdRVRURStlR'((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyt from_file�s
(RRRRNR\(((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyRK�s tInterfaceVectorcBsGeZdid�Zid�Zd�Zd�Zd�Zd�ZRS(cCsPt|_d|_tj�|_i|_|rC|j||�nt|_dS(NR( RtenabledRRRIR(tfrom_interfaceR.texpanded(Rt interfaceRL((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyR�s c
Cs�|j|_xq|j�D]c}|jtjjkr:qnd|jkrOqntj|�}x|D]}|j|�qeWqW|rHx�|j �D]�}x�|j
D]�}||j
kr�q�n|j
|}xo|jD]d} tj| �}|j|jkr|j
|_n|j|jkr,|j
|_n|j|�q�Wq�Wq�Wnx)|j�D]}
t|
|j�rUqUqUWx)|j�D]}t||j�r�q�q�Wx)|j�D]}t||j�r�q�q�WdS(Nt dontaudit(Rtavrulest rule_typeRtAVRuletALLOWRtavrule_to_access_vectorsRJttypeattributesRLtcopyR/R R0trolesR:R(t typerulesRCtinterface_callsRG(
RRaRLtavruletavsR't
typeattributeRMtattr_vecRUR7RBRE((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyR_s>
cCs/t||j�dkrn|jj|�dS(Ni(R6R(RRJ(RR'((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyRJ8scCsNg}|jd|j�x$|jD]}|jt|��q$Wdj|�S(Ns[InterfaceVector
%s]s
(tappendRRtstrR(RtsR'((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyt to_string>s
cCs
|j�S(N(R(R((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyt__str__EscCsd|j|jfS(Ns<InterfaceVector
%s:%s>(RR^(R((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyRHsN( RRR9RR_RJRtRuR(((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyR]�s4 tInterfaceSetcBs�eZdd�Zd�Zd�Zd�Zd�Zd�Zid�Z did�Z
d�Zd �Zd
�Z
d�ZRS(
cCs(i|_i|_g|_||_dS(N(t
interfacesttgt_type_mapttgt_type_alltoutput(RRz((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyRMs cCs$|jr
|jj|d�ndS(Ns
(Rztwrite(RRr((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pytoSs cCs�x�t|jj�dd��D]�}|jd|j�xJt|jj�dd��D]*}|jd|jtj|jf�qXW|jd�t|j j
��}x1|D])}|jdj|��|jd�q�WqWdS( NtkeycSs|jS(N(R(R<((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyRXss[InterfaceVector
%s
cSs|jS(N(R(R<((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyRZss%s:%s
s]
RXs
(tsortedRwtvaluesR{RR(RRR Rtto_listR(RRZtivtparamtavlR'((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pytto_fileWs%%(
cCs�d�}d}x�|D]y}|d
}|ddkr[|rL|j|�n||�}q|r|jd�}tj|�}|j|�qqW|r�|j|�n|j�dS(NcSs�|dd!j�}t|�dks5|ddkrHtd|��nt�}|d|_t|�dkrtdSx�|dD]t}|jd�}t|�dkr�td|��nt�}|d|_tj|d|_||j |j<qW|S( Nii����iiR]s)Syntax
error InterfaceVector statement %st:s-Invalid param in InterfaceVector
statement %s(
RPRQRRR]RRRtstr_to_fieldR R((RSRTtifvtfieldR*R�((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyt parse_ifvcs
"
i����iRWRX(R9tadd_ifvRPRRYRJtindex(RRZR�R�RSR[R'((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyR\bs
cCs||j|j<dS(N(RwR(RR�((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyR��scCs�x�|jj�D]�}t�}xP|jD]E}tj|j�r^|jj|�t�}Pn|j|j�q)Wx0|D](}|j j
|g�}|j|�qyWqWdS(N(RwRR;RRR0RyRqR&Rxt
setdefault(RR�R?R'R R[((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyR��s
cCs
t||�}|j|�dS(N(R]R�(RRaRLR�((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyR&�scCsTx6tj|j�|j��D]}|j||�qW|j|�|j�dS(N(R#R$Rwt templatesR&texpand_ifcallsR�(RtheadersRzRLti((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pytadd_headers�s%
cCsqtj|�rft|d�}|t|j�kr8dS|j|d}t|t�r\|S|gSn|gSdS(Ni(RRRRQRDR9t
isinstancetlist(RtidRER
RF((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyt map_param�s
c
Cs&|j|j|�}|dkr%dS|j|j|�}|dkrJdS|j|j|�}|dkrodStj�}xB|jD]7}|j||�} | dkr�q�q�|j| �q�Wt |�dkr�dSxI|D]A}
x8|D]0}x'|D]}|j
j|
|||�q�Wq�Wq�WdS(Ni(R�R/R9R0R"RR
R2tupdateRQRR&(
RR�R'RER>R?Rt new_permsR5R*R/R0R"((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyt
map_add_av�s*
cCsD|dfg}|j|j}t|_xt|�dkr?|jd�\}}|j|j}||kr�x$|jD]}|j|||�qxW|jr�q+q�nx�|j �D]�} | j
|jkr�|jtd��dSy|| j
}
Wn.t
k
r$|jtd| j
��q�nX|j|
| f�q�Wq+WdS(Nii����sFound circular interface
classs#Missing interface definition for
%s(R9RwRRR`RQtpopRR�RltifnameR|RtKeyErrorRq(RRat
if_by_nametstackR�tcurt
cur_ifcalltcur_ifvR'REtnewif((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pytdo_expand_ifcalls�s*
cCsyi}x3tj|j�|j��D]}|||j<q%Wx6tj|j�|j��D]}|j||�q[WdS(N(R#R$RwR�RR�(RR�R�R�Ra((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyR��s
%%N(RRR9RR|R�R\R�R�R&R�R�R�R�R�(((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyRvLs # $((((((RRiR#RRRRRtsepolgeni18nRRR-R6R:RCRGRHRKR]Rv(((s9/usr/lib64/python2.7/site-packages/sepolgen/interfaces.pyt<module>s" , 9 Z