In an action for foreclosure or satisfaction, a court may:
In no case under this chapter shall the possession of the property so sold be delivered to the person entitled thereto, until after the expiration of the period of redemption, subject however to the rights of any person under a valid assignment of rents, and a receiver in possession thereof. There shall be added to the amount of any such judgment all sums reasonably expended by the mortgagee for the protection and preservation of the mortgaged property or the mortgagee's interest therein. The court shall further determine the priority of any other liens, the owners of which were made a party to the action, and shall have the further power to determine the rights of subsequent liens filed after the commencement of suit.
SDCL 21-49-23