adap 0.0.13 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7a90f5e95be590f11b7922449ee42c0c28c5e7038606841ffbdaeedf9653cff
4
- data.tar.gz: 8e6bfbbe533a4306be70ada982bc365cdabe07fb16717062b8381e2edbaea797
3
+ metadata.gz: 79f0099367a12ae334622a2de2da08349595a29295bdbab740df1436a5049c3e
4
+ data.tar.gz: b1038603bd55124f3d2179736755e72e26d4015da212b7866942ced393335022
5
5
  SHA512:
6
- metadata.gz: 338adbb7c6588c96978feee4c1aafb677c6acbe6f6d8d3f02156814130d98a834c1073763b8aa25cfb6af8479392f03cd17179db505d4c718fdedd5f4f7b488a
7
- data.tar.gz: 622e87f387825d528605ddd0aaab433fe1f4b6d446f37c45de4cb49eb21f91ea710af243661090acae55c289f4a8da254d39b2b6be2ba85794d1ee5dff62d41a
6
+ metadata.gz: 54ffe5f02ce54bbdc962c176452091e37d6bad1ee56e73b0447b462535d2e09d356843e61f5d5ae6e30408ee6731ac76ad054d80b1ba69e781e748f63a322362
7
+ data.tar.gz: 9c519f4d69255a9d9bc58012d0181f35b1ccbf4427956b10bcf8d35cfb5906047e3bed4457bdd7a704fc7c1f2bfa7aec154d71e3d149285f15976cb86a0700bb
data/Gemfile CHANGED
@@ -8,3 +8,5 @@ gem "unix-crypt", "~> 1.3"
8
8
  gem "net-ldap", "~> 0.16.2"
9
9
 
10
10
  gem "mocha", "~> 1.10"
11
+
12
+ gem "rake", "~> 13.0"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- adap (0.0.7)
4
+ adap (0.0.16)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,7 +9,7 @@ GEM
9
9
  minitest (5.14.0)
10
10
  mocha (1.11.2)
11
11
  net-ldap (0.16.2)
12
- rake (10.5.0)
12
+ rake (13.0.1)
13
13
  unix-crypt (1.3.0)
14
14
 
15
15
  PLATFORMS
@@ -21,7 +21,7 @@ DEPENDENCIES
21
21
  minitest (~> 5.0)
22
22
  mocha (~> 1.10)
23
23
  net-ldap (~> 0.16.2)
24
- rake (~> 10.0)
24
+ rake (~> 13.0)
25
25
  unix-crypt (~> 1.3)
26
26
 
27
27
  BUNDLED WITH
@@ -2,12 +2,6 @@ require 'net-ldap'
2
2
 
3
3
  class Adap
4
4
 
5
- # :unixhomedirectory and :homedirectory are the attributes that has same meaning between AD and LDAP.
6
- USER_REQUIRED_ATTRIBUTES = [:cn, :sn, :uid, :uidnumber, :gidnumber, :displayname, :loginshell, :gecos, :givenname, :unixhomedirectory, :homedirectory]
7
- #USER_REQUIRED_ATTRIBUTES = ['cn', 'sn', 'uid', 'uidNumber', 'gidNumber', 'homeDirectory', 'loginShell', 'gecos', 'givenName']
8
- GROUP_OF_USER_REQUIRED_ATTRIBUTES = [:objectclass, :gidnumber, :cn, :description, :memberuid]
9
-
10
- #
11
5
  # params {
12
6
  # :ad_host required IP or hostname of AD.
13
7
  # :ad_port optional (default:389) Port of AD host.
@@ -24,11 +18,16 @@ class Adap
24
18
  #
25
19
  def initialize(params)
26
20
  raise "Initialize Adap was failed. params must not be nil" if params == nil
27
- #raise 'Adap requires keys of parameter "ad_host" "ad_binddn" "ad_basedn"' \
21
+
28
22
  [:ad_host, :ad_binddn, :ad_basedn, :ldap_host, :ldap_binddn, :ldap_basedn].each { |k|
29
23
  raise 'Adap requires keys in params ":ad_host", ":ad_binddn", ":ad_basedn", ":ldap_host", ":ldap_binddn", ":ldap_basedn"' if !params.key?(k)
30
24
  }
31
25
 
26
+ # List of attributes for user in AD
27
+ @ad_user_required_attributes = [:cn, :sn, :uid, :uidnumber, :gidnumber, :displayname, :loginshell, :gecos, :givenname, :description, :unixhomedirectory]
28
+ # List of attributes for user in LDAP
29
+ @ldap_user_required_attributes = [:cn, :sn, :uid, :uidnumber, :gidnumber, :displayname, :loginshell, :gecos, :givenname, :description, :homedirectory]
30
+
32
31
  @ad_host = params[:ad_host]
33
32
  @ad_port = (params[:ad_port] ? params[:ad_port] : 389)
34
33
  @ad_binddn = params[:ad_binddn]
@@ -37,15 +36,41 @@ class Adap
37
36
  @ldap_host = params[:ldap_host]
38
37
  @ldap_port = (params[:ldap_port] ? params[:ldap_port] : 389)
