sWc @sldZddkZddkZddkTddklZddklZddkTde fdYZ dS( s/Name Service Switch base classes used by nscfg.iNi(t*(tNssscf(terrortNssbasecBs~eZdZdZdZdZdZdjZdjZ djZ djZ dZ djZ gZhZdjZdZdZdZdZdZeZdZd Zd Zd Zd Zd ZdZhdd6dd6dd6dd6dd6dd6dd6dd6dd6dd6d 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. cCs7|id|_tiido d|_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((s../common/nssbase.pyt__init__xs  cCs t|_dS(s,Disable writing of config or SMF properties.N(tTruetno_write(R.((s../common/nssbase.pytnowritescCs ||_dS(sSet verbose flag.N(R*(R.R*((s../common/nssbase.pytverbosesc Gs@x9|D]1}yt|tdjot|}t|dnt|tdjpt|tgjot}d}xh|D]`}|o?t|tdjot|}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((s../common/nssbase.pyt print_outputs, 2   cCsa|io*td}||i}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=((s../common/nssbase.pyterr_msgs    cCsG|i|y,x%|D]}d|}t|dqWWnnXdS(sAMulti line error message output, with a little bit of formatting.s %siN(RFR:(R.RDttupletemR=((s../common/nssbase.pyterr_lists  cGs%|idjo|i|ndS(s!Debugging output. IF debug = TrueiN(R*RB(R.R;((s../common/nssbase.pyttraceitscGs%|idjo|i|ndS(s2Verbose output. IF verbose == True or debug = TrueiN(R*RB(R.R;((s../common/nssbase.pyt print_msgscCsCd|_t|_d|_d|_g|_g|_d|_dS(s8Reset the service and all existing property information.R4N( tlast_tmpR9tinitedtNonetsvcttmpfdtpgstpropstMNTDIR(R.((s../common/nssbase.pyR)s      cCs|idS(sBase class delete method.N(R)(R.((s../common/nssbase.pyt__del__sc CsT|iotSd|_t|_d|_d|_g|_g|_|i djp|i djonyt |i |_t}x|ii D]}}|d}|djo t}n|ii |xC|ii|D]/}|d}|ii di||fqWqW|p d|_g|_g|_dSt|_WnnXdS(NR4itgeneralt/(RMR0RLR9RNRORPRQRRRCtLEGACYRtget_service_pgstappendtget_propertiestjoin(R.t fnd_generaltpgltpgtpropltprop((s../common/nssbase.pytinit_svcs>             '    cCs |ip|in|ioy|djo?|djo2|iddjo|idd\}}n|djo |i}n|djo |i}n|ii||}t |djo |dSt |djo t dnWqqXndS(s"Get prop's [first] property value.RViiiis/Multiple values returned, single value expectedN( RMRaRNtfindtsplittDEFPGtDEFPROPROtget_prop_valuestlent ValueError(R.R^R`tret((s../common/nssbase.pyt get_prop_vals&  0     cCs|ip|in|ioy|djo?|djo2|iddjo|idd\}}n|djo |i}n|djo |i}n|ii||SWqqXndS(s1Get all of the prop's property values as a tuple.RViiN( RMRaRNRbRcRdReRORf(R.R^R`((s../common/nssbase.pytget_prop_val_lists  0    cCs.|ip|in|io|iSdS(s.Get the list of the service's property groups.N(RMRaRQRN(R.((s../common/nssbase.pytget_pgs#s   cCs|ip|in|iop|djp |djo|iSg}x@|ii|D],}|d}|idi||fq]W|SdS(s)Get the list of the service's properties.R4iRVN(RMRaRNRRRORZRYR[(R.R^tgpropsR_R`((s../common/nssbase.pyt get_props+s    cCs|iS(s0Return the name of the 'default' property group.(Rd(R.((s../common/nssbase.pyt default_pg9scCs|iS(s*Return the name of the 'default' property.(Re(R.((s../common/nssbase.pyt default_prop=scCs||djo(|djo|iddjo|S|djo |i}n|djo |i}ndi||fS(sSJoin and return a pg/prop combination. If pg or prop are None, use the default.RViN(RNRbRdReR[(R.R^R`((s../common/nssbase.pyR[As0    icCs|ip|in|iptS|id|iy9|ii\}}|id||id|Wnd}d}nX|djotS|i d|i |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((s../common/nssbase.pyRqNs"      c Csw|ip|in|iptS|ii}|djp |djo|idtSdidd|df}|id|yt dd }t |d t d d d t d|dt dt }|i\}}|i}|id||id||i~~Wnd} d}nX|d jot|d jot S|id|i|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((s../common/nssbase.pytcommitcs:         c Cs|ip|in|iptSy|ii||}Wn(tj o}|i|t}nX|o3y%|i}|i|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((s../common/nssbase.pytaddpgs"      cCsI|ip|in|iptSy|ii|WnnXtS(s*Delete property group with the given name.(RMRaR9ROt delete_pgR0(R.R^((s../common/nssbase.pytdelpgs  cCsI|ip|in|iptSy|ii|WnnXtS(s9Delete property group customizations with the given name.(RMRaR9ROt delcust_pgR0(R.R^((s../common/nssbase.pyRs  cCsp|ip|in|iptSy|ii||||}Wn#tj o}|i|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((s../common/nssbase.pyRs   cCs:|djo&t|tdjo ||_n|iS(s/Modify/Return the name of the legacy file name.R4N(RNR5RW(R.tfile((s../common/nssbase.pyt legacy_files& cCsC|djo/t|tdjo||_d|_n|iS(s9Modify/Return the name of the legacy directory component.R4N(RNR5t LEGACYDIRRS(R.tdir((s../common/nssbase.pyt legacy_dirs&  cCstii|i|iS(s,Return the name of the full legacy pathname.(R+R,R[RRW(R.((s../common/nssbase.pyt legacy_pathscCstii|iS(s,Was the legacy file generated from SMF data?(R+R,R-R(R.((s../common/nssbase.pyt legacy_existssc Cs|idjo|iS|id|i}yt|idi}Wn|idd}nX|i|_|djoyxv|D]j}y|i\}}}}}Wn qnX|djo+||jot i i ||_PqqqWn|iS(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((s../common/nssbase.pytmnt_dirs,        cCstii|i|iS(s7Return the name of the lofs mount path or legacy_path .(R+R,R[RRW(R.((s../common/nssbase.pytmnt_pathscCs;di|ittif}|id||S(s,Return the name of the temp legacy pathname.t.sin tmp_path: tmppath= (R[RR8R+tgetpidRJ(R.ttmppath((s../common/nssbase.pyttmp_paths'cCs|id|i|idjoy|i}|id|t|d|_ti|ii|i|i djp|i djo&ti |ii|i |i nd|_ |idWqd|_|idqXn|iS( 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((s../common/nssbase.pytopen_tmps  &  cCs#|idjotSd}|djo||7}n|djo#|iid|}||7}n||i7}t|itdjoA|djo|iid|}n |i}||d7}n|djo||7}n|id|i}|ii||i |7_ dS(s\Write out header to opened tmpfile. Modify default '#' comment tag using sep, pre, post.R4t#s tAUTO_GENN( RPRNR9tHEADERtreplaceR5tDOCRtwriteRL(R.tseptpretposttheaderttmp((s../common/nssbase.pyt header_tmps&      cCs<|idjoyt|iWq/q/Xnd|_tS(s*Create a new legacy temp file for writing.N(RPRNRR0(R.((s../common/nssbase.pyt close_tmp's cCsC|i}y(tii|oti|nWntSXtS(N(RR+R,R-tunlinkR9R0(R.R((s../common/nssbase.pyt unlink_tmp1s cCst|ttjotS|djpt|tdjotS|i}|id||djotS|o|iny-|i||i|7_|idWn)|i |i |idtSX|i tS(s0All-in-one tmp file generation from data string.R4s open fd= s written...s write fail...N( R5R0R9RNRRJRRRLRR(R.RRtfd((s../common/nssbase.pyt save_to_tmp:s*&       c Cs|i}|djo |}ntii|okdi|df}tii|o yti|Wq~tSXnyti||WqtSXnt S(s4Save away an existing legacy file to ${legacy}.orig.RtorigN( RRNR+R,R-R[RR9tlinkR0(R.taltpathRR((s../common/nssbase.pyt legacy_saveSs     cCs|i}|djo |}ntii|oXdi|df}tii|o,yti||idWqqXqntS(s.Remove ${legacy}.orig if a legacy file exists.RRsRemoved old (orig) backup.N( RRNR+R,R-R[RRKR0(R.RRR((s../common/nssbase.pyt orig_cleanupes     c Cs|i}|i}|i}|id||jo|idtS|i|tjo|idtS|id|d|y*|id|d|ti||Wn|idtSXynt dd }|i |}|i d |t |d t d d dt d|dtdt}|i\}}|i} |i d| |i d|| d jo"|i|id~~tS|i||f} |i d| t | d t d d dt d|dtdt}|i\}}|i} |i d| |i d||i~~Wn|idtSX| d jo2t|d jo|id|i|t S|id| |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((s../common/nssbase.pytlofs_legacy_savetsj                   c Csi|i|id|i}|i}t}d }yt|di}t}WnnX|d joD||i jo0|idyt i |WnnX|i Sn|o"|i o|id|iS|itjo|id|iS|id|d|yt i||Wn|id|iSX|id |i|iS( 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((s../common/nssbase.pyt tmp_to_legacysD             cCs|i}g}yet|d}|i}x9|D]1}|ido|d }n|i|q7W|iWndSX|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((s../common/nssbase.pyt load_legacys  cCsd|ip|in|iptSy|ii}Wn#tj o}|i|tSX|S(s,Return True if service is currently enabled.(RMRaR9ROt is_enabledRRF(R.RiR((s../common/nssbase.pyRs   cCsd|ip|in|iptSy|ii}Wn#tj o}|i|tSX|S(s&Execute svcadm enable on this service.(RMRaR9ROtenableRRF(R.RiR((s../common/nssbase.pyRs   cCsd|ip|in|iptSy|ii}Wn#tj o}|i|tSX|S(s'Execute svcadm disable on this service.(RMRaR9ROtdisableRRF(R.RiR((s../common/nssbase.pyRs   cCsd|ip|in|iptSy|ii}Wn#tj o}|i|tSX|S(s'Execute svcadm refresh on this service.(RMRaR9RORuRRF(R.RiR((s../common/nssbase.pyRus   cCsd|ip|in|iptSy|ii}Wn#tj o}|i|tSX|S(s'Execute svcadm restart on this service.(RMRaR9ROtrestartRRF(R.RiR((s../common/nssbase.pyR"s   cCs|idjotStS(s1Return True if this is a class for a nss backend.N(tBACKENDRNR9R0(R.((s../common/nssbase.pyt is_backend3scCs|iS(sOExport from SMF. -1 - Fail, 0 - Success, 1 - Unnecessary. ** Must Subclass **(R(R.((s../common/nssbase.pytexport_from_smf=scCs|iS(sUImport to SMF. -1 - Fail, 0 - Success, 1 - no config to import. ** Must Subclass **(R(R.((s../common/nssbase.pyt import_to_smfBscCs|iS(s>Unconfigure SMF. -1 - Fail, 0 - Success. ** Must Subclass **(R(R.((s../common/nssbase.pyt unconfig_smfGscCs|i}|djo|i|jo|i|i}|djo_t}xF|iiD]5}di|i|f}||jo t}q^q^W|otSqqntS(s/Is SMF populated with this service? True/FalseRVN( RlRNRdRnR9tALLPROPStkeysR[R0(R.RQRRtfndpropRttprop((s../common/nssbase.pyt is_populatedQs    cCsf|ioU|i}t|tgjo,t|djo|i|jotSqbntS(s,Was the legacy file generated from SMF data?i(RRR5RgRR0R9(R.R((s../common/nssbase.pytis_autogeneratedes   , cCsK|iotS|io(|iptS|iotSntS(s-Is this SMF service configured from SMF data?(RR0RRRR9(R.((s../common/nssbase.pyt is_configuredqs     c Cs|djo t|tdjo|id}t|djpt|djotSt|djoLy3t|d}|djp |djotSWntSX|d}nt|iid|idjo|id}t|d jotSyad}xB|D]:}t|}|djo|d jo|d7}qqW|d jot SWqqXqt|iid|i djoi|iid }t|djpt|d jotSx9|d D]-}t|id|i djotSqW|d }t|id|i djot St|id|idjo|id}t|d jotSyad}xB|D]:}t|}|djo|d jo|d7}qqW|d jot SWq q XqqqntS(Nt net_addressR4RViiii@Riit:ii( R5RcRgR9tinttlowert translateRNt IPV4CHARSR0t IPV6CHARStHEXCHARS( R.tsmftypetvaluetaddrtmasktdigstcounttdtx((s../common/nssbase.pyttypecheck_netaddresssn & (   (& "  ""   cCs|djo^t|ttjotSt|tdjo#|djp |djotSqn|djoqt|tdjotSt|tdjo6y(t|}t||jotSWqqXqn|djoNt|tdjo1t|iid |idjotSqn|d jo|i ||S|d jof|i d |otSt|tdjo1t|iid |idjotSqn0|d jo"t|tdjotSnt S( s?Is the value of this type or a string of this type? True/FalsetbooleanR4ttruetfalsetintegerithostnameiRR RN( R5R0RR8RgRRRNt DNSHOSTCHARSRR9(R.RRti((s../common/nssbase.pyt typechecks@       (   (   N(Zt__name__t __module__t__doc__RRtNOCONFIGRRNRCRWRRdt DEFPGTYPERetALLPGSRRRRRtUNCONFPGt UNCONFPROPR9R1R RRRRRRtDBMAPRRRR/R2R3RBRFRIRJRKR)RTRaRjRkRlRnRoRpR[RqRRRRRRRRRRRRRRRRRRRRRRRRRRuRRRRRRRRRR (((s../common/nssbase.pyR!s          )      %              < )       6( RR+ttimetmessagestnssscfRRRt subprocesstobjectR(((s../common/nssbase.pyts