Compare commits

...

59 Commits

Author SHA1 Message Date
Joe Vennix ec0153a83c Rollback rails to 3.2.2 to fix asset pipeline issues. 2012-06-06 11:22:01 -05:00
Joe Vennix c556a7e6be Rollback activerecord to 3.2.2 to prevent asset inclusion issues. 2012-06-06 11:21:52 -05:00
Tod Beardsley b504b23d2d msftidy found EOL spaces on new modules 2012-06-06 10:40:56 -05:00
Tod Beardsley 524ce94ecd Merge branch 'release' of github_r7:rapid7/metasploit-framework into release 2012-06-05 10:14:46 -05:00
HD Moore 7d07722767 Straighten out the login error path for nexpose API calls 2012-06-04 16:07:21 -05:00
Steve Tornio be00eff5b6 Adding swtornio's OSVDB ref
Watch the trailing commas, that wangs up Ruby 1.8.7 and prior.

Squashed commit of the following:

commit c00363993a726cd0c87fbaee769c44f680feff72
Author: Tod Beardsley <todb@metasploit.com>
Date:   Mon Jun 4 09:33:18 2012 -0500

    Removing trailing comma

commit 594cae0cab
Author: Steve Tornio <swtornio@gmail.com>
Date:   Mon Jun 4 09:10:36 2012 -0500

    add osvdb ref
2012-06-04 16:07:21 -05:00
jvazquez-r7 00927eec85 Use of TARGETURI 2012-06-04 16:07:21 -05:00
jvazquez-r7 097dca22bd Verbose messages cleanup 2012-06-04 16:07:20 -05:00
jvazquez-r7 3ceabbd1f2 Fix typo in the URI param 2012-06-04 16:07:20 -05:00
jvazquez-r7 8fef08275d Added module for CVE-2012-0391 2012-06-04 16:07:20 -05:00
sinn3r d9b8c653b7 Change how we handle the password complexity failure 2012-06-04 16:07:20 -05:00
Chris John Riley af5bf45b31 Altered description to include information on the password complexity check
Altered the default password to meet the complexity checks

Note: The complexity checks (even if they fail) don't prevent the payload from running. At this point it only raises an warning and continues on. I can change this if it's more desirable however!
2012-06-04 16:07:20 -05:00
sinn3r 7a8824ab5e Fix typo thanks to juan 2012-06-04 16:07:20 -05:00
Chris John Riley 61e208af37 Added WMIC and complexity checks 2012-06-04 16:07:20 -05:00
Chris John Riley 2080617029 Added WMIC and complexity checks 2012-06-04 16:07:20 -05:00
Christian Mehlmauer 21d76f1589 Adding FireFart's RPORT(80) cleanup
This was tested by creating a resource script to load every changed
module and displaying the options, like so:

````
use auxiliary/admin/2wire/xslt_password_reset
show options
use auxiliary/admin/http/contentkeeper_fileaccess
show options
````

...etc. This was run in both the master branch and FireFart's branch
while spooling out the results of msfconsole, then diffing those
results. All modules loaded successfully, and there were no changes to
the option sets, so it looks like a successful fix.

Thanks FireFart!

Squashed commit of the following:

commit 7c1eea53fe3743f59402e445cf34fab84cf5a4b7
Author: Christian Mehlmauer <FireFart@gmail.com>
Date:   Fri May 25 22:09:42 2012 +0200

    Cleanup Opt::RPORT(80) since it is already registered by Msf::Exploit::Remote::HttpClient
2012-06-04 16:07:20 -05:00
sinn3r 2dda99c5ae Change filename 2012-06-04 16:07:20 -05:00
sinn3r 2258139d3e Correct name 2012-06-04 16:07:20 -05:00
sinn3r bb5a243705 Add CVE-2011-4825 module 2012-06-04 16:07:19 -05:00
Christian Mehlmauer 06c64161f7 Adding FireFart's hashcollision DoS module
Have some minor edits below, looks like it all works now though.

Squashed commit of the following:

commit b7befd4889f12105f36794b1caca316d1691b335
Author: Tod Beardsley <todb@metasploit.com>
Date:   Fri Jun 1 14:31:32 2012 -0500

    Removing ord in favor of unpack.

    Also renaming a 'character' variable to 'c' rather than 'i' which is
    easy to mistake for an Integer counter variable.

commit e80f6a5622df2136bc3557b2385822ba077e6469
Author: Tod Beardsley <todb@metasploit.com>
Date:   Fri Jun 1 14:24:41 2012 -0500

    Cleaning up print msgs

commit 5fd65ed54cb47834dc646fdca8f047fca4b74953
Author: Tod Beardsley <todb@metasploit.com>
Date:   Fri Jun 1 14:19:10 2012 -0500

    Clean up hashcollision_dos description

    Caps, mostly. One sentence I still don't get but it's not really a show
    stopper.

commit bec0ee43dc9078d34a328eb416970cdc446e6430
Author: Christian Mehlmauer <FireFart@gmail.com>
Date:   Thu May 24 19:11:32 2012 +0200

    Removed RPORT, ruby 1.8 safe, no case insensitive check, error handling

commit 20793f0dfd9103c4d7067a71e81212b48318d183
Author: Christian Mehlmauer <FireFart@gmail.com>
Date:   Tue May 22 23:11:53 2012 +0200

    Hashcollision Script (again)
