Module: Puavo

Defined in:
lib/ldappasswd.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) ldap_passwd(host, bind_dn, current_pw, new_pw, user_dn)



6
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ldappasswd.rb', line 6

def self.ldap_passwd(host, bind_dn, current_pw, new_pw, user_dn)
  started = Time.now
  res = nil

  Open3.popen3(
    'ldappasswd',

    # Use simple authentication instead of SASL
    '-x',

    # Issue StartTLS (Transport Layer Security) extended operation
    '-Z',

    # Specify an alternate host on which the ldap server is running
    '-h', host,

    # Distinguished Name used to bind to the LDAP directory
    '-D', bind_dn.to_s,

    # The password to bind with
    '-w', current_pw,

    # Set the new password
    '-s', new_pw,

    # Timeout after 20 sec
    '-o', 'nettimeout=20',

    # User who's password we're going to change
    user_dn.to_s

  ) do |stdin, stdout, stderr, wait_thr|
    wait_thr.join

    res = {
      :duration => (Time.now.to_f - started.to_f).round(5),
      :stdout => stdout.read(1024 * 5),
      :stderr => stderr.read(1024 * 5),
      :exit_status => wait_thr.value.exitstatus
    }

  end

  return res
end