ó i'dWc@s[dZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z m Z mZmZmZmZddlmZddlmZdZdZd Zd Zd Zd Zd ZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'd„Z(d„Z)d„Z*d„Z+d„Z,dS(sF Utility functions for managing sysconfig configurations for archives iÿÿÿÿN(tetree(tPopentrunt SetUIDasEUIDtCalledProcessErrortSYSTEM_TEMP_DIRt_(t ArchiveError(tINSTALL_LOGGER_NAMEs/usr/sbin/chroots/usr/bin/getents /usr/bin/greps/usr/sbin/netadms/usr/bin/passwds/usr/bin/pgreps /usr/bin/pss /usr/bin/rms/usr/sbin/rolemods/usr/sbin/routes/usr/sbin/svccfgs/lib/svc/bin/svc.configds/usr/bin/svcprops/usr/bin/userattrs/usr/sbin/userdels /usr/sbin/zfss$etc/sudoers.d/svc-system-config-usercCsõtjtƒ}|jdƒtjtjj|dƒƒ}tjj|dƒ}||kròtjtjj|dƒƒ}x.|D]k}tj |ƒ}tj ddƒ}d|_ |j ƒj d|ƒxÁ|j ƒjd ƒD]ª} | jd } g|D]} tj| | ƒrö| ^qö} | rÜ|j| dƒtj dd | ƒ} d| _ | jƒj d | ƒ| jƒj| ƒ|s†Pq†qÜqÜWtjƒ}|d kr«d}nt|dƒ/}|jtj|dtd|dtƒƒWdQXq€Wn¸itjj|dƒd6}i}x4|D],} ytd| dddddg}t|d|ƒ}|jr| jdƒd jdƒ}|jjƒjdƒ}xl|D]a}|jdƒ}||krÕ|j|gƒj |ƒq˜|||kr˜||j |ƒq˜q˜Wnt!ƒ'td| dg}t|d|ƒWdQXWqt"k rFqXqWx\|j#ƒD]N\}}tjj||ƒ}tjj$|ƒs‘qXqXtj |ƒ}tj ddƒ}d|_ |j ƒj d|ƒx˜|j ƒjd ƒD]} | jd } | |krç|j| ƒtj dd | ƒ} d| _ | jƒj d | ƒ| jƒj| ƒ|shPqhqçqçWt|dƒ)}|jtj|dtdtƒƒWdQXqXWd}y t%j&tjj||ƒƒWnt'k rãnX|jd ƒdS(!s;Function to clean up the smf site-profile and admin layers.sPurging SMF layers.s etc/svc/*setc/svc/repository.dbsetc/svc/profile/site/*.xmlttexts‰This file has been touched by archiveadm(1m) during archive creation. Entries for Oracle Solaris system configuration have been removed.s itservicetnames5The smf service %s has been removed by archiveadm(1m)it646sUS-ASCIIsw+txml_declarationtencodingt pretty_printNtSVCCFG_REPOSITORYs-stlistprops-ls site-profiles-otfiletenvt:t/tdelcustsetc/svc/profile/sysconfig/sPurginig SMF layers completed.((tloggingt getLoggertILNtdebugtglobtostpathtjoinRtparsetCommentttailtgetroottinserttfindalltattribtretsearchtremovet getparenttlocaletgetpreferredencodingtopentwritettostringtTruetSVCCFGRtstdouttsplittstript setdefaulttappendRRt iteritemstexiststshutiltrmtreetOSError(taltroottservicestloggertetc_svc_contentstsmf_repotprofilest site_profilettreet archCommentt smf_servicetsvc_nametxR t svcCommentRtfhRtsvcs_in_site_layertcmdtpt config_svctprofiletsysconfig_path((ssysconfig_util.pytcleanup_smf_layers?s¢      +                       c CsGtjtƒ}|jdƒtjtjj|dƒƒ}tjj|dƒ}||krCitjj|dƒd6}xÉ|D]¾}y¤td|ddg}t |d|ƒ}|j r'|j j ƒ} t | ƒd kr'| d d kr't ƒ.td|d | d g}t |d|ƒWdQXq'nWq~tk r;q~Xq~WndS(sRFunction to clean up scheduling data for periodic and scheduled services. s)Purging Periodic Service Scheduling Data.s etc/svc/*setc/svc/repository.dbRs-stlistpgtperiodic_restarterRiit frameworktdelpgiN(RRRRRRRRR0RR1R2tlenRR( R;t instancesR=R>R?RtinstanceRJtproctvalues((ssysconfig_util.pytcleanup_periodic_servicesÆs&    "   c Cs¹tjtƒ}d}tjtjj|dƒƒ}tjj|dƒ}||krX|Sitjj|dƒd6}tdddddd g}yt |d |ƒ}Wnt k rÆ|j d ƒ|SX|j j ƒ}|rý|d krýtƒ&t|td |g}t |ƒ}WdQX|j j ƒjdƒd}tƒpy&t|tdd|g}t |ƒWnBtk r©} |j d| ƒ|j dƒttdƒƒ‚nXWdQXtƒ?tjj|tƒ} ytj| ƒWntk rónXWdQXn |j dƒtƒkt|tddg}y0t |ƒt|tdddg}t |ƒWnt k ry|j dƒnXWdQXtƒ*t|tddddg}t |ƒWdQX|S(s\Function to delete the sysconfig admin user and root account file from the archive. s etc/svc/*setc/svc/repository.dbRs-sssvc:/system/config-userRs-otvaluesconfigured_user/loginRs-A config-user is not configured in this zone.s""tpasswdNRis-Stfiless%ss&Please add the required authorization.sEThe archive operation requires the solaris.user.manage authorization.sNo sysconfig user to deletettypetroots-Ks type=normals!Root is not configured as a role.s-rs-d(RRRtNoneRRRRR0RRRR1R3RtCHROOTtGETENTR2tUSERDELtAttributeErrorRRtETC_SUDOERS_FILER(R:tUSERATTRtROLEMODtPASSWD( R;R=thomedirR>tsmf_repRRJRKt login_nametaetsudoers((ssysconfig_util.pytcleanup_config_user_rootès`               c CsÅtjtƒ}|jdƒdddddddd d d d d dg }xh|D]`}tjj||ƒ}tj|ƒ}x3|D]+}ytj|ƒWqt k r«qXqWqPW|jdƒdS(sPFunction to perform network configuration cleanup on the clone archive. sClean up network configuration.svar/dhcp/*.dhcsvar/dhcp/*.dh6s var/dhcp/duids var/dhcp/iaidsetc/dhcp/*.dhcsetc/dhcp/*.dh6s etc/dhcp/duids etc/dhcp/iaidsetc/defaultroutersetc/inet/static_routes-*s var/ldap/*setc/defaultdomainsetc/resolv.confs)Clean up network configuration completed.N( RRRRRRRRR(R:(R;R=tnetwork_rm_filestnw_filet alt_nwfiletpathstnw_path((ssysconfig_util.pytcleanup_network_config4s&      c Cs;tjtƒ}|jdƒtjtjj|dƒƒ}tjj|dƒ}dddg}||krÈtƒ}t j dddd ƒ\}}t j dtjj|t j d ƒƒƒ} i|d 6} t|td |d dg} t| d| ƒ} | jƒx¦|D]ž} yet|td| ddddddg } t| d| ƒ}|jj ƒrp|j|jj ƒƒnWqtk r£}|jd|ƒ|jdƒqXqWxµ|D]­}tjj|ƒ\}}tjj| |j d ƒƒ}tjjtjj|ƒƒs%tjtjj|ƒƒntjtjj||j d ƒƒtjj||ƒƒq¯Wt|tdg} yt| dtjd| ƒWn5tk rÆ}|jd|ƒttdƒƒ‚nXtdd|g} t| ƒ}|jj ƒ}ytj t!|ƒt"j#ƒWn5t$k rI}|jd|ƒttdƒƒ‚nXy`tj t!|ƒdƒtj%t!|ƒtj&ƒ\}}|dkr©ttd |ƒƒ‚nWnt$k r½nXtjj|d!ƒ}tjj|ƒrtjj'|ƒ rtj(|ƒnx{|D]s}tjj|ƒ\}}tjj||j d ƒƒ}tjtjj| |j d ƒƒtjj||ƒƒqWtj)|ƒtj*tjj||j d ƒƒƒtj*|ƒng|D]}tjj||ƒ^qÏ}tt+|ƒt+|ƒƒ}x|D]}tj*|ƒqW|jd"ƒd#S($sÜFunction to remove all data from the smf repository for the services that are managed by sysconfig. First, the manifests for the services are saved off to a temporary location, then svccfg cleanup is run to remove all data for the services from the SMF repository. Finally, copy the manifests back to the /lib/svc/manifest directory so that they will be imported on first boot as a new service. As part of this process, a svc.configd daemon is activated for the archive repository path. This needs to be killed, once the repository has been cleaned up. Finally, remove everything from the /etc/svc/ directory except for repository.db, the profile directory, and the volatile directory. sPurging SMF repository.s etc/svc/*setc/svc/repository.dbsetc/svc/profilesetc/svc/volatiletdirs/tmptprefixtrepository_door_Rt SVCCFG_DOORs-ds-rs/etc/svc/repository.dbRs-sRs-ltmanifests-oRssysconfig/groups%ss%Service does not exist for this zone.tcleanupt check_resultsUFailed to clean up services. This operation required for successful archive creation.s-fs/lib/svc/bin/svc.configd -d %ss~Failed to clean up an archive process. This may leave the archive database is in an unknown state. Please retry the operation.is*Unable to kill svc.configd daemon (pid %s)sdev/nullsSMF repository purge completed.N(,RRRRRRRRtlistttempfiletmkstemptmkdtempRR3R`t SVCCONFIGDRtwaitR0RR1R5RR2R7tmakedirsR8tmovetANYRRtPGREPtkilltinttsignaltSIGTERMR:twaitpidtWNOHANGtislinktunlinktcloseR(tset(R;R<R=R>Rit saved_etc_svct manifeststfdesct repo_tempdirtmanifest_tempdirRRJtsubproc1R RKtcpeRxtmdirtmfiletmdesttsubproc3tpidtoet killedpidt_statustfnullRFt cleanup_listtcu_file((ssysconfig_util.pytpurge_smf_repositoryRs         !  !   % ! %( (-t__doc__RR*RRR&R8R‡R|tlxmlRtsolaris_installRRRRRRtsolaris_install.archive.utilRtsolaris_install.loggerRRR`RatGREPtNETADMRgR„tPStRMRftROUTER0RtSVCPROPReRbtZFSRdRORYRmRsR¡(((ssysconfig_util.pytsD        . ‡ " L