You should only have to replace the seal to get it to hold a seal but if your car has been in an accident before then the body could be out of alignment then you would need more work.
Most auto stores will carry a rubber weather barrier that you can install in the gaps where the glass closes down on the roof line. Close the sunroof and pour a small amount of water over the top, identify where the water is coming in and then take the weather stripping and place it in the gap.
If the seal is a little hard and dry you may be able to get away with just applying several coats or amor-all or similar product. This should make it more pliable and hopefully seal the sunroof. If the seal is damaged or still won't seal you will have to contact a dealer or look for a replacement.
. first thing to do is check the black seal surrounding the glass should be smooth with no bumps secondly remove the sunroof and check the tracks for leaves andd blockage