Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Semantic Versioning #1

Merged
merged 3 commits into from
Feb 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ It supports authentication via NTLM using the [ruby ntlm gem](https://rubygems.o

## Installation

This gem has not yet been released, but when it is, do this:

Add this line to your application's Gemfile:

```ruby
Expand All @@ -26,14 +28,34 @@ Or install it yourself as:

## Usage

### Using the `Client` class

```ruby
sock = TCPSocket.new("192.168.100.140", 445)
c = Smb2::Client.new(
socket: sock,
username:"administrator",
password:"P@ssword1",
domain:"asdfasdf"
)
c.negotiate
c.authenticate
```

### Making packets manually

```ruby
sock = TCPSocket.new("192.168.100.140", 445)
neg = Smb2::Packet::NegotiateRequest.new(
dialects: "\x02\x02".b,
# This is necessary until I can figure out how to set a default for
# `rest` fields
dialects: "\x02\x02".force_encoding("binary"),
)
nbss = [neg.length].pack("N")
sock.write(nbss + neg.to_s)
data = sock.read(36)
# Grab NBSS size
size = sock.read(4).unpack("N").first
data = sock.read(size)
neg_response = Smb2::Packet::NegotiateResponse.new(data)

```
Expand Down
43 changes: 42 additions & 1 deletion lib/smb2/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
module Smb2
VERSION = "0.0.1"

# Holds components of {VERSION} as defined by {http://semver.org/spec/v2.0.0.html semantic versioning v2.0.0}.
module Version
# The major version number.
MAJOR = 0
# The minor version number, scoped to the {MAJOR} version number.
MINOR = 0
# The patch number, scoped to the {MINOR} version number.
PATCH = 1

PRERELEASE = 'semver'

# The full version string, including the {MAJOR}, {MINOR}, {PATCH}, and optionally, the {PRERELEASE} in the
# {http://semver.org/spec/v2.0.0.html semantic versioning v2.0.0} format.
#
# @return [String] '{MAJOR}.{MINOR}.{PATCH}' on master. '{MAJOR}.{MINOR}.{PATCH}-{PRERELEASE}' on any branch
# other than master.
def self.full
version = "#{MAJOR}.#{MINOR}.#{PATCH}"

if defined? PRERELEASE
version = "#{version}-#{PRERELEASE}"
end

version
end

# The full gem version string, including the {MAJOR}, {MINOR}, {PATCH}, and optionally, the {PRERELEASE} in the
# {http://guides.rubygems.org/specification-reference/#version RubyGems versioning} format.
#
# @return [String] '{MAJOR}.{MINOR}.{PATCH}' on master. '{MAJOR}.{MINOR}.{PATCH}.{PRERELEASE}' on any branch
# other than master.
def self.gem
full.gsub('-', '.pre.')
end
end

# @see Version.gem
GEM_VERSION = Version.gem

# @see Version.full
VERSION = Version.full
end
4 changes: 2 additions & 2 deletions smb2.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'smb2/version'

Gem::Specification.new do |spec|
spec.name = "smb2"
spec.version = Smb2::VERSION
spec.version = Smb2::GEM_VERSION
spec.authors = ["James Lee"]
spec.email = ["[email protected]"]
spec.summary = %q{A message creator and parser for the SMB2 protocol}
Expand All @@ -28,7 +28,7 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "fivemat"
spec.add_development_dependency "mocksocket"
spec.add_development_dependency "metasploit-version"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "simplecov"
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/smb2/version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'spec_helper'

describe Smb2::Version do
it_should_behave_like 'Metasploit::Version Version Module'
end

6 changes: 6 additions & 0 deletions spec/lib/smb2_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'spec_helper'

describe Smb2 do
it_should_behave_like 'Metasploit::Version VERSION constant'
it_should_behave_like 'Metasploit::Version GEM_VERSION constant'
end
7 changes: 7 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Use find_all_by_name instead of find_by_name as find_all_by_name will return pre-release versions
gem_specification = Gem::Specification.find_all_by_name('metasploit-version').first

Dir[File.join(gem_specification.gem_dir, 'spec', 'support', '**', '*.rb')].each do |f|
require f
end