ó  c‰`c@sadZddddddddgZd d ljZd d ljjZd d lZd d lZd d lm Z d d l m Z d d lm Z d dl mZejdkZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdejjfd„ƒYZdejfd„ƒYZd„Zd„Zd„Zd„Zd S(s5Generic io_object handler, io specific check methods.tPY2t IO_ObjecttIO_Object_ContentHandlertIO_Object_XMLGeneratort check_portt check_tcpudptcheck_protocolt check_addressiÿÿÿÿN(t functions(tb2u(terrors(t FirewallErrort3cBsteZdZd ZdZgZiZiZd„Zd„Z d„Z d„Z d„Z d„Z d„Zd „ZRS( s; Abstract IO_Object as base for icmptype, service and zone s()cCs1d|_d|_d|_t|_t|_dS(Nt(tfilenametpathtnametFalsetdefaulttbuiltin(tself((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyt__init__1s     cCsGg}x4|jD])}|jtjt||dƒƒƒqWt|ƒS(Ni(tIMPORT_EXPORT_STRUCTUREtappendtcopytdeepcopytgetattrttuple(Rtrettx((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyt export_config8s'cCsÓ|j|ƒx¿t|jƒD]®\}\}}t||tƒr®g}tƒ}x;||D]/}||kr\|j|ƒ|j|ƒq\q\W~t||t j |ƒƒqt||t j ||ƒƒqWdS(N( t check_configt enumerateRt isinstancetlisttsetRtaddtsetattrRR(Rtconftitelementtdummyt_conft_setR((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyt import_config>s "   cCs´t|tƒs=ttjd|tdƒt|ƒfƒ‚nt|ƒdkrdttjdƒ‚nxI|D]A}|jƒ rk||j krkttjd||fƒ‚qkqkWdS(Ns'%s' not of type %s, but %sR isname can't be emptys'%s' is not allowed in '%s'( R!tstrR R t INVALID_TYPEttypetlent INVALID_NAMEtisalnumtADDITIONAL_ALNUM_CHARS(RRtchar((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyt check_nameNs  cCs›t|ƒt|jƒkrIttjdt|ƒt|jƒfƒ‚nxKt|jƒD]:\}\}}|j|||ƒ|j|||ƒqYWdS(Ns structure size mismatch %d != %d(R0RR R R.R t_check_config_structuret _check_config(RR&R'R(tvalue((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyR[s""cCsdS(N((Rtdummy1tdummy2((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyR7esc Cst|ƒt|ƒksFttjd|t|ƒt|ƒfƒ‚nt|tƒr¨t|ƒdkr€ttjd|ƒ‚nx||D]}|j||dƒq‡WnWt|tƒr(t|ƒt|ƒkrôttjd|t|ƒfƒ‚nxt |ƒD] \}}|j|||ƒqWn×t|t ƒrÿt|j ƒƒd\}}x©|j ƒD]˜\}}t|ƒt|ƒkr²ttjd|t|ƒt|ƒfƒ‚nt|ƒt|ƒkr`ttjd|t|ƒt|ƒfƒ‚q`q`WndS(Ns'%s' not of type %s, but %sislen('%s') != 1islen('%s') != %d( R/R R R.R!R"R0R6RR tdicttitems( RR&t structureRR'R8tskeytsvaluetkey((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyR6is8 "    " cCs,|jƒ}t}||jkrt}|j|dk rxP|j|D]>}||krj|j|ƒqHttjd||fƒ‚qHWqn||j krÜt}x4|j |D]"}||kr³|j|ƒq³q³Wn|sûttjd|ƒ‚nx*|D]"}ttjd||fƒ‚qWdS(NsMissing attribute %s for %ssUnexpected element %ss%s: Unexpected attribute %s( tgetNamesRtPARSER_REQUIRED_ELEMENT_ATTRStTruetNonetremoveR R t PARSE_ERRORtPARSER_OPTIONAL_ELEMENT_ATTRS(RRtattrst_attrstfoundR((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pytparser_check_element_attrsŠs,      ((t__name__t __module__t__doc__RtDBUS_SIGNATURER3RBRGRRR,R5RR7R6RK(((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyR(s     !tUnexpectedElementErrorcBseZd„Zd„ZRS(cCs tt|ƒjƒ||_dS(N(tsuperRPRR(RR((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyR¨scCs d|jS(NsUnexpected element '%s'(R(R((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyt__str__«s(RLRMRRR(((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRP§s tMissingAttributeErrorcBseZd„Zd„ZRS(cCs)tt|ƒjƒ||_||_dS(N(RQRSRRt attribute(RRRT((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyR¯s cCsd|j|jfS(Ns$Element '%s': missing '%s' attribute(RRT(R((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRR³s(RLRMRRR(((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRS®s tUnexpectedAttributeErrorcBseZd„Zd„ZRS(cCs)tt|ƒjƒ||_||_dS(N(RQRURRRT(RRRT((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyR¸s cCsd|j|jfS(Ns'Element '%s': unexpected attribute '%s'(RRT(R((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRR¼s(RLRMRRR(((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRU·s cBs5eZd„Zd„Zd„Zd„Zd„ZRS(cCs||_d|_dS(NR (titemt_element(RRV((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRÁs cCs d|_dS(NR (RW(R((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyt startDocumentÅscCs d|_dS(NR (RW(RRRH((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyt startElementÈscCs@|dkr|j|j_n|dkr<|j|j_ndS(Ntshortt description(RWRVRZR[(RR((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyt endElementËs  cCs|j|jddƒ7_dS(Ns t (RWtreplace(Rtcontent((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyt charactersÑs(RLRMRRXRYR\R`(((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRÀs     cBs>eZd„Zd„Zd„Zd„Zd„Zd„ZRS(cCsotjjj|ƒ|j|_|j|_ig|_|jd|_ g|_ d|_ t |_ t |_dS(Niÿÿÿÿsutf-8(tsaxthandlertContentHandlerRtwritet_writetflusht_flusht _ns_contextst_current_contextt_undeclared_ns_mapst _encodingRt_pending_start_elementt_short_empty_elements(Rtout((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRÕs      cCs9trd„|jƒDƒ}ntjj|||ƒdS(s saxutils.XMLGenerator.startElement() expects name and attrs to be unicode and bad things happen if any of them is (utf-8) encoded. We override the method here to sanitize this case. Can be removed once we drop Python2 support. cSs+i|]!\}}t|ƒt|ƒ“qS((R (t.0RR8((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pys ís N(RR<tsaxutilst XMLGeneratorRY(RRRH((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRYæscCsÕtrv|jdt|ƒƒxF|jƒD]8\}}|jdt|ƒtjt|ƒƒfƒq*W|jdƒn[|jd|ƒx:|jƒD],\}}|jd|tj|ƒfƒq”W|jdƒdS(s* slightly modified startElement() utN(RReR R<Rpt quoteattr(RRRHR8((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyt simpleElementðs$cCstjj|t|ƒƒdS(sú saxutils.XMLGenerator.endElement() expects name to be unicode and bad things happen if it's (utf-8) encoded. We override the method here to sanitize this case. Can be removed once we drop Python2 support. N(RpRqR\R (RR((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyR\ÿscCstjj|t|ƒƒdS(sý saxutils.XMLGenerator.characters() expects content to be unicode and bad things happen if it's (utf-8) encoded. We override the method here to sanitize this case. Can be removed once we drop Python2 support. N(RpRqR`R (RR_((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyR`scCstjj|t|ƒƒdS(s saxutils.XMLGenerator.ignorableWhitespace() expects content to be unicode and bad things happen if it's (utf-8) encoded. We override the method here to sanitize this case. Can be removed once we drop Python2 support. N(RpRqtignorableWhitespaceR (RR_((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRus(RLRMRRYRtR\R`Ru(((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRÔs     cCsÁtj|ƒ}|dkr4ttjd|ƒ‚n‰|dkrYttjd|ƒ‚nd|dkr~ttjd|ƒ‚n?t|ƒdkr½|d|dkr½ttjd|ƒ‚ndS( Niþÿÿÿsport number in '%s' is too bigiÿÿÿÿs'%s' is invalid port rangesport range '%s' is ambiguousiii(Rt getPortRangeR R t INVALID_PORTRDR0(tportt port_range((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRs      & cCs)|dkr%ttjd|ƒ‚ndS(Nttcptudptsctptdccps)'%s' not from {'tcp'|'udp'|'sctp'|'dccp'}(RzR{R|R}(R R tINVALID_PROTOCOL(tprotocol((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyR&s  cCs(tj|ƒs$ttj|ƒ‚ndS(N(Rt checkProtocolR R R~(R((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyR,scCs5tj||ƒs1ttjd||fƒ‚ndS(Ns'%s' is not valid %s address(RRR R t INVALID_ADDR(tipvtaddr((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyR0s ( RNt__all__txml.saxRatxml.sax.saxutilsRpRtsystfirewallRtfirewall.functionsR R tfirewall.errorsR tversionRtobjectRt ExceptionRPRSRURbRcRRqRRRRR(((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyts,     C