EventMachine::Protocols::SASLauth

Implements SASL authd. 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.

SASL-auth is intended for reasonably fast operation inside a single machine, so it has no transport-security (although there have been multi-machine extensions incorporating transport-layer encryption).

The standard saslauthd module generally runs privileged and does its work by referring to the system-account files.

This feature was added to EventMachine to enable the development of custom authentication/authorization engines for standard servers.

To use SASLauth, include it in a class that subclasses EM::Connection, and reimplement the validate method.

The typical way to incorporate this module into an authentication daemon would be to set it as the handler for a UNIX-domain socket. The code might look like this:

 EM.start_unix_domain_server( "/var/run/saslauthd/mux", MyHandler )
 File.chmod( 0777, "/var/run/saslauthd/mux")

The chmod is probably needed to ensure that unprivileged clients can access the UNIX-domain socket.

It’s also a very good idea to drop superuser privileges (if any), after the UNIX-domain socket has been opened.

Constants

MaxFieldSize

Public Instance Methods

post_init() click to toggle source
    # File lib/em/protocols/saslauth.rb, line 85
85:       def post_init
86:         super
87:         @sasl_data = ""
88:         @sasl_values = []
89:       end
receive_data(data) click to toggle source
     # File lib/em/protocols/saslauth.rb, line 91
 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) ? "\00\\0002OK" : "\00\\0002NO" )
101:               @sasl_values.clear
102:             end
103:           else
104:             break
105:           end
106:         end
107:       end
validate(username, psw, sysname, realm) click to toggle source
     # File lib/em/protocols/saslauth.rb, line 109
109:       def validate username, psw, sysname, realm
110:         p username
111:         p psw
112:         p sysname
113:         p realm
114:         true
115:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.