39
38
  @ldap_binddn = params[:ldap_binddn]
39
+ @ldap_suffix_ou = (params[:ldap_suffix_ou] ? params[:ldap_suffix_ou] : "ou=Users")
40
40
  @ldap_basedn = params[:ldap_basedn]
41
41
  @ldap_user_basedn = params[:ldap_user_basedn]
42
42
  @ldap_auth = (params.has_key?(:ldap_password) ? { :method => :simple, :username => @ldap_binddn, :password => params[:ldap_password] } : nil )
43
+ # This attribute converted in generally ... :'msds-phoneticdisplayname' -> :'displayname;lang-ja;phonetic'
43
44
  @password_hash_algorithm = (params[:password_hash_algorithm] ? params[:password_hash_algorithm] : 'virtualCryptSHA512')
44
45
 
46
+ # Phonetics are listed in https://lists.samba.org/archive/samba/2017-March/207308.html
47
+ @map_ad_msds_phonetics = {}
48
+ @map_ldap_msds_phonetics = {}
49
+ if params[:map_msds_phonetics] != nil
50
+ p = params[:map_msds_phonetics]
51
+ # msDS-PhoneticCompanyName => companyName;lang-ja;phonetic
52
+ create_map_phonetics(p, :'msds-phoneticcompanyname') if p[:'msds-phoneticcompanyname'] != nil
53
+ # msDS-PhoneticDepartment => department;lang-ja;phonetic
54
+ create_map_phonetics(p, :'msds-phoneticdepartment') if p[:'msds-phoneticdepartment'] != nil
55
+ # msDS-PhoneticFirstName => firstname;lang-ja;phonetic
56
+ create_map_phonetics(p, :'msds-phoneticfirstname') if p[:'msds-phoneticfirstname'] != nil
57
+ # msDS-PhoneticLastName => lastname;lang-ja;phonetic
58
+ create_map_phonetics(p, :'msds-phoneticlastname') if p[:'msds-phoneticlastname'] != nil
59
+ # msDS-PhoneticDisplayName => displayname;lang-ja;phonetic
60
+ create_map_phonetics(p, :'msds-phoneticdisplayname') if p[:'msds-phoneticdisplayname'] != nil
61
+ end
62
+
45
63
  @ad_client = Adap::get_ad_client_instance(@ad_host, @ad_port, @ad_auth)
46
64
  @ldap_client = Adap::get_ldap_client_instance(@ldap_host, @ldap_port, @ldap_auth)
47
65
  end
48
66
 
67
+ private def create_map_phonetics(p, ad_phonetics)
68
+ @map_ad_msds_phonetics[ad_phonetics] = p[ad_phonetics]
69
+ @map_ldap_msds_phonetics[p[ad_phonetics]] = ad_phonetics
70
+ @ad_user_required_attributes.push(ad_phonetics)
71
+ @ldap_user_required_attributes.push(p[ad_phonetics])
72
+ end
73
+
49
74
  def self.get_ad_client_instance(ad_host, ad_port, ad_auth)
50
75
  Net::LDAP.new(:host => ad_host, :port => ad_port, :auth => ad_auth)
51
76
  end
@@ -59,23 +84,27 @@ class Adap
59
84
  end
60
85
 
61
86
  def get_ldap_dn(username)
62
- "uid=#{username},ou=Users,#{@ldap_basedn}"
87
+ "uid=#{username},#{@ldap_suffix_ou},#{@ldap_basedn}"
63
88
  end
64
89
 
65
- def create_ldap_attributes(entry)
90
+ def create_ldap_attributes(ad_entry)
66
91
  attributes = {
67
92
  :objectclass => ["top", "person", "organizationalPerson", "inetOrgPerson", "posixAccount", "shadowAccount"]
68
93
  }
69
94
 
70
- entry.each do |attribute, values|
95
+ ad_entry.each do |attribute, values|
71
96
  # Change string to lower case symbols to compare each attributes correctly
72
- attribute = attribute.downcase.to_sym
97
+ sym_attribute = attribute.downcase.to_sym
73
98
 
74
- if USER_REQUIRED_ATTRIBUTES.include?(attribute) then
75
- if attribute == :unixhomedirectory then
99
+ if @ad_user_required_attributes.include?(sym_attribute) then
100
+ if sym_attribute == :unixhomedirectory then
76
101
  attributes[:homedirectory] = values
102
+ elsif @map_ad_msds_phonetics.has_key?(sym_attribute) && ad_entry[attribute].length != 0
103
+ # entry always returns an array that length 0 if the attribute does not existed.
104
+ # So no need to check whether the ad_entry[attribute] is nil or not.
105
+ attributes[@map_ad_msds_phonetics[sym_attribute]] = values
77
106
  else
78
- attributes[attribute] = values
107
+ attributes[sym_attribute] = values
79
108
  end
80
109
  end
81
110
  end
@@ -84,14 +113,12 @@ class Adap
84
113
  end
85
114
 
86
115
  def get_password(username)
