rubylibcrack 0.1.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,10 @@ A Ruby binding to the password strength checker, libcrack/cracklib.
11
11
  == FEATURES/PROBLEMS:
12
12
 
13
13
  A very simple password class with methods, weak? and strong? to check a password.
14
- A suitable message is provided if the password is weak.
14
+ A suitable message is provided if the password is weak. You can pass a path to
15
+ a dictionary, but the gem will try to find a default too.
16
+
17
+ Tested on Ruby 1.8, Ruby 1.9 and JRuby 1.2.
15
18
 
16
19
  == SYNOPSIS:
17
20
 
@@ -21,10 +24,12 @@ Usage:
21
24
  => true
22
25
  >> require "rubylibcrack"
23
26
  => true
24
- >> my_password = Password.new("hello001")
27
+ >> my_password = Cracklib::Password.new("hello001")
25
28
  => "hello001"
26
29
  >> my_password.strong?
27
30
  => false
31
+ >> my_password.strong?("/usr/share/cracklib/pw_dict")
32
+ => false
28
33
  >> my_password.message
29
34
  => "it is based on a dictionary word"
30
35
 
@@ -34,6 +39,7 @@ Usage:
34
39
  - Gentoo will have these if cracklib is installed
35
40
  - Redhat and Fedora will require cracklib-devel
36
41
  - Ubuntu will require cracklib-devel
42
+ * FFI
37
43
 
38
44
  == INSTALL:
39
45
 
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'ffi'
3
+
4
+ module Cracklib
5
+ class Password
6
+ attr_reader :message
7
+
8
+ extend FFI::Library
9
+ ffi_lib "crack"
10
+ attach_function :check, "FascistCheck", [ :string, :string ], :string
11
+ POTENTIAL_DICT_PATHS = %w(/usr/share/cracklib/pw_dict /usr/lib/cracklib_dict /usr/lib64/cracklib_dict /var/cache/cracklib/cracklib_dict)
12
+ @@dictpath = ""
13
+
14
+ def initialize(password)
15
+ @password = password
16
+ end
17
+
18
+ def strong?(dictpath = default_dictpath)
19
+ if not valid_dictpath? dictpath
20
+ raise "#{dictpath} is not a valid dictionary path!"
21
+ end
22
+ begin
23
+ @message = check(@password, dictpath)
24
+ return @message.nil?
25
+ rescue
26
+ return true
27
+ end
28
+ return false
29
+ end
30
+
31
+ def weak?(dictpath = default_dictpath)
32
+ not strong? dictpath
33
+ end
34
+
35
+ protected
36
+
37
+ def default_dictpath
38
+ if @@dictpath.empty?
39
+ POTENTIAL_DICT_PATHS.each do |path|
40
+ if valid_dictpath? path
41
+ @@dictpath = path
42
+ break
43
+ end
44
+ end
45
+ end
46
+ @@dictpath
47
+ end
48
+
49
+ def valid_dictpath?(dictpath)
50
+ if File.exists? dictpath+'.hwm' and File.exists? dictpath+'.pwi' and File.exists? dictpath+'.pwd'
51
+ true
52
+ else
53
+ false
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,21 +1,16 @@
1
1
  require "test/unit"
2
- unless File.exist?(File.dirname(__FILE__)+"/../ext/rubylibcrack.so")
3
- puts "You must build the extension before running these tests. The rake task :test calls the :build_extension task and does all this for you."
4
- puts 'Alternatively, you can run this command: "cd ext; ruby extconf.rb; make; cd ../"'
5
- exit 0
6
- end
7
- require File.dirname(__FILE__)+"/../ext/rubylibcrack"
2
+ require File.dirname(__FILE__)+"/../lib/rubylibcrack"
8
3
 
9
4
  class PasswordTest < Test::Unit::TestCase
10
5
  def test_password
11
- poor_password = Password.new("hello")
12
- assert_kind_of Password, poor_password
6
+ poor_password = Cracklib::Password.new("hello")
7
+ assert_kind_of Cracklib::Password, poor_password
13
8
  assert !poor_password.strong?
14
9
  assert poor_password.weak?
15
10
  assert_not_nil poor_password.message
16
11
 
17
- good_password = Password.new("jUY d3 i5 gr38")
18
- assert_kind_of Password, good_password
12
+ good_password = Cracklib::Password.new("jUY d3 i5 gr38")
13
+ assert_kind_of Cracklib::Password, good_password
19
14
  assert good_password.strong?
20
15
  assert !good_password.weak?
21
16
  assert_nil good_password.message
metadata CHANGED
@@ -1,53 +1,77 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: rubylibcrack
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2007-12-28 00:00:00 +00:00
8
- summary: A Ruby binding to the password strength checker, libcrack/cracklib.
9
- require_paths:
10
- - ext
11
- email: rubyforge@scottishclimbs.com
12
- homepage: http://mark.scottishclimbs.com/ (http://www.pccl.info/)
13
- rubyforge_project: rubylibcrack
14
- description: A Ruby binding to the password strength checker, libcrack/cracklib.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ version: "0.2"
25
9
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
10
  authors:
30
- - Mark Somerville (on behalf of Purchasing Card Consultancy limited)
11
+ - Mark Somerville
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-11-18 00:00:00 +00:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: ffi
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ description:
33
+ email: mark@scottishclimbs.com
34
+ executables: []
35
+
36
+ extensions: []
37
+
38
+ extra_rdoc_files:
39
+ - README
31
40
  files:
