In an action to enforce a lien for work provided to a contractor:
(a)
The contractor shall defend the action at the contractor’s own expense. During the pendency of the action the owner may withhold from the direct contractor the amount of the lien claim.
(b)
If the judgment in the action is against the owner or the owner’s property, the owner may deduct the amount of the judgment and costs from any amount owed to the direct contractor. If the amount of the judgment and costs exceeds the amount owed to the direct contractor, or if the owner has settled with the direct contractor in full, the owner may recover from the direct contractor, or the sureties on
a bond given by the direct contractor for faithful performance of the direct contract, the amount of the judgment and costs that exceed the contract price and for which the direct contractor was originally liable.