adap 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9689b192170a4cc2976d36fad77d1e67a89a25090bbcf82eadec964e45ac6b60
4
- data.tar.gz: 3d834f3d62e8a641cceb49f353d898cbdde4edaac3550f01aeebf9bdd2239383
3
+ metadata.gz: 6062f55568a4d2f91e7ede91b7419827b7767033adcbf264d8d8cbd64e8533f2
4
+ data.tar.gz: 47ae89751e819d81ed42bcb13dcbd967221ba45cf62c9e0d7aa77bfcbff48c03
5
5
  SHA512:
6
- metadata.gz: bb859c3aca6dd3c262233c2760de8ed11e8efef924e71aeb1a61bbea48766037853fd2ec490345925864a5bdb2927749fec8d399e1a550bcc0364d125ddc19ab
7
- data.tar.gz: d7b266e66cb56c92666eb4d65766c2ce80cf312f99a9da8de4e404ad1df1eceaae31ed0822db5c0fa64b1216f2d33613156a1eb4f29e60dd426a3f9b644f9070
6
+ metadata.gz: ce373202bef4eff421528e8de4dcc56d19960834c31573f9d8d04db3f070d86f31bcdd5892c6081edbd5733fc4ee9ca4087e04aa99132201f885e5f443d89543
7
+ data.tar.gz: f07477a60bced73b4a28e9d9b5e65f42043f781a92300bad8f5820d10d134bdbd6a19c390d00dc9b43f2b1ef07e289723331a648a4b6367d0036107fd27c61d3
@@ -0,0 +1,66 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ tags: ["v*"]
13
+ branches: [ "master", "develop" ]
14
+ pull_request:
15
+ branches: [ "master" ]
16
+
17
+ permissions:
18
+ contents: read
19
+
20
+ jobs:
21
+ test:
22
+
23
+ strategy:
24
+ fail-fast: false
25
+ matrix:
26
+ #os: [ubuntu-latest]
27
+ os: [ubuntu-24.04]
28
+ # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
29
+ ruby: ['3.3']
30
+ runs-on: ${{ matrix.os }}
31
+
32
+ steps:
33
+ - name: Print variables that will be used
34
+ run: |
35
+ # You can list GitHub Actionses variables with a command below.
36
+ # $ grep -oP '\$\{\{.*?\}\}' .github/workflows/docker-image.yml | sort | uniq
37
+ echo env.dest_repository_name=${{ env.dest_repository_name }}
38
+ echo env.dest_repository_owner_name=${{ env.dest_repository_owner_name }}
39
+ echo github.event.repository.name=${{ github.event.repository.name }}
40
+ echo github.event.repository.owner.name=${{ github.event.repository.owner.name }}
41
+
42
+ - name: Check out ${{ github.event.repository.owner.name }}/${{ github.event.repository.name }}
43
+ uses: actions/checkout@v4
44
+ with:
45
+ path: ${{ github.event.repository.name }}
46
+
47
+ - name: Set up Ruby
48
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
49
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
50
+ uses: ruby/setup-ruby@v1
51
+ #uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
52
+ with:
53
+ ruby-version: ${{ matrix.ruby }}
54
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
55
+
56
+ - name: Run tests
57
+ run: |
58
+ cd ${GITHUB_WORKSPACE}/${{ github.event.repository.name }}
59
+ bundle install --retry 3
60
+ bundle exec rake
61
+
62
+ - name: Push to rubygems.org
63
+ if: startsWith(github.ref, 'refs/tags/v')
64
+ run: |
65
+ echo "DEMO: Push to rubygems.org"
66
+
data/Gemfile CHANGED
@@ -1,12 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
- # Specify your gem's dependencies in adap.gemspec
4
- gemspec
5
+ # gem "rails"
5
6
 
6
7
  gem "unix-crypt", "~> 1.3"
7
8
 
8
- gem "net-ldap", "~> 0.16.2"
9
+ gem "net-ldap", "~> 0.19.0"
10
+
11
+ gem "mocha", "~> 2.7"
12
+
13
+ gem "rake", "~> 13.2"
9
14
 
10
- gem "mocha", "~> 1.10"
15
+ gem "base64", "~> 0.2.0"
11
16
 
12
- gem "rake", "~> 13.0"
17
+ gem "minitest", "~> 5.25"
data/Gemfile.lock CHANGED
@@ -1,26 +1,26 @@
1
- PATH
2
- remote: .
3
- specs:
4
- adap (0.1.3)
5
-
6
1
  GEM
