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 mZejdkZdefdYZdefdYZdefdYZdefdYZdejjfdYZdejfdYZdZdZdZdZd S(s5Generic io_object handler, io specific check methods.tPY2t IO_ObjecttIO_Object_ContentHandlertIO_Object_XMLGeneratort check_portt check_tcpudptcheck_protocolt check_addressiN(t functions(tb2u(terrors(t FirewallErrort3cBsteZdZd ZdZgZiZiZdZdZ dZ dZ dZ dZ dZd 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||dqWt|S(Ni(tIMPORT_EXPORT_STRUCTUREtappendtcopytdeepcopytgetattrttuple(Rtrettx((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyt export_config8s'cCs|j|xt|jD]\}\}}t||trg}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 "   cCst|ts=ttjd|tdt|fnt|dkrdttjdnxI|D]A}|j rk||j krkttjd||fqkqkWdS(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  cCst|t|jkrIttjdt|t|jfnxKt|jD]:\}\}}|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|fnt|trt|dkrttjd|nx||D]}|j||dqWnWt|tr(t|t|krttjd|t|fnxt |D] \}}|j|||qWnt|t rt|j d\}}x|j D]\}}t|t|krttjd|t|t|fnt|t|kr`ttjd|t|t|fq`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||fqHWqn||j krt}x4|j |D]"}||kr|j|qqWn|sttjd|nx*|D]"}ttjd||fqWdS(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_attrss,      ((t__name__t __module__t__doc__RtDBUS_SIGNATURER3RBRGRRR,R5RR7R6RK(((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyR(s     !tUnexpectedElementErrorcBseZdZdZRS(cCs tt|j||_dS(N(tsuperRPRR(RR((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRscCs 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.pyRPs tMissingAttributeErrorcBseZdZdZRS(cCs)tt|j||_||_dS(N(RQRSRRt attribute(RRRT((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRs cCsd|j|jfS(Ns$Element '%s': missing '%s' attribute(RRT(R((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRRs(RLRMRRR(((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRSs tUnexpectedAttributeErrorcBseZdZdZRS(cCs)tt|j||_||_dS(N(RQRURRRT(RRRT((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRs cCsd|j|jfS(Ns'Element '%s': unexpected attribute '%s'(RRT(R((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRRs(RLRMRRR(((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRUs cBs5eZdZdZdZdZdZRS(cCs||_d|_dS(NR (titemt_element(RRV((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRs cCs d|_dS(NR (RW(R((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyt startDocumentscCs d|_dS(NR (RW(RRRH((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyt startElementscCs@|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 endElements  cCs|j|jdd7_dS(Ns t (RWtreplace(Rtcontent((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyt characterss(RLRMRRXRYR\R`(((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyRs     cBs>eZdZdZdZdZdZdZRS(cCsotjjj||j|_|j|_ig|_|jd|_ g|_ d|_ t |_ t |_dS(Nisutf-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.pyRs      cCs9trd|jD}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.pyRYscCstrv|jdt|xF|jD]8\}}|jdt|tjt|fq*W|jdn[|jd|x:|jD],\}}|jd|tj|fqW|jddS(s* slightly modified startElement() utN(RReR R<Rpt quoteattr(RRRHR8((s>/usr/lib/python2.7/site-packages/firewall/core/io/io_object.pyt simpleElements$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.pyRs     cCstj|}|dkr4ttjd|n|dkrYttjd|nd|dkr~ttjd|n?t|dkr|d|dkrttjd|ndS( Nisport number in '%s' is too bigis'%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||fndS(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