Class: X11::Auth
- Inherits:
-
Object
- Object
- X11::Auth
- Defined in:
- lib/X11/auth.rb
Defined Under Namespace
Classes: AuthInfo
Constant Summary collapse
- FAILED =
0
- SUCCESS =
1
- AUTHENTICATE =
2
- ADDRESS_TYPES =
{ 0 => :Internet, 1 => :DECnet, 2 => :Chaos, 252 => :LocalHost, 253 => :Krb5Principal, 254 => :Netname, 256 => :Local, 65535 => :Wild, }
Instance Method Summary collapse
-
#get_by_hostname(host, family, display_id) ⇒ Object
Get authentication data for a connection of type family to display display_id on host.
-
#initialize(path = ENV['XAUTHORITY'] || ENV['HOME'] + "/.Xauthority") ⇒ Auth
constructor
Open an authority file, and create an object to handle it.
-
#read ⇒ Object
returns one entry from Xauthority file.
- #reset ⇒ Object
Constructor Details
#initialize(path = ENV['XAUTHORITY'] || ENV['HOME'] + "/.Xauthority") ⇒ Auth
Open an authority file, and create an object to handle it. The filename will be taken from the XAUTHORITY environment variable, if present, or ‘.Xauthority’ in the user’s home directory, or it may be overridden by an argument.
30 31 32 |
# File 'lib/X11/auth.rb', line 30 def initialize(path = ENV['XAUTHORITY'] || ENV['HOME'] + "/.Xauthority") @file = File.open(path) end |
Instance Method Details
#get_by_hostname(host, family, display_id) ⇒ Object
Get authentication data for a connection of type family to display display_id on host. If family is ‘Internet’, the host will be translated into an appropriate address by gethostbyname(). If no data is found, returns nil
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/X11/auth.rb', line 37 def get_by_hostname(host, family, display_id) host = `hostname`.chomp if host == 'localhost' or host == '127.0.0.1' or host.nil? # address = TCPSocket.gethostbyname(host) if family == :Internet # this line does nothing for now auth_data = nil # with each entry from XAuthority file until @file.eof? r = read() auth_data = r if r.display.empty? || display_id.to_i == r.display.to_i end reset return auth_data end |
#read ⇒ Object
returns one entry from Xauthority file
54 55 56 57 58 59 60 61 62 |
# File 'lib/X11/auth.rb', line 54 def read auth_info = [] << ADDRESS_TYPES[ @file.read(2).unpack1('n') ] 4.times do length = @file.read(2).unpack1('n') auth_info << @file.read(length) end AuthInfo[*auth_info] end |
#reset ⇒ Object
64 |
# File 'lib/X11/auth.rb', line 64 def reset = @file.seek(0, IO::SEEK_SET) |