When is castling possible? Is castling possible if any of the squares involved in the castling are under attack, or is this a problem only if the squares moved through by the king are under attack and not the ones moved through by the rook?
Yes, you can, as long as the king doesn't pass through or end up on an attacked square.

From FIDE Laws of Chess:


  
  The right to castle has been lost:
  
  
  if the king has already moved, or
  with a rook that has already moved.
  
  Castling is prevented temporarily:
  
  
  if the square on which the king stands, or the square which it must cross, or the square which it is to occupy, is attacked by one or more of the opponent's pieces, or
  if there is any piece between the king and the rook with which castling is to be effected.