sidekick-client 0.2.1 → 0.2.2

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.
Files changed (162) hide show
  1. data/VERSION +1 -1
  2. data/lib/sidekick/client/sidekick_client.rb +0 -3
  3. data/lib/sidekick/shared/sidekick_queue_publisher.rb +1 -1
  4. data/sidekick-client.gemspec +1 -158
  5. metadata +1 -158
  6. data/lib/ext/eventmachine-0.12.10/.gitignore +0 -14
  7. data/lib/ext/eventmachine-0.12.10/README +0 -82
  8. data/lib/ext/eventmachine-0.12.10/Rakefile +0 -374
  9. data/lib/ext/eventmachine-0.12.10/docs/COPYING +0 -60
  10. data/lib/ext/eventmachine-0.12.10/docs/ChangeLog +0 -211
  11. data/lib/ext/eventmachine-0.12.10/docs/DEFERRABLES +0 -133
  12. data/lib/ext/eventmachine-0.12.10/docs/EPOLL +0 -141
  13. data/lib/ext/eventmachine-0.12.10/docs/GNU +0 -281
  14. data/lib/ext/eventmachine-0.12.10/docs/INSTALL +0 -13
  15. data/lib/ext/eventmachine-0.12.10/docs/KEYBOARD +0 -38
  16. data/lib/ext/eventmachine-0.12.10/docs/LEGAL +0 -25
  17. data/lib/ext/eventmachine-0.12.10/docs/LIGHTWEIGHT_CONCURRENCY +0 -70
  18. data/lib/ext/eventmachine-0.12.10/docs/PURE_RUBY +0 -75
  19. data/lib/ext/eventmachine-0.12.10/docs/RELEASE_NOTES +0 -94
  20. data/lib/ext/eventmachine-0.12.10/docs/SMTP +0 -2
  21. data/lib/ext/eventmachine-0.12.10/docs/SPAWNED_PROCESSES +0 -89
  22. data/lib/ext/eventmachine-0.12.10/docs/TODO +0 -8
  23. data/lib/ext/eventmachine-0.12.10/eventmachine.gemspec +0 -40
  24. data/lib/ext/eventmachine-0.12.10/examples/ex_channel.rb +0 -43
  25. data/lib/ext/eventmachine-0.12.10/examples/ex_queue.rb +0 -2
  26. data/lib/ext/eventmachine-0.12.10/examples/helper.rb +0 -2
  27. data/lib/ext/eventmachine-0.12.10/ext/binder.cpp +0 -125
  28. data/lib/ext/eventmachine-0.12.10/ext/binder.h +0 -46
  29. data/lib/ext/eventmachine-0.12.10/ext/cmain.cpp +0 -827
  30. data/lib/ext/eventmachine-0.12.10/ext/cplusplus.cpp +0 -202
  31. data/lib/ext/eventmachine-0.12.10/ext/ed.cpp +0 -1893
  32. data/lib/ext/eventmachine-0.12.10/ext/ed.h +0 -424
  33. data/lib/ext/eventmachine-0.12.10/ext/em.cpp +0 -2282
  34. data/lib/ext/eventmachine-0.12.10/ext/em.h +0 -232
  35. data/lib/ext/eventmachine-0.12.10/ext/emwin.cpp +0 -300
  36. data/lib/ext/eventmachine-0.12.10/ext/emwin.h +0 -94
  37. data/lib/ext/eventmachine-0.12.10/ext/epoll.cpp +0 -26
  38. data/lib/ext/eventmachine-0.12.10/ext/epoll.h +0 -25
  39. data/lib/ext/eventmachine-0.12.10/ext/eventmachine.h +0 -122
  40. data/lib/ext/eventmachine-0.12.10/ext/eventmachine_cpp.h +0 -96
  41. data/lib/ext/eventmachine-0.12.10/ext/extconf.rb +0 -148
  42. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/extconf.rb +0 -83
  43. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.cpp +0 -214
  44. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/mapper.h +0 -59
  45. data/lib/ext/eventmachine-0.12.10/ext/fastfilereader/rubymain.cpp +0 -127
  46. data/lib/ext/eventmachine-0.12.10/ext/files.cpp +0 -94
  47. data/lib/ext/eventmachine-0.12.10/ext/files.h +0 -65
  48. data/lib/ext/eventmachine-0.12.10/ext/kb.cpp +0 -81
  49. data/lib/ext/eventmachine-0.12.10/ext/page.cpp +0 -107
  50. data/lib/ext/eventmachine-0.12.10/ext/page.h +0 -51
  51. data/lib/ext/eventmachine-0.12.10/ext/pipe.cpp +0 -349
  52. data/lib/ext/eventmachine-0.12.10/ext/project.h +0 -151
  53. data/lib/ext/eventmachine-0.12.10/ext/rubymain.cpp +0 -1166
  54. data/lib/ext/eventmachine-0.12.10/ext/sigs.cpp +0 -89
  55. data/lib/ext/eventmachine-0.12.10/ext/sigs.h +0 -32
  56. data/lib/ext/eventmachine-0.12.10/ext/ssl.cpp +0 -460
  57. data/lib/ext/eventmachine-0.12.10/ext/ssl.h +0 -94
  58. data/lib/ext/eventmachine-0.12.10/java/.classpath +0 -8
  59. data/lib/ext/eventmachine-0.12.10/java/.project +0 -17
  60. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactor.java +0 -570
  61. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EmReactorException.java +0 -40
  62. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableChannel.java +0 -69
  63. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableDatagramChannel.java +0 -189
  64. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/EventableSocketChannel.java +0 -364
  65. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Application.java +0 -194
  66. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Connection.java +0 -74
  67. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/ConnectionFactory.java +0 -37
  68. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +0 -46
  69. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/PeriodicTimer.java +0 -38
  70. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/application/Timer.java +0 -54
  71. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ApplicationTest.java +0 -109
  72. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/ConnectTest.java +0 -148
  73. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/EMTest.java +0 -80
  74. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestDatagrams.java +0 -53
  75. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestServers.java +0 -75
  76. data/lib/ext/eventmachine-0.12.10/java/src/com/rubyeventmachine/tests/TestTimers.java +0 -90
  77. data/lib/ext/eventmachine-0.12.10/lib/em/buftok.rb +0 -138
  78. data/lib/ext/eventmachine-0.12.10/lib/em/callback.rb +0 -26
  79. data/lib/ext/eventmachine-0.12.10/lib/em/channel.rb +0 -57
  80. data/lib/ext/eventmachine-0.12.10/lib/em/connection.rb +0 -564
  81. data/lib/ext/eventmachine-0.12.10/lib/em/deferrable.rb +0 -192
  82. data/lib/ext/eventmachine-0.12.10/lib/em/file_watch.rb +0 -54
  83. data/lib/ext/eventmachine-0.12.10/lib/em/future.rb +0 -61
  84. data/lib/ext/eventmachine-0.12.10/lib/em/messages.rb +0 -66
  85. data/lib/ext/eventmachine-0.12.10/lib/em/process_watch.rb +0 -44
  86. data/lib/ext/eventmachine-0.12.10/lib/em/processes.rb +0 -119
  87. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/header_and_content.rb +0 -138
  88. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient.rb +0 -263
  89. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/httpclient2.rb +0 -590
  90. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/line_and_text.rb +0 -125
  91. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/linetext2.rb +0 -161
  92. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/memcache.rb +0 -323
  93. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/object_protocol.rb +0 -45
  94. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/postgres3.rb +0 -247
  95. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/saslauth.rb +0 -175
  96. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpclient.rb +0 -357
  97. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/smtpserver.rb +0 -547
  98. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/socks4.rb +0 -66
  99. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/stomp.rb +0 -200
  100. data/lib/ext/eventmachine-0.12.10/lib/em/protocols/tcptest.rb +0 -53
  101. data/lib/ext/eventmachine-0.12.10/lib/em/protocols.rb +0 -36
  102. data/lib/ext/eventmachine-0.12.10/lib/em/queue.rb +0 -61
  103. data/lib/ext/eventmachine-0.12.10/lib/em/spawnable.rb +0 -85
  104. data/lib/ext/eventmachine-0.12.10/lib/em/streamer.rb +0 -130
  105. data/lib/ext/eventmachine-0.12.10/lib/em/timers.rb +0 -56
  106. data/lib/ext/eventmachine-0.12.10/lib/em/version.rb +0 -3
  107. data/lib/ext/eventmachine-0.12.10/lib/eventmachine.rb +0 -1592
  108. data/lib/ext/eventmachine-0.12.10/lib/evma/callback.rb +0 -32
  109. data/lib/ext/eventmachine-0.12.10/lib/evma/container.rb +0 -75
  110. data/lib/ext/eventmachine-0.12.10/lib/evma/factory.rb +0 -77
  111. data/lib/ext/eventmachine-0.12.10/lib/evma/protocol.rb +0 -87
  112. data/lib/ext/eventmachine-0.12.10/lib/evma/reactor.rb +0 -48
  113. data/lib/ext/eventmachine-0.12.10/lib/evma.rb +0 -32
  114. data/lib/ext/eventmachine-0.12.10/lib/jeventmachine.rb +0 -257
  115. data/lib/ext/eventmachine-0.12.10/lib/pr_eventmachine.rb +0 -1022
  116. data/lib/ext/eventmachine-0.12.10/setup.rb +0 -1585
  117. data/lib/ext/eventmachine-0.12.10/tasks/cpp.rake_example +0 -77
  118. data/lib/ext/eventmachine-0.12.10/tests/client.crt +0 -31
  119. data/lib/ext/eventmachine-0.12.10/tests/client.key +0 -51
  120. data/lib/ext/eventmachine-0.12.10/tests/test_attach.rb +0 -126
  121. data/lib/ext/eventmachine-0.12.10/tests/test_basic.rb +0 -284
  122. data/lib/ext/eventmachine-0.12.10/tests/test_channel.rb +0 -63
  123. data/lib/ext/eventmachine-0.12.10/tests/test_connection_count.rb +0 -35
  124. data/lib/ext/eventmachine-0.12.10/tests/test_defer.rb +0 -47
  125. data/lib/ext/eventmachine-0.12.10/tests/test_epoll.rb +0 -160
  126. data/lib/ext/eventmachine-0.12.10/tests/test_error_handler.rb +0 -35
  127. data/lib/ext/eventmachine-0.12.10/tests/test_errors.rb +0 -82
  128. data/lib/ext/eventmachine-0.12.10/tests/test_exc.rb +0 -55
  129. data/lib/ext/eventmachine-0.12.10/tests/test_file_watch.rb +0 -49
  130. data/lib/ext/eventmachine-0.12.10/tests/test_futures.rb +0 -198
  131. data/lib/ext/eventmachine-0.12.10/tests/test_get_sock_opt.rb +0 -30
  132. data/lib/ext/eventmachine-0.12.10/tests/test_handler_check.rb +0 -37
  133. data/lib/ext/eventmachine-0.12.10/tests/test_hc.rb +0 -218
  134. data/lib/ext/eventmachine-0.12.10/tests/test_httpclient.rb +0 -218
  135. data/lib/ext/eventmachine-0.12.10/tests/test_httpclient2.rb +0 -153
  136. data/lib/ext/eventmachine-0.12.10/tests/test_inactivity_timeout.rb +0 -50
  137. data/lib/ext/eventmachine-0.12.10/tests/test_kb.rb +0 -60
  138. data/lib/ext/eventmachine-0.12.10/tests/test_ltp.rb +0 -182
  139. data/lib/ext/eventmachine-0.12.10/tests/test_ltp2.rb +0 -317
  140. data/lib/ext/eventmachine-0.12.10/tests/test_next_tick.rb +0 -133
  141. data/lib/ext/eventmachine-0.12.10/tests/test_object_protocol.rb +0 -37
  142. data/lib/ext/eventmachine-0.12.10/tests/test_pause.rb +0 -70
  143. data/lib/ext/eventmachine-0.12.10/tests/test_pending_connect_timeout.rb +0 -48
  144. data/lib/ext/eventmachine-0.12.10/tests/test_process_watch.rb +0 -48
  145. data/lib/ext/eventmachine-0.12.10/tests/test_processes.rb +0 -128
  146. data/lib/ext/eventmachine-0.12.10/tests/test_proxy_connection.rb +0 -92
  147. data/lib/ext/eventmachine-0.12.10/tests/test_pure.rb +0 -125
  148. data/lib/ext/eventmachine-0.12.10/tests/test_queue.rb +0 -44
  149. data/lib/ext/eventmachine-0.12.10/tests/test_running.rb +0 -42
  150. data/lib/ext/eventmachine-0.12.10/tests/test_sasl.rb +0 -72
  151. data/lib/ext/eventmachine-0.12.10/tests/test_send_file.rb +0 -242
  152. data/lib/ext/eventmachine-0.12.10/tests/test_servers.rb +0 -76
  153. data/lib/ext/eventmachine-0.12.10/tests/test_smtpclient.rb +0 -83
  154. data/lib/ext/eventmachine-0.12.10/tests/test_smtpserver.rb +0 -85
  155. data/lib/ext/eventmachine-0.12.10/tests/test_spawn.rb +0 -322
  156. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_args.rb +0 -79
  157. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_methods.rb +0 -50
  158. data/lib/ext/eventmachine-0.12.10/tests/test_ssl_verify.rb +0 -82
  159. data/lib/ext/eventmachine-0.12.10/tests/test_timers.rb +0 -162
  160. data/lib/ext/eventmachine-0.12.10/tests/test_ud.rb +0 -36
  161. data/lib/ext/eventmachine-0.12.10/tests/testem.rb +0 -31
  162. data/lib/ext/eventmachine-0.12.10/web/whatis +0 -7
