The Iraqi parliament has passed a long-delayed law that will clear the way for national elections in January.