32
- - ext/rubylibcrack.c
33
- - Rakefile
34
- - History.txt
35
- - Manifest.txt
36
- - README.txt
37
- test_files:
41
+ - lib/rubylibcrack.rb
38
42
  - test/test_rubylibcrack.rb
39
- rdoc_options:
40
- - --main
41
- - README.txt
42
- extra_rdoc_files:
43
- - History.txt
44
- - Manifest.txt
45
- - README.txt
46
- executables: []
43
+ - README
44
+ has_rdoc: true
45
+ homepage: http://mark.scottishclimbs.com/
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options: []
47
50
 
48
- extensions:
49
- - ext/extconf.rb
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
50
69
  requirements: []
51
70
 
52
- dependencies: []
71
+ rubyforge_project: rubylibcrack
72
+ rubygems_version: 1.3.7
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: A binding to the *nix password strength checking library, libcrack/cracklib.
76
+ test_files: []
53
77
 
data/History.txt DELETED
@@ -1,7 +0,0 @@
1
- == 0.1.0 / 2007-08-07
2
-
3
- * Initial release.
4
-
5
- == 0.1.1 / 2007-08-07
6
-
7
- * Removed that damn Hoe dependency (I hate that).
data/Manifest.txt DELETED
@@ -1,13 +0,0 @@
1
- History.txt
2
-
3
- Manifest.txt
4
-
5
- README.txt
6
-
7
- Rakefile
8
-
9
- test/test_rubylibcrack.rb
10
-
11
- ext/rubylibcrack.c
12
-
13
- ext/extconf.rb
data/Rakefile DELETED
@@ -1,37 +0,0 @@
1
- require 'rubygems'
2
- require 'hoe'
3
-
4
- class Hoe
5
- def extra_deps
6
- @extra_deps.reject do |x|
7
- Array(x).first == 'hoe'
8
- end
9
- end
10
- end
11
-
12
- Hoe.new('rubylibcrack', "0.1.1") do |p|
13
- p.rubyforge_name = 'rubylibcrack'
14
- p.author = p.paragraphs_of('README.txt', 1..1).to_s.strip.sub("By: ", "")
15
- p.email = 'rubyforge@scottishclimbs.com'
16
- p.summary = p.paragraphs_of('README.txt', 3).to_s.sub("== DESCRIPTION:", "")
17
- p.description = p.paragraphs_of('README.txt', 3).to_s.sub("== DESCRIPTION:", "")
18
- p.url = p.paragraphs_of('README.txt', 2..2).to_s.strip.sub("URL: ", "")
19
- p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
20
- p.spec_extras["files"] = [ "ext/rubylibcrack.c", "Rakefile" ]
21
- p.spec_extras["extensions"] = "ext/extconf.rb"
22
- end
23
-
24
- desc "Builds the extension"
25
- task :build_extension do
26
- system "cd ext; ruby extconf.rb; make; cd ../"
27
- end
28
-
29
- desc "Cleans the files compiled by build_extension"
30
- task :clean_extension do
31
- system "cd ext; rm dictconfig.h rubylibcrack.so rubylibcrack.o Makefile; cd ../"
32
- end
33
-
34
- desc "Run the unit tests"
35
- task :test => [ :build_extension ] do
36
- Rake::Task[ :clean_extension ].invoke
37
- end
data/ext/extconf.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'mkmf'
2
- File.open(File.dirname(__FILE__)+'/dictconfig.h', "a") do |dictconfig|
3
- dictconfig << '#define DICTPATH "/usr/lib64/cracklib_dict"'
4
- dictconfig << "\n"
5
- end
6
- $libs = append_library($libs, "crack")
7
- create_makefile('rubylibcrack')
data/ext/rubylibcrack.c DELETED
@@ -1,49 +0,0 @@
1
- #include <ruby.h>
2
- #include <crack.h>
3
- #include "dictconfig.h"
4
-
5
- /*
6
- * Runs FascistCheck and returns if the password is regarded as weak or not.
7
- * If it is, the class variable @message is set to the value of the error message.
8
- */
9
- static VALUE t_weak(VALUE self)
10
- {
11
- char *failure_message;
12
- failure_message = (char *) FascistCheck(STR2CSTR(self), DICTPATH);
13
- if(failure_message)
14
- {
15
- rb_iv_set(self, "@message", rb_str_new2(failure_message));
16
- return Qtrue;
17
- }
18
- else
19
- {
20
- return Qfalse;
21
- }
22
- }
23
-
24
- /*
25
- * Runs FascistCheck and returns if the password is regarded as strong or not.
26
- * If it isn't, the class variable @message is set to the value of the error message.
27
- */
28
- static VALUE t_strong(VALUE self)
29
- {
30
- VALUE weak;
31
- weak = t_weak(self);
32
- if(weak == Qtrue)
33
- {
34
- return Qfalse;
35
- }
36
- else
37
- {
38
- return Qtrue;
39
- }
40
- }
41
-
42
- VALUE cPassword;
43
-
44
- void Init_rubylibcrack() {
45
- cPassword = rb_define_class("Password", rb_cString);
46
- rb_define_attr(cPassword, "message", 1, 0);
47
- rb_define_method(cPassword, "weak?", t_weak, 0);
48
- rb_define_method(cPassword, "strong?", t_strong, 0);
49
- }