Class: ActiveSambaLdap::Configuration::ClassMethods::Private

Inherits:
Object
  • Object
show all
Includes:
GetTextSupport
Defined in:
lib/active_samba_ldap/configuration.rb

Constant Summary collapse

VARIABLES =
%w(base host port scope bind_dn
password method allow_anonymous

sid smb_conf samba_domain samba_netbios_name
password_hash_type

users_suffix groups_suffix computers_suffix
idmap_suffix

start_uid start_gid

user_login_shell user_home_directory
user_home_directory_mode
user_gecos user_home_unc user_profile
user_home_drive user_logon_script mail_domain

skeleton_directory

default_user_gid default_computer_gid
default_max_password_age

samba4)
AVAILABLE_HASH_TYPES =
[:crypt, :md5, :smd5, :sha, :ssha]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GetTextSupport

included

Constructor Details

#initialize(target) ⇒ Private

Returns a new instance of Private.



119
120
121
# File 'lib/active_samba_ldap/configuration.rb', line 119

def initialize(target)
  @target = target.symbolize_keys
end

Class Method Details

.compute_required_variablesObject



111
112
113
114
115
116
# File 'lib/active_samba_ldap/configuration.rb', line 111

def compute_required_variables
  not_required_variables = %w(base scope ldap_scope)
  (VARIABLES - public_methods - not_required_variables).collect do |x|
    x.to_sym
  end
end

.required_variablesObject



107
108
109
# File 'lib/active_samba_ldap/configuration.rb', line 107

def required_variables
  @required_variables ||= compute_required_variables
end

Instance Method Details

#[](name) ⇒ Object



142
143
144
# File 'lib/active_samba_ldap/configuration.rb', line 142

def [](name)
  @target[name.to_sym] || (respond_to?(name) ? send(name) : nil)
end

#allow_anonymousObject



202
203
204
# File 'lib/active_samba_ldap/configuration.rb', line 202

def allow_anonymous
  false
end

#bind_dnObject



311
312
313
# File 'lib/active_samba_ldap/configuration.rb', line 311

def bind_dn
  nil
end

#computers_suffixObject



230
231
232
233
234
235
236
237
238
# File 'lib/active_samba_ldap/configuration.rb', line 230

def computers_suffix
  suffix = retrieve_value_from_smb_conf(/ldap\s+machine\s+suffix/i)
  return suffix if suffix
  if self[:samba4]
    "cn=Computers"
  else
    "ou=Computers"
  end
end

#default_computer_gidObject



257
258
259
260
# File 'lib/active_samba_ldap/configuration.rb', line 257

def default_computer_gid
  rid = ActiveSambaLdap::Group::DOMAIN_COMPUTERS_RID
  ActiveSambaLdap::Group.rid2gid(rid)
end

#default_user_gidObject



252
253
254
255
# File 'lib/active_samba_ldap/configuration.rb', line 252

def default_user_gid
  rid = ActiveSambaLdap::Group::DOMAIN_USERS_RID
  ActiveSambaLdap::Group.rid2gid(rid)
end

#groups_suffixObject



220
221
222
223
224
225
226
227
228
# File 'lib/active_samba_ldap/configuration.rb', line 220

def groups_suffix
  suffix = retrieve_value_from_smb_conf(/ldap\s+group\s+suffix/i)
  return suffix if suffix
  if self[:samba4]
    "cn=Users"
  else
    "ou=Groups"
  end
end

#hostObject



194
195
196
# File 'lib/active_samba_ldap/configuration.rb', line 194

def host
  "localhost"
end

#idmap_suffixObject



240
241
242
# File 'lib/active_samba_ldap/configuration.rb', line 240

def idmap_suffix
  retrieve_value_from_smb_conf(/ldap\s+idmap\s+suffix/i) || "ou=Idmap"
end

#mergeObject



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/active_samba_ldap/configuration.rb', line 123

def merge
  result = @target.dup
  VARIABLES.each do |variable|
    key = variable.to_sym
    result[key] ||= send(variable) if respond_to?(variable)

    normalize_method = "normalize_#{variable}"
    if respond_to?(normalize_method)
      result[key] = __send__(normalize_method, result[key])
    end

    validate_method = "validate_#{variable}"
    if respond_to?(validate_method)
      __send__(validate_method, result[key])
    end
  end
  result
end

#methodObject



206
207
208
# File 'lib/active_samba_ldap/configuration.rb', line 206

def method
  :plain
end

#normalize_password_hash_type(type) ⇒ Object



319
320
321
# File 'lib/active_samba_ldap/configuration.rb', line 319

def normalize_password_hash_type(type)
  type.to_s.downcase.to_sym
end

#normalize_user_home_directory_mode(mode) ⇒ Object



284
285
286
287
288
289
290
291
292
293
# File 'lib/active_samba_ldap/configuration.rb', line 284

def normalize_user_home_directory_mode(mode)
  if mode
    Integer(mode)
  else
    nil
  end
