Class: Puppet::Provider::Openldap

Inherits:
Puppet::Provider
  • Object
show all
Defined in:
lib/puppet/provider/openldap.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_entries(items) ⇒ Object

Unwrap LDIF and return each entry as array of lines.

Example LDIF:

dn: cn=config
...

dn: cn=schema,cn=config
...

Results in:

[['dn: cn=config', '...'],
 ['dn: cn=schema,cn=config', '...']]


60
61
62
63
64
65
66
67
68
# File 'lib/puppet/provider/openldap.rb', line 60

def self.get_entries(items)
  items.strip.
    split("\n\n").
    map do |paragraph|
      paragraph.
        gsub("\n ", '').
        split("\n")
    end
end

.get_lines(items) ⇒ Object

Unwrap LDIF and return each attribute beginning with “olc” also removing that occurance of “olc” at the beginning.



34
35
36
37
38
39
40
# File 'lib/puppet/provider/openldap.rb', line 34

def self.get_lines(items)
  items.strip.
    gsub("\n ", '').
    split("\n").
    select { |entry| entry =~ %r{^olc} }.
    map { |entry| entry.gsub(%r{^olc}, '') }
end

.last_of_split(line, by = ' ') ⇒ Object



74
75
76
# File 'lib/puppet/provider/openldap.rb', line 74

def self.last_of_split(line, by = ' ')
  line.split(by, 2).last
end

.ldapadd(path) ⇒ Object



24
25
26
# File 'lib/puppet/provider/openldap.rb', line 24

def self.ldapadd(path)
  original_ldapadd('-cQY', 'EXTERNAL', '-H', 'ldapi:///', '-f', path)
end

.ldapmodify(path) ⇒ Object



82
83
84
# File 'lib/puppet/provider/openldap.rb', line 82

def self.ldapmodify(path)
  original_ldapmodify('-Y', 'EXTERNAL', '-H', 'ldapi:///', '-f', path)
end

.slapcat(filter, dn = '', base = 'cn=config') ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/puppet/provider/openldap.rb', line 10

def self.slapcat(filter, dn = '', base = 'cn=config')
  arguments = [
    '-b', base,
    '-o', 'ldif-wrap=no',
    '-H', "ldap:///#{dn}???#{filter}"
  ]

  original_slapcat(*arguments)
end

.temp_ldif(name = 'openldap_ldif') ⇒ Object



90
91
92
# File 'lib/puppet/provider/openldap.rb', line 90

def self.temp_ldif(name = 'openldap_ldif')
  Tempfile.new(name)
end

Instance Method Details

#add(key) ⇒ Object



114
115
116
# File 'lib/puppet/provider/openldap.rb', line 114

def add(key)
  "add: olc#{key}\n"
end

#add_or_replace_key(key, force_replace = :false) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/puppet/provider/openldap.rb', line 130

