Witnesses and survivors said the assailants sprayed gunfire among mostly unarmed Afghan soldiers and officers, many of whom were either just leaving weekly prayers at the base’s mosque or eating in its canteen.