__pycache__/__init__.cpython-36.opt-1.pyc000064400000007026147205146620014114 0ustar003 ft`@sddlmZddlmZddlmZddlmZddlZddl Zddl Z ddZ d d Z d d Z e dJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dEZdFdGZdHdIZdS)a)absolute_import)unicode_literals) transaction) is_py3bytesNc )Cstj|d}|jtjtjBxztjjD]l}tj j rDt |d}y|j d|}Wn<t tjfk r}ztjjdt|WYdd}~XnXt|sq,y t|}Wn$tk rd}tjj|YnX|d}yy|tjj|}Wn,tk r|tjj|jd}YnX|tj|} |tj|} | tjkrd| rd|d ||jdfkrd| }Wntttfk rYnXt|rt|d}|SWdS) z-Calculate the release version for the system.)rootzutf-8Zprovidesz Error: %sNz:Error: rpmdb failed to list provides. Try: rpm --rebuilddbversionutf8name)rinitReadOnlyTransactionZ pushVSFlagsrpmZ_RPMVSF_NOSIGNATURESZ_RPMVSF_NODIGESTSdnfconstZ DISTROVERPKGZpycompZPY3bytesZdbMatch TypeErrorerror exceptionsErrorstrlennext StopIterationZRPMTAG_PROVIDENAMEindex ValueErrordecodeZRPMTAG_PROVIDEFLAGSZRPMTAG_PROVIDEVERSIONZRPMSENSE_EQUALKeyError IndexErrorr) Z installroottsZ distroverpkgidxehdrmsgZ releaseverZoffflagZverr#/usr/lib/python3.6/__init__.pydetect_releaseversB  &   r%cCsptj}t|V}|j}y|j|}Wn8tjk r`}ztjj dj ||WYdd}~XnX|SQRXdS)zReturn RPM header of the file.z {0}: '{1}'N) rr openfilenoZ hdrFromFdnor rr rrformat)pathrpackageZfdnor rr#r#r$_headerIs &r+csfddDS)Ncs i|]}|D] }||qqSr#r#).0kv)dctr#r$ Vsz_invert..r#)r/r#)r/r$_invertUsr1aarch64alphaalphaev4 alphaev45alphaev5 alphaev56alphaev6 alphaev67 alphaev68alphaev7 alphapca56 armv5tejlarmv5telarmv5tlarmv6larmv7larmv8larmv6hlarmv7hlarmv7hnlarmv8hli386athlongeodei486i586i686ia64mipsmipselmips64mips64elnoarchppcppc64 ppc64iseriesppc64p7 ppc64pseriesppc64leriscv32riscv64riscv128s390s390xsh3sh4sh4asparcsparc64sparc64vsparcv8sparcv9sparcv9vx86_64amd64ia32e)r2r3ZarmZarmhfprGrMrNrOrPrQrRrSrTrXrYrZr[r\r]r^r_rargcCst|S)N) _BASEARCH_MAP)Zarchr#r#r$basearchusrkcCs||}t|rt|d}|S)z Returns value of rpm_hdr[key] as a string. Rpm has switched from bytes to str and we need to handle both properly. zutf-8)rr)Zrpm_hdrkeyvaluer#r#r$ getheaderzs rn)r2) r3r4r5r6r7r8r9r:r;r<)r=r>r?r@rArB)rCrDrErF)rGrHrIrGrJrKrL)rM)rN)rO)rP)rQ)rR)rS)rTrUrVrW)rX)rY)rZ)r[)r\)r])r^)r_r`)rarbrcrdrerf)rgrhri)Z __future__rrrZ dnf.pycomprZ dnf.constr Zdnf.exceptionsr r%r+r1rjrkrnr#r#r#r$sJ    ,  __pycache__/__init__.cpython-36.pyc000064400000007026147205146620013155 0ustar003 ft`@sddlmZddlmZddlmZddlmZddlZddl Zddl Z ddZ d d Z d d Z e dJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dEZdFdGZdHdIZdS)a)absolute_import)unicode_literals) transaction) is_py3bytesNc )Cstj|d}|jtjtjBxztjjD]l}tj j rDt |d}y|j d|}Wn<t tjfk r}ztjjdt|WYdd}~XnXt|sq,y t|}Wn$tk rd}tjj|YnX|d}yy|tjj|}Wn,tk r|tjj|jd}YnX|tj|} |tj|} | tjkrd| rd|d ||jdfkrd| }Wntttfk rYnXt|rt|d}|SWdS) z-Calculate the release version for the system.)rootzutf-8Zprovidesz Error: %sNz:Error: rpmdb failed to list provides. Try: rpm --rebuilddbversionutf8name)rinitReadOnlyTransactionZ pushVSFlagsrpmZ_RPMVSF_NOSIGNATURESZ_RPMVSF_NODIGESTSdnfconstZ DISTROVERPKGZpycompZPY3bytesZdbMatch TypeErrorerror exceptionsErrorstrlennext StopIterationZRPMTAG_PROVIDENAMEindex ValueErrordecodeZRPMTAG_PROVIDEFLAGSZRPMTAG_PROVIDEVERSIONZRPMSENSE_EQUALKeyError IndexErrorr) Z installroottsZ distroverpkgidxehdrmsgZ releaseverZoffflagZverr#/usr/lib/python3.6/__init__.pydetect_releaseversB  &   r%cCsptj}t|V}|j}y|j|}Wn8tjk r`}ztjj dj ||WYdd}~XnX|SQRXdS)zReturn RPM header of the file.z {0}: '{1}'N) rr openfilenoZ hdrFromFdnor rr rrformat)pathrpackageZfdnor rr#r#r$_headerIs &r+csfddDS)Ncs i|]}|D] }||qqSr#r#).0kv)dctr#r$ Vsz_invert..r#)r/r#)r/r$_invertUsr1aarch64alphaalphaev4 alphaev45alphaev5 alphaev56alphaev6 alphaev67 alphaev68alphaev7 alphapca56 armv5tejlarmv5telarmv5tlarmv6larmv7larmv8larmv6hlarmv7hlarmv7hnlarmv8hli386athlongeodei486i586i686ia64mipsmipselmips64mips64elnoarchppcppc64 ppc64iseriesppc64p7 ppc64pseriesppc64leriscv32riscv64riscv128s390s390xsh3sh4sh4asparcsparc64sparc64vsparcv8sparcv9sparcv9vx86_64amd64ia32e)r2r3ZarmZarmhfprGrMrNrOrPrQrRrSrTrXrYrZr[r\r]r^r_rargcCst|S)N) _BASEARCH_MAP)Zarchr#r#r$basearchusrkcCs||}t|rt|d}|S)z Returns value of rpm_hdr[key] as a string. Rpm has switched from bytes to str and we need to handle both properly. zutf-8)rr)Zrpm_hdrkeyvaluer#r#r$ getheaderzs rn)r2) r3r4r5r6r7r8r9r:r;r<)r=r>r?r@rArB)rCrDrErF)rGrHrIrGrJrKrL)rM)rN)rO)rP)rQ)rR)rS)rTrUrVrW)rX)rY)rZ)r[)r\)r])r^)r_r`)rarbrcrdrerf)rgrhri)Z __future__rrrZ dnf.pycomprZ dnf.constr Zdnf.exceptionsr r%r+r1rjrkrnr#r#r#r$sJ    ,  __pycache__/connection.cpython-36.opt-1.pyc000064400000001432147205146620014507 0ustar003 ft`Y@s@ddlmZddlmZddlmZddlZGdddeZdS))absolute_import)unicode_literals)initReadOnlyTransactionNc@s,eZdZddZeejjdddZdS) RpmConnectioncCs ||_dS)N)root)selfrr /usr/lib/python3.6/connection.py__init__szRpmConnection.__init__Z _readonly_tscCs t|jS)N)rr)rr r r readonly_tsszRpmConnection.readonly_tsN) __name__ __module__ __qualname__r propertydnfutilZlazyattrr r r r r rsr) Z __future__rrZ transactionrZdnf.utilrobjectrr r r r s   __pycache__/connection.cpython-36.pyc000064400000001432147205146620013550 0ustar003 ft`Y@s@ddlmZddlmZddlmZddlZGdddeZdS))absolute_import)unicode_literals)initReadOnlyTransactionNc@s,eZdZddZeejjdddZdS) RpmConnectioncCs ||_dS)N)root)selfrr /usr/lib/python3.6/connection.py__init__szRpmConnection.__init__Z _readonly_tscCs t|jS)N)rr)rr r r readonly_tsszRpmConnection.readonly_tsN) __name__ __module__ __qualname__r propertydnfutilZlazyattrr r r r r rsr) Z __future__rrZ transactionrZdnf.utilrobjectrr r r r s   __pycache__/error.cpython-36.opt-1.pyc000064400000000422147205146620013477 0ustar003 ft`@sGdddeZdS)c@s eZdZdS) RpmUtilsErrorN)__name__ __module__ __qualname__rr/usr/lib/python3.6/error.pyrsrN) Exceptionrrrrrs__pycache__/error.cpython-36.pyc000064400000000422147205146620012540 0ustar003 ft`@sGdddeZdS)c@s eZdZdS) RpmUtilsErrorN)__name__ __module__ __qualname__rr/usr/lib/python3.6/error.pyrsrN) Exceptionrrrrrs__pycache__/miscutils.cpython-36.opt-1.pyc000064400000004642147205146620014372 0ustar003 f@svddlmZmZmZddlZddlZddlZddlmZddl m Z ej dZ da ddZdd Zd d Zd d ZdS))print_functionabsolute_importunicode_literalsN)which)_ZdnfcCs$tdkr tdatjtdttS)Nrpmkeysz3Using rpmkeys executable at %s to verify signatures)_rpmkeys_binaryr_loggerdebugrr r /usr/lib/python3.6/miscutils.py_find_rpmkeys_binarys  r cCst|dks |ddks |dr$dSd\}}}}x^|ddD]N}d|krNdS|jdr^d }q>|jd rnd }q>|jd r~d }q>|jd s>dSq>W|rdS|rdS|rd SdS)Nrs-:Fs: BADs: NOKEYTs : NOTTRUSTEDs : NOTFOUNDs: OK)FFFFr)lenendswith)dataZseen_sigZ missing_keyZ not_trustedZ not_signedir r r _process_rpm_output$s*      rc Cst}|dkstjj| r.tjtddSddd|dddd f}tj||d d itj d |d }|j d}WdQRX|j }t |t k rtd|dks|dkrdSt|jd}|r|S|rdSdS)Nz4Cannot find rpmkeys executable to verify signatures.rrz --checksigz--rootz --verbosez#--define=_pkgverify_level signaturez--define=_pkgverify_flags 0x0-LC_ALLC/)args executableenvstdoutcwdstdinrz Popen set return code to non-int )r ospathisfiler Zcriticalr subprocessPopenPIPEZ communicate returncodetypeintAssertionErrorrsplit)packageZ installrootZrpmkeys_binaryrprr)retr r r _verifyPackageUsingRpmkeys?s0   r1c Cs>tj|tjtjBtjB}zt||jj}Wdtj|X|S)a Takes a transaction set and a package, check it's sigs, return 0 if they are all fine return 1 if the gpg key can't be found return 2 if the header is in someway damaged return 3 if the key is not trusted return 4 if the pkg is not gpg or pgp signedN) r#openO_RDONLYO_NOCTTY O_CLOEXECr1tsZrootDirclose)r6r.Zfdnovaluer r r checkSig^s  r9)Z __future__rrrr#r&ZloggingZshutilrZdnf.i18nrZ getLoggerr rr rr1r9r r r r s   __pycache__/miscutils.cpython-36.pyc000064400000004642147205146620013433 0ustar003 f@svddlmZmZmZddlZddlZddlZddlmZddl m Z ej dZ da ddZdd Zd d Zd d ZdS))print_functionabsolute_importunicode_literalsN)which)_ZdnfcCs$tdkr tdatjtdttS)Nrpmkeysz3Using rpmkeys executable at %s to verify signatures)_rpmkeys_binaryr_loggerdebugrr r /usr/lib/python3.6/miscutils.py_find_rpmkeys_binarys  r cCst|dks |ddks |dr$dSd\}}}}x^|ddD]N}d|krNdS|jdr^d }q>|jd rnd }q>|jd r~d }q>|jd s>dSq>W|rdS|rdS|rd SdS)Nrs-:Fs: BADs: NOKEYTs : NOTTRUSTEDs : NOTFOUNDs: OK)FFFFr)lenendswith)dataZseen_sigZ missing_keyZ not_trustedZ not_signedir r r _process_rpm_output$s*      rc Cst}|dkstjj| r.tjtddSddd|dddd f}tj||d d itj d |d }|j d}WdQRX|j }t |t k rtd|dks|dkrdSt|jd}|r|S|rdSdS)Nz4Cannot find rpmkeys executable to verify signatures.rrz --checksigz--rootz --verbosez#--define=_pkgverify_level signaturez--define=_pkgverify_flags 0x0-LC_ALLC/)args executableenvstdoutcwdstdinrz Popen set return code to non-int )r ospathisfiler Zcriticalr subprocessPopenPIPEZ communicate returncodetypeintAssertionErrorrsplit)packageZ installrootZrpmkeys_binaryrprr)retr r r _verifyPackageUsingRpmkeys?s0   r1c Cs>tj|tjtjBtjB}zt||jj}Wdtj|X|S)a Takes a transaction set and a package, check it's sigs, return 0 if they are all fine return 1 if the gpg key can't be found return 2 if the header is in someway damaged return 3 if the key is not trusted return 4 if the pkg is not gpg or pgp signedN) r#openO_RDONLYO_NOCTTY O_CLOEXECr1tsZrootDirclose)r6r.Zfdnovaluer r r checkSig^s  r9)Z __future__rrrr#r&ZloggingZshutilrZdnf.i18nrZ getLoggerr rr rr1r9r r r r s   __pycache__/transaction.cpython-36.opt-1.pyc000064400000007150147205146620014700 0ustar003 ft`@sRddlmZddlmZddlmZddlZdZdZGdddeZ d dd Z dS) )absolute_import)unicode_literals)_Nc@szeZdZdddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZifddZdS)TransactionWrapper/cCs@tj||_ddddddddd d d d d ddg|_g|_d|_dS)NZcheckorderZaddEraseZ addInstallZ addReinstallrunZpgpImportPubkeyZ pgpPrtPktsZproblemssetFlags setVSFlags setProbFilterZ hdrFromFdnonextZcleanT)rpmZTransactionSetts_methodstsflagsopen)selfrootr!/usr/lib/python3.6/transaction.py__init__s$ zTransactionWrapper.__init__cCs |jdS)N)close)rrrr__del__+szTransactionWrapper.__del__cCs |jr|jjd|_d|_dS)NF)rrZcloseDB)rrrrr/s zTransactionWrapper.closecOsLd|kr|jd}ng}|jj||}x |D]\}}}|j|||q,W|S)Npatterns)poprdbMatchpattern)rargskwdsrZmitagtpZpatrrrr5s zTransactionWrapper.dbMatchcCs ||jkr|j|St|dS)N)r getMethodAttributeError)rattrrrr __getattr__@s  zTransactionWrapper.__getattr__cCs|jS)N)r)rrrr__iter__FszTransactionWrapper.__iter__cCs t|j|S)N)getattrr)rmethodrrrr!IszTransactionWrapper.getMethodcCs"|jj||jj|jddS)N)rappendrr )rflagsrrr pushVSFlagsQs zTransactionWrapper.pushVSFlagscCs |jjd}|jj||BdS)Nr)rr )rflagcurflagsrrr addTsFlagUs zTransactionWrapper.addTsFlagcCs|jjd}|jj||S)Nr)rr )rr.rrr getTsFlagsYs  zTransactionWrapper.getTsFlagscCs|j}t||@S)N)r0bool)rr-valrrr isTsFlagSet^szTransactionWrapper.isTsFlagSetcCs|j|j_dS)N)filenorZscriptFd)rfdrrr setScriptFdbszTransactionWrapper.setScriptFdc Cs|j}|jtj|jddkr0|jjtj|jj|j d}|jj |g}|dk rx |D]\}\}}} |j |q^W|s|j t d|S)zetests the ts we've setup, takes a callback function and a conf dict for flags and what notZdiskspacecheckrNz(Errors occurred during test transaction.) r0r/r ZRPMTRANS_FLAG_TESTgetrr ZRPMPROB_FILTER_DISKSPACErcallbackr r*r) rcbZconfZ origflagsZtserrorsZ reserrorsZdescretypeZmountZneedrrrtestes  zTransactionWrapper.testN)r)__name__ __module__ __qualname__rrrrr$r%r!r,r/r0r3r6r<rrrrrs  rrcCs t|d}|jtjtjB|S)N)r)rr,r Z_RPMVSF_NOSIGNATURESZ_RPMVSF_NODIGESTS)rread_tsrrrinitReadOnlyTransaction{s rA)r) Z __future__rrZdnf.i18nrr r@robjectrrArrrr s   e__pycache__/transaction.cpython-36.pyc000064400000007150147205146620013741 0ustar003 ft`@sRddlmZddlmZddlmZddlZdZdZGdddeZ d dd Z dS) )absolute_import)unicode_literals)_Nc@szeZdZdddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZifddZdS)TransactionWrapper/cCs@tj||_ddddddddd d d d d ddg|_g|_d|_dS)NZcheckorderZaddEraseZ addInstallZ addReinstallrunZpgpImportPubkeyZ pgpPrtPktsZproblemssetFlags setVSFlags setProbFilterZ hdrFromFdnonextZcleanT)rpmZTransactionSetts_methodstsflagsopen)selfrootr!/usr/lib/python3.6/transaction.py__init__s$ zTransactionWrapper.__init__cCs |jdS)N)close)rrrr__del__+szTransactionWrapper.__del__cCs |jr|jjd|_d|_dS)NF)rrZcloseDB)rrrrr/s zTransactionWrapper.closecOsLd|kr|jd}ng}|jj||}x |D]\}}}|j|||q,W|S)Npatterns)poprdbMatchpattern)rargskwdsrZmitagtpZpatrrrr5s zTransactionWrapper.dbMatchcCs ||jkr|j|St|dS)N)r getMethodAttributeError)rattrrrr __getattr__@s  zTransactionWrapper.__getattr__cCs|jS)N)r)rrrr__iter__FszTransactionWrapper.__iter__cCs t|j|S)N)getattrr)rmethodrrrr!IszTransactionWrapper.getMethodcCs"|jj||jj|jddS)N)rappendrr )rflagsrrr pushVSFlagsQs zTransactionWrapper.pushVSFlagscCs |jjd}|jj||BdS)Nr)rr )rflagcurflagsrrr addTsFlagUs zTransactionWrapper.addTsFlagcCs|jjd}|jj||S)Nr)rr )rr.rrr getTsFlagsYs  zTransactionWrapper.getTsFlagscCs|j}t||@S)N)r0bool)rr-valrrr isTsFlagSet^szTransactionWrapper.isTsFlagSetcCs|j|j_dS)N)filenorZscriptFd)rfdrrr setScriptFdbszTransactionWrapper.setScriptFdc Cs|j}|jtj|jddkr0|jjtj|jj|j d}|jj |g}|dk rx |D]\}\}}} |j |q^W|s|j t d|S)zetests the ts we've setup, takes a callback function and a conf dict for flags and what notZdiskspacecheckrNz(Errors occurred during test transaction.) r0r/r ZRPMTRANS_FLAG_TESTgetrr ZRPMPROB_FILTER_DISKSPACErcallbackr r*r) rcbZconfZ origflagsZtserrorsZ reserrorsZdescretypeZmountZneedrrrtestes  zTransactionWrapper.testN)r)__name__ __module__ __qualname__rrrrr$r%r!r,r/r0r3r6r<rrrrrs  rrcCs t|d}|jtjtjB|S)N)r)rr,r Z_RPMVSF_NOSIGNATURESZ_RPMVSF_NODIGESTS)rread_tsrrrinitReadOnlyTransaction{s rA)r) Z __future__rrZdnf.i18nrr r@robjectrrArrrr s   e__init__.py000064400000011300147205146620006657 0ustar00# __init__.py # # Copyright (C) 2012-2016 Red Hat, Inc. # # This copyrighted material is made available to anyone wishing to use, # modify, copy, or redistribute it subject to the terms and conditions of # the GNU General Public License v.2, or (at your option) any later version. # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY expressed or implied, including the implied warranties 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., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. Any Red Hat trademarks that are incorporated in the # source code or documentation are not subject to the GNU General Public # License and may only be used or replicated with the express permission of # Red Hat, Inc. # from __future__ import absolute_import from __future__ import unicode_literals from . import transaction from dnf.pycomp import is_py3bytes import dnf.const import dnf.exceptions import rpm # used by ansible (dnf.rpm.rpm.labelCompare in lib/ansible/modules/packaging/os/dnf.py) def detect_releasever(installroot): # :api """Calculate the release version for the system.""" ts = transaction.initReadOnlyTransaction(root=installroot) ts.pushVSFlags(~(rpm._RPMVSF_NOSIGNATURES | rpm._RPMVSF_NODIGESTS)) for distroverpkg in dnf.const.DISTROVERPKG: if dnf.pycomp.PY3: distroverpkg = bytes(distroverpkg, 'utf-8') try: idx = ts.dbMatch('provides', distroverpkg) except (TypeError, rpm.error) as e: raise dnf.exceptions.Error('Error: %s' % str(e)) if not len(idx): continue try: hdr = next(idx) except StopIteration: msg = 'Error: rpmdb failed to list provides. Try: rpm --rebuilddb' raise dnf.exceptions.Error(msg) releasever = hdr['version'] try: try: # header returns bytes -> look for bytes # it may fail because rpm returns a decoded string since 10 Apr 2019 off = hdr[rpm.RPMTAG_PROVIDENAME].index(distroverpkg) except ValueError: # header returns a string -> look for a string off = hdr[rpm.RPMTAG_PROVIDENAME].index(distroverpkg.decode("utf8")) flag = hdr[rpm.RPMTAG_PROVIDEFLAGS][off] ver = hdr[rpm.RPMTAG_PROVIDEVERSION][off] if flag == rpm.RPMSENSE_EQUAL and ver: if hdr['name'] not in (distroverpkg, distroverpkg.decode("utf8")): # override the package version releasever = ver except (ValueError, KeyError, IndexError): pass if is_py3bytes(releasever): releasever = str(releasever, "utf-8") return releasever return None def _header(path): """Return RPM header of the file.""" ts = transaction.initReadOnlyTransaction() with open(path) as package: fdno = package.fileno() try: hdr = ts.hdrFromFdno(fdno) except rpm.error as e: raise dnf.exceptions.Error("{0}: '{1}'".format(e, path)) return hdr def _invert(dct): return {v: k for k in dct for v in dct[k]} _BASEARCH_MAP = _invert({ 'aarch64': ('aarch64',), 'alpha': ('alpha', 'alphaev4', 'alphaev45', 'alphaev5', 'alphaev56', 'alphaev6', 'alphaev67', 'alphaev68', 'alphaev7', 'alphapca56'), 'arm': ('armv5tejl', 'armv5tel', 'armv5tl', 'armv6l', 'armv7l', 'armv8l'), 'armhfp': ('armv6hl', 'armv7hl', 'armv7hnl', 'armv8hl'), 'i386': ('i386', 'athlon', 'geode', 'i386', 'i486', 'i586', 'i686'), 'ia64': ('ia64',), 'mips': ('mips',), 'mipsel': ('mipsel',), 'mips64': ('mips64',), 'mips64el': ('mips64el',), 'noarch': ('noarch',), 'ppc': ('ppc',), 'ppc64': ('ppc64', 'ppc64iseries', 'ppc64p7', 'ppc64pseries'), 'ppc64le': ('ppc64le',), 'riscv32' : ('riscv32',), 'riscv64' : ('riscv64',), 'riscv128' : ('riscv128',), 's390': ('s390',), 's390x': ('s390x',), 'sh3': ('sh3',), 'sh4': ('sh4', 'sh4a'), 'sparc': ('sparc', 'sparc64', 'sparc64v', 'sparcv8', 'sparcv9', 'sparcv9v'), 'x86_64': ('x86_64', 'amd64', 'ia32e'), }) def basearch(arch): # :api return _BASEARCH_MAP[arch] def getheader(rpm_hdr, key): ''' Returns value of rpm_hdr[key] as a string. Rpm has switched from bytes to str and we need to handle both properly. ''' value = rpm_hdr[key] if is_py3bytes(value): value = str(value, "utf-8") return value connection.py000064400000002531147205146620007265 0ustar00# connection.py # Maintain RPMDB connections. # # Copyright (C) 2012-2016 Red Hat, Inc. # # This copyrighted material is made available to anyone wishing to use, # modify, copy, or redistribute it subject to the terms and conditions of # the GNU General Public License v.2, or (at your option) any later version. # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY expressed or implied, including the implied warranties 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., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. Any Red Hat trademarks that are incorporated in the # source code or documentation are not subject to the GNU General Public # License and may only be used or replicated with the express permission of # Red Hat, Inc. # from __future__ import absolute_import from __future__ import unicode_literals from .transaction import initReadOnlyTransaction import dnf.util class RpmConnection(object): def __init__(self, root): self.root = root @property @dnf.util.lazyattr("_readonly_ts") def readonly_ts(self): return initReadOnlyTransaction(self.root) error.py000064400000002006147205146620006254 0ustar00# error.py # RpmUtilsError # # Copyright (C) 2012-2016 Red Hat, Inc. # # This copyrighted material is made available to anyone wishing to use, # modify, copy, or redistribute it subject to the terms and conditions of # the GNU General Public License v.2, or (at your option) any later version. # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY expressed or implied, including the implied warranties 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., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. Any Red Hat trademarks that are incorporated in the # source code or documentation are not subject to the GNU General Public # License and may only be used or replicated with the express permission of # Red Hat, Inc. # class RpmUtilsError(Exception): pass miscutils.py000064400000007433147205146620007150 0ustar00# 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; either version 2 of the License, or # (at your option) any later version. # # 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 Library 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Copyright 2003 Duke University from __future__ import print_function, absolute_import, unicode_literals import os import subprocess import logging from shutil import which from dnf.i18n import _ _logger = logging.getLogger('dnf') _rpmkeys_binary = None def _find_rpmkeys_binary(): global _rpmkeys_binary if _rpmkeys_binary is None: _rpmkeys_binary = which("rpmkeys") _logger.debug(_('Using rpmkeys executable at %s to verify signatures'), _rpmkeys_binary) return _rpmkeys_binary def _process_rpm_output(data): # No signatures or digests = corrupt package. # There is at least one line for -: and another (empty) entry after the # last newline. if len(data) < 3 or data[0] != b'-:' or data[-1]: return 2 seen_sig, missing_key, not_trusted, not_signed = False, False, False, False for i in data[1:-1]: if b': BAD' in i: return 2 elif i.endswith(b': NOKEY'): missing_key = True elif i.endswith(b': NOTTRUSTED'): not_trusted = True elif i.endswith(b': NOTFOUND'): not_signed = True elif not i.endswith(b': OK'): return 2 if not_trusted: return 3 elif missing_key: return 1 elif not_signed: return 4 # we still check return code, so this is safe return 0 def _verifyPackageUsingRpmkeys(package, installroot): rpmkeys_binary = _find_rpmkeys_binary() if rpmkeys_binary is None or not os.path.isfile(rpmkeys_binary): _logger.critical(_('Cannot find rpmkeys executable to verify signatures.')) return 2 # "--define=_pkgverify_level signature" enforces signature checking; # "--define=_pkgverify_flags 0x0" ensures that all signatures are checked. args = ('rpmkeys', '--checksig', '--root', installroot, '--verbose', '--define=_pkgverify_level signature', '--define=_pkgverify_flags 0x0', '-') with subprocess.Popen( args=args, executable=rpmkeys_binary, env={'LC_ALL': 'C'}, stdout=subprocess.PIPE, cwd='/', stdin=package) as p: data = p.communicate()[0] returncode = p.returncode if type(returncode) is not int: raise AssertionError('Popen set return code to non-int') # rpmkeys can return something other than 0 or 1 in the case of a # fatal error (OOM, abort() called, SIGSEGV, etc) if returncode >= 2 or returncode < 0: return 2 ret = _process_rpm_output(data.split(b'\n')) if ret: return ret return 2 if returncode else 0 def checkSig(ts, package): """Takes a transaction set and a package, check it's sigs, return 0 if they are all fine return 1 if the gpg key can't be found return 2 if the header is in someway damaged return 3 if the key is not trusted return 4 if the pkg is not gpg or pgp signed""" fdno = os.open(package, os.O_RDONLY|os.O_NOCTTY|os.O_CLOEXEC) try: value = _verifyPackageUsingRpmkeys(fdno, ts.ts.rootDir) finally: os.close(fdno) return value transaction.py000064400000007353147205146620007462 0ustar00# # Client code for Update Agent # Copyright (c) 1999-2002 Red Hat, Inc. Distributed under GPL. # # Adrian Likins # Some Edits by Seth Vidal # # a couple of classes wrapping up transactions so that we # can share transactions instead of creating new ones all over # from __future__ import absolute_import from __future__ import unicode_literals from dnf.i18n import _ import rpm read_ts = None ts = None # wrapper/proxy class for rpm.Transaction so we can # instrument it, etc easily class TransactionWrapper(object): def __init__(self, root='/'): self.ts = rpm.TransactionSet(root) self._methods = ['check', 'order', 'addErase', 'addInstall', 'addReinstall', 'run', 'pgpImportPubkey', 'pgpPrtPkts', 'problems', 'setFlags', 'setVSFlags', 'setProbFilter', 'hdrFromFdno', 'next', 'clean'] self.tsflags = [] self.open = True def __del__(self): # Automatically close the rpm transaction when the reference is lost self.close() def close(self): if self.open: self.ts.closeDB() self.ts = None self.open = False def dbMatch(self, *args, **kwds): if 'patterns' in kwds: patterns = kwds.pop('patterns') else: patterns = [] mi = self.ts.dbMatch(*args, **kwds) for (tag, tp, pat) in patterns: mi.pattern(tag, tp, pat) return mi def __getattr__(self, attr): if attr in self._methods: return self.getMethod(attr) else: raise AttributeError(attr) def __iter__(self): return self.ts def getMethod(self, method): # in theory, we can override this with # profile/etc info return getattr(self.ts, method) # push/pop methods so we dont lose the previous # set value, and we can potentiall debug a bit # easier def pushVSFlags(self, flags): self.tsflags.append(flags) self.ts.setVSFlags(self.tsflags[-1]) def addTsFlag(self, flag): curflags = self.ts.setFlags(0) self.ts.setFlags(curflags | flag) def getTsFlags(self): curflags = self.ts.setFlags(0) self.ts.setFlags(curflags) return curflags def isTsFlagSet(self, flag): val = self.getTsFlags() return bool(flag & val) def setScriptFd(self, fd): self.ts.scriptFd = fd.fileno() def test(self, cb, conf={}): """tests the ts we've setup, takes a callback function and a conf dict for flags and what not""" origflags = self.getTsFlags() self.addTsFlag(rpm.RPMTRANS_FLAG_TEST) # FIXME GARBAGE - remove once this is reimplemented elsewhere # KEEPING FOR API COMPLIANCE ONLY if conf.get('diskspacecheck') == 0: self.ts.setProbFilter(rpm.RPMPROB_FILTER_DISKSPACE) tserrors = self.ts.run(cb.callback, '') self.ts.setFlags(origflags) reserrors = [] if tserrors is not None: for (descr, (etype, mount, need)) in tserrors: reserrors.append(descr) if not reserrors: reserrors.append(_('Errors occurred during test transaction.')) return reserrors def initReadOnlyTransaction(root='/'): read_ts = TransactionWrapper(root=root) read_ts.pushVSFlags((rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS)) return read_ts