(a) A person sentenced to imprisonment in a state prison or to imprisonment pursuant to subdivision (h) of Section 1170 may during that period of confinement be deprived of such rights, and only such rights, as is reasonably related to legitimate penological interests.