@@ -1,247 +0,0 @@
1
- #--
2
- #
3
- # Author:: Francis Cianfrocca (gmail: blackhedd)
4
- # Homepage:: http://rubyeventmachine.com
5
- # Date:: 15 November 2006
6
- #
7
- # See EventMachine and EventMachine::Connection for documentation and
8
- # usage examples.
9
- #
10
- #----------------------------------------------------------------------------
11
- #
12
- # Copyright (C) 2006-08 by Francis Cianfrocca. All Rights Reserved.
13
- # Gmail: blackhedd
14
- #
15
- # This program is free software; you can redistribute it and/or modify
16
- # it under the terms of either: 1) the GNU General Public License
17
- # as published by the Free Software Foundation; either version 2 of the
18
- # License, or (at your option) any later version; or 2) Ruby's License.
19
- #
20
- # See the file COPYING for complete licensing information.
21
- #
22
- #---------------------------------------------------------------------------
23
- #
24
- #
25
- #
26
-
27
- require 'readbytes'
28
- require 'postgres-pr/message'
29
- require 'postgres-pr/connection'
30
- require 'stringio'
31
-
32
- class StringIO # :nodoc:
33
- # Reads exactly +n+ bytes.
34
- #
35
- # If the data read is nil an EOFError is raised.
36
- #
37
- # If the data read is too short a TruncatedDataError is raised and the read
38
- # data is obtainable via its #data method.
39
- def readbytes(n)
40
- str = read(n)
41
- if str == nil
42
- raise EOFError, "End of file reached"
43
- end
44
- if str.size < n
45
- raise TruncatedDataError.new("data truncated", str)
46
- end
47
- str
48
- end
49
- alias read_exactly_n_bytes readbytes
50
- end
51
-
52
-
53
- module EventMachine
54
- module Protocols
55
- # PROVISIONAL IMPLEMENTATION of an evented Postgres client.
56
- # This implements version 3 of the Postgres wire protocol, which will work
57
- # with any Postgres version from roughly 7.4 onward.
58
- #
59
- # Objective: we want to access Postgres databases without requiring threads.
60
- # Until now this has been a problem because the Postgres client implementations
61
- # have all made use of blocking I/O calls, which is incompatible with a
62
- # thread-free evented model.
63
- #
64
- # But rather than re-implement the Postgres Wire3 protocol, we're taking advantage
65
- # of the existing postgres-pr library, which was originally written by Michael
66
- # Neumann but (at this writing) appears to be no longer maintained. Still, it's
67
- # in basically a production-ready state, and the wire protocol isn't that complicated
68
- # anyway.
69
- #
70
- # We need to monkeypatch StringIO because it lacks the #readbytes method needed
71
- # by postgres-pr.
72
- #
73
- # We're tucking in a bunch of require statements that may not be present in garden-variety
74
- # EM installations. Until we find a good way to only require these if a program
75
- # requires postgres, this file will need to be required explicitly.
76
- #
77
- # The StringIO monkeypatch is lifted verbatim from the standard library readbytes.rb,
78
- # which adds method #readbytes directly to class IO. But StringIO is not a subclass of IO.
79
- #
80
- # We cloned the handling of postgres messages from lib/postgres-pr/connection.rb
81
- # in the postgres-pr library, and modified it for event-handling.
82
- #
83
- # TODO: The password handling in dispatch_conn_message is totally incomplete.
84
- #
85
- #
86
- # We return Deferrables from the user-level operations surfaced by this interface.
87
- # Experimentally, we're using the pattern of always returning a boolean value as the
88
- # first argument of a deferrable callback to indicate success or failure. This is
89
- # instead of the traditional pattern of calling Deferrable#succeed or #fail, and
90
- # requiring the user to define both a callback and an errback function.
91
- #
92
- # === Usage
93
- # EM.run {
94
- # db = EM.connect_unix_domain( "/tmp/.s.PGSQL.5432", EM::P::Postgres3 )
95
- # db.connect( dbname, username, psw ).callback do |status|
96
- # if status
97
- # db.query( "select * from some_table" ).callback do |status, result, errors|
98
- # if status
99
- # result.rows.each do |row|
100
- # p row
101
- # end
102
- # end
103
- # end
104
- # end
105
- # end
106
- # }
107
- class Postgres3 < EventMachine::Connection
108
- include PostgresPR
109
-
110
- def initialize
111
- @data = ""
112
- @params = {}
113
- end
114
-
115
- def connect db, user, psw=nil
116
- d = EM::DefaultDeferrable.new
117
- d.timeout 15
118
-
119
- if @pending_query || @pending_conn
120
- d.succeed false, "Operation already in progress"
121
- else
122
- @pending_conn = d
123
- prms = {"user"=>user, "database"=>db}
124
- @user = user
125
- if psw
126
- @password = psw
127
- #prms["password"] = psw
128
- end
129
- send_data PostgresPR::StartupMessage.new( 3 << 16, prms ).dump
130
- end
131
-
132
- d
133
- end
134
-
135
- def query sql
136
- d = EM::DefaultDeferrable.new
137
- d.timeout 15
138
-
139
- if @pending_query || @pending_conn
140
- d.succeed false, "Operation already in progress"
141
- else
142
- @r = PostgresPR::Connection::Result.new
143
- @e = []
144
- @pending_query = d
145
- send_data PostgresPR::Query.dump(sql)
146
- end
147
-
148
- d
149
- end
150
-
151
-
152
- def receive_data data
153
- @data << data
154
- while @data.length >= 5
155
- pktlen = @data[1...5].unpack("N").first
156
- if @data.length >= (1 + pktlen)
157
- pkt = @data.slice!(0...(1+pktlen))
158
- m = StringIO.open( pkt, "r" ) {|io| PostgresPR::Message.read( io ) }
159
- if @pending_conn
160
- dispatch_conn_message m
161
- elsif @pending_query
162
- dispatch_query_message m
163
- else
164
- raise "Unexpected message from database"
165
- end
166
- else
167
- break # very important, break out of the while
168
- end
169
- end
170
- end
171
-
172
-
173
- def unbind
174
- if o = (@pending_query || @pending_conn)
175
- o.succeed false, "lost connection"
176
- end
177
- end
178
-
179
- # Cloned and modified from the postgres-pr.
180
- def dispatch_conn_message msg
181
- case msg
182
- when AuthentificationClearTextPassword
183
- raise ArgumentError, "no password specified" if @password.nil?
184
- send_data PasswordMessage.new(@password).dump
185
-
186
- when AuthentificationCryptPassword
187
- raise ArgumentError, "no password specified" if @password.nil?
188
- send_data PasswordMessage.new(@password.crypt(msg.salt)).dump
189
-
190
- when AuthentificationMD5Password
191
- raise ArgumentError, "no password specified" if @password.nil?
192
- require 'digest/md5'
193
-
194
- m = Digest::MD5.hexdigest(@password + @user)
195
- m = Digest::MD5.hexdigest(m + msg.salt)
196
- m = 'md5' + m
197
- send_data PasswordMessage.new(m).dump
198
-
199
- when AuthentificationKerberosV4, AuthentificationKerberosV5, AuthentificationSCMCredential
200
- raise "unsupported authentification"
201
-
202
- when AuthentificationOk
203
- when ErrorResponse
204
- raise msg.field_values.join("\t")
205
- when NoticeResponse
206
- @notice_processor.call(msg) if @notice_processor
207
- when ParameterStatus
208
- @params[msg.key] = msg.value
209
- when BackendKeyData
210
- # TODO
211
- #p msg
212
- when ReadyForQuery
213
- # TODO: use transaction status
214
- pc,@pending_conn = @pending_conn,nil
215
- pc.succeed true
216
- else
217
- raise "unhandled message type"
218
- end
219
- end
220
-
221
- # Cloned and modified from the postgres-pr.
222
- def dispatch_query_message msg
223
- case msg
224
- when DataRow
225
- @r.rows << msg.columns
226
- when CommandComplete
227
- @r.cmd_tag = msg.cmd_tag
228
- when ReadyForQuery
229
- pq,@pending_query = @pending_query,nil
230
- pq.succeed true, @r, @e
231
- when RowDescription
232
- @r.fields = msg.fields
233
- when CopyInResponse
234
- when CopyOutResponse
235
- when EmptyQueryResponse
236
- when ErrorResponse
237
- # TODO
238
- @e << msg
239
- when NoticeResponse
240
- @notice_processor.call(msg) if @notice_processor
241
- else
242
- # TODO
243
- end
244
- end
245
- end
246
- end
247
- end
@@ -1,175 +0,0 @@
1
- #--
2
- #
3
- # Author:: Francis Cianfrocca (gmail: blackhedd)
4
- # Homepage:: http://rubyeventmachine.com
5
- # Date:: 15 November 2006
6
- #
7
- # See EventMachine and EventMachine::Connection for documentation and
8
- # usage examples.
9
- #
10
- #----------------------------------------------------------------------------
11
- #
12
- # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
- # Gmail: blackhedd
14
- #
15
- # This program is free software; you can redistribute it and/or modify
16
- # it under the terms of either: 1) the GNU General Public License
17
- # as published by the Free Software Foundation; either version 2 of the
18
- # License, or (at your option) any later version; or 2) Ruby's License.
19
- #
20
- # See the file COPYING for complete licensing information.
21
- #
22
- #---------------------------------------------------------------------------
23
- #
24
- #
25
- #
26
-
27
- module EventMachine
28
- module Protocols
29
-
30
- # Implements SASL authd.
31
- # This is a very, very simple protocol that mimics the one used
32
- # by saslauthd and pwcheck, two outboard daemons included in the
33
- # standard SASL library distro.
34
- # The only thing this is really suitable for is SASL PLAIN
35
- # (user+password) authentication, but the SASL libs that are
36
- # linked into standard servers (like imapd and sendmail) implement
37
- # the other ones.
38
- #
39
- # SASL-auth is intended for reasonably fast operation inside a
40
- # single machine, so it has no transport-security (although there
41
- # have been multi-machine extensions incorporating transport-layer
42
- # encryption).
43
- #
44
- # The standard saslauthd module generally runs privileged and does
45
- # its work by referring to the system-account files.
46
- #
47
- # This feature was added to EventMachine to enable the development
48
- # of custom authentication/authorization engines for standard servers.
49
- #
50
- # To use SASLauth, include it in a class that subclasses EM::Connection,
51
- # and reimplement the validate method.
52
- #
53
- # The typical way to incorporate this module into an authentication
54
- # daemon would be to set it as the handler for a UNIX-domain socket.
55
- # The code might look like this:
56
- #
57
- # EM.start_unix_domain_server( "/var/run/saslauthd/mux", MyHandler )
58
- # File.chmod( 0777, "/var/run/saslauthd/mux")
59
- #
60
- # The chmod is probably needed to ensure that unprivileged clients can
61
- # access the UNIX-domain socket.
62
- #
63
- # It's also a very good idea to drop superuser privileges (if any), after
64
- # the UNIX-domain socket has been opened.
65
- #--
66
- # Implementation details: assume the client can send us pipelined requests,
67
- # and that the client will close the connection.
68
- #
69
- # The client sends us four values, each encoded as a two-byte length field in
70
- # network order followed by the specified number of octets.
71
- # The fields specify the username, password, service name (such as imap),
72
- # and the "realm" name. We send back the barest minimum reply, a single
73
- # field also encoded as a two-octet length in network order, followed by
74
- # either "NO" or "OK" - simplicity itself.
75
- #
76
- # We enforce a maximum field size just as a sanity check.
77
- # We do NOT automatically time out the connection.
78
- #
79
- # The code we use to parse out the values is ugly and probably slow.
80
- # Improvements welcome.
81
- #
82
- module SASLauth
83
-
84
- MaxFieldSize = 128*1024
85
- def post_init
86
- super
87
- @sasl_data = ""
88
- @sasl_values = []
89
- end
90
-
91
- def receive_data data
92
- @sasl_data << data
93
- while @sasl_data.length >= 2
94
- len = (@sasl_data[0,2].unpack("n")).first
95
- raise "SASL Max Field Length exceeded" if len > MaxFieldSize
96
- if @sasl_data.length >= (len + 2)
97
- @sasl_values << @sasl_data[2,len]
98
- @sasl_data.slice!(0...(2+len))
99
- if @sasl_values.length == 4
100
- send_data( validate(*@sasl_values) ? "\0\002OK" : "\0\002NO" )
101
- @sasl_values.clear
102
- end
103
- else
104
- break
105
- end
106
- end
107
- end
108
-
109
- def validate username, psw, sysname, realm
110
- p username
111
- p psw
112
- p sysname
113
- p realm
114
- true
115
- end
116
- end
117
-
118
- # Implements the SASL authd client protocol.
119
- # This is a very, very simple protocol that mimics the one used
120
- # by saslauthd and pwcheck, two outboard daemons included in the
121
- # standard SASL library distro.
122
- # The only thing this is really suitable for is SASL PLAIN
123
- # (user+password) authentication, but the SASL libs that are
124
- # linked into standard servers (like imapd and sendmail) implement
125
- # the other ones.
126
- #
127
- # You can use this module directly as a handler for EM Connections,
128
- # or include it in a module or handler class of your own.
129
- #
130
- # First connect to a SASL server (it's probably a TCP server, or more
131
- # likely a Unix-domain socket). Then call the #validate? method,
132
- # passing at least a username and a password. #validate? returns
133
- # a Deferrable which will either succeed or fail, depending
134
- # on the status of the authentication operation.
135
- #
136
- module SASLauthclient
137
- MaxFieldSize = 128*1024
138
-
139
- def validate? username, psw, sysname=nil, realm=nil
140
-
141
- str = [username, psw, sysname, realm].map {|m|
142
- [(m || "").length, (m || "")]
143
- }.flatten.pack( "nA*" * 4 )
144
- send_data str
145
-
146
- d = EM::DefaultDeferrable.new
147
- @queries.unshift d
148
- d
149
- end
150
-
151
- def post_init
152
- @sasl_data = ""
153
- @queries = []
154
- end
155
-
156
- def receive_data data
157
- @sasl_data << data
158
-
159
- while @sasl_data.length > 2
160
- len = (@sasl_data[0,2].unpack("n")).first
161
- raise "SASL Max Field Length exceeded" if len > MaxFieldSize
162
- if @sasl_data.length >= (len + 2)
163
- val = @sasl_data[2,len]
164
- @sasl_data.slice!(0...(2+len))
165
- q = @queries.pop
166
- (val == "NO") ? q.fail : q.succeed
167
- else
168
- break
169
- end
170
- end
171
- end
172
- end
173
-
174
- end
175
- end