I wonder if source code can be requested under the Freedom of Information Act. The act only applies to the executive branch but that's still probably a lot of software.
This varies widely but our website code is definitely owned by NASA - they even run the version control system to make sure that other contractors don't "forget" to give it to them.
Many times, those pieces of software integrate with commercial third party components. In most of those cases, the government produced software is basically just glue to bind together lots of libraries.