adap 0.0.20 → 0.1.0

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: 717838e91b87a82d3c3989bbfb3b723c2d02d301fdfa619a74397f1b54faf847
4
- data.tar.gz: 36670ebfbde205a1ddb89ad60b5b4f6a14d2c9e73abf5f8a9c26d2675674abcc
3
+ metadata.gz: 3158307760aaffe02f99a06d508783b569321759652824029bf91615cdfea9ea
4
+ data.tar.gz: 96bf2d0170c919e0a1946d5532c1d9e929dba0003548d6b091ba7d242d3238fd
5
5
  SHA512:
6
- metadata.gz: 8c383f2725b47a79632d68af4733243a841caf43ec017e932a20217fc63854acb00fb3998a3665346b2632200766f9ad55d36929197ab311e6cfc3544e9e5c32
7
- data.tar.gz: dfdb8c54733642e6849b0ecc5b55b490184cb1d29136bdc551c0417d1080096b71b2e99540d89d4a5b242705bb494a5110f26c3032249a612f942b3bf410f347
6
+ metadata.gz: b22800cef66237c05002282ee1b63cc2e6070d151ef899ed67af75a4069b994aeb2f11987b13ff2882864b237fccc8dca9274dba0a35fa25b8da897618dc998e
7
+ data.tar.gz: fd5bbdb231aa7c046335c8849af2898c30dd0e564a6b82faab86a4a63a77c8ebd2bd63611c28c8fe5c7ea70bcbad35019ec843497ef54f187051f1034cf2c775
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- adap (0.0.19)
4
+ adap (0.0.16)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -28,6 +28,15 @@ class Adap
28
28
  # List of attributes for user in LDAP
29
29
  @ldap_user_required_attributes = [:cn, :sn, :uid, :uidnumber, :gidnumber, :displayname, :loginshell, :gecos, :givenname, :description, :mail, :homedirectory]
30
30
 
31
+ # List of supported hash algorithms keys and string values to operate
32
+ @supported_hash_algorithms_map = {
33
+ :md5 => "{MD5}",
34
+ :sha => "{SHA}",
35
+ :ssha => "{SSHA}",
36
+ :virtual_crypt_sha256 => "virtualCryptSHA256",
37
+ :virtual_crypt_sha512 => "virtualCryptSHA512"
38
+ }
39
+
31
40
  @ad_host = params[:ad_host]
32
41
  @ad_port = (params[:ad_port] ? params[:ad_port] : 389)
33
42
  @ad_binddn = params[:ad_binddn]
@@ -40,8 +49,17 @@ class Adap
40
49
  @ldap_basedn = params[:ldap_basedn]
41
50
  @ldap_user_basedn = params[:ldap_user_basedn]
42
51
  @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'
44
- @password_hash_algorithm = (params[:password_hash_algorithm] ? params[:password_hash_algorithm] : 'virtualCryptSHA512')
52
+
53
+ # A password-hash algorithm to sync to the LDAP.
54
+ # Popular LDAP products like Open LDAP usually supports md5({MD5}), sha1({SHA}) and ssha({SSHA}) algorithms.
55
+ # If you want to use virtualCryptSHA256 or virtualCryptSHA512, you have to set additional configurations to OpenLDAP.
56
+ @password_hash_algorithm = (params[:password_hash_algorithm] ? params[:password_hash_algorithm] : :ssha)
57
+ # TODO: Check a hash algorithm is supported or not
58
+ unless @supported_hash_algorithms_map.has_key?(@password_hash_algorithm) then
59
+ raise "This program only supports :md5, :sha, :ssha(default), :virtual_crypt_sha256 and :virtual_crypt_sha512 " \
60
+ + "as :password_hash_algorithm. " \
61
+ + "An algorithm you chose #{@password_hash_algorithm.is_a?(Symbol) ? ":" : ""}#{@password_hash_algorithm} was unsupported."
62
+ end
45
63
 
46
64
  # Phonetics are listed in https://lists.samba.org/archive/samba/2017-March/207308.html
47
65
  @map_ad_msds_phonetics = {}
@@ -112,20 +130,33 @@ class Adap
112
130
  attributes
113
131
  end
114
132
 
