Class: AutomateIt::AccountManager::PasswdPTY

Inherits:
BaseDriver show all
Defined in:
lib/automateit/account_manager/passwd_pty.rb

Overview

AccountManager::PasswdPTY

An AccountManager driver for passwd command found on Unix-like systems using the Ruby PTY implementation.

WARNING: The Ruby PTY module is unreliable or unavailable on most platforms. It may hang indefinitely or report incorrect results. Every attempt has been made to work around these problems, but this is a low-level problem. You are strongly encouraged to install the expect program, which works flawlessly. Once the expect program is installed, passwords will be changed using the AccountManager::PasswdExpect driver, which works properly.

Constant Summary

Constants inherited from Plugin::Driver

Plugin::Driver::BASE_DRIVER_NAME

Constants included from Constants

Constants::HELPERS_DIR, Constants::INSTALL_DIR, Constants::PERROR, Constants::PEXEC, Constants::PNOTE, Constants::WARNING_BOILERPLATE

Instance Attribute Summary

Attributes inherited from Plugin::Driver

#manager

Attributes inherited from Common

#interpreter

Instance Method Summary collapse

Methods inherited from Plugin::Driver

abstract_driver, #available?, base_driver, base_driver?, depends_on, inherited, manager_token, #setup

Methods inherited from Plugin::Base

#setup, #token, token

Methods inherited from Common

#initialize, #log, #nitpick, #noop, #noop=, #noop?, #preview, #preview=, #preview?, #preview_for, #setup, #superuser?, #writing, #writing=, #writing?

Constructor Details

This class inherits a constructor from AutomateIt::Common

Instance Method Details

#passwd(user, password, opts = {}) ⇒ Object

See AccountManager#passwd



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/automateit/account_manager/passwd_pty.rb', line 25

def passwd(user, password, opts={})
  log.info(PERROR+"Setting password with flaky Ruby PTY, which hangs or fails randomly. Install 'expect' (http://expect.nist.gov/) for reliable operation.")
  _passwd_helper(user, password, opts) do
    log.silence(Logger::WARN) do
      interpreter.mktemp do |filename|
        tries = 5
        exitstatus = nil
        begin
          exitstruct = _passwd_raw(user, password, opts)
          if exitstatus and not exitstruct.exitstatus.zero?
            # FIXME AccountManager::Linux#passwd -- The `passwd` command randomly returns exit status 10 even when it succeeds. What does this mean and how to deal with it?! Temporary workaround is to throw an error and force a retry.
            raise Errno::EPIPE.new("bad exitstatus %s" % exitstruct.exitstatus)
          end
        rescue Errno::EPIPE => e
          # FIXME AccountManager::Linux#passwd -- EPIPE exception randomly thrown even when `passwd` succeeds. How to eliminate it? How to differentiate between this false error and a real one?
          if tries <= 0
            raise e
          else
            tries -= 1
            retry
          end
        end
        return exitstruct.exitstatus.zero?
      end
    end
  end

end

#suitability(method, *args) ⇒ Object

:nodoc:



19
20
21
22
# File 'lib/automateit/account_manager/passwd_pty.rb', line 19

def suitability(method, *args) # :nodoc:
  # Level must be higher than Linux
  return available? ? 3 : 0
end