c`c@sdddgZddljZddlZddlZddlZddlmZddlm Z ddl m Z m Z m Z mZmZmZddlmZdd lmZdd lmZde fd YZd e fd YZdZddZdS(tHelpert helper_readert helper_writeriN(tconfig(t u2b_if_py2(tPY2t IO_ObjecttIO_Object_ContentHandlertIO_Object_XMLGeneratort check_portt check_tcpudp(tlog(terrors(t FirewallErrorcBseZdddddddgffZdZdd gZidd6dd6dgd 6Zid ddgd 6d d gd 6ZdZdZ dZ dZ dZ RS(tversionttshortt descriptiontfamilytmoduletportss (sssssa(ss))t-t.thelpertnametporttprotocolcCsMtt|jd|_d|_d|_d|_d|_g|_dS(NR( tsuperRt__init__RRRRRR(tself((s;/usr/lib/python2.7/site-packages/firewall/core/io/helper.pyR;s     cCs8d|_d|_d|_d|_d|_|j2dS(NR(RRRRRR(R((s;/usr/lib/python2.7/site-packages/firewall/core/io/helper.pytcleanupDs      cCst|j|_t|j|_t|j|_t|j|_t|j|_g|jD]$\}}t|t|f^qd|_dS(s HACK. I haven't been able to make sax parser return strings encoded (because of python 2) instead of in unicode. Get rid of it once we throw out python 2 support.N(RRRRRRR(Rtpotpr((s;/usr/lib/python2.7/site-packages/firewall/core/io/helper.pytencode_stringsLs cCs;ddg}||kr7ttjd||fndS(Ntipv4tipv6s'%s' not in '%s'(R R t INVALID_IPV(Rtipvtipvs((s;/usr/lib/python2.7/site-packages/firewall/core/io/helper.pyt check_ipvWs   cCs|dkr<x|D]"}t|dt|dqWnn|dkr|jdspttjd|nt|jdddkrttjd|qndS( NRiiRt nf_conntrack_s('%s' does not start with 'nf_conntrack_'RsModule name '%s' too short(R R t startswithR R tINVALID_MODULEtlentreplace(RRtitemR((s;/usr/lib/python2.7/site-packages/firewall/core/io/helper.pyt _check_config]s    (sversionR(sshortR(s descriptionR(sfamilyR(smoduleR(RRN( t__name__t __module__tIMPORT_EXPORT_STRUCTUREtDBUS_SIGNATUREtADDITIONAL_ALNUM_CHARStNonetPARSER_REQUIRED_ELEMENT_ATTRStPARSER_OPTIONAL_ELEMENT_ATTRSRRR!R'R.(((s;/usr/lib/python2.7/site-packages/firewall/core/io/helper.pyR&s(    thelper_ContentHandlercBseZdZRS(cCstj||||jj|||dkrd|krQ|d|j_nd|kr|jj|d|d|j_nd|kr|djdstt j d|dnt |dj dddkrtt j d |dn|d|j_ qn|d kr$n|d kr3n|d krt|d t|d |d |d f}||jjkr|jjj|qtjd|d |d ndS(NRRRRR(s('%s' does not start with 'nf_conntrack_'RisModule name '%s' too shortRRRRs#Port '%s/%s' already set, ignoring.(Rt startElementR-tparser_check_element_attrsRR'RR)R R R*R+R,RR R RtappendR twarning(RRtattrstentry((s;/usr/lib/python2.7/site-packages/firewall/core/io/helper.pyR8ns>    "    (R/R0R8(((s;/usr/lib/python2.7/site-packages/firewall/core/io/helper.pyR7msc CsYt}|jds1ttjd|n|d |_|j|j||_||_|j t j rxt nt |_|j|_t|}tj}|j|d||f}t|di}tjd}|j|y|j|Wn2tjk r5}ttjd|jnXWdQX~~trU|jn|S(Ns.xmls'%s' is missing .xml suffixis%s/%strbsnot a valid helper file: %s(RtendswithR R t INVALID_NAMERt check_nametfilenametpathR)Rt ETC_FIREWALLDtFalsetTruetbuiltintdefaultR7tsaxt make_parsertsetContentHandlertopent InputSourceR4t setByteStreamtparsetSAXParseExceptiontINVALID_HELPERt getExceptionRR!( RBRCRthandlertparserRtftsourcetmsg((s;/usr/lib/python2.7/site-packages/firewall/core/io/helper.pyRs8     !       c Cs|r |n|j}|jr4d||jf}nd||jf}tjj|rytj|d|Wqtk r}tj d||qXntjj |}|j t j rtjj| rtjjt j stjt j dntj|dntj|dddd }t|}|ji}|j|d <|jr~|jd kr~|j|d s   .G#