htauth 1.0.3 → 1.1.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 +15 -0
- data/CONTRIBUTING.md +46 -0
- data/HISTORY.md +36 -0
- data/Manifest.txt +45 -0
- data/{README → README.md} +21 -22
- data/Rakefile +17 -0
- data/bin/htpasswd-ruby +5 -5
- data/lib/htauth/algorithm.rb +1 -8
- data/lib/htauth/crypt.rb +1 -1
- data/lib/htauth/digest.rb +5 -2
- data/lib/htauth/digest_entry.rb +5 -4
- data/lib/htauth/digest_file.rb +1 -1
- data/lib/htauth/errors.rb +10 -0
- data/lib/htauth/file.rb +1 -1
- data/lib/htauth/md5.rb +2 -0
- data/lib/htauth/passwd.rb +10 -4
- data/lib/htauth/passwd_entry.rb +2 -1
- data/lib/htauth/passwd_file.rb +64 -63
- data/lib/htauth/plaintext.rb +12 -11
- data/lib/htauth/version.rb +8 -9
- data/lib/htauth.rb +14 -4
- data/spec/crypt_spec.rb +10 -12
- data/spec/digest_entry_spec.rb +20 -21
- data/spec/digest_file_spec.rb +11 -12
- data/spec/digest_spec.rb +23 -23
- data/spec/md5_spec.rb +2 -2
- data/spec/passwd_entry_spec.rb +47 -48
- data/spec/passwd_file_spec.rb +12 -13
- data/spec/passwd_spec.rb +37 -38
- data/spec/plaintext_spec.rb +4 -7
- data/spec/sha1_spec.rb +3 -5
- data/spec/spec_helper.rb +8 -4
- data/spec/test.add.digest +3 -0
- data/spec/test.add.passwd +3 -0
- data/spec/test.delete.digest +1 -0
- data/spec/test.delete.passwd +1 -0
- data/spec/test.original.digest +2 -0
- data/spec/test.original.passwd +2 -0
- data/spec/test.update.digest +2 -0
- data/spec/test.update.passwd +2 -0
- data/tasks/default.rake +276 -0
- data/tasks/this.rb +214 -0
- metadata +131 -75
- data/HISTORY +0 -26
- data/gemspec.rb +0 -43
- data/tasks/announce.rake +0 -38
- data/tasks/config.rb +0 -98
- data/tasks/distribution.rake +0 -46
- data/tasks/documentation.rake +0 -31
- data/tasks/rspec.rake +0 -29
- data/tasks/rubyforge.rake +0 -59
- data/tasks/utils.rb +0 -80
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTUyZDQ3ZjdhODM0ZGI2ODZkMjA2NzQ3MGVlMzEyN2RlNGQzZjZmOA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
M2I1NTRmMmRhMzE4NzVlMTY2MjI1OGNhMmExNzUzNzE0YjY2MWI1Yw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjBiNzk5NmE4NGM5MGY5OGM1MjU1YWJiMjdiZmZmYTVmYTkyOGY2MDE2OTQ2
|
10
|
+
YmI0ZmU1MGZiNDdiMjE1MzQzZWJmNjY1YWM2OGYxY2EzNWVlZmM1MzE5ZjRj
|
11
|
+
ZWU4NWRmNmVkYWRkYmRhMDgzMjA2MTJjMGM0ZGViMjBmYWQzZTA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OGY5MTIyMTQxYzM1MGVkODk0OGNjMDdiZDkxNWYyMTI1Y2E3NjNhMTZlMTcy
|
14
|
+
MmIyN2FjZDMyMjA0YjIxYmQ0MzE4ZTgzNDI4ZjAxNzk5YWYxMGUyNmJjZGIz
|
15
|
+
NWZjMmM4ZTAzNzYxMTk4NjNiY2Y0Y2U3MDgwNmQ0Y2I2ZDY3YTQ=
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Hi there!
|
2
|
+
|
3
|
+
I see you are interested in contributing. That is wonderful. I love
|
4
|
+
contributions.
|
5
|
+
|
6
|
+
I guarantee that there are bugs in this software. And I guarantee that there is
|
7
|
+
a feature you want that is not in here yet. As such, any and all bugs reports
|
8
|
+
are gratefully accepted, bugfixes even more so. Helping out with bugs is the
|
9
|
+
easiest way to contribute.
|
10
|
+
|
11
|
+
|
12
|
+
## The Quick Version
|
13
|
+
|
14
|
+
* Have a [GitHub Account][].
|
15
|
+
* Search the [GitHub Issues][] and see if your issue already present. If so
|
16
|
+
add your comments, :thumbsup:, etc.
|
17
|
+
* Issue not there? Not a problem, open up a [new issue][].
|
18
|
+
* **Bug reports** please be as detailed as possible. Include:
|
19
|
+
* full ruby engine and version: `ruby -e 'puts RUBY_DESCRIPTION'`
|
20
|
+
* operating system and version
|
21
|
+
* version of htauth `ruby -rubygems -e "require 'htauth'; puts htauth::VERSION"`
|
22
|
+
* as much detail about the bug as possible so I can replicate it. Feel free
|
23
|
+
to link in a [gist][]
|
24
|
+
* **New Feature**
|
25
|
+
* What the new feature should do.
|
26
|
+
* What benefit the new feature brings to the project.
|
27
|
+
* Fork the [repo][].
|
28
|
+
* Create a new branch for your issue: `git checkout -b issue/my-issue`
|
29
|
+
* Lovingly craft your contribution:
|
30
|
+
* `rake develop` to get started, or if you prefer bundler `rake develop:using_bundler && bundle`.
|
31
|
+
* `rake test` to run tests
|
32
|
+
* Make sure that `rake test` passes. It's important, I said it twice.
|
33
|
+
* Add yourself to the contributors section below.
|
34
|
+
* Submit your [pull request][].
|
35
|
+
|
36
|
+
# Contributors
|
37
|
+
|
38
|
+
* [Jeremy Hinegardner](https://github.com/copiousfreetime)
|
39
|
+
* [Kevin Barnes](https://github.com/vinbarnes)
|
40
|
+
|
41
|
+
[GitHub Account]: https://github.com/signup/free "GitHub Signup"
|
42
|
+
[GitHub Issues]: https://github.com/copiousfreetime/htauth/issues "Htauth Issues"
|
43
|
+
[new issue]: https://github.com/copiousfreetime/htauth/issues/new "New Htauth Issue"
|
44
|
+
[gist]: https://gist.github.com/ "New Gist"
|
45
|
+
[repo]: https://github.com/copiousfreetime/htauth "htauth Repo"
|
46
|
+
[pull request]: https://help.github.com/articles/using-pull-requests "Using Pull Requests"
|
data/HISTORY.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## Version 1.1.0 2014-03-10
|
4
|
+
|
5
|
+
* Update highline dependency
|
6
|
+
* Change the default algorithm in htpasswd-ruby to be MD5
|
7
|
+
* Convert tests to minitest
|
8
|
+
* Update to [fixme](http://github.com/copiousfreetime/fixme) project structure
|
9
|
+
* General update to ruby 1.9/2.0
|
10
|
+
* Fix all -w warnings
|
11
|
+
|
12
|
+
## Version 1.0.3 2008-12-20
|
13
|
+
|
14
|
+
* update highline dependency
|
15
|
+
|
16
|
+
## Version 1.0.2 2008-11-30
|
17
|
+
|
18
|
+
### Minor enhancement
|
19
|
+
|
20
|
+
* Change project layout
|
21
|
+
|
22
|
+
## Version 1.0.1 2008-02-06
|
23
|
+
|
24
|
+
### Bugfixes
|
25
|
+
|
26
|
+
* fix require dependency chain
|
27
|
+
* fix gem dependency on rake
|
28
|
+
|
29
|
+
## Version 1.0.0 2008-02-05
|
30
|
+
|
31
|
+
* Initial public release
|
32
|
+
|
33
|
+
### Release Notes
|
34
|
+
|
35
|
+
* Look at 'htpasswd-ruby' and 'htdigest-ruby' to get started.
|
36
|
+
|
data/Manifest.txt
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
CONTRIBUTING.md
|
2
|
+
HISTORY.md
|
3
|
+
LICENSE
|
4
|
+
Manifest.txt
|
5
|
+
README.md
|
6
|
+
Rakefile
|
7
|
+
bin/htdigest-ruby
|
8
|
+
bin/htpasswd-ruby
|
9
|
+
lib/htauth.rb
|
10
|
+
lib/htauth/algorithm.rb
|
11
|
+
lib/htauth/crypt.rb
|
12
|
+
lib/htauth/digest.rb
|
13
|
+
lib/htauth/digest_entry.rb
|
14
|
+
lib/htauth/digest_file.rb
|
15
|
+
lib/htauth/entry.rb
|
16
|
+
lib/htauth/errors.rb
|
17
|
+
lib/htauth/file.rb
|
18
|
+
lib/htauth/md5.rb
|
19
|
+
lib/htauth/passwd.rb
|
20
|
+
lib/htauth/passwd_entry.rb
|
21
|
+
lib/htauth/passwd_file.rb
|
22
|
+
lib/htauth/plaintext.rb
|
23
|
+
lib/htauth/sha1.rb
|
24
|
+
lib/htauth/version.rb
|
25
|
+
spec/crypt_spec.rb
|
26
|
+
spec/digest_entry_spec.rb
|
27
|
+
spec/digest_file_spec.rb
|
28
|
+
spec/digest_spec.rb
|
29
|
+
spec/md5_spec.rb
|
30
|
+
spec/passwd_entry_spec.rb
|
31
|
+
spec/passwd_file_spec.rb
|
32
|
+
spec/passwd_spec.rb
|
33
|
+
spec/plaintext_spec.rb
|
34
|
+
spec/sha1_spec.rb
|
35
|
+
spec/spec_helper.rb
|
36
|
+
spec/test.add.digest
|
37
|
+
spec/test.add.passwd
|
38
|
+
spec/test.delete.digest
|
39
|
+
spec/test.delete.passwd
|
40
|
+
spec/test.original.digest
|
41
|
+
spec/test.original.passwd
|
42
|
+
spec/test.update.digest
|
43
|
+
spec/test.update.passwd
|
44
|
+
tasks/default.rake
|
45
|
+
tasks/this.rb
|
data/{README → README.md}
RENAMED
@@ -1,21 +1,20 @@
|
|
1
|
-
|
1
|
+
## HTAuth
|
2
2
|
|
3
|
-
* Homepage
|
4
|
-
*
|
5
|
-
* Github[http://github.com/copiousfreetime/htauth/tree/master]
|
3
|
+
* [Homepage](http://copiousfreetime.rubyforge.org/htauth)
|
4
|
+
* [Github](http://github.com/copiousfreetime/htauth/tree/master)
|
6
5
|
* email jeremy at copiousfreetime dot org
|
7
6
|
|
8
|
-
|
7
|
+
## DESCRIPTION
|
9
8
|
|
10
9
|
HTAuth is a pure ruby replacement for the Apache support programs htdigest and
|
11
10
|
htpasswd. Command line and API access are provided for access to htdigest and
|
12
11
|
htpasswd files.
|
13
12
|
|
14
|
-
|
13
|
+
## FEATURES
|
15
14
|
|
16
15
|
HTAuth provides to drop in commands *htdigest-ruby* and *htpasswd-ruby* that
|
17
16
|
can manipulate the digest and passwd files in the same manner as Apache's
|
18
|
-
original commands.
|
17
|
+
original commands.
|
19
18
|
|
20
19
|
*htdigest-ruby* and *htpasswd-ruby* are command line compatible with *htdigest*
|
21
20
|
and *htpasswd*. They support the same exact same command line options as the
|
@@ -24,11 +23,12 @@ originals, and have some extras.
|
|
24
23
|
Additionally, you can access all the functionality of *htdigest-ruby* and
|
25
24
|
*htpasswd-ruby* through an API.
|
26
25
|
|
27
|
-
|
26
|
+
## SYNOPSIS
|
28
27
|
|
29
|
-
|
28
|
+
### htpasswd-ruby command line application
|
30
29
|
|
31
|
-
|
30
|
+
|
31
|
+
Usage:
|
32
32
|
htpasswd-ruby [-cmdpsD] passwordfile username
|
33
33
|
htpasswd-ruby -b[cmdpsD] passwordfile username password
|
34
34
|
|
@@ -46,7 +46,7 @@ Additionally, you can access all the functionality of *htdigest-ruby* and
|
|
46
46
|
-s, --sha1 Force SHA encryption of the password.
|
47
47
|
-v, --version Show version info.
|
48
48
|
|
49
|
-
|
49
|
+
### htdigest-ruby command line application
|
50
50
|
|
51
51
|
Usage: htdigest-ruby [options] passwordfile realm username
|
52
52
|
-c, --create Create a new digest password file; this overwrites an existing file.
|
@@ -54,25 +54,24 @@ Additionally, you can access all the functionality of *htdigest-ruby* and
|
|
54
54
|
-h, --help Display this help.
|
55
55
|
-v, --version Show version info.
|
56
56
|
|
57
|
-
|
57
|
+
### API Usage
|
58
58
|
|
59
|
-
|
59
|
+
HTAuth::DigestFile.open("some.htdigest") do |df|
|
60
60
|
df.add_or_update('someuser', 'myrealm', 'a password')
|
61
61
|
df.delete('someolduser', 'myotherrealm')
|
62
|
-
|
62
|
+
end
|
63
63
|
|
64
|
-
|
64
|
+
HTAuth::PasswdFile.open("some.htpasswd", HTAuth::File::CREATE) do |pf|
|
65
65
|
pf.add('someuser', 'a password', 'md5')
|
66
66
|
pf.add('someotheruser', 'a different password', 'sha1')
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
== CREDITS
|
67
|
+
end
|
68
|
+
|
69
|
+
## CREDITS
|
71
70
|
|
72
|
-
*
|
73
|
-
* all the folks who contributed to htdigest and htpassword
|
71
|
+
* [The Apache Software Foundation](http://www.apache.org/)
|
72
|
+
* all the folks who contributed to htdigest and htpassword
|
74
73
|
|
75
|
-
|
74
|
+
## LICENSE
|
76
75
|
|
77
76
|
Copyright (c) 2008 Jeremy Hinegardner
|
78
77
|
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# vim: syntax=ruby
|
2
|
+
load 'tasks/this.rb'
|
3
|
+
|
4
|
+
This.name = "htauth"
|
5
|
+
This.author = "Jeremy Hinegardner"
|
6
|
+
This.email = "jeremy@copiousfreetime.org"
|
7
|
+
This.homepage = "http://github.com/copiousfreetime/#{ This.name }"
|
8
|
+
|
9
|
+
This.ruby_gemspec do |spec|
|
10
|
+
spec.add_development_dependency( 'rake' , '~> 10.1')
|
11
|
+
spec.add_development_dependency( 'minitest' , '~> 5.0' )
|
12
|
+
spec.add_development_dependency( 'rdoc' , '~> 4.0' )
|
13
|
+
|
14
|
+
spec.add_dependency("highline", "~> 1.6")
|
15
|
+
end
|
16
|
+
|
17
|
+
load 'tasks/default.rake'
|
data/bin/htpasswd-ruby
CHANGED
@@ -8,12 +8,12 @@ rescue LoadError
|
|
8
8
|
end
|
9
9
|
|
10
10
|
begin
|
11
|
-
|
11
|
+
require 'htauth'
|
12
12
|
rescue LoadError
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
path = File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
|
14
|
+
raise if $:.include?(path)
|
15
|
+
$: << path
|
16
|
+
retry
|
17
17
|
end
|
18
18
|
|
19
19
|
HTAuth::Passwd.new.run(ARGV, ENV)
|
data/lib/htauth/algorithm.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
require 'htauth'
|
2
|
-
|
3
1
|
module HTAuth
|
4
2
|
class InvalidAlgorithmError < StandardError ; end
|
5
3
|
# base class all the Passwd algorithms derive from
|
6
4
|
class Algorithm
|
7
5
|
|
8
6
|
SALT_CHARS = (%w[ . / ] + ("0".."9").to_a + ('A'..'Z').to_a + ('a'..'z').to_a).freeze
|
9
|
-
DEFAULT =
|
7
|
+
DEFAULT = "md5"
|
10
8
|
EXISTING = "existing"
|
11
9
|
|
12
10
|
class << self
|
@@ -62,8 +60,3 @@ module HTAuth
|
|
62
60
|
end
|
63
61
|
end
|
64
62
|
end
|
65
|
-
|
66
|
-
require 'htauth/md5'
|
67
|
-
require 'htauth/sha1'
|
68
|
-
require 'htauth/crypt'
|
69
|
-
require 'htauth/plaintext'
|
data/lib/htauth/crypt.rb
CHANGED
data/lib/htauth/digest.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require 'htauth'
|
1
|
+
require 'htauth/version'
|
2
|
+
require 'htauth/errors'
|
2
3
|
require 'htauth/digest_file'
|
3
4
|
|
4
5
|
require 'ostruct'
|
@@ -15,6 +16,8 @@ module HTAuth
|
|
15
16
|
|
16
17
|
def initialize
|
17
18
|
@digest_file = nil
|
19
|
+
@option_parser = nil
|
20
|
+
@options = nil
|
18
21
|
end
|
19
22
|
|
20
23
|
def options
|
@@ -120,7 +123,7 @@ module HTAuth
|
|
120
123
|
exit 1
|
121
124
|
rescue SignalException => se
|
122
125
|
$stderr.puts
|
123
|
-
$stderr.puts "Interrupted"
|
126
|
+
$stderr.puts "Interrupted #{se}"
|
124
127
|
exit 1
|
125
128
|
end
|
126
129
|
exit 0
|
data/lib/htauth/digest_entry.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'htauth/errors'
|
1
2
|
require 'htauth/entry'
|
2
3
|
require 'digest/md5'
|
3
4
|
|
@@ -25,11 +26,11 @@ module HTAuth
|
|
25
26
|
# and the md5sum must be 32 characters long.
|
26
27
|
def is_entry!(line)
|
27
28
|
raise InvalidDigestEntry, "line commented out" if line =~ /\A#/
|
28
|
-
|
29
|
+
parts = line.strip.split(":")
|
29
30
|
raise InvalidDigestEntry, "line must be of the format username:realm:md5checksum" if parts.size != 3
|
30
31
|
raise InvalidDigestEntry, "md5 checksum is not 32 characters long" if parts.last.size != 32
|
31
32
|
raise InvalidDigestEntry, "md5 checksum has invalid characters" if parts.last !~ /\A[[:xdigit:]]{32}\Z/
|
32
|
-
|
33
|
+
return parts
|
33
34
|
end
|
34
35
|
|
35
36
|
# test if a line is an entry and return true or false
|
@@ -63,11 +64,11 @@ module HTAuth
|
|
63
64
|
end
|
64
65
|
|
65
66
|
def key
|
66
|
-
|
67
|
+
"#{user}:#{realm}"
|
67
68
|
end
|
68
69
|
|
69
70
|
def to_s
|
70
|
-
|
71
|
+
"#{user}:#{realm}:#{digest}"
|
71
72
|
end
|
72
73
|
end
|
73
74
|
end
|
data/lib/htauth/digest_file.rb
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
#--
|
2
|
+
# Copyrigth (c) 2008 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details
|
4
|
+
#++
|
5
|
+
|
6
|
+
module HTAuth
|
7
|
+
class FileAccessError < StandardError ; end
|
8
|
+
class TempFileError < StandardError ; end
|
9
|
+
class PasswordError < StandardError ; end
|
10
|
+
end
|
data/lib/htauth/file.rb
CHANGED
data/lib/htauth/md5.rb
CHANGED
data/lib/htauth/passwd.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'htauth'
|
1
|
+
require 'htauth/errors'
|
2
2
|
require 'htauth/passwd_file'
|
3
3
|
|
4
4
|
require 'ostruct'
|
@@ -15,6 +15,8 @@ module HTAuth
|
|
15
15
|
|
16
16
|
def initialize
|
17
17
|
@passwd_file = nil
|
18
|
+
@option_parser = nil
|
19
|
+
@options = nil
|
18
20
|
end
|
19
21
|
|
20
22
|
def options
|
@@ -56,7 +58,7 @@ EOB
|
|
56
58
|
options.file_mode = HTAuth::File::CREATE
|
57
59
|
end
|
58
60
|
|
59
|
-
op.on("-d", "--crypt", "Force CRYPT encryption of the password
|
61
|
+
op.on("-d", "--crypt", "Force CRYPT encryption of the password.") do |c|
|
60
62
|
options.algorithm = "crypt"
|
61
63
|
end
|
62
64
|
|
@@ -68,7 +70,7 @@ EOB
|
|
68
70
|
options.show_help = h
|
69
71
|
end
|
70
72
|
|
71
|
-
op.on("-m", "--md5", "Force MD5 encryption of the password (default
|
73
|
+
op.on("-m", "--md5", "Force MD5 encryption of the password (default).") do |m|
|
72
74
|
options.algorithm = "md5"
|
73
75
|
end
|
74
76
|
|
@@ -88,6 +90,10 @@ EOB
|
|
88
90
|
op.on("-v", "--version", "Show version info.") do |v|
|
89
91
|
options.show_version = v
|
90
92
|
end
|
93
|
+
|
94
|
+
op.separator ""
|
95
|
+
|
96
|
+
op.separator "The SHA algorihtm does not use a salt and is less secure than the MD5 algorithm"
|
91
97
|
end
|
92
98
|
end
|
93
99
|
@option_parser
|
@@ -166,7 +172,7 @@ EOB
|
|
166
172
|
exit 1
|
167
173
|
rescue SignalException => se
|
168
174
|
$stderr.puts
|
169
|
-
$stderr.puts "Interrupted"
|
175
|
+
$stderr.puts "Interrupted #{se}"
|
170
176
|
exit 1
|
171
177
|
end
|
172
178
|
exit 0
|
data/lib/htauth/passwd_entry.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'htauth/errors'
|
1
2
|
require 'htauth/entry'
|
2
3
|
require 'htauth/algorithm'
|
3
4
|
|
@@ -25,7 +26,7 @@ module HTAuth
|
|
25
26
|
# where username, and password do not contain the ':' character
|
26
27
|
def is_entry!(line)
|
27
28
|
raise InvalidPasswdEntry, "line commented out" if line =~ /\A#/
|
28
|
-
|
29
|
+
parts = line.strip.split(":")
|
29
30
|
raise InvalidPasswdEntry, "line must be of the format username:pssword" if parts.size != 2
|
30
31
|
return parts
|
31
32
|
end
|
data/lib/htauth/passwd_file.rb
CHANGED
@@ -1,83 +1,84 @@
|
|
1
1
|
require 'stringio'
|
2
2
|
require 'tempfile'
|
3
3
|
|
4
|
+
require 'htauth/errors'
|
4
5
|
require 'htauth/file'
|
5
6
|
require 'htauth/passwd_entry'
|
6
7
|
|
7
8
|
module HTAuth
|
8
|
-
|
9
|
+
class PasswdFileError < StandardError ; end
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
# PasswdFile provides API style access to an +htpasswd+ produced file
|
12
|
+
class PasswdFile < HTAuth::File
|
12
13
|
|
13
|
-
|
14
|
+
ENTRY_KLASS = HTAuth::PasswdEntry
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
# does the entry the the specified username and realm exist in the file
|
17
|
+
def has_entry?(username)
|
18
|
+
test_entry = PasswdEntry.new(username)
|
19
|
+
@entries.has_key?(test_entry.key)
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
# remove an entry from the file
|
23
|
+
def delete(username)
|
24
|
+
if has_entry?(username) then
|
25
|
+
ir = internal_record(username)
|
26
|
+
line_index = ir['line_index']
|
27
|
+
@entries.delete(ir['entry'].key)
|
28
|
+
@lines[line_index] = nil
|
29
|
+
dirty!
|
30
|
+
end
|
31
|
+
nil
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
34
|
+
# add or update an entry as appropriate
|
35
|
+
def add_or_update(username, password, algorithm = Algorithm::DEFAULT)
|
36
|
+
if has_entry?(username) then
|
37
|
+
update(username, password, algorithm)
|
38
|
+
else
|
39
|
+
add(username, password, algorithm)
|
40
|
+
end
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
43
|
+
# add an new record. raises an error if the entry exists.
|
44
|
+
def add(username, password, algorithm = Algorithm::DEFAULT)
|
45
|
+
raise PasswdFileError, "Unable to add already existing user #{username}" if has_entry?(username)
|
46
|
+
new_entry = PasswdEntry.new(username, password, algorithm)
|
47
|
+
new_index = @lines.size
|
48
|
+
@lines << new_entry.to_s
|
49
|
+
@entries[new_entry.key] = { 'entry' => new_entry, 'line_index' => new_index }
|
50
|
+
dirty!
|
51
|
+
return nil
|
52
|
+
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
54
|
+
# update an already existing entry with a new password. raises an error if the entry does not exist
|
55
|
+
def update(username, password, algorithm = Algorithm::EXISTING)
|
56
|
+
raise PasswdFileError, "Unable to update non-existent user #{username}" unless has_entry?(username)
|
57
|
+
ir = internal_record(username)
|
58
|
+
ir['entry'].algorithm = algorithm
|
59
|
+
ir['entry'].password = password
|
60
|
+
@lines[ir['line_index']] = ir['entry'].to_s
|
61
|
+
dirty!
|
62
|
+
return nil
|
63
|
+
end
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
65
|
+
# fetches a copy of an entry from the file. Updateing the entry returned from fetch will NOT
|
66
|
+
# propogate back to the file.
|
67
|
+
def fetch(username)
|
68
|
+
return nil unless has_entry?(username)
|
69
|
+
ir = internal_record(username)
|
70
|
+
return ir['entry'].dup
|
71
|
+
end
|
71
72
|
|
72
|
-
|
73
|
-
|
74
|
-
|
73
|
+
def entry_klass
|
74
|
+
ENTRY_KLASS
|
75
|
+
end
|
75
76
|
|
76
|
-
|
77
|
+
private
|
77
78
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
end
|
79
|
+
def internal_record(username)
|
80
|
+
e = PasswdEntry.new(username)
|
81
|
+
@entries[e.key]
|
82
82
|
end
|
83
|
+
end
|
83
84
|
end
|
data/lib/htauth/plaintext.rb
CHANGED
@@ -2,17 +2,18 @@ require 'htauth/algorithm'
|
|
2
2
|
|
3
3
|
module HTAuth
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
# the plaintext algorithm, which does absolutly nothing
|
6
|
+
class Plaintext < Algorithm
|
7
|
+
# ignore parameters
|
8
|
+
def initialize(params = {})
|
9
|
+
end
|
10
|
+
|
11
|
+
def prefix
|
12
|
+
""
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
end
|
15
|
+
def encode(password)
|
16
|
+
"#{password}"
|
17
17
|
end
|
18
|
+
end
|
18
19
|
end
|