scutil 0.4.5 → 0.4.6

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.rdoc CHANGED
@@ -1,6 +1,10 @@
1
1
 
2
2
  ==Changelog
3
3
 
4
+ ===0.4.6 | 2012-08-23
5
+
6
+ * Handle connection timeouts with a Scutil::Error.
7
+
4
8
  ===0.4.5 | 2012-05-25
5
9
 
6
10
  * Minor bug when running scutil with Ruby 1.8.
data/lib/scutil.rb CHANGED
@@ -29,7 +29,7 @@ require 'scutil/connection_cache'
29
29
  require 'scutil/system_connection'
30
30
 
31
31
  module Scutil
32
- SCUTIL_VERSION = '0.4.5'
32
+ SCUTIL_VERSION = '0.4.6'
33
33
 
34
34
  # By default, buffer 10M of data before writing.
35
35
  DEFAULT_OUTPUT_BUFFER_SIZE = 0xA00000
@@ -137,20 +137,10 @@ module Scutil
137
137
  end
138
138
 
139
139
  # If a custom password prompt regex has been defined, use it.
140
- if (!options[:scutil_sudo_passwd_regex].nil? &&
141
- (options[:scutil_sudo_passwd_regex].kind_of? Regexp))
142
- passwd_regex = options[:scutil_sudo_passwd_regex]
143
- else
144
- raise Scutil::Error.new(":scutil_sudo_passwd_regex must be a kind of Regexp", hostname)
145
- end
140
+ passwd_regex = set_sudo_password_prompt(options)
146
141
 
147
142
  # If a custom bad password prompt regex has been defined, use it.
148
- if (!options[:scutil_sudo_passwd_failed_regex].nil? &&
149
- (options[:scutil_sudo_passwd_failed_regex].kind_of? Regexp))
150
- passwd_failed_regex = options[:scutil_sudo_passwd_failed_regex]
151
- else
152
- raise Scutil::Error.new(":scutil_sudo_passwd_failed_regex must be a kind of Regexp", hostname)
153
- end
143
+ passwd_failed_regex = set_sudo_password_failed(options)
154
144
 
155
145
  # Setup channel callbacks
156
146
  odata = ""
@@ -177,23 +167,23 @@ module Scutil
177
167
  # :waiting => Password sent, wating for reply.
178
168
  # :done => Authenication complete or not required.
179
169
  case (sudo_passwd_state)
170
+ when :done
171
+ odata += data
180
172
  when :new
181
- if (data =~ passwd_regex)
182
- if (options[:scutil_sudo_passwd].nil?)
183
- # No password defined
173
+ if (data =~ passwd_regex) # We have been prompted for a sudo password
174
+ if (options[:scutil_sudo_passwd].nil?) # No password defined, bail
184
175
  raise Scutil::Error.new("[#{conn.host}:#{channel.local_id}] Password required for sudo.
185
176
  Define in :scutil_sudo_passwd.", hostname)
186
177
  channel.close
187
178
  end
188
179
  ch.send_data options[:scutil_sudo_passwd] + "\n"
189
180
  sudo_passwd_state = :waiting
190
- else
181
+ else # No sudo password needed, grab the data and move on.
191
182
  odata += data
192
183
  sudo_passwd_state = :done
193
184
  end
194
185
  when :waiting
195
- if (data =~ passwd_failed_regex)
196
- # Bad sudo password
186
+ if (data =~ passwd_failed_regex) # Bad sudo password
197
187
  raise Scutil::Error.new("[#{conn.host}:#{channel.local_id}] Password failed for sudo.
198
188
  Define in :scutil_sudo_passwd or check :scutil_sudo_failed_passwd for the correct failure response.",
199
189
  hostname)
@@ -203,7 +193,7 @@ Define in :scutil_sudo_passwd or check :scutil_sudo_failed_passwd for the correc
203
193
  # NoOp for "\n"
204
194
  end
205
195
  else
206
- odata += data
196
+ raise Scutil::Error.new("[#{conn.host}:#{channel.local_id}] Invalid connection state.", hostname)
207
197
  end
208
198
 
209
199
  # Only buffer some of the output before writing to disk (10M by default).
@@ -309,6 +299,8 @@ Define in :scutil_sudo_passwd or check :scutil_sudo_failed_passwd for the correc
309
299
  raise Scutil::Error.new("Authenication failed for user: #{username}", hostname)
310
300
  rescue SocketError => err
311
301
  raise Scutil::Error.new(err.message, hostname)
302
+ rescue Errno::ETIMEDOUT => err
303
+ raise Scutil::Error.new(err.message, hostname)
312
304
  end
313
305
  return conn
314
306
  end
@@ -325,10 +317,28 @@ Define in :scutil_sudo_passwd or check :scutil_sudo_failed_passwd for the correc
325
317
  :scutil_sudo_passwd => nil
326
318
  }
327
319
  end
328
- end
329
-
330
- def method_missing(method, *args, &block)
331
- return if ((method == :download) || (method == :upload))
332
- super
320
+
321
+ def set_sudo_password_prompt(options)
322
+ if (!options[:scutil_sudo_passwd_regex].nil? &&
323
+ (options[:scutil_sudo_passwd_regex].kind_of? Regexp))
324
+ return options[:scutil_sudo_passwd_regex]
325
+ else
326
+ raise Scutil::Error.new(":scutil_sudo_passwd_regex must be a kind of Regexp", hostname)
327
+ end
328
+ end
329
+
330
+ def set_sudo_password_failed(options)
331
+ if (!options[:scutil_sudo_passwd_failed_regex].nil? &&
332
+ (options[:scutil_sudo_passwd_failed_regex].kind_of? Regexp))
333
+ return options[:scutil_sudo_passwd_failed_regex]
334
+ else
335
+ raise Scutil::Error.new(":scutil_sudo_passwd_failed_regex must be a kind of Regexp", hostname)
336
+ end
337
+ end
338
+
339
+ def method_missing(method, *args, &block)
340
+ return if ((method == :download) || (method == :upload))
341
+ super
342
+ end
333
343
  end
334
344
  end
@@ -19,7 +19,7 @@ module Scutil
19
19
  conn = nil
20
20
  # Local map has precedence.
21
21
  @options.merge!(options)
22
-
22
+
23
23
  ssh_options = scrub_options @options
24
24
  options = @options
25
25
  if (pty_needed)
data/scutil.gemspec CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'scutil'
4
- s.version = '0.4.5'
5
- s.date = '2012-05-25'
4
+ s.version = '0.4.6'
5
+ s.date = '2012-08-23'
6
6
  s.summary = 'SSH Command UTILity'
7
7
  s.description = <<-EOF
8
8
  Scutil is a library for conveniently executing commands
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scutil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-25 00:00:00.000000000 Z
12
+ date: 2012-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-ssh