ó ºµiVc@s›dZddlZddlZddlZddlZddlmZmZmZddl m Z de fd„ƒYZ d„Z e dkr—e ƒndS( s auth.conf parser and generator iÿÿÿÿN(tBootmgmtArgumentErrortBootmgmtConfigReadErrortBootmgmtConfigWriteError(t LoggerMixintAuthConfigParsercBs˜eZdZdZdZdZdZejdƒZ de d„Z e d„ƒZ e jd „ƒZ d „Zd „Zd „Zd „Zde d„ZRS(sbThe AuthConfigParser class provides an interface to the auth.conf file. The auth.conf file contains 3 sections. The sections and properties include: [menulock] menulock= [superusers] superusers= [users] Zero or More of: = s·# # This file is modified without notice. # DO NOT EDIT THIS FILE DIRECTLY. CHANGES MAY NOT BE PRESERVED. # Changes to this file can be made indirectly via bootadm(1M) subcommands. # t superuserstuserstmenulocks'^([\.A-Za-z0-9_-]+\s)*[\.A-Za-z0-9_-]+$s/rpool/boot/grub/auth.confcCsrtt|ƒjƒ||_d|_t|_tj ƒ|_ i|_ i|_ i|_ |sn|j|ƒndS(N(tsuperRt__init__t _filenametNonetlast_written_pathtFalset_dirtyt ConfigParsertRawConfigParsert _cfgparserRRRt_load(tselftfilenametnew_conf((s0../../common/bootmgmt/backend/loader/authconf.pyR Cs      cCs|jS(s:Returns the state of the internal dirty variable. (R(R((s0../../common/bootmgmt/backend/loader/authconf.pytdirtyOscCs/|j|kr+|jd|ƒ||_ndS(s‹Sets the state of the internal dirty variable. Emits a debug message if the state of the internal dirty variable changed. s dirty => %sN(Rt_debug(Rtval((s0../../common/bootmgmt/backend/loader/authconf.pyRUscCsÄ|s|jdƒdS|jd|ƒyt|dƒ}Wn|jd|ƒnmXy|jj|ƒWnKtk rµ}|jtjkrŸ|jd|ƒndStd|ƒ‚n X|jƒdS(sïAttempt to load the file specified. If new_conf is True, the file's contents are not loaded. The following Exceptions may be generated: BootmgmtConfigReadError -- If there's a problem reading config file. s7No filename specified -- not loading auth configurationNsLoading auth.conf from %strsCould not open %ss[IGNORED] %s not founds1Error trying to read the auth configuration file ( RtopenRtreadfptIOErrorterrnotENOENTRt_load_sections(RRtftioerr((s0../../common/bootmgmt/backend/loader/authconf.pyR^s"  cCs®x§|jjƒD]–}|tjkrFt|jjtjƒƒ|_q|tjkrvt|jjtjƒƒ|_q|tj krt|jjtj ƒƒ|_ qqWdS(s*Load sections from auth.conf file N( RtsectionsRtSUPERUSERS_SECTtdicttitemsRt USERS_SECTRt MENULOCK_SECTR(Rtsect((s0../../common/bootmgmt/backend/loader/authconf.pyR}s   cCsh|jjdƒ}g}|rdtjj|ƒrd|jdƒ}g|D]}|jƒ^qF}qdn|S(s$Return the superusers list. Rt (RtgetRtSUPERUSERS_STR_MATCHINGtmatchtsplittstrip(Rt stringlisttlist_of_stringstx((s0../../common/bootmgmt/backend/loader/authconf.pytget_superusersŽs%cCstjƒ}|jr^|jtjƒx6|jjƒD]"\}}|jtj||ƒq5Wn|jr°|jtj ƒx6|jjƒD]"\}}|jtj ||ƒq‡Wn|j r|jtj ƒx6|j jƒD]"\}}|jtj ||ƒqÙWn|S(s_Generate a new ConfigParser using the data from superuser, users, and menulock ( RtSafeConfigParserRt add_sectionRR#R%tsetRR&RR'(Rt new_parsertkeytvalue((s0../../common/bootmgmt/backend/loader/authconf.pyt_synch_to_config_parser™s    cCsÿ|j r"| r"|jdƒdS|j rB|rB|jdƒn|jƒ|_|p]|j}|sutdƒ‚nyatjdƒ}t|dƒ}tj|ƒ|j t j ƒ|jj |ƒ||_ t |_Wn"tk rú}td|ƒ‚nXdS(sWrites the auth data to auth.conf. If no changes have been made since the configuration was loaded, write() will return without writing the file (unless force is True). If alt_file is not None, the auth configuration will be written there. Exceptions that may be generated: BootmgmtArgumentError -- If no filename is available. BootmgmtConfigWriteError -- If the auth config file cannot be created or if there's a problem writing to it. savoiding writeNs forcing writes)auth configuration filename not specifieditws&Error writing auth configuration file (RRR9RR RtostumaskRtwriteRtAUTH_CONF_PREAMBLER R RRR(Rtalt_filetforcet write_filetoldumasktoutfileR!((s0../../common/bootmgmt/backend/loader/authconf.pyR=­s(     N(t__name__t __module__t__doc__R>R#R&R'tretcompileR+R R tpropertyRtsetterRRR2R9R R=(((s0../../common/bootmgmt/backend/loader/authconf.pyR's     cCsOtdddtƒ}dt|jƒGHdt|jƒGHdt|jƒGHdS(NRs/root/temp_auth.confRsThe superuser is sThe usernm pw dict is sThe menu password is (RR tstrRRR(ttest_auth_conf((s0../../common/bootmgmt/backend/loader/authconf.pytmain×s t__main__(RFR;RRRGtbootmgmtRRRtbootmgmt.bootutilRRRMRD(((s0../../common/bootmgmt/backend/loader/authconf.pyts    °