a 'Dg"@s|ddlZddlZddlZddlmZddlZddlmZmZddl m Z ddl m Z m Z eeZGdddejjjZdS)N)StringIO)subputil)FreeBSDNetworking) PER_ALWAYS PER_INSTANCEc@seZdZdZeZdZdZdZdZ gdZ ddgZ dd gZ dd gZ dd gZd Zd ZdZdZgdZed3ddZeddeeedddZddZedddZddZd4d d!Zd"d#Zd$d%Zd5d&d'Zd(d)Z dd*d+d,Z!e"eeeeee#d-d.d/Z$e"edd0d1d2Z%dS)6DistrozY Distro subclass for FreeBSD. (N.B. DragonFlyBSD inherits from this class.) z/usr/local/libz/etc/login.confz/etc/login.conf.origz,/usr/local/etc/sudoers.d/90-cloud-init-users)pwgroupaddpkginstallremoveupdateZupgradeTz /usr/homez/var/dbzdhclient.leases.\w+)z ^{username}::z^{username}:\*:z^{username}:\*LOCKED\*:NcCs8tjd}|dur"tddStjdd|gd|dS)z Tell rc to reload its configuration Note that this only works while we're still in the process of booting. May raise ProcessExecutionError ZRC_PIDNz0Unable to reload rc(8): no RC_PID in Environmentkillz-SIGALRMTZcapturercs)osenvirongetLOGZwarningr)clsrZrc_pidr=/usr/lib/python3.9/site-packages/cloudinit/distros/freebsd.py reload_init7s   zDistro.reload_init)r)actionservice extra_argsc Gsx|j}|dg|dg|dg|dg|dg|dg|dg|dg|dg|dg|d g|d gd }|||t|}tj|d |d S)a Perform the requested action on a service. This handles FreeBSD's 'service' case. The FreeBSD 'service' is closer in features to 'systemctl' than SysV init's 'service', so we override it. May raise ProcessExecutionError stopstartenableenableddisableonestartonestoprestartstatus onestatus) rrr r!r"r#r$r%reloadz try-reloadr&r'Tr)init_cmdlistr)rrrrrr)Zcmdscmdrrrmanage_serviceEs zDistro.manage_servicecCsddd|d|gS)Nr usermod-n-Gr)self member_nameZ group_namerrr_get_add_member_to_group_cmdasz#Distro._get_add_member_to_group_cmd)returnc Kst|rtd|dSddd|g}ddd|g}dddd d d d d }dddd}|D]b\}}||vr|rt|ttfr|||t|gqZ||vrZ|rZ| ||| ||qZd|vsd|vr| d| dnH| d|j d|} | d| | d| d| | dtd|zt j ||dWn$t ynttd|Yn0| dd} | dur|j|| dddS)z~ Add a user to the system using standard tools Returns False if user already exists, otherwise True. z!User %s already exists, skipping.Fr Zuseraddr.z-d-cz-gr/z-sz-Ez-u)homedirZgecosZ primary_groupgroupsshellZinactiveuidz--no-user-groupz--systemz --no-log-init)Z no_user_groupsystemZ no_log_initZno_create_homer9z-d/nonexistentr5/z-mzAdding user %s) logstringzFailed to create user %spasswdNT)hashed)rZis_userrinfoitems isinstancestrintextendappendrhome_dirr Exceptionlogexc set_passwd) r0namekwargsZpw_useradd_cmdZlog_pw_useradd_cmdZpw_useradd_optsZpw_useradd_flagskeyvalr5Z passwd_valrrradd_userdsR             zDistro.add_usercCs@ztdd|ddgWn"ty:ttd|Yn0dS)Nr r--pz 01-Jan-1970z"Failed to set pw expiration for %srrFrrGr)r0userrrr expire_passwds  zDistro.expire_passwdFcCsX|r d}nd}z"tjdd||dg|d|dWn"tyRttd|Yn0dS) Nz-Hz-hr r-0zchpasswd for %s)datar;zFailed to set password for %srO)r0rPr<r=Zhash_optrrrrHs   zDistro.set_passwdcCs@ztdd|ddgWn"ty:ttd|Yn0dS)Nr r-z-wnoz)Failed to lock password login for user %srOr0rIrrr lock_passwds  zDistro.lock_passwdcCstd|dS)NzRDragonfly BSD/FreeBSD password lock is not reversible, ignoring unlock for user %s)rdebugrUrrr unlock_passwdszDistro.unlock_passwdc Cst}t|jD]&}|tdd|||dqt|j|j t |j| z t d|td|jgWnZtjytt d|zt|j |jWn"tytt d|jYn0Yn0dS)Nz ^default:zdefault:lang=%s: zRunning cap_mkdb for %sZcap_mkdbzFailed to apply locale %szFailed to restore %s backup)rrZload_text_file login_conf_fn splitlineswriteresubcopylogin_conf_fn_bakZ write_filegetvaluerrWrZProcessExecutionErrorrGIOError)r0localeZout_fnZnewconflinerrr apply_locales&   zDistro.apply_localecCsddiS)zJReturn environment vars used in FreeBSD package_command operationsZASSUME_ALWAYS_YESZYESr)r0rrr_get_pkg_cmd_environszDistro._get_pkg_cmd_environ)forcecCs$|jjd|jdg|rtntddS)Nzupdate-sourcesr)Zfreq)Z_runnerrunZpackage_commandrr)r0rgrrrupdate_package_sourcess  zDistro.update_package_sources)path lease_filepid_file interface config_filer3cCs"|d|d|g|rd||gn|gS)Nz-lrNr4r)rjrkrlrmrnrrrbuild_dhclient_cmds zDistro.build_dhclient_cmd)devicer3cCstdd|gdS)NZ camcontrolZeject)r)rprrr eject_mediaszDistro.eject_media)N)F)N)&__name__ __module__ __qualname____doc__rZnetworking_clsZ usr_lib_execrZr`Z ci_sudoers_fnZgroup_add_cmd_prefixZpkg_cmd_install_prefixZpkg_cmd_remove_prefixZpkg_cmd_update_prefixZpkg_cmd_upgrade_prefixZ prefer_fqdnrEZdhclient_lease_directoryZdhclient_lease_file_regexZ#shadow_empty_locked_passwd_patterns classmethodrrAr,r2boolrMrQrHrVrXrerfri staticmethodr*rorqrrrrrsT >   r)Zloggingrr]iorZcloudinit.distros.bsdZ cloudinitrrZcloudinit.distros.networkingrZcloudinit.settingsrrZ getLoggerrrrZdistrosZbsdZBSDrrrrrs