Paul Krugman of the NY Times wrote extensively both during the crisis and since about the correct way to handle this situation:
1. Put the failing bank into "receivership". I.e., a "receiver" (temporary managerment) appointed by the government takes over the company and tries to salvage it.
2. Fire the original management team. I.e., the ones that got them into this mess with their excessive risktaking. Good. They should suffer the consequences of their bad management decisions. That's capitalism.
3. Take on whatever additional debt or equity financing is necessary to turn the company around - without paying any regard to the positions or desires of the current stockholders. The current stockholders' positions' will likely get diluted to nearly worthless. Good. They should suffer the consequences of their bad investing decisions. That's capitalism.
4. After the company is turned around, take it out from under government receivership, hire a new management, and (if needed/appropriate) launch it public again via an IPO.
There's a long, established history for handling failed banks this way (read up on the S&L Crisis), and it's the proper way to keep an institution alive and out of bankruptcy, without rewarding the management and stockholders who brought it to bankruptcy in the first place.
Krugman often pointed out, though, that the Obama administration was too scared to go this route - perhaps because they were worried about the absurd accusations of "socialism" that the Psychotic Right would undoubtably have started screaming about.
So instead, they chose to reward the management and shareholders that caused the problem, by using government money to help prop up the value in their worthless company. Moral hazard indeed! Privatize all the profits, but give all the losses to the public. And socialism is the evil here?!?!?!?