def add_or_replace_key(key, force_replace = :false)
  # This list of possible attributes of cn=config has been extracted from a
  # running slapd with the following command:
  #   ldapsearch -s base -b cn=Subschema attributeTypes -o ldif-wrap=no | \
  #     grep SINGLE-VALUE | grep "NAME 'olc" | \
  #     sed -e "s|.*NAME '||g" \
  #         -e "s|' SYNTAX.*||g" \
  #         -e "s|' EQUALITY.*||g" \
  #         -e "s|' DESC.*||g"
  single_value_attributes = %w[
    ConfigFile
    ConfigDir
    AddContentAcl
    ArgsFile
    AuthzPolicy
    Backend
    Concurrency
    ConnMaxPending
    ConnMaxPendingAuth
    Database
    DefaultSearchBase
    GentleHUP
    Hidden
    IdleTimeout
    IndexSubstrIfMinLen
    IndexSubstrIfMaxLen
    IndexSubstrAnyLen
    IndexSubstrAnyStep
    IndexIntLen
    LastMod
    ListenerThreads
    LocalSSF
    LogFile
    MaxDerefDepth
    MirrorMode
    ModulePath
    Monitoring
    Overlay
    PasswordCryptSaltFormat
    PidFile
    PluginLogFile
    ReadOnly
    Referral
    ReplicaArgsFile
    ReplicaPidFile
    ReplicationInterval
    ReplogFile
    ReverseLookup
    RootDN
    RootPW
    SaslAuxprops
    SaslHost
    SaslRealm
    SaslSecProps
    SchemaDN
    SizeLimit
    SockbufMaxIncoming
    SockbufMaxIncomingAuth
    Subordinate
    SyncUseSubentry
    Threads
    TLSCACertificateFile
    TLSCACertificatePath
    TLSCertificateFile
    TLSCertificateKeyFile
    TLSCipherSuite
    TLSCRLCheck
    TLSCRLFile
    TLSRandFile
    TLSVerifyClient
    TLSDHParamFile
    TLSProtocolMin
    ToolThreads
    UpdateDN
    WriteTimeout
    DbDirectory
    DbCheckpoint
    DbNoSync
    DbMaxReaders
    DbMaxSize
    DbMode
    DbSearchStack
    PPolicyDefault
    PPolicyHashCleartext
    PPolicyForwardUpdates
    PPolicyUseLockout
    MemberOfDN
    MemberOfDangling
    MemberOfRefInt
    MemberOfGroupOC
    MemberOfMemberAD
    MemberOfMemberOfAD
    MemberOfDanglingError
    SpCheckpoint
    SpSessionlog
    SpNoPresent
    SpReloadHint
  ]

  use_replace = single_value_attributes.include?(key.to_s) || force_replace == :true

  use_replace ? replace_key(key) : add(key)
end

#changetype(t) ⇒ Object



110
111
112
# File 'lib/puppet/provider/openldap.rb', line 110

def changetype(t)
  "changetype: #{t}\n"
end

#cn_configObject



102
103
104
# File 'lib/puppet/provider/openldap.rb', line 102

def cn_config
  dn('cn=config')
end

#del(key) ⇒ Object



118
119
120
# File 'lib/puppet/provider/openldap.rb', line 118

def del(key)
  "delete: olc#{key}\n"
end

#delimitObject



98
99
100
# File 'lib/puppet/provider/openldap.rb', line 98

def delimit
  "-\n"
end

#dn(dn) ⇒ Object



106
107
108
# File 'lib/puppet/provider/openldap.rb', line 106

def dn(dn)
  "dn: #{dn}\n"
end

#get_entries(*args) ⇒ Object



70
71
72
# File 'lib/puppet/provider/openldap.rb', line 70

def get_entries(*args)
  self.class.get_entries(*args)
end

#get_lines(*args) ⇒ Object



42
43
44
# File 'lib/puppet/provider/openldap.rb', line 42

def get_lines(*args)
  self.class.get_lines(*args)
end

#key_value(key, value) ⇒ Object



126
127
128
# File 'lib/puppet/provider/openldap.rb', line 126

def key_value(key, value)
  "olc#{key}: #{value}\n"
end

#last_of_split(*args) ⇒ Object



78
79
80
# File 'lib/puppet/provider/openldap.rb', line 78

def last_of_split(*args)
  self.class.last_of_split(*args)
end

#ldapadd(*args) ⇒ Object



28
29
30
# File 'lib/puppet/provider/openldap.rb', line 28

def ldapadd(*args)
  self.class.ldapadd(*args)
end

#ldapmodify(*args) ⇒ Object



86
87
88
# File 'lib/puppet/provider/openldap.rb', line 86

def ldapmodify(*args)
  self.class.ldapmodify(*args)
end

#replace_key(key) ⇒ Object



122
123
124
# File 'lib/puppet/provider/openldap.rb', line 122

def replace_key(key)
  "replace: olc#{key}\n"
end

#slapcat(*args) ⇒ Object



20
21
22
# File 'lib/puppet/provider/openldap.rb', line 20

def slapcat(*args)
  self.class.slapcat(*args)
end

#temp_ldif(*args) ⇒ Object



94
95
96
# File 'lib/puppet/provider/openldap.rb', line 94

def temp_ldif(*args)
  self.class.temp_ldif(*args)
end