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', '...']]


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

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.



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

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

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



76
77
78
# File 'lib/puppet/provider/openldap.rb', line 76

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

.ldapadd(path) ⇒ Object



26
27
28
# File 'lib/puppet/provider/openldap.rb', line 26

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

.ldapmodify(path) ⇒ Object



84
85
86
# File 'lib/puppet/provider/openldap.rb', line 84

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

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



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

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



92
93
94
# File 'lib/puppet/provider/openldap.rb', line 92

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

Instance Method Details

#add(key) ⇒ Object



116
117
118
# File 'lib/puppet/provider/openldap.rb', line 116

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

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



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
233
234
235
# File 'lib/puppet/provider/openldap.rb', line 132

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
    MultiProvider
    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



112
113
114
# File 'lib/puppet/provider/openldap.rb', line 112

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

#cn_configObject



104
105
106
# File 'lib/puppet/provider/openldap.rb', line 104

def cn_config
  dn('cn=config')
end

#del(key) ⇒ Object



120
121
122
# File 'lib/puppet/provider/openldap.rb', line 120

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

#delimitObject



100
101
102
# File 'lib/puppet/provider/openldap.rb', line 100

def delimit
  "-\n"
end

#dn(dn) ⇒ Object



108
109
110
# File 'lib/puppet/provider/openldap.rb', line 108

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

#get_entries(*args) ⇒ Object



72
73
74
# File 'lib/puppet/provider/openldap.rb', line 72

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

#get_lines(*args) ⇒ Object



44
45
46
# File 'lib/puppet/provider/openldap.rb', line 44

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

#key_value(key, value) ⇒ Object



128
129
130
# File 'lib/puppet/provider/openldap.rb', line 128

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

#last_of_split(*args) ⇒ Object



80
81
82
# File 'lib/puppet/provider/openldap.rb', line 80

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

#ldapadd(*args) ⇒ Object



30
31
32
# File 'lib/puppet/provider/openldap.rb', line 30

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

#ldapmodify(*args) ⇒ Object



88
89
90
# File 'lib/puppet/provider/openldap.rb', line 88

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

#replace_key(key) ⇒ Object



124
125
126
# File 'lib/puppet/provider/openldap.rb', line 124

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

#slapcat(*args) ⇒ Object



22
23
24
# File 'lib/puppet/provider/openldap.rb', line 22

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

#temp_ldif(*args) ⇒ Object



96
97
98
# File 'lib/puppet/provider/openldap.rb', line 96

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