The court shall ascertain and declare the rights, titles, and interest of all the parties to such action, the plaintiffs as well as the defendants, and shall give judgment according to the rights of the parties.