7
2
  remote: https://rubygems.org/
8
3
  specs:
9
- minitest (5.14.0)
10
- mocha (1.11.2)
11
- net-ldap (0.16.2)
12
- unix-crypt (1.3.0)
4
+ base64 (0.2.0)
5
+ minitest (5.25.4)
6
+ mocha (2.7.1)
7
+ ruby2_keywords (>= 0.0.5)
8
+ net-ldap (0.19.0)
9
+ rake (13.2.1)
10
+ ruby2_keywords (0.0.5)
11
+ unix-crypt (1.3.1)
13
12
 
14
13
  PLATFORMS
15
14
  ruby
15
+ x86_64-linux
16
16
 
17
17
  DEPENDENCIES
18
- adap!
19
- bundler (~> 2.0)
20
- minitest (~> 5.0)
21
- mocha (~> 1.10)
22
- net-ldap (~> 0.16.2)
18
+ base64 (~> 0.2.0)
19
+ minitest (~> 5.25)
20
+ mocha (~> 2.7)
21
+ net-ldap (~> 0.19.0)
22
+ rake (~> 13.2)
23
23
  unix-crypt (~> 1.3)
24
24
 
25
25
  BUNDLED WITH
26
- 2.2.23
26
+ 2.5.22
data/README.md CHANGED
@@ -209,10 +209,6 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
209
209
 
210
210
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
211
211
 
212
- ## Build
213
-
214
- gem build adap.gemspec
215
-
216
212
  ## Contributing
217
213
 
218
214
  Bug reports and pull requests are welcome on GitHub at https://github.com/TsutomuNakamura/adap.
data/lib/adap/adap.rb CHANGED
@@ -19,8 +19,8 @@ class Adap
19
19
  def initialize(params)
20
20
  raise "Initialize Adap was failed. params must not be nil" if params == nil
21
21
 
