(a) A person is guilty of possession of a weapon on school grounds when, knowing that such person is not licensed or privileged to do so, such person possesses a firearm or deadly weapon, as defined in section 53a-3, (1) in or on the real property comprising a public or private elementary or secondary school, or (2) at a school-sponsored activity as defined in subsection (h) of section 10-233a.

      (b) The provisions of subsection (a) of this section shall not apply to the otherwise lawful possession of a firearm (1) by a person for use in a program approved by school officials in or on such school property or at such school-sponsored activity, (2) by a person in accordance with an agreement entered into between school officials and such person or such person’s employer, (3) by a peace officer, as defined in subdivision (9) of section 53a-3, while engaged in the performance of such peace officer’s official duties, or (4) by a person while traversing such school property for the purpose of gaining access to public or private lands open to hunting or for other lawful purposes, provided such firearm is not loaded and the entry on such school property is permitted by the local or regional board of education.

      (c) Possession of a weapon on school grounds is a class D felony.