hrr_rb_sftp-statvfs 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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +3 -0
- data/.travis.yml +25 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/demo/hrr_rb_sftp_server.rb +24 -0
- data/demo/instantiate_hrr_rb_sftp_server.rb +68 -0
- data/demo/spawn_hrr_rb_sftp_server.rb +67 -0
- data/hrr_rb_sftp-statvfs.gemspec +27 -0
- data/lib/hrr_rb_sftp/protocol/version3/extensions/fstatvfs_at_openssh_com.rb +107 -0
- data/lib/hrr_rb_sftp/protocol/version3/extensions/statvfs_at_openssh_com.rb +104 -0
- data/lib/hrr_rb_sftp/statvfs.rb +23 -0
- data/lib/hrr_rb_sftp/statvfs/version.rb +9 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 80e0b58692f8638aa572ce5979be7a0fb450fddacf5c4451dd89c3dd87629a18
|
4
|
+
data.tar.gz: 3875d38847ecc646c83514ce1eeb0886a34897e8e10bc0d862e1b6119db8f720
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52b3490d238890b44f0a10e65fa66cd0f2f30d5c1d74b055f7b068ca05733c947ff779e5dd24dbedc47a85760f3465012ce8e3557780c6326c280d12099dde80
|
7
|
+
data.tar.gz: a36f3a8d2df917fba7ba120814c1ee7a9d2a2a6e89ccfffb1839bf73b8e8bddca70b3a3b9c3e643ffbbf00a28c5237befa75f7b47536a32ef2b3b6640d977492
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
---
|
2
|
+
language: ruby
|
3
|
+
cache: bundler
|
4
|
+
rvm:
|
5
|
+
- 2.0
|
6
|
+
- 2.1
|
7
|
+
- 2.2
|
8
|
+
- 2.3
|
9
|
+
- 2.4
|
10
|
+
- 2.5
|
11
|
+
- 2.6
|
12
|
+
- 2.7
|
13
|
+
- ruby-head
|
14
|
+
jobs:
|
15
|
+
allow_failures:
|
16
|
+
- rvm: ruby-head
|
17
|
+
before_install:
|
18
|
+
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
19
|
+
- gem install bundler -v '< 2'
|
20
|
+
- yes | gem update --system --force
|
21
|
+
- gem update bundler
|
22
|
+
install:
|
23
|
+
- bundle install
|
24
|
+
script:
|
25
|
+
- bundle exec rake spec
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at hirura@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 hirura
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# HrrRbSftp::Statvfs
|
2
|
+
|
3
|
+
[](https://travis-ci.com/hirura/hrr_rb_sftp-statvfs)
|
4
|
+
[](https://badge.fury.io/rb/hrr_rb_sftp-statvfs)
|
5
|
+
|
6
|
+
hrr_rb_sftp-statvfs is an hrr_rb_sftp extension that supports statvfs@openssh.com and fstatvfs@openssh.com extensions.
|
7
|
+
|
8
|
+
## Table of Contents
|
9
|
+
|
10
|
+
- [Installation](#installation)
|
11
|
+
- [Usage](#usage)
|
12
|
+
- [Supported extensions](#supported-extensions)
|
13
|
+
- [Development](#development)
|
14
|
+
- [Contributing](#contributing)
|
15
|
+
- [License](#license)
|
16
|
+
- [Code of Conduct](#code-of-conduct)
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'hrr_rb_sftp'
|
24
|
+
gem 'hrr_rb_sftp-statvfs'
|
25
|
+
```
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
$ bundle install
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
$ gem install hrr_rb_sftp
|
34
|
+
$ gem install hrr_rb_sftp-statvfs
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
hrr_rb_sftp-statvfs can be used with hrr_rb_sftp library.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
require "hrr_rb_sftp"
|
42
|
+
require "hrr_rb_sftp/statvfs"
|
43
|
+
```
|
44
|
+
|
45
|
+
## Supported extensions
|
46
|
+
|
47
|
+
The following extensions are additionally supported.
|
48
|
+
|
49
|
+
- statvfs@openssh.com version 2
|
50
|
+
- fstatvfs@openssh.com version 2
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
55
|
+
|
56
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hirura/hrr_rb_sftp-statvfs. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/hirura/hrr_rb_sftp-statvfs/blob/master/CODE_OF_CONDUCT.md).
|
61
|
+
|
62
|
+
## License
|
63
|
+
|
64
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
65
|
+
|
66
|
+
## Code of Conduct
|
67
|
+
|
68
|
+
Everyone interacting in the HrrRbSftp::Statvfs project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hirura/hrr_rb_sftp-statvfs/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "hrr_rb_sftp/statvfs"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "logger"
|
4
|
+
require "hrr_rb_sftp"
|
5
|
+
|
6
|
+
begin
|
7
|
+
require "hrr_rb_sftp/statvfs"
|
8
|
+
rescue LoadError
|
9
|
+
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
10
|
+
require "hrr_rb_sftp/statvfs"
|
11
|
+
end
|
12
|
+
|
13
|
+
class MyLoggerFormatter < ::Logger::Formatter
|
14
|
+
def call severity, time, progname, msg
|
15
|
+
"%s, [%s#%d.%x] %5s -- %s: %s\n" % [severity[0..0], format_datetime(time), Process.pid, Thread.current.object_id, severity, progname, msg2str(msg)]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
logger = Logger.new(File.join(File.dirname(__FILE__), "hrr_rb_sftp_server.log"))
|
20
|
+
logger.level = Logger::INFO
|
21
|
+
logger.formatter = MyLoggerFormatter.new
|
22
|
+
|
23
|
+
server = HrrRbSftp::Server.new(logger: logger)
|
24
|
+
server.start $stdin, $stdout, $stderr
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require "logger"
|
2
|
+
require "socket"
|
3
|
+
require "hrr_rb_ssh"
|
4
|
+
require "hrr_rb_sftp"
|
5
|
+
|
6
|
+
begin
|
7
|
+
require "hrr_rb_sftp/statvfs"
|
8
|
+
rescue LoadError
|
9
|
+
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
10
|
+
require "hrr_rb_sftp/statvfs"
|
11
|
+
end
|
12
|
+
|
13
|
+
class MyLoggerFormatter < ::Logger::Formatter
|
14
|
+
def call severity, time, progname, msg
|
15
|
+
"%s, [%s#%d.%x] %5s -- %s: %s\n" % [severity[0..0], format_datetime(time), Process.pid, Thread.current.object_id, severity, progname, msg2str(msg)]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
logger = Logger.new(File.join(File.dirname(__FILE__), "instantiate_hrr_rb_sftp_server.log"))
|
20
|
+
logger.level = Logger::INFO
|
21
|
+
logger.formatter = MyLoggerFormatter.new
|
22
|
+
|
23
|
+
auth_publickey = HrrRbSsh::Authentication::Authenticator.new { |ctx|
|
24
|
+
true # accept any user
|
25
|
+
}
|
26
|
+
|
27
|
+
conn_subsys = HrrRbSsh::Connection::RequestHandler.new { |ctx|
|
28
|
+
ctx.chain_proc { |chain|
|
29
|
+
case ctx.subsystem_name
|
30
|
+
when "sftp"
|
31
|
+
sftp_server = HrrRbSftp::Server.new(logger: logger)
|
32
|
+
sftp_server.start(ctx.io[0], ctx.io[1], ctx.io[2])
|
33
|
+
exitstatus = 0
|
34
|
+
else
|
35
|
+
exitstatus = 1
|
36
|
+
end
|
37
|
+
exitstatus
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
options = {}
|
42
|
+
options["authentication_publickey_authenticator"] = auth_publickey
|
43
|
+
options["connection_channel_request_subsystem"] = conn_subsys
|
44
|
+
|
45
|
+
server = TCPServer.new 10022
|
46
|
+
while true
|
47
|
+
Thread.new(server.accept) do |io|
|
48
|
+
begin
|
49
|
+
pid = fork do
|
50
|
+
begin
|
51
|
+
ssh_server = HrrRbSsh::Server.new(options, logger: logger)
|
52
|
+
ssh_server.start io
|
53
|
+
rescue => e
|
54
|
+
logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
55
|
+
exit false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
logger.info { "process #{pid} started" }
|
59
|
+
io.close rescue nil
|
60
|
+
pid, status = Process.waitpid2(pid)
|
61
|
+
rescue => e
|
62
|
+
logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
63
|
+
ensure
|
64
|
+
status ||= nil
|
65
|
+
logger.info { "process #{pid} finished with status #{status.inspect}" }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "logger"
|
2
|
+
require "socket"
|
3
|
+
require "hrr_rb_ssh"
|
4
|
+
require "hrr_rb_sftp"
|
5
|
+
|
6
|
+
begin
|
7
|
+
require "hrr_rb_sftp/statvfs"
|
8
|
+
rescue LoadError
|
9
|
+
$:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
10
|
+
require "hrr_rb_sftp/statvfs"
|
11
|
+
end
|
12
|
+
|
13
|
+
class MyLoggerFormatter < ::Logger::Formatter
|
14
|
+
def call severity, time, progname, msg
|
15
|
+
"%s, [%s#%d.%x] %5s -- %s: %s\n" % [severity[0..0], format_datetime(time), Process.pid, Thread.current.object_id, severity, progname, msg2str(msg)]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
logger = Logger.new(File.join(File.dirname(__FILE__), "spawn_hrr_rb_sftp_server.log"))
|
20
|
+
logger.level = Logger::INFO
|
21
|
+
logger.formatter = MyLoggerFormatter.new
|
22
|
+
|
23
|
+
auth_publickey = HrrRbSsh::Authentication::Authenticator.new { |ctx|
|
24
|
+
true # accept any user
|
25
|
+
}
|
26
|
+
|
27
|
+
conn_subsys = HrrRbSsh::Connection::RequestHandler.new { |ctx|
|
28
|
+
ctx.chain_proc { |chain|
|
29
|
+
case ctx.subsystem_name
|
30
|
+
when "sftp"
|
31
|
+
pid = spawn(File.join(File.dirname(__FILE__), "hrr_rb_sftp_server.rb"), {in: ctx.io[0], out: ctx.io[1], err: ctx.io[2]})
|
32
|
+
exitstatus = Process.waitpid(pid).to_i
|
33
|
+
else
|
34
|
+
exitstatus = 1
|
35
|
+
end
|
36
|
+
exitstatus
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
options = {}
|
41
|
+
options["authentication_publickey_authenticator"] = auth_publickey
|
42
|
+
options["connection_channel_request_subsystem"] = conn_subsys
|
43
|
+
|
44
|
+
server = TCPServer.new 10022
|
45
|
+
while true
|
46
|
+
Thread.new(server.accept) do |io|
|
47
|
+
begin
|
48
|
+
pid = fork do
|
49
|
+
begin
|
50
|
+
ssh_server = HrrRbSsh::Server.new(options, logger: logger)
|
51
|
+
ssh_server.start io
|
52
|
+
rescue => e
|
53
|
+
logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
54
|
+
exit false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
logger.info { "process #{pid} started" }
|
58
|
+
io.close rescue nil
|
59
|
+
pid, status = Process.waitpid2(pid)
|
60
|
+
rescue => e
|
61
|
+
logger.error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
62
|
+
ensure
|
63
|
+
status ||= nil
|
64
|
+
logger.info { "process #{pid} finished with status #{status.inspect}" }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'lib/hrr_rb_sftp/statvfs/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "hrr_rb_sftp-statvfs"
|
5
|
+
spec.version = HrrRbSftp::Statvfs::VERSION
|
6
|
+
spec.authors = ["hirura"]
|
7
|
+
spec.email = ["hirura@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{An hrr_rb_sftp extension that supports statvfs@openssh.com and fstatvfs@openssh.com extensions.}
|
10
|
+
spec.description = %q{An hrr_rb_sftp extension that supports statvfs@openssh.com and fstatvfs@openssh.com extensions.}
|
11
|
+
spec.homepage = "https://github.com/hirura/hrr_rb_sftp-statvfs"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.0.0")
|
14
|
+
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
#spec.metadata["source_code_uri"] = spec.homepage
|
17
|
+
#spec.metadata["changelog_uri"] = spec.homepage
|
18
|
+
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "sys-filesystem"
|
26
|
+
spec.add_runtime_dependency "hrr_rb_sftp", "~> 0.2.0"
|
27
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module HrrRbSftp
|
2
|
+
class Protocol
|
3
|
+
module Version3
|
4
|
+
class Extensions
|
5
|
+
|
6
|
+
#
|
7
|
+
# This class implements fstatvfs@openssh.com version 2 extension format and responder.
|
8
|
+
#
|
9
|
+
class FstatvfsAtOpensshCom < Extension
|
10
|
+
|
11
|
+
#
|
12
|
+
# Represents fstatvfs@openssh.com version 2 extension name.
|
13
|
+
#
|
14
|
+
EXTENSION_NAME = "fstatvfs@openssh.com"
|
15
|
+
|
16
|
+
#
|
17
|
+
# Represents fstatvfs@openssh.com version 2 extension data.
|
18
|
+
#
|
19
|
+
EXTENSION_DATA = "2"
|
20
|
+
|
21
|
+
#
|
22
|
+
# Represents fstatvfs@openssh.com version 2 extension read-only flag.
|
23
|
+
#
|
24
|
+
SSH_FXE_STATVFS_ST_RDONLY = 0x1 # read-only
|
25
|
+
|
26
|
+
#
|
27
|
+
# Represents fstatvfs@openssh.com version 2 extension no setuid flag.
|
28
|
+
#
|
29
|
+
SSH_FXE_STATVFS_ST_NOSUID = 0x2 # no setuid
|
30
|
+
|
31
|
+
#
|
32
|
+
# Represents SSH_FXP_EXTENDED packet additional format for fstatvfs@openssh.com version 2 extension.
|
33
|
+
#
|
34
|
+
REQUEST_FORMAT = {
|
35
|
+
:"extended-request" => {
|
36
|
+
"fstatvfs@openssh.com" => [
|
37
|
+
[DataTypes::String, :"handle"],
|
38
|
+
],
|
39
|
+
},
|
40
|
+
}
|
41
|
+
|
42
|
+
#
|
43
|
+
# Represents SSH_FXP_EXTENDED_REPLY packet additional format for fstatvfs@openssh.com version 2 extension.
|
44
|
+
#
|
45
|
+
REPLY_FORMAT = {
|
46
|
+
:"extended-reply" => {
|
47
|
+
"fstatvfs@openssh.com" => [
|
48
|
+
[DataTypes::Uint64, :"f_bsize" ], # file system block size
|
49
|
+
[DataTypes::Uint64, :"f_frsize" ], # fundamental fs block size
|
50
|
+
[DataTypes::Uint64, :"f_blocks" ], # number of blocks (unit f_frsize)
|
51
|
+
[DataTypes::Uint64, :"f_bfree" ], # free blocks in file system
|
52
|
+
[DataTypes::Uint64, :"f_bavail" ], # free blocks for non-root
|
53
|
+
[DataTypes::Uint64, :"f_files" ], # total file inodes
|
54
|
+
[DataTypes::Uint64, :"f_ffree" ], # free file inodes
|
55
|
+
[DataTypes::Uint64, :"f_favail" ], # free file inodes for to non-root
|
56
|
+
[DataTypes::Uint64, :"f_fsid" ], # file system id
|
57
|
+
[DataTypes::Uint64, :"f_flag" ], # bit mask of f_flag values
|
58
|
+
[DataTypes::Uint64, :"f_namemax"], # maximum filename length
|
59
|
+
],
|
60
|
+
},
|
61
|
+
}
|
62
|
+
|
63
|
+
#
|
64
|
+
# Responds to SSH_FXP_EXTENDED request with fstatvfs@openssh.com extended-request.
|
65
|
+
#
|
66
|
+
# @param request [Hash{Symbol=>Object}] SSH_FXP_EXTENDED request represented in Hash.
|
67
|
+
# @return [Hash{Symbol=>Object}] Response represented in Hash. In case of success, its type is SSH_FXP_EXTENDED_REPLY. In other cases, its type is SSH_FXP_STATUS.
|
68
|
+
#
|
69
|
+
def respond_to request
|
70
|
+
begin
|
71
|
+
raise "Specified handle does not exist" unless handles.has_key?(request[:"handle"])
|
72
|
+
log_debug { "file = handles[#{request[:"handle"].inspect}]" }
|
73
|
+
file = handles[request[:"handle"]]
|
74
|
+
log_debug { "Sys::Filesystem.stat(#{file.path.inspect})" }
|
75
|
+
stat = Sys::Filesystem.stat(file.path)
|
76
|
+
{
|
77
|
+
:"type" => Packets::SSH_FXP_EXTENDED_REPLY::TYPE,
|
78
|
+
:"request-id" => request[:"request-id"],
|
79
|
+
:"extended-reply" => request[:"extended-request"], # implied field in reply format
|
80
|
+
:"f_bsize" => stat.block_size,
|
81
|
+
:"f_frsize" => stat.fragment_size,
|
82
|
+
:"f_blocks" => stat.blocks,
|
83
|
+
:"f_bfree" => stat.blocks_free,
|
84
|
+
:"f_bavail" => stat.blocks_available,
|
85
|
+
:"f_files" => stat.files,
|
86
|
+
:"f_ffree" => stat.files_free,
|
87
|
+
:"f_favail" => stat.files_available,
|
88
|
+
:"f_fsid" => stat.filesystem_id,
|
89
|
+
:"f_flag" => stat.flags & (Sys::Filesystem::Stat::RDONLY | Sys::Filesystem::Stat::NOSUID),
|
90
|
+
:"f_namemax" => stat.name_max,
|
91
|
+
}
|
92
|
+
rescue Sys::Filesystem::Error => e
|
93
|
+
log_debug { e.message }
|
94
|
+
{
|
95
|
+
:"type" => Packets::SSH_FXP_STATUS::TYPE,
|
96
|
+
:"request-id" => request[:"request-id"],
|
97
|
+
:"code" => Packets::SSH_FXP_STATUS::SSH_FX_FAILURE,
|
98
|
+
:"error message" => e.message,
|
99
|
+
:"language tag" => "",
|
100
|
+
}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module HrrRbSftp
|
2
|
+
class Protocol
|
3
|
+
module Version3
|
4
|
+
class Extensions
|
5
|
+
|
6
|
+
#
|
7
|
+
# This class implements statvfs@openssh.com version 2 extension format and responder.
|
8
|
+
#
|
9
|
+
class StatvfsAtOpensshCom < Extension
|
10
|
+
|
11
|
+
#
|
12
|
+
# Represents statvfs@openssh.com version 2 extension name.
|
13
|
+
#
|
14
|
+
EXTENSION_NAME = "statvfs@openssh.com"
|
15
|
+
|
16
|
+
#
|
17
|
+
# Represents statvfs@openssh.com version 2 extension data.
|
18
|
+
#
|
19
|
+
EXTENSION_DATA = "2"
|
20
|
+
|
21
|
+
#
|
22
|
+
# Represents statvfs@openssh.com version 2 extension read-only flag.
|
23
|
+
#
|
24
|
+
SSH_FXE_STATVFS_ST_RDONLY = 0x1 # read-only
|
25
|
+
|
26
|
+
#
|
27
|
+
# Represents statvfs@openssh.com version 2 extension no setuid flag.
|
28
|
+
#
|
29
|
+
SSH_FXE_STATVFS_ST_NOSUID = 0x2 # no setuid
|
30
|
+
|
31
|
+
#
|
32
|
+
# Represents SSH_FXP_EXTENDED packet additional format for statvfs@openssh.com version 2 extension.
|
33
|
+
#
|
34
|
+
REQUEST_FORMAT = {
|
35
|
+
:"extended-request" => {
|
36
|
+
"statvfs@openssh.com" => [
|
37
|
+
[DataTypes::String, :"path"],
|
38
|
+
],
|
39
|
+
},
|
40
|
+
}
|
41
|
+
|
42
|
+
#
|
43
|
+
# Represents SSH_FXP_EXTENDED_REPLY packet additional format for statvfs@openssh.com version 2 extension.
|
44
|
+
#
|
45
|
+
REPLY_FORMAT = {
|
46
|
+
:"extended-reply" => {
|
47
|
+
"statvfs@openssh.com" => [
|
48
|
+
[DataTypes::Uint64, :"f_bsize" ], # file system block size
|
49
|
+
[DataTypes::Uint64, :"f_frsize" ], # fundamental fs block size
|
50
|
+
[DataTypes::Uint64, :"f_blocks" ], # number of blocks (unit f_frsize)
|
51
|
+
[DataTypes::Uint64, :"f_bfree" ], # free blocks in file system
|
52
|
+
[DataTypes::Uint64, :"f_bavail" ], # free blocks for non-root
|
53
|
+
[DataTypes::Uint64, :"f_files" ], # total file inodes
|
54
|
+
[DataTypes::Uint64, :"f_ffree" ], # free file inodes
|
55
|
+
[DataTypes::Uint64, :"f_favail" ], # free file inodes for to non-root
|
56
|
+
[DataTypes::Uint64, :"f_fsid" ], # file system id
|
57
|
+
[DataTypes::Uint64, :"f_flag" ], # bit mask of f_flag values
|
58
|
+
[DataTypes::Uint64, :"f_namemax"], # maximum filename length
|
59
|
+
],
|
60
|
+
},
|
61
|
+
}
|
62
|
+
|
63
|
+
#
|
64
|
+
# Responds to SSH_FXP_EXTENDED request with statvfs@openssh.com extended-request.
|
65
|
+
#
|
66
|
+
# @param request [Hash{Symbol=>Object}] SSH_FXP_EXTENDED request represented in Hash.
|
67
|
+
# @return [Hash{Symbol=>Object}] Response represented in Hash. In case of success, its type is SSH_FXP_EXTENDED_REPLY. In other cases, its type is SSH_FXP_STATUS.
|
68
|
+
#
|
69
|
+
def respond_to request
|
70
|
+
begin
|
71
|
+
log_debug { "Sys::Filesystem.stat(#{request[:"path"].inspect})" }
|
72
|
+
stat = Sys::Filesystem.stat(request[:"path"])
|
73
|
+
{
|
74
|
+
:"type" => Packets::SSH_FXP_EXTENDED_REPLY::TYPE,
|
75
|
+
:"request-id" => request[:"request-id"],
|
76
|
+
:"extended-reply" => request[:"extended-request"], # implied field in reply format
|
77
|
+
:"f_bsize" => stat.block_size,
|
78
|
+
:"f_frsize" => stat.fragment_size,
|
79
|
+
:"f_blocks" => stat.blocks,
|
80
|
+
:"f_bfree" => stat.blocks_free,
|
81
|
+
:"f_bavail" => stat.blocks_available,
|
82
|
+
:"f_files" => stat.files,
|
83
|
+
:"f_ffree" => stat.files_free,
|
84
|
+
:"f_favail" => stat.files_available,
|
85
|
+
:"f_fsid" => stat.filesystem_id,
|
86
|
+
:"f_flag" => stat.flags & (Sys::Filesystem::Stat::RDONLY | Sys::Filesystem::Stat::NOSUID),
|
87
|
+
:"f_namemax" => stat.name_max,
|
88
|
+
}
|
89
|
+
rescue Sys::Filesystem::Error => e
|
90
|
+
log_debug { e.message }
|
91
|
+
{
|
92
|
+
:"type" => Packets::SSH_FXP_STATUS::TYPE,
|
93
|
+
:"request-id" => request[:"request-id"],
|
94
|
+
:"code" => Packets::SSH_FXP_STATUS::SSH_FX_FAILURE,
|
95
|
+
:"error message" => e.message,
|
96
|
+
:"language tag" => "",
|
97
|
+
}
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module HrrRbSftp
|
2
|
+
|
3
|
+
#
|
4
|
+
# hrr_rb_sftp-statvfs is an hrr_rb_sftp extension that supports statvfs@openssh.com and fstatvfs@openssh.com extensions.
|
5
|
+
#
|
6
|
+
# The following extensions are additionally supported.
|
7
|
+
# - statvfs@openssh.com
|
8
|
+
# - fstatvfs@openssh.com
|
9
|
+
#
|
10
|
+
# hrr_rb_sftp-statvfs can be used with hrr_rb_sftp library.
|
11
|
+
#
|
12
|
+
# require "hrr_rb_sftp"
|
13
|
+
# require "hrr_rb_sftp/statvfs"
|
14
|
+
#
|
15
|
+
module Statvfs
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require "sys/filesystem"
|
20
|
+
require "hrr_rb_sftp"
|
21
|
+
require "hrr_rb_sftp/statvfs/version"
|
22
|
+
require "hrr_rb_sftp/protocol/version3/extensions/statvfs_at_openssh_com"
|
23
|
+
require "hrr_rb_sftp/protocol/version3/extensions/fstatvfs_at_openssh_com"
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hrr_rb_sftp-statvfs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hirura
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sys-filesystem
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hrr_rb_sftp
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.0
|
41
|
+
description: An hrr_rb_sftp extension that supports statvfs@openssh.com and fstatvfs@openssh.com
|
42
|
+
extensions.
|
43
|
+
email:
|
44
|
+
- hirura@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rspec"
|
51
|
+
- ".travis.yml"
|
52
|
+
- CODE_OF_CONDUCT.md
|
53
|
+
- Gemfile
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- bin/console
|
58
|
+
- bin/setup
|
59
|
+
- demo/hrr_rb_sftp_server.rb
|
60
|
+
- demo/instantiate_hrr_rb_sftp_server.rb
|
61
|
+
- demo/spawn_hrr_rb_sftp_server.rb
|
62
|
+
- hrr_rb_sftp-statvfs.gemspec
|
63
|
+
- lib/hrr_rb_sftp/protocol/version3/extensions/fstatvfs_at_openssh_com.rb
|
64
|
+
- lib/hrr_rb_sftp/protocol/version3/extensions/statvfs_at_openssh_com.rb
|
65
|
+
- lib/hrr_rb_sftp/statvfs.rb
|
66
|
+
- lib/hrr_rb_sftp/statvfs/version.rb
|
67
|
+
homepage: https://github.com/hirura/hrr_rb_sftp-statvfs
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata:
|
71
|
+
homepage_uri: https://github.com/hirura/hrr_rb_sftp-statvfs
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 2.0.0
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubygems_version: 3.1.3
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: An hrr_rb_sftp extension that supports statvfs@openssh.com and fstatvfs@openssh.com
|
91
|
+
extensions.
|
92
|
+
test_files: []
|