115
- def get_password(username)
116
- result = get_raw_password(username, @password_hash_algorithm)
117
- if not result.nil? then
118
- result = result.chomp
133
+ def get_password_hash(username, password)
134
+ case @password_hash_algorithm
135
+ when :md5, :sha, :ssha then
136
+ if password.nil? then
137
+ raise "Password must not be nil when you chose the algorithm of password-hash is :md5 or :sha or :ssha. Pass password of #{username} please."
138
+ end
139
+ result = Net::LDAP::Password.generate(@password_hash_algorithm, password)
140
+ else
141
+ # Expects :virtual_crypt_sha256(virtualCryptSHA256) or :virtual_crypt_sha512(virtualCryptSHA512)
142
+ result = get_raw_password_from_ad(username, @supported_hash_algorithms_map[@password_hash_algorithm])
143
+ end
144
+
145
+ if result.nil? or result.empty? then
146
+ raise "Failed to get hashed password with algorithm :#{@password_hash_algorithm} of user #{username}. " +
147
+ "Its result was nil. If you chose hash-algorithm :virtual_crypt_sha256 or :virtual_crypt_sha512, " +
148
+ "did you enabled AD to store passwords as virtualCryptSHA256 and/or virtualCryptSHA512 in your smb.conf? " +
149
+ "This program requires the configuration to get password from AD as virtualCryptSHA256 or virtualCryptSHA512."
119
150
  end
120
151
 
121
- return result
152
+ result.chomp
122
153
  end
123
154
 
124
- def get_raw_password(username, algo)
155
+ def get_raw_password_from_ad(username, algo)
125
156
  `samba-tool user getpassword #{username} --attribute #{algo} 2> /dev/null | grep -E '^virtualCrypt' -A 1 | tr -d ' \n' | cut -d ':' -f 2`
126
157
  end
127
158
 
128
- def sync_user(uid)
159
+ def sync_user(uid, password=nil)
129
160
  ad_entry = nil
130
161
  ldap_entry = nil
131
162
  ad_dn = get_ad_dn(uid)
@@ -137,6 +168,7 @@ class Adap
137
168
  end
138
169
  ret_code = @ad_client.get_operation_result.code
139
170
 
171
+ # Return 32 means that the object does not exist
140
172
  return {
141
173
  :code => ret_code,
142
174
  :operations => nil,
@@ -156,11 +188,11 @@ class Adap
156
188
 
157
189
  ret = nil
158
190
  if !ad_entry.nil? and ldap_entry.nil? then
159
- ret = add_user(ldap_dn, ad_entry, get_password(uid))
191
+ ret = add_user(ldap_dn, ad_entry, get_password_hash(uid, password))
160
192
  elsif ad_entry.nil? and !ldap_entry.nil? then
161
193
  ret = delete_user(ldap_dn)
162
194
  elsif !ad_entry.nil? and !ldap_entry.nil? then
163
- ret = modify_user(ldap_dn, ad_entry, ldap_entry, get_password(uid))
195
+ ret = modify_user(ldap_dn, ad_entry, ldap_entry, get_password_hash(uid, password))
164
196
  else
165
197
  # ad_entry.nil? and ldap_entry.nil? then
166
198
  return {:code => 0, :operations => nil, :message => "There are not any data of #{uid} to sync."}
@@ -183,7 +215,7 @@ class Adap
183
215
 
184
216
  def add_user(ldap_user_dn, ad_entry, password)
185
217
  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?"
218
+ raise "add_user() requires password. Set a hashed password of the user #{ad_entry[:cn]} please."
187
219
  end
188
220
 
189
221
  attributes = create_ldap_attributes(ad_entry)
@@ -211,7 +243,7 @@ class Adap
211
243
  return {
212
244
  :code => ret_code,
213
245
  :operations => [:add_user],
214
- :message => "Failed to modify a user #{ldap_user_dn} in add_user() - " + @ldap_client.get_operation_result.error_message
246
+ :message => "Failed to modify a user #{ldap_user_dn} to add userPassword in add_user() - " + @ldap_client.get_operation_result.error_message
215
247
  } if ret_code != 0
216
248
 
217
249
  return {:code => ret_code, :operations => [:add_user], :message => nil}
@@ -1,3 +1,3 @@
1
1
  module ModAdap
2
- VERSION = "0.0.20"
2
+ VERSION = "0.1.0"
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.20
4
+ version: 0.1.0
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-07-29 00:00:00.000000000 Z
11
+ date: 2020-08-01 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: []