1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- require 'tempfile'
- # Base provider class for OpenLDAP defined types
- class Puppet::Provider::Openldap < Puppet::Provider
- # Initialize provider structure
- initvars
- # Declare binaries that we use
- commands original_ldapadd: 'ldapadd',
- original_ldapmodify: 'ldapmodify',
- original_slapcat: 'slapcat'
- # Class-level wrapper methods for ldap binaries
- def self.ldapadd(path)
- original_ldapadd('-cQY', 'EXTERNAL', '-H', 'ldapi:///', '-f', path)
- end
- def self.ldapmodify(path)
- original_ldapmodify('-Y', 'EXTERNAL', '-H', 'ldapi:///', '-f', path)
- end
- def self.slapcat(filter, dn = '', base = 'cn=config')
- arguments = [
- '-b', base,
- '-o', 'ldif-wrap=no',
- '-H', "ldap:///#{dn}???#{filter}"
- ]
- original_slapcat(*arguments)
- end
- # Instance-level wrapper methods
- def ldapadd(*args)
- self.class.ldapadd(*args)
- end
- def ldapmodify(*args)
- self.class.ldapmodify(*args)
- end
- def slapcat(*args)
- self.class.slapcat(*args)
- end
- # Create temporary LDIF file
- def self.temp_ldif(name = 'openldap_ldif')
- Tempfile.new(name)
- end
- def temp_ldif(*args)
- self.class.temp_ldif(*args)
- end
- # Methods to generate LDIF fragments
- def delimit
- "-\n"
- end
- def cn_config
- dn('cn=config')
- end
- def dn(dn)
- "dn: #{dn}\n"
- end
- def changetype(t)
- "changetype: #{t}\n"
- end
- def add(key)
- "add: olc#{key}\n"
- end
- def del(key)
- "delete: olc#{key}\n"
- end
- def replace(key)
- "replace: olc#{key}\n"
- end
- def key_with_value(key, value)
- "olc#{key}: #{value}\n"
- end
- end
|