Unless the roof is designated as "rough" or "cover", the infantry on it would be considered "in the open" and take double damage. If "rough", then normal damage. If it provides cover, then the to-hit odds would be reduced, but they'd take normal damage if hit. I was never fond of the abstraction, where damage is not reduced by cover, but either "all" or "nothing", depending on if the die roll indicates a hit or miss. Better infantry weapon damage rules are sorely needed.
For the second question, the infantry would fire at the building, and damage would then be reduced by the building's construction factor and type. Anything above that damage reduction would then transfer to the infantry inside. Once again, damage is heavily abstracted, so there's not even the slightest chance of a trooper being hit by a lucky shot or ricochet if the CF is high enough to stop the damage.