EventMachine::Protocols::SASLauthclient

Implements the SASL authd client protocol. This is a very, very simple protocol that mimics the one used by saslauthd and pwcheck, two outboard daemons included in the standard SASL library distro. The only thing this is really suitable for is SASL PLAIN (user+password) authentication, but the SASL libs that are linked into standard servers (like imapd and sendmail) implement the other ones.

You can use this module directly as a handler for EM Connections, or include it in a module or handler class of your own.

First connect to a SASL server (it’s probably a TCP server, or more likely a Unix-domain socket). Then call the # method, passing at least a username and a password. # returns a Deferrable which will either succeed or fail, depending on the status of the authentication operation.

Constants

MaxFieldSize

Public Instance Methods

post_init() click to toggle source
     # File lib/em/protocols/saslauth.rb, line 151
151:       def post_init
152:         @sasl_data = ""
153:         @queries = []
154:       end
receive_data(data) click to toggle source
     # File lib/em/protocols/saslauth.rb, line 156
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
validate?(username, psw, sysname=nil, realm=nil) click to toggle source
     # File lib/em/protocols/saslauth.rb, line 139
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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.