Module: Bandshell::Passwords
- Defined in:
- lib/bandshell/passwords.rb
Class Method Summary collapse
Class Method Details
.restore_shadow ⇒ Object
41 42 43 44 45 |
# File 'lib/bandshell/passwords.rb', line 41 def self.restore_shadow oldshadow = IO.read("/etc/shadow") shadow_content = Bandshell::ConfigStore.read_config('shadow_file', oldshadow) IO.write("/etc/shadow", shadow_content) end |
.save_shadow ⇒ Object
36 37 38 39 |
# File 'lib/bandshell/passwords.rb', line 36 def self.save_shadow shadow_content = IO.read("/etc/shadow") Bandshell::ConfigStore.write_config('shadow_file', shadow_content) end |
.set_local_passwords ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bandshell/passwords.rb', line 7 def self.set_local_passwords if Bandshell::ConfigStore.config_exists?('system_passwords_changed') # if we have changed the passwords, try to restore the shadow file # from the configuration store restore_shadow else #if the password has not been changed before during initial setup, #read a new one and change passwords accordingly system_password = Bandshell::ConfigStore.read_config('system_password', '') unless system_password.empty? IO.popen("chpasswd", mode='r+') do |io| io.puts "root:#{system_password}" io.puts "concerto:#{system_password}" end if $? == 0 # remove plain text passwords from config and set flag Bandshell::ConfigStore.delete_config('system_password') Bandshell::ConfigStore.write_config('system_passwords_changed', 'true') # save shadow file (with password hashes) into config save_shadow else # chpasswd returned nonzero status... do something to indicate error end end end end |