87
- password = get_raw_password(username, @password_hash_algorithm)
88
-
89
- if password == nil || password.empty?
90
- raise "Failed to get password of #{username} from AD. Did you enabled AD password option virtualCryptSHA512 and/or virtualCryptSHA256?"
116
+ result = get_raw_password(username, @password_hash_algorithm)
117
+ if not result.nil? then
118
+ result = result.chomp
91
119
  end
92
- password = password.chomp
93
120
 
94
- password
121
+ return result
95
122
  end
96
123
 
97
124
  def get_raw_password(username, algo)
@@ -155,6 +182,10 @@ class Adap
155
182
  end
156
183
 
157
184
  def add_user(ldap_user_dn, ad_entry, password)
185
+ if password == nil || password.empty?
186
+ raise "Password of #{ldap_user_dn} from AD in add_user is empty or nil. Did you enabled AD password option virtualCryptSHA512 and/or virtualCryptSHA256?"
187
+ end
188
+
158
189
  attributes = create_ldap_attributes(ad_entry)
159
190
 
160
191
  @ldap_client.add(
@@ -210,27 +241,43 @@ class Adap
210
241
 
211
242
  ad_entry.each do |key, value|
212
243
  ad_key_sym = key.downcase.to_sym
213
- ldap_key = (ad_key_sym != :unixhomedirectory ? ad_key_sym : :homedirectory)
244
+ ldap_key = if ad_key_sym == :unixhomedirectory
245
+ :homedirectory
246
+ elsif @map_ad_msds_phonetics.has_key?(ad_key_sym)
247
+ @map_ad_msds_phonetics[ad_key_sym]
248
+ else
249
+ ad_key_sym
250
+ end
214
251
  ldap_key_sym = ldap_key.downcase.to_sym
215
252
 
216
- if USER_REQUIRED_ATTRIBUTES.include?(ad_key_sym)
217
- next if value == ldap_entry[ldap_key]
253
+ # TODO: Can @ad_user_required_attributes.include? be put more early line?
254
+ if @ad_user_required_attributes.include?(ad_key_sym) && value != ldap_entry[ldap_key]
255
+ #next if value == ldap_entry[ldap_key]
218
256
  operations.push((ldap_entry[ldap_key] != nil ? [:replace, ldap_key_sym, value] : [:add, ldap_key_sym, value]))
219
257
  end
220
258
  end
221
259
 
222
260
  ldap_entry.each do |key, value|
223
261
  ldap_key_sym = key.downcase.to_sym
224
- ad_key = (ldap_key_sym != :homedirectory ? ldap_key_sym : :unixhomedirectory)
225
-
226
- if USER_REQUIRED_ATTRIBUTES.include?(ldap_key_sym)
227
- operations.push([:delete, ldap_key_sym, nil]) if ad_entry[ad_key] == nil
262
+ #ad_key = (ldap_key_sym != :homedirectory ? ldap_key_sym : :unixhomedirectory)
263
+ ad_key = if ldap_key_sym == :homedirectory
264
+ :unixhomedirectory
265
+ elsif @map_ldap_msds_phonetics.has_key?(ldap_key_sym)
266
+ @map_ldap_msds_phonetics[ldap_key_sym]
267
+ else
268
+ ldap_key_sym
269
+ end
270
+
271
+ if @ldap_user_required_attributes.include?(ldap_key_sym) && ad_entry[ad_key] == nil
272
+ operations.push([:delete, ldap_key_sym, nil])
228
273
  end
229
274
  end
230
275
 
231
276
  # AD does not have password as simple ldap attribute.
232
277
  # So password will always be updated for this reason.
233
- operations.push([:replace, :userpassword, password])
278
+ if not password.nil? and not password.empty? then
279
+ operations.push([:replace, :userpassword, password])
280
+ end
234
281
 
235
282
  operations
236
283
  end
@@ -459,12 +506,13 @@ class Adap
459
506
 
460
507
  def get_primary_gidnumber_from_ad(uid)
461
508
  return nil if uid ==nil
509
+ primary_gid = nil
462
510
 
463
511
  @ad_client.search(:base => "CN=#{uid},CN=Users,#{@ad_basedn}") do |entry|
464
512
  primary_gid = entry[:gidnumber].first
465
513
  end
466
514
 
467
- return primary_gid
515
+ primary_gid
468
516
  end
469
517
 
470
518
  end
@@ -1,3 +1,3 @@
1
1
  module ModAdap
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.19"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tsutomu Nakamura
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-26 00:00:00.000000000 Z
11
+ date: 2020-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -79,7 +79,7 @@ homepage: https://github.com/TsutomuNakamura/adap
79
79
  licenses: []
80
80
  metadata:
81
81
  homepage_uri: https://github.com/TsutomuNakamura/adap
82
- post_install_message:
82
+ post_install_message:
83
83
  rdoc_options: []
84
84
  require_paths:
85
85
  - lib
@@ -94,8 +94,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  requirements: []
97
- rubygems_version: 3.1.2
98
- signing_key:
97
+ rubygems_version: 3.1.3
98
+ signing_key:
99
99
  specification_version: 4
100
100
  summary: LDAP migration tool from AD to NT schema
101
101
  test_files: []