F8a_@sddljjZddlmZddlZddljZddl Z ddl Z ddl Z ddl ZddlZddlZGdddejZGdddejZdS)N)lint_fmri_successorcseZdZdZdZfddZddZddd Zd d Zd d Z ddZ ddZ dddZ e de _dddZe de_dddZe de_S)UserlandActionCheckerz3An opensolaris.org-specific class to check actions.zuserland.actioncs%td|_tjd}|dkr<|j|_n d|_dddddg|_dd d d d g|_tj d tj dtj dg|_ tj dtj dtj dtj dtj dg|_ tj d|_ i|_ i|_tt|j|dS)Nz2checks Userland packages for common content errorsZ PROTO_PATHZi86Zsparcv7Z32zi86pc-solaris-64intzsun4-solaris-64intamd64Zsparcv964zi86pc-solaris-thread-multi-64zsun4-solaris-thread-multi-64z ^/lib(/.*)?$z^/usr/z ^\$ORIGIN/z ^.*/64(/.*)?$z^.*/amd64(/.*)?$z^.*/sparcv9(/.*)?$z^.*/i86pc-solaris-64(/.*)?$z^.*/sun4-solaris-64(/.*)?$z^etc/(rc.|init)\.d)_ descriptionosgetenvsplit proto_path pathlist32 pathlist64recompile runpath_re runpath_64_re initscript_re lint_paths ref_pathssuperr__init__)selfconfigpath) __class__D/jenkins/jobs/oi-userland/workspace/tools/python/pkglint/userland.pyr-s8             zUserlandActionChecker.__init__csdddd}i}xQ|j|jd|jd|jD]+}|j|jjgj|jq=Wx6|jD]+}|j|jjgj|jqvW|j j t dxj|j|j d|jD]Mt fdd |jjjgDs|d |jqW|j j t d x?|j|jd|jd|jD]|d |jqcW|j j t d x$|jD]|d |jqW|j|j|jd |jdS)zInitialize the checker with a dictionary of paths, so that we can do link resolution. This is copied from the core pkglint code, but should eventually be made common. NFc Ss|j}|r1dd|j|D}ndd|jD}x|D]}|ro|j|kroqQ||jkrqQ|j}|j||jj||j|} |j| gj |j |fqQWdS)zUpdates a dictionary of { attr: [(fmri, action), ..]} where attr is the value of that attribute from actions of a given type atype, in the given manifest.css|] }|VqdS)Nr).0arrr kszCUserlandActionChecker.startup..seed_dict..css|] }|VqdS)Nr)rrrrrrmsN) get_all_variantsgen_actions_by_type gen_actionsnameattrsget_variant_template merge_unknownupdate setdefaultappendfmri) mfattrdicatypeverbosepkg_varsZmfgactionvariantsprrr seed_dictbs     z0UserlandActionChecker.startup..seed_dictreleasepatternz+Seeding reference action path dictionaries.c3s!|]}t|jVqdS)N)rr*)rr*)manifestrrrsz0UserlandActionChecker.startup..rz&Seeding lint action path dictionaries.z'Seeding local action path dictionaries. ignore_pubs) gen_manifests lint_api_instr5r6r(r*get_namer)lint_manifestsloggerdebugr ref_api_instanygetrr"_UserlandActionChecker__merge_dictr8)renginer4 lint_fmrismr)r7rstartupZs4))  "    zUserlandActionChecker.startupTcCsx|D]}||kr*||||.build_dicr8N)copyr;rpopr'r))rsrctargetr8r3rIsrc_dictarg_dic src_pfmri targ_pfmrisnametnamelrHr1rrrZ __merge_dicts*         z"UserlandActionChecker.__merge_dictcCsxtjj|}x_|jtjD]K}|dkrLtjj|}q%|dkr[q%tjj||}q%W|S)z-Combine path and target to get the real path.z...)rrdirnamer sepjoin)rrrMresultfragrrrZ __realpaths  z UserlandActionChecker.__realpathc Csd}tj|}|jd}|dkr4|Stjd|dddtjdtj}|j\}}|jdkr|jt d |d d |j d f|St j d |dk r|S|j t d|d d|j d f|S)Ntypeexez'/usr/bin/elfedit -r -e 'dyn:sunw_aslr' shellTstdoutstderrrz'%s' is not tagged for aslrmsgidz%s%s.5001ZENABLEz'%s' does not have aslr enabledz%s%s.6)elfget_inforA subprocessPopenPIPE communicate returncodeerrorrr#rsearchwarning) rrrCrYeir[Zaslr_tag_processZaslr_tag_stringerrrrrZ__elf_aslr_checks*  z&UserlandActionChecker.__elf_aslr_checkc Csd}g}tj|}tj|}|jd}xn|jddjdD]Q}|dksU|dkrvqUd} x'|jD]} | j|rd} PqW|dkr|j|| dkr|j||dkr:x|jD]E} | j |r|j t d||fdd|j dfqWqUd} x'|jD]} | j |rJd} PqJW| dkrU|j t d||fdd|j dfqUWt |dkrt ddj|}|S)NbitsZrunpath:FT/lib/lib/64 /lib/amd64 /lib/sparcv9/usr/lib /usr/lib/64/usr/lib/amd64/usr/lib/sparcv9 z364-bit runpath in 32-bit binary, '%s' includes '%s'r`z%s%s.3raz332-bit runpath in 64-bit binary, '%s' includes '%s'rz bad RUNPATH, '%%s' includes '%s')rqrrrsrtrurvrwrx)rb get_dynamicrcrAr rmatchr)rrjrkrr#lenrX) rrrCrYlistZedrlrndirr{exprrrrZ__elf_runpath_checksN"      z)UserlandActionChecker.__elf_runpath_checkc Csd}tj|}|jd}|jd}tjj|jd}d}x#|jD]}||kr^d}q^Wd} x#|jD]}||krd} qW|dkr|dkr| dkr|dkr|S|dkr|rt d }n|dkr| rt d }|S) Nrnr[/FTr\@ryz!32-bit object '%s' in 64-bit pathz!64-bit object '%s' in 32-bit path) rbrcrArrrVr r r r) rrrYrlrnr[ZelemsZpath64r3Zpath32rrrZ__elf_wrong_location_check7s(    0 z0UserlandActionChecker.__elf_wrong_location_checkrac Cs|jdkrdS|j}|dks4|dkrA|jd}d|jkr|jd}t|dd@dkrqd |jkrq|jtd d|d|id d |j|fnd |jkrqd|jkr;|jd}t|dd@dkrq|jtd d|d|id d|j|fn6|jtdd|d|id d|j|f|jdk rx2|jD]'}|d|}tjj |rPqWtjj |s|j td|d d|j|fnt j |r|j |} | dkrB|j| |d d|j|f|j||} | dkr|j| |d d|j|fdS)z'Checks for existence in the proto area.fileNNOHASHrmoderpreservezA%(path)s is writable (%(mode)s), but missing a preserve attributer`z%s%s.0z>%(path)s has a preserve action, but is not writable (%(mode)s)z%s%s.4z+%(path)s has a preserve action, but no modez%s%s.3rz3%s missing from proto area, skipping content checksz%s%s.1z%s%s.2)r)r#hashr$intrirr rrexistsinforb is_elf_object0_UserlandActionChecker__elf_wrong_location_check)_UserlandActionChecker__elf_runpath_check) rr1r7rC pkglint_idrr directoryZfullpathrYrrr file_actionTsR   (     z!UserlandActionChecker.file_actionz%Paths should exist in the proto area.002c Cs|jd krdS|jd}|jd}|j||}|jj|drXdS|d7}x$|jD]}|j|rldSqlW|jtd|j||fdd |j|fdS) zChecks for link resolution.linkhardlinkNrrMrz"%s %s has unresolvable target '%s'r`z%s%s.0)rr)r#r$ _UserlandActionChecker__realpathrrA startswithrir) rr1r7rCrrrMZ realtargetkeyrrr link_resolvess   z#UserlandActionChecker.link_resolveszlinks should resolve.003cCs`|jd krdS|jd}|jj|r\|jtd|dd |j|fdS) z Checks for SVR4 startup scripts.rr~rrNrz.SVR4 startup '%s', deliver SMF service insteadr`z%s%s.0)rr~rr)r#r$rr{rkr)rr1r7rCrrrrr init_scripts  z!UserlandActionChecker.init_scriptz-SVR4 startup scripts should not be delivered.)__name__ __module__ __qualname____doc__r#rrFrBrZ&_UserlandActionChecker__elf_aslr_checkrrrr pkglint_descrrrr)rrr(s - L/  ! 2 9! rcseZdZdZdZfddZdddZede_d d d Z ed e _d ddZ ede _S)UserlandManifestCheckerz5An opensolaris.org-specific class to check manifests.zuserland.manifestcstt|j|dS)N)rrr)rr)rrrrsz UserlandManifestChecker.__init__Z1001c Cstjjdsx|jdD]~}xu|jdD]d}tjj|j}tj j j j tj j j j ttj j j jgB}tj jj}tj j jdtj j j|dddd} | j|gd|} | tj j jjr8|jd|jjd d d g} xo| tj j jjD]W} | j| krA|jtd d |jd|d| jidd|j|fqAWq8Wq"WdS)NZ ENCUMBEREDdependr*rcSsdS)NFr)xrrrsz=UserlandManifestChecker.forbidden_publisher..Tz%s.allowed_pubs zopenindiana.orgz on-nightlyzWpackage %(pkg)s depends on %(name)s, which comes from forbidden publisher %(publisher)spkgr# publisherr`z%s%s.1)renvironrAr!attrlistrr*PkgFmripkg_nameclientapi PackageInfo ALL_OPTIONSACTION_OPTIONS frozensetLICENSESprogressNullProgressTrackerImageInterfaceCURRENT_API_VERSIONr INFO_FOUND get_paramr#r rrir) rr7rCrr1fr info_neededZ progtrackerZ interfaceret allowed_pubsirrrforbidden_publishers 3)z+UserlandManifestChecker.forbidden_publisherz1Dependencies should come from standard publishersracCsg}d}d}x|jdD] }d}Pq"W|dkrCdSxT|jdD]C}|jds|jtddd|j|fqSd}PqSW|dkr|jtddd|j|fdS) NFrTlicensezNmissing vaue for action license attribute 'license' like 'CDDL','MIT','GPL'...r`z%s%s.0zmissing license action)r!r$rirr#)rr7rCrZmanifest_pathsfilesrr1rrrcomponent_checks"   z'UserlandManifestChecker.component_checkzFlicense actions and ARC information are required if you deliver files.rcCsq|jd|jjd}|j}|jrm|j|krm|jtd|jdd|j|fdS)Nz%s.allowed_pubsrzpackage %s has a publisher set!r`z%s%s.2)rr#r r*rrir)rr7rCrrr*rrrpublisher_in_fmris  z)UserlandManifestChecker.publisher_in_fmrizextra publisher set) rrrrr#rrrrrrrr)rrrs    r) pkg.lint.baselintbasepkg.lint.enginerpkg.fmrirpkg.elfrbrZos.pathrrdpkg.client.apipkg.client.api_errorspkg.client.progress ActionCheckerrManifestCheckerrrrrrs