Module: EventMachine::Protocols::SASLauthclient

### Home Classes Methods

### In Files

- lib/em/protocols/saslauth.rb

### Methods

- #post_init
- #receive_data
- #validate?

### Files

- ChangeLog
- DEFERRABLES
- EPOLL
- INSTALL
- KEYBOARD
- LEGAL
- LIGHTWEIGHT_CONCURRENCY
- PURE_RUBY
- RELEASE_NOTES
- SMTP
- SPAWNED_PROCESSES
- TODO

### Class/Module Index

Quicksearch

- EventMachine
- EventMachine
- EventMachine::Channel
- EventMachine::Completion
- EventMachine::Connection
- EventMachine::DNS
- EventMachine::DNS::Request
- EventMachine::DNS::RequestIdAlreadyUsed
- EventMachine::DNS::Resolver
- EventMachine::DNS::Socket
- EventMachine::DatagramObject
- EventMachine::DefaultDeferrable
- EventMachine::Deferrable
- EventMachine::DeferrableChildProcess
- EventMachine::Error
- EventMachine::EvmaKeyboard
- EventMachine::EvmaTCPClient
- EventMachine::EvmaTCPServer
- EventMachine::EvmaUDPSocket
- EventMachine::EvmaUNIXClient
- EventMachine::EvmaUNIXServer
- EventMachine::FileNotFoundException
- EventMachine::FileStreamer
- EventMachine::FileWatch
- EventMachine::Iterator
- EventMachine::LoopbreakReader
- EventMachine::PeriodicTimer
- EventMachine::Pool
- EventMachine::ProcessWatch
- EventMachine::Protocols
- EventMachine::Protocols
- EventMachine::Protocols::HeaderAndContentProtocol
- EventMachine::Protocols::HttpClient
- EventMachine::Protocols::HttpClient2
- EventMachine::Protocols::HttpClient2::Request
- EventMachine::Protocols::LineAndTextProtocol
- EventMachine::Protocols::LineProtocol
- EventMachine::Protocols::LineText2
- EventMachine::Protocols::Memcache
- EventMachine::Protocols::Memcache::ParserError
- EventMachine::Protocols::ObjectProtocol
- EventMachine::Protocols::Postgres3
- EventMachine::Protocols::SASLauth
- EventMachine::Protocols::SASLauthclient
- EventMachine::Protocols::SmtpClient
- EventMachine::Protocols::SmtpServer
- EventMachine::Protocols::Socks4
- EventMachine::Protocols::Stomp
- EventMachine::Protocols::Stomp::Message
- EventMachine::Protocols::TcpConnectTester
- EventMachine::Queue
- EventMachine::Reactor
- EventMachine::Selectable
- EventMachine::SpawnedProcess
- EventMachine::StreamObject
- EventMachine::SystemCmd
- EventMachine::ThreadedResource
- EventMachine::TickLoop
- EventMachine::Timer
- EventMachine::UuidGenerator
- EventMachine::YieldBlockFromSpawnedProcess
- Object
- Object::EM
- Object::P
- BufferedTokenizer
- IO
- StringIO
- TestConnection

No matching classes.

# 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 validate? method, passing at least a username and a password. validate? 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
    def post_init
      @sasl_data = ""
      @queries = []
    end

receive_data(data) click to toggle source

    # File lib/em/protocols/saslauth.rb, line 156
    def receive_data data
      @sasl_data << data

      while @sasl_data.length > 2
        len = (@sasl_data[0,2].unpack("n")).first
        raise "SASL Max Field Length exceeded" if len > MaxFieldSize
        if @sasl_data.length >= (len + 2)
          val = @sasl_data[2,len]
          @sasl_data.slice!(0...(2+len))
          q = @queries.pop
          (val == "NO") ? q.fail : q.succeed
        else
          break
        end
      end
    end

validate?(username, psw, sysname=nil, realm=nil) click to toggle source

    # File lib/em/protocols/saslauth.rb, line 139
    def validate? username, psw, sysname=nil, realm=nil

      str = [username, psw, sysname, realm].map {|m|
        [(m || "").length, (m || "")]
      }.flatten.pack( "nA*" * 4 )
      send_data str

      d = EM::DefaultDeferrable.new
      @queries.unshift d
      d
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.