rbmk 0.1.0.d → 0.1.0.e

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
  SHA1:
3
- metadata.gz: a4110b7240f29397f17634e175d64974cdd2738d
4
- data.tar.gz: 5f3c5aa09b7fe10d7f0da8dc75110deb341dff00
3
+ metadata.gz: b34d42c2d4d978cd76745a1b0b6bc5184ea5aa9f
4
+ data.tar.gz: a738a1fd9e9cd2169aff876c7f4f311ef6c8144f
5
5
  SHA512:
6
- metadata.gz: ebf931c83e0eaf760d92835b8f4b92954081ba70ae85d39a900307a0f81012e0cca692f435eaf9936b3de73489aa08870fe5048526cef76a145afdb895693693
7
- data.tar.gz: d51ff4ca6818bb25178ec927b7ea01d471a0074e5ba967378a6c4695767cef7f4bbeafdd83a45b18620edacd20ba0afdb93fa27eaa3ba35624d2aecaf61d98b1
6
+ metadata.gz: 58b9db953f0e4205beb825a9f48a9898b19282dad5352d9db46d51e89cfc0a08aa73b9932708dbe43ec244c1979f5805908aa1d9f285b0b1956a7f6b20971ae8
7
+ data.tar.gz: f55b7e5c2c8211bb984846a7234ae78b4891c8888cfdf0c9be5688b8ff6ad71233e34dcf2ca0fb22ce1072cabf3039c0599b2075e6bdc2097fa6f95081cb5b4b
@@ -147,6 +147,7 @@ class Operation < LDAP::Server::Operation
147
147
  # --------------------------------------------------------------------------
148
148
  # Okay, now the actual code
149
149
  #
150
+ attr_reader :server, :orig, :transformed
150
151
  def initialize conn, mid
151
152
  super conn, mid
152
153
  @orig = {}
@@ -155,7 +156,7 @@ class Operation < LDAP::Server::Operation
155
156
 
156
157
  def simple_bind version, dn, password
157
158
  orig = {version: version, dn: dn, password: password}
158
- opts = transformed __method__ => orig.clone
159
+ opts = transformed __method__, orig.clone
159
160
  $log.info sprintf('Bind version: %s, dn: %s',
160
161
  log_chunk(orig, opts, '%i', :version),
161
162
  log_chunk(orig, opts, '%p', :dn)
@@ -168,7 +169,7 @@ class Operation < LDAP::Server::Operation
168
169
 
169
170
  def search base, scope, deref, filter
170
171
  orig = {filter_array: filter, base: base, scope: scope, deref: deref, attrs: @attributes, vals: (not @typesOnly), limit: (@sizelimit.to_i rescue 0)}
171
- opts = transformed __method__ => orig.clone
172
+ opts = transformed __method__, orig.clone
172
173
  orig[:filter_string] = LDAP::Server::Filter.to_rfc orig[:filter_array]
173
174
  opts[:filter_string] = LDAP::Server::Filter.to_rfc opts[:filter_array]
174
175
  $log.info sprintf('Search %s from %s, scope: %s, deref: %s, attrs: %s, vals: %s, limit: %s',
@@ -181,7 +182,7 @@ class Operation < LDAP::Server::Operation
181
182
  log_chunk(orig, opts, '%i', :limit),
182
183
  )
183
184
  entries = @server.ldap.search_ext2(*opts.values_at(:base, :scope, :filter_string, :attrs), (not opts[:vals]), nil, nil, 0, 0, opts[:limit])
184
- transformed(entries: entries).each { |entry| send_SearchResultEntry entry.delete('dn').first, entry }
185
+ transformed(:entries, entries).each { |entry| send_SearchResultEntry entry.delete('dn').first, entry }
185
186
  rescue LDAP::ResultError
186
187
  @server.handle_ldap_error
187
188
  end
@@ -202,13 +203,9 @@ protected
202
203
  raise $!
203
204
  end
204
205
 
205
- def transformed spec
206
- raise ArgumentError.new('Please provide a hash with exactly one key.') unless (spec.is_a? Hash) and (1 == spec.count)
207
- spec.each do |type, object|
208
- @orig[type] = object
209
- transformed = RBMK::Transform.send type, object
210
- return @transformed[type] = transformed
211
- end
206
+ def transformed type, object
207
+ @orig[type] = object
208
+ @transformed[type] = RBMK::Transform.send type, object, self
212
209
  rescue
213
210
  $!.log
214
211
  object
data/lib/rbmk/server.rb CHANGED
@@ -5,8 +5,6 @@ class Server
5
5
 
6
6
  %w( CHLD INT HUP QUIT TERM ).each { |sig| const_set ('SIG%s' % sig).to_sym, Signal.list[sig] }
7
7
 
8
- class Reaped < StandardError; end
9
-
10
8
  def initialize
11
9
  $master = true
12
10
  @arvg0 = File.basename Process.argv0
@@ -56,7 +54,7 @@ protected
56
54
  act_as_a_child_for peer
57
55
  end
58
56
  rescue SignalException
59
- $log.debug 'Trapped %p' % $!.signm
57
+ $log.debug 'Trapped %p' % ($!.signm.empty? ? 'SIGINT' : $!.signm)
60
58
  case $!.signo
61
59
  when SIGCHLD then reap
62
60
  when SIGINT, SIGHUP, SIGTERM then exit
@@ -74,7 +72,7 @@ protected
74
72
  $0 = sprintf '%s worker for %s', @arvg0, peer
75
73
  Timeout.timeout(self.class.worker_timeout) { serve peer } # FIXME shall move to master in the future or maybe drop altogether in favour of activity detection
76
74
  rescue SignalException
77
- $log.debug 'Trapped %p' % $!.signm
75
+ $log.debug 'Trapped %p' % ($!.signm.empty? ? 'SIGINT' : $!.signm)
78
76
  raise $!
79
77
  rescue Exception
80
78
  $!.log
@@ -6,7 +6,7 @@ module Transform
6
6
  # :version LDAP protocol version; should probably be 3
7
7
  # :dn Bind DN; like a "username"
8
8
  # :password Cleartext! Verrrry sensitive!
9
- def self.simple_bind opts
9
+ def self.simple_bind opts, op
10
10
  opts
11
11
  end
12
12
 
@@ -19,13 +19,13 @@ module Transform
19
19
  # :attrs Attributes to be included in resulting objects
20
20
  # :vals Whether to include values at all
21
21
  # :limit Search will not return more than this amount of objects
22
- def self.search opts
22
+ def self.search opts, op
23
23
  opts
24
24
  end
25
25
 
26
26
  # Patch this method to transform outbound found entries.
27
27
  # Expect an array of hashes, each of which MUST have a 'dn' key
28
- def self.found entries
28
+ def self.found entries, op
29
29
  entries
30
30
  end
31
31
 
data/lib/rbmk/upstream.rb CHANGED
@@ -13,10 +13,29 @@ class Upstream
13
13
  configContext: {s: 12, oid: '1.3.6.1.4.1.4203.1.12.2.1', f: 'sua'},
14
14
  }
