rbus 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.txt +3 -0
- data/Manifest.txt +1 -0
- data/lib/rbus/auth/external_win.rb +129 -0
- data/lib/rbus/etc/blankslate.rb +23 -0
- data/lib/rbus/etc/version.rb +2 -2
- metadata +3 -2
data/CHANGELOG.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -0,0 +1,129 @@
|
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
# R-Bus is a native Ruby implementation of the D-Bus protocol.
|
4
|
+
# Copyright (C) 2007 Cezar Sá Espinola (cezarsa@gmail.com)
|
5
|
+
#
|
6
|
+
# This program is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with this program; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19
|
+
# MA 02110-1301, USA. A copy of the GNU General Public License is
|
20
|
+
# also available at http://www.gnu.org/copyleft/gpl.html.
|
21
|
+
#
|
22
|
+
#++
|
23
|
+
#
|
24
|
+
|
25
|
+
# This file replaces Process.uid on Windows machines, to make it possible
|
26
|
+
# to authenticate.
|
27
|
+
|
28
|
+
# If we are not on Windows the whole file should be ignored.
|
29
|
+
catch(:not_windows) do
|
30
|
+
|
31
|
+
throw :not_windows if RUBY_PLATFORM.split("-")[1] != 'mswin32'
|
32
|
+
|
33
|
+
require 'Win32API'
|
34
|
+
|
35
|
+
module RBus
|
36
|
+
module Auth
|
37
|
+
# Used to access Win32API and grab a ATOM to be used in replace of
|
38
|
+
# Process.uid in the EXTERNAL authentication mechanism.
|
39
|
+
class WinUid
|
40
|
+
@@ERROR_INSUFFICIENT_BUFFER = 122
|
41
|
+
@@TOKEN_QUERY = 0x0008
|
42
|
+
@@TokenUser = 1
|
43
|
+
def win_error_msg(msg)
|
44
|
+
"#{msg} GetLastError()=#{@GetLastError.call}"
|
45
|
+
end
|
46
|
+
def initialize
|
47
|
+
@GetLastError = Win32API.new('kernel32', 'GetLastError', [], 'L')
|
48
|
+
@GetCurrentProcess = Win32API.new('kernel32', 'GetCurrentProcess', [], 'L')
|
49
|
+
@CloseHandle = Win32API.new('kernel32', 'CloseHandle', ['L'], 'L')
|
50
|
+
@GlobalAddAtom = Win32API.new('kernel32', 'GlobalAddAtom', ['L'], 'L')
|
51
|
+
@LocalFree = Win32API.new('kernel32', 'LocalFree', ['L'], 'L')
|
52
|
+
|
53
|
+
@OpenProcessToken = Win32API.new('advapi32', 'OpenProcessToken', ['L','L','P'], 'L')
|
54
|
+
@GetTokenInformation = Win32API.new('advapi32', 'GetTokenInformation', ['L','P','P','L','P'], 'L')
|
55
|
+
@IsValidSid = Win32API.new('advapi32', 'IsValidSid', ['L'], 'L')
|
56
|
+
@ConvertSidToStringSid = Win32API.new('advapi32', 'ConvertSidToStringSid', ['L','P'], 'L')
|
57
|
+
end
|
58
|
+
def uid
|
59
|
+
process_token_long = nil
|
60
|
+
sid_ptr_long = nil
|
61
|
+
process_token = "\0" * 4
|
62
|
+
length = "\0" * 4
|
63
|
+
|
64
|
+
begin
|
65
|
+
current_process = @GetCurrentProcess.call()
|
66
|
+
|
67
|
+
result = @OpenProcessToken.call(current_process, @@TOKEN_QUERY, process_token)
|
68
|
+
if result == 0
|
69
|
+
raise win_error_msg('OpenProcessToken')
|
70
|
+
end
|
71
|
+
|
72
|
+
process_token_long = process_token.unpack('L')[0]
|
73
|
+
|
74
|
+
result = @GetTokenInformation.call(process_token_long, @@TokenUser, 0, 0, length)
|
75
|
+
if result == 0 && @GetLastError.call != @@ERROR_INSUFFICIENT_BUFFER
|
76
|
+
raise win_error_msg('GetTokenInformation')
|
77
|
+
end
|
78
|
+
|
79
|
+
length_long = length.unpack('L')[0]
|
80
|
+
token_user = "\0" * length_long
|
81
|
+
|
82
|
+
result = @GetTokenInformation.call(process_token_long, @@TokenUser, token_user, length_long, length)
|
83
|
+
if result == 0
|
84
|
+
raise win_error_msg('GetTokenInformation(2)')
|
85
|
+
end
|
86
|
+
|
87
|
+
psid = token_user.unpack('L')[0]
|
88
|
+
|
89
|
+
result = @IsValidSid.call(psid)
|
90
|
+
if result == 0
|
91
|
+
raise win_error_msg('IsValidSid')
|
92
|
+
end
|
93
|
+
|
94
|
+
sid_ptr = "\0" * 4
|
95
|
+
result = @ConvertSidToStringSid.call(psid, sid_ptr)
|
96
|
+
if result == 0
|
97
|
+
raise win_error_msg('ConvertSidToStringSid')
|
98
|
+
end
|
99
|
+
sid_ptr_long = sid_ptr.unpack('L')[0]
|
100
|
+
|
101
|
+
atom = @GlobalAddAtom.call(sid_ptr_long)
|
102
|
+
|
103
|
+
if atom == 0
|
104
|
+
raise win_error_msg('GlobalAddAtom')
|
105
|
+
end
|
106
|
+
ensure
|
107
|
+
if not process_token_long.nil?
|
108
|
+
@CloseHandle.call(process_token_long)
|
109
|
+
end
|
110
|
+
|
111
|
+
if not sid_ptr_long.nil?
|
112
|
+
@LocalFree.call(sid_ptr_long)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
# Insure ATOM is only 2 bytes
|
116
|
+
atom & 0xffff
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Override Process.uid with windows version.
|
123
|
+
module Process
|
124
|
+
def self.uid
|
125
|
+
RBus::Auth::WinUid.new.uid
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
data/lib/rbus/etc/blankslate.rb
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
# R-Bus is a native Ruby implementation of the D-Bus protocol.
|
4
|
+
# Copyright (C) 2007 Kristoffer Lundén (kristoffer.lunden@gmail.com)
|
5
|
+
#
|
6
|
+
# This program is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with this program; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19
|
+
# MA 02110-1301, USA. A copy of the GNU General Public License is
|
20
|
+
# also available at http://www.gnu.org/copyleft/gpl.html.
|
21
|
+
#
|
22
|
+
#++
|
23
|
+
#
|
1
24
|
module RBus
|
2
25
|
# BlankSlate is a superclass that empties (almost) all instance methods
|
3
26
|
# from it's subclasses.
|
data/lib/rbus/etc/version.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rbus
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-05-
|
6
|
+
version: 0.2.0
|
7
|
+
date: 2007-05-06 00:00:00 +02:00
|
8
8
|
summary: A native implementation of the D-Bus protocol.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- lib/rbus/auth/dbus_cookie_sha1.rb
|
55
55
|
- lib/rbus/auth/dummy.rb
|
56
56
|
- lib/rbus/auth/external.rb
|
57
|
+
- lib/rbus/auth/external_win.rb
|
57
58
|
- lib/rbus/auth/state_machine.rb
|
58
59
|
- lib/rbus/bus/bus.rb
|
59
60
|
- lib/rbus/bus/proxy.rb
|