sudo 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MANIFEST +2 -0
- data/README.rdoc +16 -16
- data/examples/lib/writable_root.rb +7 -0
- data/examples/writable_root.rb +52 -0
- data/lib/sudo/constants.rb +2 -1
- data/lib/sudo/wrapper.rb +18 -38
- metadata +26 -40
data/MANIFEST
CHANGED
data/README.rdoc
CHANGED
@@ -44,9 +44,8 @@ Use it!
|
|
44
44
|
sudo[MyClass].my_class_method
|
45
45
|
|
46
46
|
|
47
|
-
When you've done,
|
48
|
-
|
49
|
-
garbage-collected.
|
47
|
+
When you've done, +stop!+ it. Otherwise, that will be done (only) when
|
48
|
+
the +sudo+ object gets garbage-collected.
|
50
49
|
|
51
50
|
sudo.stop!
|
52
51
|
|
@@ -77,22 +76,28 @@ Access control is entirely delegated to +sudo+.
|
|
77
76
|
+sudo+ has a +-A+ option to accept password via an external program
|
78
77
|
(maybe graphical): support this feature.
|
79
78
|
|
80
|
-
==
|
79
|
+
== CREDITS
|
81
80
|
|
82
|
-
|
83
|
-
ruby-talk[http://www.ruby-forum.com/topic/262655].
|
84
|
-
|
85
|
-
== AUTHOR
|
81
|
+
=== AUTHOR
|
86
82
|
|
87
83
|
{Guido De Rosa}[http://github.com/gderosa/].
|
88
84
|
|
89
|
-
Sponsored by {VEMAR s.a.s.}[http://www.vemarsas.it/]
|
85
|
+
Sponsored by {VEMAR s.a.s.}[http://www.vemarsas.it/]
|
86
|
+
|
87
|
+
=== CONTRIBUTORS
|
88
|
+
|
89
|
+
{Robert M. Koch}[http://github.com/threadmetal/].
|
90
|
+
|
91
|
+
=== THANKS
|
92
|
+
|
93
|
+
Thanks to Tony Arcieri and Brian Candler for suggestions on
|
94
|
+
ruby-talk[http://www.ruby-forum.com/topic/262655].
|
90
95
|
|
91
|
-
|
96
|
+
=== COPYRIGHT
|
92
97
|
|
93
98
|
(The MIT License)
|
94
99
|
|
95
|
-
Copyright (c) 2010 Guido De Rosa
|
100
|
+
Copyright (c) 2010, 2011, 2012, 2013 Guido De Rosa
|
96
101
|
|
97
102
|
Permission is hereby granted, free of charge, to any person obtaining
|
98
103
|
a copy of this software and associated documentation files (the
|
@@ -112,8 +117,3 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
112
117
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
113
118
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
114
119
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'sudo'
|
2
|
+
|
3
|
+
|
4
|
+
t0 = Time.now
|
5
|
+
su = Sudo::Wrapper.new.start!
|
6
|
+
t1 = Time.now
|
7
|
+
|
8
|
+
writable_root = su[File].writable? '/'
|
9
|
+
t2 = Time.now
|
10
|
+
writable_root_by_normal_user = File.writable? '/'
|
11
|
+
|
12
|
+
puts
|
13
|
+
puts "writable_root = #{writable_root}"
|
14
|
+
puts "writable_root_by_normal_user = #{writable_root_by_normal_user}"
|
15
|
+
puts "Starting Sudo::Wrapper object took #{t1-t0} seconds"
|
16
|
+
puts "Using it, as in su[File].writable? '/', took #{t2-t1} seconds"
|
17
|
+
|
18
|
+
puts
|
19
|
+
puts "Now trying on an instance of WritableRoot custom class:"
|
20
|
+
|
21
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/lib"
|
22
|
+
require 'writable_root'
|
23
|
+
|
24
|
+
wr1 = WritableRoot.new
|
25
|
+
wr2 = WritableRoot.new
|
26
|
+
|
27
|
+
wr1.check
|
28
|
+
su[wr2].check
|
29
|
+
|
30
|
+
puts
|
31
|
+
puts "Hit ENTER to stop the Sudo::Wrapper object"
|
32
|
+
puts "(in the meantime, you can look at the ruby sudo-ed process with ps)"
|
33
|
+
gets
|
34
|
+
|
35
|
+
# Optional (it will be stopped automatically as soon as 'su' object gets out of scope).
|
36
|
+
su.stop!
|
37
|
+
|
38
|
+
puts "Now trying with a block (Sudo::Wrapper.run):"
|
39
|
+
writable_root = Sudo::Wrapper.run do |sudo|
|
40
|
+
print "As uid=#{ sudo[Process].uid }, "
|
41
|
+
sudo[File].writable? '/'
|
42
|
+
end
|
43
|
+
puts "writable_root = #{writable_root.inspect}"
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
data/lib/sudo/constants.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
module Sudo
|
2
2
|
|
3
|
-
VERSION = '0.1.
|
3
|
+
VERSION = '0.1.1'
|
4
4
|
ROOTDIR = File.expand_path File.join File.dirname(__FILE__), '../..'
|
5
5
|
LIBDIR = File.join ROOTDIR, 'lib'
|
6
6
|
SERVER_SCRIPT = File.join ROOTDIR, 'libexec/server.rb'
|
7
|
+
SUDO_CMD = ENV['rvm_path'] ? 'rvmsudo' : 'sudo'
|
7
8
|
|
8
9
|
class RuntimeError < RuntimeError; end
|
9
10
|
|
data/lib/sudo/wrapper.rb
CHANGED
@@ -5,12 +5,6 @@ require 'sudo/constants'
|
|
5
5
|
require 'sudo/system'
|
6
6
|
require 'sudo/proxy'
|
7
7
|
|
8
|
-
begin
|
9
|
-
DRb.current_server
|
10
|
-
rescue DRb::DRbServerNotFound
|
11
|
-
DRb.start_service
|
12
|
-
end
|
13
|
-
|
14
8
|
module Sudo
|
15
9
|
class Wrapper
|
16
10
|
|
@@ -27,21 +21,15 @@ module Sudo
|
|
27
21
|
class << self
|
28
22
|
|
29
23
|
# Yields a new running Sudo::Wrapper, and do all the necessary
|
30
|
-
# cleanup when the block exits.
|
24
|
+
# cleanup when the block exits.
|
31
25
|
#
|
32
|
-
# ruby_opts:: is passed to Sudo::Wrapper::new .
|
33
|
-
def run(ruby_opts) # :yields: sudo
|
26
|
+
# ruby_opts:: is passed to Sudo::Wrapper::new .
|
27
|
+
def run(ruby_opts = '') # :yields: sudo
|
34
28
|
sudo = new(ruby_opts).start!
|
35
|
-
yield sudo
|
29
|
+
retval = yield sudo
|
36
30
|
sudo.stop!
|
37
|
-
|
38
|
-
|
39
|
-
# currently unused
|
40
|
-
#def load_features
|
41
|
-
# ObjectSpace.each_object(self).each{|x| x.load_features}
|
42
|
-
#end
|
43
|
-
|
44
|
-
protected
|
31
|
+
retval
|
32
|
+
end
|
45
33
|
|
46
34
|
# Do the actual resources clean-up.
|
47
35
|
#
|
@@ -56,10 +44,10 @@ module Sudo
|
|
56
44
|
|
57
45
|
# +ruby_opts+ are the command line options to the sudo ruby interpreter;
|
58
46
|
# usually you don't need to specify stuff like "-rmygem/mylib", libraries
|
59
|
-
# will be sorta "inherited".
|
60
|
-
def initialize(ruby_opts='')
|
47
|
+
# will be sorta "inherited".
|
48
|
+
def initialize(ruby_opts='')
|
61
49
|
@proxy = nil
|
62
|
-
@socket = "/tmp/rubysu-#{Process.pid}-#{object_id}"
|
50
|
+
@socket = "/tmp/rubysu-#{Process.pid}-#{object_id}"
|
63
51
|
@sudo_pid = nil
|
64
52
|
@ruby_opts = ruby_opts
|
65
53
|
@loaded_features = []
|
@@ -67,14 +55,14 @@ module Sudo
|
|
67
55
|
end
|
68
56
|
|
69
57
|
def server_uri; "drbunix:#{@socket}"; end
|
70
|
-
|
58
|
+
|
71
59
|
# Start the sudo-ed Ruby process.
|
72
|
-
def start!
|
60
|
+
def start!
|
73
61
|
Sudo::System.check
|
74
|
-
|
75
|
-
@sudo_pid = spawn(
|
76
|
-
"
|
77
|
-
)
|
62
|
+
|
63
|
+
@sudo_pid = spawn(
|
64
|
+
"#{SUDO_CMD} ruby -I#{LIBDIR} #{@ruby_opts} #{SERVER_SCRIPT} #{@socket} #{Process.uid}"
|
65
|
+
)
|
78
66
|
Process.detach(@sudo_pid) if @sudo_pid # avoid zombies
|
79
67
|
ObjectSpace.define_finalizer self, Finalizer.new(
|
80
68
|
:pid => @sudo_pid, :socket => @socket
|
@@ -83,23 +71,16 @@ module Sudo
|
|
83
71
|
if wait_for(:timeout => 1){File.exists? @socket}
|
84
72
|
@proxy = DRbObject.new_with_uri(server_uri)
|
85
73
|
else
|
86
|
-
raise RuntimeError, "Couldn't create DRb socket #{@socket}"
|
74
|
+
raise RuntimeError, "Couldn't create DRb socket #{@socket}"
|
87
75
|
end
|
88
76
|
|
89
77
|
#set_load_path # apparently, we don't need this
|
90
|
-
|
78
|
+
|
91
79
|
load_features
|
92
80
|
|
93
81
|
self
|
94
82
|
end
|
95
83
|
|
96
|
-
# apparently, we don't need this
|
97
|
-
#def set_load_path
|
98
|
-
# ($LOAD_PATH - @load_path).reverse.each do |dir|
|
99
|
-
# @proxy.proxy Kernel, :eval, "$LOAD_PATH.unshift #{dir}"
|
100
|
-
# end
|
101
|
-
#end
|
102
|
-
|
103
84
|
# Load needed libraries in the DRb server. Usually you don't need
|
104
85
|
# to call this directly.
|
105
86
|
def load_features
|
@@ -128,7 +109,7 @@ module Sudo
|
|
128
109
|
self.class.cleanup!(:pid => @sudo_pid, :socket => @socket)
|
129
110
|
@proxy = nil
|
130
111
|
end
|
131
|
-
|
112
|
+
|
132
113
|
# Gives a copy of +object+ with root privileges.
|
133
114
|
def [](object)
|
134
115
|
if running?
|
@@ -154,4 +135,3 @@ module Sudo
|
|
154
135
|
|
155
136
|
end
|
156
137
|
end
|
157
|
-
|
metadata
CHANGED
@@ -1,39 +1,33 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sudo
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
version: 0.1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Guido De Rosa
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2010-10-25 00:00:00 +02:00
|
18
|
-
default_executable:
|
12
|
+
date: 2013-01-06 00:00:00.000000000 Z
|
19
13
|
dependencies: []
|
14
|
+
description: ! 'Give Ruby objects superuser privileges.
|
15
|
+
|
20
16
|
|
21
|
-
description: |
|
22
|
-
Give Ruby objects superuser privileges.
|
23
|
-
|
24
17
|
Based on dRuby and sudo (the Unix program).
|
25
18
|
|
19
|
+
'
|
26
20
|
email: guido.derosa@vemarsas.it
|
27
21
|
executables: []
|
28
|
-
|
29
22
|
extensions: []
|
30
|
-
|
31
|
-
extra_rdoc_files:
|
23
|
+
extra_rdoc_files:
|
32
24
|
- README.rdoc
|
33
|
-
files:
|
25
|
+
files:
|
34
26
|
- examples/block.rb
|
35
27
|
- examples/dsl.rb
|
36
28
|
- examples/new.rb
|
29
|
+
- examples/writable_root.rb
|
30
|
+
- examples/lib/writable_root.rb
|
37
31
|
- libexec/server.rb
|
38
32
|
- lib/sudo/constants.rb
|
39
33
|
- lib/sudo/dsl.rb
|
@@ -46,39 +40,31 @@ files:
|
|
46
40
|
- lib/sudo/wrapper.rb
|
47
41
|
- MANIFEST
|
48
42
|
- README.rdoc
|
49
|
-
has_rdoc: true
|
50
43
|
homepage: http://github.com/gderosa/rubysu
|
51
44
|
licenses: []
|
52
|
-
|
53
45
|
post_install_message:
|
54
|
-
rdoc_options:
|
46
|
+
rdoc_options:
|
55
47
|
- --charset=UTF-8
|
56
48
|
- --main
|
57
49
|
- README.rdoc
|
58
|
-
require_paths:
|
50
|
+
require_paths:
|
59
51
|
- lib
|
60
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
53
|
none: false
|
62
|
-
requirements:
|
63
|
-
- -
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
|
66
|
-
|
67
|
-
version: "0"
|
68
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
59
|
none: false
|
70
|
-
requirements:
|
71
|
-
- -
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
- 0
|
75
|
-
version: "0"
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
76
64
|
requirements: []
|
77
|
-
|
78
65
|
rubyforge_project:
|
79
|
-
rubygems_version: 1.
|
66
|
+
rubygems_version: 1.8.11
|
80
67
|
signing_key:
|
81
68
|
specification_version: 3
|
82
69
|
summary: Give Ruby objects superuser privileges
|
83
70
|
test_files: []
|
84
|
-
|