15
15
 
16
+ def self.search ldap, opts
17
+ args = [
18
+ opts.fetch(:base, ''),
19
+ opts.fetch(:scope, LDAP::LDAP_SCOPE_SUBTREE),
20
+ opts.fetch(:filter, '(objectClass=*)'),
21
+ opts.fetch(:attrs, ['*', '+']),
22
+ (not opts.fetch(:vals, true)),
23
+ opts.fetch(:serverctrls, nil),
24
+ opts.fetch(:clientctrls, nil),
25
+ opts.fetch(:sec, 0),
26
+ opts.fetch(:usec, 0),
27
+ opts.fetch(:s_attr, 0),
28
+ opts.fetch(:s_proc, ''),
29
+ ]
30
+ res = ldap.search_ext2 *args
31
+ res.each { |e| yield e } if block_given?
32
+ res
33
+ end
34
+
16
35
  attr_reader :ldap, :root_dse, :schema
17
36
  def initialize
18
37
  @schema = LDAP::Server::Schema.new
19
- SPECIAL_ATS.each { |name,at| @schema.add_attrtype format(name, at) }
38
+ SPECIAL_ATS.each { |name, at| @schema.add_attrtype format(name, at) }
20
39
  ldap = LDAP::Conn.new self.class.host, self.class.port
21
40
  ldap.set_option LDAP::LDAP_OPT_PROTOCOL_VERSION, 3
22
41
  ldap.bind do |ldap|
@@ -25,6 +44,7 @@ class Upstream
25
44
  {add_attrtype: 'attributeTypes', add_objectclass: 'objectClasses'}.each { |meth,id| ssse[id].each { |str| @schema.send meth, str unless str.start_with? FILTER_PREFIX } }
26
45
  end
27
46
  @schema.resolve_oids
47
+ user_init
28
48
  end
29
49
 
30
50
  def bind version, dn, password
@@ -68,5 +88,8 @@ protected
68
88
  saved.close
69
89
  end
70
90
 
91
+ # Patch this method to do something useful right after initialization
92
+ def user_init; end
93
+
71
94
  end
72
95
  end
data/lib/rbmk/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module RBMK
2
- VERSION = '0.1.0.d'
3
- CODENAME = 'not listening'
2
+ VERSION = '0.1.0.e'
3
+ CODENAME = 'never again'
4
4
  end
data/lib/rbmk/worker.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'ldap/server'
2
2
  require 'rbmk/operation'
3
- require 'rbmk/peer'
4
3
  module RBMK
5
4
  class Worker
6
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbmk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.d
4
+ version: 0.1.0.e
5
5
  platform: ruby
6
6
  authors:
7
7
  - stronny red
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-26 00:00:00.000000000 Z
11
+ date: 2015-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-ldap