22
- [:ad_host, :ad_binddn, :ad_basedn, :ldap_host, :ldap_binddn, :ldap_basedn].each { |k|
23
- raise 'Adap requires keys in params ":ad_host", ":ad_binddn", ":ad_basedn", ":ldap_host", ":ldap_binddn", ":ldap_basedn"' if !params.key?(k)
22
+ [:ad_host, :ad_binddn, :ad_user_basedn, :ad_group_basedn, :ldap_host, :ldap_binddn, :ldap_user_basedn, :ldap_group_basedn].each { |k|
23
+ raise 'Adap requires keys in params ":ad_host", ":ad_binddn", ":ad_user_basedn", ":ad_group_basedn", ":ldap_host", ":ldap_binddn", ":ldap_user_basedn", ":ldap_group_basedn"' if !params.key?(k)
24
24
  }
25
25
 
26
26
  # List of attributes for user in AD
@@ -42,14 +42,15 @@ class Adap
42
42
  @ad_host = params[:ad_host]
43
43
  @ad_port = (params[:ad_port] ? params[:ad_port] : 389)
44
44
  @ad_binddn = params[:ad_binddn]
45
- @ad_basedn = params[:ad_basedn]
45
+ @ad_user_basedn = params[:ad_user_basedn]
46
+ @ad_group_basedn = params[:ad_group_basedn]
46
47
  @ad_auth = (params.has_key?(:ad_password) ? { :method => :simple, :username => @ad_binddn, :password => params[:ad_password] } : nil)
47
48
  @ldap_host = params[:ldap_host]
48
49
  @ldap_port = (params[:ldap_port] ? params[:ldap_port] : 389)
49
50
  @ldap_binddn = params[:ldap_binddn]
50
- @ldap_suffix_ou = (params[:ldap_suffix_ou] ? params[:ldap_suffix_ou] : "ou=Users")
51
51
  @ldap_basedn = params[:ldap_basedn]
52
52
  @ldap_user_basedn = params[:ldap_user_basedn]
53
+ @ldap_group_basedn = params[:ldap_group_basedn]
53
54
  @ldap_auth = (params.has_key?(:ldap_password) ? { :method => :simple, :username => @ldap_binddn, :password => params[:ldap_password] } : nil )
54
55
 
55
56
  # A password-hash algorithm to sync to the LDAP.
@@ -99,12 +100,12 @@ class Adap
99
100
  Net::LDAP.new(:host => ldap_host, :port => ldap_port, :auth => ldap_auth)
100
101
  end
101
102
 
102
- def get_ad_dn(username)
103
- "CN=#{username},CN=Users,#{@ad_basedn}"
103
+ def get_ad_user_dn(username)
104
+ "CN=#{username},#{@ad_user_basedn}"
104
105
  end
105
106
 
106
- def get_ldap_dn(username)
107
- "uid=#{username},#{@ldap_suffix_ou},#{@ldap_basedn}"
107
+ def get_ldap_user_dn(username)
108
+ "uid=#{username},#{@ldap_user_basedn}"
108
109
  end
109
110
 
110
111
  def create_ldap_attributes(ad_entry)
@@ -159,13 +160,13 @@ class Adap
159
160
  end
160
161
 
161
162
  def sync_user(uid, password=nil)
162
- ad_entry = nil
163
- ldap_entry = nil
164
- ad_dn = get_ad_dn(uid)
165
- ldap_dn = get_ldap_dn(uid)
163
+ ad_entry = nil
164
+ ldap_entry = nil
165
+ ad_user_dn = get_ad_user_dn(uid)
166
+ ldap_user_dn = get_ldap_user_dn(uid)
166
167
 
167
168
  # dn: CN=user-name,CN=Users,DC=mysite,DC=example,DC=com
168
- @ad_client.search(:base => ad_dn) do |entry|
169
+ @ad_client.search(:base => ad_user_dn) do |entry|
169
170
  ad_entry = entry
170
171
  end
171
172
  ret_code = @ad_client.get_operation_result.code
@@ -174,10 +175,10 @@ class Adap
174
175
  return {
175
176
  :code => ret_code,
176
177
  :operations => nil,
177
- :message => "Failed to get a user #{ad_dn} from AD - " + @ad_client.get_operation_result.error_message
178
+ :message => "Failed to get a user #{ad_user_dn} from AD - " + @ad_client.get_operation_result.error_message
178
179
  } if ret_code != 0 && ret_code != 32
179
180
 
180
- @ldap_client.search(:base => ldap_dn) do |entry|
181
+ @ldap_client.search(:base => ldap_user_dn) do |entry|
181
182
  ldap_entry = entry
182
183
  end
183
184
  ret_code = @ldap_client.get_operation_result.code
@@ -185,17 +186,17 @@ class Adap
185
186
  return {
186
187
  :code => ret_code,
187
188
  :operations => nil,
188
- :message => "Failed to get a user #{ldap_dn} from LDAP - " + @ldap_client.get_operation_result.error_message
189
+ :message => "Failed to get a user #{ldap_user_dn} from LDAP - " + @ldap_client.get_operation_result.error_message
189
190
  } if ret_code != 0 && ret_code != 32
190
191
 
191
192
  ret = nil
192
193
  if !ad_entry.nil? and ldap_entry.nil? then
193
- ret = add_user(ldap_dn, ad_entry, get_password_hash(uid, password))
194
+ ret = add_user(ldap_user_dn, ad_entry, get_password_hash(uid, password))
194
195
  elsif ad_entry.nil? and !ldap_entry.nil? then
195
- ret = delete_user(ldap_dn)
196
+ ret = delete_user(ldap_user_dn)
196
197
  elsif !ad_entry.nil? and !ldap_entry.nil? then
197
198
  ret = modify_user(
198
- ldap_dn,
199
+ ldap_user_dn,
199
200
  ad_entry,
200
201
  ldap_entry,
201
202
  ( password.nil? and (@unsupported_hash_algorithms_in_ad.include?(@password_hash_algorithm)) ) ? nil : get_password_hash(uid, password)
@@ -341,21 +342,28 @@ class Adap
341
342
  # Creating AD ldapsearch filter
342
343
 
343
344
  ad_filter = if primary_gid_number == nil then
345
+ # TODO: Searching with filter `objectCategory=CN=Group,CN=Schema,CN=Configuration,#{@ad_basedn}` is more accureate.
346
+ #Net::LDAP::Filter.construct(
347
+ # "(&(objectCategory=CN=Group,CN=Schema,CN=Configuration,#{@ad_basedn})(member=CN=#{uid},CN=Users,#{@ad_basedn}))")
348
+
344
349
  Net::LDAP::Filter.construct(
345
- "(&(objectCategory=CN=Group,CN=Schema,CN=Configuration,#{@ad_basedn})(member=CN=#{uid},CN=Users,#{@ad_basedn}))")
350
+ "(&(objectClass=group)(member=CN=#{uid},#{@ad_user_basedn}))")
346
351
  else
352
+ # TODO: Searching with filter `objectCategory=CN=Group,CN=Schema,CN=Configuration,#{@ad_basedn}` is more accureate.
353
+ #Net::LDAP::Filter.construct(
354
+ # "(&(objectCategory=CN=Group,CN=Schema,CN=Configuration,#{@ad_basedn})(|(member=CN=#{uid},CN=Users,#{@ad_basedn})(gidNumber=#{primary_gid_number})))")
355
+
347
356
  Net::LDAP::Filter.construct(
348
- "(&(objectCategory=CN=Group,CN=Schema,CN=Configuration,#{@ad_basedn})(|(member=CN=#{uid},CN=Users,#{@ad_basedn})(gidNumber=#{primary_gid_number})))")
357
+ "(&(objectClass=group)(|(member=CN=#{uid},#{@ad_user_basedn})(gidNumber=#{primary_gid_number})))")
349
358
  end
