An action may be brought by the attorney-general, in the name of the people of this state, upon his own information, or upon a complaint of a private party, against any person who usurps, intrudes into, or unlawfully holds or exercises any public office, civil or military, or any franchise, or against any corporation, either de jure or de facto, which usurps, intrudes into, or unlawfully holds or exercises any franchise, within this state. And the attorney-general must bring the action, whenever he has reason to believe that any such office or franchise has been usurped, intruded into, or unlawfully held or exercised by any person, or when he is directed to do so by the governor.
Whenever such action is brought, the Attorney General, in addition to the statement of the cause of action, may also set forth in the complaint the name of the person rightly entitled to the office, with a statement of his right thereto.
In every such action judgment may be rendered upon the right of the defendant, and also upon the right of the party so alleged to be entitled, or only upon the right of the defendant, as justice may require.
If the judgment be rendered upon the right of the person so alleged to be entitled, and the same be in favor of such person, he will be entitled, after taking the oath of office and executing such official bond as may be required by law, to take upon himself the execution of the office.
If judgment be rendered upon the right of the person so alleged to be entitled, in favor of such person, he may recover, by action, the damages which he may have sustained by reason of the usurpation of the office by the defendant.
When several persons claim to be entitled to the same office or franchise, one action may be brought against all such persons, in order to try their respective rights to such office or franchise.
When a defendant, against whom such action has been brought, is adjudged guilty of usurping or intruding into, or unlawfully holding any office, franchise, or privilege, judgment must be rendered that such defendant be excluded from the office, franchise, or privilege, and that he pay the costs of the action. The Court may also, in its discretion, impose upon the defendant a fine not exceeding five thousand dollars, which find, when collected, must be paid into the Treasury of the State.
When the action is brought upon the information or application of a private party, the Attorney General may require such party to enter into an undertaking, with sureties to be approved by the Attorney General, conditioned that such party or the sureties will pay any judgment for costs or damages recovered against the plaintiff, and all the costs and expenses incurred in the prosecution of the action.
The action provided for in this chapter may be maintained by the board of supervisors or any county or city and county or the legislative body of any municipal corporation, respectively, in the name of such county, city and county or municipal corporation against any person who usurps, intrudes into or unlawfully holds or exercises any franchise, or portion thereof, within the respective territorial limits of such county, city and county or municipal corporation and which is of a kind that is within the jurisdiction of such board or body to grant or withhold.