2012-06-04 16:07:19 -05:00
Joe Vennix 2361a529c5 Add fix for counter_cache migration to keep from throwing readonly column error. 2012-06-04 16:07:19 -05:00
Tod Beardsley ad8f14432b Whitespace fix for script-fu module
This is really just to check the GitHub IRC bot thinger.
2012-06-04 16:07:19 -05:00
Joe Vennix 1fc8e8ff96 Add migrations for counter_cache columns to framework. 2012-06-04 16:07:19 -05:00
sinn3r d6a8e7a5f5 Modify the description 2012-06-04 16:07:19 -05:00
jvazquez-r7 87a9fefb3e Added module for CVE-2012-2763 2012-06-04 16:07:19 -05:00
David Maloney 42cd97e834 Bringin in new version of pcanywhere_login 2012-06-04 16:07:19 -05:00
David Maloney e6a53c834b trying to work around wierd git issue 2012-06-04 16:07:19 -05:00
Samuel Huckins 660c41efc6 MDM Update 2012-06-04 16:07:19 -05:00
David Maloney ac6661fadb Fix nil responses 2012-06-04 16:07:18 -05:00
James Lee 2ee620cee4 Whitespace, thanks msftidy.rb! 2012-06-04 16:07:18 -05:00
James Lee e0ce84a6e9 Chdir to TMP before writing files 2012-06-04 16:07:18 -05:00
Samuel Huckins a33c7db47e Now only loading MetasploitDataModels when not already loaded and
contained objects not in namespace
[Story #30430877]
2012-06-04 16:07:18 -05:00
James Lee bbaceffb8b Work around a bug in rubinius 2012-06-04 16:07:18 -05:00
Joe Vennix 84af16a8b4 Updating to Rails 3.2.4.
Among other fixes, this addresses the Rails security advisory
from 5/31/2012:

http://groups.google.com/group/rubyonrails-security/browse_thread/thread/7546a238e1962f59
http://groups.google.com/group/rubyonrails-security/browse_thread/thread/f1203e3376acec0f

Thanks Joe and Trevor!

Squashed commit of the following:

commit d7031cebcc
Author: Joe Vennix <Joe_Vennix@rapid7.com>
Date:   Thu May 31 16:57:29 2012 -0500

    Update activerecord in gemcache to support rails 3.2.4. [#30507689]

commit c7369f6d66
Author: Joe Vennix <Joe_Vennix@rapid7.com>
Date:   Thu May 31 16:53:01 2012 -0500

    Bump rails version.
2012-06-04 16:07:18 -05:00
Tod Beardsley 9a25b10059 Fixing description for citrix module 2012-06-04 16:07:18 -05:00
Tod Beardsley 080a231770 Fixing description for citrix module 2012-06-04 16:07:18 -05:00
Tod Beardsley f5bf954bf1 Fixing description for juan's Citrix module 2012-06-04 16:07:18 -05:00
jvazquez-r7 145747b48e Fixed name module 2012-06-04 16:07:17 -05:00
jvazquez-r7 6ca474e0d9 Citrix Provisioning Services 5.6 SP1 Streamprocess Opcode 0x40020002 Buffer Overflow 2012-06-04 16:07:17 -05:00
jvazquez-r7 4842be014a Added module for Citrix Streamprocess Opcode 0x40020002 Buffer Overflow 2012-06-04 16:07:17 -05:00
jvazquez-r7 df389bcd63 description updated 2012-06-04 16:07:17 -05:00
jvazquez-r7 82aa0185da Added module for ZDI-12-010 2012-06-04 16:07:17 -05:00
HD Moore 60bfe2ba1c Handle cases where a user-agent was set via headers 2012-06-04 16:07:17 -05:00
HD Moore 7e7690e5fb Handle cisco devices better with ssh logins 2012-06-04 16:07:17 -05:00
David Maloney cb4ccd427d Adds thelightcosine's pcanywhere module
Adds PCAnywhere bruteforce capabilities

Squashed commit of the following:

commit 5354fd849f0c009c534d7ce18369382dd56de550
Author: David Maloney <DMaloney@rapid7.com>
Date:   Thu May 31 14:35:23 2012 -0500

    Add explicit pack to encrypted header

commit 7911dd309a94df2729c8247c3817cf5de6b99aad
Author: David Maloney <DMaloney@rapid7.com>
Date:   Thu May 31 13:11:19 2012 -0500

    adds pcanywhere_login module
2012-06-04 16:07:17 -05:00
Steve Tornio 8d460f8343 add osvdb ref 2012-06-04 16:07:17 -05:00
sinn3r 2ea6795e02 Add s40 dir traversal vuln
I can't believe I stayed up all night, and this is all I could find.
2012-06-04 16:07:17 -05:00
Raphael Mudge ea18387d9c Adding rsmudge's Armitage update
Squashed commit of the following:

commit 60be1b2d1d
Author: Raphael Mudge <rsmudge@gmail.com>
Date:   Wed May 30 19:43:07 2012 -0400

    Armitage 05.30.12
    A small collection of bug fixes.
2012-06-04 16:07:17 -05:00
James Lee ff556cdbe1 But not *that* verbose 2012-06-04 16:07:16 -05:00
James Lee 8e46799e7a Make meterpreter test a little more verbose 2012-06-04 16:07:16 -05:00
James Lee f6bda30545 Add cd and pwd to Post::File API
Also changes working dir to /tmp (or %TMP% on Windows) when testing file
stuff.
2012-06-04 16:07:16 -05:00
sinn3r 7bf6431685 Print IP/Port for each message 2012-06-04 16:07:16 -05:00
sinn3r 785407b444 If we don't get a new file, we assume the upload failed. This is
possible when we actually don't have WRITE permission to the
'uploads/' directory.
2012-06-04 16:07:16 -05:00
sinn3r 6f7ab508c9 Don't really care about the return value for the last send_request_raw 2012-06-04 16:07:16 -05:00
sinn3r 0c50f9eac2 Allow the login() function to be a little more verbose for debugging purposes 2012-06-04 16:07:16 -05:00
James Lee 476cfb642d Committing Egypt's README updates
This is all documentation changes -- adds THIRD-PARTY licenses, updates
readme to be more like a readme, and moves the old readme to a COPYING
file.

Note that while this lands pull #388, it skips the Meterpreter changes
that were brought in almost certainly by accident.

Squashed commit of the following:

commit 7125509e8b
Author: James Lee <egypt@metasploit.com>
Date:   Wed May 23 13:12:45 2012 -0600

    Add license info for rkelly and anemone

commit 14367041c3
Author: James Lee <egypt@metasploit.com>
Date:   Wed May 23 12:49:14 2012 -0600

    Add licenses for gemcache stuff to THIRD-PARTY

commit c22138cf24
Author: James Lee <egypt@metasploit.com>
Date:   Mon May 14 17:24:14 2012 -0600

    Add useful links

commit 47a9df3d54
Author: James Lee <egypt@metasploit.com>
Date:   Mon May 14 16:41:21 2012 -0600

    Add copyright notices

commit 687567dfe2
Author: James Lee <egypt@metasploit.com>
Date:   Mon May 14 16:28:17 2012 -0600

    Give THIRD-PARTY an md extension

    Should make display on Github nicer

commit e322676413
Author: James Lee <egypt@metasploit.com>
Date:   Mon May 14 16:22:55 2012 -0600

    Break licenses for bundled stuff into THIRD-PARTY

commit e6463c6e7f
Author: James Lee <egypt@metasploit.com>
Date:   Mon May 14 14:06:01 2012 -0600

    Move README to COPYING

commit 8a6a6bb63f
Author: James Lee <egypt@metasploit.com>
Date:   Mon May 14 12:53:31 2012 -0600

    Better wording.

commit 5ac46d4f68
Author: James Lee <egypt@metasploit.com>
Date:   Mon May 14 12:51:58 2012 -0600

    Add a little more explanitory text to Contributing.

commit 54dab50d98
Author: James Lee <egypt@metasploit.com>
Date:   Mon May 14 12:37:09 2012 -0600

    Missed one

commit e23c80f01e
Author: James Lee <egypt@metasploit.com>
Date:   Mon May 14 12:36:33 2012 -0600

    Better links

commit 47b944ec65
Author: James Lee <egypt@metasploit.com>
Date:   Mon May 14 12:26:12 2012 -0600

    Meh, GFM doesn't like my headings

commit 12a7651e91
Author: James Lee <egypt@metasploit.com>
Date:   Mon May 14 12:24:42 2012 -0600

    Initial stab at a better README

commit e3a0d4731b
Author: James Lee <egypt@metasploit.com>
Date:   Mon May 14 11:59:41 2012 -0600

    LLC -> Inc.

commit 5b32b4245c
Author: James Lee <egypt@metasploit.com>
Date:   Sun May 13 17:50:04 2012 -0600

    Whitespace at EOL

commit e6719f18ab
Author: James Lee <egypt@metasploit.com>
Date:   Sun May 13 17:48:50 2012 -0600

    Only open /dev/null if we need it
2012-06-04 16:07:16 -05:00
sinn3r 7c5ede47f9 Add PHP Volunteer Management System exploit 2012-06-04 16:07:16 -05:00
Tod Beardsley 953c54aab9 Minor updates; added BID, fixed grammar
Modules should not refer to themselves in the first person unless they
are looking for Sarah Connor.
2012-05-30 16:17:01 -05:00
David Maloney 142a1727c9 Revert " Sets the passive flag on the JtR modules"
This reverts commit e70ccddc9a.
2012-05-30 10:14:13 -05:00
153 changed files with 152 additions and 394 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
source 'http://rubygems.org'
gem 'rails', '3.2.4'
gem 'rails', '3.2.2'
gem 'metasploit_data_models', '0.0.2', :git => "git://github.com/rapid7/metasploit_data_models.git"
gem 'pg', '>=0.13'
gem 'msgpack'
@@ -1,43 +1,3 @@
## Rails 3.2.4 (May 31, 2012) ##
* Perf fix: Don't load the records when doing assoc.delete_all.
GH #6289. *Jon Leighton*
* Association preloading shouldn't be affected by the current scoping.
This could cause infinite recursion and potentially other problems.
See GH #5667. *Jon Leighton*
* Datetime attributes are forced to be changed. GH #3965
* Fix attribute casting. GH #5549
* Fix #5667. Preloading should ignore scoping.
* Predicate builder should not recurse for determining where columns.
Thanks to Ben Murphy for reporting this! CVE-2012-2661
## Rails 3.2.3 (March 30, 2012) ##
* Added find_or_create_by_{attribute}! dynamic method. *Andrew White*
* Whitelist all attribute assignment by default. Change the default for newly generated applications to whitelist all attribute assignment. Also update the generated model classes so users are reminded of the importance of attr_accessible. *NZKoz*
* Update ActiveRecord::AttributeMethods#attribute_present? to return false for empty strings. *Jacobkg*
* Fix associations when using per class databases. *larskanis*
* Revert setting NOT NULL constraints in add_timestamps *fxn*
* Fix mysql to use proper text types. Fixes #3931. *kennyj*
* Fix #5069 - Protect foreign key from mass assignment through association builder. *byroot*
## Rails 3.2.2 (March 1, 2012) ##
* No changes.
## Rails 3.2.1 (January 26, 2012) ##
* The threshold for auto EXPLAIN is ignored if there's no logger. *fxn*
@@ -232,8 +192,7 @@
*Brian Durand*
## Rails 3.1.3 (November 20, 2011) ##
## Rails 3.1.3 (unreleased) ##
* Perf fix: If we're deleting all records in an association, don't add a IN(..) clause
to the query. *GH 3672*
@@ -246,8 +205,7 @@
*Christos Zisopoulos and Kenny J*
## Rails 3.1.2 (November 18, 2011) ##
## Rails 3.1.2 (unreleased) ##
* Fix bug with PostgreSQLAdapter#indexes. When the search path has multiple schemas, spaces
were not being stripped from the schema names after the first.
@@ -294,7 +252,6 @@
*Kenny J*
## Rails 3.1.1 (October 7, 2011) ##
* Add deprecation for the preload_associations method. Fixes #3022.
@@ -203,7 +203,7 @@ The latest version of Active Record can be installed with RubyGems:
Source code can be downloaded as part of the Rails project on GitHub
* https://github.com/rails/rails/tree/3-2-stable/activerecord
* https://github.com/rails/rails/tree/master/activerecord
== License

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

@@ -46,7 +46,7 @@ module ActiveRecord
#
# def <=>(other_money)
# if currency == other_money.currency
# amount <=> other_money.amount
# amount <=> amount
# else
# amount <=> other_money.exchange_to(currency).amount
# end
@@ -1513,8 +1513,8 @@ module ActiveRecord
# * <tt>Developer#projects.size</tt>
# * <tt>Developer#projects.find(id)</tt>
# * <tt>Developer#projects.exists?(...)</tt>
# * <tt>Developer#projects.build</tt> (similar to <tt>Project.new("developer_id" => id)</tt>)
# * <tt>Developer#projects.create</tt> (similar to <tt>c = Project.new("developer_id" => id); c.save; c</tt>)
# * <tt>Developer#projects.build</tt> (similar to <tt>Project.new("project_id" => id)</tt>)
# * <tt>Developer#projects.create</tt> (similar to <tt>c = Project.new("project_id" => id); c.save; c</tt>)
# The declaration may include an options hash to specialize the behavior of the association.
#
# === Options
@@ -5,13 +5,12 @@ module ActiveRecord
# Keeps track of table aliases for ActiveRecord::Associations::ClassMethods::JoinDependency and
# ActiveRecord::Associations::ThroughAssociationScope
class AliasTracker # :nodoc:
attr_reader :aliases, :table_joins, :connection
attr_reader :aliases, :table_joins
# table_joins is an array of arel joins which might conflict with the aliases we assign here
def initialize(connection = ActiveRecord::Model.connection, table_joins = [])
def initialize(table_joins = [])
@aliases = Hash.new { |h,k| h[k] = initial_count_for(k) }
@table_joins = table_joins
@connection = connection
end
def aliased_table_for(table_name, aliased_name = nil)
@@ -71,6 +70,10 @@ module ActiveRecord
def truncate(name)
name.slice(0, connection.table_alias_length - 2)
end
def connection
ActiveRecord::Base.connection
end
end
end
end
@@ -231,8 +231,7 @@ module ActiveRecord
def build_record(attributes, options)
reflection.build_association(attributes, options) do |record|
attributes = create_scope.except(*(record.changed - [reflection.foreign_key]))
record.assign_attributes(attributes, :without_protection => true)
record.assign_attributes(create_scope.except(*record.changed), :without_protection => true)
end
end
end
@@ -10,7 +10,7 @@ module ActiveRecord
def initialize(association)
@association = association
@alias_tracker = AliasTracker.new klass.connection
@alias_tracker = AliasTracker.new
end
def scope
@@ -75,7 +75,7 @@ module ActiveRecord
conditions.each do |condition|
if options[:through] && condition.is_a?(Hash)
condition = disambiguate_condition(table, condition)
condition = { table.name => condition }
end
scope = scope.where(interpolate(condition))
@@ -114,21 +114,6 @@ module ActiveRecord
end
end
def disambiguate_condition(table, condition)
if condition.is_a?(Hash)
Hash[
condition.map do |k, v|
if v.is_a?(Hash)
[k, v]
else
[table.table_alias || table.name, { k => v }]
end
end
]
else
condition
end
end
end
end
end
@@ -154,7 +154,7 @@ module ActiveRecord
#
# See delete for more info.
def delete_all
delete(:all).tap do
delete(load_target).tap do
reset
loaded!
end
@@ -226,17 +226,7 @@ module ActiveRecord
# are actually removed from the database, that depends precisely on
# +delete_records+. They are in any case removed from the collection.
def delete(*records)
dependent = options[:dependent]
if records.first == :all
if loaded? || dependent == :destroy
delete_or_destroy(load_target, dependent)
else
delete_records(:all, dependent)
end
else
delete_or_destroy(records, dependent)
end
delete_or_destroy(records, options[:dependent])
end
# Destroy +records+ and remove them from this association calling
@@ -491,8 +481,6 @@ module ActiveRecord
raise RecordNotSaved, "Failed to replace #{reflection.name} because one or more of the " \
"new records could not be saved."
end
target
end
def concat_records(records)
@@ -44,20 +44,13 @@ module ActiveRecord
def delete_records(records, method)
if sql = options[:delete_sql]
records = load_target if records == :all
records.each { |record| owner.connection.delete(interpolate(sql, record)) }
else
relation = join_table
condition = relation[reflection.foreign_key].eq(owner.id)
unless records == :all
condition = condition.and(
relation[reflection.association_foreign_key].
in(records.map { |x| x.id }.compact)
)
end
owner.connection.delete(relation.where(condition).compile_delete)
relation = join_table
stmt = relation.where(relation[reflection.foreign_key].eq(owner.id).
and(relation[reflection.association_foreign_key].in(records.map { |x| x.id }.compact))
).compile_delete
owner.connection.delete stmt
end
end
@@ -89,12 +89,8 @@ module ActiveRecord
records.each { |r| r.destroy }
update_counter(-records.length) unless inverse_updates_counter_cache?
else
if records == :all
scope = scoped
else
keys = records.map { |r| r[reflection.association_primary_key] }
scope = scoped.where(reflection.association_primary_key => keys)
end
keys = records.map { |r| r[reflection.association_primary_key] }
scope = scoped.where(reflection.association_primary_key => keys)
if method == :delete_all
update_counter(-scope.delete_all)
@@ -73,9 +73,7 @@ module ActiveRecord
# association
def build_through_record(record)
@through_records[record.object_id] ||= begin
ensure_mutable
through_record = through_association.build
through_record = through_association.build(construct_join_attributes(record))
through_record.send("#{source_reflection.name}=", record)
through_record
end
@@ -126,10 +124,6 @@ module ActiveRecord
def delete_records(records, method)
ensure_not_nested
# This is unoptimised; it will load all the target records
# even when we just want to delete everything.
records = load_target if records == :all
scope = through_association.scoped.where(construct_join_attributes(*records))
case method
@@ -13,7 +13,7 @@ module ActiveRecord
@join_parts = [JoinBase.new(base)]
@associations = {}
@reflections = []
@alias_tracker = AliasTracker.new(base.connection, joins)
@alias_tracker = AliasTracker.new(joins)
@alias_tracker.aliased_name_for(base.table_name) # Updates the count for base.table_name to 1
build(associations)
end
@@ -77,7 +77,7 @@ module ActiveRecord
# Some databases impose a limit on the number of ids in a list (in Oracle it's 1000)
# Make several smaller queries if necessary or make one query if the adapter supports it
sliced = owner_keys.each_slice(model.connection.in_clause_length || owner_keys.size)
records = sliced.map { |slice| records_for(slice).to_a }.flatten
records = sliced.map { |slice| records_for(slice) }.flatten
end
# Each record may have multiple owners, and vice-versa
@@ -93,8 +93,7 @@ module ActiveRecord
end
def build_scope
scope = klass.unscoped
scope.default_scoped = true
scope = klass.scoped
scope = scope.where(process_conditions(options[:conditions]))
scope = scope.where(process_conditions(preload_options[:conditions]))
@@ -37,7 +37,9 @@ module ActiveRecord
# situation it is more natural for the user to just create or modify their join records
# directly as required.
def construct_join_attributes(*records)
ensure_mutable
if source_reflection.macro != :belongs_to
raise HasManyThroughCantAssociateThroughHasOneOrManyReflection.new(owner, reflection)
end
join_attributes = {
source_reflection.foreign_key =>
@@ -71,12 +73,6 @@ module ActiveRecord
!owner[through_reflection.foreign_key].nil?
end
def ensure_mutable
if source_reflection.macro != :belongs_to
raise HasManyThroughCantAssociateThroughHasOneOrManyReflection.new(owner, reflection)
end
end
def ensure_not_nested
if reflection.nested?
raise HasManyThroughNestedAssociationsAreReadonly.new(owner, reflection)
@@ -64,7 +64,6 @@ module ActiveRecord
return if attribute_methods_generated?
superclass.define_attribute_methods unless self == base_class
super(column_names)
column_names.each { |name| define_external_attribute_method(name) }
@attribute_methods_generated = true
end
end
@@ -213,7 +212,7 @@ module ActiveRecord
# nil nor empty? (the latter only applies to objects that respond to empty?, most notably Strings).
def attribute_present?(attribute)
value = read_attribute(attribute)
!value.nil? && !(value.respond_to?(:empty?) && value.empty?)
!value.nil? || (value.respond_to?(:empty?) && !value.empty?)
end
# Returns the column object for the named attribute.
@@ -67,9 +67,19 @@ module ActiveRecord
# we first define with the __temp__ identifier, and then use alias method to
# rename it to what we want.
def define_method_attribute(attr_name)
cast_code = attribute_cast_code(attr_name)
generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
def __temp__
#{internal_attribute_access_code(attr_name, attribute_cast_code(attr_name))}
#{internal_attribute_access_code(attr_name, cast_code)}
end
alias_method '#{attr_name}', :__temp__
undef_method :__temp__
STR
generated_external_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
def __temp__(v, attributes, attributes_cache, attr_name)
#{external_attribute_access_code(attr_name, cast_code)}
end
alias_method '#{attr_name}', :__temp__
undef_method :__temp__
@@ -77,17 +87,6 @@ module ActiveRecord
end
private
def define_external_attribute_method(attr_name)
generated_external_attribute_methods.module_eval <<-STR, __FILE__, __LINE__ + 1
def __temp__(v, attributes, attributes_cache, attr_name)
#{external_attribute_access_code(attr_name, attribute_cast_code(attr_name))}
end
alias_method '#{attr_name}', :__temp__
undef_method :__temp__
STR
end
def cacheable_column?(column)
attribute_types_cached_by_default.include?(column.type)
end
@@ -43,7 +43,6 @@ module ActiveRecord
end
time = time.in_time_zone rescue nil if time
write_attribute(:#{attr_name}, original_time)
#{attr_name}_will_change!
@attributes_cache["#{attr_name}"] = time
end
EOV
@@ -208,9 +208,6 @@ module ActiveRecord #:nodoc:
# # Now 'Bob' exist and is an 'admin'
# User.find_or_create_by_name('Bob', :age => 40) { |u| u.admin = true }
#
# Adding an exclamation point (!) on to the end of <tt>find_or_create_by_</tt> will
# raise an <tt>ActiveRecord::RecordInvalid</tt> error if the new record is invalid.
#
# Use the <tt>find_or_initialize_by_</tt> finder if you want to return a new record without
# saving it first. Protected attributes won't be set unless they are given in a block.
#
@@ -442,7 +439,7 @@ module ActiveRecord #:nodoc:
if self == ActiveRecord::Base
ActiveRecord::Base
else
connection_handler.retrieve_connection_pool(self) ? self : superclass.arel_engine
connection_handler.connection_pools[name] ? self : superclass.arel_engine
end
end
end
@@ -92,18 +92,13 @@ module ActiveRecord
# #connection can be called any number of times; the connection is
# held in a hash keyed by the thread id.
def connection
synchronize do
@reserved_connections[current_connection_id] ||= checkout
end
@reserved_connections[current_connection_id] ||= checkout
end
# Is there an open connection that is being used for the current thread?
# Check to see if there is an active connection in this connection
# pool.
def active_connection?
synchronize do
@reserved_connections.fetch(current_connection_id) {
return false
}.in_use?
end
active_connections.any?
end
# Signal that the thread is finished with the current connection.
@@ -230,9 +225,8 @@ connection. For example: ActiveRecord::Base.connection.close
# - ConnectionTimeoutError: no connection can be obtained from the pool
# within the timeout period.
def checkout
# Checkout an available connection
synchronize do
waited_time = 0
loop do
conn = @connections.find { |c| c.lease }
@@ -248,25 +242,17 @@ connection. For example: ActiveRecord::Base.connection.close
return conn
end
if waited_time >= @timeout
raise ConnectionTimeoutError, "could not obtain a database connection#{" within #{@timeout} seconds" if @timeout} (waited #{waited_time} seconds). The max pool size is currently #{@size}; consider increasing it."
end
@queue.wait(@timeout)
# Sometimes our wait can end because a connection is available,
# but another thread can snatch it up first. If timeout hasn't
# passed but no connection is avail, looks like that happened --
# loop and wait again, for the time remaining on our timeout.
before_wait = Time.now
@queue.wait( [@timeout - waited_time, 0].max )
waited_time += (Time.now - before_wait)
# Will go away in Rails 4, when we don't clean up
# after leaked connections automatically anymore. Right now, clean
# up after we've returned from a 'wait' if it looks like it's
# needed, then loop and try again.
if(active_connections.size >= @connections.size)
if(active_connections.size < @connections.size)
next
else
clear_stale_cached_connections!
if @size == active_connections.size
raise ConnectionTimeoutError, "could not obtain a database connection#{" within #{@timeout} seconds" if @timeout}. The max pool size is currently #{@size}; consider increasing it."
end
end
end
end
end
@@ -282,29 +268,11 @@ connection. For example: ActiveRecord::Base.connection.close
conn.expire
@queue.signal
end
release conn
end
end
private
def release(conn)
synchronize do
thread_id = nil
if @reserved_connections[current_connection_id] == conn
thread_id = current_connection_id
else
thread_id = @reserved_connections.keys.find { |k|
@reserved_connections[k] == conn
}
end
@reserved_connections.delete thread_id if thread_id
end
end
def new_connection
ActiveRecord::Base.send(spec.adapter_method, spec.config)
end
@@ -376,7 +344,9 @@ connection. For example: ActiveRecord::Base.connection.close
connection_pools.values.any? { |pool| pool.active_connection? }
end
# Returns any connections in use by the current thread back to the pool.
# Returns any connections in use by the current thread back to the pool,
# and also returns connections to the pool cached by threads that are no
# longer alive.
def clear_active_connections!
@connection_pools.each_value {|pool| pool.release_connection }
end
@@ -160,7 +160,7 @@ module ActiveRecord
yield td if block_given?
if options[:force] && table_exists?(table_name)
drop_table(table_name, options)
drop_table(table_name)
end
create_sql = "CREATE#{' TEMPORARY' if options[:temporary]} TABLE "
@@ -252,7 +252,7 @@ module ActiveRecord
end
# Drops a table from the database.
def drop_table(table_name, options = {})
def drop_table(table_name)
execute "DROP TABLE #{quote_table_name(table_name)}"
end
@@ -269,15 +269,7 @@ module ActiveRecord
# remove_column(:suppliers, :qualification)
# remove_columns(:suppliers, :qualification, :experience)
def remove_column(table_name, *column_names)
if column_names.flatten!
message = 'Passing array to remove_columns is deprecated, please use ' +
'multiple arguments, like: `remove_columns(:posts, :foo, :bar)`'
ActiveSupport::Deprecation.warn message, caller
end
columns_for_remove(table_name, *column_names).each do |column_name|
execute "ALTER TABLE #{quote_table_name(table_name)} DROP #{column_name}"
end
columns_for_remove(table_name, *column_names).each {|column_name| execute "ALTER TABLE #{quote_table_name(table_name)} DROP #{column_name}" }
end
alias :remove_columns :remove_column
@@ -516,8 +508,8 @@ module ActiveRecord
# ===== Examples
# add_timestamps(:suppliers)
def add_timestamps(table_name)
add_column table_name, :created_at, :datetime
add_column table_name, :updated_at, :datetime
add_column table_name, :created_at, :datetime, :null => false
add_column table_name, :updated_at, :datetime, :null => false
end
# Removes the timestamp columns (created_at and updated_at) from the table definition.
@@ -54,7 +54,7 @@ module ActiveRecord
define_callbacks :checkout, :checkin
attr_accessor :visitor, :pool
attr_reader :schema_cache, :last_use, :in_use, :logger
attr_reader :schema_cache, :last_use, :in_use
alias :in_use? :in_use
def initialize(connection, logger = nil, pool = nil) #:nodoc:
@@ -484,26 +484,15 @@ module ActiveRecord
# Maps logical Rails types to MySQL-specific data types.
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
case type.to_s
when 'integer'
case limit
when 1; 'tinyint'
when 2; 'smallint'
when 3; 'mediumint'
when nil, 4, 11; 'int(11)' # compatibility with MySQL default
when 5..8; 'bigint'
else raise(ActiveRecordError, "No integer type has byte size #{limit}")
end
when 'text'
case limit
when 0..0xff; 'tinytext'
when nil, 0x100..0xffff; 'text'
when 0x10000..0xffffff; 'mediumtext'
when 0x1000000..0xffffffff; 'longtext'
else raise(ActiveRecordError, "No text type has character length #{limit}")
end
else
super
return super unless type.to_s == 'integer'
case limit
when 1; 'tinyint'
when 2; 'smallint'
when 3; 'mediumint'
when nil, 4, 11; 'int(11)' # compatibility with MySQL default
when 5..8; 'bigint'
else raise(ActiveRecordError, "No integer type has byte size #{limit}")
end
end
@@ -525,7 +514,7 @@ module ActiveRecord
def pk_and_sequence_for(table)
execute_and_free("SHOW CREATE TABLE #{quote_table_name(table)}", 'SCHEMA') do |result|
create_table = each_hash(result).first[:"Create Table"]
if create_table.to_s =~ /PRIMARY KEY\s+(?:USING\s+\w+\s+)?\((.+)\)/
if create_table.to_s =~ /PRIMARY KEY\s+\((.+)\)/
keys = $1.split(",").map { |key| key.gsub(/[`"]/, "") }
keys.length == 1 ? [keys.first, nil] : nil
else
@@ -264,7 +264,7 @@ module ActiveRecord
# increase timeout so mysql server doesn't disconnect us
wait_timeout = @config[:wait_timeout]
wait_timeout = 2147483 unless wait_timeout.is_a?(Fixnum)
wait_timeout = 2592000 unless wait_timeout.is_a?(Fixnum)
variable_assignments << "@@wait_timeout = #{wait_timeout}"
execute("SET #{variable_assignments.join(', ')}", :skip_logging)
@@ -885,7 +885,7 @@ module ActiveRecord
# This should be not be called manually but set in database.yml.
def schema_search_path=(schema_csv)
if schema_csv
execute("SET search_path TO #{schema_csv}", 'SCHEMA')
execute "SET search_path TO #{schema_csv}"
@schema_search_path = schema_csv
end
end
@@ -1067,25 +1067,14 @@ module ActiveRecord
# Maps logical Rails types to PostgreSQL-specific data types.
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
case type.to_s
when 'binary'
# PostgreSQL doesn't support limits on binary (bytea) columns.
# The hard limit is 1Gb, because of a 32-bit size field, and TOAST.
case limit
when nil, 0..0x3fffffff; super(type)
else raise(ActiveRecordError, "No binary type has byte size #{limit}.")
end
when 'integer'
return 'integer' unless limit
case limit
when 1, 2; 'smallint'
when 3, 4; 'integer'
when 5..8; 'bigint'
else raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with precision 0 instead.")
end
else
super
return super unless type.to_s == 'integer'
return 'integer' unless limit
case limit
when 1, 2; 'smallint'
when 3, 4; 'integer'
when 5..8; 'bigint'
else raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with precision 0 instead.")
end
end
@@ -204,7 +204,7 @@ module ActiveRecord
value = super
if column.type == :string && value.encoding == Encoding::ASCII_8BIT
logger.error "Binary data inserted for `string` type on column `#{column.name}`" if logger
@logger.error "Binary data inserted for `string` type on column `#{column.name}`"
value.encode! 'utf-8'
end
value
@@ -407,14 +407,7 @@ module ActiveRecord
def remove_column(table_name, *column_names) #:nodoc:
raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if column_names.empty?
if column_names.flatten!
message = 'Passing array to remove_columns is deprecated, please use ' +
'multiple arguments, like: `remove_columns(:posts, :foo, :bar)`'
ActiveSupport::Deprecation.warn message, caller
end
column_names.each do |column_name|
column_names.flatten.each do |column_name|
alter_table(table_name) do |definition|
definition.columns.delete(definition[column_name])
end
@@ -18,10 +18,6 @@ module ActiveRecord
when /^find_by_([_a-zA-Z]\w*)\!$/
bang = true
names = $1
when /^find_or_create_by_([_a-zA-Z]\w*)\!$/
bang = true
instantiator = :create
names = $1
when /^find_or_(initialize|create)_by_([_a-zA-Z]\w*)$/
instantiator = $1 == 'initialize' ? :new : :create
names = $2
@@ -56,13 +52,5 @@ module ActiveRecord
def bang?
@bang
end
def save_record?
@instantiator == :create
end
def save_method
bang? ? :save! : :save
end
end
end
@@ -419,15 +419,11 @@ module ActiveRecord
cache_for_connection(connection).update(fixtures_map)
end
#--
# TODO:NOTE: in the next version, the __with_new_arity suffix and
# the method with the old arity will be removed.
#++
def self.instantiate_fixtures__with_new_arity(object, fixture_set, load_instances = true) # :nodoc:
def self.instantiate_fixtures(object, fixture_name, fixtures, load_instances = true)
if load_instances
fixture_set.each do |fixture_name, fixture|
fixtures.each do |name, fixture|
begin
object.instance_variable_set "@#{fixture_name}", fixture.find
object.instance_variable_set "@#{name}", fixture.find
rescue FixtureClassNotFound
nil
end
@@ -435,24 +431,9 @@ module ActiveRecord
end
end
# The use with parameters <tt>(object, fixture_set_name, fixture_set, load_instances = true)</tt> is deprecated, +fixture_set_name+ parameter is not used.
# Use as:
#
# instantiate_fixtures(object, fixture_set, load_instances = true)
def self.instantiate_fixtures(object, fixture_set, load_instances = true, rails_3_2_compatibility_argument = true)
unless load_instances == true || load_instances == false
ActiveSupport::Deprecation.warn(
"ActiveRecord::Fixtures.instantiate_fixtures with parameters (object, fixture_set_name, fixture_set, load_instances = true) is deprecated and shall be removed from future releases. Use it with parameters (object, fixture_set, load_instances = true) instead (skip fixture_set_name).",
caller)
fixture_set = load_instances
load_instances = rails_3_2_compatibility_argument
end
instantiate_fixtures__with_new_arity(object, fixture_set, load_instances)
end
def self.instantiate_all_loaded_fixtures(object, load_instances = true)
all_loaded_fixtures.each_value do |fixture_set|
ActiveRecord::Fixtures.instantiate_fixtures(object, fixture_set, load_instances)
all_loaded_fixtures.each do |table_name, fixtures|
ActiveRecord::Fixtures.instantiate_fixtures(object, table_name, fixtures, load_instances)
end
end
@@ -678,6 +659,9 @@ module ActiveRecord
"#{@fixture_path}.yml"
end
def yaml_fixtures_key(path)
::File.basename(@fixture_path).split(".").first
end
end
class Fixture #:nodoc:
@@ -909,8 +893,8 @@ module ActiveRecord
ActiveRecord::Fixtures.instantiate_all_loaded_fixtures(self, load_instances?)
else
raise RuntimeError, 'Load fixtures before instantiating them.' if @loaded_fixtures.nil?
@loaded_fixtures.each_value do |fixture_set|
ActiveRecord::Fixtures.instantiate_fixtures(self, fixture_set, load_instances?)
@loaded_fixtures.each do |fixture_name, fixtures|
ActiveRecord::Fixtures.instantiate_fixtures(self, fixture_name, fixtures, load_instances?)
end
end
end
@@ -90,7 +90,7 @@ module ActiveRecord
end
def add(record)
repository[record.class.symbolized_sti_name][record.id] = record if contain_all_columns?(record)
repository[record.class.symbolized_sti_name][record.id] = record
end
def remove(record)
@@ -104,12 +104,6 @@ module ActiveRecord
def clear
repository.clear
end
private
def contain_all_columns?(record)
(record.class.column_names - record.attribute_names).empty?
end
end
# Reinitialize an Identity Map model object from +coder+.
@@ -63,7 +63,15 @@ module ActiveRecord
record_id = sti_class.primary_key && record[sti_class.primary_key]
if ActiveRecord::IdentityMap.enabled? && record_id
instance = use_identity_map(sti_class, record_id, record)
if (column = sti_class.columns_hash[sti_class.primary_key]) && column.number?
record_id = record_id.to_i
end
if instance = IdentityMap.get(sti_class, record_id)
instance.reinit_with('attributes' => record)
else
instance = sti_class.allocate.init_with('attributes' => record)
IdentityMap.add(instance)
end
else
instance = sti_class.allocate.init_with('attributes' => record)
end
@@ -114,21 +122,6 @@ module ActiveRecord
private
def use_identity_map(sti_class, record_id, record)
if (column = sti_class.columns_hash[sti_class.primary_key]) && column.number?
record_id = record_id.to_i
end
if instance = IdentityMap.get(sti_class, record_id)
instance.reinit_with('attributes' => record)
else
instance = sti_class.allocate.init_with('attributes' => record)
IdentityMap.add(instance)
end
instance
end
def find_sti_class(type_name)
if type_name.blank? || !columns_hash.include?(inheritance_column)
self
@@ -346,24 +346,12 @@ module ActiveRecord
@name = self.class.name
@version = nil
@connection = nil
@reverting = false
end
# instantiate the delegate object after initialize is defined
self.verbose = true
self.delegate = new
def revert
@reverting = true
yield
ensure
@reverting = false
end
def reverting?
@reverting
end
def up
self.class.delegate = self
return unless self.class.respond_to?(:up)
@@ -397,11 +385,9 @@ module ActiveRecord
end
@connection = conn
time = Benchmark.measure {
self.revert {
recorder.inverse.each do |cmd, args|
send(cmd, *args)
end
}
recorder.inverse.each do |cmd, args|
send(cmd, *args)
end
}
else
time = Benchmark.measure { change }
@@ -456,11 +442,9 @@ module ActiveRecord
arg_list = arguments.map{ |a| a.inspect } * ', '
say_with_time "#{method}(#{arg_list})" do
unless reverting?
unless arguments.empty? || method == :execute
arguments[0] = Migrator.proper_table_name(arguments.first)
arguments[1] = Migrator.proper_table_name(arguments.second) if method == :rename_table
end
unless arguments.empty? || method == :execute
arguments[0] = Migrator.proper_table_name(arguments.first)
arguments[1] = Migrator.proper_table_name(arguments.second) if method == :rename_table
end
return super unless connection.respond_to?(method)
connection.send(method, *arguments, &block)

Some files were not shown because too many files have changed in this diff Show More