350
359
 
351
360
  # Get groups from AD
352
361
  # entry = {
353
362
  # :gidnumber => xxx,
354
363
  # }
355
- #
356
- @ad_client.search(:base => @ad_basedn, :filter => ad_filter) do |entry|
357
- ad_group_map[entry[:name].first] = {:gidnumber => entry[:gidnumber]}
358
- #ad_group_map[entry[:name]] = nil
364
+ @ad_client.search(:base => @ad_group_basedn, :filter => ad_filter, :attributes => [:cn, :gidnumber]) do |entry|
365
+ ad_group_map[entry[:cn].first] = {:gidnumber => entry[:gidnumber]}
366
+ #ad_group_map[entry[:cn]] = nil
359
367
  end
360
368
  ret_code = @ad_client.get_operation_result.code
361
369
 
@@ -369,8 +377,8 @@ class Adap
369
377
  ldap_filter = Net::LDAP::Filter.construct("(memberUid=#{uid})")
370
378
 
371
379
  # Get groups from LDAP
372
- @ldap_client.search(:base => "ou=Groups," + @ldap_basedn, :filter => ldap_filter) do |entry|
373
- # gidnumber is not necessary for LDAP entry
380
+ @ldap_client.search(:base => @ldap_group_basedn, :filter => ldap_filter, :attributes => [:cn]) do |entry|
381
+ # Capture common name of groups. gidnumber is not necessary for LDAP entry
374
382
  ldap_group_map[entry[:cn].first] = nil
375
383
  end
376
384
  ret_code = @ldap_client.get_operation_result.code
@@ -408,7 +416,7 @@ class Adap
408
416
  operation_pool = {}
409
417
 
410
418
  ad_group_map.each_key do |key|
411
- dn = "cn=#{key},ou=Groups,#{@ldap_basedn}"
419
+ dn = "cn=#{key},#{@ldap_group_basedn}"
412
420
  # Convert AD entries to LDAP entries to create operation to update LDAP data.
413
421
  operation_pool[dn] = {
414
422
  :cn => key,
@@ -418,7 +426,7 @@ class Adap
418
426
  end
419
427
 
420
428
  ldap_group_map.each_key do |key|
421
- operation_pool["cn=#{key},ou=Groups,#{@ldap_basedn}"] = {
429
+ operation_pool["cn=#{key},#{@ldap_group_basedn}"] = {
422
430
  # :cn and :gidnumber are not necessary
423
431
  :operations => [[:delete, :memberuid, uid]]
424
432
  } if !ad_group_map.has_key?(key)
data/lib/adap/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ModAdap
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
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.1.4
4
+ version: 0.1.5
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: 2021-07-14 00:00:00.000000000 Z
11
+ date: 2025-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -59,7 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - ".circleci/config.yml"
62
+ - ".github/workflows/ruby.yml"
63
63
  - ".gitignore"
64
64
  - Gemfile
65
65
  - Gemfile.lock
@@ -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.5.22
98
+ signing_key:
99
99
  specification_version: 4
100
100
  summary: LDAP migration tool from AD to NT schema
101
101
  test_files: []
data/.circleci/config.yml DELETED
@@ -1,16 +0,0 @@
1
- version: 2.1
2
- orbs:
3
- ruby: circleci/ruby@0.1.2
4
-
5
- jobs:
6
- build:
7
- docker:
8
- - image: ruby:2.7
9
- executor: ruby/default
10
- steps:
11
- - checkout
12
- - run: bundle check || bundle install
13
- - run:
14
- command: bundle exec rake test
15
- when: always
16
-