rescue ArgumentError
  raise InvalidConfigurationValueError.new("user_home_directory",
                                           mode, $!.message)
end

#password_hash_typeObject



315
316
317
# File 'lib/active_samba_ldap/configuration.rb', line 315

def password_hash_type
  :ssha
end

#portObject



198
199
200
# File 'lib/active_samba_ldap/configuration.rb', line 198

def port
  389
end

#samba4Object



323
324
325
326
327
328
329
330
# File 'lib/active_samba_ldap/configuration.rb', line 323

def samba4
  smb_conf = self[:smb_conf]
  if smb_conf and /^\s*server\s*role\s*=/ =~ File.read(smb_conf)
    true
  else
    false
  end
end

#samba_domainObject



162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/active_samba_ldap/configuration.rb', line 162

def samba_domain
  _smb_conf = self["smb_conf"]
  if _smb_conf
    File.open(_smb_conf) do |f|
      f.read.grep(/^\s*[^#;]/).each do |line|
        if /^\s*workgroup\s*=\s*(\S+)\s*$/i =~ line
          return $1.upcase
        end
      end
    end
  else
    nil
  end
end

#samba_netbios_nameObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/active_samba_ldap/configuration.rb', line 177

def samba_netbios_name
  netbios_name = nil
  _smb_conf = self["smb_conf"]
  if _smb_conf
    File.open(_smb_conf) do |f|
      f.read.grep(/^\s*[^#;]/).each do |line|
        if /^\s*netbios\s*name\s*=\s*(.+)\s*$/i =~ line
          netbios_name = $1
          break
        end
      end
    end
  end
  netbios_name ||= Socket.gethostname
  netbios_name ? netbios_name.upcase : nil
end

#sidObject



146
147
148
149
150
151
152
153
# File 'lib/active_samba_ldap/configuration.rb', line 146

def sid
  result = `net getlocalsid`
  if $?.success?
    result.chomp.gsub(/\G[^:]+:\s*/, '')
  else
    nil
  end
end

#skeleton_directoryObject



262
263
264
# File 'lib/active_samba_ldap/configuration.rb', line 262

def skeleton_directory
  "/etc/skel"
end

#smb_confObject



155
156
157
158
159
160
# File 'lib/active_samba_ldap/configuration.rb', line 155

def smb_conf
  %w(/etc/samba/smb.conf /usr/local/etc/samba/smb.conf).each do |guess|
    return guess if File.exist?(guess)
  end
  nil
end

#start_gidObject



248
249
250
# File 'lib/active_samba_ldap/configuration.rb', line 248

def start_gid
  10000
end

#start_uidObject



244
245
246
# File 'lib/active_samba_ldap/configuration.rb', line 244

def start_uid
  10000
end

#user_gecosObject



307
308
309
# File 'lib/active_samba_ldap/configuration.rb', line 307

def user_gecos
  nil
end

#user_home_directoryObject



276
277
278
# File 'lib/active_samba_ldap/configuration.rb', line 276

def user_home_directory
  "/home/%U"
end

#user_home_directory_modeObject



280
281
282
# File 'lib/active_samba_ldap/configuration.rb', line 280

def user_home_directory_mode
  0755
end

#user_home_driveObject



299
300
301
# File 'lib/active_samba_ldap/configuration.rb', line 299

def user_home_drive
  "H:"
end

#user_home_uncObject



266
267
268
269
# File 'lib/active_samba_ldap/configuration.rb', line 266

def user_home_unc
  netbios_name = self["samba_netbios_name"]
  netbios_name ? "\\\\#{netbios_name}\\%U" : nil
end

#user_login_shellObject



295
296
297
# File 'lib/active_samba_ldap/configuration.rb', line 295

def 
  "/bin/false"
end

#user_logon_scriptObject



303
304
305
# File 'lib/active_samba_ldap/configuration.rb', line 303

def user_logon_script
  "logon.bat"
end

#user_profileObject



271
272
273
274
# File 'lib/active_samba_ldap/configuration.rb', line 271

def 
  netbios_name = self["samba_netbios_name"]
  netbios_name ? "\\\\#{netbios_name}\\profiles\\%U" : nil
end

#users_suffixObject



210
211
212
213
214
215
216
217
218
# File 'lib/active_samba_ldap/configuration.rb', line 210

def users_suffix
  suffix = retrieve_value_from_smb_conf(/ldap\s+user\s+suffix/i)
  return suffix if suffix
  if self[:samba4]
    "cn=Users"
  else
    "ou=Users"
  end
end

#validate_password_hash_type(type) ⇒ Object



333
334
335
336
337
338
339
340
# File 'lib/active_samba_ldap/configuration.rb', line 333

def validate_password_hash_type(type)
  unless AVAILABLE_HASH_TYPES.include?(type)
    types = AVAILABLE_HASH_TYPES.collect {|x| x.inspect}.join(", ")
    raise InvalidConfigurationValueError.new("password_hash_type",
                                             type,
                                             _("must be in %s") % types)
  end
end