pangdudu-ruby-dbus 0.2.4.1 → 0.2.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +26 -4
- data/lib/dbus/auth.rb +22 -12
- data/lib/dbus/bus.rb +13 -2
- data/lib/dbus/introspect.rb +2 -0
- data/lib/dbus.rb +0 -3
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -91,10 +91,32 @@ painful to use.
|
|
91
91
|
The file content also get's updated every 5 minutes (when a client fails to auth etc.).
|
92
92
|
Making copy and paste from one shell to another very frolic.
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
94
|
+
=== Hackish solution from pangdudu/robots/lib/robots_agent.rb
|
95
|
+
|
96
|
+
#because dbus remote auth still betrays us, we need to hack it
|
97
|
+
def get_remote_cookie
|
98
|
+
if @config[:robots_socket_name].include? "tcp:"
|
99
|
+
af, port, daemon_name, daemon_addr = (Socket::getaddrinfo(@config[:daemonhost],@config[:daemonhost].to_i)).first
|
100
|
+
ilog "Trying to get/hack remote cookie from: #{daemon_name}."
|
101
|
+
begin
|
102
|
+
cookiepath = "#{ENV['HOME']}/.dbus-keyrings/org_freedesktop_general"
|
103
|
+
#oki, the scp magic only works, if you use sshkeys
|
104
|
+
`scp #{daemon_addr}:.dbus-keyrings/org_freedesktop_general #{cookiepath}`
|
105
|
+
if File.exist? cookiepath
|
106
|
+
cookie = File.open(cookiepath)
|
107
|
+
dlog "Got cookie: #{cookie.gets}"
|
108
|
+
end
|
109
|
+
rescue
|
110
|
+
elog "Oops, something is wrong."
|
111
|
+
end
|
112
|
+
else
|
113
|
+
dlog "Nothing to hack, boring."
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
in principle, this is ok. we can now do what we want and it is save to exchange cookies over
|
118
|
+
a ssh session. However I'm still not feeling comfortable doing this. I guess everything else
|
119
|
+
would mean touching the reference C dbus-daemon implementation.
|
98
120
|
|
99
121
|
|
100
122
|
more infos:
|
data/lib/dbus/auth.rb
CHANGED
@@ -6,7 +6,10 @@
|
|
6
6
|
# License, version 2.1 as published by the Free Software Foundation.
|
7
7
|
# See the file "COPYING" for the exact licensing terms.
|
8
8
|
|
9
|
+
$debug = false #it's all over the state machine
|
10
|
+
|
9
11
|
module DBus
|
12
|
+
|
10
13
|
# Exception raised when authentication fails somehow.
|
11
14
|
class AuthenticationFailed < Exception
|
12
15
|
end
|
@@ -39,10 +42,12 @@ module DBus
|
|
39
42
|
# Class for 'CookieSHA1' type authentication.
|
40
43
|
# Implements the AUTH DBUS_COOKIE_SHA1 mechanism.
|
41
44
|
class DBusCookieSHA1 < Authenticator
|
42
|
-
|
45
|
+
|
43
46
|
#the autenticate method (called in stage one of authentification)
|
44
47
|
def authenticate
|
45
48
|
require 'etc'
|
49
|
+
#number of retries we have for auth
|
50
|
+
@retries = 1
|
46
51
|
return "#{hex_encode(Etc.getlogin)}" #server expects it to be binary
|
47
52
|
end
|
48
53
|
|
@@ -61,12 +66,12 @@ module DBus
|
|
61
66
|
c_challenge = Array.new(s_challenge.length/2).map{|obj|obj=rand(255).to_s}.join
|
62
67
|
# Search cookie file for id
|
63
68
|
path = File.join(ENV['HOME'], '.dbus-keyrings', context)
|
64
|
-
dlog "path: #{path.inspect}"
|
69
|
+
dlog "path: #{path.inspect}" #if $debug
|
65
70
|
File.foreach(path) do |line|
|
66
71
|
if line.index(id) == 0
|
67
72
|
# Right line of file, read cookie
|
68
73
|
cookie = line.split(' ')[2].chomp
|
69
|
-
dlog "cookie: #{cookie.inspect}"
|
74
|
+
dlog "cookie: #{cookie.inspect}" if $debug
|
70
75
|
# Concatenate and encrypt
|
71
76
|
to_encrypt = [s_challenge, c_challenge, cookie].join(':')
|
72
77
|
sha = Digest::SHA1.hexdigest(to_encrypt)
|
@@ -77,7 +82,12 @@ module DBus
|
|
77
82
|
return response
|
78
83
|
end
|
79
84
|
end
|
80
|
-
|
85
|
+
#a little rescue magic
|
86
|
+
elog "Could not auth, will now exit." unless @retries <= 0
|
87
|
+
elog "Unable to locate cookie, retry in 1 second."
|
88
|
+
@retries -= 1
|
89
|
+
sleep 1
|
90
|
+
data(hexdata)
|
81
91
|
end
|
82
92
|
|
83
93
|
# encode plain to hex
|
@@ -132,7 +142,7 @@ module DBus
|
|
132
142
|
raise AuthException if @auth_list.size == 0
|
133
143
|
@authenticator = @auth_list.shift.new
|
134
144
|
auth_msg = ["AUTH", @authenticator.name, @authenticator.authenticate]
|
135
|
-
dlog "auth_msg: #{auth_msg.inspect}"
|
145
|
+
dlog "auth_msg: #{auth_msg.inspect}" if $debug
|
136
146
|
send(auth_msg)
|
137
147
|
rescue AuthException
|
138
148
|
@socket.close
|
@@ -154,7 +164,7 @@ module DBus
|
|
154
164
|
break if data.include? crlf #crlf means line finished, the TCP socket keeps on listening, so we break
|
155
165
|
end
|
156
166
|
readline = data.chomp.split(" ")
|
157
|
-
dlog "readline: #{readline.inspect}"
|
167
|
+
dlog "readline: #{readline.inspect}" if $debug
|
158
168
|
return readline
|
159
169
|
end
|
160
170
|
|
@@ -162,7 +172,7 @@ module DBus
|
|
162
172
|
def next_state
|
163
173
|
msg = next_msg
|
164
174
|
if @state == :Starting
|
165
|
-
dlog ":Starting msg: #{msg[0].inspect}"
|
175
|
+
dlog ":Starting msg: #{msg[0].inspect}" if $debug
|
166
176
|
case msg[0]
|
167
177
|
when "OK"
|
168
178
|
@state = :WaitingForOk
|
@@ -172,15 +182,15 @@ module DBus
|
|
172
182
|
@state = :WaitingForData
|
173
183
|
end
|
174
184
|
end
|
175
|
-
dlog "state: #{@state}"
|
185
|
+
dlog "state: #{@state}" if $debug
|
176
186
|
case @state
|
177
187
|
when :WaitingForData
|
178
|
-
dlog ":WaitingForData msg: #{msg[0].inspect}"
|
188
|
+
dlog ":WaitingForData msg: #{msg[0].inspect}" if $debug
|
179
189
|
case msg[0]
|
180
190
|
when "DATA"
|
181
191
|
chall = msg[1]
|
182
192
|
resp, chall = @authenticator.data(chall)
|
183
|
-
dlog ":WaitingForData/DATA resp: #{resp.inspect}"
|
193
|
+
dlog ":WaitingForData/DATA resp: #{resp.inspect}" if $debug
|
184
194
|
case resp
|
185
195
|
when :AuthContinue
|
186
196
|
send("DATA", chall)
|
@@ -206,7 +216,7 @@ module DBus
|
|
206
216
|
@state = :WaitingForData
|
207
217
|
end
|
208
218
|
when :WaitingForOk
|
209
|
-
dlog ":WaitingForOk msg: #{msg[0].inspect}"
|
219
|
+
dlog ":WaitingForOk msg: #{msg[0].inspect}" if $debug
|
210
220
|
case msg[0]
|
211
221
|
when "OK"
|
212
222
|
send("BEGIN")
|
@@ -222,7 +232,7 @@ module DBus
|
|
222
232
|
@state = :WaitingForOk
|
223
233
|
end
|
224
234
|
when :WaitingForReject
|
225
|
-
dlog ":WaitingForReject msg: #{msg[0].inspect}"
|
235
|
+
dlog ":WaitingForReject msg: #{msg[0].inspect}" if $debug
|
226
236
|
case msg[0]
|
227
237
|
when "REJECT"
|
228
238
|
next_authenticator
|
data/lib/dbus/bus.rb
CHANGED
@@ -176,6 +176,7 @@ module DBus
|
|
176
176
|
# "transport1:key1=value1,key2=value2;transport2:key1=value1,key2=value2"
|
177
177
|
# e.g. "unix:path=/tmp/dbus-test" or "tcp:host=localhost,port=2687"
|
178
178
|
def initialize(path)
|
179
|
+
dlog "path: #{path}"
|
179
180
|
@path = path
|
180
181
|
@unique_name = nil
|
181
182
|
@buffer = ""
|
@@ -184,6 +185,7 @@ module DBus
|
|
184
185
|
@signal_matchrules = Array.new
|
185
186
|
@proxy = nil
|
186
187
|
@object_root = Node.new("/")
|
188
|
+
@is_tcp = false
|
187
189
|
end
|
188
190
|
|
189
191
|
# Connect to the bus and initialize the connection.
|
@@ -203,11 +205,12 @@ module DBus
|
|
203
205
|
port = para.sub("port=","").to_i if para.include? "port="
|
204
206
|
family = para.sub("family=","") if para.include? "family="
|
205
207
|
end
|
206
|
-
dlog "host,port,family : #{host},#{port},#{family}"
|
208
|
+
#dlog "host,port,family : #{host},#{port},#{family}"
|
207
209
|
begin
|
208
210
|
#initialize the tcp socket
|
209
211
|
@socket = TCPSocket.new(host,port)
|
210
212
|
init_connection
|
213
|
+
@is_tcp = true
|
211
214
|
rescue
|
212
215
|
elog "Could not establish connection to: #{@path}, will now exit."
|
213
216
|
exit(0) #a little harsh
|
@@ -446,7 +449,15 @@ module DBus
|
|
446
449
|
# Fill (append) the buffer from data that might be available on the
|
447
450
|
# socket.
|
448
451
|
def update_buffer
|
449
|
-
@buffer += @socket.read_nonblock(MSG_BUF_SIZE)
|
452
|
+
@buffer += @socket.read_nonblock(MSG_BUF_SIZE) if @is_tcp
|
453
|
+
unless @is_tcp
|
454
|
+
begin
|
455
|
+
@buffer += @socket.read_nonblock(MSG_BUF_SIZE)
|
456
|
+
rescue
|
457
|
+
wlog ".read_nonblock failed, falling back to .recv"
|
458
|
+
@buffer += @socket.recv(MSG_BUF_SIZE)
|
459
|
+
end
|
460
|
+
end
|
450
461
|
end
|
451
462
|
|
452
463
|
# Get one message from the bus and remove it from the buffer.
|
data/lib/dbus/introspect.rb
CHANGED
@@ -470,6 +470,8 @@ module DBus
|
|
470
470
|
if @default_iface and has_iface?(@default_iface)
|
471
471
|
@interfaces[@default_iface].method(name).call(*args)
|
472
472
|
else
|
473
|
+
dlog "interfaces: #{@interfaces.keys.inspect}"
|
474
|
+
dlog "default_iface: #{@default_iface}"
|
473
475
|
raise NoMethodError
|
474
476
|
end
|
475
477
|
end
|
data/lib/dbus.rb
CHANGED
@@ -9,9 +9,6 @@
|
|
9
9
|
# See the file "COPYING" for the exact licensing terms.
|
10
10
|
require 'rubygems'
|
11
11
|
require 'rofl' #http://github.com/pangdudu/rofl/tree/master makes the debug/tracing easy
|
12
|
-
#comes from the Rofl logger/tracer module
|
13
|
-
@logger.level = Logger::DEBUG
|
14
|
-
|
15
12
|
require 'dbus/type'
|
16
13
|
require 'dbus/introspect'
|
17
14
|
require 'dbus/export'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pangdudu-ruby-dbus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.4.
|
4
|
+
version: 0.2.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruby DBUS Team, pangdudu
|
@@ -9,7 +9,7 @@ autorequire: dbus
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-31 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|