sWc@sldZddlZddlZddlTddlmZddlmZddlTde fdYZ dS( s/Name Service Switch base classes used by nscfg.iNi(t*(tNssscf(terrortNssbasecBs~eZdZdZdZdZdZdjZdjZ djZ djZ dZ djZ gZiZdjZdZdZdZdZdZeZdZd Zd Zd Zd Zd ZdZidd6dd6dd6dd6dd6dd6dd6dd6dd6dd6d d 6d!d!6d"d"6d#d$6d%d&6d'd(6d)d)6d*d*6d+d+6d,d,6d-d-6d.d/6Zd0Z d1Z!djZ"d2Z#d3Z$dd4Z%d5Z&d6Z'd7Z(d8Z)d9Z*d:Z+d;Z,d<Z-djdjd=Z.djdjd>Z/d?Z0djd@Z1dAZ2dBZ3djdjdCZ4dDdEZ5djdFZ6dGZ7dHZ8dIZ9dJZ:djdKZ;djdLZ<dMZ=dNZ>dOZ?dPZ@dQZAdRZBdjdjdjdSZCdTZDdUZEdVZFdjdWZGdjdXZHdYZIdZZJd[ZKd\ZLd]ZMd^ZNd_ZOd`ZPdaZQdbZRdcZSddZTdeZUdfZVdgZWdhZXdiZYRS(ksName Service Switch base class. Represents the common base class used by the other name service switch classes. ** USE AS BASE CLASS ONLY **iiit applicationitunconfig_groupt unconfigureds&abcdefghijklmnopqrstuvwxyz0123456789-.s 0123456789.sabcdef0123456789:.tabcdef0123456789s /etc/mnttabs /usr/sbin/mount -O -F lofs %s %ss/usr/sbin/umount %stpasswordtpasswdtgroupthostthoststipnodestnetworktnetworkstprotocolt protocolstrpctethertetherstnetmasktnetmaskst bootparamt bootparamst publickeytnetgroupt automounttaliastaliasestservicetservicestprintertprinterstprojectt auth_attrt prof_attrttnrhtpttnrhdbtsudoertsudoerss# _AUTOGENERATED_FROM_SMF_V1_sl # AUTO_GEN # # WARNING: THIS FILE GENERATED FROM SMF DATA. # DO NOT EDIT THIS FILE. EDITS WILL BE LOST. cCs5|jd|_tjjdr1d|_ndS(svBase class init method. Creates BASE service object. Collects pg's and properties. Required: SERVICE, LEGACYis/var/tmp/nscfg_debugiN(t reset_svctvolumetostpathtexists(tself((scommon/nssbase.pyt__init__xs  cCs t|_dS(s,Disable writing of config or SMF properties.N(tTruetno_write(R.((scommon/nssbase.pytnowritescCs ||_dS(sSet verbose flag.N(R*(R.R*((scommon/nssbase.pytverbosescGs7x0|D](}yt|tdkrDt|}t|dnt|tdkstt|tgkrt}d}xd|D]\}|rt|tdkrt|}n t|}t}q|dt|7}qWd|}t|dntt|dWqttdqXqWdS(s>Trace/Verbose message output, with a little bit of formatting.tis s%s s Output ErrorN((ttypet_t printStdoutR0tstrtFalset printStderr(R.targstavtmsgtfirsttdstrtatoutstr((scommon/nssbase.pyt print_outputs(  0    cCs_|jr2td}||j}t|dntd}|t|}t|ddS(s6Error message output, with a little bit of formatting.sError in service: %sis Error: %s N(R*R6tSERVICER:(R.temsgttagR=((scommon/nssbase.pyterr_msgs    cCsG|j|y,x%|D]}d|}t|dqWWnnXdS(sAMulti line error message output, with a little bit of formatting.s %siN(RFR:(R.RDttupletemR=((scommon/nssbase.pyterr_lists   cGs#|jdkr|j|ndS(s!Debugging output. IF debug = TrueiN(R*RB(R.R;((scommon/nssbase.pyttraceitscGs#|jdkr|j|ndS(s2Verbose output. IF verbose == True or debug = TrueiN(R*RB(R.R;((scommon/nssbase.pyt print_msgscCsCd|_t|_d|_d|_g|_g|_d|_dS(s8Reset the service and all existing property information.R4N( tlast_tmpR9tinitedtNonetsvcttmpfdtpgstpropstMNTDIR(R.((scommon/nssbase.pyR)s      cCs|jdS(sBase class delete method.N(R)(R.((scommon/nssbase.pyt__del__scCsK|jr tSd|_t|_d|_d|_g|_g|_|j dksG|j dkrdnyt |j |_t}x|jj D]{}|d}|dkrt}n|jj |xC|jj|D]/}|d}|jj dj||fqWqW|s3d|_g|_g|_dSt|_WnnXdS(NR4itgeneralt/(RMR0RLR9RNRORPRQRRRCtLEGACYRtget_service_pgstappendtget_propertiestjoin(R.t fnd_generaltpgltpgtpropltprop((scommon/nssbase.pytinit_svcs:            '    cCs|js|jn|jry|dkrj|dkrj|jddkrj|jdd\}}n|dkr|j}n|dkr|j}n|jj||}t |dkr|dSt |dkrt dnWqqXndS(s"Get prop's [first] property value.RViiiis/Multiple values returned, single value expectedN( RMRaRNtfindtsplittDEFPGtDEFPROPROtget_prop_valuestlent ValueError(R.R^R`tret((scommon/nssbase.pyt get_prop_vals&   -     cCs|js|jn|jry|dkrj|dkrj|jddkrj|jdd\}}n|dkr|j}n|dkr|j}n|jj||SWqqXndS(s1Get all of the prop's property values as a tuple.RViiN( RMRaRNRbRcRdReRORf(R.R^R`((scommon/nssbase.pytget_prop_val_lists   -    cCs*|js|jn|jr&|jSdS(s.Get the list of the service's property groups.N(RMRaRQRN(R.((scommon/nssbase.pytget_pgs#s    cCs|js|jn|jr|dks7|dkr>|jSg}x@|jj|D],}|d}|jdj||fqWW|SdS(s)Get the list of the service's properties.R4iRVN(RMRaRNRRRORZRYR[(R.R^tgpropsR_R`((scommon/nssbase.pyt get_props+s     cCs|jS(s0Return the name of the 'default' property group.(Rd(R.((scommon/nssbase.pyt default_pg9scCs|jS(s*Return the name of the 'default' property.(Re(R.((scommon/nssbase.pyt default_prop=scCst|dkr1|dkr1|jddkr1|S|dkrI|j}n|dkra|j}ndj||fS(sSJoin and return a pg/prop combination. If pg or prop are None, use the default.RViN(RNRbRdReR[(R.R^R`((scommon/nssbase.pyR[As-    icCs|js|jn|js#tS|jd|jy9|jj\}}|jd||jd|Wnd}d}nX|dkrtS|j d|j |tS(s?Validate the service properties. Retry num_tries times ignored.s!Validate service properties for: sRET: sOUTPUT: s*Unable to process libscf validate command iisValidate Error: ( RMRaR9RKRCROtvalidateRJR0RF(R.t num_triesRitoutput((scommon/nssbase.pyRqNs"       c Csm|js|jn|js#tS|jj}|dksJ|dkr[|jdtSdjdd|df}|jd|yt dd }t |d t d d d t d|dt dt }|j\}}|j}|jd||jd||j~~Wnd} d}nX|d krOt|d krOt S|jd|j|tS(sRefresh the service and commit any new/changed properties. If pg is not None, then wait for pg to exist in its most current form.R4s No :default instance name found.t s/usr/sbin/svccfgs-strefreshsRefresh svccfg command: s /dev/nullsr+tshelltbufsizeit close_fdststdintstdouttstderrsRET: sOUTPUT: s)Unable to process svccfg refresh command isCommit Error. Svccfg says: N(RMRaR9ROt get_instfmriRNRFR[RKtopentPopenR0tPIPEtSTDOUTt communicatetwaitRJtcloseRg( R.R^tinstancetcmdtiotpRstignoreRiterrout((scommon/nssbase.pytcommitcs:         cCs|js|jn|js#tSy|jj||}Wn&tk rd}|j|t}nX|ry%|j}|j|dd|}WqqXn|S(s2Add a property group with the given name and type.tvalue_authorizationtastring( RMRaR9ROtadd_pgt NssscfErrorRFt VALUE_AUTHt add_prop_val(R.R^tpgtypeRiterrtval((scommon/nssbase.pytaddpgs"       cCsE|js|jn|js#tSy|jj|WnnXtS(s*Delete property group with the given name.(RMRaR9ROt delete_pgR0(R.R^((scommon/nssbase.pytdelpgs   cCsE|js|jn|js#tSy|jj|WnnXtS(s9Delete property group customizations with the given name.(RMRaR9ROt delcust_pgR0(R.R^((scommon/nssbase.pyRs   cCsj|js|jn|js#tSy|jj||||}Wn!tk re}|j|tSX|S(sAdd property value val to property group/property of type ptype. val may be a string, or a sequence of strings (tuple/array).(RMRaR9ROt set_propvalueRRF(R.R^R`tptypeRRiR((scommon/nssbase.pyRs    cCs7|dkr0t|tdkr0||_n|jS(s/Modify/Return the name of the legacy file name.R4N(RNR5RW(R.tfile((scommon/nssbase.pyt legacy_files$ cCs@|dkr9t|tdkr9||_d|_n|jS(s9Modify/Return the name of the legacy directory component.R4N(RNR5t LEGACYDIRRS(R.tdir((scommon/nssbase.pyt legacy_dirs$  cCstjj|j|jS(s,Return the name of the full legacy pathname.(R+R,R[RRW(R.((scommon/nssbase.pyt legacy_pathscCstjj|jS(s,Was the legacy file generated from SMF data?(R+R,R-R(R.((scommon/nssbase.pyt legacy_existssc Cs|jdkr|jS|jd|j}yt|jdj}Wn|jdd}nX|j|_|dkrxq|D]f}y|j\}}}}}Wn qnX|dkr||krt j j ||_PqqqWn|jS(s3Return the name of the lofs mountdir or LEGACYDIR .s'Looking in /etc/mnttab, for lofs mount.trs,No lofs mountpoint found (using legacy dir).tlofsN( RSRNRKRR}t ETC_MNTTABt readlinesRRcR+R,tdirname( R.tlegacytdatatltsrctmntR5toptstmisc((scommon/nssbase.pytmnt_dirs*         cCstjj|j|jS(s7Return the name of the lofs mount path or legacy_path .(R+R,R[RRW(R.((scommon/nssbase.pytmnt_pathscCs;dj|jttjf}|jd||S(s,Return the name of the temp legacy pathname.t.sin tmp_path: tmppath= (R[RR8R+tgetpidRJ(R.ttmppath((scommon/nssbase.pyttmp_paths'cCs|jd|j|jdkry|j}|jd|t|d|_tj|jj|j|j dks|j dkrtj |jj|j |j nd|_ |jdWqd|_|jdqXn|jS( s*Create a new legacy temp file for writing.sin open_tmp: tmpfd= s opening: tmppath= sw+iR4s open successfuls open failedN( RJRPRNRR}R+tfchmodtfilenotPERMtOWNERtGROUPtfchownRL(R.R((scommon/nssbase.pytopen_tmps %  cCs|jdkrtSd}|dkr2||7}n|dkr`|jjd|}||7}n ||j7}t|jtdkr|dkr|jjd|}n |j}||d7}n|dkr||7}n|jd|j}|jj||j |7_ dS(s\Write out header to opened tmpfile. Modify default '#' comment tag using sep, pre, post.R4t#s tAUTO_GENN( RPRNR9tHEADERtreplaceR5tDOCRtwriteRL(R.tseptpretposttheaderttmp((scommon/nssbase.pyt header_tmps&         cCs:|jdkr-yt|jWq-q-Xnd|_tS(s*Create a new legacy temp file for writing.N(RPRNRR0(R.((scommon/nssbase.pyt close_tmp's cCsA|j}y&tjj|r1tj|nWntSXtS(N(RR+R,R-tunlinkR9R0(R.R((scommon/nssbase.pyt unlink_tmp1s cCst|ttkrtS|dks@t|tdkrDtS|j}|jd||dkrptS|r|jny-|j||j|7_|jdWn)|j |j |jdtSX|j tS(s0All-in-one tmp file generation from data string.R4s open fd= s written...s write fail...N( R5R0R9RNRRJRRRLRR(R.RRtfd((scommon/nssbase.pyt save_to_tmp:s*$        cCs|j}|dkr!|}ntjj|rdj|df}tjj|ryytj|WqytSXnytj||WqtSXnt S(s4Save away an existing legacy file to ${legacy}.orig.RtorigN( RRNR+R,R-R[RR9tlinkR0(R.taltpathRR((scommon/nssbase.pyt legacy_saveSs   cCs|j}|dkr!|}ntjj|rdj|df}tjj|rytj||jdWqqXqntS(s.Remove ${legacy}.orig if a legacy file exists.RRsRemoved old (orig) backup.N( RRNR+R,R-R[RRKR0(R.RRR((scommon/nssbase.pyt orig_cleanupes     c Cs|j}|j}|j}|jd||krN|jdtS|j|tkrt|jdtS|jd|d|y*|jd|d|tj||Wn|jdtSXylt dd }|j |}|j d |t |d t d d dt d|dtdt}|j\}}|j} |j d| |j d|| d kr|j|jd~~tS|j||f} |j d| t | d t d d dt d|dtdt}|j\}}|j} |j d| |j d||j~~Wn|jdtSX| d krt|d kr|jd|j|t S|jd| |tS(sAttempt to remount the legacy file as a lofs mount point. For this to be successful, there must be a pre-existing mount fail here mean fallback to the rename file method.s# Try legacy re-mount using lofs.s, Legacy file is not currently using lofs.s'Unable to archive existing legacy file.s Try to re-mount: s to s Move temp: s' Could not move temp to mount source.s /dev/nullsr+s UMNTCMD: RvRwiRxRyRzR{s UMNT RET: s UMNT OUTPUT: s) Could not umount previous lofs mount.s LOFS MNTCMD: s MNT RET: s MNT OUTPUT: s( Could not lofs re-mount legacy file.s lofs re-mount successful.s'Warning: mount error on lofs re-mount: (RRRRKR9RRFR+trenameR}t LOFS_UMOUNTRJR~R0RRRRRt LOFS_MOUNTRgR( R.RtmntpathRRtumntcmdRRsRRitmntcmd((scommon/nssbase.pytlofs_legacy_savetsj                  cCs`|j|jd|j}|j}t}d }yt|dj}t}WnnX|d kr||j kr|jdyt j |WnnX|j Sn|r|j r|jd|jS|jtkr|jd|jS|jd|d|yt j||Wn|jd|jSX|jd |j|jS( sReplace legacy config file with tmp config file. Save away existing legacy file as necessary. Returns: -1 - Error, 0 - Success, 1 - Unnecessary.sSave new legacy file...Rs( Legacy contents identical. skip saves#Legacy save (lofs remount). successs'Unable to archive existing legacy file.s Try legacy rename: s to sCould not install legacy file.sLegacy save. successN(RRKRRR9RNR}treadR0RLR+RtNOCHANGERtSUCCESSRRFtFAILRR(R.RRtread_legacy_filetlegdata((scommon/nssbase.pyt tmp_to_legacysD             cCs|j}g}yct|d}|j}x7|D]/}|jdrY|d }n|j|q7W|jWndSX|S(sReadlines an existing legacy file. Return a list of lines. Return: None if no legacy file, [] if empty, or [...] Note: ' ' are pruned from all lines before return.Rs iN(RR}RtendswithRYRRN(R.RtlinestlfdtlnR((scommon/nssbase.pyt load_legacys    cCs^|js|jn|js#tSy|jj}Wn!tk rY}|j|tSX|S(s,Return True if service is currently enabled.(RMRaR9ROt is_enabledRRF(R.RiR((scommon/nssbase.pyRs    cCs^|js|jn|js#tSy|jj}Wn!tk rY}|j|tSX|S(s&Execute svcadm enable on this service.(RMRaR9ROtenableRRF(R.RiR((scommon/nssbase.pyRs    cCs^|js|jn|js#tSy|jj}Wn!tk rY}|j|tSX|S(s'Execute svcadm disable on this service.(RMRaR9ROtdisableRRF(R.RiR((scommon/nssbase.pyRs    cCs^|js|jn|js#tSy|jj}Wn!tk rY}|j|tSX|S(s'Execute svcadm refresh on this service.(RMRaR9RORuRRF(R.RiR((scommon/nssbase.pyRus    cCs^|js|jn|js#tSy|jj}Wn!tk rY}|j|tSX|S(s'Execute svcadm restart on this service.(RMRaR9ROtrestartRRF(R.RiR((scommon/nssbase.pyR"s    cCs|jdkrtStS(s1Return True if this is a class for a nss backend.N(tBACKENDRNR9R0(R.((scommon/nssbase.pyt is_backend3scCs|jS(sOExport from SMF. -1 - Fail, 0 - Success, 1 - Unnecessary. ** Must Subclass **(R(R.((scommon/nssbase.pytexport_from_smf=scCs|jS(sUImport to SMF. -1 - Fail, 0 - Success, 1 - no config to import. ** Must Subclass **(R(R.((scommon/nssbase.pyt import_to_smfBscCs|jS(s>Unconfigure SMF. -1 - Fail, 0 - Success. ** Must Subclass **(R(R.((scommon/nssbase.pyt unconfig_smfGscCs|j}|dkr|j|kr|j|j}|dkrt}xD|jjD]3}dj|j|f}||kr[t}q[q[W|rtSqqntS(s/Is SMF populated with this service? True/FalseRVN( RlRNRdRnR9tALLPROPStkeysR[R0(R.RQRRtfndpropRttprop((scommon/nssbase.pyt is_populatedQs      cCs_|jr[|j}t|tgkr[t|dkr[|j|krXtSq[ntS(s,Was the legacy file generated from SMF data?i(RRR5RgRR0R9(R.R((scommon/nssbase.pytis_autogeneratedes   * cCsC|jrtS|jr?|js,tS|jr?tSntS(s-Is this SMF service configured from SMF data?(RR0RRRR9(R.((scommon/nssbase.pyt is_configuredqs    c Cs|dkrt|tdkr|jd}t|dksWt|dkr[tSt|dkry0t|d}|dks|dkrtSWntSX|d}nt|jjd|jdkrj|jd}t|d krtSy\d}x?|D]7}t|}|dkr|d kr|d7}qqW|d kr\t SWqqXqt|jjd|j dkr|jjd }t|dkst|d krtSx7|d D]+}t|jd|j dkrtSqW|d }t|jd|j dkr7t St|jd|jdkr|jd}t|d kr}tSy\d}x?|D]7}t|}|dkr|d kr|d7}qqW|d krt SWqqXqqqntS(Nt net_addressR4RViiii@Riit:ii( R5RcRgR9tinttlowert translateRNt IPV4CHARSR0t IPV6CHARStHEXCHARS( R.tsmftypetvaluetaddrtmasktdigstcounttdtx((scommon/nssbase.pyttypecheck_netaddresssh $ '   '$! !!   cCs|dkrbt|ttkr(tSt|tdkr|dksX|dkr_tSqn}|dkrt|tdkrtSt|tdkry&t|}t||krtSWqqXqn|dkr-t|tdkrt|jjd |jdkr*tSqn|d krI|j ||S|d kr|j d |rktSt|tdkrt|jjd |jdkrtSqn+|d krt|tdkrtSnt S( s?Is the value of this type or a string of this type? True/FalsetbooleanR4ttruetfalsetintegerithostnameiRR RN( R5R0RR8RgRRRNt DNSHOSTCHARSRR9(R.RRti((scommon/nssbase.pyt typechecks@      '   '  N(Zt__name__t __module__t__doc__RRtNOCONFIGRRNRCRWRRdt DEFPGTYPERetALLPGSRRRRRtUNCONFPGt UNCONFPROPR9R1R RRRRRRtDBMAPRRRR/R2R3RBRFRIRJRKR)RTRaRjRkRlRnRoRpR[RqRRRRRRRRRRRRRRRRRRRRRRRRRRuRRRRRRRRRR (((scommon/nssbase.pyR!s          )      %              < )       6( RR+ttimetmessagestnssscfRRRt subprocesstobjectR(((scommon/nssbase.pyts